dcesrv_reply: just drop responses if the connection is already terminating
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Nov 2023 13:42:35 +0000 (14:42 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 9 Jan 2024 11:26:55 +0000 (11:26 +0000)
There's no reason to waste resources...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Tue Jan  9 11:26:55 UTC 2024 on atb-devel-224

librpc/rpc/dcesrv_reply.c

index 94a616c7f592285ef2e54deac2a5ef13d863a41d..6d6051681766bad1202d56fd804f9e86e78c2c44 100644 (file)
@@ -92,6 +92,16 @@ NTSTATUS dcesrv_fault_with_flags(struct dcesrv_call_state *call,
        struct data_blob_list_item *rep;
        NTSTATUS status;
 
+       if (call->conn->terminate != NULL) {
+               /*
+                * If we're already disconnecting
+                * we should just drop a possible
+                * response
+                */
+               talloc_free(call);
+               return NT_STATUS_OK;
+       }
+
        /* setup a fault */
        dcesrv_init_hdr(&pkt, lpcfg_rpc_big_endian(call->conn->dce_ctx->lp_ctx));
        pkt.auth_length = 0;
@@ -149,12 +159,27 @@ _PUBLIC_ NTSTATUS dcesrv_reply(struct dcesrv_call_state *call)
        struct dcesrv_auth *auth = call->auth_state;
        size_t sig_size = 0;
 
-       /* call the reply function */
+       /*
+        * call the reply function,
+        * it's mostly for debug messages
+        * and dcesrv_fault() also checks for
+        * (call->conn->terminate != NULL) internally.
+        */
        status = context->iface->reply(call, call, call->r);
        if (!NT_STATUS_IS_OK(status)) {
                return dcesrv_fault(call, call->fault_code);
        }
 
+       if (call->conn->terminate != NULL) {
+               /*
+                * If we're already disconnecting
+                * we should just drop a possible
+                * response
+                */
+               talloc_free(call);
+               return NT_STATUS_OK;
+       }
+
        /* form the reply NDR */
        push = ndr_push_init_ctx(call);
        NT_STATUS_HAVE_NO_MEMORY(push);