From 674a60748884dc55ee7091b7c23a41240e75f73c Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Tue, 1 Jun 2004 02:46:09 +0000 Subject: Makefile.in contains updated files required --HG-- extra : convert_revision : cc8a8c49dc70e632c352853a39801089b08149be --- common-chansession.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 common-chansession.c (limited to 'common-chansession.c') diff --git a/common-chansession.c b/common-chansession.c new file mode 100644 index 0000000..ad9c7ed --- /dev/null +++ b/common-chansession.c @@ -0,0 +1,43 @@ +/* + * Dropbear - a SSH2 server + * + * Copyright (c) 2002,2003 Matt Johnston + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ + +#include "chansession.h" + +/* Mapping of signal values to ssh signal strings */ +const extern struct SigMap signames[] = { + {SIGABRT, "ABRT"}, + {SIGALRM, "ALRM"}, + {SIGFPE, "FPE"}, + {SIGHUP, "HUP"}, + {SIGILL, "ILL"}, + {SIGINT, "INT"}, + {SIGKILL, "KILL"}, + {SIGPIPE, "PIPE"}, + {SIGQUIT, "QUIT"}, + {SIGSEGV, "SEGV"}, + {SIGTERM, "TERM"}, + {SIGUSR1, "USR1"}, + {SIGUSR2, "USR2"}, + {0, NULL} +}; -- cgit v1.2.3 From 513f947d62351e5af77676e20740232d753cd5b1 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 2 Jun 2004 04:59:49 +0000 Subject: Chantype handling is sorted --HG-- extra : convert_revision : 807efead6ecf690f147fd8145aa9d78ff894cdb2 --- channel.h | 5 +++-- common-channel.c | 19 +++++++++++------ common-chansession.c | 2 +- debug.h | 4 +++- localtcpfwd.c | 15 ++++++++++++- localtcpfwd.h | 2 +- remotetcpfwd.c | 1 + svr-chansession.c | 60 ++++++++++++++++++++++++++-------------------------- svr-session.c | 2 ++ 9 files changed, 67 insertions(+), 43 deletions(-) (limited to 'common-chansession.c') diff --git a/channel.h b/channel.h index 750a9bb..e033164 100644 --- a/channel.h +++ b/channel.h @@ -81,7 +81,7 @@ struct Channel { int initconn; /* used for TCP forwarding, whether the channel has been fully initialised */ - struct ChanType* type; + const struct ChanType* type; }; @@ -100,7 +100,8 @@ void chaninitialise(); void chancleanup(); void setchannelfds(fd_set *readfd, fd_set *writefd); void channelio(fd_set *readfd, fd_set *writefd); -struct Channel* newchannel(unsigned int remotechan, struct ChanType *type, +struct Channel* newchannel(unsigned int remotechan, + const struct ChanType *type, unsigned int transwindow, unsigned int transmaxpacket); void recv_msg_channel_open(); diff --git a/common-channel.c b/common-channel.c index 135e098..4643fc2 100644 --- a/common-channel.c +++ b/common-channel.c @@ -96,7 +96,8 @@ void chancleanup() { /* If remotechan, transwindow and transmaxpacket are not know (for a new * outgoing connection, with them to be filled on confirmation), they should * all be set to 0 */ -struct Channel* newchannel(unsigned int remotechan, struct ChanType *type, +struct Channel* newchannel(unsigned int remotechan, + const struct ChanType *type, unsigned int transwindow, unsigned int transmaxpacket) { struct Channel * newchan; @@ -535,8 +536,6 @@ void recv_msg_channel_request() { dropbear_exit("Unknown channel"); } - TRACE(("chan type is %d", channel->type)); - if (channel->type->reqhandler) { channel->type->reqhandler(channel); } else { @@ -737,6 +736,7 @@ void recv_msg_channel_open() { unsigned int typelen; unsigned int remotechan, transwindow, transmaxpacket; struct Channel *channel; + const struct ChanType **cp; const struct ChanType *chantype; unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE; int ret; @@ -758,19 +758,24 @@ void recv_msg_channel_open() { goto failure; } - /* Get the channel type. This will depend if it is a client or a server, - * so we iterate through the connection-specific list which was - * set up when the connection started */ - for (chantype = ses.chantypes[0]; chantype != NULL; chantype++) { + /* Get the channel type. Client and server style invokation will set up a + * different list for ses.chantypes at startup. We just iterate through + * this list and find the matching name */ + for (cp = &ses.chantypes[0], chantype = (*cp); + chantype != NULL; + cp++, chantype = (*cp)) { if (strcmp(type, chantype->name) == 0) { break; } } if (chantype == NULL) { + TRACE(("No matching type for '%s'", type)); goto failure; } + TRACE(("matched type '%s'", type)); + /* create the channel */ channel = newchannel(remotechan, chantype, transwindow, transmaxpacket); diff --git a/common-chansession.c b/common-chansession.c index ad9c7ed..b350c6c 100644 --- a/common-chansession.c +++ b/common-chansession.c @@ -25,7 +25,7 @@ #include "chansession.h" /* Mapping of signal values to ssh signal strings */ -const extern struct SigMap signames[] = { +const struct SigMap signames[] = { {SIGABRT, "ABRT"}, {SIGALRM, "ALRM"}, {SIGFPE, "FPE"}, diff --git a/debug.h b/debug.h index 75f9503..f41a2e4 100644 --- a/debug.h +++ b/debug.h @@ -34,7 +34,9 @@ /* #define DEBUG_VALGRIND */ /* Define this to print trace statements - very verbose */ -#define DEBUG_TRACE +/* Caution: Don't use this in an unfriendly environment (ie unfirewalled), + * since the printing does not sanitise strings etc */ +/*#define DEBUG_TRACE*/ /* All functions writing to the cleartext payload buffer call * CHECKCLEARTOWRITE() before writing. This is only really useful if you're diff --git a/localtcpfwd.c b/localtcpfwd.c index 9894f46..bf89fa0 100644 --- a/localtcpfwd.c +++ b/localtcpfwd.c @@ -1,14 +1,27 @@ #include "includes.h" #include "session.h" #include "dbutil.h" +#include "channel.h" #include "localtcpfwd.h" #ifndef DISABLE_LOCALTCPFWD +static int newtcpdirect(struct Channel * channel); static int newtcp(const char * host, int port); +const struct ChanType chan_tcpdirect = { + 0, /* sepfds */ + "direct-tcpip", + newtcpdirect, /* init */ + NULL, /* checkclose */ + NULL, /* reqhandler */ + NULL /* closehandler */ +}; + + + /* Called upon creating a new direct tcp channel (ie we connect out to an * address */ -int newtcpdirect(struct Channel * channel) { +static int newtcpdirect(struct Channel * channel) { unsigned char* desthost = NULL; unsigned int destport; diff --git a/localtcpfwd.h b/localtcpfwd.h index 324cb55..65efa6e 100644 --- a/localtcpfwd.h +++ b/localtcpfwd.h @@ -28,7 +28,7 @@ #include "includes.h" #include "channel.h" -int newtcpdirect(struct Channel * channel); +extern const struct ChanType chan_tcpdirect; #endif #endif diff --git a/remotetcpfwd.c b/remotetcpfwd.c index c58b820..40a3a82 100644 --- a/remotetcpfwd.c +++ b/remotetcpfwd.c @@ -90,6 +90,7 @@ static void acceptremote(struct TCPListener *listener) { return; } + /* XXX XXX XXX - type here needs fixing */ if (send_msg_channel_open_init(fd, CHANNEL_ID_TCPFORWARDED, "forwarded-tcpip") == DROPBEAR_SUCCESS) { buf_putstring(ses.writepayload, tcpinfo->addr, diff --git a/svr-chansession.c b/svr-chansession.c index 2705069..f5b4308 100644 --- a/svr-chansession.c +++ b/svr-chansession.c @@ -56,16 +56,6 @@ static void chansessionrequest(struct Channel *channel); static void send_exitsignalstatus(struct Channel *channel); static int sesscheckclose(struct Channel *channel); -const struct ChanType svrchansess = { - 0, /* sepfds */ - "session", /* name */ - newchansess, /* inithandler */ - sesscheckclose, /* checkclosehandler */ - chansessionrequest, /* reqhandler */ - closechansess, /* closehandler */ -}; - - /* required to clear environment */ extern char** environ; @@ -75,25 +65,6 @@ static int sesscheckclose(struct Channel *channel) { return chansess->exited; } -/* Set up the general chansession environment, in particular child-exit - * handling */ -void svr_chansessinitialise() { - - struct sigaction sa_chld; - - /* single child process intially */ - svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid)); - svr_ses.childpids[0].pid = -1; /* unused */ - svr_ses.childpids[0].chansess = NULL; - svr_ses.childpidsize = 1; - sa_chld.sa_handler = sesssigchild_handler; - sa_chld.sa_flags = SA_NOCLDSTOP; - if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { - dropbear_exit("signal() error"); - } - -} - /* handler for childs exiting, store the state for return to the client */ static void sesssigchild_handler(int dummy) { @@ -254,7 +225,7 @@ static void closechansess(struct Channel *channel) { chansess = (struct ChanSess*)channel->typedata; - send_exitsignalstatus(chansess); + send_exitsignalstatus(channel); TRACE(("enter closechansess")); if (chansess == NULL) { @@ -911,6 +882,35 @@ static void execchild(struct ChanSess *chansess) { dropbear_exit("child failed"); } +const struct ChanType svrchansess = { + 0, /* sepfds */ + "session", /* name */ + newchansess, /* inithandler */ + sesscheckclose, /* checkclosehandler */ + chansessionrequest, /* reqhandler */ + closechansess, /* closehandler */ +}; + + +/* Set up the general chansession environment, in particular child-exit + * handling */ +void svr_chansessinitialise() { + + struct sigaction sa_chld; + + /* single child process intially */ + svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid)); + svr_ses.childpids[0].pid = -1; /* unused */ + svr_ses.childpids[0].chansess = NULL; + svr_ses.childpidsize = 1; + sa_chld.sa_handler = sesssigchild_handler; + sa_chld.sa_flags = SA_NOCLDSTOP; + if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { + dropbear_exit("signal() error"); + } + +} + /* add a new environment variable, allocating space for the entry */ void addnewvar(const char* param, const char* var) { diff --git a/svr-session.c b/svr-session.c index c6f05cc..8e8eaea 100644 --- a/svr-session.c +++ b/svr-session.c @@ -35,6 +35,7 @@ #include "channel.h" #include "chansession.h" #include "atomicio.h" +#include "localtcpfwd.h" static void svr_remoteclosed(); @@ -42,6 +43,7 @@ struct serversession svr_ses; const struct ChanType *chantypes[] = { &svrchansess, + &chan_tcpdirect, NULL /* Null termination is mandatory. */ }; -- cgit v1.2.3