mirror of
https://github.com/clearml/dropbear
synced 2025-04-10 15:35:41 +00:00
add -f background option to dbclient
--HG-- extra : convert_revision : 5ef61c30c0a634ac0da22a8c694ce235690e8170
This commit is contained in:
parent
be2b7d9725
commit
c81e058bb0
@ -51,6 +51,7 @@ static void printhelp() {
|
|||||||
"-t Allocate a pty\n"
|
"-t Allocate a pty\n"
|
||||||
"-T Don't allocate a pty\n"
|
"-T Don't allocate a pty\n"
|
||||||
"-N Don't run a remote command\n"
|
"-N Don't run a remote command\n"
|
||||||
|
"-f Run in background after auth\n"
|
||||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||||
"-i <identityfile> (multiple allowed)\n"
|
"-i <identityfile> (multiple allowed)\n"
|
||||||
#endif
|
#endif
|
||||||
@ -90,6 +91,7 @@ void cli_getopts(int argc, char ** argv) {
|
|||||||
cli_opts.username = NULL;
|
cli_opts.username = NULL;
|
||||||
cli_opts.cmd = NULL;
|
cli_opts.cmd = NULL;
|
||||||
cli_opts.no_cmd = 0;
|
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.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */
|
||||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||||
cli_opts.privkeys = NULL;
|
cli_opts.privkeys = NULL;
|
||||||
@ -168,6 +170,9 @@ void cli_getopts(int argc, char ** argv) {
|
|||||||
case 'N':
|
case 'N':
|
||||||
cli_opts.no_cmd = 1;
|
cli_opts.no_cmd = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
cli_opts.backgrounded = 1;
|
||||||
|
break;
|
||||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||||
case 'L':
|
case 'L':
|
||||||
nextislocal = 1;
|
nextislocal = 1;
|
||||||
@ -274,6 +279,11 @@ void cli_getopts(int argc, char ** argv) {
|
|||||||
cli_opts.wantpty = 0;
|
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
|
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||||
|
@ -212,6 +212,23 @@ static void cli_sessionloop() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
case USERAUTH_SUCCESS_RCVD:
|
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
|
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||||
setup_localtcp();
|
setup_localtcp();
|
||||||
#endif
|
#endif
|
||||||
|
@ -63,6 +63,10 @@ Don't allocate a pty.
|
|||||||
.B \-N
|
.B \-N
|
||||||
Don't request a remote shell or run any commands. Any command arguments are ignored.
|
Don't request a remote shell or run any commands. Any command arguments are ignored.
|
||||||
.TP
|
.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
|
.B \-g
|
||||||
Allow non-local hosts to connect to forwarded ports. Applies to -L and -R
|
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
|
forwarded ports, though remote connections to -R forwarded ports may be limited
|
||||||
|
@ -103,6 +103,7 @@ typedef struct cli_runopts {
|
|||||||
char *cmd;
|
char *cmd;
|
||||||
int wantpty;
|
int wantpty;
|
||||||
int no_cmd;
|
int no_cmd;
|
||||||
|
int backgrounded;
|
||||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||||
struct SignKeyList *privkeys; /* Keys to use for public-key auth */
|
struct SignKeyList *privkeys; /* Keys to use for public-key auth */
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user