[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#352589: patch



The patch below around the problem for me.  It's rather ugly in that
it violates the semantics specified for (this version of) SFTP, but
those semantics are impossible to implement on filesystems that lack
hard links in any case.

My current plan is to use a separate SFTP server, with this patch, in
/usr/local/bin.  However the patch's behaviour might be suitable with
some kind of toggle for controlling, perhaps an SFTP extension where
the client declares what rename semantics it wants.

I note that draft-ietf-secsh-filexfer-12.txt (not implemented in this
version of OpenSSH) specifies an additional flags word to
SSH_FXP_RENAME which may be sufficient to request rename(2) behaviour,
which is what I actually wanted in the first place.

ttfn/rjk

--- sftp-server.c.orig	2006-07-09 12:07:07.000000000 +0100
+++ sftp-server.c	2006-07-09 12:11:23.000000000 +0100
@@ -839,9 +839,22 @@
 		status = errno_to_portable(errno);
 	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) {
+		if (link(oldpath, newpath) == -1) {
+			if(errno == EPERM) {
+				/* Writing to a filesystem that does not
+				 * support link(), for instance FAT32.  Instead
+				 * of just giving up we accept alternative
+				 * rename semantics as a workaround.
+				 *
+				 * http://bugs.debian.org/352589
+				 */
+				if(rename(oldpath, newpath) == -1)
+					status = errno_to_portable(errno);
+				else
+					status = SSH2_FX_OK;
+			} else
+				status = errno_to_portable(errno);
+		} else if (unlink(oldpath) == -1) {
 			status = errno_to_portable(errno);
 			/* clean spare link */
 			unlink(newpath);




Reply to: