From b05ab854ae9b5ecc179a4075ee8d7953d42ffd2b Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 25 Jan 2006 17:13:38 +0000 Subject: Check that the output circular buffer is actually empty before closing the channel (thanks to Tomas Vanek for his help). --HG-- extra : convert_revision : 7fb3ca52f21072127c9615a5bdbc054c24669e51 --- common-channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common-channel.c') diff --git a/common-channel.c b/common-channel.c index 7e8d428..4bed78d 100644 --- a/common-channel.c +++ b/common-channel.c @@ -377,7 +377,7 @@ static void writechannel(struct Channel* channel, int fd, circbuffer *cbuf) { cbuf_incrread(cbuf, len); channel->recvdonelen += len; - if (fd == channel->writefd && len == maxlen && channel->recveof) { + if (fd == channel->writefd && cbuf_getused(cbuf) == 0 && channel->recveof) { /* Check if we're closing up */ closewritefd(channel); TRACE(("leave writechannel: recveof set")) -- cgit v1.2.3 From 1dc06524446b6ed8fa152ff99b0d5763214737f2 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 8 Mar 2006 12:09:02 +0000 Subject: Stomp on some minor warnings --HG-- extra : convert_revision : 4cbdd6e0a0d8c061075b9ed7609a06c4547f67d3 --- common-channel.c | 1 - rsa.c | 1 - tcp-accept.c | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'common-channel.c') diff --git a/common-channel.c b/common-channel.c index 7e8d428..e5d8c27 100644 --- a/common-channel.c +++ b/common-channel.c @@ -181,7 +181,6 @@ void channelio(fd_set *readfds, fd_set *writefds) { struct Channel *channel; unsigned int i; - int ret; /* iterate through all the possible channels */ for (i = 0; i < ses.chansize; i++) { diff --git a/rsa.c b/rsa.c index cc16fa0..005e4ca 100644 --- a/rsa.c +++ b/rsa.c @@ -264,7 +264,6 @@ void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data, DEF_MP_INT(rsa_tmp1); DEF_MP_INT(rsa_tmp2); DEF_MP_INT(rsa_tmp3); - unsigned char *tmpbuf; TRACE(("enter buf_put_rsa_sign")) dropbear_assert(key != NULL); diff --git a/tcp-accept.c b/tcp-accept.c index 90d72b3..ffb175e 100644 --- a/tcp-accept.c +++ b/tcp-accept.c @@ -47,7 +47,7 @@ static void tcp_acceptor(struct Listener *listener, int sock) { int fd; struct sockaddr_storage addr; - int len; + socklen_t len; char ipstring[NI_MAXHOST], portstring[NI_MAXSERV]; struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); -- cgit v1.2.3 From 1e03393b6813b8dc77916665d8940475f06acdb2 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 25 Mar 2006 12:57:37 +0000 Subject: Some cleanups/fixes for various TRACE statements --HG-- extra : convert_revision : 84eb6fedc6df0666f8053b9018bf16635dbfb257 --- cli-auth.c | 2 +- cli-chansession.c | 4 ++-- common-channel.c | 2 +- svr-auth.c | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) (limited to 'common-channel.c') diff --git a/cli-auth.c b/cli-auth.c index d08de9a..ba4cf6c 100644 --- a/cli-auth.c +++ b/cli-auth.c @@ -236,8 +236,8 @@ void recv_msg_userauth_success() { void cli_auth_try() { - TRACE(("enter cli_auth_try")) int finished = 0; + TRACE(("enter cli_auth_try")) CHECKCLEARTOWRITE(); diff --git a/cli-chansession.c b/cli-chansession.c index 6d358b7..1dad607 100644 --- a/cli-chansession.c +++ b/cli-chansession.c @@ -162,14 +162,14 @@ void cli_tty_cleanup() { static void put_termcodes() { - TRACE(("enter put_termcodes")) - struct termios tio; unsigned int sshcode; const struct TermCode *termcode; unsigned int value; unsigned int mapcode; + TRACE(("enter put_termcodes")) + unsigned int bufpos1, bufpos2; if (tcgetattr(STDIN_FILENO, &tio) == -1) { diff --git a/common-channel.c b/common-channel.c index 68d2b48..0be354d 100644 --- a/common-channel.c +++ b/common-channel.c @@ -236,7 +236,7 @@ static void checkclose(struct Channel *channel) { TRACE(("checkclose: writefd %d, readfd %d, errfd %d, sentclosed %d, recvclosed %d", channel->writefd, channel->readfd, channel->errfd, channel->sentclosed, channel->recvclosed)) - TRACE(("writebuf %d extrabuf %s extrabuf %d", + TRACE(("writebuf size %d extrabuf ptr 0x%x extrabuf size %d", cbuf_getused(channel->writebuf), channel->writebuf, channel->writebuf ? 0 : cbuf_getused(channel->extrabuf))) diff --git a/svr-auth.c b/svr-auth.c index f0fca38..d0eba9b 100644 --- a/svr-auth.c +++ b/svr-auth.c @@ -315,14 +315,15 @@ void send_msg_userauth_failure(int partial, int incrfail) { buf_setpos(typebuf, 0); buf_putstring(ses.writepayload, buf_getptr(typebuf, typebuf->len), typebuf->len); + + TRACE(("auth fail: methods %d, '%s'", ses.authstate.authtypes, + buf_getptr(typebuf, typebuf->len))); + buf_free(typebuf); buf_putbyte(ses.writepayload, partial ? 1 : 0); encrypt_packet(); - TRACE(("auth fail: methods %d, '%s'", ses.authstate.authtypes, - buf_getptr(typebuf, typebuf->len))); - if (incrfail) { usleep(300000); /* XXX improve this */ ses.authstate.failcount++; -- cgit v1.2.3 From e8fa3ce478681a356d2882e29550a6a63fed7b31 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sun, 11 Jun 2006 16:19:32 +0000 Subject: progress towards exiting on writefd closure rather than on process exit - dbclient hangs with scp, so requires work. --HG-- extra : convert_revision : 2186a678a5f79ef432f6593a10e3e13df2a313d5 --- common-channel.c | 52 ++++++++++++++++++++++++++++------------------------ svr-chansession.c | 3 +-- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'common-channel.c') diff --git a/common-channel.c b/common-channel.c index 5765f07..0cd6ef8 100644 --- a/common-channel.c +++ b/common-channel.c @@ -181,6 +181,7 @@ void channelio(fd_set *readfds, fd_set *writefds) { struct Channel *channel; unsigned int i; + int ret; /* iterate through all the possible channels */ for (i = 0; i < ses.chansize; i++) { @@ -204,7 +205,8 @@ void channelio(fd_set *readfds, fd_set *writefds) { /* if we can read from the writefd, it might be closed, so we try to * see if it has errors */ - if (channel->writefd >= 0 && channel->writefd != channel->readfd + if (IS_DROPBEAR_SERVER && channel->writefd >= 0 + && channel->writefd != channel->readfd && FD_ISSET(channel->writefd, readfds)) { if (channel->initconn) { /* Handling for "in progress" connection - this is needed @@ -259,27 +261,27 @@ static void checkclose(struct Channel *channel) { channel->writebuf, channel->writebuf ? 0 : cbuf_getused(channel->extrabuf))) - if (!channel->sentclosed) { - - /* check for exited - currently only used for server sessions, - * if the shell has exited etc */ - if (channel->type->checkclose) { - if (channel->type->checkclose(channel)) { - closewritefd(channel); - } + /* server chansession channels are special, since readfd mightn't + * close in the case of "sleep 4 & echo blah" until the sleep is up */ + if (channel->type->checkclose) { + if (channel->type->checkclose(channel)) { + closewritefd(channel); + closereadfd(channel, channel->readfd); + closereadfd(channel, channel->errfd); } + } - if (!channel->senteof - && channel->readfd == FD_CLOSED - && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { - send_msg_channel_eof(channel); - } + if (!channel->senteof + && channel->readfd == FD_CLOSED + && (channel->extrabuf == NULL || channel->errfd == FD_CLOSED)) { + send_msg_channel_eof(channel); + } - if (channel->writefd == FD_CLOSED - && channel->readfd == FD_CLOSED - && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { - send_msg_channel_close(channel); - } + if (!channel->sentclosed + && channel->writefd == FD_CLOSED + && channel->readfd == FD_CLOSED + && (channel->extrabuf == NULL || channel->errfd == FD_CLOSED)) { + send_msg_channel_close(channel); } /* When either party wishes to terminate the channel, it sends @@ -444,20 +446,22 @@ void setchannelfds(fd_set *readfds, fd_set *writefds) { } } - /* For checking FD status (ie closure etc) - we don't actually - * read data from writefd */ TRACE(("writefd = %d, readfd %d, errfd %d, bufused %d", channel->writefd, channel->readfd, channel->errfd, cbuf_getused(channel->writebuf) )) - if (channel->writefd >= 0 && channel->writefd != channel->readfd) { + + /* For checking FD status (ie closure etc) - we don't actually + * read data from writefd. We don't want to do this for the client, + * since redirection to /dev/null will make it spin in the select */ + if (IS_DROPBEAR_SERVER && channel->writefd >= 0 + && channel->writefd != channel->readfd) { FD_SET(channel->writefd, readfds); } - /* Stuff from the wire, to local program/shell/user etc */ + /* Stuff from the wire */ if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 ) || channel->initconn) { - FD_SET(channel->writefd, writefds); } diff --git a/svr-chansession.c b/svr-chansession.c index 605bb60..fed8240 100644 --- a/svr-chansession.c +++ b/svr-chansession.c @@ -67,8 +67,7 @@ static void get_termmodes(struct ChanSess *chansess); extern char** environ; static int sesscheckclose(struct Channel *channel) { - struct ChanSess *chansess = (struct ChanSess*)channel->typedata; - return chansess->exit.exitpid >= 0; + return channel->writefd == -1; } /* Handler for childs exiting, store the state for return to the client */ -- cgit v1.2.3 From 5092e30605dfc5c45990d91cf606990e5c768255 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 3 Feb 2007 08:09:55 +0000 Subject: disapproval of revision '2186a678a5f79ef432f6593a10e3e13df2a313d5' --HG-- extra : convert_revision : 1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c --- common-channel.c | 52 ++++++++++++++++++++++++---------------------------- svr-chansession.c | 3 ++- 2 files changed, 26 insertions(+), 29 deletions(-) (limited to 'common-channel.c') diff --git a/common-channel.c b/common-channel.c index 0cd6ef8..5765f07 100644 --- a/common-channel.c +++ b/common-channel.c @@ -181,7 +181,6 @@ void channelio(fd_set *readfds, fd_set *writefds) { struct Channel *channel; unsigned int i; - int ret; /* iterate through all the possible channels */ for (i = 0; i < ses.chansize; i++) { @@ -205,8 +204,7 @@ void channelio(fd_set *readfds, fd_set *writefds) { /* if we can read from the writefd, it might be closed, so we try to * see if it has errors */ - if (IS_DROPBEAR_SERVER && channel->writefd >= 0 - && channel->writefd != channel->readfd + if (channel->writefd >= 0 && channel->writefd != channel->readfd && FD_ISSET(channel->writefd, readfds)) { if (channel->initconn) { /* Handling for "in progress" connection - this is needed @@ -261,27 +259,27 @@ static void checkclose(struct Channel *channel) { channel->writebuf, channel->writebuf ? 0 : cbuf_getused(channel->extrabuf))) - /* server chansession channels are special, since readfd mightn't - * close in the case of "sleep 4 & echo blah" until the sleep is up */ - if (channel->type->checkclose) { - if (channel->type->checkclose(channel)) { - closewritefd(channel); - closereadfd(channel, channel->readfd); - closereadfd(channel, channel->errfd); + if (!channel->sentclosed) { + + /* check for exited - currently only used for server sessions, + * if the shell has exited etc */ + if (channel->type->checkclose) { + if (channel->type->checkclose(channel)) { + closewritefd(channel); + } } - } - if (!channel->senteof - && channel->readfd == FD_CLOSED - && (channel->extrabuf == NULL || channel->errfd == FD_CLOSED)) { - send_msg_channel_eof(channel); - } + if (!channel->senteof + && channel->readfd == FD_CLOSED + && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { + send_msg_channel_eof(channel); + } - if (!channel->sentclosed - && channel->writefd == FD_CLOSED - && channel->readfd == FD_CLOSED - && (channel->extrabuf == NULL || channel->errfd == FD_CLOSED)) { - send_msg_channel_close(channel); + if (channel->writefd == FD_CLOSED + && channel->readfd == FD_CLOSED + && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { + send_msg_channel_close(channel); + } } /* When either party wishes to terminate the channel, it sends @@ -446,22 +444,20 @@ void setchannelfds(fd_set *readfds, fd_set *writefds) { } } + /* For checking FD status (ie closure etc) - we don't actually + * read data from writefd */ TRACE(("writefd = %d, readfd %d, errfd %d, bufused %d", channel->writefd, channel->readfd, channel->errfd, cbuf_getused(channel->writebuf) )) - - /* For checking FD status (ie closure etc) - we don't actually - * read data from writefd. We don't want to do this for the client, - * since redirection to /dev/null will make it spin in the select */ - if (IS_DROPBEAR_SERVER && channel->writefd >= 0 - && channel->writefd != channel->readfd) { + if (channel->writefd >= 0 && channel->writefd != channel->readfd) { FD_SET(channel->writefd, readfds); } - /* Stuff from the wire */ + /* Stuff from the wire, to local program/shell/user etc */ if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 ) || channel->initconn) { + FD_SET(channel->writefd, writefds); } diff --git a/svr-chansession.c b/svr-chansession.c index fed8240..605bb60 100644 --- a/svr-chansession.c +++ b/svr-chansession.c @@ -67,7 +67,8 @@ static void get_termmodes(struct ChanSess *chansess); extern char** environ; static int sesscheckclose(struct Channel *channel) { - return channel->writefd == -1; + struct ChanSess *chansess = (struct ChanSess*)channel->typedata; + return chansess->exit.exitpid >= 0; } /* Handler for childs exiting, store the state for return to the client */ -- cgit v1.2.3