diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2002-11-09 15:54:08 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2002-11-09 15:54:08 +0000 |
commit | 007eb912eae0258744043d08e85f99ba3201aeea (patch) | |
tree | a1257a91a6f17f9c3cbd85b1561d439a122eae82 | |
parent | b6df73b06abb12772d816e64f210ad30ebaf54cb (diff) |
- 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | scp.c | 29 |
2 files changed, 31 insertions, 4 deletions
@@ -32,6 +32,10 @@ | |||
32 | target host and ssh-keysign(8) does not know the remote hostname | 32 | target host and ssh-keysign(8) does not know the remote hostname |
33 | and not trust ssh(1) about the hostname, so we add a new option | 33 | and not trust ssh(1) about the hostname, so we add a new option |
34 | EnableSSHKeysign; ok djm@, report from zierke@informatik.uni-hamburg.de | 34 | EnableSSHKeysign; ok djm@, report from zierke@informatik.uni-hamburg.de |
35 | - markus@cvs.openbsd.org 2002/11/07 22:35:38 | ||
36 | [scp.c] | ||
37 | check exit status from ssh, and exit(1) if ssh fails; bug#369; | ||
38 | binder@arago.de | ||
35 | 39 | ||
36 | 20021021 | 40 | 20021021 |
37 | - (djm) Bug #400: Kill ssh-rand-helper children on timeout, patch from | 41 | - (djm) Bug #400: Kill ssh-rand-helper children on timeout, patch from |
@@ -809,4 +813,4 @@ | |||
809 | save auth method before monitor_reset_key_state(); bugzilla bug #284; | 813 | save auth method before monitor_reset_key_state(); bugzilla bug #284; |
810 | ok provos@ | 814 | ok provos@ |
811 | 815 | ||
812 | $Id: ChangeLog,v 1.2508 2002/11/09 15:52:31 mouring Exp $ | 816 | $Id: ChangeLog,v 1.2509 2002/11/09 15:54:08 mouring Exp $ |
@@ -75,7 +75,7 @@ | |||
75 | */ | 75 | */ |
76 | 76 | ||
77 | #include "includes.h" | 77 | #include "includes.h" |
78 | RCSID("$OpenBSD: scp.c,v 1.91 2002/06/19 00:27:55 deraadt Exp $"); | 78 | RCSID("$OpenBSD: scp.c,v 1.92 2002/11/07 22:35:38 markus Exp $"); |
79 | 79 | ||
80 | #include "xmalloc.h" | 80 | #include "xmalloc.h" |
81 | #include "atomicio.h" | 81 | #include "atomicio.h" |
@@ -125,6 +125,9 @@ int showprogress = 1; | |||
125 | /* This is the program to execute for the secured connection. ("ssh" or -S) */ | 125 | /* This is the program to execute for the secured connection. ("ssh" or -S) */ |
126 | char *ssh_program = _PATH_SSH_PROGRAM; | 126 | char *ssh_program = _PATH_SSH_PROGRAM; |
127 | 127 | ||
128 | /* This is used to store the pid of ssh_program */ | ||
129 | pid_t do_cmd_pid; | ||
130 | |||
128 | /* | 131 | /* |
129 | * This function executes the given command as the specified user on the | 132 | * This function executes the given command as the specified user on the |
130 | * given host. This returns < 0 if execution fails, and >= 0 otherwise. This | 133 | * 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) | |||
159 | close(reserved[1]); | 162 | close(reserved[1]); |
160 | 163 | ||
161 | /* For a child to execute the command on the remote host using ssh. */ | 164 | /* For a child to execute the command on the remote host using ssh. */ |
162 | if (fork() == 0) { | 165 | do_cmd_pid = fork(); |
166 | if (do_cmd_pid == 0) { | ||
163 | /* Child. */ | 167 | /* Child. */ |
164 | close(pin[1]); | 168 | close(pin[1]); |
165 | close(pout[0]); | 169 | close(pout[0]); |
@@ -177,6 +181,8 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc) | |||
177 | execvp(ssh_program, args.list); | 181 | execvp(ssh_program, args.list); |
178 | perror(ssh_program); | 182 | perror(ssh_program); |
179 | exit(1); | 183 | exit(1); |
184 | } else if (do_cmd_pid == -1) { | ||
185 | fatal("fork: %s", strerror(errno)); | ||
180 | } | 186 | } |
181 | /* Parent. Close the other side, and return the local side. */ | 187 | /* Parent. Close the other side, and return the local side. */ |
182 | close(pin[0]); | 188 | close(pin[0]); |
@@ -219,7 +225,7 @@ main(argc, argv) | |||
219 | int argc; | 225 | int argc; |
220 | char *argv[]; | 226 | char *argv[]; |
221 | { | 227 | { |
222 | int ch, fflag, tflag; | 228 | int ch, fflag, tflag, status; |
223 | char *targ; | 229 | char *targ; |
224 | extern char *optarg; | 230 | extern char *optarg; |
225 | extern int optind; | 231 | extern int optind; |
@@ -317,6 +323,7 @@ main(argc, argv) | |||
317 | targetshouldbedirectory = 1; | 323 | targetshouldbedirectory = 1; |
318 | 324 | ||
319 | remin = remout = -1; | 325 | remin = remout = -1; |
326 | do_cmd_pid = -1; | ||
320 | /* Command to be executed on remote system using "ssh". */ | 327 | /* Command to be executed on remote system using "ssh". */ |
321 | (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s", | 328 | (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s", |
322 | verbose_mode ? " -v" : "", | 329 | verbose_mode ? " -v" : "", |
@@ -332,6 +339,22 @@ main(argc, argv) | |||
332 | if (targetshouldbedirectory) | 339 | if (targetshouldbedirectory) |
333 | verifydir(argv[argc - 1]); | 340 | verifydir(argv[argc - 1]); |
334 | } | 341 | } |
342 | /* | ||
343 | * Finally check the exit status of the ssh process, if one was forked | ||
344 | * and no error has occured yet | ||
345 | */ | ||
346 | if (do_cmd_pid != -1 && errs == 0) { | ||
347 | if (remin != -1) | ||
348 | (void) close(remin); | ||
349 | if (remout != -1) | ||
350 | (void) close(remout); | ||
351 | if (waitpid(do_cmd_pid, &status, 0) == -1) | ||
352 | errs = 1; | ||
353 | else { | ||
354 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) | ||
355 | errs = 1; | ||
356 | } | ||
357 | } | ||
335 | exit(errs != 0); | 358 | exit(errs != 0); |
336 | } | 359 | } |
337 | 360 | ||