s3:rpc_server: Set dcerpc_ncacn_connection destructor
authorSamuel Cabrero <scabrero@suse.de>
Tue, 5 Feb 2019 12:34:39 +0000 (13:34 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Jul 2019 16:49:14 +0000 (16:49 +0000)
And call disconnection callback from there if it is set.
Additionally change named_pipe_termination_fn to have * in typedef.

Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h

index 747562e3a3b44fcdfb828887cfcc962e47e84fae..84d48352be88e6abd998c28c7a489157d890f7d6 100644 (file)
@@ -264,7 +264,7 @@ struct named_pipe_client *named_pipe_client_init(TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev_ctx,
                                                 struct messaging_context *msg_ctx,
                                                 const char *pipe_name,
-                                                named_pipe_termination_fn *term_fn,
+                                                named_pipe_termination_fn term_fn,
                                                 uint16_t file_type,
                                                 uint16_t device_state,
                                                 uint64_t allocation_size,
@@ -303,7 +303,7 @@ static void named_pipe_accept_done(struct tevent_req *subreq);
 void named_pipe_accept_function(struct tevent_context *ev_ctx,
                                struct messaging_context *msg_ctx,
                                const char *pipe_name, int fd,
-                               named_pipe_termination_fn *term_fn,
+                               named_pipe_termination_fn term_fn,
                                void *private_data)
 {
        struct named_pipe_client *npc;
@@ -991,6 +991,17 @@ struct dcerpc_ncacn_conn {
        size_t count;
 };
 
+static int dcerpc_ncacn_conn_destructor(struct dcerpc_ncacn_conn *ncacn_conn)
+{
+       if (ncacn_conn->disconnect_fn != NULL) {
+               bool ok = ncacn_conn->disconnect_fn(ncacn_conn->p);
+               if (!ok) {
+                       DBG_WARNING("Failed to call disconnect function\n");
+               }
+       }
+       return 0;
+}
+
 static void dcerpc_ncacn_packet_process(struct tevent_req *subreq);
 static void dcerpc_ncacn_packet_done(struct tevent_req *subreq);
 
@@ -1019,6 +1030,7 @@ void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
                close(s);
                return;
        }
+       talloc_set_destructor(ncacn_conn, dcerpc_ncacn_conn_destructor);
 
        ncacn_conn->transport = transport;
        ncacn_conn->ev_ctx = ev_ctx;
@@ -1211,12 +1223,6 @@ static void dcerpc_ncacn_packet_process(struct tevent_req *subreq)
        status = dcerpc_read_ncacn_packet_recv(subreq, ncacn_conn, &pkt, &recv_buffer);
        TALLOC_FREE(subreq);
        if (!NT_STATUS_IS_OK(status)) {
-               if (ncacn_conn->disconnect_fn != NULL) {
-                       ok = ncacn_conn->disconnect_fn(ncacn_conn->p);
-                       if (!ok) {
-                               DEBUG(3, ("Failed to call disconnect function\n"));
-                       }
-               }
                goto fail;
        }
 
index ca0f61ce4e68dfb553d35f0953242d9362e68130..8c043bc4ba51bfb364716c567f4532a1b2d39f68 100644 (file)
@@ -25,7 +25,7 @@
 struct pipes_struct;
 
 typedef bool (*dcerpc_ncacn_disconnect_fn)(struct pipes_struct *p);
-typedef void (named_pipe_termination_fn)(void *private_data);
+typedef void (*named_pipe_termination_fn)(void *private_data);
 
 struct named_pipe_client {
        const char *pipe_name;
@@ -53,7 +53,7 @@ struct named_pipe_client {
        struct iovec *iov;
        size_t count;
 
-       named_pipe_termination_fn *term_fn;
+       named_pipe_termination_fn term_fn;
        void *private_data;
 };
 
@@ -61,7 +61,7 @@ struct named_pipe_client *named_pipe_client_init(TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev_ctx,
                                                 struct messaging_context *msg_ctx,
                                                 const char *pipe_name,
-                                                named_pipe_termination_fn *term_fn,
+                                                named_pipe_termination_fn term_fn,
                                                 uint16_t file_type,
                                                 uint16_t device_state,
                                                 uint64_t allocation_size,
@@ -86,7 +86,7 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(const char *pipe_name,
 void named_pipe_accept_function(struct tevent_context *ev_ctx,
                                struct messaging_context *msg_ctx,
                                const char *pipe_name, int fd,
-                               named_pipe_termination_fn *term_fn,
+                               named_pipe_termination_fn term_fn,
                                void *private_data);
 void named_pipe_packet_process(struct tevent_req *subreq);