From be2b7d9725f8adef1b75bddc9944f69b87219120 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 7 Jun 2006 15:01:20 +0000 Subject: Add -N "no remote command" dbclient option. Document -N in dbclient.1 and -P in dropbear.8 --HG-- extra : convert_revision : 7cada79bf8f61e09a72e5d492170bd10ab0acee3 --- cli-session.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cli-session.c') diff --git a/cli-session.c b/cli-session.c index 35510fa..c47bd3b 100644 --- a/cli-session.c +++ b/cli-session.c @@ -218,13 +218,15 @@ static void cli_sessionloop() { #ifdef ENABLE_CLI_REMOTETCPFWD setup_remotetcp(); #endif - cli_send_chansess_request(); - TRACE(("leave cli_sessionloop: cli_send_chansess_request")) + if (!cli_opts.no_cmd) { + cli_send_chansess_request(); + } + TRACE(("leave cli_sessionloop: running")) cli_ses.state = SESSION_RUNNING; return; case SESSION_RUNNING: - if (ses.chancount < 1) { + if (ses.chancount < 1 && !cli_opts.no_cmd) { cli_finished(); } -- cgit v1.2.3 From c81e058bb05b274b9a88e684ffd95a03a0ac4377 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 7 Jun 2006 15:47:04 +0000 Subject: add -f background option to dbclient --HG-- extra : convert_revision : 5ef61c30c0a634ac0da22a8c694ce235690e8170 --- cli-runopts.c | 10 ++++++++++ cli-session.c | 17 +++++++++++++++++ dbclient.1 | 4 ++++ runopts.h | 1 + 4 files changed, 32 insertions(+) (limited to 'cli-session.c') diff --git a/cli-runopts.c b/cli-runopts.c index 2e7c0ac..a4a8a58 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -51,6 +51,7 @@ static void printhelp() { "-t Allocate a pty\n" "-T Don't allocate a pty\n" "-N Don't run a remote command\n" + "-f Run in background after auth\n" #ifdef ENABLE_CLI_PUBKEY_AUTH "-i (multiple allowed)\n" #endif @@ -90,6 +91,7 @@ void cli_getopts(int argc, char ** argv) { cli_opts.username = NULL; cli_opts.cmd = NULL; cli_opts.no_cmd = 0; + cli_opts.backgrounded = 0; cli_opts.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */ #ifdef ENABLE_CLI_PUBKEY_AUTH cli_opts.privkeys = NULL; @@ -168,6 +170,9 @@ void cli_getopts(int argc, char ** argv) { case 'N': cli_opts.no_cmd = 1; break; + case 'f': + cli_opts.backgrounded = 1; + break; #ifdef ENABLE_CLI_LOCALTCPFWD case 'L': nextislocal = 1; @@ -274,6 +279,11 @@ void cli_getopts(int argc, char ** argv) { cli_opts.wantpty = 0; } } + + if (cli_opts.backgrounded && cli_opts.cmd == NULL + && cli_opts.no_cmd == 0) { + dropbear_exit("command required for -f"); + } } #ifdef ENABLE_CLI_PUBKEY_AUTH diff --git a/cli-session.c b/cli-session.c index c47bd3b..be36bec 100644 --- a/cli-session.c +++ b/cli-session.c @@ -212,6 +212,23 @@ static void cli_sessionloop() { */ case USERAUTH_SUCCESS_RCVD: + + if (cli_opts.backgrounded) { + int devnull; + // keeping stdin open steals input from the terminal and + // is confusing, though stdout/stderr could be useful. + devnull = open(_PATH_DEVNULL, O_RDONLY); + if (devnull < 0) { + dropbear_exit("opening /dev/null: %d %s", + errno, strerror(errno)); + } + dup2(devnull, STDIN_FILENO); + if (daemon(0, 1) < 0) { + dropbear_exit("Backgrounding failed: %d %s", + errno, strerror(errno)); + } + } + #ifdef ENABLE_CLI_LOCALTCPFWD setup_localtcp(); #endif diff --git a/dbclient.1 b/dbclient.1 index 27e2d20..acff59d 100644 --- a/dbclient.1 +++ b/dbclient.1 @@ -63,6 +63,10 @@ Don't allocate a pty. .B \-N Don't request a remote shell or run any commands. Any command arguments are ignored. .TP +.B \-f +Fork into the background after authentication. A command argument (or -N) is required. +This is useful when using password authentication. +.TP .B \-g Allow non-local hosts to connect to forwarded ports. Applies to -L and -R forwarded ports, though remote connections to -R forwarded ports may be limited diff --git a/runopts.h b/runopts.h index cb5e4ca..c3db42c 100644 --- a/runopts.h +++ b/runopts.h @@ -103,6 +103,7 @@ typedef struct cli_runopts { char *cmd; int wantpty; int no_cmd; + int backgrounded; #ifdef ENABLE_CLI_PUBKEY_AUTH struct SignKeyList *privkeys; /* Keys to use for public-key auth */ #endif -- cgit v1.2.3 From 7f12251fbb2acefac04e13a7c6a95ca4dd4b5578 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Fri, 16 Feb 2007 14:42:08 +0000 Subject: Fix for -pedantic -ansi compilation, change // to /**/, plus some signedness and trailing-comma-in-array issues --HG-- extra : convert_revision : c22be8b8f570b48e9662dac32c7b3e7148a42206 --- cli-session.c | 4 ++-- common-channel.c | 4 ++-- dbutil.c | 8 ++++---- random.c | 2 +- session.h | 6 ++---- svr-main.c | 5 +++-- svr-session.c | 2 +- tcp-accept.c | 2 +- 8 files changed, 16 insertions(+), 17 deletions(-) (limited to 'cli-session.c') diff --git a/cli-session.c b/cli-session.c index be36bec..360187f 100644 --- a/cli-session.c +++ b/cli-session.c @@ -215,8 +215,8 @@ static void cli_sessionloop() { if (cli_opts.backgrounded) { int devnull; - // keeping stdin open steals input from the terminal and - // is confusing, though stdout/stderr could be useful. + /* keeping stdin open steals input from the terminal and + is confusing, though stdout/stderr could be useful. */ devnull = open(_PATH_DEVNULL, O_RDONLY); if (devnull < 0) { dropbear_exit("opening /dev/null: %d %s", diff --git a/common-channel.c b/common-channel.c index fdaeb24..34316b4 100644 --- a/common-channel.c +++ b/common-channel.c @@ -461,7 +461,7 @@ void setchannelfds(fd_set *readfds, fd_set *writefds) { FD_SET(channel->writefd, writefds); } - if (ERRFD_IS_WRITE(channel) != NULL && channel->errfd >= 0 + if (ERRFD_IS_WRITE(channel) && channel->errfd >= 0 && cbuf_getused(channel->extrabuf) > 0 ) { FD_SET(channel->errfd, writefds); } @@ -640,7 +640,7 @@ static void send_msg_channel_data(struct Channel *channel, int isextended) { /* If we receive less data than we requested when flushing, we've reached the equivalent of EOF */ - if (channel->flushing && len < maxlen) + if (channel->flushing && len < (ssize_t)maxlen) { TRACE(("closing from channel, flushing out.")) close_chan_fd(channel, fd, SHUT_RD); diff --git a/dbutil.c b/dbutil.c index 4559ba9..0967ddc 100644 --- a/dbutil.c +++ b/dbutil.c @@ -199,10 +199,10 @@ int dropbear_listen(const char* address, const char* port, hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */ hints.ai_socktype = SOCK_STREAM; - // for calling getaddrinfo: - // address == NULL and !AI_PASSIVE: local loopback - // address == NULL and AI_PASSIVE: all interfaces - // address != NULL: whatever the address says + /* for calling getaddrinfo: + address == NULL and !AI_PASSIVE: local loopback + address == NULL and AI_PASSIVE: all interfaces + address != NULL: whatever the address says */ if (!address) { TRACE(("dropbear_listen: local loopback")) } else { diff --git a/random.c b/random.c index 36fedff..f1475ed 100644 --- a/random.c +++ b/random.c @@ -214,7 +214,7 @@ void gen_random_mpint(mp_int *max, mp_int *rand) { unsigned char *randbuf = NULL; unsigned int len = 0; - const char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; + const unsigned char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; const int size_bits = mp_count_bits(max); diff --git a/session.h b/session.h index 78e3e57..559fe29 100644 --- a/session.h +++ b/session.h @@ -190,8 +190,7 @@ typedef enum { KEX_NOTHING, KEXINIT_RCVD, KEXDH_INIT_SENT, - KEXDONE, - + KEXDONE } cli_kex_state; typedef enum { @@ -203,8 +202,7 @@ typedef enum { USERAUTH_REQ_SENT, USERAUTH_FAIL_RCVD, USERAUTH_SUCCESS_RCVD, - SESSION_RUNNING, - + SESSION_RUNNING } cli_state; struct clientsession { diff --git a/svr-main.c b/svr-main.c index ddf5445..616ddaf 100644 --- a/svr-main.c +++ b/svr-main.c @@ -125,8 +125,9 @@ void main_noinetd() { int childsock; int childpipe[2]; - // Note: commonsetup() must happen before we daemon()ise. Otherwise - // daemon() will chdir("/"), and we won't be able to find local-dir hostkeys. + /* Note: commonsetup() must happen before we daemon()ise. Otherwise + daemon() will chdir("/"), and we won't be able to find local-dir + hostkeys. */ commonsetup(); /* fork */ diff --git a/svr-session.c b/svr-session.c index fe78bcc..3701597 100644 --- a/svr-session.c +++ b/svr-session.c @@ -188,7 +188,7 @@ void svr_dropbear_log(int priority, const char* format, va_list param) { || strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S", localtime(×ec)) == 0) { - // upon failure, just print the epoch-seconds time. + /* upon failure, just print the epoch-seconds time. */ snprintf(datestr, sizeof(datestr), "%d", timesec); } fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf); diff --git a/tcp-accept.c b/tcp-accept.c index 14a6312..7457c9b 100644 --- a/tcp-accept.c +++ b/tcp-accept.c @@ -104,7 +104,7 @@ int listen_tcpfwd(struct TCPListener* tcpinfo) { struct Listener *listener = NULL; int nsocks; char* errstring = NULL; - // listen_spec = NULL indicates localhost + /* listen_spec = NULL indicates localhost */ const char* listen_spec = NULL; TRACE(("enter listen_tcpfwd")) -- cgit v1.2.3