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

Diff for /src/usr.bin/ssh/sftp-server.c between version 1.38 and 1.38.2.2

version 1.38, 2002/09/11 22:41:50 version 1.38.2.2, 2003/04/03 23:27:12
Line 152 
Line 152 
                         handles[i].use = use;                          handles[i].use = use;
                         handles[i].dirp = dirp;                          handles[i].dirp = dirp;
                         handles[i].fd = fd;                          handles[i].fd = fd;
                         handles[i].name = name;                          handles[i].name = xstrdup(name);
                         return i;                          return i;
                 }                  }
         }          }
Line 224 
Line 224 
         if (handle_is_ok(handle, HANDLE_FILE)) {          if (handle_is_ok(handle, HANDLE_FILE)) {
                 ret = close(handles[handle].fd);                  ret = close(handles[handle].fd);
                 handles[handle].use = HANDLE_UNUSED;                  handles[handle].use = HANDLE_UNUSED;
                   xfree(handles[handle].name);
         } else if (handle_is_ok(handle, HANDLE_DIR)) {          } else if (handle_is_ok(handle, HANDLE_DIR)) {
                 ret = closedir(handles[handle].dirp);                  ret = closedir(handles[handle].dirp);
                 handles[handle].use = HANDLE_UNUSED;                  handles[handle].use = HANDLE_UNUSED;
                   xfree(handles[handle].name);
         } else {          } else {
                 errno = ENOENT;                  errno = ENOENT;
         }          }
Line 390 
Line 392 
         if (fd < 0) {          if (fd < 0) {
                 status = errno_to_portable(errno);                  status = errno_to_portable(errno);
         } else {          } else {
                 handle = handle_new(HANDLE_FILE, xstrdup(name), fd, NULL);                  handle = handle_new(HANDLE_FILE, name, fd, NULL);
                 if (handle < 0) {                  if (handle < 0) {
                         close(fd);                          close(fd);
                 } else {                  } else {
Line 661 
Line 663 
         if (dirp == NULL) {          if (dirp == NULL) {
                 status = errno_to_portable(errno);                  status = errno_to_portable(errno);
         } else {          } else {
                 handle = handle_new(HANDLE_DIR, xstrdup(path), 0, dirp);                  handle = handle_new(HANDLE_DIR, path, 0, dirp);
                 if (handle < 0) {                  if (handle < 0) {
                         closedir(dirp);                          closedir(dirp);
                 } else {                  } else {
Line 812 
Line 814 
 process_rename(void)  process_rename(void)
 {  {
         u_int32_t id;          u_int32_t id;
         struct stat st;  
         char *oldpath, *newpath;          char *oldpath, *newpath;
         int ret, status = SSH2_FX_FAILURE;          int status;
           struct stat sb;
   
         id = get_int();          id = get_int();
         oldpath = get_string(NULL);          oldpath = get_string(NULL);
         newpath = get_string(NULL);          newpath = get_string(NULL);
         TRACE("rename id %u old %s new %s", id, oldpath, newpath);          TRACE("rename id %u old %s new %s", id, oldpath, newpath);
         /* fail if 'newpath' exists */          status = SSH2_FX_FAILURE;
         if (stat(newpath, &st) == -1) {          if (lstat(oldpath, &sb) == -1)
                 ret = rename(oldpath, newpath);                  status = errno_to_portable(errno);
                 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;          else if (S_ISREG(sb.st_mode)) {
                   /* Race-free rename of regular files */
                   if (link(oldpath, newpath) == -1)
                           status = errno_to_portable(errno);
                   else if (unlink(oldpath) == -1) {
                           status = errno_to_portable(errno);
                           /* clean spare link */
                           unlink(newpath);
                   } else
                           status = SSH2_FX_OK;
           } else if (stat(newpath, &sb) == -1) {
                   if (rename(oldpath, newpath) == -1)
                           status = errno_to_portable(errno);
                   else
                           status = SSH2_FX_OK;
         }          }
         send_status(id, status);          send_status(id, status);
         xfree(oldpath);          xfree(oldpath);
Line 858 
Line 874 
 process_symlink(void)  process_symlink(void)
 {  {
         u_int32_t id;          u_int32_t id;
         struct stat st;  
         char *oldpath, *newpath;          char *oldpath, *newpath;
         int ret, status = SSH2_FX_FAILURE;          int ret, status;
   
         id = get_int();          id = get_int();
         oldpath = get_string(NULL);          oldpath = get_string(NULL);
         newpath = get_string(NULL);          newpath = get_string(NULL);
         TRACE("symlink id %u old %s new %s", id, oldpath, newpath);          TRACE("symlink id %u old %s new %s", id, oldpath, newpath);
         /* fail if 'newpath' exists */          /* this will fail if 'newpath' exists */
         if (stat(newpath, &st) == -1) {          ret = symlink(oldpath, newpath);
                 ret = symlink(oldpath, newpath);          status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
                 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;  
         }  
         send_status(id, status);          send_status(id, status);
         xfree(oldpath);          xfree(oldpath);
         xfree(newpath);          xfree(newpath);

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.38.2.2