]> andersk Git - gssapi-openssh.git/blobdiff - openssh/scp.c
update to http://www.psc.edu/networking/projects/hpn-ssh/openssh-4.7p1-hpn13v1.diff.gz
[gssapi-openssh.git] / openssh / scp.c
index d6005f81047e85fe881adc19aec98ab076e5f190..1c17f22c854e4a135d8fb6e1ebc7dabc3821c527 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: scp.c,v 1.155 2006/08/03 03:34:42 deraadt Exp $ */
+/* $OpenBSD: scp.c,v 1.160 2007/08/06 19:16:06 sobrado Exp $ */
 /*
  * scp - secure remote copy.  This is basically patched BSD rcp which
  * uses ssh to do the data transfer (instead of using rcmd).
@@ -96,6 +96,9 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
+#include <vis.h>
+#endif
 
 #include "xmalloc.h"
 #include "atomicio.h"
@@ -318,8 +321,8 @@ main(int argc, char **argv)
                case '4':
                case '6':
                case 'C':
-                        addargs(&args, "-%c", ch);
-                        break;
+                       addargs(&args, "-%c", ch);
+                       break;
                case 'o':
                case 'c':
                case 'i':
@@ -380,7 +383,7 @@ main(int argc, char **argv)
        if ((pwd = getpwuid(userid = getuid())) == NULL)
                fatal("unknown user %u", (u_int) userid);
 
-       if (!isatty(STDERR_FILENO))
+       if (!isatty(STDOUT_FILENO))
                showprogress = 0;
 
        remin = STDIN_FILENO;
@@ -582,7 +585,7 @@ source(int argc, char **argv)
        off_t i, amt, statbytes;
        size_t result;
        int fd = -1, haderr, indx;
-       char *last, *name, buf[16384];
+       char *last, *name, buf[16384], encname[MAXPATHLEN];
        int len;
 
        for (indx = 0; indx < argc; ++indx) {
@@ -591,17 +594,17 @@ source(int argc, char **argv)
                len = strlen(name);
                while (len > 1 && name[len-1] == '/')
                        name[--len] = '\0';
+               if ((fd = open(name, O_RDONLY|O_NONBLOCK, 0)) < 0)
+                       goto syserr;
                if (strchr(name, '\n') != NULL) {
-                       run_err("%s: skipping, filename contains a newline",
-                           name);
-                       goto next;
+                       strnvis(encname, name, sizeof(encname), VIS_NL);
+                       name = encname;
                }
-               if ((fd = open(name, O_RDONLY, 0)) < 0)
-                       goto syserr;
                if (fstat(fd, &stb) < 0) {
 syserr:                        run_err("%s: %s", name, strerror(errno));
                        goto next;
                }
+               unset_nonblock(fd);
                switch (stb.st_mode & S_IFMT) {
                case S_IFREG:
                        break;
@@ -1021,7 +1024,8 @@ bad:                      run_err("%s: %s", np, strerror(errno));
                        wrerr = YES;
                        wrerrno = errno;
                }
-               if (wrerr == NO && ftruncate(ofd, size) != 0) {
+               if (wrerr == NO && (!exists || S_ISREG(stb.st_mode)) &&
+                   ftruncate(ofd, size) != 0) {
                        run_err("%s: truncate: %s", np, strerror(errno));
                        wrerr = DISPLAYED;
                }
@@ -1116,7 +1120,7 @@ usage(void)
        (void) fprintf(stderr,
            "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"
            "           [-l limit] [-o ssh_option] [-P port] [-S program]\n"
-           "           [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
+           "           [[user@]host1:]file1 ... [[user@]host2:]file2\n");
        exit(1);
 }
 
This page took 0.036571 seconds and 4 git commands to generate.