]> andersk Git - gssapi-openssh.git/blobdiff - openssh/scp.c
add prototype for expand_authorized_keys()
[gssapi-openssh.git] / openssh / scp.c
index 04d3b09b050bf84123e41d800ae3f5f2a1eb933f..d6005f81047e85fe881adc19aec98ab076e5f190 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: scp.c,v 1.155 2006/08/03 03:34:42 deraadt Exp $ */
 /*
  * scp - secure remote copy.  This is basically patched BSD rcp which
  * uses ssh to do the data transfer (instead of using rcmd).
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.130 2006/01/31 10:35:43 djm Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <sys/wait.h>
+#include <sys/uio.h>
+
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.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>
 
 #include "xmalloc.h"
 #include "atomicio.h"
@@ -82,6 +106,8 @@ RCSID("$OpenBSD: scp.c,v 1.130 2006/01/31 10:35:43 djm Exp $");
 
 extern char *__progname;
 
+int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout);
+
 void bwlimit(int);
 
 /* Struct for addargs */
@@ -167,7 +193,7 @@ do_local_cmd(arglist *a)
  */
 
 int
-do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
+do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
 {
        int pin[2], pout[2], reserved[2];
 
@@ -181,7 +207,8 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
         * Reserve two descriptors so that the real pipes won't get
         * descriptors 0 and 1 because that will screw up dup2 below.
         */
-       pipe(reserved);
+       if (pipe(reserved) < 0)
+               fatal("pipe: %s", strerror(errno));
 
        /* Create a socket pair for communicating with ssh. */
        if (pipe(pin) < 0)
@@ -234,7 +261,6 @@ typedef struct {
 
 BUF *allocbuf(BUF *, int, int);
 void lostconn(int);
-void nospace(void);
 int okname(char *);
 void run_err(const char *,...);
 void verifydir(char *);
@@ -258,15 +284,21 @@ void usage(void);
 int
 main(int argc, char **argv)
 {
-       int ch, fflag, tflag, status;
+       int ch, fflag, tflag, status, n;
        double speed;
-       char *targ, *endp;
+       char *targ, *endp, **newargv;
        extern char *optarg;
        extern int optind;
 
        /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
        sanitise_stdfd();
 
+       /* Copy argv, because we modify it */
+       newargv = xcalloc(MAX(argc + 1, 1), sizeof(*newargv));
+       for (n = 0; n < argc; n++)
+               newargv[n] = xstrdup(argv[n]);
+       argv = newargv;
+
        __progname = ssh_get_progname(argv[0]);
 
        memset(&args, '\0', sizeof(args));
@@ -278,7 +310,7 @@ main(int argc, char **argv)
        addargs(&args, "-oClearAllForwardings yes");
 
        fflag = tflag = 0;
-       while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246zS:o:F:R:")) != -1)
+       while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246S:o:F:")) != -1)
                switch (ch) {
                /* User-visible flags. */
                case '1':
@@ -286,9 +318,8 @@ main(int argc, char **argv)
                case '4':
                case '6':
                case 'C':
-               case 'z':       
-                       addargs(&args, "-%c", ch);
-                       break;
+                        addargs(&args, "-%c", ch);
+                        break;
                case 'o':
                case 'c':
                case 'i':
@@ -340,12 +371,6 @@ main(int argc, char **argv)
                        setmode(0, O_BINARY);
 #endif
                        break;
-               case 'R':
-                 addargs(&args, "-r%s", optarg);
-                 break;
-               case 'w':
-                 addargs(&args, "-w%s", optarg);
-                 break;
                default:
                        usage();
                }
@@ -416,9 +441,9 @@ main(int argc, char **argv)
 void
 toremote(char *targ, int argc, char **argv)
 {
-       int i, len;
        char *bp, *host, *src, *suser, *thost, *tuser, *arg;
        arglist alist;
+       int i;
 
        memset(&alist, '\0', sizeof(alist));
        alist.list = NULL;
@@ -483,12 +508,10 @@ toremote(char *targ, int argc, char **argv)
                                errs = 1;
                } else {        /* local to remote */
                        if (remin == -1) {
-                               len = strlen(targ) + CMDNEEDS + 20;
-                               bp = xmalloc(len);
-                               (void) snprintf(bp, len, "%s -t %s", cmd, targ);
+                               xasprintf(&bp, "%s -t %s", cmd, targ);
                                host = cleanhostname(thost);
                                if (do_cmd(host, tuser, bp, &remin,
-                                   &remout, argc) < 0)
+                                   &remout) < 0)
                                        exit(1);
                                if (response() < 0)
                                        exit(1);
@@ -497,14 +520,15 @@ toremote(char *targ, int argc, char **argv)
                        source(1, argv + i);
                }
        }
+       xfree(arg);
 }
 
 void
 tolocal(int argc, char **argv)
 {
-       int i, len;
        char *bp, *host, *src, *suser;
        arglist alist;
+       int i;
 
        memset(&alist, '\0', sizeof(alist));
        alist.list = NULL;
@@ -536,10 +560,8 @@ tolocal(int argc, char **argv)
                                suser = pwd->pw_name;
                }
                host = cleanhostname(host);
