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

Diff for /src/usr.bin/ssh/Attic/sftp-int.c between version 1.26 and 1.26.2.1

version 1.26, 2001/03/07 10:11:23 version 1.26.2.1, 2001/03/12 15:44:15
Line 40 
Line 40 
 #include "sftp-client.h"  #include "sftp-client.h"
 #include "sftp-int.h"  #include "sftp-int.h"
   
 /* File to read commands from */  
 extern FILE *infile;  
   
 /* Version of server we are speaking to */  
 int version;  
   
 /* Seperators for interactive commands */  /* Seperators for interactive commands */
 #define WHITESPACE " \t\r\n"  #define WHITESPACE " \t\r\n"
   
Line 70 
Line 64 
 #define I_RM            18  #define I_RM            18
 #define I_RMDIR         19  #define I_RMDIR         19
 #define I_SHELL         20  #define I_SHELL         20
 #define I_SYMLINK       21  
   
 struct CMD {  struct CMD {
         const char *c;          const char *c;
Line 91 
Line 84 
         { "lchdir",     I_LCHDIR },          { "lchdir",     I_LCHDIR },
         { "lls",        I_LLS },          { "lls",        I_LLS },
         { "lmkdir",     I_LMKDIR },          { "lmkdir",     I_LMKDIR },
         { "ln",         I_SYMLINK },  
         { "lpwd",       I_LPWD },          { "lpwd",       I_LPWD },
         { "ls",         I_LS },          { "ls",         I_LS },
         { "lumask",     I_LUMASK },          { "lumask",     I_LUMASK },
Line 102 
Line 94 
         { "rename",     I_RENAME },          { "rename",     I_RENAME },
         { "rm",         I_RM },          { "rm",         I_RM },
         { "rmdir",      I_RMDIR },          { "rmdir",      I_RMDIR },
         { "symlink",    I_SYMLINK },  
         { "!",          I_SHELL },          { "!",          I_SHELL },
         { "?",          I_HELP },          { "?",          I_HELP },
         { NULL,                 -1}          { NULL,                 -1}
Line 120 
Line 111 
         printf("help                          Display this help text\n");          printf("help                          Display this help text\n");
         printf("get remote-path [local-path]  Download file\n");          printf("get remote-path [local-path]  Download file\n");
         printf("lls [ls-options [path]]       Display local directory listing\n");          printf("lls [ls-options [path]]       Display local directory listing\n");
         printf("ln oldpath newpath            Symlink remote file\n");  
         printf("lmkdir path                   Create local directory\n");          printf("lmkdir path                   Create local directory\n");
         printf("lpwd                          Print local working directory\n");          printf("lpwd                          Print local working directory\n");
         printf("ls [path]                     Display remote directory listing\n");          printf("ls [path]                     Display remote directory listing\n");
Line 133 
Line 123 
         printf("rename oldpath newpath        Rename remote file\n");          printf("rename oldpath newpath        Rename remote file\n");
         printf("rmdir path                    Remove remote directory\n");          printf("rmdir path                    Remove remote directory\n");
         printf("rm path                       Delete remote file\n");          printf("rm path                       Delete remote file\n");
         printf("symlink oldpath newpath       Symlink remote file\n");  
         printf("!command                      Execute 'command' in local shell\n");          printf("!command                      Execute 'command' in local shell\n");
         printf("!                             Escape to local shell\n");          printf("!                             Escape to local shell\n");
         printf("?                             Synonym for help\n");          printf("?                             Synonym for help\n");
Line 365 
Line 354 
                         return(-1);                          return(-1);
                 break;                  break;
         case I_RENAME:          case I_RENAME:
         case I_SYMLINK:                  /* Get first pathname (mandatory) */
                 if (get_pathname(&cp, path1))                  if (get_pathname(&cp, path1))
                         return(-1);                          return(-1);
                 if (get_pathname(&cp, path2))                  if (get_pathname(&cp, path2))
Line 454 
Line 443 
         int pflag, cmdnum;          int pflag, cmdnum;
         unsigned long n_arg;          unsigned long n_arg;
         Attrib a, *aa;          Attrib a, *aa;
         char path_buf[MAXPATHLEN];          char path_buf[PATH_MAX];
         int err = 0;  
   
         path1 = path2 = NULL;          path1 = path2 = NULL;
         cmdnum = parse_args(&cmd, &pflag, &n_arg, &path1, &path2);          cmdnum = parse_args(&cmd, &pflag, &n_arg, &path1, &path2);
Line 466 
Line 454 
                 break;                  break;
         case I_GET:          case I_GET:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 err = do_download(in, out, path1, path2, pflag);                  do_download(in, out, path1, path2, pflag);
                 break;                  break;
         case I_PUT:          case I_PUT:
                 path2 = make_absolute(path2, *pwd);                  path2 = make_absolute(path2, *pwd);
                 err = do_upload(in, out, path1, path2, pflag);                  do_upload(in, out, path1, path2, pflag);
                 break;                  break;
         case I_RENAME:          case I_RENAME:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 path2 = make_absolute(path2, *pwd);                  path2 = make_absolute(path2, *pwd);
                 err = do_rename(in, out, path1, path2);                  do_rename(in, out, path1, path2);
                 break;                  break;
         case I_SYMLINK:  
                 if (version < 3) {  
                         error("The server (version %d) does not support "  
                             "this operation", version);  
                         err = -1;  
                 } else {  
                         path2 = make_absolute(path2, *pwd);  
                         err = do_symlink(in, out, path1, path2);  
                 }  
                 break;  
         case I_RM:          case I_RM:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 err = do_rm(in, out, path1);                  do_rm(in, out, path1);
                 break;                  break;
         case I_MKDIR:          case I_MKDIR:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 attrib_clear(&a);                  attrib_clear(&a);
                 a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;                  a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;
                 a.perm = 0777;                  a.perm = 0777;
                 err = do_mkdir(in, out, path1, &a);                  do_mkdir(in, out, path1, &a);
                 break;                  break;
         case I_RMDIR:          case I_RMDIR:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 err = do_rmdir(in, out, path1);                  do_rmdir(in, out, path1);
                 break;                  break;
         case I_CHDIR:          case I_CHDIR:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 if ((tmp = do_realpath(in, out, path1)) == NULL) {                  if ((tmp = do_realpath(in, out, path1)) == NULL)
                         err = 1;  
                         break;                          break;
                 }  
                 if ((aa = do_stat(in, out, tmp)) == NULL) {                  if ((aa = do_stat(in, out, tmp)) == NULL) {
                         xfree(tmp);                          xfree(tmp);
                         err = 1;  
                         break;                          break;
                 }                  }
                 if (!(aa->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) {                  if (!(aa->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) {
                         error("Can't change directory: Can't check target");                          error("Can't change directory: Can't check target");
                         xfree(tmp);                          xfree(tmp);
                         err = 1;  
                         break;                          break;
                 }                  }
                 if (!S_ISDIR(aa->perm)) {                  if (!S_ISDIR(aa->perm)) {
                         error("Can't change directory: \"%s\" is not "                          error("Can't change directory: \"%s\" is not "
                             "a directory", tmp);                              "a directory", tmp);
                         xfree(tmp);                          xfree(tmp);
                         err = 1;  
                         break;                          break;
                 }                  }
                 xfree(*pwd);                  xfree(*pwd);
Line 549 
Line 522 
                 do_ls(in, out, path1);                  do_ls(in, out, path1);
                 break;                  break;
         case I_LCHDIR:          case I_LCHDIR:
                 if (chdir(path1) == -1) {                  if (chdir(path1) == -1)
                         error("Couldn't change local directory to "                          error("Couldn't change local directory to "
                             "\"%s\": %s", path1, strerror(errno));                              "\"%s\": %s", path1, strerror(errno));
                         err = 1;  
                 }  
                 break;                  break;
         case I_LMKDIR:          case I_LMKDIR:
                 if (mkdir(path1, 0777) == -1) {                  if (mkdir(path1, 0777) == -1)
                         error("Couldn't create local directory "                          error("Couldn't create local directory "
                             "\"%s\": %s", path1, strerror(errno));                              "\"%s\": %s", path1, strerror(errno));
                         err = 1;  
                 }  
                 break;                  break;
         case I_LLS:          case I_LLS:
                 local_do_ls(cmd);                  local_do_ls(cmd);
Line 610 
Line 579 
                 break;                  break;
         case I_LPWD:          case I_LPWD:
                 if (!getcwd(path_buf, sizeof(path_buf)))                  if (!getcwd(path_buf, sizeof(path_buf)))
                         error("Couldn't get local cwd: %s",                          error("Couldn't get local cwd: %s\n",
                             strerror(errno));                              strerror(errno));
                 else                  else
                         printf("Local working directory: %s\n",                          printf("Local working directory: %s\n",
Line 629 
Line 598 
                 xfree(path1);                  xfree(path1);
         if (path2)          if (path2)
                 xfree(path2);                  xfree(path2);
   
         /* If an error occurs in batch mode we should abort. */  
         if (infile != stdin && err > 0)  
                 return -1;  
   
         return(0);          return(0);
 }  }
   
Line 643 
Line 607 
         char *pwd;          char *pwd;
         char cmd[2048];          char cmd[2048];
   
         version = do_init(fd_in, fd_out);  
         if (version == -1)  
                 fatal("Couldn't initialise connection to server");  
   
         pwd = do_realpath(fd_in, fd_out, ".");          pwd = do_realpath(fd_in, fd_out, ".");
         if (pwd == NULL)          if (pwd == NULL)
                 fatal("Need cwd");                  fatal("Need cwd");
   
         setvbuf(stdout, NULL, _IOLBF, 0);          setvbuf(stdout, NULL, _IOLBF, 0);
         setvbuf(infile, NULL, _IOLBF, 0);          setvbuf(stdin, NULL, _IOLBF, 0);
   
         for(;;) {          for(;;) {
                 char *cp;                  char *cp;
Line 660 
Line 620 
                 printf("sftp> ");                  printf("sftp> ");
   
                 /* XXX: use libedit */                  /* XXX: use libedit */
                 if (fgets(cmd, sizeof(cmd), infile) == NULL) {                  if (fgets(cmd, sizeof(cmd), stdin) == NULL) {
                         printf("\n");                          printf("\n");
                         break;                          break;
                 } else if (infile != stdin) /* Bluff typing */                  }
                         printf("%s", cmd);  
   
                 cp = strrchr(cmd, '\n');                  cp = strrchr(cmd, '\n');
                 if (cp)                  if (cp)
                         *cp = '\0';                          *cp = '\0';
   
                 if (parse_dispatch_command(fd_in, fd_out, cmd, &pwd))                  if (parse_dispatch_command(fd_in, fd_out, cmd, &pwd))
                         break;                          break;
         }          }

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.26.2.1