contrib: smb2: backport patches from master
authorThomas Guillem <thomas@gllm.fr>
Tue, 12 Feb 2019 11:48:43 +0000 (12:48 +0100)
committerThomas Guillem <thomas@gllm.fr>
Tue, 12 Feb 2019 11:48:43 +0000 (12:48 +0100)
Waiting for a future release.

contrib/src/smb2/0001-master-backport.patch [new file with mode: 0644]
contrib/src/smb2/rules.mak

diff --git a/contrib/src/smb2/0001-master-backport.patch b/contrib/src/smb2/0001-master-backport.patch
new file mode 100644 (file)
index 0000000..0f9cf7c
--- /dev/null
@@ -0,0 +1,330 @@
+From 49525025f8c91ae14e5fe3cfea0dc7948b7f5480 Mon Sep 17 00:00:00 2001
+From: Thomas Guillem <thomas@gllm.fr>
+Date: Tue, 12 Feb 2019 12:42:37 +0100
+Subject: [PATCH] master-backport
+
+Waiting for a new release, including the following patches:
+
+libsmb_error patch
+Delete libsmb2_error.latest.patch
+Allow passing NULL to smb2_set_password
+Add more error status
+Map more EACCESS error status
+---
+ include/smb2/smb2-errors.h |  50 +++++++++++
+ lib/errors.c               | 178 +++++++++++++++++++++++++++++++++++--
+ lib/init.c                 |   4 +
+ 3 files changed, 223 insertions(+), 9 deletions(-)
+
+diff --git a/include/smb2/smb2-errors.h b/include/smb2/smb2-errors.h
+index 49c5d5c..3b741e7 100644
+--- a/include/smb2/smb2-errors.h
++++ b/include/smb2/smb2-errors.h
+@@ -35,13 +35,63 @@
+ /* Error codes */
+ #define SMB2_STATUS_SUCCESS                  0x00000000
+ #define SMB2_STATUS_PENDING                  0x00000103
++#define SMB2_STATUS_SMB_BAD_FID              0x00060001
+ #define SMB2_STATUS_NO_MORE_FILES            0x80000006
++#define SMB2_STATUS_NOT_IMPLEMENTED          0xC0000002
++#define SMB2_STATUS_INVALID_HANDLE           0xC0000008
+ #define SMB2_STATUS_INVALID_PARAMETER        0xC000000d
++#define SMB2_STATUS_NO_SUCH_DEVICE           0xC000000E
++#define SMB2_STATUS_NO_SUCH_FILE             0xC000000F
++#define SMB2_STATUS_INVALID_DEVICE_REQUEST   0xC0000010
+ #define SMB2_STATUS_END_OF_FILE              0xC0000011
++#define SMB2_STATUS_NO_MEDIA_IN_DEVICE       0xC0000013
+ #define SMB2_STATUS_MORE_PROCESSING_REQUIRED 0xC0000016
++#define SMB2_STATUS_INVALID_LOCK_SEQUENCE    0xC000001E
++#define SMB2_STATUS_INVALID_VIEW_SIZE        0xC000001F
++#define SMB2_STATUS_ALREADY_COMMITTED        0xC0000021
+ #define SMB2_STATUS_ACCESS_DENIED            0xC0000022
++#define SMB2_STATUS_OBJECT_TYPE_MISMATCH     0xC0000024
+ #define SMB2_STATUS_OBJECT_NAME_NOT_FOUND    0xC0000034
++#define SMB2_STATUS_OBJECT_NAME_COLLISION    0xC0000035
++#define SMB2_STATUS_PORT_DISCONNECTED        0xC0000037
++#define SMB2_STATUS_OBJECT_PATH_INVALID      0xC0000039
++#define SMB2_STATUS_OBJECT_PATH_NOT_FOUND    0xC000003A
++#define SMB2_STATUS_OBJECT_PATH_SYNTAX_BAD   0xC000003B
++#define SMB2_STATUS_DATA_ERROR               0xC000003E
++#define SMB2_STATUS_CRC_ERROR                0xC000003F
++#define SMB2_STATUS_SECTION_TOO_BIG          0xC0000040
++#define SMB2_STATUS_PORT_CONNECTION_REFUSED  0xC0000041
++#define SMB2_STATUS_INVALID_PORT_HANDLE      0xC0000042
++#define SMB2_STATUS_SHARING_VIOLATION        0xC0000043
++#define SMB2_STATUS_THREAD_IS_TERMINATING    0xC000004B
++#define SMB2_STATUS_FILE_LOCK_CONFLICT       0xC0000054
++#define SMB2_STATUS_LOCK_NOT_GRANTED         0xC0000055
++#define SMB2_STATUS_DELETE_PENDING           0xC0000056
++#define SMB2_STATUS_PRIVILEGE_NOT_HELD       0xC0000061
+ #define SMB2_STATUS_LOGON_FAILURE            0xC000006d
++#define SMB2_STATUS_ACCOUNT_RESTRICTION      0xC000006E
++#define SMB2_STATUS_INVALID_LOGON_HOURS      0xC000006F
++#define SMB2_STATUS_PASSWORD_EXPIRED         0xC0000071
++#define SMB2_STATUS_ACCOUNT_DISABLED         0xC0000072
++#define SMB2_STATUS_DISK_FULL                0xC000007F
++#define SMB2_STATUS_TOO_MANY_PAGING_FILES    0xC0000097
++#define SMB2_STATUS_DFS_EXIT_PATH_FOUND      0xC000009B
++#define SMB2_STATUS_DEVICE_DATA_ERROR        0xC000009C
++#define SMB2_STATUS_MEDIA_WRITE_PROTECTED    0xC00000A2
++#define SMB2_STATUS_ILLEGAL_FUNCTION         0xC00000AF
++#define SMB2_STATUS_PIPE_DISCONNECTED        0xC00000B0
++#define SMB2_STATUS_FILE_IS_A_DIRECTORY      0xC00000BA
++#define SMB2_STATUS_NETWORK_ACCESS_DENIED    0xC00000CA
+ #define SMB2_STATUS_BAD_NETWORK_NAME         0xC00000CC
++#define SMB2_STATUS_NOT_SAME_DEVICE          0xC00000D4
++#define SMB2_STATUS_FILE_RENAMED             0xC00000D5
++#define SMB2_STATUS_REDIRECTOR_NOT_STARTED   0xC00000FB
++#define SMB2_STATUS_DIRECTORY_NOT_EMPTY      0xC0000101
+ #define SMB2_STATUS_NOT_A_DIRECTORY          0xC0000103
++#define SMB2_STATUS_PROCESS_IS_TERMINATING   0xC000010A
++#define SMB2_STATUS_TOO_MANY_OPENED_FILES    0xC000011F
++#define SMB2_STATUS_CANNOT_DELETE            0xC0000121
++#define SMB2_STATUS_FILE_DELETED             0xC0000123
+ #define SMB2_STATUS_FILE_CLOSED              0xC0000128
++#define SMB2_STATUS_INSUFF_SERVER_RESOURCES  0xC0000205
++#define SMB2_STATUS_HANDLE_NOT_CLOSABLE      0xC0000235
+diff --git a/lib/errors.c b/lib/errors.c
+index 68150a0..2e1648d 100644
+--- a/lib/errors.c
++++ b/lib/errors.c
+@@ -30,26 +30,124 @@ const char *nterror_to_str(uint32_t status) {
+                 return "STATUS_PENDING";
+         case SMB2_STATUS_NO_MORE_FILES:
+                 return "STATUS_NO_MORE_FILES";
++        case SMB2_STATUS_NOT_IMPLEMENTED:
++                return "STATUS_NOT_IMPLEMENTED";
++        case SMB2_STATUS_INVALID_HANDLE:
++                return "STATUS_INVALID_HANDLE";
++        case SMB2_STATUS_INVALID_PARAMETER:
++                return "STATUS_INVALID_PARAMETER";
++        case SMB2_STATUS_NO_SUCH_DEVICE:
++                return "STATUS_NO_SUCH_DEVICE";
++        case SMB2_STATUS_NO_SUCH_FILE:
++                return "STATUS_NO_SUCH_FILE";
++        case SMB2_STATUS_INVALID_DEVICE_REQUEST:
++                return "STATUS_INVALID_DEVICE_REQUEST";
++        case SMB2_STATUS_END_OF_FILE:
++                return "STATUS_END_OF_FILE";
++        case SMB2_STATUS_NO_MEDIA_IN_DEVICE:
++                return "STATUS_NO_MEDIA_IN_DEVICE";
+         case SMB2_STATUS_MORE_PROCESSING_REQUIRED:
+                 return "STATUS_MORE_PROCESSING_REQUIRED";
++        case SMB2_STATUS_INVALID_LOCK_SEQUENCE:
++                return "STATUS_INVALID_LOCK_SEQUENCE";
++        case SMB2_STATUS_INVALID_VIEW_SIZE:
++                return "STATUS_INVALID_VIEW_SIZE";
++        case SMB2_STATUS_ALREADY_COMMITTED:
++                return "STATUS_ALREADY_COMMITTED";
+         case SMB2_STATUS_ACCESS_DENIED:
+                 return "STATUS_ACCESS_DENIED";
++        case SMB2_STATUS_OBJECT_TYPE_MISMATCH:
++                return "STATUS_OBJECT_TYPE_MISMATCH";
++        case SMB2_STATUS_OBJECT_NAME_NOT_FOUND:
++                return "STATUS_OBJECT_NAME_NOT_FOUND";
++        case SMB2_STATUS_OBJECT_NAME_COLLISION:
++                return "STATUS_OBJECT_NAME_COLLISION";
++        case SMB2_STATUS_PORT_DISCONNECTED:
++                return "STATUS_PORT_DISCONNECTED";
++        case SMB2_STATUS_OBJECT_PATH_INVALID:
++                return "STATUS_OBJECT_PATH_INVALID";
++        case SMB2_STATUS_OBJECT_PATH_NOT_FOUND:
++                return "STATUS_OBJECT_PATH_NOT_FOUND";
++        case SMB2_STATUS_OBJECT_PATH_SYNTAX_BAD:
++                return "STATUS_OBJECT_PATH_SYNTAX_BAD";
++        case SMB2_STATUS_DATA_ERROR:
++                return "STATUS_DATA_ERROR";
++        case SMB2_STATUS_CRC_ERROR:
++                return "STATUS_CRC_ERROR";
++        case SMB2_STATUS_SECTION_TOO_BIG:
++                return "STATUS_SECTION_TOO_BIG";
++        case SMB2_STATUS_PORT_CONNECTION_REFUSED:
++                return "STATUS_PORT_CONNECTION_REFUSED";
++        case SMB2_STATUS_INVALID_PORT_HANDLE:
++                return "STATUS_INVALID_PORT_HANDLE";
++        case SMB2_STATUS_SHARING_VIOLATION:
++                return "STATUS_SHARING_VIOLATION";
++        case SMB2_STATUS_THREAD_IS_TERMINATING:
++                return "STATUS_THREAD_IS_TERMINATING";
++        case SMB2_STATUS_FILE_LOCK_CONFLICT:
++                return "STATUS_FILE_LOCK_CONFLICT";
++        case SMB2_STATUS_LOCK_NOT_GRANTED:
++                return "STATUS_LOCK_NOT_GRANTED";
++        case SMB2_STATUS_DELETE_PENDING:
++                return "STATUS_DELETE_PENDING";
++        case SMB2_STATUS_PRIVILEGE_NOT_HELD:
++                return "STATUS_PRIVILEGE_NOT_HELD";
+         case SMB2_STATUS_LOGON_FAILURE:
+                 return "STATUS_LOGON_FAILURE";
++        case SMB2_STATUS_ACCOUNT_RESTRICTION:
++                return "STATUS_ACCOUNT_RESTRICTION";
++        case SMB2_STATUS_INVALID_LOGON_HOURS:
++                return "STATUS_INVALID_LOGON_HOURS";
++        case SMB2_STATUS_PASSWORD_EXPIRED:
++                return "STATUS_PASSWORD_EXPIRED";
++        case SMB2_STATUS_ACCOUNT_DISABLED:
++                return "STATUS_ACCOUNT_DISABLED";
++        case SMB2_STATUS_DISK_FULL:
++                return "STATUS_DISK_FULL";
++        case SMB2_STATUS_TOO_MANY_PAGING_FILES:
++                return "STATUS_TOO_MANY_PAGING_FILES";
++        case SMB2_STATUS_DFS_EXIT_PATH_FOUND:
++                return "STATUS_DFS_EXIT_PATH_FOUND";
++        case SMB2_STATUS_DEVICE_DATA_ERROR:
++                return "STATUS_DEVICE_DATA_ERROR";
++        case SMB2_STATUS_MEDIA_WRITE_PROTECTED:
++                return "STATUS_MEDIA_WRITE_PROTECTED";
++        case SMB2_STATUS_ILLEGAL_FUNCTION:
++                return "STATUS_ILLEGAL_FUNCTION";
++        case SMB2_STATUS_PIPE_DISCONNECTED:
++                return "STATUS_PIPE_DISCONNECTED";
++        case SMB2_STATUS_FILE_IS_A_DIRECTORY:
++                return "STATUS_FILE_IS_A_DIRECTORY";
++        case SMB2_STATUS_NETWORK_ACCESS_DENIED:
++                return "STATUS_NETWORK_ACCESS_DENIED";
+         case SMB2_STATUS_BAD_NETWORK_NAME:
+                 return "STATUS_BAD_NETWORK_NAME";
++        case SMB2_STATUS_NOT_SAME_DEVICE:
++                return "STATUS_NOT_SAME_DEVICE";
++        case SMB2_STATUS_FILE_RENAMED:
++                return "STATUS_FILE_RENAMED";
++        case SMB2_STATUS_REDIRECTOR_NOT_STARTED:
++                return "STATUS_REDIRECTOR_NOT_STARTED";
++        case SMB2_STATUS_DIRECTORY_NOT_EMPTY:
++                return "STATUS_DIRECTORY_NOT_EMPTY";
+         case SMB2_STATUS_NOT_A_DIRECTORY:
+                 return "STATUS_NOT_A_DIRECTORY";
+-        case SMB2_STATUS_INVALID_PARAMETER:
+-                return "STATUS_INVALID_PARAMETER";
+-        case SMB2_STATUS_END_OF_FILE:
+-                return "STATUS_END_OF_FILE";
++        case SMB2_STATUS_PROCESS_IS_TERMINATING:
++                return "STATUS_PROCESS_IS_TERMINATING";
++        case SMB2_STATUS_TOO_MANY_OPENED_FILES:
++                return "STATUS_TOO_MANY_OPENED_FILES";
++        case SMB2_STATUS_CANNOT_DELETE:
++                return "STATUS_CANNOT_DELETE";
++        case SMB2_STATUS_FILE_DELETED:
++                return "STATUS_FILE_DELETED";
+         case SMB2_STATUS_FILE_CLOSED:
+                 return "STATUS_FILE_CLOSED";
+-        case SMB2_STATUS_OBJECT_NAME_NOT_FOUND:
+-                return "STATUS_OBJECT_NAME_NOT_FOUND";
++        case SMB2_STATUS_INSUFF_SERVER_RESOURCES:
++                return "STATUS_INSUFF_SERVER_RESOURCES";
++        case SMB2_STATUS_HANDLE_NOT_CLOSABLE:
++                return "STATUS_HANDLE_NOT_CLOSABLE";
+         default:
+-                return "Unknown";
++                 return "Unknown";
+         }
+ }
+@@ -58,25 +156,87 @@ int nterror_to_errno(uint32_t status) {
+         case SMB2_STATUS_SUCCESS:
+         case SMB2_STATUS_END_OF_FILE:
+                 return 0;
++        case SMB2_STATUS_PENDING:
++                return EAGAIN;
++        case SMB2_STATUS_NO_SUCH_FILE:
++        case SMB2_STATUS_NO_SUCH_DEVICE:
+         case SMB2_STATUS_BAD_NETWORK_NAME:
+         case SMB2_STATUS_OBJECT_NAME_NOT_FOUND:
++        case SMB2_STATUS_OBJECT_PATH_INVALID:
++        case SMB2_STATUS_OBJECT_PATH_NOT_FOUND:
++        case SMB2_STATUS_OBJECT_PATH_SYNTAX_BAD:
++        case SMB2_STATUS_DFS_EXIT_PATH_FOUND:
++        case SMB2_STATUS_REDIRECTOR_NOT_STARTED:
+                 return ENOENT;
+         case SMB2_STATUS_FILE_CLOSED:
++        case SMB2_STATUS_SMB_BAD_FID:
++        case SMB2_STATUS_INVALID_HANDLE:
++        case SMB2_STATUS_OBJECT_TYPE_MISMATCH:
++        case SMB2_STATUS_PORT_DISCONNECTED:
++        case SMB2_STATUS_INVALID_PORT_HANDLE:
++        case SMB2_STATUS_HANDLE_NOT_CLOSABLE:
+                 return EBADF;
+         case SMB2_STATUS_MORE_PROCESSING_REQUIRED:
+                 return EAGAIN;
+         case SMB2_STATUS_ACCESS_DENIED:
++        case SMB2_STATUS_NETWORK_ACCESS_DENIED:
++        case SMB2_STATUS_ACCOUNT_RESTRICTION:
++        case SMB2_STATUS_INVALID_LOGON_HOURS:
++        case SMB2_STATUS_PASSWORD_EXPIRED:
++        case SMB2_STATUS_ACCOUNT_DISABLED:
+                 return EACCES;
+-        case SMB2_STATUS_PENDING:
+-                return EAGAIN;
++        case SMB2_STATUS_INVALID_LOCK_SEQUENCE:
++        case SMB2_STATUS_INVALID_VIEW_SIZE:
++        case SMB2_STATUS_ALREADY_COMMITTED:
++        case SMB2_STATUS_PORT_CONNECTION_REFUSED:
++        case SMB2_STATUS_THREAD_IS_TERMINATING:
++        case SMB2_STATUS_DELETE_PENDING:
++        case SMB2_STATUS_PRIVILEGE_NOT_HELD:
++        case SMB2_STATUS_FILE_IS_A_DIRECTORY:
++        case SMB2_STATUS_FILE_RENAMED:
++        case SMB2_STATUS_PROCESS_IS_TERMINATING:
++        case SMB2_STATUS_DIRECTORY_NOT_EMPTY:
++        case SMB2_STATUS_CANNOT_DELETE:
++        case SMB2_STATUS_FILE_DELETED:
++                return EPERM;
+         case SMB2_STATUS_NO_MORE_FILES:
+                 return ENODATA;
+         case SMB2_STATUS_LOGON_FAILURE:
+                 return ECONNREFUSED;
+         case SMB2_STATUS_NOT_A_DIRECTORY:
+                 return ENOTDIR;
++        case SMB2_STATUS_NOT_IMPLEMENTED:
++        case SMB2_STATUS_INVALID_DEVICE_REQUEST:
++        case SMB2_STATUS_ILLEGAL_FUNCTION:
+         case SMB2_STATUS_INVALID_PARAMETER:
+                 return EINVAL;
++        case SMB2_STATUS_TOO_MANY_OPENED_FILES:
++                return EMFILE;
++        case SMB2_STATUS_SECTION_TOO_BIG:
++        case SMB2_STATUS_TOO_MANY_PAGING_FILES:
++        case SMB2_STATUS_INSUFF_SERVER_RESOURCES:
++                return ENOMEM;
++        case SMB2_STATUS_NOT_SAME_DEVICE:
++                return EXDEV;
++        case SMB2_STATUS_SHARING_VIOLATION:
++                return ETXTBSY;
++        case SMB2_STATUS_FILE_LOCK_CONFLICT:
++        case SMB2_STATUS_LOCK_NOT_GRANTED:
++                return EDEADLK;
++        case SMB2_STATUS_OBJECT_NAME_COLLISION:
++                return EEXIST;
++        case SMB2_STATUS_PIPE_DISCONNECTED:
++                return EPIPE;
++        case SMB2_STATUS_MEDIA_WRITE_PROTECTED:
++                return EROFS;
++        case SMB2_STATUS_NO_MEDIA_IN_DEVICE:
++                return ENOMEDIUM;
++        case SMB2_STATUS_DATA_ERROR:
++        case SMB2_STATUS_CRC_ERROR:
++        case SMB2_STATUS_DEVICE_DATA_ERROR:
++                return EIO;
++        case SMB2_STATUS_DISK_FULL:
++                return ENOSPC;
+         default:
+                 return EIO;
+         }
+diff --git a/lib/init.c b/lib/init.c
+index 3720a1c..6c95cd2 100644
+--- a/lib/init.c
++++ b/lib/init.c
+@@ -412,6 +412,10 @@ void smb2_set_password(struct smb2_context *smb2, const char *password)
+ {
+         if (smb2->password) {
+                 free(discard_const(smb2->password));
++                smb2->password = NULL;
++        }
++        if (password == NULL) {
++                return;
+         }
+         smb2->password = strdup(password);
+ }
+-- 
+2.20.1
+
index 81937b9..62c000a 100644 (file)
@@ -18,6 +18,7 @@ $(TARBALLS)/libsmb2-$(SMB2_VERSION).tar.gz:
 
 smb2: libsmb2-$(SMB2_VERSION).tar.gz .sum-smb2
        $(UNPACK)
+       $(APPLY) $(SRC)/smb2/0001-master-backport.patch
        $(MOVE)
 
 .smb2: smb2