]> andersk Git - openssh.git/blobdiff - scp.c
Oops.. =) mispelt NGROUPS_MAX.
[openssh.git] / scp.c
diff --git a/scp.c b/scp.c
index 8d5a251b58e39d166db7eec118e701a3daa8486e..f8f123af4f8b24fc1a65b04aa501c3b1ad432aa8 100644 (file)
--- a/scp.c
+++ b/scp.c
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.41 2000/10/11 20:03:27 markus Exp $");
+RCSID("$OpenBSD: scp.c,v 1.51 2001/01/21 19:05:55 markus Exp $");
 
-#include "ssh.h"
 #include "xmalloc.h"
+#include "atomicio.h"
+#include "pathnames.h"
+#include "log.h"
 
-#ifndef _PATH_CP
-#define _PATH_CP "cp"
+#ifdef HAVE___PROGNAME
+extern char *__progname;
+#else
+char *__progname;
 #endif
 
 /* For progressmeter() -- number of seconds before xfer considered "stalled" */
@@ -109,7 +113,7 @@ void addargs(char *fmt, ...) __attribute__((format(printf, 1, 2)));
 static struct timeval start;
 
 /* Number of bytes of current file transferred so far. */
-volatile unsigned long statbytes;
+volatile u_long statbytes;
 
 /* Total size of current file. */
 off_t totalbytes = 0;
@@ -120,14 +124,11 @@ char *curfile;
 /* This is set to non-zero to enable verbose mode. */
 int verbose_mode = 0;
 
-/* This is set to non-zero if compression is desired. */
-int compress_flag = 0;
-
 /* This is set to zero if the progressmeter is not desired. */
 int showprogress = 1;
 
 /* This is the program to execute for the secured connection. ("ssh" or -S) */
-char *ssh_program = SSH_PROGRAM;
+char *ssh_program = _PATH_SSH_PROGRAM;
 
 /* This is the list of arguments that scp passes to ssh */
 struct {
@@ -195,19 +196,6 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
        return 0;
 }
 
-void
-fatal(const char *fmt,...)
-{
-       va_list ap;
-       char buf[1024];
-
-       va_start(ap, fmt);
-       vsnprintf(buf, sizeof(buf), fmt, ap);
-       va_end(ap);
-       fprintf(stderr, "%s\n", buf);
-       exit(255);
-}
-
 typedef struct {
        int cnt;
        char *buf;
@@ -249,13 +237,15 @@ main(argc, argv)
        extern char *optarg;
        extern int optind;
 
+       __progname = get_progname(argv[0]);
+
        args.list = NULL;
        addargs("ssh");         /* overwritten with ssh_program */
        addargs("-x");
        addargs("-oFallBackToRsh no");
 
        fflag = tflag = 0;
-       while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != EOF)
+       while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != -1)
                switch (ch) {
                /* User-visible flags. */
                case '4':
@@ -266,13 +256,13 @@ main(argc, argv)
                case 'o':
                case 'c':
                case 'i':
-                       addargs("-%c %s", ch, optarg);
+                       addargs("-%c%s", ch, optarg);
                        break;
                case 'P':
-                       addargs("-p %s", optarg);
+                       addargs("-p%s", optarg);
                        break;
                case 'B':
-                       addargs("-o Batchmode yes");
+                       addargs("-oBatchmode yes");
                        break;
                case 'p':
                        pflag = 1;
@@ -407,20 +397,20 @@ toremote(targ, argc, argv)
                                        suser = pwd->pw_name;
                                else if (!okname(suser))
                                        continue;
-                               (void) sprintf(bp,
+                               sprintf(bp,
                                    "%s%s -x -o'FallBackToRsh no' -n -l %s %s %s %s '%s%s%s:%s'",
-                                    ssh_program, verbose_mode ? " -v" : "",
-                                    suser, host, cmd, src,
-                                    tuser ? tuser : "", tuser ? "@" : "",
-                                    thost, targ);
+                                   ssh_program, verbose_mode ? " -v" : "",
+                                   suser, host, cmd, src,
+                                   tuser ? tuser : "", tuser ? "@" : "",
+                                   thost, targ);
                        } else {
                                host = cleanhostname(argv[i]);
-                               (void) sprintf(bp,
+                               sprintf(bp,
                                    "exec %s%s -x -o'FallBackToRsh no' -n %s %s %s '%s%s%s:%s'",
-                                    ssh_program, verbose_mode ? " -v" : "",
-                                    host, cmd, src,
-                                    tuser ? tuser : "", tuser ? "@" : "",
-                                    thost, targ);
+                                   ssh_program, verbose_mode ? " -v" : "",
+                                   host, cmd, src,
+                                   tuser ? tuser : "", tuser ? "@" : "",
+                                   thost, targ);
                        }
                        if (verbose_mode)
                                fprintf(stderr, "Executing: %s\n", bp);
