summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2004-06-02 04:59:49 +0000
committerMatt Johnston <matt@ucc.asn.au>2004-06-02 04:59:49 +0000
commit6bde8e19cd3098839dcfe9916f232b9777887e87 (patch)
treeab192e9de5cff39eaffe5b01eeb96d7a283826d1
parent60a495d854b1132dd31c927ea59ecdcd790286ee (diff)
downloaddropbear-6bde8e19cd3098839dcfe9916f232b9777887e87.tar.gz
Chantype handling is sorted
-rw-r--r--channel.h5
-rw-r--r--common-channel.c19
-rw-r--r--common-chansession.c2
-rw-r--r--debug.h4
-rw-r--r--localtcpfwd.c15
-rw-r--r--localtcpfwd.h2
-rw-r--r--remotetcpfwd.c1
-rw-r--r--svr-chansession.c60
-rw-r--r--svr-session.c2
9 files changed, 67 insertions, 43 deletions
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. */
};