Bugzilla – Attachment 3200 Details for
Bug 2926
In batch mode sftp echoes the prompt and the commands back
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Allow @ and - to appear in any order
bz2926.diff (text/plain), 4.83 KB, created by
Damien Miller
on 2018-11-09 14:35:55 AEDT
(
hide
)
Description:
Allow @ and - to appear in any order
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2018-11-09 14:35:55 AEDT
Size:
4.83 KB
patch
obsolete
>diff --git a/sftp.1 b/sftp.1 >index 0fd54ca..091ef5e 100644 >--- a/sftp.1 >+++ b/sftp.1 >@@ -127,6 +127,7 @@ at connection time (see > and > .Xr ssh-keygen 1 > for details). >+.Pp > A > .Ar batchfile > of >@@ -141,11 +142,17 @@ commands fail: > .Ic chgrp , lpwd , df , symlink , > and > .Ic lmkdir . >+.Pp > Termination on error can be suppressed on a command by command basis by > prefixing the command with a > .Sq \- > character (for example, > .Ic -rm /tmp/blah* ) . >+Echo of the command may be suppressed by prefixing the command with a >+.Sq @ >+character. >+These two prefixes may be combined in any order, for example >+.Ic -@ls /bsd . > .It Fl C > Enables compression (via ssh's > .Fl C >diff --git a/sftp.c b/sftp.c >index 9f2c0a6..4f2020c 100644 >--- a/sftp.c >+++ b/sftp.c >@@ -1268,7 +1268,7 @@ makeargv(const char *arg, int *argcp, int sloppy, char *lastquote, > } > > static int >-parse_args(const char **cpp, int *ignore_errors, int *aflag, >+parse_args(const char **cpp, int *ignore_errors, int *disable_echo, int *aflag, > int *fflag, int *hflag, int *iflag, int *lflag, int *pflag, > int *rflag, int *sflag, > unsigned long *n_arg, char **path1, char **path2) >@@ -1282,13 +1282,23 @@ parse_args(const char **cpp, int *ignore_errors, int *aflag, > /* Skip leading whitespace */ > cp = cp + strspn(cp, WHITESPACE); > >- /* Check for leading '-' (disable error processing) */ >+ /* >+ * Check for leading '-' (disable error processing) and '@' (suppress >+ * command echo) >+ */ > *ignore_errors = 0; >- if (*cp == '-') { >- *ignore_errors = 1; >- cp++; >- cp = cp + strspn(cp, WHITESPACE); >+ *disable_echo = 0; >+ for (;*cp != '\0'; cp++) { >+ if (*cp == '-') { >+ *ignore_errors = 1; >+ } else if (*cp == '@') { >+ *disable_echo = 1; >+ } else { >+ /* all other characters terminate prefix processing */ >+ break; >+ } > } >+ cp = cp + strspn(cp, WHITESPACE); > > /* Ignore blank lines and lines which begin with comment '#' char */ > if (*cp == '\0' || *cp == '#') >@@ -1463,11 +1473,12 @@ parse_args(const char **cpp, int *ignore_errors, int *aflag, > > static int > parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, >- const char *startdir, int err_abort) >+ const char *startdir, int err_abort, int echo_command) > { >+ const char *ocmd = cmd; > char *path1, *path2, *tmp; >- int ignore_errors = 0, aflag = 0, fflag = 0, hflag = 0, >- iflag = 0; >+ int ignore_errors = 0, disable_echo = 1; >+ int aflag = 0, fflag = 0, hflag = 0, iflag = 0; > int lflag = 0, pflag = 0, rflag = 0, sflag = 0; > int cmdnum, i; > unsigned long n_arg = 0; >@@ -1477,11 +1488,15 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, > glob_t g; > > path1 = path2 = NULL; >- cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag, >- &iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2); >+ cmdnum = parse_args(&cmd, &ignore_errors, &disable_echo, &aflag, &fflag, >+ &hflag, &iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, >+ &path1, &path2); > if (ignore_errors != 0) > err_abort = 0; > >+ if (echo_command && !disable_echo) >+ mprintf("sftp> %s\n", ocmd); >+ > memset(&g, 0, sizeof(g)); > > /* Perform command */ >@@ -2137,7 +2152,7 @@ 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, startdir, 1) != 0) { >+ &remote_path, startdir, 1, 0) != 0) { > free(dir); > free(startdir); > free(remote_path); >@@ -2151,7 +2166,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) > file2 == NULL ? "" : " ", > file2 == NULL ? "" : file2); > err = parse_dispatch_command(conn, cmd, >- &remote_path, startdir, 1); >+ &remote_path, startdir, 1, 0); > free(dir); > free(startdir); > free(remote_path); >@@ -2167,7 +2182,6 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) > interactive = !batchmode && isatty(STDIN_FILENO); > err = 0; > for (;;) { >- char *cp; > const char *line; > int count = 0; > >@@ -2181,12 +2195,6 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) > printf("\n"); > break; > } >- if (!interactive) { /* Echo command */ >- mprintf("sftp> %s", cmd); >- if (strlen(cmd) > 0 && >- cmd[strlen(cmd) - 1] != '\n') >- printf("\n"); >- } > } else { > if ((line = el_gets(el, &count)) == NULL || > count <= 0) { >@@ -2200,16 +2208,14 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2) > } > } > >- cp = strrchr(cmd, '\n'); >- if (cp) >- *cp = '\0'; >+ cmd[strcspn(cmd, "\n")] = '\0'; > > /* Handle user interrupts gracefully during commands */ > interrupted = 0; > signal(SIGINT, cmd_interrupt); > > err = parse_dispatch_command(conn, cmd, &remote_path, >- startdir, batchmode); >+ startdir, batchmode, !interactive && el == NULL); > if (err != 0) > break; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
dtucker
:
ok+
Actions:
View
|
Diff
Attachments on
bug 2926
:
3199
| 3200