[BACK]Return to scp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/scp.c between version 1.43.2.7 and 1.44

version 1.43.2.7, 2002/03/08 17:04:43 version 1.44, 2000/12/11 17:27:33
Line 14 
Line 14 
  * called by a name other than "ssh" or "Secure Shell".   * called by a name other than "ssh" or "Secure Shell".
  */   */
 /*  /*
  * Copyright (c) 1999 Theo de Raadt.  All rights reserved.   * Copyright (c) 1999 Theo de Raadt. All rights reserved.
  * Copyright (c) 1999 Aaron Campbell.  All rights reserved.   * Copyright (c) 1999 Aaron Campbell. All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 77 
Line 77 
 #include "includes.h"  #include "includes.h"
 RCSID("$OpenBSD$");  RCSID("$OpenBSD$");
   
   #include "ssh.h"
 #include "xmalloc.h"  #include "xmalloc.h"
 #include "atomicio.h"  
 #include "pathnames.h"  
 #include "log.h"  
 #include "misc.h"  
   
   #define _PATH_CP "cp"
   
 /* For progressmeter() -- number of seconds before xfer considered "stalled" */  /* For progressmeter() -- number of seconds before xfer considered "stalled" */
 #define STALLTIME       5  #define STALLTIME       5
 /* alarm() interval for updating progress meter */  
 #define PROGRESSTIME    1  
   
 /* Visual statistics about files as they are transferred. */  /* Visual statistics about files as they are transferred. */
 void progressmeter(int);  void progressmeter(int);
Line 95 
Line 92 
 int getttywidth(void);  int getttywidth(void);
 int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc);  int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc);
   
 /* Struct for addargs */  /* setup arguments for the call to ssh */
 arglist args;  void addargs(char *fmt, ...) __attribute__((format(printf, 1, 2)));
   
 /* Time a transfer started. */  /* Time a transfer started. */
 static struct timeval start;  static struct timeval start;
   
 /* Number of bytes of current file transferred so far. */  /* Number of bytes of current file transferred so far. */
 volatile off_t statbytes;  volatile unsigned long statbytes;
   
 /* Total size of current file. */  /* Total size of current file. */
 off_t totalbytes = 0;  off_t totalbytes = 0;
