]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Move process_smb to smb2_process.c
authorDavid Mulder <dmulder@suse.com>
Fri, 18 Mar 2022 20:53:19 +0000 (14:53 -0600)
committerJeremy Allison <jra@samba.org>
Thu, 7 Apr 2022 17:37:30 +0000 (17:37 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/process.c
source3/smbd/proto.h
source3/smbd/smb2_process.c

index 9ed957a6e2e62bde3bc801559009d5e4d4a0ecbf..3d48f49b649e6087a26e3eaae0a076f44e83a8d6 100644 (file)
@@ -277,7 +277,7 @@ out:
        return (ret > 0);
 }
 
-static bool valid_smb_header(const uint8_t *inbuf)
+bool valid_smb_header(const uint8_t *inbuf)
 {
        if (is_encrypted_packet(inbuf)) {
                return true;
@@ -1626,23 +1626,10 @@ error:
  Process an smb from the client
 ****************************************************************************/
 
-static void process_smb2(struct smbXsrv_connection *xconn,
-                        uint8_t *inbuf, size_t nread, size_t unread_bytes,
-                        uint32_t seqnum, bool encrypted,
-                        struct smb_perfcount_data *deferred_pcd)
-{
-       const uint8_t *inpdu = inbuf + NBT_HDR_SIZE;
-       size_t pdulen = nread - NBT_HDR_SIZE;
-       NTSTATUS status = smbd_smb2_process_negprot(xconn, 0, inpdu, pdulen);
-       if (!NT_STATUS_IS_OK(status)) {
-               exit_server_cleanly("SMB2 negprot fail");
-       }
-}
-
-static void process_smb1(struct smbXsrv_connection *xconn,
-                        uint8_t *inbuf, size_t nread, size_t unread_bytes,
-                        uint32_t seqnum, bool encrypted,
-                        struct smb_perfcount_data *deferred_pcd)
+void process_smb1(struct smbXsrv_connection *xconn,
+                 uint8_t *inbuf, size_t nread, size_t unread_bytes,
+                 uint32_t seqnum, bool encrypted,
+                 struct smb_perfcount_data *deferred_pcd)
 {
        struct smbd_server_connection *sconn = xconn->client->sconn;
 
@@ -1678,68 +1665,6 @@ static void process_smb1(struct smbXsrv_connection *xconn,
        sconn->trans_num++;
 }
 
-void process_smb(struct smbXsrv_connection *xconn,
-                uint8_t *inbuf, size_t nread, size_t unread_bytes,
-                uint32_t seqnum, bool encrypted,
-                struct smb_perfcount_data *deferred_pcd)
-{
-       struct smbd_server_connection *sconn = xconn->client->sconn;
-       int msg_type = CVAL(inbuf,0);
-
-       DO_PROFILE_INC(request);
-
-       DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type,
-                   smb_len(inbuf) ) );
-       DEBUG(3, ("Transaction %d of length %d (%u toread)\n",
-                 sconn->trans_num, (int)nread, (unsigned int)unread_bytes));
-
-       if (msg_type != NBSSmessage) {
-               /*
-                * NetBIOS session request, keepalive, etc.
-                */
-               reply_special(xconn, (char *)inbuf, nread);
-               goto done;
-       }
-
-#if defined(WITH_SMB1SERVER)
-       if (sconn->using_smb2) {
-               /* At this point we're not really using smb2,
-                * we make the decision here.. */
-               if (smbd_is_smb2_header(inbuf, nread)) {
-#endif
-                       process_smb2(xconn, inbuf, nread, unread_bytes, seqnum,
-                                    encrypted, deferred_pcd);
-                       return;
-#if defined(WITH_SMB1SERVER)
-               }
-               if (nread >= smb_size && valid_smb_header(inbuf)
-                               && CVAL(inbuf, smb_com) != 0x72) {
-                       /* This is a non-negprot SMB1 packet.
-                          Disable SMB2 from now on. */
-                       sconn->using_smb2 = false;
-               }
-       }
-       process_smb1(xconn, inbuf, nread, unread_bytes, seqnum, encrypted,
-                    deferred_pcd);
-#endif
-
-done:
-       sconn->num_requests++;
-
-       /* The timeout_processing function isn't run nearly
-          often enough to implement 'max log size' without
-          overrunning the size of the file by many megabytes.
-          This is especially true if we are running at debug
-          level 10.  Checking every 50 SMBs is a nice
-          tradeoff of performance vs log file size overrun. */
-
-       if ((sconn->num_requests % 50) == 0 &&
-           need_to_check_log_size()) {
-               change_to_root_user();
-               check_log_size();
-       }
-}
-
 /****************************************************************************
  Return a string containing the function name of a SMB command.
 ****************************************************************************/
index b379dab00cd13fd91f100cfd55c0a3189e3d1fa1..910d33f2a92c40b7cfd0974f16cd5d09048ee242 100644 (file)
@@ -883,14 +883,15 @@ NTSTATUS smb1_receive_talloc(TALLOC_CTX *mem_ctx,
                             size_t *p_len,
                             uint32_t *seqnum,
                             bool trusted_channel);
-void process_smb(struct smbXsrv_connection *xconn,
-                uint8_t *inbuf, size_t nread, size_t unread_bytes,
-                uint32_t seqnum, bool encrypted,
-                struct smb_perfcount_data *deferred_pcd);
 bool push_deferred_open_message_smb1(struct smb_request *req,
                                     struct timeval timeout,
                                     struct file_id id,
                                     struct deferred_open_record *open_rec);
+void process_smb1(struct smbXsrv_connection *xconn,
+                 uint8_t *inbuf, size_t nread, size_t unread_bytes,
+                 uint32_t seqnum, bool encrypted,
+                 struct smb_perfcount_data *deferred_pcd);
+bool valid_smb_header(const uint8_t *inbuf);
 
 /* The following definitions come from smbd/smb2_process.c  */
 
@@ -929,6 +930,10 @@ bool create_outbuf(TALLOC_CTX *mem_ctx, struct smb_request *req,
                    uint8_t num_words, uint32_t num_bytes);
 void construct_reply_common_req(struct smb_request *req, char *outbuf);
 void reply_outbuf(struct smb_request *req, uint8_t num_words, uint32_t num_bytes);
+void process_smb(struct smbXsrv_connection *xconn,
+                uint8_t *inbuf, size_t nread, size_t unread_bytes,
+                uint32_t seqnum, bool encrypted,
+                struct smb_perfcount_data *deferred_pcd);
 
 /* The following definitions come from smbd/quotas.c  */
 
index 7f1bac6fc81e44fcfeff656f914b7ca6735318ee..38d90e8f1b6198b3c8408daabf46143fc8c80233 100644 (file)
@@ -570,3 +570,82 @@ void reply_outbuf(struct smb_request *req, uint8_t num_words, uint32_t num_bytes
        }
        req->outbuf = (uint8_t *)outbuf;
 }
