s4:rpc_server: add wait_send/recv infrastructure
authorStefan Metzmacher <metze@samba.org>
Mon, 15 May 2017 06:11:29 +0000 (08:11 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 21 May 2017 19:05:12 +0000 (21:05 +0200)
This will be used to implement async BIND/ALTER_CONTEXT/AUTH3
using gensec_update_send/recv.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/rpc_server/dcerpc_server.c
source4/rpc_server/dcerpc_server.h

index a9f8854a91efc315f9ed0915a30a256ea27888ca..0a8e7e5196b7f35063c320a51e0b24ec4b43a245 100644 (file)
@@ -2160,6 +2160,10 @@ static void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn, cons
        srv_conn = talloc_get_type(dce_conn->transport.private_data,
                                   struct stream_connection);
 
+       dce_conn->wait_send = NULL;
+       dce_conn->wait_recv = NULL;
+       dce_conn->wait_private = NULL;
+
        dce_conn->allow_bind = false;
        dce_conn->allow_auth3 = false;
        dce_conn->allow_alter = false;
@@ -2513,6 +2517,8 @@ static void dcesrv_sock_accept(struct stream_connection *srv_conn)
        return;
 }
 
+static void dcesrv_conn_wait_done(struct tevent_req *subreq);
+
 static void dcesrv_read_fragment_done(struct tevent_req *subreq)
 {
        struct dcesrv_connection *dce_conn = tevent_req_callback_data(subreq,
@@ -2548,6 +2554,63 @@ static void dcesrv_read_fragment_done(struct tevent_req *subreq)
                return;
        }
 
+       /*
+        * This is used to block the connection during
+        * pending authentication.
+        */
+       if (dce_conn->wait_send != NULL) {
+               subreq = dce_conn->wait_send(dce_conn,
+                                            dce_conn->event_ctx,
+                                            dce_conn->wait_private);
+               if (!subreq) {
+                       status = NT_STATUS_NO_MEMORY;
+                       dcesrv_terminate_connection(dce_conn, nt_errstr(status));
+                       return;
+               }
+               tevent_req_set_callback(subreq, dcesrv_conn_wait_done, dce_conn);
+               return;
+       }
+
+       subreq = dcerpc_read_ncacn_packet_send(dce_conn,
+                                              dce_conn->event_ctx,
+                                              dce_conn->stream);
+       if (!subreq) {
+               status = NT_STATUS_NO_MEMORY;
+               dcesrv_terminate_connection(dce_conn, nt_errstr(status));
+               return;
+       }
+       tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dce_conn);
+}
+
+static void dcesrv_conn_wait_done(struct tevent_req *subreq)
+{
+       struct dcesrv_connection *dce_conn = tevent_req_callback_data(subreq,
+                                            struct dcesrv_connection);
+       struct dcesrv_context *dce_ctx = dce_conn->dce_ctx;
+       NTSTATUS status;
+
+       if (dce_conn->terminate) {
+               /*
+                * if the current connection is broken
+                * we need to clean it up before any other connection
+                */
+               dcesrv_terminate_connection(dce_conn, dce_conn->terminate);
+               dcesrv_cleanup_broken_connections(dce_ctx);
+               return;
+       }
+
+       dcesrv_cleanup_broken_connections(dce_ctx);
+
+       status = dce_conn->wait_recv(subreq);
+       dce_conn->wait_send = NULL;
+       dce_conn->wait_recv = NULL;
+       dce_conn->wait_private = NULL;
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               dcesrv_terminate_connection(dce_conn, nt_errstr(status));
+               return;
+       }
+
        subreq = dcerpc_read_ncacn_packet_send(dce_conn,
                                               dce_conn->event_ctx,
                                               dce_conn->stream);
index 9a643415b0c4a2e17d9a1f2951aafa86f69fc355..c038075e0ddcc129f883f69c0ddb072631cc243d 100644 (file)
@@ -288,6 +288,16 @@ struct dcesrv_connection {
 
        /* the negotiated bind time features */
        uint16_t bind_time_features;
+
+       /*
+        * This is used to block the connection during
+        * pending authentication.
+        */
+       struct tevent_req *(*wait_send)(TALLOC_CTX *mem_ctx,
+                                       struct tevent_context *ev,
+                                       void *private_data);
+       NTSTATUS (*wait_recv)(struct tevent_req *req);
+       void *wait_private;
 };