[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.91.2.1 and 1.91.2.2

version 1.91.2.1, 2003/04/01 00:12:14 version 1.91.2.2, 2003/09/16 21:20:27
Line 52 
Line 52 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 107 
Line 103 
 char *ssh_program = _PATH_SSH_PROGRAM;  char *ssh_program = _PATH_SSH_PROGRAM;
   
 /* This is used to store the pid of ssh_program */  /* This is used to store the pid of ssh_program */
 pid_t do_cmd_pid;  pid_t do_cmd_pid = -1;
   
   static void
   killchild(int signo)
   {
           if (do_cmd_pid > 1)
                   kill(do_cmd_pid, signo);
   
           _exit(1);
   }
   
 /*  /*
  * 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 142 
Line 147 
         close(reserved[0]);          close(reserved[0]);
         close(reserved[1]);          close(reserved[1]);
   
         /* For a child to execute the command on the remote host using ssh. */          /* Fork a child to execute the command on the remote host using ssh. */
         do_cmd_pid = fork();          do_cmd_pid = fork();
         if (do_cmd_pid == 0) {          if (do_cmd_pid == 0) {
                 /* Child. */                  /* Child. */
Line 170 
Line 175 
         *fdout = pin[1];          *fdout = pin[1];
         close(pout[1]);          close(pout[1]);
         *fdin = pout[0];          *fdin = pout[0];
           signal(SIGTERM, killchild);
           signal(SIGINT, killchild);
           signal(SIGHUP, killchild);
         return 0;          return 0;
 }  }
   
Line 202 
Line 210 
 void usage(void);  void usage(void);
   
 int  int
 main(argc, argv)  main(int argc, char **argv)
         int argc;  
         char *argv[];  
 {  {
         int ch, fflag, tflag, status;          int ch, fflag, tflag, status;
         double speed;          double speed;
Line 283 
Line 289 
         argv += optind;          argv += optind;
   
         if ((pwd = getpwuid(userid = getuid())) == NULL)          if ((pwd = getpwuid(userid = getuid())) == NULL)
                 fatal("unknown user %d", (int) userid);                  fatal("unknown user %u", (u_int) userid);
   
         if (!isatty(STDERR_FILENO))          if (!isatty(STDERR_FILENO))
                 showprogress = 0;                  showprogress = 0;
Line 344 
Line 350 
 }  }
   
 void  void
 toremote(targ, argc, argv)  toremote(char *targ, int argc, char **argv)
         char *targ, *argv[];  
         int argc;  
 {  {
         int i, len;          int i, len;
         char *bp, *host, *src, *suser, *thost, *tuser;          char *bp, *host, *src, *suser, *thost, *tuser;
Line 434 
Line 438 
 }  }
   
 void  void
 tolocal(argc, argv)  tolocal(int argc, char **argv)
         int argc;  
         char *argv[];  
 {  {
         int i, len;          int i, len;
         char *bp, *host, *src, *suser;          char *bp, *host, *src, *suser;
Line 485 
Line 487 
 }  }
   
 void  void
 source(argc, argv)  source(int argc, char **argv)
         int argc;  
         char *argv[];  
 {  {
         struct stat stb;          struct stat stb;
         static BUF buffer;          static BUF buffer;
Line 540 
Line 540 
                         (void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",                          (void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",
                             (u_long) stb.st_mtime,                              (u_long) stb.st_mtime,
                             (u_long) stb.st_atime);                              (u_long) stb.st_atime);
                         (void) atomicio(write, remout, buf, strlen(buf));                          (void) atomicio(vwrite, remout, buf, strlen(buf));
                         if (response() < 0)                          if (response() < 0)
                                 goto next;                                  goto next;
                 }                  }