@@ -542,17 +532,16 @@ syserr:                   run_err("%s: %s", name, strerror(errno));
                         * versions expecting microseconds.
                         */
                        (void) sprintf(buf, "T%lu 0 %lu 0\n",
-                           (unsigned long) stb.st_mtime,
-                           (unsigned long) stb.st_atime);
+                           (u_long) stb.st_mtime,
+                           (u_long) stb.st_atime);
                        (void) atomicio(write, remout, buf, strlen(buf));
                        if (response() < 0)
                                goto next;
                }
 #define        FILEMODEMASK    (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
-               (void) sprintf(buf, "C%04o %lu %s\n",
-                            (unsigned int) (stb.st_mode & FILEMODEMASK),
-                              (unsigned long) stb.st_size,
-                              last);
+               sprintf(buf, "C%04o %lu %s\n",
+                   (u_int) (stb.st_mode & FILEMODEMASK),
+                   (u_long) stb.st_size, last);
                if (verbose_mode) {
                        fprintf(stderr, "Sending file modes: %s", buf);
                        fflush(stderr);
@@ -620,8 +609,8 @@ rsource(name, statp)
                last++;
        if (pflag) {
                (void) sprintf(path, "T%lu 0 %lu 0\n",
-                   (unsigned long) statp->st_mtime,
-                   (unsigned long) statp->st_atime);
+                   (u_long) statp->st_mtime,
+                   (u_long) statp->st_atime);
                (void) atomicio(write, remout, path, strlen(path));
                if (response() < 0) {
                        closedir(dirp);
@@ -629,7 +618,7 @@ rsource(name, statp)
                }
        }
        (void) sprintf(path, "D%04o %d %.1024s\n",
-           (unsigned int) (statp->st_mode & FILEMODEMASK), 0, last);
+           (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
        if (verbose_mode)
                fprintf(stderr, "Entering directory: %s", path);
        (void) atomicio(write, remout, path, strlen(path));
@@ -707,7 +696,7 @@ sink(argc, argv)
                if (buf[0] == '\01' || buf[0] == '\02') {
                        if (iamremote == 0)
                                (void) atomicio(write, STDERR_FILENO,
-                                            buf + 1, strlen(buf + 1));
+                                   buf + 1, strlen(buf + 1));
                        if (buf[0] == '\02')
                                exit(1);
                        ++errs;
@@ -838,8 +827,10 @@ bad:                       run_err("%s: %s", np, strerror(errno));
                                amt = size - i;
                        count += amt;
                        do {
-                               j = atomicio(read, remin, cp, amt);
-                               if (j <= 0) {
+                               j = read(remin, cp, amt);
+                               if (j == -1 && (errno == EINTR || errno == EAGAIN)) {
+                                       continue;
+                               } else if (j <= 0) {
                                        run_err("%s", j ? strerror(errno) :
                                                "dropped connection");
                                        exit(1);
@@ -1040,7 +1031,8 @@ okname(cp0)
                c = *cp;
                if (c & 0200)
                        goto bad;
-               if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
+               if (!isalpha(c) && !isdigit(c) &&
+                   c != '_' && c != '-' && c != '.' && c != '+')
                        goto bad;
        } while (*++cp);
        return (1);
@@ -1119,11 +1111,7 @@ foregroundproc()
        if (pgrp == -1)
                pgrp = getpgrp();
 
-#ifdef HAVE_CYGWIN
-       /*
-        * Cygwin only supports tcgetpgrp() for getting the controlling tty
-         * currently.
-        */
+#ifdef HAVE_TCGETPGRP
        return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 &&
                ctty_pgrp == pgrp);
 #else
@@ -1177,8 +1165,7 @@ progressmeter(int flag)
                abbrevsize >>= 10;
        }
        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5d %c%c ",
-            (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' :
-                'B');
+           (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' : 'B');
 
        timersub(&now, &lastupdate, &wait);
        if (cursize > lastsize) {
@@ -1193,16 +1180,17 @@ progressmeter(int flag)
        timersub(&now, &start, &td);
        elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
 
-       if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes) {
+       if (flag != 1 &&
+           (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) {
                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                        "   --:-- ETA");
+                   "   --:-- ETA");
        } else if (wait.tv_sec >= STALLTIME) {
                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
-                        " - stalled -");
+                   " - stalled -");
        } else {
                if (flag != 1)
-                       remaining =
-                           (int)(totalbytes / (statbytes / elapsed) - elapsed);
+                       remaining = (int)(totalbytes / (statbytes / elapsed) -
+                           elapsed);
                else
                        remaining = elapsed;
 
This page took 0.055364 seconds and 4 git commands to generate.