diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | sftp-server.c | 28 |
2 files changed, 18 insertions, 15 deletions
@@ -48,6 +48,9 @@ | |||
48 | - markus@cvs.openbsd.org 2003/02/06 09:27:29 | 48 | - markus@cvs.openbsd.org 2003/02/06 09:27:29 |
49 | [ssh.c ssh_config.5] | 49 | [ssh.c ssh_config.5] |
50 | support 'ProxyCommand none'; bugzilla #433; binder@arago.de; ok djm@ | 50 | support 'ProxyCommand none'; bugzilla #433; binder@arago.de; ok djm@ |
51 | - markus@cvs.openbsd.org 2003/02/06 09:29:18 | ||
52 | [sftp-server.c] | ||
53 | fix races in rename/symlink; from Tony Finch; ok djm@ | ||
51 | 54 | ||
52 | 20030211 | 55 | 20030211 |
53 | - (djm) Cygwin needs libcrypt too. Patch from vinschen@redhat.com | 56 | - (djm) Cygwin needs libcrypt too. Patch from vinschen@redhat.com |
@@ -1148,4 +1151,4 @@ | |||
1148 | save auth method before monitor_reset_key_state(); bugzilla bug #284; | 1151 | save auth method before monitor_reset_key_state(); bugzilla bug #284; |
1149 | ok provos@ | 1152 | ok provos@ |
1150 | 1153 | ||
1151 | $Id: ChangeLog,v 1.2606 2003/02/24 00:57:32 djm Exp $ | 1154 | $Id: ChangeLog,v 1.2607 2003/02/24 00:58:44 djm Exp $ |
diff --git a/sftp-server.c b/sftp-server.c index 84264693d..4eb31d94e 100644 --- a/sftp-server.c +++ b/sftp-server.c | |||
@@ -22,7 +22,7 @@ | |||
22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | */ | 23 | */ |
24 | #include "includes.h" | 24 | #include "includes.h" |
25 | RCSID("$OpenBSD: sftp-server.c,v 1.38 2002/09/11 22:41:50 djm Exp $"); | 25 | RCSID("$OpenBSD: sftp-server.c,v 1.39 2003/02/06 09:29:18 markus Exp $"); |
26 | 26 | ||
27 | #include "buffer.h" | 27 | #include "buffer.h" |
28 | #include "bufaux.h" | 28 | #include "bufaux.h" |
@@ -832,19 +832,22 @@ static void | |||
832 | process_rename(void) | 832 | process_rename(void) |
833 | { | 833 | { |
834 | u_int32_t id; | 834 | u_int32_t id; |
835 | struct stat st; | ||
836 | char *oldpath, *newpath; | 835 | char *oldpath, *newpath; |
837 | int ret, status = SSH2_FX_FAILURE; | 836 | int status; |
838 | 837 | ||
839 | id = get_int(); | 838 | id = get_int(); |
840 | oldpath = get_string(NULL); | 839 | oldpath = get_string(NULL); |
841 | newpath = get_string(NULL); | 840 | newpath = get_string(NULL); |
842 | TRACE("rename id %u old %s new %s", id, oldpath, newpath); | 841 | TRACE("rename id %u old %s new %s", id, oldpath, newpath); |
843 | /* fail if 'newpath' exists */ | 842 | /* fail if 'newpath' exists */ |
844 | if (stat(newpath, &st) == -1) { | 843 | if (link(oldpath, newpath) == -1) |
845 | ret = rename(oldpath, newpath); | 844 | status = errno_to_portable(errno); |
846 | status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; | 845 | else if (unlink(oldpath) == -1) { |
847 | } | 846 | status = errno_to_portable(errno); |
847 | /* clean spare link */ | ||
848 | unlink(newpath); | ||
849 | } else | ||
850 | status = SSH2_FX_OK; | ||
848 | send_status(id, status); | 851 | send_status(id, status); |
849 | xfree(oldpath); | 852 | xfree(oldpath); |
850 | xfree(newpath); | 853 | xfree(newpath); |
@@ -878,19 +881,16 @@ static void | |||
878 | process_symlink(void) | 881 | process_symlink(void) |
879 | { | 882 | { |
880 | u_int32_t id; | 883 | u_int32_t id; |
881 | struct stat st; | ||
882 | char *oldpath, *newpath; | 884 | char *oldpath, *newpath; |
883 | int ret, status = SSH2_FX_FAILURE; | 885 | int ret, status; |
884 | 886 | ||
885 | id = get_int(); | 887 | id = get_int(); |
886 | oldpath = get_string(NULL); | 888 | oldpath = get_string(NULL); |
887 | newpath = get_string(NULL); | 889 | newpath = get_string(NULL); |
888 | TRACE("symlink id %u old %s new %s", id, oldpath, newpath); | 890 | TRACE("symlink id %u old %s new %s", id, oldpath, newpath); |
889 | /* fail if 'newpath' exists */ | 891 | /* this will fail if 'newpath' exists */ |
890 | if (stat(newpath, &st) == -1) { | 892 | ret = symlink(oldpath, newpath); |
891 | ret = symlink(oldpath, newpath); | 893 | status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; |
892 | status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; | ||
893 | } | ||
894 | send_status(id, status); | 894 | send_status(id, status); |
895 | xfree(oldpath); | 895 | xfree(oldpath); |
896 | xfree(newpath); | 896 | xfree(newpath); |