smbd: Split srv_send_smb into smb1_srv_send/smb2_srv_send
authorDavid Mulder <dmulder@suse.com>
Fri, 18 Mar 2022 14:13:43 +0000 (08:13 -0600)
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
source3/smbd/proto.h

index 0a89788c0d109e3bbe0aba9731123ff4d716d2e0..b56fb4fa6599a67c8d9514d7bf0014dfa626e0c7 100644 (file)
@@ -212,10 +212,10 @@ void smbd_unlock_socket(struct smbXsrv_connection *xconn)
  Send an smb to a fd.
 ****************************************************************************/
 
-bool srv_send_smb(struct smbXsrv_connection *xconn, char *buffer,
-                 bool do_signing, uint32_t seqnum,
-                 bool do_encrypt,
-                 struct smb_perfcount_data *pcd)
+bool smb1_srv_send(struct smbXsrv_connection *xconn, char *buffer,
+                  bool do_signing, uint32_t seqnum,
+                  bool do_encrypt,
+                  struct smb_perfcount_data *pcd)
 {
        size_t len = 0;
        ssize_t ret;
@@ -281,6 +281,65 @@ out:
        return (ret > 0);
 }
 
+#if !defined(WITH_SMB1SERVER)
+static bool smb2_srv_send(struct smbXsrv_connection *xconn, char *buffer,
+                         bool do_signing, uint32_t seqnum,
+                         bool do_encrypt,
+                         struct smb_perfcount_data *pcd)
+{
+       size_t len = 0;
+       ssize_t ret;
+       char *buf_out = buffer;
+
+       if (!NT_STATUS_IS_OK(xconn->transport.status)) {
+               /*
+                * we're not supposed to do any io
+                */
+               return true;
+       }
+
+       len = smb_len_large(buf_out) + 4;
+
+       ret = write_data(xconn->transport.sock, buf_out, len);
+       if (ret <= 0) {
+               int saved_errno = errno;
+               /*
+                * Try and give an error message saying what
+                * client failed.
+                */
+               DEBUG(1,("pid[%d] Error writing %d bytes to client %s. %d. (%s)\n",
+                        (int)getpid(), (int)len,
+                        smbXsrv_connection_dbg(xconn),
+                        (int)ret, strerror(saved_errno)));
+               errno = saved_errno;
+
+               srv_free_enc_buffer(xconn, buf_out);
+               goto out;
+       }
+
+       SMB_PERFCOUNT_SET_MSGLEN_OUT(pcd, len);
+       srv_free_enc_buffer(xconn, buf_out);
+out:
+       SMB_PERFCOUNT_END(pcd);
+
+       return (ret > 0);
+}
+#endif
+
+bool srv_send_smb(struct smbXsrv_connection *xconn, char *buffer,
+                 bool do_signing, uint32_t seqnum,
+                 bool do_encrypt,
+                 struct smb_perfcount_data *pcd)
+{
+#if !defined(WITH_SMB1SERVER)
+       return smb2_srv_send(xconn, buffer, do_signing, seqnum,
+                            do_encrypt, pcd);
+#else
+       return smb1_srv_send(xconn, buffer, do_signing, seqnum,
+                            do_encrypt, pcd);
+#endif
+}
+
 /*******************************************************************
  Setup the word count and byte count for a smb message.
 ********************************************************************/
index 9405f7baa5558b623ef47b1e8882863fc7549c0f..109c5596f38c20e6f07ba635d69c0b29adf1c57a 100644 (file)
@@ -852,6 +852,10 @@ bool srv_send_smb(struct smbXsrv_connection *xconn, char *buffer,
                  bool no_signing, uint32_t seqnum,
                  bool do_encrypt,
                  struct smb_perfcount_data *pcd);
+bool smb1_srv_send(struct smbXsrv_connection *xconn, char *buffer,
+                  bool do_signing, uint32_t seqnum,
+                  bool do_encrypt,
+                  struct smb_perfcount_data *pcd);
 size_t srv_set_message(char *buf,
                       size_t num_words,
                       size_t num_bytes,