diff --git a/sesschan.c b/sesschan.c index 84007644..ecb34f4c 100644 --- a/sesschan.c +++ b/sesschan.c @@ -297,7 +297,8 @@ static void sesschan_start_backend(sesschan *sess, const char *cmd) sess->backend = pty_backend_create( &sess->seat, sess->child_logctx, sess->conf, NULL, cmd, - sess->ttymodes, !sess->want_pty, env_to_unset); + sess->ttymodes, !sess->want_pty, sess->ssc->session_starting_dir, + env_to_unset); backend_size(sess->backend, sess->wc, sess->hc); } diff --git a/sshserver.h b/sshserver.h index 1f0be6e7..bbdb8765 100644 --- a/sshserver.h +++ b/sshserver.h @@ -1,6 +1,8 @@ typedef struct AuthPolicy AuthPolicy; struct SshServerConfig { + const char *session_starting_dir; + RSAKey *rsa_kex_key; /* @@ -102,7 +104,7 @@ Channel *sesschan_new(SshChannel *c, LogContext *logctx, Backend *pty_backend_create( Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd, - struct ssh_ttymodes ttymodes, bool pipes_instead_of_pty, + struct ssh_ttymodes ttymodes, bool pipes_instead_of_pty, const char *dir, const char *const *env_vars_to_unset); int pty_backend_exit_signum(Backend *be); ptrlen pty_backend_exit_signame(Backend *be, char **aux_msg); diff --git a/unix/uxpty.c b/unix/uxpty.c index 437eba49..d3b64b68 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -857,7 +857,7 @@ static void copy_ttymodes_into_termios( */ Backend *pty_backend_create( Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd, - struct ssh_ttymodes ttymodes, bool pipes_instead, + struct ssh_ttymodes ttymodes, bool pipes_instead, const char *dir, const char *const *env_vars_to_unset) { int slavefd; @@ -1145,6 +1145,9 @@ Backend *pty_backend_create( } } + if (dir) + chdir(dir); + /* * SIGINT, SIGQUIT and SIGPIPE may have been set to ignored by * our parent, particularly by things like sh -c 'pterm &' and @@ -1274,7 +1277,7 @@ static const char *pty_init(Seat *seat, Backend **backend_handle, cmd = pty_argv[0]; *backend_handle= pty_backend_create( - seat, logctx, conf, pty_argv, cmd, modes, false, NULL); + seat, logctx, conf, pty_argv, cmd, modes, false, NULL, NULL); *realhost = dupstr(""); return NULL; } diff --git a/unix/uxserver.c b/unix/uxserver.c index 9f2dd9be..83e5f379 100644 --- a/unix/uxserver.c +++ b/unix/uxserver.c @@ -312,6 +312,7 @@ static void show_help(FILE *fp) "(in SSH-1 format)\n" " --userkey KEY public key" " acceptable for user authentication\n" + " --sessiondir DIR cwd for session subprocess (default $HOME)\n" " --bannertext TEXT send TEXT as SSH-2 auth banner\n" " --bannerfile FILE send contents of FILE as SSH-2 auth " "banner\n" @@ -527,6 +528,8 @@ int main(int argc, char **argv) memset(&ssc, 0, sizeof(ssc)); + ssc.session_starting_dir = getenv("HOME"); + if (argc <= 1) { /* * We're going to terminate with an error message below, @@ -710,6 +713,8 @@ int main(int argc, char **argv) ssc.banner = ptrlen_from_strbuf(sb); } else if (longoptarg(arg, "--bannertext", &val, &argc, &argv)) { ssc.banner = ptrlen_from_asciz(val); + } else if (longoptarg(arg, "--sessiondir", &val, &argc, &argv)) { + ssc.session_starting_dir = val; } else if (longoptarg(arg, "--kexinit-kex", &val, &argc, &argv)) { ssc.kex_override[KEXLIST_KEX] = ptrlen_from_asciz(val); } else if (longoptarg(arg, "--kexinit-hostkey", &val, &argc, &argv)) {