# HG changeset patch # User Matt Johnston # Date 1086152389 0 # Node ID 425ed5c20157516e3debcc4e3ac390da2777cc41 # Parent ab00ef513e975c6f4054ece7030f886593337d26 Chantype handling is sorted diff -r ab00ef513e97 -r 425ed5c20157 channel.h --- a/channel.h Tue Jun 01 10:48:46 2004 +0000 +++ b/channel.h Wed Jun 02 04:59:49 2004 +0000 @@ -81,7 +81,7 @@ 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 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 -r ab00ef513e97 -r 425ed5c20157 common-channel.c --- a/common-channel.c Tue Jun 01 10:48:46 2004 +0000 +++ b/common-channel.c Wed Jun 02 04:59:49 2004 +0000 @@ -96,7 +96,8 @@ /* 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 @@ dropbear_exit("Unknown channel"); } - TRACE(("chan type is %d", channel->type)); - if (channel->type->reqhandler) { channel->type->reqhandler(channel); } else { @@ -737,6 +736,7 @@ 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 @@ 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 -r ab00ef513e97 -r 425ed5c20157 common-chansession.c --- a/common-chansession.c Tue Jun 01 10:48:46 2004 +0000 +++ b/common-chansession.c Wed Jun 02 04:59:49 2004 +0000 @@ -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 -r ab00ef513e97 -r 425ed5c20157 debug.h --- a/debug.h Tue Jun 01 10:48:46 2004 +0000 +++ b/debug.h Wed Jun 02 04:59:49 2004 +0000 @@ -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 -r ab00ef513e97 -r 425ed5c20157 localtcpfwd.c --- a/localtcpfwd.c Tue Jun 01 10:48:46 2004 +0000 +++ b/localtcpfwd.c Wed Jun 02 04:59:49 2004 +0000 @@ -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 -r ab00ef513e97 -r 425ed5c20157 localtcpfwd.h --- a/localtcpfwd.h Tue Jun 01 10:48:46 2004 +0000 +++ b/localtcpfwd.h Wed Jun 02 04:59:49 2004 +0000 @@ -28,7 +28,7 @@ #include "includes.h" #include "channel.h" -int newtcpdirect(struct Channel * channel); +extern const struct ChanType chan_tcpdirect; #endif #endif diff -r ab00ef513e97 -r 425ed5c20157 remotetcpfwd.c --- a/remotetcpfwd.c Tue Jun 01 10:48:46 2004 +0000 +++ b/remotetcpfwd.c Wed Jun 02 04:59:49 2004 +0000 @@ -90,6 +90,7 @@ 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 -r ab00ef513e97 -r 425ed5c20157 svr-chansession.c --- a/svr-chansession.c Tue Jun 01 10:48:46 2004 +0000 +++ b/svr-chansession.c Wed Jun 02 04:59:49 2004 +0000 @@ -56,16 +56,6 @@ 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 @@ 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 @@ chansess = (struct ChanSess*)channel->typedata; - send_exitsignalstatus(chansess); + send_exitsignalstatus(channel); TRACE(("enter closechansess")); if (chansess == NULL) { @@ -911,6 +882,35 @@ 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 -r ab00ef513e97 -r 425ed5c20157 svr-session.c --- a/svr-session.c Tue Jun 01 10:48:46 2004 +0000 +++ b/svr-session.c Wed Jun 02 04:59:49 2004 +0000 @@ -35,6 +35,7 @@ #include "channel.h" #include "chansession.h" #include "atomicio.h" +#include "localtcpfwd.h" static void svr_remoteclosed(); @@ -42,6 +43,7 @@ const struct ChanType *chantypes[] = { &svrchansess, + &chan_tcpdirect, NULL /* Null termination is mandatory. */ };