Line 113 
Line 110 
 /* This is set to non-zero to enable verbose mode. */  /* This is set to non-zero to enable verbose mode. */
 int verbose_mode = 0;  int verbose_mode = 0;
   
   /* This is set to non-zero if compression is desired. */
   int compress = 0;
   
 /* This is set to zero if the progressmeter is not desired. */  /* This is set to zero if the progressmeter is not desired. */
 int showprogress = 1;  int showprogress = 1;
   
 /* This is the program to execute for the secured connection. ("ssh" or -S) */  /* This is the program to execute for the secured connection. ("ssh" or -S) */
 char *ssh_program = _PATH_SSH_PROGRAM;  char *ssh_program = SSH_PROGRAM;
   
   /* This is the list of arguments that scp passes to ssh */
   struct {
           char    **list;
           int     num;
           int     nalloc;
   } args;
   
 /*  /*
  * This function executes the given command as the specified user on the   * This function executes the given command as the specified user on the
  * given host.  This returns < 0 if execution fails, and >= 0 otherwise. This   * given host.  This returns < 0 if execution fails, and >= 0 otherwise. This
Line 131 
Line 138 
         int pin[2], pout[2], reserved[2];          int pin[2], pout[2], reserved[2];
   
         if (verbose_mode)          if (verbose_mode)
                 fprintf(stderr,                  fprintf(stderr, "Executing: program %s host %s, user %s, command %s\n",
                     "Executing: program %s host %s, user %s, command %s\n",                      ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
                     ssh_program, host,  
                     remuser ? remuser : "(unspecified)", cmd);  
   
         /*          /*
          * Reserve two descriptors so that the real pipes won't get           * Reserve two descriptors so that the real pipes won't get
Line 164 
Line 169 
   
                 args.list[0] = ssh_program;                  args.list[0] = ssh_program;
                 if (remuser != NULL)                  if (remuser != NULL)
                         addargs(&args, "-l%s", remuser);                          addargs("-l%s", remuser);
                 addargs(&args, "%s", host);                  addargs("%s", host);
                 addargs(&args, "%s", cmd);                  addargs("%s", cmd);
   
                 execvp(ssh_program, args.list);                  execvp(ssh_program, args.list);
                 perror(ssh_program);                  perror(ssh_program);
Line 180 
Line 185 
         return 0;          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 {  typedef struct {
         int cnt;          int cnt;
         char *buf;          char *buf;
 } BUF;  } BUF;
   
   extern int iamremote;
   
 BUF *allocbuf(BUF *, int, int);  BUF *allocbuf(BUF *, int, int);
   char *colon(char *);
 void lostconn(int);  void lostconn(int);
 void nospace(void);  void nospace(void);
 int okname(char *);  int okname(char *);
Line 219 
Line 240 
         extern int optind;          extern int optind;
   
         args.list = NULL;          args.list = NULL;
         addargs(&args, "ssh");          /* overwritten with ssh_program */          addargs("ssh");         /* overwritten with ssh_program */
         addargs(&args, "-x");          addargs("-x");
         addargs(&args, "-oForwardAgent no");          addargs("-oFallBackToRsh no");
         addargs(&args, "-oFallBackToRsh no");  
         addargs(&args, "-oClearAllForwardings yes");  
   
         fflag = tflag = 0;          fflag = tflag = 0;
         while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:F:")) != -1)          while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != EOF)
                 switch (ch) {                  switch (ch) {
                 /* User-visible flags. */                  /* User-visible flags. */
                 case '4':                  case '4':
                 case '6':                  case '6':
                 case 'C':                  case 'C':
                         addargs(&args, "-%c", ch);                          addargs("-%c", ch);
                         break;                          break;
                 case 'o':                  case 'o':
                 case 'c':                  case 'c':
                 case 'i':                  case 'i':
                 case 'F':                          addargs("-%c%s", ch, optarg);
                         addargs(&args, "-%c%s", ch, optarg);  
                         break;                          break;
                 case 'P':                  case 'P':
                         addargs(&args, "-p%s", optarg);                          addargs("-p%s", optarg);
                         break;                          break;
                 case 'B':                  case 'B':
                         addargs(&args, "-oBatchmode yes");                          addargs("-oBatchmode yes");
                         break;                          break;
                 case 'p':                  case 'p':
                         pflag = 1;                          pflag = 1;
Line 256 
Line 274 
                         ssh_program = xstrdup(optarg);                          ssh_program = xstrdup(optarg);
                         break;                          break;
                 case 'v':                  case 'v':
                         addargs(&args, "-v");  
                         verbose_mode = 1;                          verbose_mode = 1;
                         break;                          break;
                 case 'q':                  case 'q':
Line 275 
Line 292 
                         iamremote = 1;                          iamremote = 1;
                         tflag = 1;                          tflag = 1;
                         break;                          break;
                   case '?':
                 default:                  default:
                         usage();                          usage();
                 }                  }
Line 290 
Line 308 
         remin = STDIN_FILENO;          remin = STDIN_FILENO;
         remout = STDOUT_FILENO;          remout = STDOUT_FILENO;
   
         if (fflag) {          if (fflag) {
                 /* Follow "protocol", send data. */                  /* Follow "protocol", send data. */
                 (void) response();                  (void) response();
                 source(argc, argv);                  source(argc, argv);
Line 308 
Line 326 
   
         remin = remout = -1;          remin = remout = -1;
         /* Command to be executed on remote system using "ssh". */          /* Command to be executed on remote system using "ssh". */
         (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",          (void) sprintf(cmd, "scp%s%s%s%s", verbose_mode ? " -v" : "",
             verbose_mode ? " -v" : "",  
             iamrecursive ? " -r" : "", pflag ? " -p" : "",              iamrecursive ? " -r" : "", pflag ? " -p" : "",
             targetshouldbedirectory ? " -d" : "");              targetshouldbedirectory ? " -d" : "");
   
Line 325 
Line 342 
         exit(errs != 0);          exit(errs != 0);
 }  }
   
   char *
   cleanhostname(host)
           char *host;
   {
           if (*host == '[' && host[strlen(host) - 1] == ']') {
                   host[strlen(host) - 1] = '\0';
                   return (host + 1);
           } else
                   return host;
   }
   
 void  void
 toremote(targ, argc, argv)  toremote(targ, argc, argv)
         char *targ, *argv[];          char *targ, *argv[];
