Chantype handling is sorted

--HG--
extra : convert_revision : 807efead6ecf690f147fd8145aa9d78ff894cdb2
This commit is contained in:
Matt Johnston 2004-06-02 04:59:49 +00:00
parent 6152263045
commit 513f947d62
9 changed files with 67 additions and 43 deletions

View File

@ -81,7 +81,7 @@ struct Channel {
int initconn; /* used for TCP forwarding, whether the channel has been int initconn; /* used for TCP forwarding, whether the channel has been
fully initialised */ fully initialised */
struct ChanType* type; const struct ChanType* type;
}; };
@ -100,7 +100,8 @@ void chaninitialise();
void chancleanup(); void chancleanup();
void setchannelfds(fd_set *readfd, fd_set *writefd); void setchannelfds(fd_set *readfd, fd_set *writefd);
void channelio(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); unsigned int transwindow, unsigned int transmaxpacket);
void recv_msg_channel_open(); void recv_msg_channel_open();

View File

@ -96,7 +96,8 @@ void chancleanup() {
/* If remotechan, transwindow and transmaxpacket are not know (for a new /* If remotechan, transwindow and transmaxpacket are not know (for a new
* outgoing connection, with them to be filled on confirmation), they should * outgoing connection, with them to be filled on confirmation), they should
* all be set to 0 */ * 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) { unsigned int transwindow, unsigned int transmaxpacket) {
struct Channel * newchan; struct Channel * newchan;
@ -535,8 +536,6 @@ void recv_msg_channel_request() {
dropbear_exit("Unknown channel"); dropbear_exit("Unknown channel");
} }
TRACE(("chan type is %d", channel->type));
if (channel->type->reqhandler) { if (channel->type->reqhandler) {
channel->type->reqhandler(channel); channel->type->reqhandler(channel);
} else { } else {
@ -737,6 +736,7 @@ void recv_msg_channel_open() {
unsigned int typelen; unsigned int typelen;
unsigned int remotechan, transwindow, transmaxpacket; unsigned int remotechan, transwindow, transmaxpacket;
struct Channel *channel; struct Channel *channel;
const struct ChanType **cp;
const struct ChanType *chantype; const struct ChanType *chantype;
unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE; unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE;
int ret; int ret;
@ -758,19 +758,24 @@ void recv_msg_channel_open() {
goto failure; goto failure;
} }
/* Get the channel type. This will depend if it is a client or a server, /* Get the channel type. Client and server style invokation will set up a
* so we iterate through the connection-specific list which was * different list for ses.chantypes at startup. We just iterate through
* set up when the connection started */ * this list and find the matching name */
for (chantype = ses.chantypes[0]; chantype != NULL; chantype++) { for (cp = &ses.chantypes[0], chantype = (*cp);
chantype != NULL;
cp++, chantype = (*cp)) {
if (strcmp(type, chantype->name) == 0) { if (strcmp(type, chantype->name) == 0) {
break; break;
} }
} }
if (chantype == NULL) { if (chantype == NULL) {
TRACE(("No matching type for '%s'", type));
goto failure; goto failure;
} }
TRACE(("matched type '%s'", type));
/* create the channel */ /* create the channel */
channel = newchannel(remotechan, chantype, transwindow, transmaxpacket); channel = newchannel(remotechan, chantype, transwindow, transmaxpacket);

View File

@ -25,7 +25,7 @@
#include "chansession.h" #include "chansession.h"
/* Mapping of signal values to ssh signal strings */ /* Mapping of signal values to ssh signal strings */
const extern struct SigMap signames[] = { const struct SigMap signames[] = {
{SIGABRT, "ABRT"}, {SIGABRT, "ABRT"},
{SIGALRM, "ALRM"}, {SIGALRM, "ALRM"},
{SIGFPE, "FPE"}, {SIGFPE, "FPE"},

View File

@ -34,7 +34,9 @@
/* #define DEBUG_VALGRIND */ /* #define DEBUG_VALGRIND */
/* Define this to print trace statements - very verbose */ /* 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 /* All functions writing to the cleartext payload buffer call
* CHECKCLEARTOWRITE() before writing. This is only really useful if you're * CHECKCLEARTOWRITE() before writing. This is only really useful if you're

View File

@ -1,14 +1,27 @@
#include "includes.h" #include "includes.h"
#include "session.h" #include "session.h"
#include "dbutil.h" #include "dbutil.h"
#include "channel.h"
#include "localtcpfwd.h" #include "localtcpfwd.h"
#ifndef DISABLE_LOCALTCPFWD #ifndef DISABLE_LOCALTCPFWD
static int newtcpdirect(struct Channel * channel);
static int newtcp(const char * host, int port); 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 /* Called upon creating a new direct tcp channel (ie we connect out to an
* address */ * address */
int newtcpdirect(struct Channel * channel) { static int newtcpdirect(struct Channel * channel) {
unsigned char* desthost = NULL; unsigned char* desthost = NULL;
unsigned int destport; unsigned int destport;

View File

@ -28,7 +28,7 @@
#include "includes.h" #include "includes.h"
#include "channel.h" #include "channel.h"
int newtcpdirect(struct Channel * channel); extern const struct ChanType chan_tcpdirect;
#endif #endif
#endif #endif

View File

@ -90,6 +90,7 @@ static void acceptremote(struct TCPListener *listener) {
return; return;
} }
/* XXX XXX XXX - type here needs fixing */
if (send_msg_channel_open_init(fd, CHANNEL_ID_TCPFORWARDED, if (send_msg_channel_open_init(fd, CHANNEL_ID_TCPFORWARDED,
"forwarded-tcpip") == DROPBEAR_SUCCESS) { "forwarded-tcpip") == DROPBEAR_SUCCESS) {
buf_putstring(ses.writepayload, tcpinfo->addr, buf_putstring(ses.writepayload, tcpinfo->addr,

View File

@ -56,16 +56,6 @@ static void chansessionrequest(struct Channel *channel);
static void send_exitsignalstatus(struct Channel *channel); static void send_exitsignalstatus(struct Channel *channel);
static int sesscheckclose(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 */ /* required to clear environment */
extern char** environ; extern char** environ;
@ -75,25 +65,6 @@ static int sesscheckclose(struct Channel *channel) {
return chansess->exited; 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 */ /* handler for childs exiting, store the state for return to the client */
static void sesssigchild_handler(int dummy) { static void sesssigchild_handler(int dummy) {
@ -254,7 +225,7 @@ static void closechansess(struct Channel *channel) {
chansess = (struct ChanSess*)channel->typedata; chansess = (struct ChanSess*)channel->typedata;
send_exitsignalstatus(chansess); send_exitsignalstatus(channel);
TRACE(("enter closechansess")); TRACE(("enter closechansess"));
if (chansess == NULL) { if (chansess == NULL) {
@ -911,6 +882,35 @@ static void execchild(struct ChanSess *chansess) {
dropbear_exit("child failed"); 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 */ /* add a new environment variable, allocating space for the entry */
void addnewvar(const char* param, const char* var) { void addnewvar(const char* param, const char* var) {

View File

@ -35,6 +35,7 @@
#include "channel.h" #include "channel.h"
#include "chansession.h" #include "chansession.h"
#include "atomicio.h" #include "atomicio.h"
#include "localtcpfwd.h"
static void svr_remoteclosed(); static void svr_remoteclosed();
@ -42,6 +43,7 @@ struct serversession svr_ses;
const struct ChanType *chantypes[] = { const struct ChanType *chantypes[] = {
&svrchansess, &svrchansess,
&chan_tcpdirect,
NULL /* Null termination is mandatory. */ NULL /* Null termination is mandatory. */
}; };