]> andersk Git - openssh.git/blobdiff - sftp-server.c
change "No more 4-term BSD licenses in our tree" to
[openssh.git] / sftp-server.c
index 0c00003f89245cc56a42cb6ec34bea9243ef7d2d..794404ae5ae11a8ac8f8bd630206f474d52fe29b 100644 (file)
@@ -22,7 +22,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: sftp-server.c,v 1.40 2003/03/05 22:33:43 markus Exp $");
+RCSID("$OpenBSD: sftp-server.c,v 1.42 2003/04/08 20:21:29 itojun Exp $");
 
 #include "buffer.h"
 #include "bufaux.h"
@@ -442,7 +442,7 @@ process_read(void)
            (u_int64_t)off, len);
        if (len > sizeof buf) {
                len = sizeof buf;
-               log("read change len %d", len);
+               logit("read change len %d", len);
        }
        fd = handle_to_fd(handle);
        if (fd >= 0) {
@@ -495,7 +495,7 @@ process_write(void)
                        } else if (ret == len) {
                                status = SSH2_FX_OK;
                        } else {
-                               log("nothing at all written");
+                               logit("nothing at all written");
                        }
                }
        }
@@ -836,20 +836,31 @@ process_rename(void)
        u_int32_t id;
        char *oldpath, *newpath;
        int status;
+       struct stat sb;
 
        id = get_int();
        oldpath = get_string(NULL);
        newpath = get_string(NULL);
        TRACE("rename id %u old %s new %s", id, oldpath, newpath);
-       /* fail if 'newpath' exists */
-       if (link(oldpath, newpath) == -1)
+       status = SSH2_FX_FAILURE;
+       if (lstat(oldpath, &sb) == -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 (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);
        xfree(oldpath);
        xfree(newpath);
This page took 0.0344 seconds and 4 git commands to generate.