Line 353 
Line 381 
         for (i = 0; i < argc - 1; i++) {          for (i = 0; i < argc - 1; i++) {
                 src = colon(argv[i]);                  src = colon(argv[i]);
                 if (src) {      /* remote to remote */                  if (src) {      /* remote to remote */
                         static char *ssh_options =  
                             "-x -o'FallBackToRsh no' "  
                             "-o'ClearAllForwardings yes'";  
                         *src++ = 0;                          *src++ = 0;
                         if (*src == 0)                          if (*src == 0)
                                 src = ".";                                  src = ".";
                         host = strchr(argv[i], '@');                          host = strchr(argv[i], '@');
                         len = strlen(ssh_program) + strlen(argv[i]) +                          len = strlen(ssh_program) + strlen(argv[i]) +
                             strlen(src) + (tuser ? strlen(tuser) : 0) +                              strlen(src) + (tuser ? strlen(tuser) : 0) +
                             strlen(thost) + strlen(targ) +                              strlen(thost) + strlen(targ) + CMDNEEDS + 32;
                             strlen(ssh_options) + CMDNEEDS + 20;  
                         bp = xmalloc(len);                          bp = xmalloc(len);
                         if (host) {                          if (host) {
                                 *host++ = 0;                                  *host++ = 0;
Line 373 
Line 397 
                                         suser = pwd->pw_name;                                          suser = pwd->pw_name;
                                 else if (!okname(suser))                                  else if (!okname(suser))
                                         continue;                                          continue;
                                 snprintf(bp, len,                                  sprintf(bp,
                                     "%s%s %s -n "                                      "%s%s -x -o'FallBackToRsh no' -n -l %s %s %s %s '%s%s%s:%s'",
                                     "-l %s %s %s %s '%s%s%s:%s'",  
                                     ssh_program, verbose_mode ? " -v" : "",                                      ssh_program, verbose_mode ? " -v" : "",
                                     ssh_options, suser, host, cmd, src,                                      suser, host, cmd, src,
                                     tuser ? tuser : "", tuser ? "@" : "",                                      tuser ? tuser : "", tuser ? "@" : "",
                                     thost, targ);                                      thost, targ);
                         } else {                          } else {
                                 host = cleanhostname(argv[i]);                                  host = cleanhostname(argv[i]);
                                 snprintf(bp, len,                                  sprintf(bp,
                                     "exec %s%s %s -n %s "                                      "exec %s%s -x -o'FallBackToRsh no' -n %s %s %s '%s%s%s:%s'",
                                     "%s %s '%s%s%s:%s'",  
                                     ssh_program, verbose_mode ? " -v" : "",                                      ssh_program, verbose_mode ? " -v" : "",
                                     ssh_options, host, cmd, src,                                      host, cmd, src,
                                     tuser ? tuser : "", tuser ? "@" : "",                                      tuser ? tuser : "", tuser ? "@" : "",
                                     thost, targ);                                      thost, targ);
                         }                          }
Line 398 
Line 420 
                         if (remin == -1) {                          if (remin == -1) {
                                 len = strlen(targ) + CMDNEEDS + 20;                                  len = strlen(targ) + CMDNEEDS + 20;
                                 bp = xmalloc(len);                                  bp = xmalloc(len);
                                 (void) snprintf(bp, len, "%s -t %s", cmd, targ);                                  (void) sprintf(bp, "%s -t %s", cmd, targ);
                                 host = cleanhostname(thost);                                  host = cleanhostname(thost);
                                 if (do_cmd(host, tuser, bp, &remin,                                  if (do_cmd(host, tuser, bp, &remin,
                                     &remout, argc) < 0)                                      &remout, argc) < 0)
Line 425 
Line 447 
                         len = strlen(_PATH_CP) + strlen(argv[i]) +                          len = strlen(_PATH_CP) + strlen(argv[i]) +
                             strlen(argv[argc - 1]) + 20;                              strlen(argv[argc - 1]) + 20;
                         bp = xmalloc(len);                          bp = xmalloc(len);
                         (void) snprintf(bp, len, "exec %s%s%s %s %s", _PATH_CP,                          (void) sprintf(bp, "exec %s%s%s %s %s", _PATH_CP,
                             iamrecursive ? " -r" : "", pflag ? " -p" : "",                              iamrecursive ? " -r" : "", pflag ? " -p" : "",
                             argv[i], argv[argc - 1]);                              argv[i], argv[argc - 1]);
                         if (verbose_mode)                          if (verbose_mode)
Line 452 
Line 474 
                 host = cleanhostname(host);                  host = cleanhostname(host);
                 len = strlen(src) + CMDNEEDS + 20;                  len = strlen(src) + CMDNEEDS + 20;
                 bp = xmalloc(len);                  bp = xmalloc(len);
                 (void) snprintf(bp, len, "%s -f %s", cmd, src);                  (void) sprintf(bp, "%s -f %s", cmd, src);
                 if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {                  if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {
                         (void) xfree(bp);                          (void) xfree(bp);
                         ++errs;                          ++errs;
Line 473 
Line 495 
         struct stat stb;          struct stat stb;
         static BUF buffer;          static BUF buffer;
         BUF *bp;          BUF *bp;
         off_t i, amt, result;          off_t i;
         int fd, haderr, indx;          int amt, fd, haderr, indx, result;
         char *last, *name, buf[2048];          char *last, *name, buf[2048];
         int len;  
   
         for (indx = 0; indx < argc; ++indx) {          for (indx = 0; indx < argc; ++indx) {
                 name = argv[indx];                  name = argv[indx];
                 statbytes = 0;                  statbytes = 0;
                 len = strlen(name);  
                 while (len > 1 && name[len-1] == '/')  
                         name[--len] = '\0';  
                 if (strchr(name, '\n') != NULL) {  
                         run_err("%s: skipping, filename contains a newline",  
                             name);  
                         goto next;  
                 }  
                 if ((fd = open(name, O_RDONLY, 0)) < 0)                  if ((fd = open(name, O_RDONLY, 0)) < 0)
                         goto syserr;                          goto syserr;
                 if (fstat(fd, &stb) < 0) {                  if (fstat(fd, &stb) < 0) {
Line 518 
Line 531 
                          * Make it compatible with possible future                           * Make it compatible with possible future
                          * versions expecting microseconds.                           * versions expecting microseconds.
                          */                           */
                         (void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",                          (void) sprintf(buf, "T%lu 0 %lu 0\n",
                             (u_long) stb.st_mtime,                              (unsigned long) stb.st_mtime,
                             (u_long) stb.st_atime);                              (unsigned long) stb.st_atime);
                         (void) atomicio(write, remout, buf, strlen(buf));                          (void) atomicio(write, remout, buf, strlen(buf));
                         if (response() < 0)                          if (response() < 0)
                                 goto next;                                  goto next;
                 }                  }
 #define FILEMODEMASK    (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)  #define FILEMODEMASK    (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
                 snprintf(buf, sizeof buf, "C%04o %lld %s\n",                  sprintf(buf, "C%04o %lu %s\n",
                     (u_int) (stb.st_mode & FILEMODEMASK),                      (unsigned int) (stb.st_mode & FILEMODEMASK),
                     (long long)stb.st_size, last);                      (unsigned long) stb.st_size, last);
                 if (verbose_mode) {                  if (verbose_mode) {
                         fprintf(stderr, "Sending file modes: %s", buf);                          fprintf(stderr, "Sending file modes: %s", buf);
                         fflush(stderr);                          fflush(stderr);
Line 595 
Line 608 
         else          else
                 last++;                  last++;
         if (pflag) {          if (pflag) {
                 (void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",                  (void) sprintf(path, "T%lu 0 %lu 0\n",
                     (u_long) statp->st_mtime,                      (unsigned long) statp->st_mtime,
                     (u_long) statp->st_atime);                      (unsigned long) statp->st_atime);
                 (void) atomicio(write, remout, path, strlen(path));                  (void) atomicio(write, remout, path, strlen(path));
                 if (response() < 0) {                  if (response() < 0) {
                         closedir(dirp);                          closedir(dirp);
                         return;                          return;
                 }                  }
         }          }
         (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",          (void) sprintf(path, "D%04o %d %.1024s\n",
             (u_int) (statp->st_mode & FILEMODEMASK), 0, last);              (unsigned int) (statp->st_mode & FILEMODEMASK), 0, last);
         if (verbose_mode)          if (verbose_mode)
                 fprintf(stderr, "Entering directory: %s", path);                  fprintf(stderr, "Entering directory: %s", path);
         (void) atomicio(write, remout, path, strlen(path));          (void) atomicio(write, remout, path, strlen(path));
Line 613 
Line 626 
                 closedir(dirp);                  closedir(dirp);
                 return;                  return;
         }          }
         while ((dp = readdir(dirp)) != NULL) {          while ((dp = readdir(dirp))) {
                 if (dp->d_ino == 0)                  if (dp->d_ino == 0)
                         continue;                          continue;
                 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))                  if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
Line 622 
Line 635 
                         run_err("%s/%s: name too long", name, dp->d_name);                          run_err("%s/%s: name too long", name, dp->d_name);
                         continue;                          continue;
                 }                  }
                 (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name);                  (void) sprintf(path, "%s/%s", name, dp->d_name);
                 vect[0] = path;                  vect[0] = path;
                 source(1, vect);                  source(1, vect);
         }          }
Line 647 
Line 660 
         off_t size;          off_t size;
         int setimes, targisdir, wrerrno = 0;          int setimes, targisdir, wrerrno = 0;
         char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];          char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
           int dummy_usec;
         struct timeval tv[2];          struct timeval tv[2];
   
 #define atime   tv[0]  #define SCREWUP(str)    { why = str; goto screwup; }
 #define mtime   tv[1]  
 #define SCREWUP(str)    do { why = str; goto screwup; } while (0)  
   
         setimes = targisdir = 0;          setimes = targisdir = 0;
         mask = umask(0);          mask = umask(0);
Line 697 
Line 709 
                 if (ch == '\n')                  if (ch == '\n')
                         *--cp = 0;                          *--cp = 0;
   
   #define getnum(t) (t) = 0; \
     while (*cp >= '0' && *cp <= '9') (t) = (t) * 10 + (*cp++ - '0');
                 cp = buf;                  cp = buf;
                 if (*cp == 'T') {                  if (*cp == 'T') {
                         setimes++;                          setimes++;
                         cp++;                          cp++;
                         mtime.tv_sec = strtol(cp, &cp, 10);                          getnum(tv[1].tv_sec);
                         if (!cp || *cp++ != ' ')                          if (*cp++ != ' ')
                                 SCREWUP("mtime.sec not delimited");                                  SCREWUP("mtime.sec not delimited");
                         mtime.tv_usec = strtol(cp, &cp, 10);                          getnum(dummy_usec);
                         if (!cp || *cp++ != ' ')                          tv[1].tv_usec = 0;
                           if (*cp++ != ' ')
                                 SCREWUP("mtime.usec not delimited");                                  SCREWUP("mtime.usec not delimited");
                         atime.tv_sec = strtol(cp, &cp, 10);                          getnum(tv[0].tv_sec);
                         if (!cp || *cp++ != ' ')                          if (*cp++ != ' ')
                                 SCREWUP("atime.sec not delimited");                                  SCREWUP("atime.sec not delimited");
                         atime.tv_usec = strtol(cp, &cp, 10);                          getnum(dummy_usec);
                         if (!cp || *cp++ != '\0')                          tv[0].tv_usec = 0;
                           if (*cp++ != '\0')
                                 SCREWUP("atime.usec not delimited");                                  SCREWUP("atime.usec not delimited");
                         (void) atomicio(write, remout, "", 1);                          (void) atomicio(write, remout, "", 1);
                         continue;                          continue;
Line 739 
Line 755 
                 if (*cp++ != ' ')                  if (*cp++ != ' ')
                         SCREWUP("mode not delimited");                          SCREWUP("mode not delimited");
   
                 for (size = 0; isdigit(*cp);)                  for (size = 0; *cp >= '0' && *cp <= '9';)
                         size = size * 10 + (*cp++ - '0');                          size = size * 10 + (*cp++ - '0');
                 if (*cp++ != ' ')                  if (*cp++ != ' ')
                         SCREWUP("size not delimited");                          SCREWUP("size not delimited");
Line 749 
Line 765 
                         size_t need;                          size_t need;
   
                         need = strlen(targ) + strlen(cp) + 250;                          need = strlen(targ) + strlen(cp) + 250;
                         if (need > cursize) {                          if (need > cursize)
                                 if (namebuf)  
                                         xfree(namebuf);  
                                 namebuf = xmalloc(need);                                  namebuf = xmalloc(need);
                                 cursize = need;                          (void) sprintf(namebuf, "%s%s%s", targ,
                         }  
                         (void) snprintf(namebuf, need, "%s%s%s", targ,  
                             *targ ? "/" : "", cp);                              *targ ? "/" : "", cp);
                         np = namebuf;                          np = namebuf;
                 } else                  } else
Line 778 
Line 790 
                                 if (mkdir(np, mode | S_IRWXU) < 0)                                  if (mkdir(np, mode | S_IRWXU) < 0)
                                         goto bad;                                          goto bad;
                         }                          }
                         vect[0] = xstrdup(np);                          vect[0] = np;
                         sink(1, vect);                          sink(1, vect);
                         if (setimes) {                          if (setimes) {
                                 setimes = 0;                                  setimes = 0;
                                 if (utimes(vect[0], tv) < 0)                                  if (utimes(np, tv) < 0)
                                         run_err("%s: set times: %s",                                          run_err("%s: set times: %s",
                                             vect[0], strerror(errno));                                                  np, strerror(errno));
                         }                          }
                         if (mod_flag)                          if (mod_flag)
                                 (void) chmod(vect[0], mode);                                  (void) chmod(np, mode);
                         if (vect[0])  
                                 xfree(vect[0]);  
                         continue;                          continue;
                 }                  }
                 omode = mode;                  omode = mode;
                 mode |= S_IWRITE;                  mode |= S_IWRITE;
                 if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) < 0) {                  if ((ofd = open(np, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) {
 bad:                    run_err("%s: %s", np, strerror(errno));  bad:                    run_err("%s: %s", np, strerror(errno));
                         continue;                          continue;
                 }                  }
Line 818 
Line 828 
                         count += amt;                          count += amt;
                         do {                          do {
                                 j = read(remin, cp, amt);                                  j = read(remin, cp, amt);
                                 if (j == -1 && (errno == EINTR ||                                  if (j == -1 && (errno == EINTR || errno == EAGAIN)) {
                                     errno == EAGAIN)) {  
                                         continue;                                          continue;
                                 } else if (j <= 0) {                                  } else if (j <= 0) {
                                         run_err("%s", j ? strerror(errno) :                                          run_err("%s", j ? strerror(errno) :
                                             "dropped connection");                                                  "dropped connection");
                                         exit(1);                                          exit(1);
                                 }                                  }
                                 amt -= j;                                  amt -= j;
Line 850 
Line 859 
                         wrerr = YES;                          wrerr = YES;
                         wrerrno = j >= 0 ? EIO : errno;                          wrerrno = j >= 0 ? EIO : errno;
                 }                  }
   #if 0
                 if (ftruncate(ofd, size)) {                  if (ftruncate(ofd, size)) {
                         run_err("%s: truncate: %s", np, strerror(errno));                          run_err("%s: truncate: %s", np, strerror(errno));
                         wrerr = DISPLAYED;                          wrerr = DISPLAYED;
                 }                  }
   #endif
                 if (pflag) {                  if (pflag) {
                         if (exists || omode != mode)                          if (exists || omode != mode)
                                 if (fchmod(ofd, omode))                                  if (fchmod(ofd, omode))
                                         run_err("%s: set mode: %s",                                          run_err("%s: set mode: %s",
                                             np, strerror(errno));                                                  np, strerror(errno));
                 } else {                  } else {
                         if (!exists && omode != mode)                          if (!exists && omode != mode)
                                 if (fchmod(ofd, omode & ~mask))                                  if (fchmod(ofd, omode & ~mask))
                                         run_err("%s: set mode: %s",                                          run_err("%s: set mode: %s",
                                             np, strerror(errno));                                                  np, strerror(errno));
                 }                  }
                 if (close(ofd) == -1) {                  if (close(ofd) == -1) {
                         wrerr = YES;                          wrerr = YES;
Line 874 
Line 885 
                         setimes = 0;                          setimes = 0;
                         if (utimes(np, tv) < 0) {                          if (utimes(np, tv) < 0) {
                                 run_err("%s: set times: %s",                                  run_err("%s: set times: %s",
                                     np, strerror(errno));                                          np, strerror(errno));
                                 wrerr = DISPLAYED;                                  wrerr = DISPLAYED;
                         }                          }
                 }                  }
Line 895 
Line 906 
 }  }
   
 int  int
 response(void)  response()
 {  {
         char ch, *cp, resp, rbuf[2048];          char ch, *cp, resp, rbuf[2048];
   
Line 928 
Line 939 
 }  }
   
 void  void
 usage(void)  usage()
 {  {
         (void) fprintf(stderr,          (void) fprintf(stderr, "usage: scp "
             "usage: scp [-pqrvBC46] [-F config] [-S ssh] [-P port] [-c cipher] [-i identity]\n"              "[-pqrvC46] [-S ssh] [-P port] [-c cipher] [-i identity] f1 f2; or:\n"
             "           [-o option] f1 f2\n"              "       scp [options] f1 ... fn directory\n");
             "   or: scp [options] f1 ... fn directory\n");  
         exit(1);          exit(1);
 }  }
   
