s3-rpc_server: Added disconnect callback function.
authorAndreas Schneider <asn@samba.org>
Mon, 14 Mar 2011 11:29:49 +0000 (12:29 +0100)
committerSimo Sorce <idra@samba.org>
Wed, 23 Mar 2011 16:19:22 +0000 (17:19 +0100)
source3/rpc_server/epmd.c
source3/rpc_server/rpc_ep_setup.c
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h

index 0b5d671775bb6d577666d997666ae03cae296ebf..5b0f4c4a5240066b310aac6de987b54d92da580e 100644 (file)
@@ -263,7 +263,8 @@ void start_epmd(struct tevent_context *ev_ctx,
        ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
                                         msg_ctx,
                                         ndr_table_epmapper.syntax_id,
-                                        "EPMAPPER");
+                                        "EPMAPPER",
+                                        NULL);
        if (!ok) {
                DEBUG(0, ("Failed to open epmd ncalrpc pipe!\n"));
                exit(1);
index 9baee276b2dab703c14689c6beedc991c2e7765a..4f23ae2891f8cba4d754e34334f1ca16e75386cd 100644 (file)
@@ -451,7 +451,8 @@ static bool winreg_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -520,7 +521,8 @@ static bool srvsvc_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -590,7 +592,8 @@ static bool lsarpc_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -660,7 +663,8 @@ static bool samr_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -730,7 +734,8 @@ static bool netlogon_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -1136,7 +1141,8 @@ static bool netdfs_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -1205,7 +1211,8 @@ static bool dssetup_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
@@ -1273,7 +1280,8 @@ static bool wkssvc_init_cb(void *ptr)
                ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
                                                 ep_ctx->msg_ctx,
                                                 abstract_syntax,
-                                                pipe_name);
+                                                pipe_name,
+                                                NULL);
                if (!ok) {
                        return false;
                }
index 9f88531a98329c0b071bd01d98227de5b1809742..94aa5a5453587b741141cceb23f6679a6884db82 100644 (file)
@@ -232,6 +232,7 @@ struct dcerpc_ncacn_listen_state {
 
        struct tevent_context *ev_ctx;
        struct messaging_context *msg_ctx;
+       dcerpc_ncacn_disconnect_fn disconnect_fn;
 };
 
 static void named_pipe_listener(struct tevent_context *ev,
@@ -681,7 +682,8 @@ static void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
                                uint16_t port,
                                struct tsocket_address *cli_addr,
                                struct tsocket_address *srv_addr,
-                               int s);
+                               int s,
+                               dcerpc_ncacn_disconnect_fn fn);
 
 /********************************************************************
  * Start listening on the tcp/ip socket
@@ -711,6 +713,7 @@ uint16_t setup_dcerpc_ncacn_tcpip_socket(struct tevent_context *ev_ctx,
        state->syntax_id = syntax_id;
        state->fd = -1;
        state->ep.port = port;
+       state->disconnect_fn = NULL;
 
        if (state->ep.port == 0) {
                uint16_t i;
@@ -839,7 +842,8 @@ static void dcerpc_ncacn_tcpip_listener(struct tevent_context *ev,
                            state->ep.port,
                            cli_addr,
                            srv_addr,
-                           s);
+                           s,
+                           NULL);
 }
 
 /********************************************************************
@@ -854,7 +858,8 @@ static void dcerpc_ncalrpc_listener(struct tevent_context *ev,
 bool setup_dcerpc_ncalrpc_socket(struct tevent_context *ev_ctx,
                                 struct messaging_context *msg_ctx,
                                 struct ndr_syntax_id syntax_id,
-                                const char *name)
+                                const char *name,
+                                dcerpc_ncacn_disconnect_fn fn)
 {
        struct dcerpc_ncacn_listen_state *state;
        struct tevent_fd *fde;
@@ -867,6 +872,7 @@ bool setup_dcerpc_ncalrpc_socket(struct tevent_context *ev_ctx,
 
        state->syntax_id = syntax_id;
        state->fd = -1;
+       state->disconnect_fn = fn;
 
        if (name == NULL) {
                name = "DEFAULT";
@@ -962,7 +968,8 @@ static void dcerpc_ncalrpc_listener(struct tevent_context *ev,
                            state->msg_ctx,
                            state->syntax_id, NCALRPC,
                            state->ep.name, 0,
-                           cli_addr, NULL, sd);
+                           cli_addr, NULL, sd,
+                           state->disconnect_fn);
 }
 
 struct dcerpc_ncacn_conn {
@@ -978,6 +985,7 @@ struct dcerpc_ncacn_conn {
        int sock;
 
        struct pipes_struct *p;
+       dcerpc_ncacn_disconnect_fn disconnect_fn;
 
        struct tevent_context *ev_ctx;
        struct messaging_context *msg_ctx;
@@ -1006,7 +1014,8 @@ static void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
                                uint16_t port,
                                struct tsocket_address *cli_addr,
                                struct tsocket_address *srv_addr,
-                               int s) {
+                               int s,
+                               dcerpc_ncacn_disconnect_fn fn) {
        struct dcerpc_ncacn_conn *ncacn_conn;
        struct tevent_req *subreq;
        const char *cli_str;
@@ -1032,6 +1041,7 @@ static void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
        ncacn_conn->ev_ctx = ev_ctx;
        ncacn_conn->msg_ctx = msg_ctx;
        ncacn_conn->sock = s;
+       ncacn_conn->disconnect_fn = fn;
 
        ncacn_conn->client = talloc_move(ncacn_conn, &cli_addr);
        if (tsocket_address_is_inet(ncacn_conn->client, "ip")) {
@@ -1215,6 +1225,12 @@ 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 18c790500c02f7cf1655448ee249cf7ec1246802..3791589bb6425234654accefb12bd278da3fe8d7 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef _RPC_SERVER_H_
 #define _RPC_SERVER_H_
 
+typedef bool (*dcerpc_ncacn_disconnect_fn)(struct pipes_struct *p);
+
 void set_incoming_fault(struct pipes_struct *p);
 void process_complete_pdu(struct pipes_struct *p);
 bool setup_named_pipe_socket(const char *pipe_name,
@@ -34,6 +36,7 @@ uint16_t setup_dcerpc_ncacn_tcpip_socket(struct tevent_context *ev_ctx,
 bool setup_dcerpc_ncalrpc_socket(struct tevent_context *ev_ctx,
                                 struct messaging_context *msg_ctx,
                                 struct ndr_syntax_id syntax_id,
-                                const char *name);
+                                const char *name,
+                                dcerpc_ncacn_disconnect_fn fn);
 
 #endif /* _PRC_SERVER_H_ */