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

Diff for /src/usr.bin/ssh/sftp.c between version 1.31 and 1.31.2.2

version 1.31, 2002/07/25 01:16:59 version 1.31.2.2, 2003/09/16 21:20:27
Line 26 
Line 26 
   
 RCSID("$OpenBSD$");  RCSID("$OpenBSD$");
   
 /* XXX: short-form remote directory listings (like 'ls -C') */  
   
 #include "buffer.h"  #include "buffer.h"
 #include "xmalloc.h"  #include "xmalloc.h"
 #include "log.h"  #include "log.h"
Line 42 
Line 40 
 FILE* infile;  FILE* infile;
 size_t copy_buffer_len = 32768;  size_t copy_buffer_len = 32768;
 size_t num_requests = 16;  size_t num_requests = 16;
   static pid_t sshpid = -1;
   
   extern int showprogress;
   
 static void  static void
 connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid)  killchild(int signo)
 {  {
           if (sshpid > 1)
                   kill(sshpid, signo);
   
           _exit(1);
   }
   
   static void
   connect_to_server(char *path, char **args, int *in, int *out)
   {
         int c_in, c_out;          int c_in, c_out;
   
 #ifdef USE_PIPES  #ifdef USE_PIPES
Line 66 
Line 76 
         c_in = c_out = inout[1];          c_in = c_out = inout[1];
 #endif /* USE_PIPES */  #endif /* USE_PIPES */
   
         if ((*sshpid = fork()) == -1)          if ((sshpid = fork()) == -1)
                 fatal("fork: %s", strerror(errno));                  fatal("fork: %s", strerror(errno));
         else if (*sshpid == 0) {          else if (sshpid == 0) {
                 if ((dup2(c_in, STDIN_FILENO) == -1) ||                  if ((dup2(c_in, STDIN_FILENO) == -1) ||
                     (dup2(c_out, STDOUT_FILENO) == -1)) {                      (dup2(c_out, STDOUT_FILENO) == -1)) {
                         fprintf(stderr, "dup2: %s\n", strerror(errno));                          fprintf(stderr, "dup2: %s\n", strerror(errno));
Line 83 
Line 93 
                 exit(1);                  exit(1);
         }          }
   
           signal(SIGTERM, killchild);
           signal(SIGINT, killchild);
           signal(SIGHUP, killchild);
         close(c_in);          close(c_in);
         close(c_out);          close(c_out);
 }  }
Line 93 
Line 106 
         extern char *__progname;          extern char *__progname;
   
         fprintf(stderr,          fprintf(stderr,
             "usage: %s [-vC1] [-b batchfile] [-o option] [-s subsystem|path] [-B buffer_size]\n"              "usage: %s [-vC1] [-b batchfile] [-o ssh_option] [-s subsystem | sftp_server]\n"
             "            [-F config] [-P direct server path] [-S program]\n"              "            [-B buffer_size] [-F ssh_config] [-P sftp_server path]\n"
               "            [-R num_requests] [-S program]\n"
             "            [user@]host[:file [file]]\n", __progname);              "            [user@]host[:file [file]]\n", __progname);
         exit(1);          exit(1);
 }  }
Line 102 
Line 116 
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         int in, out, ch;          int in, out, ch, err;
         pid_t sshpid;  
         char *host, *userhost, *cp, *file2;          char *host, *userhost, *cp, *file2;
         int debug_level = 0, sshver = 2;          int debug_level = 0, sshver = 2;
         char *file1 = NULL, *sftp_server = NULL;          char *file1 = NULL, *sftp_server = NULL;
Line 155 
Line 168 
                                         fatal("%s (%s).", strerror(errno), optarg);                                          fatal("%s (%s).", strerror(errno), optarg);
                         } else                          } else
                                 fatal("Filename already specified.");                                  fatal("Filename already specified.");
                           showprogress = 0;
                         break;                          break;
                 case 'P':                  case 'P':
                         sftp_direct = optarg;                          sftp_direct = optarg;
Line 190 
Line 204 
                         file1 = cp;                          file1 = cp;
                 }                  }
   
                 if ((host = strchr(userhost, '@')) == NULL)                  if ((host = strrchr(userhost, '@')) == NULL)
                         host = userhost;                          host = userhost;
                 else {                  else {
                         *host++ = '\0';                          *host++ = '\0';
Line 219 
Line 233 
                 args.list[0] = ssh_program;                  args.list[0] = ssh_program;
   
                 fprintf(stderr, "Connecting to %s...\n", host);                  fprintf(stderr, "Connecting to %s...\n", host);
                 connect_to_server(ssh_program, args.list, &in, &out,                  connect_to_server(ssh_program, args.list, &in, &out);
                     &sshpid);  
         } else {          } else {
                 args.list = NULL;                  args.list = NULL;
                 addargs(&args, "sftp-server");                  addargs(&args, "sftp-server");
   
                 fprintf(stderr, "Attaching to %s...\n", sftp_direct);                  fprintf(stderr, "Attaching to %s...\n", sftp_direct);
                 connect_to_server(sftp_direct, args.list, &in, &out,                  connect_to_server(sftp_direct, args.list, &in, &out);
                     &sshpid);  
         }          }
   
         interactive_loop(in, out, file1, file2);          err = interactive_loop(in, out, file1, file2);
   
         close(in);          close(in);
         close(out);          close(out);
Line 242 
Line 254 
                         fatal("Couldn't wait for ssh process: %s",                          fatal("Couldn't wait for ssh process: %s",
                             strerror(errno));                              strerror(errno));
   
         exit(0);          exit(err == 0 ? 0 : 1);
 }  }

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.31.2.2