Line 942 
Line 952 
 {  {
         static FILE *fp;          static FILE *fp;
         va_list ap;          va_list ap;
           va_start(ap, fmt);
   
         ++errs;          ++errs;
         if (fp == NULL && !(fp = fdopen(remout, "w")))          if (fp == NULL && !(fp = fdopen(remout, "w")))
                 return;                  return;
         (void) fprintf(fp, "%c", 0x01);          (void) fprintf(fp, "%c", 0x01);
         (void) fprintf(fp, "scp: ");          (void) fprintf(fp, "scp: ");
         va_start(ap, fmt);  
         (void) vfprintf(fp, fmt, ap);          (void) vfprintf(fp, fmt, ap);
         va_end(ap);  
         (void) fprintf(fp, "\n");          (void) fprintf(fp, "\n");
         (void) fflush(fp);          (void) fflush(fp);
   
         if (!iamremote) {          if (!iamremote) {
                 va_start(ap, fmt);  
                 vfprintf(stderr, fmt, ap);                  vfprintf(stderr, fmt, ap);
                 va_end(ap);  
                 fprintf(stderr, "\n");                  fprintf(stderr, "\n");
         }          }
           va_end(ap);
 }  }
   
   char *
   colon(cp)
           char *cp;
   {
           int flag = 0;
   
           if (*cp == ':')         /* Leading colon is part of file name. */
                   return (0);
           if (*cp == '[')
                   flag = 1;
   
           for (; *cp; ++cp) {
                   if (*cp == '@' && *(cp+1) == '[')
                           flag = 1;
                   if (*cp == ']' && *(cp+1) == ':' && flag)
                           return (cp+1);
                   if (*cp == ':' && !flag)
                           return (cp);
                   if (*cp == '/')
                           return (0);
           }
           return (0);
   }
   
 void  void
 verifydir(cp)  verifydir(cp)
         char *cp;          char *cp;
