]> andersk Git - openssh.git/blobdiff - scp.c
- (dtucker) [INSTALL] Link to tcpwrappers.
[openssh.git] / scp.c
diff --git a/scp.c b/scp.c
index cf8db8f3445a7d94dfe9e202486debe94b59e433..1765a44e642f97840998f05289f377f2cb9492e9 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scp.c,v 1.151 2006/07/25 02:59:21 stevesk 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).
@@ -74,6 +74,7 @@
 #include "includes.h"
 
 #include <sys/types.h>
+#include <sys/param.h>
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
@@ -81,6 +82,7 @@
 # include <sys/time.h>
 #endif
 #include <sys/wait.h>
+#include <sys/uio.h>
 
 #include <ctype.h>
 #include <dirent.h>
 #include <pwd.h>
 #include <signal.h>
 #include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
 #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"
@@ -376,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;
@@ -578,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[2048];
+       char *last, *name, buf[2048], encname[MAXPATHLEN];
        int len;
 
        for (indx = 0; indx < argc; ++indx) {
@@ -587,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;
@@ -1017,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;
                }
@@ -1112,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.112232 seconds and 4 git commands to generate.