diff options
author | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:32:03 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:32:03 +0000 |
commit | 04942aa41fa94ec6f2c3ce1d348f600f31bb7c78 (patch) | |
tree | af8e928bd79d3f2d0219bb5b2c78b573ec31d94c /scp.c | |
parent | 9ad7b718d42e43f3a285fcbc8f91193931fce324 (diff) | |
parent | 16704d57999d987fb8d9ba53379841a79f016d67 (diff) |
import openssh-4.2p1-gsskex-20050926-2.patch
Diffstat (limited to 'scp.c')
-rw-r--r-- | scp.c | 51 |
1 files changed, 28 insertions, 23 deletions
@@ -71,7 +71,7 @@ | |||
71 | */ | 71 | */ |
72 | 72 | ||
73 | #include "includes.h" | 73 | #include "includes.h" |
74 | RCSID("$OpenBSD: scp.c,v 1.119 2005/01/24 10:22:06 dtucker Exp $"); | 74 | RCSID("$OpenBSD: scp.c,v 1.125 2005/07/27 10:39:03 dtucker Exp $"); |
75 | 75 | ||
76 | #include "xmalloc.h" | 76 | #include "xmalloc.h" |
77 | #include "atomicio.h" | 77 | #include "atomicio.h" |
@@ -109,11 +109,13 @@ static void | |||
109 | killchild(int signo) | 109 | killchild(int signo) |
110 | { | 110 | { |
111 | if (do_cmd_pid > 1) { | 111 | if (do_cmd_pid > 1) { |
112 | kill(do_cmd_pid, signo); | 112 | kill(do_cmd_pid, signo ? signo : SIGTERM); |
113 | waitpid(do_cmd_pid, NULL, 0); | 113 | waitpid(do_cmd_pid, NULL, 0); |
114 | } | 114 | } |
115 | 115 | ||
116 | _exit(1); | 116 | if (signo) |
117 | _exit(1); | ||
118 | exit(1); | ||
117 | } | 119 | } |
118 | 120 | ||
119 | /* | 121 | /* |
@@ -184,7 +186,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc) | |||
184 | } | 186 | } |
185 | 187 | ||
186 | typedef struct { | 188 | typedef struct { |
187 | int cnt; | 189 | size_t cnt; |
188 | char *buf; | 190 | char *buf; |
189 | } BUF; | 191 | } BUF; |
190 | 192 | ||
@@ -361,20 +363,21 @@ void | |||
361 | toremote(char *targ, int argc, char **argv) | 363 | toremote(char *targ, int argc, char **argv) |
362 | { | 364 | { |
363 | int i, len; | 365 | int i, len; |
364 | char *bp, *host, *src, *suser, *thost, *tuser; | 366 | char *bp, *host, *src, *suser, *thost, *tuser, *arg; |
365 | 367 | ||
366 | *targ++ = 0; | 368 | *targ++ = 0; |
367 | if (*targ == 0) | 369 | if (*targ == 0) |
368 | targ = "."; | 370 | targ = "."; |
369 | 371 | ||
370 | if ((thost = strrchr(argv[argc - 1], '@'))) { | 372 | arg = xstrdup(argv[argc - 1]); |
373 | if ((thost = strrchr(arg, '@'))) { | ||
371 | /* user@host */ | 374 | /* user@host */ |
372 | *thost++ = 0; | 375 | *thost++ = 0; |
373 | tuser = argv[argc - 1]; | 376 | tuser = arg; |
374 | if (*tuser == '\0') | 377 | if (*tuser == '\0') |
375 | tuser = NULL; | 378 | tuser = NULL; |
376 | } else { | 379 | } else { |
377 | thost = argv[argc - 1]; | 380 | thost = arg; |
378 | tuser = NULL; | 381 | tuser = NULL; |
379 | } | 382 | } |
380 | 383 | ||
@@ -501,8 +504,9 @@ source(int argc, char **argv) | |||
501 | struct stat stb; | 504 | struct stat stb; |
502 | static BUF buffer; | 505 | static BUF buffer; |
503 | BUF *bp; | 506 | BUF *bp; |
504 | off_t i, amt, result, statbytes; | 507 | off_t i, amt, statbytes; |
505 | int fd, haderr, indx; | 508 | size_t result; |
509 | int fd = -1, haderr, indx; | ||
506 | char *last, *name, buf[2048]; | 510 | char *last, *name, buf[2048]; |
507 | int len; | 511 | int len; |
508 | 512 | ||
@@ -577,14 +581,14 @@ next: (void) close(fd); | |||
577 | if (!haderr) { | 581 | if (!haderr) { |
578 | result = atomicio(read, fd, bp->buf, amt); | 582 | result = atomicio(read, fd, bp->buf, amt); |
579 | if (result != amt) | 583 | if (result != amt) |
580 | haderr = result >= 0 ? EIO : errno; | 584 | haderr = errno; |
581 | } | 585 | } |
582 | if (haderr) | 586 | if (haderr) |
583 | (void) atomicio(vwrite, remout, bp->buf, amt); | 587 | (void) atomicio(vwrite, remout, bp->buf, amt); |
584 | else { | 588 | else { |
585 | result = atomicio(vwrite, remout, bp->buf, amt); | 589 | result = atomicio(vwrite, remout, bp->buf, amt); |
586 | if (result != amt) | 590 | if (result != amt) |
587 | haderr = result >= 0 ? EIO : errno; | 591 | haderr = errno; |
588 | statbytes += result; | 592 | statbytes += result; |
589 | } | 593 | } |
590 | if (limit_rate) | 594 | if (limit_rate) |
@@ -719,8 +723,9 @@ sink(int argc, char **argv) | |||
719 | YES, NO, DISPLAYED | 723 | YES, NO, DISPLAYED |
720 | } wrerr; | 724 | } wrerr; |
721 | BUF *bp; | 725 | BUF *bp; |
722 | off_t i, j; | 726 | off_t i; |
723 | int amt, count, exists, first, mask, mode, ofd, omode; | 727 | size_t j, count; |
728 | int amt, exists, first, mask, mode, ofd, omode; | ||
724 | off_t size, statbytes; | 729 | off_t size, statbytes; |
725 | int setimes, targisdir, wrerrno = 0; | 730 | int setimes, targisdir, wrerrno = 0; |
726 | char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; | 731 | char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; |
@@ -747,7 +752,7 @@ sink(int argc, char **argv) | |||
747 | targisdir = 1; | 752 | targisdir = 1; |
748 | for (first = 1;; first = 0) { | 753 | for (first = 1;; first = 0) { |
749 | cp = buf; | 754 | cp = buf; |
750 | if (atomicio(read, remin, cp, 1) <= 0) | 755 | if (atomicio(read, remin, cp, 1) != 1) |
751 | return; | 756 | return; |
752 | if (*cp++ == '\n') | 757 | if (*cp++ == '\n') |
753 | SCREWUP("unexpected <newline>"); | 758 | SCREWUP("unexpected <newline>"); |
@@ -828,7 +833,7 @@ sink(int argc, char **argv) | |||
828 | } | 833 | } |
829 | if (targisdir) { | 834 | if (targisdir) { |
830 | static char *namebuf; | 835 | static char *namebuf; |
831 | static int cursize; | 836 | static size_t cursize; |
832 | size_t need; | 837 | size_t need; |
833 | 838 | ||
834 | need = strlen(targ) + strlen(cp) + 250; | 839 | need = strlen(targ) + strlen(cp) + 250; |
@@ -901,7 +906,7 @@ bad: run_err("%s: %s", np, strerror(errno)); | |||
901 | count += amt; | 906 | count += amt; |
902 | do { | 907 | do { |
903 | j = atomicio(read, remin, cp, amt); | 908 | j = atomicio(read, remin, cp, amt); |
904 | if (j <= 0) { | 909 | if (j == 0) { |
905 | run_err("%s", j ? strerror(errno) : | 910 | run_err("%s", j ? strerror(errno) : |
906 | "dropped connection"); | 911 | "dropped connection"); |
907 | exit(1); | 912 | exit(1); |
@@ -917,10 +922,10 @@ bad: run_err("%s: %s", np, strerror(errno)); | |||
917 | if (count == bp->cnt) { | 922 | if (count == bp->cnt) { |
918 | /* Keep reading so we stay sync'd up. */ | 923 | /* Keep reading so we stay sync'd up. */ |
919 | if (wrerr == NO) { | 924 | if (wrerr == NO) { |
920 | j = atomicio(vwrite, ofd, bp->buf, count); | 925 | if (atomicio(vwrite, ofd, bp->buf, |
921 | if (j != count) { | 926 | count) != count) { |
922 | wrerr = YES; | 927 | wrerr = YES; |
923 | wrerrno = j >= 0 ? EIO : errno; | 928 | wrerrno = errno; |
924 | } | 929 | } |
925 | } | 930 | } |
926 | count = 0; | 931 | count = 0; |
@@ -930,9 +935,9 @@ bad: run_err("%s: %s", np, strerror(errno)); | |||
930 | if (showprogress) | 935 | if (showprogress) |
931 | stop_progress_meter(); | 936 | stop_progress_meter(); |
932 | if (count != 0 && wrerr == NO && | 937 | if (count != 0 && wrerr == NO && |
933 | (j = atomicio(vwrite, ofd, bp->buf, count)) != count) { | 938 | atomicio(vwrite, ofd, bp->buf, count) != count) { |
934 | wrerr = YES; | 939 | wrerr = YES; |
935 | wrerrno = j >= 0 ? EIO : errno; | 940 | wrerrno = errno; |
936 | } | 941 | } |
937 | if (wrerr == NO && ftruncate(ofd, size) != 0) { | 942 | if (wrerr == NO && ftruncate(ofd, size) != 0) { |
938 | run_err("%s: truncate: %s", np, strerror(errno)); | 943 | run_err("%s: truncate: %s", np, strerror(errno)); |
@@ -1069,7 +1074,7 @@ verifydir(char *cp) | |||
1069 | errno = ENOTDIR; | 1074 | errno = ENOTDIR; |
1070 | } | 1075 | } |
1071 | run_err("%s: %s", cp, strerror(errno)); | 1076 | run_err("%s: %s", cp, strerror(errno)); |
1072 | exit(1); | 1077 | killchild(0); |
1073 | } | 1078 | } |
1074 | 1079 | ||
1075 | int | 1080 | int |