Line 986 
Line 1018 
   
         cp = cp0;          cp = cp0;
         do {          do {
                 c = (int)*cp;                  c = *cp;
                 if (c & 0200)                  if (c & 0200)
                         goto bad;                          goto bad;
                 if (!isalpha(c) && !isdigit(c) &&                  if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-' && c != '.')
                     c != '_' && c != '-' && c != '.' && c != '+')  
                         goto bad;                          goto bad;
         } while (*++cp);          } while (*++cp);
         return (1);          return (1);
Line 1022 
Line 1053 
                 bp->buf = xmalloc(size);                  bp->buf = xmalloc(size);
         else          else
                 bp->buf = xrealloc(bp->buf, size);                  bp->buf = xrealloc(bp->buf, size);
         memset(bp->buf, 0, size);  
         bp->cnt = size;          bp->cnt = size;
         return (bp);          return (bp);
 }  }
Line 1032 
Line 1062 
         int signo;          int signo;
 {  {
         if (!iamremote)          if (!iamremote)
                 write(STDERR_FILENO, "lost connection\n", 16);                  fprintf(stderr, "lost connection\n");
         if (signo)          exit(1);
                 _exit(1);  
         else  
                 exit(1);  
 }  }
   
 static void  
   void
   alarmtimer(int wait)
   {
           struct itimerval itv;
   
           itv.it_value.tv_sec = wait;
           itv.it_value.tv_usec = 0;
           itv.it_interval = itv.it_value;
           setitimer(ITIMER_REAL, &itv, NULL);
   }
   
   void
 updateprogressmeter(int ignore)  updateprogressmeter(int ignore)
 {  {
         int save_errno = errno;          int save_errno = errno;
   
         progressmeter(0);          progressmeter(0);
         signal(SIGALRM, updateprogressmeter);  
         alarm(PROGRESSTIME);  
         errno = save_errno;          errno = save_errno;
 }  }
   
 static int  int
 foregroundproc(void)  foregroundproc()
 {  {
         static pid_t pgrp = -1;          static pid_t pgrp = -1;
         int ctty_pgrp;          int ctty_pgrp;
Line 1099 
Line 1136 
                 i = barlength * ratio / 100;                  i = barlength * ratio / 100;
                 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),                  snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
                     "|%.*s%*s|", i,                      "|%.*s%*s|", i,
                     "***************************************"                      "*****************************************************************************"
                     "***************************************"                      "*****************************************************************************",
                     "***************************************"  
                     "***************************************",  
                     barlength - i, "");                      barlength - i, "");
         }          }
         i = 0;          i = 0;
