Bug 369 - Inconsistant exit status from scp
Summary: Inconsistant exit status from scp
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: scp (show other bugs)
Version: -current
Hardware: ix86 FreeBSD
: P2 normal
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-25 04:05 AEST by Kevin Oberman
Modified: 2004-04-14 12:24 AEST (History)
0 users

See Also:


Attachments
Check ssh's exit status in scp (2.06 KB, patch)
2002-09-12 00:43 AEST, Thomas Binder
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Oberman 2002-07-25 04:05:52 AEST
Teh man page states that scp returns 0 for success and >0 for failure. This is
non-standard.
Worse, it may return 0 after a failure.
scp -B bogus@system:file1 file1
If authentication fails, the string "Permision denied" is sent to STDERR, but
the status is 0, making this indistinguishable from success without an extra
check of
the test sent to STDERR.
Comment 1 Markus Friedl 2002-07-25 04:25:40 AEST
0 for success and >0 for failure _is_ standard on unix.
Comment 2 Markus Friedl 2002-07-25 04:26:41 AEST
scp chould check ssh's exit status.
Comment 3 TBS Internet 2002-09-10 19:19:03 AEST
I confirm that this bug does exist. It's especially annoying since we use here 
a lot of scripts which check for the return values of scp to indicate success 
or failure.

In fact it does the good thing on nonexistent files/dirs/etc, but fails in case 
of auth failure, name resolution failures and so on (the number after "rtfm" in 
the prompt reports the cmd exit status):

fg!rtfm 0 (pts/2) ~ $ scp -v root@mod-tsf.pitux.com:.bashrc /tmp
Executing: program /usr/bin/ssh host mod-tsf.pitux.com, user root, command scp 
-v -f .bashrc
OpenSSH_3.4p1, SSH protocols 1.5/2.0, OpenSSL 0x0090602f
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Rhosts Authentication disabled, originating port will not be trusted.
debug1: ssh_connect: needpriv 0
ssh: mod-tsf.pitux.com: Name or service not known
fg!rtfm 0 (pts/2) ~ $ scp -v root@mod-tsd.pitux.com:fartr /tmp  
Executing: program /usr/bin/ssh host mod-tsd.pitux.com, user root, command scp 
-v -f fartr
OpenSSH_3.4p1, SSH protocols 1.5/2.0, OpenSSL 0x0090602f
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Rhosts Authentication disabled, originating port will not be trusted.
debug1: ssh_connect: needpriv 0
debug1: Connecting to mod-tsd.pitux.com [212.67.34.43] port 22.
debug1: Connection established.
debug1: identity file /home/fg/.ssh/identity type 0
debug1: identity file /home/fg/.ssh/id_rsa type -1
debug1: identity file /home/fg/.ssh/id_dsa type -1
debug1: Remote protocol version 1.5, remote software version OpenSSH_3.2.2p1
debug1: match: OpenSSH_3.2.2p1 pat OpenSSH*
debug1: Local version string SSH-1.5-OpenSSH_3.4p1
debug1: Waiting for server public key.
debug1: Received server public key (768 bits) and host key (1024 bits).
debug1: Host 'mod-tsd.pitux.com' is known and matches the RSA1 host key.
debug1: Found key in /home/fg/.ssh/known_hosts:17
debug1: Encryption type: 3des
debug1: Sent encrypted session key.
debug1: cipher_init: set keylen (16 -> 32)
debug1: cipher_init: set keylen (16 -> 32)
debug1: Installing crc compensation attack detector.
debug1: Received encrypted confirmation.
debug1: Trying RSA authentication via agent with 'fgaliegue@ovh.tbs-internet.com'
debug1: Received RSA challenge from server.
debug1: Sending response to RSA challenge.
debug1: Remote: RSA authentication accepted.
debug1: RSA authentication accepted by server.
debug1: Sending command: scp -v -f fartr
debug1: Entering interactive session.
debug1: fd 0 setting O_NONBLOCK
debug1: fd 1 setting O_NONBLOCK
scp: fartr: No such file or directory
debug1: fd 1 clearing O_NONBLOCK
debug1: Transferred: stdin 1, stdout 39, stderr 0 bytes in 0.3 seconds
debug1: Bytes per second: stdin 3.5, stdout 136.5, stderr 0.0
debug1: Exit status 1
fg!rtfm 1 (pts/2) ~ $  scp -v fg@mod-tsd.pitux.com:fartr /tmp
Executing: program /usr/bin/ssh host mod-tsd.pitux.com, user fg, command scp -v 
-f fartr
OpenSSH_3.4p1, SSH protocols 1.5/2.0, OpenSSL 0x0090602f
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Rhosts Authentication disabled, originating port will not be trusted.
debug1: ssh_connect: needpriv 0
debug1: Connecting to mod-tsd.pitux.com [212.67.34.43] port 22.
debug1: Connection established.
debug1: identity file /home/fg/.ssh/identity type 0
debug1: identity file /home/fg/.ssh/id_rsa type -1
debug1: identity file /home/fg/.ssh/id_dsa type -1
debug1: Remote protocol version 1.5, remote software version OpenSSH_3.2.2p1
debug1: match: OpenSSH_3.2.2p1 pat OpenSSH*
debug1: Local version string SSH-1.5-OpenSSH_3.4p1
debug1: Waiting for server public key.
debug1: Received server public key (768 bits) and host key (1024 bits).
debug1: Host 'mod-tsd.pitux.com' is known and matches the RSA1 host key.
debug1: Found key in /home/fg/.ssh/known_hosts:17
debug1: Encryption type: 3des
debug1: Sent encrypted session key.
debug1: cipher_init: set keylen (16 -> 32)
debug1: cipher_init: set keylen (16 -> 32)
debug1: Installing crc compensation attack detector.
debug1: Received encrypted confirmation.
debug1: Trying RSA authentication via agent with 'fgaliegue@ovh.tbs-internet.com'
debug1: Server refused our key.
debug1: RSA authentication using agent refused.
debug1: Trying RSA authentication with key '/home/fg/.ssh/identity'
debug1: Server refused our key.
debug1: Doing challenge response authentication.
debug1: No challenge.
Permission denied.
debug1: Calling cleanup 0x8067140(0x0)
fg!rtfm 0 (pts/2) ~ $ 



