librpc: Make "dcesrv_context->callbacks" a pointer
authorVolker Lendecke <vl@samba.org>
Tue, 2 Feb 2021 14:07:35 +0000 (15:07 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 16 Mar 2021 17:09:32 +0000 (17:09 +0000)
This structure just grew from 3 to 6 pointers, avoid making a copy of
this. All callers of dcesrv_init_context() have this as a static
struct in the C object, so a pointer to that won't change.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
librpc/rpc/dcesrv_auth.c
librpc/rpc/dcesrv_core.c
librpc/rpc/dcesrv_core.h
source3/rpc_server/rpc_ncacn_np.c
source3/winbindd/winbindd_dual_ndr.c
testsuite/unittests/test_sambafs_srv_pipe.c

index 1f09bf0d18e17df89a166d3790920612c92e606a..6bbac4e016082879f519e4390d76e79493fe8f7f 100644 (file)
@@ -79,7 +79,7 @@ static bool dcesrv_auth_prepare_gensec(struct dcesrv_call_state *call)
 {
        struct dcesrv_connection *dce_conn = call->conn;
        struct dcesrv_auth *auth = call->auth_state;
-       struct dcesrv_context_callbacks *cb = &call->conn->dce_ctx->callbacks;
+       struct dcesrv_context_callbacks *cb = call->conn->dce_ctx->callbacks;
        NTSTATUS status;
 
        if (auth->auth_started) {
@@ -249,7 +249,7 @@ void dcesrv_default_auth_state_prepare_request(struct dcesrv_call_state *call)
 {
        struct dcesrv_connection *dce_conn = call->conn;
        struct dcesrv_auth *auth = call->auth_state;
-       struct dcesrv_context_callbacks *cb = &call->conn->dce_ctx->callbacks;
+       struct dcesrv_context_callbacks *cb = call->conn->dce_ctx->callbacks;
 
        if (auth->auth_audited) {
                return;
@@ -287,7 +287,7 @@ bool dcesrv_auth_bind(struct dcesrv_call_state *call)
 {
        struct ncacn_packet *pkt = &call->pkt;
        struct dcesrv_auth *auth = call->auth_state;
-       struct dcesrv_context_callbacks *cb = &call->conn->dce_ctx->callbacks;
+       struct dcesrv_context_callbacks *cb = call->conn->dce_ctx->callbacks;
        NTSTATUS status;
 
        if (pkt->auth_length == 0) {
index a5bfac507f54b4bf47cbe799902197371184a4cc..70e0245532ed5907616543f25262404d2a65e564 100644 (file)
@@ -952,8 +952,8 @@ static NTSTATUS dcesrv_bind(struct dcesrv_call_state *call)
        conn->max_recv_frag = max_rep;
        conn->max_xmit_frag = max_rep;
 
-       status = dce_ctx->callbacks.assoc_group.find(
-               call, dce_ctx->callbacks.assoc_group.private_data);
+       status = dce_ctx->callbacks->assoc_group.find(
+               call, dce_ctx->callbacks->assoc_group.private_data);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_NOTICE("Failed to find assoc_group 0x%08x: %s\n",
                           call->pkt.u.bind.assoc_group_id, nt_errstr(status));
@@ -2311,6 +2311,10 @@ _PUBLIC_ NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx,
 {
        struct dcesrv_context *dce_ctx;
 
+       if (cb == NULL) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
        dce_ctx = talloc_zero(mem_ctx, struct dcesrv_context);
        NT_STATUS_HAVE_NO_MEMORY(dce_ctx);
 
@@ -2330,9 +2334,7 @@ _PUBLIC_ NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
        dce_ctx->broken_connections = NULL;
-       if (cb != NULL) {
-               dce_ctx->callbacks = *cb;
-       }
+       dce_ctx->callbacks = cb;
 
        *_dce_ctx = dce_ctx;
        return NT_STATUS_OK;
index d566aa532172155318b12274c311d47737f717fe..d8d5f9030959973fe35c8aa50847f8aaab24d7eb 100644 (file)
@@ -440,7 +440,7 @@ struct dcesrv_context {
 
        struct dcesrv_connection *broken_connections;
 
-       struct dcesrv_context_callbacks callbacks;
+       struct dcesrv_context_callbacks *callbacks;
 };
 
 /* this structure is used by modules to determine the size of some critical types */
index 30f2d88d4bf84ac44ad26649c4a1aa54801337ad..598efd1f33976c5ce03fd0e4fdd1fa8c47fe8804 100644 (file)
@@ -488,9 +488,9 @@ static struct tevent_req *rpcint_bh_raw_call_send(TALLOC_CTX *mem_ctx,
        if (hs->conn->assoc_group == NULL) {
                ZERO_STRUCT(state->call->pkt);
                state->call->pkt.u.bind.assoc_group_id = 0;
-               status = dce_ctx->callbacks.assoc_group.find(
+               status = dce_ctx->callbacks->assoc_group.find(
                        state->call,
-                       dce_ctx->callbacks.assoc_group.private_data);
+                       dce_ctx->callbacks->assoc_group.private_data);
                if (tevent_req_nterror(req, status)) {
                        return tevent_req_post(req, ev);
                }
index 39c3a146c037e15917b92485935ca7189dfbdfe7..5f0ec82067c0b3a931d10fc24d970018aa752b5f 100644 (file)
@@ -524,7 +524,7 @@ enum winbindd_result winbindd_dual_ndrcmd(struct winbindd_domain *domain,
        ZERO_STRUCT(dcesrv_call->pkt);
        dcesrv_call->pkt.u.bind.assoc_group_id = 0;
 
-       cb = &dcesrv_call->conn->dce_ctx->callbacks;
+       cb = dcesrv_call->conn->dce_ctx->callbacks;
        status = cb->assoc_group.find(
                dcesrv_call, cb->assoc_group.private_data);
        if (!NT_STATUS_IS_OK(status)) {
index 40798b588c7f8f7322771c26b9a560e1c2c30b1f..75797c9bcee318e1102b71580c9d890e575644c8 100644 (file)
@@ -21,6 +21,10 @@ struct test_state {
        struct dcesrv_context *dce_ctx;
 };
 
+static struct dcesrv_context_callbacks srv_callbacks = {
+       .log.successful_authz = NULL,
+};
+
 static int setup_samr(void **state)
 {
        TALLOC_CTX *mem_ctx;
@@ -42,7 +46,7 @@ static int setup_samr(void **state)
        status = dcerpc_register_ep_server(ep_server);
        assert_true(NT_STATUS_IS_OK(status));
 
-       status = dcesrv_init_context(s, NULL, NULL, &s->dce_ctx);
+       status = dcesrv_init_context(s, NULL, &srv_callbacks, &s->dce_ctx);
        assert_true(NT_STATUS_IS_OK(status));
 
        status = dcesrv_init_ep_server(s->dce_ctx, "samr");