+
+/****************************************************************************
+ Process an smb from the client
+****************************************************************************/
+
+static void process_smb2(struct smbXsrv_connection *xconn,
+                        uint8_t *inbuf, size_t nread, size_t unread_bytes,
+                        uint32_t seqnum, bool encrypted,
+                        struct smb_perfcount_data *deferred_pcd)
+{
+       const uint8_t *inpdu = inbuf + NBT_HDR_SIZE;
+       size_t pdulen = nread - NBT_HDR_SIZE;
+       NTSTATUS status = smbd_smb2_process_negprot(xconn, 0, inpdu, pdulen);
+       if (!NT_STATUS_IS_OK(status)) {
+               exit_server_cleanly("SMB2 negprot fail");
+       }
+}
+
+void process_smb(struct smbXsrv_connection *xconn,
+                uint8_t *inbuf, size_t nread, size_t unread_bytes,
+                uint32_t seqnum, bool encrypted,
+                struct smb_perfcount_data *deferred_pcd)
+{
+       struct smbd_server_connection *sconn = xconn->client->sconn;
+       int msg_type = CVAL(inbuf,0);
+
+       DO_PROFILE_INC(request);
+
+       DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type,
+                   smb_len(inbuf) ) );
+       DEBUG(3, ("Transaction %d of length %d (%u toread)\n",
+                 sconn->trans_num, (int)nread, (unsigned int)unread_bytes));
+
+       if (msg_type != NBSSmessage) {
+               /*
+                * NetBIOS session request, keepalive, etc.
+                */
+               reply_special(xconn, (char *)inbuf, nread);
+               goto done;
+       }
+
+#if defined(WITH_SMB1SERVER)
+       if (sconn->using_smb2) {
+               /* At this point we're not really using smb2,
+                * we make the decision here.. */
+               if (smbd_is_smb2_header(inbuf, nread)) {
+#endif
+                       process_smb2(xconn, inbuf, nread, unread_bytes, seqnum,
+                                    encrypted, deferred_pcd);
+                       return;
+#if defined(WITH_SMB1SERVER)
+               }
+               if (nread >= smb_size && valid_smb_header(inbuf)
+                               && CVAL(inbuf, smb_com) != 0x72) {
+                       /* This is a non-negprot SMB1 packet.
+                          Disable SMB2 from now on. */
+                       sconn->using_smb2 = false;
+               }
+       }
+       process_smb1(xconn, inbuf, nread, unread_bytes, seqnum, encrypted,
+                    deferred_pcd);
+#endif
+
+done:
+       sconn->num_requests++;
+
+       /* The timeout_processing function isn't run nearly
+          often enough to implement 'max log size' without
+          overrunning the size of the file by many megabytes.
+          This is especially true if we are running at debug
+          level 10.  Checking every 50 SMBs is a nice
+          tradeoff of performance vs log file size overrun. */
+
+       if ((sconn->num_requests % 50) == 0 &&
+           need_to_check_log_size()) {
+               change_to_root_user();
+               check_log_size();
+       }
+}