From be2b7d9725f8adef1b75bddc9944f69b87219120 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Wed, 7 Jun 2006 15:01:20 +0000
Subject: [PATCH] Add -N "no remote command" dbclient option. Document -N in
 dbclient.1 and -P in dropbear.8

--HG--
extra : convert_revision : 7cada79bf8f61e09a72e5d492170bd10ab0acee3
---
 cli-runopts.c | 5 +++++
 cli-session.c | 8 +++++---
 dbclient.1    | 3 +++
 dropbear.8    | 4 ++++
 dropbearkey.c | 3 +--
 runopts.h     | 1 +
 6 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/cli-runopts.c b/cli-runopts.c
index 54d4875c..2e7c0aca 100644
--- a/cli-runopts.c
+++ b/cli-runopts.c
@@ -50,6 +50,7 @@ static void printhelp() {
 					"-l <username>\n"
 					"-t    Allocate a pty\n"
 					"-T    Don't allocate a pty\n"
+					"-N    Don't run a remote command\n"
 #ifdef ENABLE_CLI_PUBKEY_AUTH
 					"-i <identityfile>   (multiple allowed)\n"
 #endif
@@ -88,6 +89,7 @@ void cli_getopts(int argc, char ** argv) {
 	cli_opts.remoteport = NULL;
 	cli_opts.username = NULL;
 	cli_opts.cmd = NULL;
+	cli_opts.no_cmd = 0;
 	cli_opts.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */
 #ifdef ENABLE_CLI_PUBKEY_AUTH
 	cli_opts.privkeys = NULL;
@@ -163,6 +165,9 @@ void cli_getopts(int argc, char ** argv) {
 				case 'T': /* don't want a pty */
 					cli_opts.wantpty = 0;
 					break;
+				case 'N':
+					cli_opts.no_cmd = 1;
+					break;
 #ifdef ENABLE_CLI_LOCALTCPFWD
 				case 'L':
 					nextislocal = 1;
diff --git a/cli-session.c b/cli-session.c
index 35510fa9..c47bd3bc 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();
 			}
 
diff --git a/dbclient.1 b/dbclient.1
index 4d7cc3c3..27e2d201 100644
--- a/dbclient.1
+++ b/dbclient.1
@@ -60,6 +60,9 @@ Allocate a pty.
 .B \-T
 Don't allocate a pty.
 .TP
+.B \-N
+Don't request a remote shell or run any commands. Any command arguments are ignored.
+.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/dropbear.8 b/dropbear.8
index 38cf7e22..fbbb26bf 100644
--- a/dropbear.8
+++ b/dropbear.8
@@ -72,6 +72,10 @@ Use this option to run
 under TCP/IP servers like inetd, tcpsvd, or tcpserver.
 In program mode the \-F option is implied, and \-p options are ignored.
 .TP
+.B \-P \fIpidfile
+Specify a pidfile to create when running as a daemon. If not specified, the 
+default is /var/run/dropbear.pid
+.TP
 .B \-a
 Allow remote hosts to connect to forwarded ports.
 .SH AUTHOR
diff --git a/dropbearkey.c b/dropbearkey.c
index 08250530..280e1b34 100644
--- a/dropbearkey.c
+++ b/dropbearkey.c
@@ -321,8 +321,7 @@ static void printpubkey(sign_key * key, int keytype) {
 	/* a user@host comment is informative */
 	username = "";
 	pw = getpwuid(getuid());
-	if (pw)
-	{
+	if (pw) {
 		username = pw->pw_name;
 	}
 
diff --git a/runopts.h b/runopts.h
index 1e102e67..cb5e4ca8 100644
--- a/runopts.h
+++ b/runopts.h
@@ -102,6 +102,7 @@ typedef struct cli_runopts {
 
 	char *cmd;
 	int wantpty;
+	int no_cmd;
 #ifdef ENABLE_CLI_PUBKEY_AUTH
 	struct SignKeyList *privkeys; /* Keys to use for public-key auth */
 #endif
-- 
GitLab