s4:librpc: use gensec_update_send() in dcerpc_bind_auth_send()
authorStefan Metzmacher <metze@samba.org>
Mon, 15 May 2017 20:36:20 +0000 (22:36 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 21 May 2017 19:05:13 +0000 (21:05 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/librpc/rpc/dcerpc_auth.c

index e790a9f51d25828aad0e4b61c2facccfd148ec03..ee13a6b094b79ce4e701b6c184db824c4333a2d1 100644 (file)
@@ -136,6 +136,8 @@ _PUBLIC_ NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
 
 struct bind_auth_state {
        struct dcerpc_pipe *pipe;
+       struct ndr_syntax_id syntax;
+       struct ndr_syntax_id transfer_syntax;
        struct dcerpc_auth out_auth_info;
        struct dcerpc_auth in_auth_info;
        bool more_processing;   /* Is there anything more to do after the
@@ -289,6 +291,8 @@ static void bind_auth_recv_bindreply(struct tevent_req *subreq)
 }
 
 
+static void dcerpc_bind_auth_gensec_done(struct tevent_req *subreq);
+
 /**
    Bind to a DCE/RPC pipe, send async request
    @param mem_ctx TALLOC_CTX for the allocation of the composite_context
@@ -313,7 +317,6 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
        struct bind_auth_state *state;
        struct dcecli_security *sec;
        struct tevent_req *subreq;
-       struct ndr_syntax_id syntax, transfer_syntax;
        const char *target_principal = NULL;
 
        /* composite context allocation and setup */
@@ -327,8 +330,8 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
        state->pipe = p;
 
        c->status = dcerpc_init_syntaxes(p, table,
-                                        &syntax,
-                                        &transfer_syntax);
+                                        &state->syntax,
+                                        &state->transfer_syntax);
        if (!composite_is_ok(c)) return c;
 
        sec = &p->conn->security_state;
@@ -420,22 +423,34 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
         * it doesn't like that either
         */
 
-       state->pipe->inhibit_timeout_processing = true;
-       state->pipe->timed_out = false;
-       c->status = gensec_update_ev(sec->generic_state, state,
-                                 p->conn->event_ctx,
-                                 data_blob_null,
-                                 &state->out_auth_info.credentials);
-       if (state->pipe->timed_out) {
-               composite_error(c, NT_STATUS_IO_TIMEOUT);
-               return c;
-       }
-       state->pipe->inhibit_timeout_processing = false;
+       subreq = gensec_update_send(state,
+                                   p->conn->event_ctx,
+                                   sec->generic_state,
+                                   data_blob_null);
+       if (composite_nomem(subreq, c)) return c;
+       tevent_req_set_callback(subreq, dcerpc_bind_auth_gensec_done, c);
 
+       return c;
+}
+
+static void dcerpc_bind_auth_gensec_done(struct tevent_req *subreq)
+{
+       struct composite_context *c =
+               tevent_req_callback_data(subreq,
+               struct composite_context);
+       struct bind_auth_state *state =
+               talloc_get_type_abort(c->private_data,
+               struct bind_auth_state);
+       struct dcerpc_pipe *p = state->pipe;
+       struct dcecli_security *sec = &p->conn->security_state;
+
+       c->status = gensec_update_recv(subreq, state,
+                                      &state->out_auth_info.credentials);
+       TALLOC_FREE(subreq);
        if (!NT_STATUS_IS_OK(c->status) &&
            !NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
                composite_error(c, c->status);
-               return c;
+               return;
        }
 
        state->more_processing = NT_STATUS_EQUAL(c->status,
@@ -443,7 +458,7 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
 
        if (state->out_auth_info.credentials.length == 0) {
                composite_done(c);
-               return c;
+               return;
        }
 
        if (gensec_have_feature(sec->generic_state, GENSEC_FEATURE_SIGN_PKT_HEADER)) {
@@ -462,11 +477,11 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
        /* The first request always is a dcerpc_bind. The subsequent ones
         * depend on gensec results */
        subreq = dcerpc_bind_send(state, p->conn->event_ctx, p,
-                                 &syntax, &transfer_syntax);
-       if (composite_nomem(subreq, c)) return c;
+                                 &state->syntax, &state->transfer_syntax);
+       if (composite_nomem(subreq, c)) return;
        tevent_req_set_callback(subreq, bind_auth_recv_bindreply, c);
 
-       return c;
+       return;
 }