OpenCoverage

scp.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/scp.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: scp.c,v 1.197 2018/06/01 04:31:48 dtucker Exp $ */-
2/*-
3 * scp - secure remote copy. This is basically patched BSD rcp which-
4 * uses ssh to do the data transfer (instead of using rcmd).-
5 *-
6 * NOTE: This version should NOT be suid root. (This uses ssh to-
7 * do the transfer and ssh has the necessary privileges.)-
8 *-
9 * 1995 Timo Rinne <tri@iki.fi>, Tatu Ylonen <ylo@cs.hut.fi>-
10 *-
11 * As far as I am concerned, the code I have written for this software-
12 * can be used freely for any purpose. Any derived versions of this-
13 * software must be clearly marked as such, and if the derived work is-
14 * incompatible with the protocol description in the RFC file, it must be-
15 * called by a name other than "ssh" or "Secure Shell".-
16 */-
17/*-
18 * Copyright (c) 1999 Theo de Raadt. All rights reserved.-
19 * Copyright (c) 1999 Aaron Campbell. All rights reserved.-
20 *-
21 * Redistribution and use in source and binary forms, with or without-
22 * modification, are permitted provided that the following conditions-
23 * are met:-
24 * 1. Redistributions of source code must retain the above copyright-
25 * notice, this list of conditions and the following disclaimer.-
26 * 2. Redistributions in binary form must reproduce the above copyright-
27 * notice, this list of conditions and the following disclaimer in the-
28 * documentation and/or other materials provided with the distribution.-
29 *-
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR-
31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES-
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.-
33 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,-
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT-
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF-
39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-
40 */-
41-
42/*-
43 * Parts from:-
44 *-
45 * Copyright (c) 1983, 1990, 1992, 1993, 1995-
46 * The Regents of the University of California. All rights reserved.-
47 *-
48 * Redistribution and use in source and binary forms, with or without-
49 * modification, are permitted provided that the following conditions-
50 * are met:-
51 * 1. Redistributions of source code must retain the above copyright-
52 * notice, this list of conditions and the following disclaimer.-
53 * 2. Redistributions in binary form must reproduce the above copyright-
54 * notice, this list of conditions and the following disclaimer in the-
55 * documentation and/or other materials provided with the distribution.-
56 * 3. Neither the name of the University nor the names of its contributors-
57 * may be used to endorse or promote products derived from this software-
58 * without specific prior written permission.-
59 *-
60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND-
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE-
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE-
63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE-
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL-
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS-
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT-
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY-
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF-
70 * SUCH DAMAGE.-
71 *-
72 */-
73-
74#include "includes.h"-
75-
76#include <sys/types.h>-
77#ifdef HAVE_SYS_STAT_H-
78# include <sys/stat.h>-
79#endif-
80#ifdef HAVE_POLL_H-
81#include <poll.h>-
82#else-
83# ifdef HAVE_SYS_POLL_H-
84# include <sys/poll.h>-
85# endif-
86#endif-
87#ifdef HAVE_SYS_TIME_H-
88# include <sys/time.h>-
89#endif-
90#include <sys/wait.h>-
91#include <sys/uio.h>-
92-
93#include <ctype.h>-
94#include <dirent.h>-
95#include <errno.h>-
96#include <fcntl.h>-
97#include <limits.h>-
98#include <locale.h>-
99#include <pwd.h>-
100#include <signal.h>-
101#include <stdarg.h>-
102#ifdef HAVE_STDINT_H-
103#include <stdint.h>-
104#endif-
105#include <stdio.h>-
106#include <stdlib.h>-
107#include <string.h>-
108#include <time.h>-
109#include <unistd.h>-
110#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)-
111#include <vis.h>-
112#endif-
113-
114#include "xmalloc.h"-
115#include "ssh.h"-
116#include "atomicio.h"-
117#include "pathnames.h"-
118#include "log.h"-
119#include "misc.h"-
120#include "progressmeter.h"-
121#include "utf8.h"-
122-
123extern char *__progname;-
124-
125#define COPY_BUFLEN 16384-
126-
127int do_cmd(char *host, char *remuser, int port, char *cmd, int *fdin, int *fdout);-
128int do_cmd2(char *host, char *remuser, int port, char *cmd, int fdin, int fdout);-
129-
130/* Struct for addargs */-
131arglist args;-
132arglist remote_remote_args;-
133-
134/* Bandwidth limit */-
135long long limit_kbps = 0;-
136struct bwlimit bwlimit;-
137-
138/* Name of current file being transferred. */-
139char *curfile;-
140-
141/* This is set to non-zero to enable verbose mode. */-
142int verbose_mode = 0;-
143-
144/* This is set to zero if the progressmeter is not desired. */-
145int showprogress = 1;-
146-
147/*-
148 * This is set to non-zero if remote-remote copy should be piped-
149 * through this process.-
150 */-
151int throughlocal = 0;-
152-
153/* Non-standard port to use for the ssh connection or -1. */-
154int sshport = -1;-
155-
156/* This is the program to execute for the secured connection. ("ssh" or -S) */-
157char *ssh_program = _PATH_SSH_PROGRAM;-
158-
159/* This is used to store the pid of ssh_program */-
160pid_t do_cmd_pid = -1;-
161-
162static void-
163killchild(int signo)-
164{-
165 if (do_cmd_pid > 1) {
do_cmd_pid > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
166 kill(do_cmd_pid, signo ? signo : SIGTERM);-
167 waitpid(do_cmd_pid, NULL, 0);-
168 }
never executed: end of block
0
169-
170 if (signo)
signoDescription
TRUEnever evaluated
FALSEnever evaluated
0
171 _exit(1);
never executed: _exit(1);
0
172 exit(1);
never executed: exit(1);
0
173}-
174-
175static void-
176suspchild(int signo)-
177{-
178 int status;-
179-
180 if (do_cmd_pid > 1) {
do_cmd_pid > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
181 kill(do_cmd_pid, signo);-
182 while (waitpid(do_cmd_pid, &status, WUNTRACED) == -1 &&
waitpid(do_cmd...tus, 2 ) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
183 errno == EINTR)
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
0
184 ;
never executed: ;
0
185 kill(getpid(), SIGSTOP);-
186 }
never executed: end of block
0
187}
never executed: end of block
0
188-
189static int-
190do_local_cmd(arglist *a)-
191{-
192 u_int i;-
193 int status;-
194 pid_t pid;-
195-
196 if (a->num == 0)
a->num == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
197 fatal("do_local_cmd: no arguments");
never executed: fatal("do_local_cmd: no arguments");
0
198-
199 if (verbose_mode) {
verbose_modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
200 fprintf(stderr, "Executing:");-
201 for (i = 0; i < a->num; i++)
i < a->numDescription
TRUEnever evaluated
FALSEnever evaluated
0
202 fmprintf(stderr, " %s", a->list[i]);
never executed: fmprintf( stderr , " %s", a->list[i]);
0
203 fprintf(stderr, "\n");-
204 }
never executed: end of block
0
205 if ((pid = fork()) == -1)
(pid = fork()) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
206 fatal("do_local_cmd: fork: %s", strerror(errno));
never executed: fatal("do_local_cmd: fork: %s", strerror( (*__errno_location ()) ));
0
207-
208 if (pid == 0) {
pid == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
209 execvp(a->list[0], a->list);-
210 perror(a->list[0]);-
211 exit(1);
never executed: exit(1);
0
212 }-
213-
214 do_cmd_pid = pid;-
215 signal(SIGTERM, killchild);-
216 signal(SIGINT, killchild);-
217 signal(SIGHUP, killchild);-
218-
219 while (waitpid(pid, &status, 0) == -1)
waitpid(pid, &status, 0) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
220 if (errno != EINTR)
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
0
221 fatal("do_local_cmd: waitpid: %s", strerror(errno));
never executed: fatal("do_local_cmd: waitpid: %s", strerror( (*__errno_location ()) ));
0
222-
223 do_cmd_pid = -1;-
224-
225 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
! ((( status ) & 0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
((( status ) &...00) >> 8) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
226 return (-1);
never executed: return (-1);
0
227-
228 return (0);
never executed: return (0);
0
229}-
230-
231/*-
232 * This function executes the given command as the specified user on the-
233 * given host. This returns < 0 if execution fails, and >= 0 otherwise. This-
234 * assigns the input and output file descriptors on success.-
235 */-
236-
237int-
238do_cmd(char *host, char *remuser, int port, char *cmd, int *fdin, int *fdout)-
239{-
240 int pin[2], pout[2], reserved[2];-
241-
242 if (verbose_mode)
verbose_modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
243 fmprintf(stderr,
never executed: fmprintf( stderr , "Executing: program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
244 "Executing: program %s host %s, user %s, command %s\n",
never executed: fmprintf( stderr , "Executing: program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
245 ssh_program, host,
never executed: fmprintf( stderr , "Executing: program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
246 remuser ? remuser : "(unspecified)", cmd);
never executed: fmprintf( stderr , "Executing: program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
247-
248 if (port == -1)
port == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
249 port = sshport;
never executed: port = sshport;
0
250-
251 /*-
252 * Reserve two descriptors so that the real pipes won't get-
253 * descriptors 0 and 1 because that will screw up dup2 below.-
254 */-
255 if (pipe(reserved) < 0)
pipe(reserved) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
256 fatal("pipe: %s", strerror(errno));
never executed: fatal("pipe: %s", strerror( (*__errno_location ()) ));
0
257-
258 /* Create a socket pair for communicating with ssh. */-
259 if (pipe(pin) < 0)
pipe(pin) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
260 fatal("pipe: %s", strerror(errno));
never executed: fatal("pipe: %s", strerror( (*__errno_location ()) ));
0
261 if (pipe(pout) < 0)
pipe(pout) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
262 fatal("pipe: %s", strerror(errno));
never executed: fatal("pipe: %s", strerror( (*__errno_location ()) ));
0
263-
264 /* Free the reserved descriptors. */-
265 close(reserved[0]);-
266 close(reserved[1]);-
267-
268 signal(SIGTSTP, suspchild);-
269 signal(SIGTTIN, suspchild);-
270 signal(SIGTTOU, suspchild);-
271-
272 /* Fork a child to execute the command on the remote host using ssh. */-
273 do_cmd_pid = fork();-
274 if (do_cmd_pid == 0) {
do_cmd_pid == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
275 /* Child. */-
276 close(pin[1]);-
277 close(pout[0]);-
278 dup2(pin[0], 0);-
279 dup2(pout[1], 1);-
280 close(pin[0]);-
281 close(pout[1]);-
282-
283 replacearg(&args, 0, "%s", ssh_program);-
284 if (port != -1) {
port != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
285 addargs(&args, "-p");-
286 addargs(&args, "%d", port);-
287 }
never executed: end of block
0
288 if (remuser != NULL) {
remuser != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
289 addargs(&args, "-l");-
290 addargs(&args, "%s", remuser);-
291 }
never executed: end of block
0
292 addargs(&args, "--");-
293 addargs(&args, "%s", host);-
294 addargs(&args, "%s", cmd);-
295-
296 execvp(ssh_program, args.list);-
297 perror(ssh_program);-
298 exit(1);
never executed: exit(1);
0
299 } else if (do_cmd_pid == -1) {
do_cmd_pid == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
300 fatal("fork: %s", strerror(errno));-
301 }
never executed: end of block
0
302 /* Parent. Close the other side, and return the local side. */-
303 close(pin[0]);-
304 *fdout = pin[1];-
305 close(pout[1]);-
306 *fdin = pout[0];-
307 signal(SIGTERM, killchild);-
308 signal(SIGINT, killchild);-
309 signal(SIGHUP, killchild);-
310 return 0;
never executed: return 0;
0
311}-
312-
313/*-
314 * This function executes a command similar to do_cmd(), but expects the-
315 * input and output descriptors to be setup by a previous call to do_cmd().-
316 * This way the input and output of two commands can be connected.-
317 */-
318int-
319do_cmd2(char *host, char *remuser, int port, char *cmd, int fdin, int fdout)-
320{-
321 pid_t pid;-
322 int status;-
323-
324 if (verbose_mode)
verbose_modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
325 fmprintf(stderr,
never executed: fmprintf( stderr , "Executing: 2nd program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
326 "Executing: 2nd program %s host %s, user %s, command %s\n",
never executed: fmprintf( stderr , "Executing: 2nd program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
327 ssh_program, host,
never executed: fmprintf( stderr , "Executing: 2nd program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
328 remuser ? remuser : "(unspecified)", cmd);
never executed: fmprintf( stderr , "Executing: 2nd program %s host %s, user %s, command %s\n", ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
0
329-
330 if (port == -1)
port == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
331 port = sshport;
never executed: port = sshport;
0
332-
333 /* Fork a child to execute the command on the remote host using ssh. */-
334 pid = fork();-
335 if (pid == 0) {
pid == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
336 dup2(fdin, 0);-
337 dup2(fdout, 1);-
338-
339 replacearg(&args, 0, "%s", ssh_program);-
340 if (port != -1) {
port != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
341 addargs(&args, "-p");-
342 addargs(&args, "%d", port);-
343 }
never executed: end of block
0
344 if (remuser != NULL) {
remuser != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
345 addargs(&args, "-l");-
346 addargs(&args, "%s", remuser);-
347 }
never executed: end of block
0
348 addargs(&args, "--");-
349 addargs(&args, "%s", host);-
350 addargs(&args, "%s", cmd);-
351-
352 execvp(ssh_program, args.list);-
353 perror(ssh_program);-
354 exit(1);
never executed: exit(1);
0
355 } else if (pid == -1) {
pid == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
356 fatal("fork: %s", strerror(errno));-
357 }
never executed: end of block
0
358 while (waitpid(pid, &status, 0) == -1)
waitpid(pid, &status, 0) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
359 if (errno != EINTR)
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
0
360 fatal("do_cmd2: waitpid: %s", strerror(errno));
never executed: fatal("do_cmd2: waitpid: %s", strerror( (*__errno_location ()) ));
0
361 return 0;
never executed: return 0;
0
362}-
363-
364typedef struct {-
365 size_t cnt;-
366 char *buf;-
367} BUF;-
368-
369BUF *allocbuf(BUF *, int, int);-
370void lostconn(int);-
371int okname(char *);-
372void run_err(const char *,...);-
373void verifydir(char *);-
374-
375struct passwd *pwd;-
376uid_t userid;-
377int errs, remin, remout;-
378int pflag, iamremote, iamrecursive, targetshouldbedirectory;-
379-
380#define CMDNEEDS 64-
381char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */-
382-
383int response(void);-
384void rsource(char *, struct stat *);-
385void sink(int, char *[]);-
386void source(int, char *[]);-
387void tolocal(int, char *[]);-
388void toremote(int, char *[]);-
389void usage(void);-
390-
391int-
392main(int argc, char **argv)-
393{-
394 int ch, fflag, tflag, status, n;-
395 char **newargv;-
396 const char *errstr;-
397 extern char *optarg;-
398 extern int optind;-
399-
400 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */-
401 sanitise_stdfd();-
402-
403 msetlocale();-
404-
405 /* Copy argv, because we modify it */-
406 newargv = xcalloc(MAXIMUM(argc + 1, 1), sizeof(*newargv));-
407 for (n = 0; n < argc; n++)
n < argcDescription
TRUEnever evaluated
FALSEnever evaluated
0
408 newargv[n] = xstrdup(argv[n]);
never executed: newargv[n] = xstrdup(argv[n]);
0
409 argv = newargv;-
410-
411 __progname = ssh_get_progname(argv[0]);-
412-
413 memset(&args, '\0', sizeof(args));-
414 memset(&remote_remote_args, '\0', sizeof(remote_remote_args));-
415 args.list = remote_remote_args.list = NULL;-
416 addargs(&args, "%s", ssh_program);-
417 addargs(&args, "-x");-
418 addargs(&args, "-oForwardAgent=no");-
419 addargs(&args, "-oPermitLocalCommand=no");-
420 addargs(&args, "-oClearAllForwardings=yes");-
421 addargs(&args, "-oRemoteCommand=none");-
422 addargs(&args, "-oRequestTTY=no");-
423-
424 fflag = tflag = 0;-
425 while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q12346S:o:F:")) != -1)
(ch = BSDgetop...:o:F:")) != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
426 switch (ch) {-
427 /* User-visible flags. */-
428 case '1':
never executed: case '1':
0
429 fatal("SSH protocol v.1 is no longer supported");-
430 break;
never executed: break;
0
431 case '2':
never executed: case '2':
0
432 /* Ignored */-
433 break;
never executed: break;
0
434 case '4':
never executed: case '4':
0
435 case '6':
never executed: case '6':
0
436 case 'C':
never executed: case 'C':
0
437 addargs(&args, "-%c", ch);-
438 addargs(&remote_remote_args, "-%c", ch);-
439 break;
never executed: break;
0
440 case '3':
never executed: case '3':
0
441 throughlocal = 1;-
442 break;
never executed: break;
0
443 case 'o':
never executed: case 'o':
0
444 case 'c':
never executed: case 'c':
0
445 case 'i':
never executed: case 'i':
0
446 case 'F':
never executed: case 'F':
0
447 addargs(&remote_remote_args, "-%c", ch);-
448 addargs(&remote_remote_args, "%s", optarg);-
449 addargs(&args, "-%c", ch);-
450 addargs(&args, "%s", optarg);-
451 break;
never executed: break;
0
452 case 'P':
never executed: case 'P':
0
453 sshport = a2port(optarg);-
454 if (sshport <= 0)
sshport <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
455 fatal("bad port \"%s\"\n", optarg);
never executed: fatal("bad port \"%s\"\n", BSDoptarg);
0
456 break;
never executed: break;
0
457 case 'B':
never executed: case 'B':
0
458 addargs(&remote_remote_args, "-oBatchmode=yes");-
459 addargs(&args, "-oBatchmode=yes");-
460 break;
never executed: break;
0
461 case 'l':
never executed: case 'l':
0
462 limit_kbps = strtonum(optarg, 1, 100 * 1024 * 1024,-
463 &errstr);-
464 if (errstr != NULL)
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
465 usage();
never executed: usage();
0
466 limit_kbps *= 1024; /* kbps */-
467 bandwidth_limit_init(&bwlimit, limit_kbps, COPY_BUFLEN);-
468 break;
never executed: break;
0
469 case 'p':
never executed: case 'p':
0
470 pflag = 1;-
471 break;
never executed: break;
0
472 case 'r':
never executed: case 'r':
0
473 iamrecursive = 1;-
474 break;
never executed: break;
0
475 case 'S':
never executed: case 'S':
0
476 ssh_program = xstrdup(optarg);-
477 break;
never executed: break;
0
478 case 'v':
never executed: case 'v':
0
479 addargs(&args, "-v");-
480 addargs(&remote_remote_args, "-v");-
481 verbose_mode = 1;-
482 break;
never executed: break;
0
483 case 'q':
never executed: case 'q':
0
484 addargs(&args, "-q");-
485 addargs(&remote_remote_args, "-q");-
486 showprogress = 0;-
487 break;
never executed: break;
0
488-
489 /* Server options. */-
490 case 'd':
never executed: case 'd':
0
491 targetshouldbedirectory = 1;-
492 break;
never executed: break;
0
493 case 'f': /* "from" */
never executed: case 'f':
0
494 iamremote = 1;-
495 fflag = 1;-
496 break;
never executed: break;
0
497 case 't': /* "to" */
never executed: case 't':
0
498 iamremote = 1;-
499 tflag = 1;-
500#ifdef HAVE_CYGWIN-
501 setmode(0, O_BINARY);-
502#endif-
503 break;
never executed: break;
0
504 default:
never executed: default:
0
505 usage();-
506 }
never executed: end of block
0
507 argc -= optind;-
508 argv += optind;-
509-
510 if ((pwd = getpwuid(userid = getuid())) == NULL)
(pwd = getpwui...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
511 fatal("unknown user %u", (u_int) userid);
never executed: fatal("unknown user %u", (u_int) userid);
0
512-
513 if (!isatty(STDOUT_FILENO))
!isatty( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
0
514 showprogress = 0;
never executed: showprogress = 0;
0
515-
516 if (pflag) {
pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
517 /* Cannot pledge: -p allows setuid/setgid files... */-
518 } else {
never executed: end of block
0
519 if (pledge("stdio rpath wpath cpath fattr tty proc exec",
pledge("stdio ...d *)0) ) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
520 NULL) == -1) {
pledge("stdio ...d *)0) ) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
521 perror("pledge");-
522 exit(1);
never executed: exit(1);
0
523 }-
524 }
never executed: end of block
0
525-
526 remin = STDIN_FILENO;-
527 remout = STDOUT_FILENO;-
528-
529 if (fflag) {
fflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
530 /* Follow "protocol", send data. */-
531 (void) response();-
532 source(argc, argv);-
533 exit(errs != 0);
never executed: exit(errs != 0);
0
534 }-
535 if (tflag) {
tflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
536 /* Receive data. */-
537 sink(argc, argv);-
538 exit(errs != 0);
never executed: exit(errs != 0);
0
539 }-
540 if (argc < 2)
argc < 2Description
TRUEnever evaluated
FALSEnever evaluated
0
541 usage();
never executed: usage();
0
542 if (argc > 2)
argc > 2Description
TRUEnever evaluated
FALSEnever evaluated
0
543 targetshouldbedirectory = 1;
never executed: targetshouldbedirectory = 1;
0
544-
545 remin = remout = -1;-
546 do_cmd_pid = -1;-
547 /* Command to be executed on remote system using "ssh". */-
548 (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",-
549 verbose_mode ? " -v" : "",-
550 iamrecursive ? " -r" : "", pflag ? " -p" : "",-
551 targetshouldbedirectory ? " -d" : "");-
552-
553 (void) signal(SIGPIPE, lostconn);-
554-
555 if (colon(argv[argc - 1])) /* Dest is remote host. */
colon(argv[argc - 1])Description
TRUEnever evaluated
FALSEnever evaluated
0
556 toremote(argc, argv);
never executed: toremote(argc, argv);
0
557 else {-
558 if (targetshouldbedirectory)
targetshouldbedirectoryDescription
TRUEnever evaluated
FALSEnever evaluated
0
559 verifydir(argv[argc - 1]);
never executed: verifydir(argv[argc - 1]);
0
560 tolocal(argc, argv); /* Dest is local host. */-
561 }
never executed: end of block
0
562 /*-
563 * Finally check the exit status of the ssh process, if one was forked-
564 * and no error has occurred yet-
565 */-
566 if (do_cmd_pid != -1 && errs == 0) {
do_cmd_pid != -1Description
TRUEnever evaluated
FALSEnever evaluated
errs == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
567 if (remin != -1)
remin != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
568 (void) close(remin);
never executed: (void) close(remin);
0
569 if (remout != -1)
remout != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
570 (void) close(remout);
never executed: (void) close(remout);
0
571 if (waitpid(do_cmd_pid, &status, 0) == -1)
waitpid(do_cmd...atus, 0) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
572 errs = 1;
never executed: errs = 1;
0
573 else {-
574 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
! ((( status ) & 0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
((( status ) &...00) >> 8) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
575 errs = 1;
never executed: errs = 1;
0
576 }
never executed: end of block
0
577 }-
578 exit(errs != 0);
never executed: exit(errs != 0);
0
579}-
580-
581/* Callback from atomicio6 to update progress meter and limit bandwidth */-
582static int-
583scpio(void *_cnt, size_t s)-
584{-
585 off_t *cnt = (off_t *)_cnt;-
586-
587 *cnt += s;-
588 if (limit_kbps > 0)
limit_kbps > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
589 bandwidth_limit(&bwlimit, s);
never executed: bandwidth_limit(&bwlimit, s);
0
590 return 0;
never executed: return 0;
0
591}-
592-
593static int-
594do_times(int fd, int verb, const struct stat *sb)-
595{-
596 /* strlen(2^64) == 20; strlen(10^6) == 7 */-
597 char buf[(20 + 7 + 2) * 2 + 2];-
598-
599 (void)snprintf(buf, sizeof(buf), "T%llu 0 %llu 0\n",-
600 (unsigned long long) (sb->st_mtime < 0 ? 0 : sb->st_mtime),-
601 (unsigned long long) (sb->st_atime < 0 ? 0 : sb->st_atime));-
602 if (verb) {
verbDescription
TRUEnever evaluated
FALSEnever evaluated
0
603 fprintf(stderr, "File mtime %lld atime %lld\n",-
604 (long long)sb->st_mtime, (long long)sb->st_atime);-
605 fprintf(stderr, "Sending file timestamps: %s", buf);-
606 }
never executed: end of block
0
607 (void) atomicio(vwrite, fd, buf, strlen(buf));-
608 return (response());
never executed: return (response());
0
609}-
610-
611static int-
612parse_scp_uri(const char *uri, char **userp, char **hostp, int *portp,-
613 char **pathp)-
614{-
615 int r;-
616-
617 r = parse_uri("scp", uri, userp, hostp, portp, pathp);-
618 if (r == 0 && *pathp == NULL)
r == 0Description
TRUEnever evaluated
FALSEnever evaluated
*pathp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
619 *pathp = xstrdup(".");
never executed: *pathp = xstrdup(".");
0
620 return r;
never executed: return r;
0
621}-
622-
623void-
624toremote(int argc, char **argv)-
625{-
626 char *suser = NULL, *host = NULL, *src = NULL;-
627 char *bp, *tuser, *thost, *targ;-
628 int sport = -1, tport = -1;-
629 arglist alist;-
630 int i, r;-
631 u_int j;-
632-
633 memset(&alist, '\0', sizeof(alist));-
634 alist.list = NULL;-
635-
636 /* Parse target */-
637 r = parse_scp_uri(argv[argc - 1], &tuser, &thost, &tport, &targ);-
638 if (r == -1) {
r == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
639 fmprintf(stderr, "%s: invalid uri\n", argv[argc - 1]);-
640 ++errs;-
641 goto out;
never executed: goto out;
0
642 }-
643 if (r != 0) {
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
644 if (parse_user_host_path(argv[argc - 1], &tuser, &thost,
parse_user_hos..., &targ) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
645 &targ) == -1) {
parse_user_hos..., &targ) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
646 fmprintf(stderr, "%s: invalid target\n", argv[argc - 1]);-
647 ++errs;-
648 goto out;
never executed: goto out;
0
649 }-
650 }
never executed: end of block
0
651 if (tuser != NULL && !okname(tuser)) {
tuser != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
!okname(tuser)Description
TRUEnever evaluated
FALSEnever evaluated
0
652 ++errs;-
653 goto out;
never executed: goto out;
0
654 }-
655-
656 /* Parse source files */-
657 for (i = 0; i < argc - 1; i++) {
i < argc - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
658 free(suser);-
659 free(host);-
660 free(src);-
661 r = parse_scp_uri(argv[i], &suser, &host, &sport, &src);-
662 if (r == -1) {
r == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
663 fmprintf(stderr, "%s: invalid uri\n", argv[i]);-
664 ++errs;-
665 continue;
never executed: continue;
0
666 }-
667 if (r != 0) {
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
668 parse_user_host_path(argv[i], &suser, &host, &src);-
669 }
never executed: end of block
0
670 if (suser != NULL && !okname(suser)) {
suser != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
!okname(suser)Description
TRUEnever evaluated
FALSEnever evaluated
0
671 ++errs;-
672 continue;
never executed: continue;
0
673 }-
674 if (host && throughlocal) { /* extended remote to remote */
hostDescription
TRUEnever evaluated
FALSEnever evaluated
throughlocalDescription
TRUEnever evaluated
FALSEnever evaluated
0
675 xasprintf(&bp, "%s -f %s%s", cmd,-
676 *src == '-' ? "-- " : "", src);-
677 if (do_cmd(host, suser, sport, bp, &remin, &remout) < 0)
do_cmd(host, s..., &remout) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
678 exit(1);
never executed: exit(1);
0
679 free(bp);-
680 xasprintf(&bp, "%s -t %s%s", cmd,-
681 *targ == '-' ? "-- " : "", targ);-
682 if (do_cmd2(thost, tuser, tport, bp, remin, remout) < 0)
do_cmd2(thost,...n, remout) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
683 exit(1);
never executed: exit(1);
0
684 free(bp);-
685 (void) close(remin);-
686 (void) close(remout);-
687 remin = remout = -1;-
688 } else if (host) { /* standard remote to remote */
never executed: end of block
hostDescription
TRUEnever evaluated
FALSEnever evaluated
0
689 if (tport != -1 && tport != SSH_DEFAULT_PORT) {
tport != -1Description
TRUEnever evaluated
FALSEnever evaluated
tport != 22Description
TRUEnever evaluated
FALSEnever evaluated
0
690 /* This would require the remote support URIs */-
691 fatal("target port not supported with two "-
692 "remote hosts without the -3 option");-
693 }
never executed: end of block
0
694-
695 freeargs(&alist);-
696 addargs(&alist, "%s", ssh_program);-
697 addargs(&alist, "-x");-
698 addargs(&alist, "-oClearAllForwardings=yes");-
699 addargs(&alist, "-n");-
700 for (j = 0; j < remote_remote_args.num; j++) {
j < remote_remote_args.numDescription
TRUEnever evaluated
FALSEnever evaluated
0
701 addargs(&alist, "%s",-
702 remote_remote_args.list[j]);-
703 }
never executed: end of block
0
704-
705 if (sport != -1) {
sport != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
706 addargs(&alist, "-p");-
707 addargs(&alist, "%d", sport);-
708 }
never executed: end of block
0
709 if (suser) {
suserDescription
TRUEnever evaluated
FALSEnever evaluated
0
710 addargs(&alist, "-l");-
711 addargs(&alist, "%s", suser);-
712 }
never executed: end of block
0
713 addargs(&alist, "--");-
714 addargs(&alist, "%s", host);-
715 addargs(&alist, "%s", cmd);-
716 addargs(&alist, "%s", src);-
717 addargs(&alist, "%s%s%s:%s",-
718 tuser ? tuser : "", tuser ? "@" : "",-
719 thost, targ);-
720 if (do_local_cmd(&alist) != 0)
do_local_cmd(&alist) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
721 errs = 1;
never executed: errs = 1;
0
722 } else { /* local to remote */
never executed: end of block
0
723 if (remin == -1) {
remin == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
724 xasprintf(&bp, "%s -t %s%s", cmd,-
725 *targ == '-' ? "-- " : "", targ);-
726 if (do_cmd(thost, tuser, tport, bp, &remin,
do_cmd(thost, ..., &remout) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
727 &remout) < 0)
do_cmd(thost, ..., &remout) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
728 exit(1);
never executed: exit(1);
0
729 if (response() < 0)
response() < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
730 exit(1);
never executed: exit(1);
0
731 free(bp);-
732 }
never executed: end of block
0
733 source(1, argv + i);-
734 }
never executed: end of block
0
735 }-
736out:
code before this statement never executed: out:
0
737 free(tuser);-
738 free(thost);-
739 free(targ);-
740 free(suser);-
741 free(host);-
742 free(src);-
743}
never executed: end of block
0
744-
745void-
746tolocal(int argc, char **argv)-
747{-
748 char *bp, *host = NULL, *src = NULL, *suser = NULL;-
749 arglist alist;-
750 int i, r, sport = -1;-
751-
752 memset(&alist, '\0', sizeof(alist));-
753 alist.list = NULL;-
754-
755 for (i = 0; i < argc - 1; i++) {
i < argc - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
756 free(suser);-
757 free(host);-
758 free(src);-
759 r = parse_scp_uri(argv[i], &suser, &host, &sport, &src);-
760 if (r == -1) {
r == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
761 fmprintf(stderr, "%s: invalid uri\n", argv[i]);-
762 ++errs;-
763 continue;
never executed: continue;
0
764 }-
765 if (r != 0)
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
766 parse_user_host_path(argv[i], &suser, &host, &src);
never executed: parse_user_host_path(argv[i], &suser, &host, &src);
0
767 if (suser != NULL && !okname(suser)) {
suser != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
!okname(suser)Description
TRUEnever evaluated
FALSEnever evaluated
0
768 ++errs;-
769 continue;
never executed: continue;
0
770 }-
771 if (!host) { /* Local to local. */
!hostDescription
TRUEnever evaluated
FALSEnever evaluated
0
772 freeargs(&alist);-
773 addargs(&alist, "%s", _PATH_CP);-
774 if (iamrecursive)
iamrecursiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
775 addargs(&alist, "-r");
never executed: addargs(&alist, "-r");
0
776 if (pflag)
pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
777 addargs(&alist, "-p");
never executed: addargs(&alist, "-p");
0
778 addargs(&alist, "--");-
779 addargs(&alist, "%s", argv[i]);-
780 addargs(&alist, "%s", argv[argc-1]);-
781 if (do_local_cmd(&alist))
do_local_cmd(&alist)Description
TRUEnever evaluated
FALSEnever evaluated
0
782 ++errs;
never executed: ++errs;
0
783 continue;
never executed: continue;
0
784 }-
785 /* Remote to local. */-
786 xasprintf(&bp, "%s -f %s%s",-
787 cmd, *src == '-' ? "-- " : "", src);-
788 if (do_cmd(host, suser, sport, bp, &remin, &remout) < 0) {
do_cmd(host, s..., &remout) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
789 free(bp);-
790 ++errs;-
791 continue;
never executed: continue;
0
792 }-
793 free(bp);-
794 sink(1, argv + argc - 1);-
795 (void) close(remin);-
796 remin = remout = -1;-
797 }
never executed: end of block
0
798 free(suser);-
799 free(host);-
800 free(src);-
801}
never executed: end of block
0
802-
803void-
804source(int argc, char **argv)-
805{-
806 struct stat stb;-
807 static BUF buffer;-
808 BUF *bp;-
809 off_t i, statbytes;-
810 size_t amt, nr;-
811 int fd = -1, haderr, indx;-
812 char *last, *name, buf[2048], encname[PATH_MAX];-
813 int len;-
814-
815 for (indx = 0; indx < argc; ++indx) {
indx < argcDescription
TRUEnever evaluated
FALSEnever evaluated
0
816 name = argv[indx];-
817 statbytes = 0;-
818 len = strlen(name);-
819 while (len > 1 && name[len-1] == '/')
len > 1Description
TRUEnever evaluated
FALSEnever evaluated
name[len-1] == '/'Description
TRUEnever evaluated
FALSEnever evaluated
0
820 name[--len] = '\0';
never executed: name[--len] = '\0';
0
821 if ((fd = open(name, O_RDONLY|O_NONBLOCK, 0)) < 0)
(fd = open(nam...4000 , 0)) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
822 goto syserr;
never executed: goto syserr;
0
823 if (strchr(name, '\n') != NULL) {
(__extension__...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( '\n' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEnever evaluated
( '\n' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
824 strnvis(encname, name, sizeof(encname), VIS_NL);-
825 name = encname;-
826 }
never executed: end of block
0
827 if (fstat(fd, &stb) < 0) {
fstat(fd, &stb) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
828syserr: run_err("%s: %s", name, strerror(errno));-
829 goto next;
never executed: goto next;
0
830 }-
831 if (stb.st_size < 0) {
stb.st_size < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
832 run_err("%s: %s", name, "Negative file size");-
833 goto next;
never executed: goto next;
0
834 }-
835 unset_nonblock(fd);-
836 switch (stb.st_mode & S_IFMT) {-
837 case S_IFREG:
never executed: case 0100000 :
0
838 break;
never executed: break;
0
839 case S_IFDIR:
never executed: case 0040000 :
0
840 if (iamrecursive) {
iamrecursiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
841 rsource(name, &stb);-
842 goto next;
never executed: goto next;
0
843 }-
844 /* FALLTHROUGH */-
845 default:
code before this statement never executed: default:
never executed: default:
0
846 run_err("%s: not a regular file", name);-
847 goto next;
never executed: goto next;
0
848 }-
849 if ((last = strrchr(name, '/')) == NULL)
(last = strrch...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
850 last = name;
never executed: last = name;
0
851 else-
852 ++last;
never executed: ++last;
0
853 curfile = last;-
854 if (pflag) {
pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
855 if (do_times(remout, verbose_mode, &stb) < 0)
do_times(remou...ode, &stb) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
856 goto next;
never executed: goto next;
0
857 }
never executed: end of block
0
858#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)-
859 snprintf(buf, sizeof buf, "C%04o %lld %s\n",-
860 (u_int) (stb.st_mode & FILEMODEMASK),-
861 (long long)stb.st_size, last);-
862 if (verbose_mode)
verbose_modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
863 fmprintf(stderr, "Sending file modes: %s", buf);
never executed: fmprintf( stderr , "Sending file modes: %s", buf);
0
864 (void) atomicio(vwrite, remout, buf, strlen(buf));-
865 if (response() < 0)
response() < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
866 goto next;
never executed: goto next;
0
867 if ((bp = allocbuf(&buffer, fd, COPY_BUFLEN)) == NULL) {
(bp = allocbuf...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
868next: if (fd != -1) {
fd != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
869 (void) close(fd);-
870 fd = -1;-
871 }
never executed: end of block
0
872 continue;
never executed: continue;
0
873 }-
874 if (showprogress)
showprogressDescription
TRUEnever evaluated
FALSEnever evaluated
0
875 start_progress_meter(curfile, stb.st_size, &statbytes);
never executed: start_progress_meter(curfile, stb.st_size, &statbytes);
0
876 set_nonblock(remout);-
877 for (haderr = i = 0; i < stb.st_size; i += bp->cnt) {
i < stb.st_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
878 amt = bp->cnt;-
879 if (i + (off_t)amt > stb.st_size)
i + (off_t)amt > stb.st_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
880 amt = stb.st_size - i;
never executed: amt = stb.st_size - i;
0
881 if (!haderr) {
!haderrDescription
TRUEnever evaluated
FALSEnever evaluated
0
882 if ((nr = atomicio(read, fd,
(nr = atomicio..., amt)) != amtDescription
TRUEnever evaluated
FALSEnever evaluated
0
883 bp->buf, amt)) != amt) {
(nr = atomicio..., amt)) != amtDescription
TRUEnever evaluated
FALSEnever evaluated
0
884 haderr = errno;-
885 memset(bp->buf + nr, 0, amt - nr);-
886 }
never executed: end of block
0
887 }
never executed: end of block
0
888 /* Keep writing after error to retain sync */-
889 if (haderr) {
haderrDescription
TRUEnever evaluated
FALSEnever evaluated
0
890 (void)atomicio(vwrite, remout, bp->buf, amt);-
891 memset(bp->buf, 0, amt);-
892 continue;
never executed: continue;
0
893 }-
894 if (atomicio6(vwrite, remout, bp->buf, amt, scpio,
atomicio6((ssi...tbytes) != amtDescription
TRUEnever evaluated
FALSEnever evaluated
0
895 &statbytes) != amt)
atomicio6((ssi...tbytes) != amtDescription
TRUEnever evaluated
FALSEnever evaluated
0
896 haderr = errno;
never executed: haderr = (*__errno_location ()) ;
0
897 }
never executed: end of block
0
898 unset_nonblock(remout);-
899-
900 if (fd != -1) {
fd != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
901 if (close(fd) < 0 && !haderr)
close(fd) < 0Description
TRUEnever evaluated
FALSEnever evaluated
!haderrDescription
TRUEnever evaluated
FALSEnever evaluated
0
902 haderr = errno;
never executed: haderr = (*__errno_location ()) ;
0
903 fd = -1;-
904 }
never executed: end of block
0
905 if (!haderr)
!haderrDescription
TRUEnever evaluated
FALSEnever evaluated
0
906 (void) atomicio(vwrite, remout, "", 1);
never executed: (void) atomicio((ssize_t (*)(int, void *, size_t))write, remout, "", 1);
0
907 else-
908 run_err("%s: %s", name, strerror(haderr));
never executed: run_err("%s: %s", name, strerror(haderr));
0
909 (void) response();-
910 if (showprogress)
showprogressDescription
TRUEnever evaluated
FALSEnever evaluated
0
911 stop_progress_meter();
never executed: stop_progress_meter();
0
912 }
never executed: end of block
0
913}
never executed: end of block
0
914-
915void-
916rsource(char *name, struct stat *statp)-
917{-
918 DIR *dirp;-
919 struct dirent *dp;-
920 char *last, *vect[1], path[PATH_MAX];-
921-
922 if (!(dirp = opendir(name))) {
!(dirp = opendir(name))Description
TRUEnever evaluated
FALSEnever evaluated
0
923 run_err("%s: %s", name, strerror(errno));-
924 return;
never executed: return;
0
925 }-
926 last = strrchr(name, '/');-
927 if (last == NULL)
last == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
928 last = name;
never executed: last = name;
0
929 else-
930 last++;
never executed: last++;
0
931 if (pflag) {
pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
932 if (do_times(remout, verbose_mode, statp) < 0) {
do_times(remou...de, statp) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
933 closedir(dirp);-
934 return;
never executed: return;
0
935 }-
936 }
never executed: end of block
0
937 (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",-
938 (u_int) (statp->st_mode & FILEMODEMASK), 0, last);-
939 if (verbose_mode)
verbose_modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
940 fmprintf(stderr, "Entering directory: %s", path);
never executed: fmprintf( stderr , "Entering directory: %s", path);
0
941 (void) atomicio(vwrite, remout, path, strlen(path));-
942 if (response() < 0) {
response() < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
943 closedir(dirp);-
944 return;
never executed: return;
0
945 }-
946 while ((dp = readdir(dirp)) != NULL) {
(dp = readdir(...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
947 if (dp->d_ino == 0)
dp->d_ino == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
948 continue;
never executed: continue;
0
949 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
never executed: __result = (((const unsigned char *) (const char *) ( dp->d_name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "." ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( dp->d_name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ".." ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
! __extension_..., "." )))); })Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
! __extension_... ".." )))); })Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
950 continue;
never executed: continue;
0
951 if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) {
strlen(name) +...zeof(path) - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
952 run_err("%s/%s: name too long", name, dp->d_name);-
953 continue;
never executed: continue;
0
954 }-
955 (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name);-
956 vect[0] = path;-
957 source(1, vect);-
958 }
never executed: end of block
0
959 (void) closedir(dirp);-
960 (void) atomicio(vwrite, remout, "E\n", 2);-
961 (void) response();-
962}
never executed: end of block
0
963-
964#define TYPE_OVERFLOW(type, val) \-
965 ((sizeof(type) == 4 && (val) > INT32_MAX) || \-
966 (sizeof(type) == 8 && (val) > INT64_MAX) || \-
967 (sizeof(type) != 4 && sizeof(type) != 8))-
968-
969void-
970sink(int argc, char **argv)-
971{-
972 static BUF buffer;-
973 struct stat stb;-
974 enum {-
975 YES, NO, DISPLAYED-
976 } wrerr;-
977 BUF *bp;-
978 off_t i;-
979 size_t j, count;-
980 int amt, exists, first, ofd;-
981 mode_t mode, omode, mask;-
982 off_t size, statbytes;-
983 unsigned long long ull;-
984 int setimes, targisdir, wrerrno = 0;-
985 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048], visbuf[2048];-
986 struct timeval tv[2];-
987-
988#define atime tv[0]-
989#define mtime tv[1]-
990#define SCREWUP(str) { why = str; goto screwup; }-
991-
992 if (TYPE_OVERFLOW(time_t, 0) || TYPE_OVERFLOW(off_t, 0))
sizeof(time_t) == 4Description
TRUEnever evaluated
FALSEnever evaluated
(0) > (2147483647)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) == 8Description
TRUEnever evaluated
FALSEnever evaluated
(0) > (9223372036854775807L)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) != 4Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) != 8Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) == 4Description
TRUEnever evaluated
FALSEnever evaluated
(0) > (2147483647)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) == 8Description
TRUEnever evaluated
FALSEnever evaluated
(0) > (9223372036854775807L)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) != 4Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) != 8Description
TRUEnever evaluated
FALSEnever evaluated
0
993 SCREWUP("Unexpected off_t/time_t size");
never executed: goto screwup;
0
994-
995 setimes = targisdir = 0;-
996 mask = umask(0);-
997 if (!pflag)
!pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
998 (void) umask(mask);
never executed: (void) umask(mask);
0
999 if (argc != 1) {
argc != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1000 run_err("ambiguous target");-
1001 exit(1);
never executed: exit(1);
0
1002 }-
1003 targ = *argv;-
1004 if (targetshouldbedirectory)
targetshouldbedirectoryDescription
TRUEnever evaluated
FALSEnever evaluated
0
1005 verifydir(targ);
never executed: verifydir(targ);
0
1006-
1007 (void) atomicio(vwrite, remout, "", 1);-
1008 if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
stat(targ, &stb) == 0Description
TRUEnever evaluated
FALSEnever evaluated
(((( stb.st_mo... == (0040000))Description
TRUEnever evaluated
FALSEnever evaluated
0
1009 targisdir = 1;
never executed: targisdir = 1;
0
1010 for (first = 1;; first = 0) {-
1011 cp = buf;-
1012 if (atomicio(read, remin, cp, 1) != 1)
atomicio(read,...n, cp, 1) != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1013 return;
never executed: return;
0
1014 if (*cp++ == '\n')
*cp++ == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1015 SCREWUP("unexpected <newline>");
never executed: goto screwup;
0
1016 do {-
1017 if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
atomicio(read,... != sizeof(ch)Description
TRUEnever evaluated
FALSEnever evaluated
0
1018 SCREWUP("lost connection");
never executed: goto screwup;
0
1019 *cp++ = ch;-
1020 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
never executed: end of block
cp < &buf[sizeof(buf) - 1]Description
TRUEnever evaluated
FALSEnever evaluated
ch != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1021 *cp = 0;-
1022 if (verbose_mode)
verbose_modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1023 fmprintf(stderr, "Sink: %s", buf);
never executed: fmprintf( stderr , "Sink: %s", buf);
0
1024-
1025 if (buf[0] == '\01' || buf[0] == '\02') {
buf[0] == '\01'Description
TRUEnever evaluated
FALSEnever evaluated
buf[0] == '\02'Description
TRUEnever evaluated
FALSEnever evaluated
0
1026 if (iamremote == 0) {
iamremote == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1027 (void) snmprintf(visbuf, sizeof(visbuf),-
1028 NULL, "%s", buf + 1);-
1029 (void) atomicio(vwrite, STDERR_FILENO,-
1030 visbuf, strlen(visbuf));-
1031 }
never executed: end of block
0
1032 if (buf[0] == '\02')
buf[0] == '\02'Description
TRUEnever evaluated
FALSEnever evaluated
0
1033 exit(1);
never executed: exit(1);
0
1034 ++errs;-
1035 continue;
never executed: continue;
0
1036 }-
1037 if (buf[0] == 'E') {
buf[0] == 'E'Description
TRUEnever evaluated
FALSEnever evaluated
0
1038 (void) atomicio(vwrite, remout, "", 1);-
1039 return;
never executed: return;
0
1040 }-
1041 if (ch == '\n')
ch == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1042 *--cp = 0;
never executed: *--cp = 0;
0
1043-
1044 cp = buf;-
1045 if (*cp == 'T') {
*cp == 'T'Description
TRUEnever evaluated
FALSEnever evaluated
0
1046 setimes++;-
1047 cp++;-
1048 if (!isdigit((unsigned char)*cp))
! ((*__ctype_b...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
1049 SCREWUP("mtime.sec not present");
never executed: goto screwup;
0
1050 ull = strtoull(cp, &cp, 10);-
1051 if (!cp || *cp++ != ' ')
!cpDescription
TRUEnever evaluated
FALSEnever evaluated
*cp++ != ' 'Description
TRUEnever evaluated
FALSEnever evaluated
0
1052 SCREWUP("mtime.sec not delimited");
never executed: goto screwup;
0
1053 if (TYPE_OVERFLOW(time_t, ull))
sizeof(time_t) == 4Description
TRUEnever evaluated
FALSEnever evaluated
(ull) > (2147483647)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) == 8Description
TRUEnever evaluated
FALSEnever evaluated
(ull) > (9223372036854775807L)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) != 4Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) != 8Description
TRUEnever evaluated
FALSEnever evaluated
0
1054 setimes = 0; /* out of range */
never executed: setimes = 0;
0
1055 mtime.tv_sec = ull;-
1056 mtime.tv_usec = strtol(cp, &cp, 10);-
1057 if (!cp || *cp++ != ' ' || mtime.tv_usec < 0 ||
!cpDescription
TRUEnever evaluated
FALSEnever evaluated
*cp++ != ' 'Description
TRUEnever evaluated
FALSEnever evaluated
tv[1].tv_usec < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1058 mtime.tv_usec > 999999)
tv[1].tv_usec > 999999Description
TRUEnever evaluated
FALSEnever evaluated
0
1059 SCREWUP("mtime.usec not delimited");
never executed: goto screwup;
0
1060 if (!isdigit((unsigned char)*cp))
! ((*__ctype_b...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
1061 SCREWUP("atime.sec not present");
never executed: goto screwup;
0
1062 ull = strtoull(cp, &cp, 10);-
1063 if (!cp || *cp++ != ' ')
!cpDescription
TRUEnever evaluated
FALSEnever evaluated
*cp++ != ' 'Description
TRUEnever evaluated
FALSEnever evaluated
0
1064 SCREWUP("atime.sec not delimited");
never executed: goto screwup;
0
1065 if (TYPE_OVERFLOW(time_t, ull))
sizeof(time_t) == 4Description
TRUEnever evaluated
FALSEnever evaluated
(ull) > (2147483647)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) == 8Description
TRUEnever evaluated
FALSEnever evaluated
(ull) > (9223372036854775807L)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) != 4Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(time_t) != 8Description
TRUEnever evaluated
FALSEnever evaluated
0
1066 setimes = 0; /* out of range */
never executed: setimes = 0;
0
1067 atime.tv_sec = ull;-
1068 atime.tv_usec = strtol(cp, &cp, 10);-
1069 if (!cp || *cp++ != '\0' || atime.tv_usec < 0 ||
!cpDescription
TRUEnever evaluated
FALSEnever evaluated
*cp++ != '\0'Description
TRUEnever evaluated
FALSEnever evaluated
tv[0].tv_usec < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1070 atime.tv_usec > 999999)
tv[0].tv_usec > 999999Description
TRUEnever evaluated
FALSEnever evaluated
0
1071 SCREWUP("atime.usec not delimited");
never executed: goto screwup;
0
1072 (void) atomicio(vwrite, remout, "", 1);-
1073 continue;
never executed: continue;
0
1074 }-
1075 if (*cp != 'C' && *cp != 'D') {
*cp != 'C'Description
TRUEnever evaluated
FALSEnever evaluated
*cp != 'D'Description
TRUEnever evaluated
FALSEnever evaluated
0
1076 /*-
1077 * Check for the case "rcp remote:foo\* local:bar".-
1078 * In this case, the line "No match." can be returned-
1079 * by the shell before the rcp command on the remote is-
1080 * executed so the ^Aerror_message convention isn't-
1081 * followed.-
1082 */-
1083 if (first) {
firstDescription
TRUEnever evaluated
FALSEnever evaluated
0
1084 run_err("%s", cp);-
1085 exit(1);
never executed: exit(1);
0
1086 }-
1087 SCREWUP("expected control record");
never executed: goto screwup;
0
1088 }-
1089 mode = 0;-
1090 for (++cp; cp < buf + 5; cp++) {
cp < buf + 5Description
TRUEnever evaluated
FALSEnever evaluated
0
1091 if (*cp < '0' || *cp > '7')
*cp < '0'Description
TRUEnever evaluated
FALSEnever evaluated
*cp > '7'Description
TRUEnever evaluated
FALSEnever evaluated
0
1092 SCREWUP("bad mode");
never executed: goto screwup;
0
1093 mode = (mode << 3) | (*cp - '0');-
1094 }
never executed: end of block
0
1095 if (!pflag)
!pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
1096 mode &= ~mask;
never executed: mode &= ~mask;
0
1097 if (*cp++ != ' ')
*cp++ != ' 'Description
TRUEnever evaluated
FALSEnever evaluated
0
1098 SCREWUP("mode not delimited");
never executed: goto screwup;
0
1099-
1100 if (!isdigit((unsigned char)*cp))
! ((*__ctype_b...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
1101 SCREWUP("size not present");
never executed: goto screwup;
0
1102 ull = strtoull(cp, &cp, 10);-
1103 if (!cp || *cp++ != ' ')
!cpDescription
TRUEnever evaluated
FALSEnever evaluated
*cp++ != ' 'Description
TRUEnever evaluated
FALSEnever evaluated
0
1104 SCREWUP("size not delimited");
never executed: goto screwup;
0
1105 if (TYPE_OVERFLOW(off_t, ull))
sizeof(off_t) == 4Description
TRUEnever evaluated
FALSEnever evaluated
(ull) > (2147483647)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) == 8Description
TRUEnever evaluated
FALSEnever evaluated
(ull) > (9223372036854775807L)Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) != 4Description
TRUEnever evaluated
FALSEnever evaluated
sizeof(off_t) != 8Description
TRUEnever evaluated
FALSEnever evaluated
0
1106 SCREWUP("size out of range");
never executed: goto screwup;
0
1107 size = (off_t)ull;-
1108-
1109 if ((strchr(cp, '/') != NULL) || (strcmp(cp, "..") == 0)) {
never executed: __result = (((const unsigned char *) (const char *) ( cp ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ".." ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( (__extension... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( '/' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_constant_p ( cp )Description
TRUEnever evaluated
FALSEnever evaluated
( '/' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1110 run_err("error: unexpected filename: %s", cp);-
1111 exit(1);
never executed: exit(1);
0
1112 }-
1113 if (targisdir) {
targisdirDescription
TRUEnever evaluated
FALSEnever evaluated
0
1114 static char *namebuf;-
1115 static size_t cursize;-
1116 size_t need;-
1117-
1118 need = strlen(targ) + strlen(cp) + 250;-
1119 if (need > cursize) {
need > cursizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1120 free(namebuf);-
1121 namebuf = xmalloc(need);-
1122 cursize = need;-
1123 }
never executed: end of block
0
1124 (void) snprintf(namebuf, need, "%s%s%s", targ,-
1125 strcmp(targ, "/") ? "/" : "", cp);
never executed: __result = (((const unsigned char *) (const char *) ( targ ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "/" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1126 np = namebuf;-
1127 } else
never executed: end of block
0
1128 np = targ;
never executed: np = targ;
0
1129 curfile = cp;-
1130 exists = stat(np, &stb) == 0;-
1131 if (buf[0] == 'D') {
buf[0] == 'D'Description
TRUEnever evaluated
FALSEnever evaluated
0
1132 int mod_flag = pflag;-
1133 if (!iamrecursive)
!iamrecursiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
1134 SCREWUP("received directory without -r");
never executed: goto screwup;
0
1135 if (exists) {
existsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1136 if (!S_ISDIR(stb.st_mode)) {
! (((( stb.st_... == (0040000))Description
TRUEnever evaluated
FALSEnever evaluated
0
1137 errno = ENOTDIR;-
1138 goto bad;
never executed: goto bad;
0
1139 }-
1140 if (pflag)
pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
1141 (void) chmod(np, mode);
never executed: (void) chmod(np, mode);
0
1142 } else {
never executed: end of block
0
1143 /* Handle copying from a read-only-
1144 directory */-
1145 mod_flag = 1;-
1146 if (mkdir(np, mode | S_IRWXU) < 0)
mkdir(np, mode...00|0100) ) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1147 goto bad;
never executed: goto bad;
0
1148 }
never executed: end of block
0
1149 vect[0] = xstrdup(np);-
1150 sink(1, vect);-
1151 if (setimes) {
setimesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1152 setimes = 0;-
1153 if (utimes(vect[0], tv) < 0)
utimes(vect[0], tv) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1154 run_err("%s: set times: %s",
never executed: run_err("%s: set times: %s", vect[0], strerror( (*__errno_location ()) ));
0
1155 vect[0], strerror(errno));
never executed: run_err("%s: set times: %s", vect[0], strerror( (*__errno_location ()) ));
0
1156 }
never executed: end of block
0
1157 if (mod_flag)
mod_flagDescription
TRUEnever evaluated
FALSEnever evaluated
0
1158 (void) chmod(vect[0], mode);
never executed: (void) chmod(vect[0], mode);
0
1159 free(vect[0]);-
1160 continue;
never executed: continue;
0
1161 }-
1162 omode = mode;-
1163 mode |= S_IWUSR;-
1164 if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) < 0) {
(ofd = open(np...0 , mode)) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1165bad: run_err("%s: %s", np, strerror(errno));-
1166 continue;
never executed: continue;
0
1167 }-
1168 (void) atomicio(vwrite, remout, "", 1);-
1169 if ((bp = allocbuf(&buffer, ofd, COPY_BUFLEN)) == NULL) {
(bp = allocbuf...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1170 (void) close(ofd);-
1171 continue;
never executed: continue;
0
1172 }-
1173 cp = bp->buf;-
1174 wrerr = NO;-
1175-
1176 statbytes = 0;-
1177 if (showprogress)
showprogressDescription
TRUEnever evaluated
FALSEnever evaluated
0
1178 start_progress_meter(curfile, size, &statbytes);
never executed: start_progress_meter(curfile, size, &statbytes);
0
1179 set_nonblock(remin);-
1180 for (count = i = 0; i < size; i += bp->cnt) {
i < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1181 amt = bp->cnt;-
1182 if (i + amt > size)
i + amt > sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1183 amt = size - i;
never executed: amt = size - i;
0
1184 count += amt;-
1185 do {-
1186 j = atomicio6(read, remin, cp, amt,-
1187 scpio, &statbytes);-
1188 if (j == 0) {
j == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1189 run_err("%s", j != EPIPE ?-
1190 strerror(errno) :-
1191 "dropped connection");-
1192 exit(1);
never executed: exit(1);
0
1193 }-
1194 amt -= j;-
1195 cp += j;-
1196 } while (amt > 0);
never executed: end of block
amt > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1197-
1198 if (count == bp->cnt) {
count == bp->cntDescription
TRUEnever evaluated
FALSEnever evaluated
0
1199 /* Keep reading so we stay sync'd up. */-
1200 if (wrerr == NO) {
wrerr == NODescription
TRUEnever evaluated
FALSEnever evaluated
0
1201 if (atomicio(vwrite, ofd, bp->buf,
atomicio((ssiz...ount) != countDescription
TRUEnever evaluated
FALSEnever evaluated
0
1202 count) != count) {
atomicio((ssiz...ount) != countDescription
TRUEnever evaluated
FALSEnever evaluated
0
1203 wrerr = YES;-
1204 wrerrno = errno;-
1205 }
never executed: end of block
0
1206 }
never executed: end of block
0
1207 count = 0;-
1208 cp = bp->buf;-
1209 }
never executed: end of block
0
1210 }
never executed: end of block
0
1211 unset_nonblock(remin);-
1212 if (count != 0 && wrerr == NO &&
count != 0Description
TRUEnever evaluated
FALSEnever evaluated
wrerr == NODescription
TRUEnever evaluated
FALSEnever evaluated
0
1213 atomicio(vwrite, ofd, bp->buf, count) != count) {
atomicio((ssiz...ount) != countDescription
TRUEnever evaluated
FALSEnever evaluated
0
1214 wrerr = YES;-
1215 wrerrno = errno;-
1216 }
never executed: end of block
0
1217 if (wrerr == NO && (!exists || S_ISREG(stb.st_mode)) &&
wrerr == NODescription
TRUEnever evaluated
FALSEnever evaluated
!existsDescription
TRUEnever evaluated
FALSEnever evaluated
(((( stb.st_mo... == (0100000))Description
TRUEnever evaluated
FALSEnever evaluated
0
1218 ftruncate(ofd, size) != 0) {
ftruncate(ofd, size) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1219 run_err("%s: truncate: %s", np, strerror(errno));-
1220 wrerr = DISPLAYED;-
1221 }
never executed: end of block
0
1222 if (pflag) {
pflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
1223 if (exists || omode != mode)
existsDescription
TRUEnever evaluated
FALSEnever evaluated
omode != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1224#ifdef HAVE_FCHMOD-
1225 if (fchmod(ofd, omode)) {
fchmod(ofd, omode)Description
TRUEnever evaluated
FALSEnever evaluated
0
1226#else /* HAVE_FCHMOD */-
1227 if (chmod(np, omode)) {-
1228#endif /* HAVE_FCHMOD */-
1229 run_err("%s: set mode: %s",-
1230 np, strerror(errno));-
1231 wrerr = DISPLAYED;-
1232 }
never executed: end of block
0
1233 } else {
never executed: end of block
0
1234 if (!exists && omode != mode)
!existsDescription
TRUEnever evaluated
FALSEnever evaluated
omode != modeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1235#ifdef HAVE_FCHMOD-
1236 if (fchmod(ofd, omode & ~mask)) {
fchmod(ofd, omode & ~mask)Description
TRUEnever evaluated
FALSEnever evaluated
0
1237#else /* HAVE_FCHMOD */-
1238 if (chmod(np, omode & ~mask)) {-
1239#endif /* HAVE_FCHMOD */-
1240 run_err("%s: set mode: %s",-
1241 np, strerror(errno));-
1242 wrerr = DISPLAYED;-
1243 }
never executed: end of block
0
1244 }
never executed: end of block
0
1245 if (close(ofd) == -1) {
close(ofd) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1246 wrerr = YES;-
1247 wrerrno = errno;-
1248 }
never executed: end of block
0
1249 (void) response();-
1250 if (showprogress)
showprogressDescription
TRUEnever evaluated
FALSEnever evaluated
0
1251 stop_progress_meter();
never executed: stop_progress_meter();
0
1252 if (setimes && wrerr == NO) {
setimesDescription
TRUEnever evaluated
FALSEnever evaluated
wrerr == NODescription
TRUEnever evaluated
FALSEnever evaluated
0
1253 setimes = 0;-
1254 if (utimes(np, tv) < 0) {
utimes(np, tv) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1255 run_err("%s: set times: %s",-
1256 np, strerror(errno));-
1257 wrerr = DISPLAYED;-
1258 }
never executed: end of block
0
1259 }
never executed: end of block
0
1260 switch (wrerr) {-
1261 case YES:
never executed: case YES:
0
1262 run_err("%s: %s", np, strerror(wrerrno));-
1263 break;
never executed: break;
0
1264 case NO:
never executed: case NO:
0
1265 (void) atomicio(vwrite, remout, "", 1);-
1266 break;
never executed: break;
0
1267 case DISPLAYED:
never executed: case DISPLAYED:
0
1268 break;
never executed: break;
0
1269 }-
1270 }
never executed: end of block
0
1271screwup:
code before this statement never executed: screwup:
0
1272 run_err("protocol error: %s", why);-
1273 exit(1);
never executed: exit(1);
0
1274}-
1275-
1276int-
1277response(void)-
1278{-
1279 char ch, *cp, resp, rbuf[2048], visbuf[2048];-
1280-
1281 if (atomicio(read, remin, &resp, sizeof(resp)) != sizeof(resp))
atomicio(read,...= sizeof(resp)Description
TRUEnever evaluated
FALSEnever evaluated
0
1282 lostconn(0);
never executed: lostconn(0);
0
1283-
1284 cp = rbuf;-
1285 switch (resp) {-
1286 case 0: /* ok */
never executed: case 0:
0
1287 return (0);
never executed: return (0);
0
1288 default:
never executed: default:
0
1289 *cp++ = resp;-
1290 /* FALLTHROUGH */-
1291 case 1: /* error, followed by error msg */
code before this statement never executed: case 1:
never executed: case 1:
0
1292 case 2: /* fatal error, "" */
never executed: case 2:
0
1293 do {-
1294 if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
atomicio(read,... != sizeof(ch)Description
TRUEnever evaluated
FALSEnever evaluated
0
1295 lostconn(0);
never executed: lostconn(0);
0
1296 *cp++ = ch;-
1297 } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
never executed: end of block
cp < &rbuf[sizeof(rbuf) - 1]Description
TRUEnever evaluated
FALSEnever evaluated
ch != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1298-
1299 if (!iamremote) {
!iamremoteDescription
TRUEnever evaluated
FALSEnever evaluated
0
1300 cp[-1] = '\0';-
1301 (void) snmprintf(visbuf, sizeof(visbuf),-
1302 NULL, "%s\n", rbuf);-
1303 (void) atomicio(vwrite, STDERR_FILENO,-
1304 visbuf, strlen(visbuf));-
1305 }
never executed: end of block
0
1306 ++errs;-
1307 if (resp == 1)
resp == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1308 return (-1);
never executed: return (-1);
0
1309 exit(1);
never executed: exit(1);
0
1310 }-
1311 /* NOTREACHED */-
1312}-
1313-
1314void-
1315usage(void)-
1316{-
1317 (void) fprintf(stderr,-
1318 "usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"-
1319 " [-l limit] [-o ssh_option] [-P port] [-S program] source ... target\n");-
1320 exit(1);
never executed: exit(1);
0
1321}-
1322-
1323void-
1324run_err(const char *fmt,...)-
1325{-
1326 static FILE *fp;-
1327 va_list ap;-
1328-
1329 ++errs;-
1330 if (fp != NULL || (remout != -1 && (fp = fdopen(remout, "w")))) {
fp != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
remout != -1Description
TRUEnever evaluated
FALSEnever evaluated
(fp = fdopen(remout, "w"))Description
TRUEnever evaluated
FALSEnever evaluated
0
1331 (void) fprintf(fp, "%c", 0x01);-
1332 (void) fprintf(fp, "scp: ");-
1333 va_start(ap, fmt);-
1334 (void) vfprintf(fp, fmt, ap);-
1335 va_end(ap);-
1336 (void) fprintf(fp, "\n");-
1337 (void) fflush(fp);-
1338 }
never executed: end of block
0
1339-
1340 if (!iamremote) {
!iamremoteDescription
TRUEnever evaluated
FALSEnever evaluated
0
1341 va_start(ap, fmt);-
1342 vfmprintf(stderr, fmt, ap);-
1343 va_end(ap);-
1344 fprintf(stderr, "\n");-
1345 }
never executed: end of block
0
1346}
never executed: end of block
0
1347-
1348void-
1349verifydir(char *cp)-
1350{-
1351 struct stat stb;-
1352-
1353 if (!stat(cp, &stb)) {
!stat(cp, &stb)Description
TRUEnever evaluated
FALSEnever evaluated
0
1354 if (S_ISDIR(stb.st_mode))
(((( stb.st_mo... == (0040000))Description
TRUEnever evaluated
FALSEnever evaluated
0
1355 return;
never executed: return;
0
1356 errno = ENOTDIR;-
1357 }
never executed: end of block
0
1358 run_err("%s: %s", cp, strerror(errno));-
1359 killchild(0);-
1360}
never executed: end of block
0
1361-
1362int-
1363okname(char *cp0)-
1364{-
1365 int c;-
1366 char *cp;-
1367-
1368 cp = cp0;-
1369 do {-
1370 c = (int)*cp;-
1371 if (c & 0200)
c & 0200Description
TRUEnever evaluated
FALSEnever evaluated
0
1372 goto bad;
never executed: goto bad;
0
1373 if (!isalpha(c) && !isdigit((unsigned char)c)) {
! ((*__ctype_b...int) _ISalpha)Description
TRUEnever evaluated
FALSEnever evaluated
! ((*__ctype_b...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
1374 switch (c) {-
1375 case '\'':
never executed: case '\'':
0
1376 case '"':
never executed: case '"':
0
1377 case '`':
never executed: case '`':
0
1378 case ' ':
never executed: case ' ':
0
1379 case '#':
never executed: case '#':
0
1380 goto bad;
never executed: goto bad;
0
1381 default:
never executed: default:
0
1382 break;
never executed: break;
0
1383 }-
1384 }-
1385 } while (*++cp);
never executed: end of block
*++cpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1386 return (1);
never executed: return (1);
0
1387-
1388bad: fmprintf(stderr, "%s: invalid user name\n", cp0);-
1389 return (0);
never executed: return (0);
0
1390}-
1391-
1392BUF *-
1393allocbuf(BUF *bp, int fd, int blksize)-
1394{-
1395 size_t size;-
1396#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE-
1397 struct stat stb;-
1398-
1399 if (fstat(fd, &stb) < 0) {
fstat(fd, &stb) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1400 run_err("fstat: %s", strerror(errno));-
1401 return (0);
never executed: return (0);
0
1402 }-
1403 size = ROUNDUP(stb.st_blksize, blksize);-
1404 if (size == 0)
size == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1405 size = blksize;
never executed: size = blksize;
0
1406#else /* HAVE_STRUCT_STAT_ST_BLKSIZE */-
1407 size = blksize;-
1408#endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */-
1409 if (bp->cnt >= size)
bp->cnt >= sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1410 return (bp);
never executed: return (bp);
0
1411 bp->buf = xrecallocarray(bp->buf, bp->cnt, size, 1);-
1412 bp->cnt = size;-
1413 return (bp);
never executed: return (bp);
0
1414}-
1415-
1416void-
1417lostconn(int signo)-
1418{-
1419 if (!iamremote)
!iamremoteDescription
TRUEnever evaluated
FALSEnever evaluated
0
1420 (void)write(STDERR_FILENO, "lost connection\n", 16);
never executed: (void)write( 2 , "lost connection\n", 16);
0
1421 if (signo)
signoDescription
TRUEnever evaluated
FALSEnever evaluated
0
1422 _exit(1);
never executed: _exit(1);
0
1423 else-
1424 exit(1);
never executed: exit(1);
0
1425}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2