diff options
author | djm@openbsd.org@openbsd.org <djm@openbsd.org@openbsd.org> | 2017-11-03 04:46:52 +0100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2017-11-03 06:20:41 +0100 |
commit | fbe8e7ac94c2fa380421a9205a8bc966549c2f91 (patch) | |
tree | f4045b45c8dcb4bf33df5aa96bde3d5ced4cac4a /sftp.c | |
parent | upstream commit (diff) | |
download | openssh-fbe8e7ac94c2fa380421a9205a8bc966549c2f91.tar.xz openssh-fbe8e7ac94c2fa380421a9205a8bc966549c2f91.zip |
upstream commit
allow "cd" and "lcd" commands with no explicit path
argument. lcd will change to the local user's home directory as usual. cd
will change to the starting directory for session (because the protocol
offers no way to obtain the remote user's home directory). bz#2760 ok
dtucker@
OpenBSD-Commit-ID: 15333f5087cee8c1ed1330cac1bd0a3e6a767393
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: sftp.c,v 1.181 2017/10/21 23:06:24 millert Exp $ */ +/* $OpenBSD: sftp.c,v 1.182 2017/11/03 03:46:52 djm Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> * @@ -217,8 +217,6 @@ static const struct CMD cmds[] = { { NULL, -1, -1 } }; -int interactive_loop(struct sftp_conn *, char *file1, char *file2); - /* ARGSUSED */ static void killchild(int signo) @@ -1288,7 +1286,7 @@ parse_args(const char **cpp, int *ignore_errors, int *aflag, char *cp2, **argv; int base = 0; long l; - int i, cmdnum, optidx, argc; + int path1_mandatory = 0, i, cmdnum, optidx, argc; /* Skip leading whitespace */ cp = cp + strspn(cp, WHITESPACE); @@ -1378,13 +1376,17 @@ parse_args(const char **cpp, int *ignore_errors, int *aflag, case I_RM: case I_MKDIR: case I_RMDIR: + case I_LMKDIR: + path1_mandatory = 1; + /* FALLTHROUGH */ case I_CHDIR: case I_LCHDIR: - case I_LMKDIR: if ((optidx = parse_no_flags(cmd, argv, argc)) == -1) return -1; /* Get pathname (mandatory) */ if (argc - optidx < 1) { + if (!path1_mandatory) + break; /* return a NULL path1 */ error("You must specify a path after a %s command.", cmd); return -1; @@ -1469,7 +1471,7 @@ parse_args(const char **cpp, int *ignore_errors, int *aflag, static int parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, - int err_abort) + const char *startdir, int err_abort) { char *path1, *path2, *tmp; int ignore_errors = 0, aflag = 0, fflag = 0, hflag = 0, @@ -1549,6 +1551,8 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, err = do_rmdir(conn, path1); break; case I_CHDIR: + if (path1 == NULL || *path1 == '\0') + path1 = xstrdup(startdir); path1 = make_absolute(path1, *pwd); if ((tmp = do_realpath(conn, path1)) == NULL) { err = 1; @@ -1597,6 +1601,8 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, err = do_df(conn, path1, hflag, iflag); break; case I_LCHDIR: + if (path1 == NULL || *path1 == '\0') + path1 = xstrdup("~"); tmp = tilde_expand_filename(path1, getuid()); free(path1); path1 = tmp; @@ -2083,11 +2089,11 @@ complete(EditLine *el, int ch) } #endif /* USE_LIBEDIT */ -int +static int interactive_loop(struct sftp_conn *conn, char *file1, char *file2) { char *remote_path; - char *dir = NULL; + char *dir = NULL, *startdir = NULL; char cmd[2048]; int err, interactive; EditLine *el = NULL; @@ -2131,6 +2137,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) remote_path = do_realpath(conn, "."); if (remote_path == NULL) fatal("Need cwd"); + startdir = xstrdup(remote_path); if (file1 != NULL) { dir = xstrdup(file1); @@ -2141,8 +2148,9 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) mprintf("Changing to: %s\n", dir); snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); if (parse_dispatch_command(conn, cmd, - &remote_path, 1) != 0) { + &remote_path, startdir, 1) != 0) { free(dir); + free(startdir); free(remote_path); free(conn); return (-1); @@ -2154,8 +2162,9 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) file2 == NULL ? "" : " ", file2 == NULL ? "" : file2); err = parse_dispatch_command(conn, cmd, - &remote_path, 1); + &remote_path, startdir, 1); free(dir); + free(startdir); free(remote_path); free(conn); return (err); @@ -2214,11 +2223,12 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) signal(SIGINT, cmd_interrupt); err = parse_dispatch_command(conn, cmd, &remote_path, - batchmode); + startdir, batchmode); if (err != 0) break; } free(remote_path); + free(startdir); free(conn); #ifdef USE_LIBEDIT |