Browse Source

Replace TRANS2_CREATE_DIRECTORY directory make with Core Protocol command for better compatibility

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Sylver Bruneau 9 years ago
parent
commit
1f769b240b
2 changed files with 39 additions and 54 deletions
  1. 28 41
      src/smb_dir.c
  2. 11 13
      src/smb_packets.h

+ 28 - 41
src/smb_dir.c

@@ -94,12 +94,11 @@ uint32_t  smb_directory_rm(smb_session *s, smb_tid tid, const char *path)
 
 uint32_t  smb_directory_create(smb_session *s, smb_tid tid, const char *path)
 {
-    smb_message              *req_msg, resp_msg;
-    smb_trans2_req           tr2;
-    smb_tr2_create_directory create_dir;
-    size_t                   utf_path_len, msg_len;
-    char                     *utf_path;
-    int                      padding = 0;
+    smb_message           *req_msg, resp_msg;
+    smb_directory_mk_req  req;
+    smb_directory_mk_resp *resp;
+    size_t                utf_pattern_len;
+    char                  *utf_pattern;
 
     if (s == NULL)
         return DSM_ERROR_INVALID_SESSION;
@@ -108,52 +107,40 @@ uint32_t  smb_directory_create(smb_session *s, smb_tid tid, const char *path)
     if (path == NULL)
         return DSM_ERROR_INVALID_PATH;
 
-    utf_path_len = smb_to_utf16(path, strlen(path) + 1, &utf_path);
-    if (utf_path_len == 0)
+    utf_pattern_len = smb_to_utf16(path, strlen(path) + 1, &utf_pattern);
+    if (utf_pattern_len == 0)
         return DSM_ERROR_UTF16_CONV_FAILED;
 
-    msg_len   = sizeof(smb_trans2_req) + sizeof(smb_tr2_query);
-    msg_len  += utf_path_len;
-    if (msg_len %4)
-        padding = 4 - msg_len % 4;
-
-    req_msg = smb_message_new(SMB_CMD_TRANS2);
-    if (!req_msg) {
-        free(utf_path);
+    req_msg = smb_message_new(SMB_CMD_MKDIR);
+    if (!req_msg)
+    {
+        free(utf_pattern);
         return DSM_ERROR_INTERNAL;
     }
+
     req_msg->packet->header.tid = (uint16_t)tid;
 
-    SMB_MSG_INIT_PKT(tr2);
-    tr2.wct                = 15;
-    tr2.total_param_count  = (uint16_t)(utf_path_len + sizeof(smb_tr2_create_directory));
-    tr2.param_count        = tr2.total_param_count;
-    tr2.max_param_count    = 2; // ?? Why not the same or 12 ?
-    tr2.max_data_count     = 0xffff;
-    tr2.param_offset       = 68; // Offset of find_first_params in packet;
-    tr2.data_count         = 0;
-    tr2.data_offset        = 96; // Offset of pattern in packet
-    tr2.setup_count        = 1;
-    tr2.cmd                = SMB_TR2_CREATE_DIRECTORY;
-    tr2.bct                = (uint16_t)(sizeof(smb_tr2_create_directory) + utf_path_len + padding);
-    SMB_MSG_PUT_PKT(req_msg, tr2);
-
-    SMB_MSG_INIT_PKT(create_dir);
-    create_dir.reserved = 0x00000000; // Must be 0
-    SMB_MSG_PUT_PKT(req_msg, create_dir);
-
-    smb_message_append(req_msg, utf_path, utf_path_len);
-    free(utf_path);
-
-    // Adds padding at the end if necessary.
-    while (padding--)
-        smb_message_put8(req_msg, 0);
+    SMB_MSG_INIT_PKT(req);
+    req.wct              = 0x00; // Must be 0
+    req.bct              = (uint16_t)(utf_pattern_len + 1);
+    req.buffer_format    = 0x04; // Must be 4
+    SMB_MSG_PUT_PKT(req_msg, req);
+    smb_message_append(req_msg, utf_pattern, utf_pattern_len);
 
     smb_session_send_msg(s, req_msg);
     smb_message_destroy(req_msg);
 
+    free(utf_pattern);
+
     if (!smb_session_recv_msg(s, &resp_msg))
         return DSM_ERROR_INVALID_RCV_MESS;
 
-    return resp_msg.packet->header.status;
+    if (resp_msg.packet->header.status != NT_STATUS_SUCCESS)
+        return resp_msg.packet->header.status;
+
+    resp = (smb_directory_mk_resp *)resp_msg.packet->payload;
+    if ((resp->wct != 0) || (resp->bct != 0))
+        return DSM_ERROR_INVALID_RCV_MESS;
+    
+    return NT_STATUS_SUCCESS;
 }

+ 11 - 13
src/smb_packets.h

@@ -356,6 +356,17 @@ typedef struct
 //<- Move File
 typedef smb_simple_struct smb_file_mv_resp;
 
+//-> Create Directory
+typedef struct
+{
+    uint8_t         wct;                // 0x00
+    uint16_t        bct;                // >= 2
+    uint8_t         buffer_format;      // 0x04
+} __attribute__((packed))   smb_directory_mk_req;
+
+//<- Create Directory
+typedef smb_simple_struct smb_directory_mk_resp;
+
 //-> Trans
 typedef struct
 {
@@ -440,13 +451,6 @@ typedef struct
     uint8_t       path[];
 } __attribute__((packed))   smb_tr2_query;
 
-//// -> Trans2|CreateDirectory
-typedef struct
-{
-    uint32_t      reserved;   // 0x00000000
-    uint8_t       path[];
-} __attribute__((packed))   smb_tr2_create_directory;
-
 //<- Trans2
 
 typedef struct
@@ -529,12 +533,6 @@ typedef struct
     uint8_t       name[];
 } __attribute__((packed))   smb_tr2_path_info;
 
-//// <- Trans2|CreateDirectory
-typedef struct
-{
-    uint16_t      ea_error_offset;
-} __attribute__((packed))   smb_tr2_create_directory_params;
-
 //-> Example
 typedef struct
 {