]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Split process_smb() into process_smb1() and process_smb2()
authorDavid Mulder <dmulder@suse.com>
Thu, 10 Mar 2022 20:09:06 +0000 (13:09 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 7 Apr 2022 17:37:29 +0000 (17:37 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/process.c

index 54b3bb88e010b2159f49dd47ca1fa7a658e02d91..0a89788c0d109e3bbe0aba9731123ff4d716d2e0 100644 (file)
@@ -1943,6 +1943,59 @@ 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)
+{
+       struct smbd_server_connection *sconn = xconn->client->sconn;
+
+       /* Make sure this is an SMB packet. smb_size contains NetBIOS header
+        * so subtract 4 from it. */
+       if ((nread < (smb_size - 4)) || !valid_smb_header(inbuf)) {
+               DEBUG(2,("Non-SMB packet of length %d. Terminating server\n",
+                        smb_len(inbuf)));
+
+               /* special magic for immediate exit */
+               if ((nread == 9) &&
+                   (IVAL(inbuf, 4) == SMB_SUICIDE_PACKET) &&
+                   lp_parm_bool(-1, "smbd", "suicide mode", false)) {
+                       uint8_t exitcode = CVAL(inbuf, 8);
+                       DBG_WARNING("SUICIDE: Exiting immediately with code %d\n",
+                                   (int)exitcode);
+                       exit(exitcode);
+               }
+
+               exit_server_cleanly("Non-SMB packet");
+       }
+
+       show_msg((char *)inbuf);
+
+       if ((unread_bytes == 0) && smb1_is_chain(inbuf)) {
+               construct_reply_chain(xconn, (char *)inbuf, nread,
+                                     seqnum, encrypted, deferred_pcd);
+       } else {
+               construct_reply(xconn, (char *)inbuf, nread, unread_bytes,
+                               seqnum, encrypted, deferred_pcd);
+       }
+
+       sconn->trans_num++;
+}
+
 static void process_smb(struct smbXsrv_connection *xconn,
                        uint8_t *inbuf, size_t nread, size_t unread_bytes,
                        uint32_t seqnum, bool encrypted,
@@ -1966,21 +2019,16 @@ static void process_smb(struct smbXsrv_connection *xconn,
                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)) {
-                       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");
-                       }
+#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) {
@@ -1989,37 +2037,9 @@ static void process_smb(struct smbXsrv_connection *xconn,
                        sconn->using_smb2 = false;
                }
        }
-
-       /* Make sure this is an SMB packet. smb_size contains NetBIOS header
-        * so subtract 4 from it. */
-       if ((nread < (smb_size - 4)) || !valid_smb_header(inbuf)) {
-               DEBUG(2,("Non-SMB packet of length %d. Terminating server\n",
-                        smb_len(inbuf)));
-
-               /* special magic for immediate exit */
-               if ((nread == 9) &&
-                   (IVAL(inbuf, 4) == SMB_SUICIDE_PACKET) &&
-                   lp_parm_bool(-1, "smbd", "suicide mode", false)) {
-                       uint8_t exitcode = CVAL(inbuf, 8);
-                       DBG_WARNING("SUICIDE: Exiting immediately with code %d\n",
-                                   (int)exitcode);
-                       exit(exitcode);
-               }
-
-               exit_server_cleanly("Non-SMB packet");
-       }
-
-       show_msg((char *)inbuf);
-
-       if ((unread_bytes == 0) && smb1_is_chain(inbuf)) {
-               construct_reply_chain(xconn, (char *)inbuf, nread,
-                                     seqnum, encrypted, deferred_pcd);
-       } else {
-               construct_reply(xconn, (char *)inbuf, nread, unread_bytes,
-                               seqnum, encrypted, deferred_pcd);
-       }
-
-       sconn->trans_num++;
+       process_smb1(xconn, inbuf, nread, unread_bytes, seqnum, encrypted,
+                    deferred_pcd);
+#endif
 
 done:
        sconn->num_requests++;