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

Diff for /src/usr.bin/ssh/sftp-client.c between version 1.137 and 1.138

version 1.137, 2020/10/18 11:32:02 version 1.138, 2020/11/20 03:16:56
Line 1478 
Line 1478 
         int i, ret = 0;          int i, ret = 0;
         SFTP_DIRENT **dir_entries;          SFTP_DIRENT **dir_entries;
         char *filename, *new_src = NULL, *new_dst = NULL;          char *filename, *new_src = NULL, *new_dst = NULL;
         mode_t mode = 0777;          mode_t mode = 0777, tmpmode = mode;
   
         if (depth >= MAX_DIR_DEPTH) {          if (depth >= MAX_DIR_DEPTH) {
                 error("Maximum directory depth exceeded: %d levels", depth);                  error("Maximum directory depth exceeded: %d levels", depth);
Line 1497 
Line 1497 
         if (print_flag)          if (print_flag)
                 mprintf("Retrieving %s\n", src);                  mprintf("Retrieving %s\n", src);
   
         if (dirattrib->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)          if (dirattrib->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
                 mode = dirattrib->perm & 01777;                  mode = dirattrib->perm & 01777;
         else {                  tmpmode = mode | (S_IWUSR|S_IXUSR);
           } else {
                 debug("Server did not send permissions for "                  debug("Server did not send permissions for "
                     "directory \"%s\"", dst);                      "directory \"%s\"", dst);
         }          }
   
         if (mkdir(dst, mode) == -1 && errno != EEXIST) {          if (mkdir(dst, tmpmode) == -1 && errno != EEXIST) {
                 error("mkdir %s: %s", dst, strerror(errno));                  error("mkdir %s: %s", dst, strerror(errno));
                 return -1;                  return -1;
         }          }
Line 1559 
Line 1560 
                             "\"%s\"", dst);                              "\"%s\"", dst);
         }          }
   
           if (mode != tmpmode && chmod(dst, mode) == -1)
                   error("Can't set final mode on \"%s\": %s", dst,
                       strerror(errno));
   
         free_sftp_dirents(dir_entries);          free_sftp_dirents(dir_entries);
   
         return ret;          return ret;
Line 1810 
Line 1815 
         char *filename, *new_src = NULL, *new_dst = NULL;          char *filename, *new_src = NULL, *new_dst = NULL;
         struct stat sb;          struct stat sb;
         Attrib a, *dirattrib;          Attrib a, *dirattrib;
           u_int32_t saved_perm;
   
         if (depth >= MAX_DIR_DEPTH) {          if (depth >= MAX_DIR_DEPTH) {
                 error("Maximum directory depth exceeded: %d levels", depth);                  error("Maximum directory depth exceeded: %d levels", depth);
Line 1839 
Line 1845 
         /*          /*
          * sftp lacks a portable status value to match errno EEXIST,           * sftp lacks a portable status value to match errno EEXIST,
          * so if we get a failure back then we must check whether           * so if we get a failure back then we must check whether
          * the path already existed and is a directory.           * the path already existed and is a directory.  Ensure we can
            * write to the directory we create for the duration of the transfer.
          */           */
           saved_perm = a.perm;
           a.perm |= (S_IWUSR|S_IXUSR);
         if (do_mkdir(conn, dst, &a, 0) != 0) {          if (do_mkdir(conn, dst, &a, 0) != 0) {
                 if ((dirattrib = do_stat(conn, dst, 0)) == NULL)                  if ((dirattrib = do_stat(conn, dst, 0)) == NULL)
                         return -1;                          return -1;
Line 1849 
Line 1858 
                         return -1;                          return -1;
                 }                  }
         }          }
           a.perm = saved_perm;
   
         if ((dirp = opendir(src)) == NULL) {          if ((dirp = opendir(src)) == NULL) {
                 error("Failed to open dir \"%s\": %s", src, strerror(errno));                  error("Failed to open dir \"%s\": %s", src, strerror(errno));

Legend:
Removed from v.1.137  
changed lines
  Added in v.1.138