From 2d963d87210c6a0c5eadfa5f02c808f6d983b47e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 7 Nov 2004 20:04:10 +1100 Subject: - djm@cvs.openbsd.org 2004/11/05 12:19:56 [sftp.c] command editing and history support via libedit; ok markus@ thanks to hshoexer@ and many testers on tech@ too --- sftp.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 9 deletions(-) (limited to 'sftp.c') diff --git a/sftp.c b/sftp.c index f01c9194c..2db394e23 100644 --- a/sftp.c +++ b/sftp.c @@ -16,7 +16,13 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.56 2004/07/11 17:48:47 deraadt Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.57 2004/11/05 12:19:56 djm Exp $"); + +#ifdef USE_LIBEDIT +#include +#else +typedef void EditLine; +#endif #include "buffer.h" #include "xmalloc.h" @@ -1206,6 +1212,14 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, return (0); } +#ifdef USE_LIBEDIT +static char * +prompt(EditLine *el) +{ + return ("sftp> "); +} +#endif + int interactive_loop(int fd_in, int fd_out, char *file1, char *file2) { @@ -1214,6 +1228,27 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) char cmd[2048]; struct sftp_conn *conn; int err; + EditLine *el = NULL; +#ifdef USE_LIBEDIT + History *hl = NULL; + HistEvent hev; + extern char *__progname; + + if (!batchmode && isatty(STDIN_FILENO)) { + if ((el = el_init(__progname, stdin, stdout, stderr)) == NULL) + fatal("Couldn't initialise editline"); + if ((hl = history_init()) == NULL) + fatal("Couldn't initialise editline history"); + history(hl, &hev, H_SETSIZE, 100); + el_set(el, EL_HIST, history, hl); + + el_set(el, EL_PROMPT, prompt); + el_set(el, EL_EDITOR, "emacs"); + el_set(el, EL_TERMINAL, NULL); + el_set(el, EL_SIGNAL, 1); + el_source(el, NULL); + } +#endif /* USE_LIBEDIT */ conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests); if (conn == NULL) @@ -1261,17 +1296,29 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) signal(SIGINT, SIG_IGN); - printf("sftp> "); + if (el == NULL) { + printf("sftp> "); + if (fgets(cmd, sizeof(cmd), infile) == NULL) { + printf("\n"); + break; + } + if (batchmode) /* Echo command */ + printf("%s", cmd); + } else { +#ifdef USE_LIBEDIT + const char *line; + int count = 0; - /* XXX: use libedit */ - if (fgets(cmd, sizeof(cmd), infile) == NULL) { - printf("\n"); - break; + if ((line = el_gets(el, &count)) == NULL || count <= 0) + break; + history(hl, &hev, H_ENTER, line); + if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { + fprintf(stderr, "Error: input line too long\n"); + continue; + } +#endif /* USE_LIBEDIT */ } - if (batchmode) /* Echo command */ - printf("%s", cmd); - cp = strrchr(cmd, '\n'); if (cp) *cp = '\0'; -- cgit v1.2.3 From cd516efea147ef64f0b3d0be3e3c94b450c11c24 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 6 Dec 2004 22:43:43 +1100 Subject: - (dtucker) OpenBSD CVS Sync - markus@cvs.openbsd.org 2004/11/25 22:22:14 [sftp-client.c sftp.c] leak; from mpech --- ChangeLog | 6 +++++- sftp-client.c | 4 +++- sftp.c | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'sftp.c') diff --git a/ChangeLog b/ChangeLog index 11f7bbd87..f80f685de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 20041206 - (dtucker) [TODO WARNING.RNG] Update to reflect current reality. ok djm@ + - (dtucker) OpenBSD CVS Sync + - markus@cvs.openbsd.org 2004/11/25 22:22:14 + [sftp-client.c sftp.c] + leak; from mpech 20041203 - (dtucker) OpenBSD CVS Sync @@ -1873,4 +1877,4 @@ - (djm) Trim deprecated options from INSTALL. Mention UsePAM - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu -$Id: ChangeLog,v 1.3585 2004/12/06 11:40:10 dtucker Exp $ +$Id: ChangeLog,v 1.3586 2004/12/06 11:43:43 dtucker Exp $ diff --git a/sftp-client.c b/sftp-client.c index 0ffacbccc..d894a11f2 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -20,7 +20,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.51 2004/07/11 17:48:47 deraadt Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.52 2004/11/25 22:22:14 markus Exp $"); #include "openbsd-compat/sys-queue.h" @@ -172,6 +172,7 @@ get_handle(int fd, u_int expected_id, u_int *len) int status = buffer_get_int(&msg); error("Couldn't get handle: %s", fx2txt(status)); + buffer_free(&msg); return(NULL); } else if (type != SSH2_FXP_HANDLE) fatal("Expected SSH2_FXP_HANDLE(%u) packet, got %u", @@ -206,6 +207,7 @@ get_decode_stat(int fd, u_int expected_id, int quiet) debug("Couldn't stat remote file: %s", fx2txt(status)); else error("Couldn't stat remote file: %s", fx2txt(status)); + buffer_free(&msg); return(NULL); } else if (type != SSH2_FXP_ATTRS) { fatal("Expected SSH2_FXP_ATTRS(%u) packet, got %u", diff --git a/sftp.c b/sftp.c index 2db394e23..b37c36b71 100644 --- a/sftp.c +++ b/sftp.c @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.57 2004/11/05 12:19:56 djm Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.58 2004/11/25 22:22:14 markus Exp $"); #ifdef USE_LIBEDIT #include @@ -1265,8 +1265,11 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2) if (remote_is_dir(conn, dir) && file2 == NULL) { printf("Changing to: %s\n", dir); snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); - if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) + if (parse_dispatch_command(conn, cmd, &pwd, 1) != 0) { + xfree(dir); + xfree(pwd); return (-1); + } } else { if (file2 == NULL) snprintf(cmd, sizeof cmd, "get %s", dir); -- cgit v1.2.3 From e2f189a841c9beecae75a2df3784d73f9e6dd762 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 6 Dec 2004 22:45:53 +1100 Subject: - djm@cvs.openbsd.org 2004/11/29 07:41:24 [sftp-client.h sftp.c] Some small fixes from moritz@jodeit.org. ok deraadt@ --- ChangeLog | 5 ++++- sftp-client.h | 6 +++--- sftp.c | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'sftp.c') diff --git a/ChangeLog b/ChangeLog index 3a925d505..520b9b485 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,9 @@ - jmc@cvs.openbsd.org 2004/11/29 00:05:17 [sftp.1] missing full stop; + - djm@cvs.openbsd.org 2004/11/29 07:41:24 + [sftp-client.h sftp.c] + Some small fixes from moritz@jodeit.org. ok deraadt@ 20041203 - (dtucker) OpenBSD CVS Sync @@ -1880,4 +1883,4 @@ - (djm) Trim deprecated options from INSTALL. Mention UsePAM - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu -$Id: ChangeLog,v 1.3587 2004/12/06 11:44:32 dtucker Exp $ +$Id: ChangeLog,v 1.3588 2004/12/06 11:45:53 dtucker Exp $ diff --git a/sftp-client.h b/sftp-client.h index a0e8e44b3..991e05d33 100644 --- a/sftp-client.h +++ b/sftp-client.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sftp-client.h,v 1.12 2004/02/17 05:39:51 djm Exp $ */ +/* $OpenBSD: sftp-client.h,v 1.13 2004/11/29 07:41:24 djm Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller @@ -30,8 +30,8 @@ struct SFTP_DIRENT { }; /* - * Initialiase a SSH filexfer connection. Returns -1 on error or - * protocol version on success. + * Initialiase a SSH filexfer connection. Returns NULL on error or + * a pointer to a initialized sftp_conn struct on success. */ struct sftp_conn *do_init(int, int, u_int, u_int); diff --git a/sftp.c b/sftp.c index b37c36b71..2c7b546f7 100644 --- a/sftp.c +++ b/sftp.c @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.58 2004/11/25 22:22:14 markus Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.59 2004/11/29 07:41:24 djm Exp $"); #ifdef USE_LIBEDIT #include @@ -160,9 +160,11 @@ static void cmd_interrupt(int signo) { const char msg[] = "\rInterrupt \n"; + int olderrno = errno; write(STDERR_FILENO, msg, sizeof(msg) - 1); interrupted = 1; + errno = olderrno; } static void @@ -262,7 +264,7 @@ path_strip(char *path, char *strip) return (xstrdup(path)); len = strlen(strip); - if (strip != NULL && strncmp(path, strip, len) == 0) { + if (strncmp(path, strip, len) == 0) { if (strip[len - 1] != '/' && path[len] == '/') len++; return (xstrdup(path + len)); -- cgit v1.2.3 From 596dcfa21fba253b25020be8578efb6a1a1e30d2 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 11 Dec 2004 13:37:22 +1100 Subject: - fgsch@cvs.openbsd.org 2004/12/10 03:10:42 [sftp.c] - fix globbed ls for paths the same lenght as the globbed path when we have a unique matching. - fix globbed ls in case of a directory when we have a unique matching. - as a side effect, if the path does not exist error (used to silently ignore). - don't do extra do_lstat() if we only have one matching file. djm@ ok --- ChangeLog | 11 ++++++++++- sftp.c | 27 ++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'sftp.c') diff --git a/ChangeLog b/ChangeLog index 49b1472bc..8c4cca4ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,15 @@ - markus@cvs.openbsd.org 2004/12/06 16:00:43 [bufaux.c] use 0x00 not \0 since buf[] is a bignum + - fgsch@cvs.openbsd.org 2004/12/10 03:10:42 + [sftp.c] + - fix globbed ls for paths the same lenght as the globbed path when + we have a unique matching. + - fix globbed ls in case of a directory when we have a unique matching. + - as a side effect, if the path does not exist error (used to silently + ignore). + - don't do extra do_lstat() if we only have one matching file. + djm@ ok 20041208 - (tim) [configure.ac] Comment some non obvious platforms in the @@ -1933,4 +1942,4 @@ - (djm) Trim deprecated options from INSTALL. Mention UsePAM - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu -$Id: ChangeLog,v 1.3601 2004/12/11 02:34:56 dtucker Exp $ +$Id: ChangeLog,v 1.3602 2004/12/11 02:37:22 dtucker Exp $ diff --git a/sftp.c b/sftp.c index 2c7b546f7..9e29cb02e 100644 --- a/sftp.c +++ b/sftp.c @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.59 2004/11/29 07:41:24 djm Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.60 2004/12/10 03:10:42 fgsch Exp $"); #ifdef USE_LIBEDIT #include @@ -746,12 +746,14 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, { glob_t g; int i, c = 1, colspace = 0, columns = 1; - Attrib *a; + Attrib *a = NULL; memset(&g, 0, sizeof(g)); if (remote_glob(conn, path, GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE, - NULL, &g)) { + NULL, &g) || (g.gl_pathc && !g.gl_matchc)) { + if (g.gl_pathc) + globfree(&g); error("Can't ls: \"%s\" not found", path); return (-1); } @@ -760,19 +762,21 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, goto out; /* - * If the glob returns a single match, which is the same as the - * input glob, and it is a directory, then just list its contents + * If the glob returns a single match and it is a directory, + * then just list its contents. */ - if (g.gl_pathc == 1 && - strncmp(path, g.gl_pathv[0], strlen(g.gl_pathv[0]) - 1) == 0) { - if ((a = do_lstat(conn, path, 1)) == NULL) { + if (g.gl_matchc == 1) { + if ((a = do_lstat(conn, g.gl_pathv[0], 1)) == NULL) { globfree(&g); return (-1); } if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && S_ISDIR(a->perm)) { + int err; + + err = do_ls_dir(conn, g.gl_pathv[0], strip_path, lflag); globfree(&g); - return (do_ls_dir(conn, path, strip_path, lflag)); + return (err); } } @@ -792,7 +796,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, colspace = width / columns; } - for (i = 0; g.gl_pathv[i] && !interrupted; i++) { + for (i = 0; g.gl_pathv[i] && !interrupted; i++, a = NULL) { char *fname; fname = path_strip(g.gl_pathv[i], strip_path); @@ -809,7 +813,8 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, * that the server returns as well as the filenames. */ memset(&sb, 0, sizeof(sb)); - a = do_lstat(conn, g.gl_pathv[i], 1); + if (a == NULL) + a = do_lstat(conn, g.gl_pathv[i], 1); if (a != NULL) attrib_to_stat(a, &sb); lname = ls_file(fname, &sb, 1); -- cgit v1.2.3 From ba66df81a38c42c9e7419d1a564be9ae17b62268 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 24 Jan 2005 21:57:40 +1100 Subject: - dtucker@cvs.openbsd.org 2005/01/24 10:22:06 [scp.c sftp.c] Have scp and sftp wait for the spawned ssh to exit before they exit themselves. This prevents ssh from being unable to restore terminal modes (not normally a problem on OpenBSD but common with -Portable on POSIX platforms). From peak at argo.troja.mff.cuni.cz (bz#950); ok djm@ markus@ --- ChangeLog | 9 ++++++++- scp.c | 6 ++++-- sftp.c | 6 ++++-- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'sftp.c') diff --git a/ChangeLog b/ChangeLog index d271cf5e5..5e77d1e9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,13 @@ - djm@cvs.openbsd.org 2005/01/23 10:18:12 [cipher.c] config option "Ciphers" should be case-sensitive; ok dtucker@ + - dtucker@cvs.openbsd.org 2005/01/24 10:22:06 + [scp.c sftp.c] + Have scp and sftp wait for the spawned ssh to exit before they exit + themselves. This prevents ssh from being unable to restore terminal + modes (not normally a problem on OpenBSD but common with -Portable + on POSIX platforms). From peak at argo.troja.mff.cuni.cz (bz#950); + ok djm@ markus@ 20050120 - (dtucker) OpenBSD CVS Sync @@ -2030,4 +2037,4 @@ - (djm) Trim deprecated options from INSTALL. Mention UsePAM - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu -$Id: ChangeLog,v 1.3623 2005/01/24 10:57:11 dtucker Exp $ +$Id: ChangeLog,v 1.3624 2005/01/24 10:57:40 dtucker Exp $ diff --git a/scp.c b/scp.c index 69b5fc6d3..f69fd05fc 100644 --- a/scp.c +++ b/scp.c @@ -71,7 +71,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: scp.c,v 1.118 2004/09/15 18:46:04 deraadt Exp $"); +RCSID("$OpenBSD: scp.c,v 1.119 2005/01/24 10:22:06 dtucker Exp $"); #include "xmalloc.h" #include "atomicio.h" @@ -108,8 +108,10 @@ pid_t do_cmd_pid = -1; static void killchild(int signo) { - if (do_cmd_pid > 1) + if (do_cmd_pid > 1) { kill(do_cmd_pid, signo); + waitpid(do_cmd_pid, NULL, 0); + } _exit(1); } diff --git a/sftp.c b/sftp.c index 9e29cb02e..31c634994 100644 --- a/sftp.c +++ b/sftp.c @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.60 2004/12/10 03:10:42 fgsch Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.61 2005/01/24 10:22:06 dtucker Exp $"); #ifdef USE_LIBEDIT #include @@ -150,8 +150,10 @@ int interactive_loop(int fd_in, int fd_out, char *file1, char *file2); static void killchild(int signo) { - if (sshpid > 1) + if (sshpid > 1) { kill(sshpid, SIGTERM); + waitpid(sshpid, NULL, 0); + } _exit(1); } -- cgit v1.2.3 From 64e8d44fbd556c7a78bba1d8ff3bee5b07b2440d Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 1 Mar 2005 21:16:47 +1100 Subject: - djm@cvs.openbsd.org 2005/02/20 22:59:06 [sftp.c] turn on ssh batch mode when in sftp batch mode, patch from jdmossh AT nand.net; ok markus@ --- ChangeLog | 7 ++++++- sftp.c | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'sftp.c') diff --git a/ChangeLog b/ChangeLog index 06b5d755b..67c993667 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,11 @@ - djm@cvs.openbsd.org 2005/02/18 03:05:53 [canohost.c] better error messages for getnameinfo failures; ok dtucker@ + - djm@cvs.openbsd.org 2005/02/20 22:59:06 + [sftp.c] + turn on ssh batch mode when in sftp batch mode, patch from + jdmossh AT nand.net; + ok markus@ 20050226 - (dtucker) [openbsd-compat/bsd-openpty.c openbsd-compat/inet_ntop.c] @@ -2182,4 +2187,4 @@ - (djm) Trim deprecated options from INSTALL. Mention UsePAM - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu -$Id: ChangeLog,v 1.3668 2005/03/01 10:16:18 djm Exp $ +$Id: ChangeLog,v 1.3669 2005/03/01 10:16:47 djm Exp $ diff --git a/sftp.c b/sftp.c index 31c634994..f8553ed82 100644 --- a/sftp.c +++ b/sftp.c @@ -16,7 +16,7 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.61 2005/01/24 10:22:06 dtucker Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.62 2005/02/20 22:59:06 djm Exp $"); #ifdef USE_LIBEDIT #include @@ -1479,6 +1479,7 @@ main(int argc, char **argv) fatal("%s (%s).", strerror(errno), optarg); showprogress = 0; batchmode = 1; + addargs(&args, "-obatchmode yes"); break; case 'P': sftp_direct = optarg; -- cgit v1.2.3