List: openssh-unix-dev Subject: [PATCH] add atomic rename extension to sftp-server From: Miklos Szeredi Date: 2006-08-19 15:21:10 Message-ID: E1GESdK-000363-00 () dorka ! pomaz ! szeredi ! hu This is needed to be able to support a rename() operation conforming to POSIX in the SSH filesystem. With the rename operation defined in the SFTP spec, this is impossible, since in case the target exists it's not possible to perform the rename+unlink atomically. Miklos Index: ssh/sftp-server.c =================================================================== --- ssh.orig/sftp-server.c 2006-08-19 16:49:03.000000000 +0200 +++ ssh/sftp-server.c 2006-08-19 16:51:26.000000000 +0200 @@ -1087,6 +1087,23 @@ process_extended_statfs(u_int32_t id) } static void +process_extended_posix_rename(u_int32_t id) +{ + char *oldpath, *newpath; + + oldpath = get_string(NULL); + newpath = get_string(NULL); + debug3("request %u: posix-rename", id); + logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); + if (rename(oldpath, newpath) == -1) + send_status(id, errno_to_portable(errno)); + else + send_status(id, SSH2_FX_OK); + xfree(oldpath); + xfree(newpath); +} + +static void process_extended(void) { u_int32_t id; @@ -1096,6 +1113,8 @@ process_extended(void) request = get_string(NULL); if (strcmp(request, "statfs@openssh.org") == 0) process_extended_statfs(id); + if (strcmp(request, "posix-rename@openssh.org") == 0) + process_extended_posix_rename(id); else send_status(id, SSH2_FX_OP_UNSUPPORTED); /* MUST */ xfree(request); _______________________________________________ openssh-unix-dev mailing list openssh-unix-dev@mindrot.org http://lists.mindrot.org/mailman/listinfo/openssh-unix-dev