Bug 2926 - In batch mode sftp echoes the prompt and the commands back
Summary: In batch mode sftp echoes the prompt and the commands back
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: 7.7p1
Hardware: amd64 Linux
: P5 enhancement
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks: V_8_0
  Show dependency treegraph
 
Reported: 2018-11-04 03:48 AEDT by Enzo
Modified: 2021-10-14 01:40 AEDT (History)
3 users (show)

See Also:


Attachments
allow '@' prefix to suppress command echo (2.36 KB, patch)
2018-11-09 14:17 AEDT, Damien Miller
no flags Details | Diff
Allow @ and - to appear in any order (4.83 KB, patch)
2018-11-09 14:35 AEDT, Damien Miller
dtucker: ok+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Enzo 2018-11-04 03:48:52 AEDT
Batch mode is meant for script automation, not human operations, so echoing the prompt and the commands doesn't make any sense and needs extra stuff while programatically processing the output

A possible solution that's also backward compatible with all uses of the batch mode is to allow for a special prefix character to commands to avoid any echoing, just like the "-" is used to avoid a single failing command to terminate the session.

Something like "@" or "#" would be ok IMHO.

For example, the command syntax could become:

[@][-]<command> [arguments]...

The current workaround is to expunge every first output line, but am not sure whether this can apply to all use cases.
Comment 1 Damien Miller 2018-11-09 14:17:29 AEDT
Created attachment 3199 [details]
allow '@' prefix to suppress command echo

The prefix is a good idea. This implements '@command' to suppress echo.
Comment 2 Darren Tucker 2018-11-09 14:21:25 AEDT
Comment on attachment 3199 [details]
allow '@' prefix to suppress command echo

>+			if (!interactive && *cmd != '@') {
> 				mprintf("sftp> %s", cmd);

You're only checking the first character but the man page says - and @ can be supplied in any order, so -@ is not going to do what the man page says.
Comment 3 Damien Miller 2018-11-09 14:35:55 AEDT
Created attachment 3200 [details]
Allow @ and - to appear in any order

Darren points out that, despite what I advertised in the manpage, my previous patch did not allow '-' and '@' to appear in any order. This fixes this by moving the echo until after the entire command has been parsed.
Comment 4 Damien Miller 2018-11-16 13:30:25 AEDT
Patch is committed and will be in OpenSSH 8.0
Comment 5 Enzo 2018-11-16 19:03:46 AEDT
At the section "Lines 1282-1294 parse_args(const char **cpp, int *ignore_errors, int *aflag," I see a possible bug.
You can intercept the "-" and the "@" at any place in the command string.
Which can lead to unwanted results.

IMHO the correct code could begin with something like:

for (char* cpend=cp+2;*cp != '\0' && cp < cpend; cp++) {
Comment 6 Damien Miller 2021-04-23 15:00:23 AEST
closing resolved bugs as of 8.6p1 release
Comment 7 Ahmed Sayeed 2021-10-14 01:40:29 AEDT
[spam removed]