Line 1111 
Line 1146 
                 i++;                  i++;
                 abbrevsize >>= 10;                  abbrevsize >>= 10;
         }          }
         snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5llu %c%c ",          snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5qd %c%c ",
             (unsigned long long) abbrevsize, prefixes[i],              (quad_t) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' : 'B');
             prefixes[i] == ' ' ? ' ' : 'B');  
   
         timersub(&now, &lastupdate, &wait);          timersub(&now, &lastupdate, &wait);
         if (cursize > lastsize) {          if (cursize > lastsize) {
Line 1158 
Line 1192 
   
         if (flag == -1) {          if (flag == -1) {
                 signal(SIGALRM, updateprogressmeter);                  signal(SIGALRM, updateprogressmeter);
                 alarm(PROGRESSTIME);                  alarmtimer(1);
         } else if (flag == 1) {          } else if (flag == 1) {
                 alarm(0);                  alarmtimer(0);
                 atomicio(write, fileno(stdout), "\n", 1);                  atomicio(write, fileno(stdout), "\n", 1);
                 statbytes = 0;                  statbytes = 0;
         }          }
Line 1175 
Line 1209 
                 return (winsize.ws_col ? winsize.ws_col : 80);                  return (winsize.ws_col ? winsize.ws_col : 80);
         else          else
                 return (80);                  return (80);
   }
   
   void
   addargs(char *fmt, ...)
   {
           va_list ap;
           char buf[1024];
   
           va_start(ap, fmt);
           vsnprintf(buf, sizeof(buf), fmt, ap);
           va_end(ap);
   
           if (args.list == NULL) {
                   args.nalloc = 32;
                   args.num = 0;
                   args.list = xmalloc(args.nalloc * sizeof(char *));
           } else if (args.num+2 >= args.nalloc) {
                   args.nalloc *= 2;
                   args.list = xrealloc(args.list, args.nalloc * sizeof(char *));
           }
           args.list[args.num++] = xstrdup(buf);
           args.list[args.num] = NULL;
 }  }

Legend:
Removed from v.1.43.2.7  
changed lines
  Added in v.1.44