[PATCH 2/4] add SFTPv4 constants & handle error & file mode strings

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

 



Just register the new SFTPv4 constants, and fill out the utility funcs
that translate some of them to strings.  No code actually uses SFTPv4.
---
 sftp-server.c | 23 +++++++++++++++++++++--
 sftp.h        | 27 ++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/sftp-server.c b/sftp-server.c
index 859e93f31111..bef7b6c18aa7 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -222,11 +222,15 @@ errno_to_portable(int unixerrno)
 	case 0:
 		ret = SSH2_FX_OK;
 		break;
+	case EBADF:
+		ret = sftp_version <= 3 ? SSH2_FX_NO_SUCH_FILE :
+		    SSH2_FX_INVALID_HANDLE;
+		break;
 	case ENOENT:
 	case ENOTDIR:
-	case EBADF:
 	case ELOOP:
-		ret = SSH2_FX_NO_SUCH_FILE;
+		ret = sftp_version <= 3 ? SSH2_FX_NO_SUCH_PATH :
+		   SSH2_FX_NO_SUCH_FILE;
 		break;
 	case EPERM:
 	case EACCES:
@@ -240,6 +244,14 @@ errno_to_portable(int unixerrno)
 	case ENOSYS:
 		ret = SSH2_FX_OP_UNSUPPORTED;
 		break;
+	case EEXIST:
+		ret = sftp_version <= 3 ? SSH2_FX_FAILURE :
+		    SSH2_FX_FILE_ALREADY_EXISTS;
+		break;
+	case EROFS:
+		ret = sftp_version <= 3 ? SSH2_FX_FAILURE :
+		    SSH2_FX_WRITE_PROTECT;
+		break;
 	default:
 		ret = SSH2_FX_FAILURE;
 		break;
@@ -296,6 +308,8 @@ string_from_portable(int pflags)
 		PAPPEND("TRUNCATE")
 	if (pflags & SSH2_FXF_EXCL)
 		PAPPEND("EXCL")
+	if (sftp_version >= 4 && pflags & SSH2_FXF_TEXT)
+		PAPPEND("TEXT")
 
 	return ret;
 }
@@ -536,6 +550,11 @@ status_to_message(u_int32_t status)
 		"No connection",		/* SSH_FX_NO_CONNECTION */
 		"Connection lost",		/* SSH_FX_CONNECTION_LOST */
 		"Operation unsupported",	/* SSH_FX_OP_UNSUPPORTED */
+		"Invalid handle",		/* SSH_FX_INVALID_HANDLE */
+		"No such path",			/* SSH_FX_NO_SUCH_PATH */
+		"File already exists",		/* SSH_FX_FILE_ALREADY_EXISTS */
+		"Write protected",		/* SSH_FX_WRITE_PROTECT */
+		"No media",			/* SSH_FX_NO_MEDIA */
 		"Unknown error"			/* Others */
 	};
 	return (status_messages[MINIMUM(status,SSH2_FX_MAX)]);
diff --git a/sftp.h b/sftp.h
index 4c22bcc81bb6..2489a212d36d 100644
--- a/sftp.h
+++ b/sftp.h
@@ -25,7 +25,7 @@
  */
 
 /*
- * draft-ietf-secsh-filexfer-01.txt
+ * draft-ietf-secsh-filexfer-02.txt & draft-ietf-secsh-filexfer-04.txt
  */
 
 /* client to server */
@@ -61,12 +61,26 @@
 #define SSH2_FXP_EXTENDED		200
 #define SSH2_FXP_EXTENDED_REPLY		201
 
-/* attributes */
+/* SFTPv3 attributes */
 #define SSH2_FILEXFER_ATTR_SIZE		0x00000001
 #define SSH2_FILEXFER_ATTR_UIDGID	0x00000002
 #define SSH2_FILEXFER_ATTR_PERMISSIONS	0x00000004
 #define SSH2_FILEXFER_ATTR_ACMODTIME	0x00000008
 #define SSH2_FILEXFER_ATTR_EXTENDED	0x80000000
+/* SFTPv4 attributes */
+#define SSH2_FILEXFER_ATTR_ACCESSTIME	0x00000008
+#define SSH2_FILEXFER_ATTR_CREATETIME	0x00000010
+#define SSH2_FILEXFER_ATTR_MODIFYTIME	0x00000020
+#define SSH2_FILEXFER_ATTR_ACL		0x00000040
+#define SSH2_FILEXFER_ATTR_OWNERGROUP	0x00000080
+#define SSH2_FILEXFER_ATTR_SUBSECOND_TIMES	0x00000100
+
+/* SFTPv4 types */
+#define SSH2_FILEXFER_TYPE_REGULAR	1
+#define SSH2_FILEXFER_TYPE_DIRECTORY	2
+#define SSH2_FILEXFER_TYPE_SYMLINK	3
+#define SSH2_FILEXFER_TYPE_SPECIAL	4
+#define SSH2_FILEXFER_TYPE_UNKNOWN	5
 
 /* portable open modes */
 #define SSH2_FXF_READ			0x00000001
@@ -75,6 +89,7 @@
 #define SSH2_FXF_CREAT			0x00000008
 #define SSH2_FXF_TRUNC			0x00000010
 #define SSH2_FXF_EXCL			0x00000020
+#define SSH2_FXF_TEXT			0x00000040
 
 /* statvfs@xxxxxxxxxxx f_flag flags */
 #define SSH2_FXE_STATVFS_ST_RDONLY	0x00000001
@@ -90,7 +105,13 @@
 #define SSH2_FX_NO_CONNECTION		6
 #define SSH2_FX_CONNECTION_LOST		7
 #define SSH2_FX_OP_UNSUPPORTED		8
-#define SSH2_FX_MAX			8
+/* SFTPv4 errors */
+#define SSH2_FX_INVALID_HANDLE		9
+#define SSH2_FX_NO_SUCH_PATH		10
+#define SSH2_FX_FILE_ALREADY_EXISTS	11
+#define SSH2_FX_WRITE_PROTECT		12
+#define SSH2_FX_NO_MEDIA		13
+#define SSH2_FX_MAX			13
 
 struct passwd;
 
-- 
2.33.0

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



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

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux