|
Lines 125-130
Link Here
|
| 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 |
|
Lines 159-165
Link Here
|
| 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]); |
|
Lines 178-183
Link Here
|
| 178 |
perror(ssh_program); |
182 |
perror(ssh_program); |
| 179 |
exit(1); |
183 |
exit(1); |
| 180 |
} |
184 |
} |
|
|
185 |
else if (do_cmd_pid == (pid_t)-1) { |
| 186 |
/* fork() failed */ |
| 187 |
fatal("fork: %s", strerror(errno)); |
| 188 |
} |
| 181 |
/* Parent. Close the other side, and return the local side. */ |
189 |
/* Parent. Close the other side, and return the local side. */ |
| 182 |
close(pin[0]); |
190 |
close(pin[0]); |
| 183 |
*fdout = pin[1]; |
191 |
*fdout = pin[1]; |
|
Lines 219-225
Link Here
|
| 219 |
int argc; |
227 |
int argc; |
| 220 |
char *argv[]; |
228 |
char *argv[]; |
| 221 |
{ |
229 |
{ |
| 222 |
int ch, fflag, tflag; |
230 |
int ch, fflag, tflag, status; |
| 223 |
char *targ; |
231 |
char *targ; |
| 224 |
extern char *optarg; |
232 |
extern char *optarg; |
| 225 |
extern int optind; |
233 |
extern int optind; |
|
Lines 317-322
Link Here
|
| 317 |
targetshouldbedirectory = 1; |
325 |
targetshouldbedirectory = 1; |
| 318 |
|
326 |
|
| 319 |
remin = remout = -1; |
327 |
remin = remout = -1; |
|
|
328 |
do_cmd_pid = (pid_t)-1; |
| 320 |
/* Command to be executed on remote system using "ssh". */ |
329 |
/* Command to be executed on remote system using "ssh". */ |
| 321 |
(void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s", |
330 |
(void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s", |
| 322 |
verbose_mode ? " -v" : "", |
331 |
verbose_mode ? " -v" : "", |
|
Lines 331-336
Link Here
|
| 331 |
tolocal(argc, argv); /* Dest is local host. */ |
340 |
tolocal(argc, argv); /* Dest is local host. */ |
| 332 |
if (targetshouldbedirectory) |
341 |
if (targetshouldbedirectory) |
| 333 |
verifydir(argv[argc - 1]); |
342 |
verifydir(argv[argc - 1]); |
|
|
343 |
} |
| 344 |
/* |
| 345 |
* Finally check the exit status of the ssh process, if one was forked |
| 346 |
* and no error has occured yet |
| 347 |
*/ |
| 348 |
if (do_cmd_pid != (pid_t)-1 && errs == 0) { |
| 349 |
if (remin != -1) |
| 350 |
(void) close(remin); |
| 351 |
if (remout != -1) |
| 352 |
(void) close(remout); |
| 353 |
if (waitpid(do_cmd_pid, &status, 0) == -1) |
| 354 |
errs = 1; |
| 355 |
else { |
| 356 |
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) |
| 357 |
errs = 1; |
| 358 |
} |
| 334 |
} |
359 |
} |
| 335 |
exit(errs != 0); |
360 |
exit(errs != 0); |
| 336 |
} |
361 |
} |