summaryrefslogtreecommitdiffhomepage
path: root/cli-runopts.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli-runopts.c')
-rw-r--r--cli-runopts.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/cli-runopts.c b/cli-runopts.c
index 54d4875..fc67850 100644
--- a/cli-runopts.c
+++ b/cli-runopts.c
@@ -44,12 +44,15 @@ static void addforward(char* str, struct TCPFwdList** fwdlist);
static void printhelp() {
fprintf(stderr, "Dropbear client v%s\n"
- "Usage: %s [options] [user@]host\n"
+ "Usage: %s [options] [user@]host [command]\n"
"Options are:\n"
"-p <remoteport>\n"
"-l <username>\n"
"-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"
+ "-y Always accept remote host key if unknown\n"
#ifdef ENABLE_CLI_PUBKEY_AUTH
"-i <identityfile> (multiple allowed)\n"
#endif
@@ -88,7 +91,10 @@ 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.backgrounded = 0;
cli_opts.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */
+ cli_opts.always_accept_key = 0;
#ifdef ENABLE_CLI_PUBKEY_AUTH
cli_opts.privkeys = NULL;
#endif
@@ -144,6 +150,9 @@ void cli_getopts(int argc, char ** argv) {
/* A flag *waves* */
switch (argv[i][1]) {
+ case 'y': /* always accept the remote hostkey */
+ cli_opts.always_accept_key = 1;
+ break;
case 'p': /* remoteport */
next = &cli_opts.remoteport;
break;
@@ -163,6 +172,12 @@ 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;
+ case 'f':
+ cli_opts.backgrounded = 1;
+ break;
#ifdef ENABLE_CLI_LOCALTCPFWD
case 'L':
nextislocal = 1;
@@ -269,6 +284,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
@@ -348,7 +368,8 @@ static void addforward(char* origstr, struct TCPFwdList** fwdlist) {
TRACE(("enter addforward"))
- /* We probably don't want to be editing argvs */
+ /* We need to split the original argument up. This var
+ is never free()d. */
str = m_strdup(origstr);
listenport = str;
@@ -358,8 +379,7 @@ static void addforward(char* origstr, struct TCPFwdList** fwdlist) {
TRACE(("connectaddr == NULL"))
goto fail;
}
-
- connectaddr[0] = '\0';
+ *connectaddr = '\0';
connectaddr++;
connectport = strchr(connectaddr, ':');
@@ -367,8 +387,7 @@ static void addforward(char* origstr, struct TCPFwdList** fwdlist) {
TRACE(("connectport == NULL"))
goto fail;
}
-
- connectport[0] = '\0';
+ *connectport = '\0';
connectport++;
newfwd = (struct TCPFwdList*)m_malloc(sizeof(struct TCPFwdList));