Comment 4 Markus Friedl 2002-09-10 22:45:33 AEST
do you have a patch for checking the exit status of ssh? 
Comment 5 Kevin Oberman 2002-09-11 03:26:11 AEST
I have no patch for this. I simply reported the problem I discovered when
running scp from a Perl script and checking for errors.
Comment 6 TBS Internet 2002-09-11 17:29:43 AEST
In response to #4:

I attempted to do a patch to scp.c which adds a call to waitpid() in do_cmd() 
in order to check for the exit status in the parent. Unfortunately, while it 
does the right thing on ssh failures, it just hangs the command in case it is 
bound to succeed. I'll investigate some more when I have the time.
Comment 7 Thomas Binder 2002-09-12 00:43:21 AEST
Created attachment 144 [details]
Check ssh's exit status in scp

The attached rough patch should do the trick. Note that you have to close()
the file handles used to communicate with the ssh process, as otherwise the
remote scp (when copying to remote) will continue waiting for data, causing
waitpid() to wait forever.

Also note that this patch may cause hangs of the local scp client when the
remote sshd should have been compiled with USE_PIPES defined, but hasn't.
Comment 8 Thomas Binder 2002-09-12 00:45:47 AEST
Forgot to mention that the patch in attachment #144 [details] also adds a check for
fork() failure.
Comment 9 TBS Internet 2002-09-14 00:22:59 AEST
Congratulations Thomas, it Works Wonderfully For Me(tm). I've retried all test 
cases in #3 and it returned the good error code each time. Problem solved for 
me, I just recompiled my 3.4p1 with this patch and so far so good.
Comment 10 Markus Friedl 2002-11-08 09:38:20 AEDT
patch applied.
Comment 11 Emil Samovsky 2002-12-18 20:34:04 AEDT
Unfortunately this bug still exists in 3.5p1 and 3.4p1 versions.
I've checked it on Sun Solaris 2.6 and HP 11.00 platforms and on both has this
problem.
If the failure based on scp function itself like "file not found" i've got
correct (>0) exit status.
If the failure conection related like "Connection refused" or "bad hostname"
i've got exit status 0.
It denies using scp (and ssh in general) in scripts.
Comment 12 Thomas Binder 2002-12-18 22:32:45 AEDT
The fix was applied after OpenSSh 3.5 was released, i.e. 3.5 does not yet
contain the patch.
Comment 13 Damien Miller 2004-04-14 12:24:18 AEST
Mass change of RESOLVED bugs to CLOSED