diff options
author | Matt Johnston <matt@ucc.asn.au> | 2008-09-15 12:51:50 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2008-09-15 12:51:50 +0000 |
commit | b619e88f5481649a480e133494caf27f8880437a (patch) | |
tree | d8410822e892282abc5cdcd804db031285fe613c | |
parent | 460bf4382257a262fda862f66d6fe97c749f5bb7 (diff) |
- Split main socket var into ses.sock_in/ses.sock_out in preparation
for -J proxy_cmd option (and some prelim options for that)
--HG--
extra : convert_revision : 47cdea9a7d66c553c6f5eec43b899821939d4e4c
-rw-r--r-- | cli-main.c | 18 | ||||
-rw-r--r-- | cli-runopts.c | 11 | ||||
-rw-r--r-- | cli-session.c | 10 | ||||
-rw-r--r-- | common-session.c | 29 | ||||
-rw-r--r-- | options.h | 4 | ||||
-rw-r--r-- | packet.c | 6 | ||||
-rw-r--r-- | runopts.h | 3 | ||||
-rw-r--r-- | session.h | 7 | ||||
-rw-r--r-- | svr-session.c | 10 |
9 files changed, 66 insertions, 32 deletions
@@ -39,7 +39,7 @@ int cli_main(int argc, char ** argv) { int main(int argc, char ** argv) { #endif - int sock; + int sock_in, sock_out; char* error = NULL; char* hostandport; int len; @@ -58,10 +58,18 @@ int main(int argc, char ** argv) { dropbear_exit("signal() error"); } - sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, - 0, &error); +#ifdef CLI_ENABLE_PROXYCMD + if (cli_runopts.proxycmd) { - if (sock < 0) { + } else +#endif + { + int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, + 0, &error); + sock_in = sock_out = sock; + } + + if (sock_in < 0) { dropbear_exit("%s", error); } @@ -72,7 +80,7 @@ int main(int argc, char ** argv) { snprintf(hostandport, len, "%s:%s", cli_opts.remotehost, cli_opts.remoteport); - cli_session(sock, hostandport); + cli_session(sock_in, sock_out, hostandport); /* not reached */ return -1; diff --git a/cli-runopts.c b/cli-runopts.c index 42c5a9f..a1be06a 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -65,6 +65,9 @@ static void printhelp() { #endif "-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n" "-K <keepalive> (0 is never, default %d)\n" +#ifdef ENABLE_CLI_PROXYCMD + "-J <proxy_program> Use program rather than tcp connection" +#endif #ifdef DEBUG_TRACE "-v verbose\n" #endif @@ -87,6 +90,9 @@ void cli_getopts(int argc, char ** argv) { #ifdef ENABLE_CLI_REMOTETCPFWD int nextisremote = 0; #endif +#ifdef ENABLE_CLI_PROXYCMD + int nextisproxycmd = 0; +#endif char* dummy = NULL; /* Not used for anything real */ char* recv_window_arg = NULL; @@ -199,6 +205,11 @@ void cli_getopts(int argc, char ** argv) { nextisremote = 1; break; #endif +#ifdef ENABLE_CLI_PROXYCMD + case 'J': + next = &cli_opts.proxycmd; + break; +#endif case 'l': next = &cli_opts.username; break; diff --git a/cli-session.c b/cli-session.c index 360187f..3d9ce98 100644 --- a/cli-session.c +++ b/cli-session.c @@ -74,13 +74,13 @@ static const struct ChanType *cli_chantypes[] = { NULL /* Null termination */ }; -void cli_session(int sock, char* remotehost) { +void cli_session(int sock_in, int sock_out, char* remotehost) { seedrandom(); crypto_init(); - common_session_init(sock, remotehost); + common_session_init(sock_in, sock_out, remotehost); chaninitialise(cli_chantypes); @@ -294,8 +294,10 @@ static void cli_remoteclosed() { /* XXX TODO perhaps print a friendlier message if we get this but have * already sent/received disconnect message(s) ??? */ - close(ses.sock); - ses.sock = -1; + m_close(ses.sock_in); + m_close(ses.sock_out); + ses.sock_in = -1; + ses.sock_out = -1; dropbear_exit("remote closed the connection"); } diff --git a/common-session.c b/common-session.c index 79313f2..30c0a58 100644 --- a/common-session.c +++ b/common-session.c @@ -52,14 +52,15 @@ int exitflag = 0; /* GLOBAL */ /* called only at the start of a session, set up initial state */ -void common_session_init(int sock, char* remotehost) { +void common_session_init(int sock_in, int sock_out, char* remotehost) { TRACE(("enter session_init")) ses.remotehost = remotehost; - ses.sock = sock; - ses.maxfd = sock; + ses.sock_in = sock_in; + ses.sock_out = sock_out; + ses.maxfd = MAX(sock_in, sock_out); ses.connect_time = 0; ses.last_packet_time = 0; @@ -137,11 +138,11 @@ void session_loop(void(*loophandler)()) { FD_ZERO(&writefd); FD_ZERO(&readfd); dropbear_assert(ses.payload == NULL); - if (ses.sock != -1) { - FD_SET(ses.sock, &readfd); - if (!isempty(&ses.writequeue)) { - FD_SET(ses.sock, &writefd); - } + if (ses.sock_in != -1) { + FD_SET(ses.sock_in, &readfd); + } + if (ses.sock_out != -1 && !isempty(&ses.writequeue)) { + FD_SET(ses.sock_out, &writefd); } /* We get woken up when signal handlers write to this pipe. @@ -183,12 +184,14 @@ void session_loop(void(*loophandler)()) { checktimeouts(); /* process session socket's incoming/outgoing data */ - if (ses.sock != -1) { - if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) { + if (ses.sock_out != -1) { + if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) { write_packet(); } + } - if (FD_ISSET(ses.sock, &readfd)) { + if (ses.sock_in != -1) { + if (FD_ISSET(ses.sock_in, &readfd)) { read_packet(); } @@ -248,14 +251,14 @@ void session_identification() { int i; /* write our version string, this blocks */ - if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n", + if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n", strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { ses.remoteclosed(); } /* If they send more than 50 lines, something is wrong */ for (i = 0; i < 50; i++) { - len = ident_readln(ses.sock, linebuf, sizeof(linebuf)); + len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); if (len < 0 && errno != EINTR) { /* It failed */ @@ -60,6 +60,10 @@ etc) slower (perhaps by 50%). Recommended for most small systems. */ #define ENABLE_CLI_LOCALTCPFWD #define ENABLE_CLI_REMOTETCPFWD +/* Allow using -J <proxycommand> to run the connection through a + pipe to a program, rather the normal TCP connection */ +/*#define ENABLE_CLI_PROXYCMD*/ + #define ENABLE_SVR_LOCALTCPFWD #define ENABLE_SVR_REMOTETCPFWD @@ -61,7 +61,7 @@ void write_packet() { len = writebuf->len - writebuf->pos; dropbear_assert(len > 0); /* Try to write as much as possible */ - written = write(ses.sock, buf_getptr(writebuf, len), len); + written = write(ses.sock_out, buf_getptr(writebuf, len), len); if (written < 0) { if (errno == EINTR) { @@ -122,7 +122,7 @@ void read_packet() { * mightn't be any available (EAGAIN) */ dropbear_assert(ses.readbuf != NULL); maxlen = ses.readbuf->len - ses.readbuf->pos; - len = read(ses.sock, buf_getptr(ses.readbuf, maxlen), maxlen); + len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen); if (len == 0) { ses.remoteclosed(); @@ -171,7 +171,7 @@ static void read_packet_init() { maxlen = blocksize - ses.readbuf->pos; /* read the rest of the packet if possible */ - len = read(ses.sock, buf_getwriteptr(ses.readbuf, maxlen), + len = read(ses.sock_in, buf_getwriteptr(ses.readbuf, maxlen), maxlen); if (len == 0) { ses.remoteclosed(); @@ -117,6 +117,9 @@ typedef struct cli_runopts { #ifdef ENABLE_CLI_LOCALTCPFWD struct TCPFwdList * localfwds; #endif +#ifdef ENABLE_CLI_PROXYCMD + char *proxycmd; +#endif } cli_runopts; @@ -41,7 +41,7 @@ extern int sessinitdone; /* Is set to 0 somewhere */ extern int exitflag; -void common_session_init(int sock, char* remotehost); +void common_session_init(int sock_in, int sock_out, char* remotehost); void session_loop(void(*loophandler)()); void common_session_cleanup(); void session_identification(); @@ -54,7 +54,7 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param); void svr_dropbear_log(int priority, const char* format, va_list param); /* Client */ -void cli_session(int sock, char *remotehost); +void cli_session(int sock_in, int sock_out, char *remotehost); void cli_session_cleanup(); void cleantext(unsigned char* dirtytext); @@ -97,7 +97,8 @@ struct sshsession { (cleared after auth once we're not respecting AUTH_TIMEOUT any more) */ - int sock; + int sock_in; + int sock_out; unsigned char *remotehost; /* the peer hostname */ diff --git a/svr-session.c b/svr-session.c index 5a8364a..658bc6e 100644 --- a/svr-session.c +++ b/svr-session.c @@ -80,7 +80,7 @@ void svr_session(int sock, int childpipe, reseedrandom(); crypto_init(); - common_session_init(sock, remotehost); + common_session_init(sock, sock, remotehost); /* Initialise server specific parts of the session */ svr_ses.childpipe = childpipe; @@ -183,7 +183,7 @@ void svr_dropbear_log(int priority, const char* format, va_list param) { localtime(×ec)) == 0) { /* upon failure, just print the epoch-seconds time. */ - snprintf(datestr, sizeof(datestr), "%d", timesec); + snprintf(datestr, sizeof(datestr), "%d", (int)timesec); } fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf); } @@ -192,8 +192,10 @@ void svr_dropbear_log(int priority, const char* format, va_list param) { /* called when the remote side closes the connection */ static void svr_remoteclosed() { - close(ses.sock); - ses.sock = -1; + m_close(ses.sock_in); + m_close(ses.sock_out); + ses.sock_in = -1; + ses.sock_out = -1; dropbear_close("Exited normally"); } |