Split out creation of oplock/lease break payload from smbd_smb2_send_break()
authorSachin Prabhu <sprabhu@redhat.com>
Fri, 23 Mar 2018 14:00:51 +0000 (14:00 +0000)
committerStefan Metzmacher <metze@samba.org>
Tue, 28 Jan 2020 12:26:51 +0000 (13:26 +0100)
Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
source3/smbd/smb2_server.c

index fa607f217f027b56a5c17d95a91b27df5a6876a2..5b79a379a135988b7bcfc01ef80e9a97547d3f4d 100644 (file)
@@ -3547,38 +3547,30 @@ struct smbd_smb2_send_break_state {
        uint8_t body[1];
 };
 
-static NTSTATUS smbd_smb2_send_break(struct smbXsrv_connection *xconn,
-                                    struct smbXsrv_session *session,
-                                    struct smbXsrv_tcon *tcon,
-                                    const uint8_t *body,
-                                    size_t body_len)
+static NTSTATUS smbd_smb2_build_break_state_payload
+                               (struct smbXsrv_connection *xconn,
+                                struct smbXsrv_session *session,
+                                struct smbXsrv_tcon *tcon,
+                                const uint8_t *body, size_t body_len,
+                                struct smbd_smb2_send_break_state *state)
 {
-       struct smbd_smb2_send_break_state *state;
        bool do_encryption = false;
        uint64_t session_wire_id = 0;
        uint64_t nonce_high = 0;
        uint64_t nonce_low = 0;
        NTSTATUS status;
-       size_t statelen;
        bool ok;
 
        if (session != NULL) {
                session_wire_id = session->global->session_wire_id;
-               do_encryption = session->global->encryption_flags & SMBXSRV_ENCRYPTION_DESIRED;
-               if (tcon->global->encryption_flags & SMBXSRV_ENCRYPTION_DESIRED) {
+               do_encryption = session->global->encryption_flags &
+                                               SMBXSRV_ENCRYPTION_DESIRED;
+               if (tcon->global->encryption_flags &
+                               SMBXSRV_ENCRYPTION_DESIRED) {
                        do_encryption = true;
                }
        }
 
-       statelen = offsetof(struct smbd_smb2_send_break_state, body) +
-               body_len;
-
-       state = talloc_zero_size(xconn, statelen);
-       if (state == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       talloc_set_name_const(state, "struct smbd_smb2_send_break_state");
-
        if (do_encryption) {
                status = smb2_get_new_nonce(session,
                                            &nonce_high,
@@ -3659,6 +3651,34 @@ static NTSTATUS smbd_smb2_send_break(struct smbXsrv_connection *xconn,
                }
        }
 
+       return NT_STATUS_OK;
+}
+
+static NTSTATUS smbd_smb2_send_break(struct smbXsrv_connection *xconn,
+                                    struct smbXsrv_session *session,
+                                    struct smbXsrv_tcon *tcon,
+                                    const uint8_t *body,
+                                    size_t body_len)
+{
+       struct smbXsrv_client *client = xconn->client;
+       struct smbd_smb2_send_break_state *state;
+       NTSTATUS status;
+       size_t statelen;
+
+       statelen = offsetof(struct smbd_smb2_send_break_state, body)
+                                                               + body_len;
+       state = talloc_zero_size(client, statelen);
+       if (state == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       talloc_set_name_const(state, "struct smbd_smb2_send_break_state");
+
+       status = smbd_smb2_build_break_state_payload(xconn, session, tcon,
+                                                   body, body_len, state);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
        state->queue_entry.mem_ctx = state;
        state->queue_entry.vector = state->vector;
        state->queue_entry.count = ARRAY_SIZE(state->vector);