]> andersk Git - openssh.git/commitdiff
- markus@cvs.openbsd.org 2002/11/07 22:35:38
authormouring <mouring>
Sat, 9 Nov 2002 15:54:08 +0000 (15:54 +0000)
committermouring <mouring>
Sat, 9 Nov 2002 15:54:08 +0000 (15:54 +0000)
     [scp.c]
     check exit status from ssh, and exit(1) if ssh fails; bug#369;
     binder@arago.de

ChangeLog
scp.c

index 9d3874ce054dcfbe4e189c28c5da5dfcddef2eee..8707c651fc2c86b92d2d3b087019f7d94b8b0195 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
      target host and ssh-keysign(8) does not know the remote hostname
      and not trust ssh(1) about the hostname, so we add a new option
      EnableSSHKeysign; ok djm@, report from zierke@informatik.uni-hamburg.de
+   - markus@cvs.openbsd.org 2002/11/07 22:35:38
+     [scp.c]
+     check exit status from ssh, and exit(1) if ssh fails; bug#369; 
+     binder@arago.de
 
 20021021
  - (djm) Bug #400: Kill ssh-rand-helper children on timeout, patch from 
diff --git a/scp.c b/scp.c
index 921ffeedc96daf550e2f5e08bed06f20c53658dd..05c490f4e6f852d5b0bf3d4d21d1404d2e62e6df 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -75,7 +75,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.91 2002/06/19 00:27:55 deraadt Exp $");
+RCSID("$OpenBSD: scp.c,v 1.92 2002/11/07 22:35:38 markus Exp $");
 
 #include "xmalloc.h"
 #include "atomicio.h"
@@ -125,6 +125,9 @@ int showprogress = 1;
 /* This is the program to execute for the secured connection. ("ssh" or -S) */
 char *ssh_program = _PATH_SSH_PROGRAM;
 
+/* This is used to store the pid of ssh_program */
+pid_t do_cmd_pid;
+
 /*
  * This function executes the given command as the specified user on the
  * given host.  This returns < 0 if execution fails, and >= 0 otherwise. This
@@ -159,7 +162,8 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
        close(reserved[1]);
 
        /* For a child to execute the command on the remote host using ssh. */
-       if (fork() == 0)  {
+       do_cmd_pid = fork();
+       if (do_cmd_pid == 0) {
                /* Child. */
                close(pin[1]);
                close(pout[0]);
@@ -177,6 +181,8 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
                execvp(ssh_program, args.list);
                perror(ssh_program);
                exit(1);
+       } else if (do_cmd_pid == -1) {
+               fatal("fork: %s", strerror(errno));
        }
        /* Parent.  Close the other side, and return the local side. */
        close(pin[0]);
@@ -219,7 +225,7 @@ main(argc, argv)
        int argc;
        char *argv[];
 {
-       int ch, fflag, tflag;
+       int ch, fflag, tflag, status;
        char *targ;
        extern char *optarg;
        extern int optind;
@@ -317,6 +323,7 @@ main(argc, argv)
                targetshouldbedirectory = 1;
 
        remin = remout = -1;
+       do_cmd_pid = -1;
        /* Command to be executed on remote system using "ssh". */
        (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
            verbose_mode ? " -v" : "",
@@ -332,6 +339,22 @@ main(argc, argv)
                if (targetshouldbedirectory)
                        verifydir(argv[argc - 1]);
        }
+       /*
+        * Finally check the exit status of the ssh process, if one was forked
+        * and no error has occured yet
+        */
+       if (do_cmd_pid != -1 && errs == 0) {
+               if (remin != -1)
+                   (void) close(remin);
+               if (remout != -1)
+                   (void) close(remout);
+               if (waitpid(do_cmd_pid, &status, 0) == -1)
+                       errs = 1;
+               else {
+                       if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+                               errs = 1;
+               }
+       }
        exit(errs != 0);
 }
 
This page took 0.048938 seconds and 5 git commands to generate.