-               len = strlen(src) + CMDNEEDS + 20;
-               bp = xmalloc(len);
-               (void) snprintf(bp, len, "%s -f %s", cmd, src);
-               if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {
+               xasprintf(&bp, "%s -f %s", cmd, src);
+               if (do_cmd(host, suser, bp, &remin, &remout) < 0) {
                        (void) xfree(bp);
                        ++errs;
                        continue;
@@ -620,10 +642,6 @@ syserr:                    run_err("%s: %s", name, strerror(errno));
                (void) atomicio(vwrite, remout, buf, strlen(buf));
                if (response() < 0)
                        goto next;
-               /* this change decreases the number of read/write syscalls*/
-               /* when scp acts as data source. this is the critical change*/
-               /* buf can actually remain at 2k but increasing both to 16k*/
-               /* seemed to make sense*/
                if ((bp = allocbuf(&buffer, fd, sizeof(buf))) == NULL) {
 next:                  if (fd != -1) {
                                (void) close(fd);
@@ -788,7 +806,8 @@ sink(int argc, char **argv)
        BUF *bp;
        off_t i;
        size_t j, count;
-       int amt, exists, first, mask, mode, ofd, omode;
+       int amt, exists, first, ofd;
+       mode_t mode, omode, mask;
        off_t size, statbytes;
        int setimes, targisdir, wrerrno = 0;
        char ch, *cp, *np, *targ, *why, *vect[1], buf[16384];
@@ -1096,7 +1115,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] [-R Receive buffer size (Kb)] [-S program]\n"
+           "           [-l limit] [-o ssh_option] [-P port] [-S program]\n"
            "           [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
        exit(1);
 }
@@ -1108,15 +1127,15 @@ run_err(const char *fmt,...)
        va_list ap;
 
        ++errs;
-       if (fp == NULL && !(fp = fdopen(remout, "w")))
-               return;
-       (void) fprintf(fp, "%c", 0x01);
-       (void) fprintf(fp, "scp: ");
-       va_start(ap, fmt);
-       (void) vfprintf(fp, fmt, ap);
-       va_end(ap);
-       (void) fprintf(fp, "\n");
-       (void) fflush(fp);
+       if (fp != NULL || (remout != -1 && (fp = fdopen(remout, "w")))) {
+               (void) fprintf(fp, "%c", 0x01);
+               (void) fprintf(fp, "scp: ");
+               va_start(ap, fmt);
+               (void) vfprintf(fp, fmt, ap);
+               va_end(ap);
+               (void) fprintf(fp, "\n");
+               (void) fflush(fp);
+       }
 
        if (!iamremote) {
                va_start(ap, fmt);
@@ -1192,7 +1211,7 @@ allocbuf(BUF *bp, int fd, int blksize)
        if (bp->buf == NULL)
                bp->buf = xmalloc(size);
        else
-               bp->buf = xrealloc(bp->buf, size);
+               bp->buf = xrealloc(bp->buf, 1, size);
        memset(bp->buf, 0, size);
        bp->cnt = size;
        return (bp);
This page took 0.04626 seconds and 4 git commands to generate.