Lines Matching +full:remote +full:- +full:pid

3  * scp - secure remote copy.  This is basically patched BSD rcp which
103 # include "openbsd-compat/glob.h"
138 #include "sftp-common.h"
139 #include "sftp-client.h"
159 /* This is set to non-zero to enable verbose mode. */
167 * This is set to non-zero if remote-remote copy should be piped
172 /* Non-standard port to use for the ssh connection or -1. */
173 int sshport = -1;
175 /* This is the program to execute for the secured connection. ("ssh" or -S) */
178 /* This is used to store the pid of ssh_program */
179 pid_t do_cmd_pid = -1;
180 pid_t do_cmd_pid2 = -1;
190 int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */
210 suspone(int pid, int signo) in suspone() argument
214 if (pid > 1) { in suspone()
215 kill(pid, signo); in suspone()
216 while (waitpid(pid, &status, WUNTRACED) == -1 && in suspone()
235 pid_t pid; in do_local_cmd() local
237 if (a->num == 0) in do_local_cmd()
242 for (i = 0; i < a->num; i++) in do_local_cmd()
243 fmprintf(stderr, " %s", a->list[i]); in do_local_cmd()
246 if ((pid = fork()) == -1) in do_local_cmd()
249 if (pid == 0) { in do_local_cmd()
250 execvp(a->list[0], a->list); in do_local_cmd()
251 perror(a->list[0]); in do_local_cmd()
255 do_cmd_pid = pid; in do_local_cmd()
260 while (waitpid(pid, &status, 0) == -1) in do_local_cmd()
264 do_cmd_pid = -1; in do_local_cmd()
267 return (-1); in do_local_cmd()
280 char *cmd, int *fdin, int *fdout, pid_t *pid) in do_cmd() argument
294 if (port == -1) in do_cmd()
298 if (pipe(pin) == -1 || pipe(pout) == -1) in do_cmd()
302 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) in do_cmd()
310 /* Fork a child to execute the command on the remote host using ssh. */ in do_cmd()
311 *pid = fork(); in do_cmd()
312 switch (*pid) { in do_cmd()
313 case -1: in do_cmd()
318 if (dup2(pin[0], STDIN_FILENO) == -1 || in do_cmd()
319 dup2(pout[1], STDOUT_FILENO) == -1) { in do_cmd()
328 if (dup2(sv[0], STDIN_FILENO) == -1 || in do_cmd()
329 dup2(sv[0], STDOUT_FILENO) == -1) { in do_cmd()
337 if (port != -1) { in do_cmd()
338 addargs(&args, "-p"); in do_cmd()
342 addargs(&args, "-l"); in do_cmd()
346 addargs(&args, "-s"); in do_cmd()
347 addargs(&args, "--"); in do_cmd()
383 pid_t pid; in do_cmd2() local
391 if (port == -1) in do_cmd2()
394 /* Fork a child to execute the command on the remote host using ssh. */ in do_cmd2()
395 pid = fork(); in do_cmd2()
396 if (pid == 0) { in do_cmd2()
397 if (dup2(fdin, 0) == -1) in do_cmd2()
399 if (dup2(fdout, 1) == -1) in do_cmd2()
403 if (port != -1) { in do_cmd2()
404 addargs(&args, "-p"); in do_cmd2()
408 addargs(&args, "-l"); in do_cmd2()
411 addargs(&args, "-oBatchMode=yes"); in do_cmd2()
412 addargs(&args, "--"); in do_cmd2()
419 } else if (pid == -1) { in do_cmd2()
422 while (waitpid(pid, &status, 0) == -1) in do_cmd2()
449 char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
501 addargs(&args, "-x"); in main()
502 addargs(&args, "-oPermitLocalCommand=no"); in main()
503 addargs(&args, "-oClearAllForwardings=yes"); in main()
504 addargs(&args, "-oRemoteCommand=none"); in main()
505 addargs(&args, "-oRequestTTY=no"); in main()
509 "12346ABCTdfOpqRrstvD:F:J:M:P:S:c:i:l:o:X:")) != -1) { in main()
511 /* User-visible flags. */ in main()
522 addargs(&args, "-%c", ch); in main()
523 addargs(&remote_remote_args, "-%c", ch); in main()
539 addargs(&remote_remote_args, "-%c", ch); in main()
541 addargs(&args, "-%c", ch); in main()
556 addargs(&remote_remote_args, "-oBatchmode=yes"); in main()
557 addargs(&args, "-oBatchmode=yes"); in main()
577 addargs(&args, "-v"); in main()
578 addargs(&remote_remote_args, "-v"); in main()
586 addargs(&args, "-q"); in main()
587 addargs(&remote_remote_args, "-q"); in main()
591 /* Please keep in sync with sftp.c -X */ in main()
595 r = -1; in main()
598 if (r == -1) { in main()
612 fatal("Invalid -X option"); in main()
638 argc -= optind; in main()
644 addargs(&args, "-oForwardAgent=no"); in main()
656 /* Cannot pledge: -p allows setuid/setgid files... */ in main()
659 NULL) == -1) { in main()
684 remin = remout = -1; in main()
685 do_cmd_pid = -1; in main()
686 /* Command to be executed on remote system using "ssh". */ in main()
688 verbose_mode ? " -v" : "", in main()
689 iamrecursive ? " -r" : "", pflag ? " -p" : "", in main()
690 targetshouldbedirectory ? " -d" : ""); in main()
694 if (colon(argv[argc - 1])) /* Dest is remote host. */ in main()
698 verifydir(argv[argc - 1]); in main()
705 if (do_cmd_pid != -1 && (mode == MODE_SFTP || errs == 0)) { in main()
706 if (remin != -1) in main()
708 if (remout != -1) in main()
710 if (waitpid(do_cmd_pid, &status, 0) == -1) in main()
740 (unsigned long long) (sb->st_mtime < 0 ? 0 : sb->st_mtime), in do_times()
741 (unsigned long long) (sb->st_atime < 0 ? 0 : sb->st_atime)); in do_times()
744 (long long)sb->st_mtime, (long long)sb->st_atime); in do_times()
763 /* Appends a string to an array; returns 0 on success, -1 on alloc failure */
770 return -1; in append()
779 * returns 0 on success or -1 for invalid patterns.
787 *startp = *endp = -1; in find_brace()
810 if (*startp == -1) in find_brace()
819 return -1; in find_brace()
821 if (--brace_level <= 0) in find_brace()
828 return -1; in find_brace()
833 * Assembles and records a successfully-expanded pattern, returns -1 on
845 return -1; in emit_expansion()
848 if ((cp = malloc(brace_start + (sel_end - sel_start) + in emit_expansion()
850 return -1; in emit_expansion()
858 if (sel_end - sel_start > 0) { in emit_expansion()
860 sel_end - sel_start); in emit_expansion()
861 o += sel_end - sel_start; in emit_expansion()
871 return -1; in emit_expansion()
880 * Returns 0 on success or -1 on allocation failure.
898 } else if (brace_start == -1) in brace_expand_one()
912 brace_level--; in brace_expand_one()
921 if (i < brace_end - 1) in brace_expand_one()
925 if (pattern[i] == ',' || i == brace_end - 1) { in brace_expand_one()
931 sel_end = (i == brace_end - 1) ? brace_end : i; in brace_expand_one()
934 return -1; in brace_expand_one()
949 /* Expand braces from pattern. Returns 0 on success, -1 on failure */
955 int ret = -1, invalid = 0, expanded = 0; in brace_expand()
962 return -1; in brace_expand()
965 return -1; in brace_expand()
968 cp = active[nactive - 1]; in brace_expand()
969 nactive--; in brace_expand()
971 &expanded, &invalid) == -1) { in brace_expand()
1026 addargs(&args, "sftp-server"); in do_sftp_connect()
1027 if (do_cmd(sftp_direct, host, NULL, -1, 0, "sftp", in do_sftp_connect()
1040 int sport = -1, tport = -1; in toremote()
1051 r = parse_scp_uri(argv[argc - 1], &tuser, &thost, &tport, &targ); in toremote()
1052 if (r == -1) { in toremote()
1053 fmprintf(stderr, "%s: invalid uri\n", argv[argc - 1]); in toremote()
1058 if (parse_user_host_path(argv[argc - 1], &tuser, &thost, in toremote()
1059 &targ) == -1) { in toremote()
1060 fmprintf(stderr, "%s: invalid target\n", argv[argc - 1]); in toremote()
1067 for (i = 0; i < argc - 1; i++) { in toremote()
1072 if (r == -1) { in toremote()
1084 if (host && throughlocal) { /* extended remote to remote */ in toremote()
1086 if (remin == -1) { in toremote()
1095 debug3_f("origin in %d out %d pid %ld", in toremote()
1102 * scp -3 hosta:/foo hosta:/bar hostb: in toremote()
1112 debug3_f("destination in %d out %d pid %ld", in toremote()
1117 remin2 = remout2 = -1; in toremote()
1118 if (waitpid(do_cmd_pid2, &status, 0) == -1) in toremote()
1123 do_cmd_pid2 = -1; in toremote()
1126 xasprintf(&bp, "%s -f %s%s", cmd, in toremote()
1127 *src == '-' ? "-- " : "", src); in toremote()
1132 xasprintf(&bp, "%s -t %s%s", cmd, in toremote()
1133 *targ == '-' ? "-- " : "", targ); in toremote()
1140 remin = remout = -1; in toremote()
1142 } else if (host) { /* standard remote to remote */ in toremote()
1144 * Second remote user is passed to first remote side in toremote()
1145 * via scp command-line. Ensure it contains no obvious in toremote()
1152 if (tport != -1 && tport != SSH_DEFAULT_PORT) { in toremote()
1153 /* This would require the remote support URIs */ in toremote()
1155 "remote hosts and the -R option"); in toremote()
1160 addargs(&alist, "-x"); in toremote()
1161 addargs(&alist, "-oClearAllForwardings=yes"); in toremote()
1162 addargs(&alist, "-n"); in toremote()
1168 if (sport != -1) { in toremote()
1169 addargs(&alist, "-p"); in toremote()
1173 addargs(&alist, "-l"); in toremote()
1176 addargs(&alist, "--"); in toremote()
1185 } else { /* local to remote */ in toremote()
1192 if (remin == -1) { in toremote()
1193 /* Connect to remote now */ in toremote()
1208 if (remin == -1) { in toremote()
1209 xasprintf(&bp, "%s -t %s%s", cmd, in toremote()
1210 *targ == '-' ? "-- " : "", targ); in toremote()
1238 int i, r, sport = -1; in tolocal()
1243 for (i = 0; i < argc - 1; i++) { in tolocal()
1248 if (r == -1) { in tolocal()
1263 addargs(&alist, "-r"); in tolocal()
1265 addargs(&alist, "-p"); in tolocal()
1266 addargs(&alist, "--"); in tolocal()
1268 addargs(&alist, "%s", argv[argc-1]); in tolocal()
1273 /* Remote to local. */ in tolocal()
1284 sink_sftp(1, argv[argc - 1], src, conn); in tolocal()
1289 remin = remout = -1; in tolocal()
1293 xasprintf(&bp, "%s -f %s%s", in tolocal()
1294 cmd, *src == '-' ? "-- " : "", src); in tolocal()
1302 sink(1, argv + argc - 1, src); in tolocal()
1304 remin = remout = -1; in tolocal()
1311 /* Prepare remote path, handling ~ by assuming cwd is the homedir */
1330 error("server expand-path extension is required " in prepare_remote_path()
1351 * No need to glob here - the local shell already took care of in source_sftp()
1371 debug3_f("copying local %s to remote %s", src, abs_dst); in source_sftp()
1396 int fd = -1, haderr, indx; in source()
1404 while (len > 1 && name[len-1] == '/') in source()
1405 name[--len] = '\0'; in source()
1406 if ((fd = open(name, O_RDONLY|O_NONBLOCK)) == -1) in source()
1412 if (fstat(fd, &stb) == -1) { in source()
1453 next: if (fd != -1) { in source()
1455 fd = -1; in source()
1462 for (haderr = i = 0; i < stb.st_size; i += bp->cnt) { in source()
1463 amt = bp->cnt; in source()
1465 amt = stb.st_size - i; in source()
1468 bp->buf, amt)) != amt) { in source()
1470 memset(bp->buf + nr, 0, amt - nr); in source()
1475 (void)atomicio(vwrite, remout, bp->buf, amt); in source()
1476 memset(bp->buf, 0, amt); in source()
1479 if (atomicio6(vwrite, remout, bp->buf, amt, scpio, in source()
1485 if (fd != -1) { in source()
1486 if (close(fd) == -1 && !haderr) in source()
1488 fd = -1; in source()
1523 (u_int) (statp->st_mode & FILEMODEMASK), 0, last); in rsource()
1532 if (dp->d_ino == 0) in rsource()
1534 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) in rsource()
1536 if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) { in rsource()
1537 run_err("%s/%s: name too long", name, dp->d_name); in rsource()
1540 (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name); in rsource()
1562 * Here, we need remote glob as SFTP can not depend on remote shell in sink_sftp()
1566 err = -1; in sink_sftp()
1570 debug3_f("copying remote %s to local %s", abs_src, dst); in sink_sftp()
1577 err = -1; in sink_sftp()
1590 err = -1; in sink_sftp()
1603 err = -1; in sink_sftp()
1609 err = -1; in sink_sftp()
1619 err = -1; in sink_sftp()
1631 NULL, pflag, SFTP_PROGRESS_ONLY, 0, 0, 1, 1) == -1) in sink_sftp()
1632 err = -1; in sink_sftp()
1635 pflag, 0, 0, 1) == -1) in sink_sftp()
1636 err = -1; in sink_sftp()
1648 if (err == -1) in sink_sftp()
1716 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
1738 *--cp = 0;
1773 * Check for the case "rcp remote:foo\* local:bar".
1775 * by the shell before the rcp command on the remote is
1789 mode = (mode << 3) | (*cp - '0');
1848 SCREWUP("received directory without -r");
1857 /* Handle copying from a read-only directory */
1859 if (mkdir(np, mode | S_IRWXU) == -1)
1875 if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) == -1) {
1884 cp = bp->buf;
1896 for (count = i = 0; i < size; i += bp->cnt) {
1897 amt = bp->cnt;
1899 amt = size - i;
1910 amt -= j;
1914 if (count == bp->cnt) {
1917 if (atomicio(vwrite, ofd, bp->buf,
1925 cp = bp->buf;
1930 atomicio(vwrite, ofd, bp->buf, count) != count) {
1958 if (close(ofd) == -1)
1965 if (utimes(np, tv) == -1) {
2007 err = -1;
2011 debug3_f("copying remote %s to remote %s", abs_src, target);
2018 err = -1;
2031 err = -1;
2040 err = -1;
2052 NULL, pflag, SFTP_PROGRESS_ONLY, 1) == -1)
2053 err = -1;
2056 NULL, pflag) == -1)
2057 err = -1;
2071 if (err == -1)
2096 } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
2099 cp[-1] = '\0';
2107 return (-1);
2117 "usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]\n"
2118 " [-i identity_file] [-J destination] [-l limit] [-o ssh_option]\n"
2119 " [-P port] [-S program] [-X sftp_option] source ... target\n");
2130 if (fp != NULL || (remout != -1 && (fp = fdopen(remout, "w")))) {
2150 * no error has been noted or -1 otherwise. Use note_err(NULL) to flush
2159 /* Replay any previously-noted error */
2166 return -1;
2170 /* Prefer first-noted error */
2172 return -1;
2177 return -1;
2231 if (fstat(fd, &stb) == -1) {
2241 if (bp->cnt >= size)
2243 bp->buf = xrecallocarray(bp->buf, bp->cnt, size, 1);
2244 bp->cnt = size;