Line 551 
Line 551 
                 if (verbose_mode) {                  if (verbose_mode) {
                         fprintf(stderr, "Sending file modes: %s", buf);                          fprintf(stderr, "Sending file modes: %s", buf);
                 }                  }
                 (void) atomicio(write, remout, buf, strlen(buf));                  (void) atomicio(vwrite, remout, buf, strlen(buf));
                 if (response() < 0)                  if (response() < 0)
                         goto next;                          goto next;
                 if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {                  if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
Line 571 
Line 571 
                                         haderr = result >= 0 ? EIO : errno;                                          haderr = result >= 0 ? EIO : errno;
                         }                          }
                         if (haderr)                          if (haderr)
                                 (void) atomicio(write, remout, bp->buf, amt);                                  (void) atomicio(vwrite, remout, bp->buf, amt);
                         else {                          else {
                                 result = atomicio(write, remout, bp->buf, amt);                                  result = atomicio(vwrite, remout, bp->buf, amt);
                                 if (result != amt)                                  if (result != amt)
                                         haderr = result >= 0 ? EIO : errno;                                          haderr = result >= 0 ? EIO : errno;
                                 statbytes += result;                                  statbytes += result;
Line 587 
Line 587 
                 if (close(fd) < 0 && !haderr)                  if (close(fd) < 0 && !haderr)
                         haderr = errno;                          haderr = errno;
                 if (!haderr)                  if (!haderr)
                         (void) atomicio(write, remout, "", 1);                          (void) atomicio(vwrite, remout, "", 1);
                 else                  else
                         run_err("%s: %s", name, strerror(haderr));                          run_err("%s: %s", name, strerror(haderr));
                 (void) response();                  (void) response();
Line 595 
Line 595 
 }  }
   
 void  void
 rsource(name, statp)  rsource(char *name, struct stat *statp)
         char *name;  
         struct stat *statp;  
 {  {
         DIR *dirp;          DIR *dirp;
         struct dirent *dp;          struct dirent *dp;
Line 616 
Line 614 
                 (void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",                  (void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",
                     (u_long) statp->st_mtime,                      (u_long) statp->st_mtime,
                     (u_long) statp->st_atime);                      (u_long) statp->st_atime);
                 (void) atomicio(write, remout, path, strlen(path));                  (void) atomicio(vwrite, remout, path, strlen(path));
                 if (response() < 0) {                  if (response() < 0) {
                         closedir(dirp);                          closedir(dirp);
                         return;                          return;
Line 626 
Line 624 
             (u_int) (statp->st_mode & FILEMODEMASK), 0, last);              (u_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(vwrite, remout, path, strlen(path));
         if (response() < 0) {          if (response() < 0) {
                 closedir(dirp);                  closedir(dirp);
                 return;                  return;
Line 645 
Line 643 
                 source(1, vect);                  source(1, vect);
         }          }
         (void) closedir(dirp);          (void) closedir(dirp);
         (void) atomicio(write, remout, "E\n", 2);          (void) atomicio(vwrite, remout, "E\n", 2);
         (void) response();          (void) response();
 }  }
   
Line 704 
Line 702 
 }  }
   
 void  void
 sink(argc, argv)  sink(int argc, char **argv)
         int argc;  
         char *argv[];  
 {  {
         static BUF buffer;          static BUF buffer;
         struct stat stb;          struct stat stb;
Line 737 
Line 733 
         if (targetshouldbedirectory)          if (targetshouldbedirectory)
                 verifydir(targ);                  verifydir(targ);
   
         (void) atomicio(write, remout, "", 1);          (void) atomicio(vwrite, remout, "", 1);
         if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))          if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
                 targisdir = 1;                  targisdir = 1;
         for (first = 1;; first = 0) {          for (first = 1;; first = 0) {
Line 755 
Line 751 
   
                 if (buf[0] == '\01' || buf[0] == '\02') {                  if (buf[0] == '\01' || buf[0] == '\02') {
                         if (iamremote == 0)                          if (iamremote == 0)
                                 (void) atomicio(write, STDERR_FILENO,                                  (void) atomicio(vwrite, STDERR_FILENO,
                                     buf + 1, strlen(buf + 1));                                      buf + 1, strlen(buf + 1));
                         if (buf[0] == '\02')                          if (buf[0] == '\02')
                                 exit(1);                                  exit(1);
Line 763 
Line 759 
                         continue;                          continue;
                 }                  }
                 if (buf[0] == 'E') {                  if (buf[0] == 'E') {
                         (void) atomicio(write, remout, "", 1);                          (void) atomicio(vwrite, remout, "", 1);
                         return;                          return;
                 }                  }
                 if (ch == '\n')                  if (ch == '\n')
Line 785 
Line 781 
                         atime.tv_usec = strtol(cp, &cp, 10);                          atime.tv_usec = strtol(cp, &cp, 10);
                         if (!cp || *cp++ != '\0')                          if (!cp || *cp++ != '\0')
                                 SCREWUP("atime.usec not delimited");                                  SCREWUP("atime.usec not delimited");
                         (void) atomicio(write, remout, "", 1);                          (void) atomicio(vwrite, remout, "", 1);
                         continue;                          continue;
                 }                  }
                 if (*cp != 'C' && *cp != 'D') {                  if (*cp != 'C' && *cp != 'D') {
Line 870 
Line 866 
 bad:                    run_err("%s: %s", np, strerror(errno));  bad:                    run_err("%s: %s", np, strerror(errno));
                         continue;                          continue;
                 }                  }
                 (void) atomicio(write, remout, "", 1);                  (void) atomicio(vwrite, remout, "", 1);
                 if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {                  if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
                         (void) close(ofd);                          (void) close(ofd);
                         continue;                          continue;
Line 907 
Line 903 
                         if (count == bp->cnt) {                          if (count == bp->cnt) {
                                 /* Keep reading so we stay sync'd up. */                                  /* Keep reading so we stay sync'd up. */
                                 if (wrerr == NO) {                                  if (wrerr == NO) {
                                         j = atomicio(write, ofd, bp->buf, count);                                          j = atomicio(vwrite, ofd, bp->buf, count);
                                         if (j != count) {                                          if (j != count) {
                                                 wrerr = YES;                                                  wrerr = YES;
                                                 wrerrno = j >= 0 ? EIO : errno;                                                  wrerrno = j >= 0 ? EIO : errno;
Line 920 
Line 916 
                 if (showprogress)                  if (showprogress)
                         stop_progress_meter();                          stop_progress_meter();
                 if (count != 0 && wrerr == NO &&                  if (count != 0 && wrerr == NO &&
                     (j = atomicio(write, ofd, bp->buf, count)) != count) {                      (j = atomicio(vwrite, ofd, bp->buf, count)) != count) {
                         wrerr = YES;                          wrerr = YES;
                         wrerrno = j >= 0 ? EIO : errno;                          wrerrno = j >= 0 ? EIO : errno;
                 }                  }
Line 957 
Line 953 
                         run_err("%s: %s", np, strerror(wrerrno));                          run_err("%s: %s", np, strerror(wrerrno));
                         break;                          break;
                 case NO:                  case NO:
                         (void) atomicio(write, remout, "", 1);                          (void) atomicio(vwrite, remout, "", 1);
                         break;                          break;
                 case DISPLAYED:                  case DISPLAYED:
                         break;                          break;
Line 992 
Line 988 
                 } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');                  } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
   
                 if (!iamremote)                  if (!iamremote)
                         (void) atomicio(write, STDERR_FILENO, rbuf, cp - rbuf);                          (void) atomicio(vwrite, STDERR_FILENO, rbuf, cp - rbuf);
                 ++errs;                  ++errs;
                 if (resp == 1)                  if (resp == 1)
                         return (-1);                          return (-1);
Line 1037 
Line 1033 
 }  }
   
 void  void
 verifydir(cp)  verifydir(char *cp)
         char *cp;  
 {  {
         struct stat stb;          struct stat stb;
   
Line 1052 
Line 1047 
 }  }
   
 int  int
 okname(cp0)  okname(char *cp0)
         char *cp0;  
 {  {
         int c;          int c;
         char *cp;          char *cp;
Line 1083 
Line 1077 
 }  }
   
 BUF *  BUF *
 allocbuf(bp, fd, blksize)  allocbuf(BUF *bp, int fd, int blksize)
         BUF *bp;  
         int fd, blksize;  
 {  {
         size_t size;          size_t size;
         struct stat stb;          struct stat stb;
Line 1109 
Line 1101 
 }  }
   
 void  void
 lostconn(signo)  lostconn(int signo)
         int signo;  
 {  {
         if (!iamremote)          if (!iamremote)
                 write(STDERR_FILENO, "lost connection\n", 16);                  write(STDERR_FILENO, "lost connection\n", 16);

Legend:
Removed from v.1.91.2.1  
changed lines
  Added in v.1.91.2.2