s3-rpc: make process_request_pdu_send async
authorDavid Disseldorp <ddiss@samba.org>
Thu, 26 Apr 2012 08:52:48 +0000 (10:52 +0200)
committerDavid Disseldorp <ddiss@samba.org>
Mon, 15 Apr 2013 16:15:17 +0000 (18:15 +0200)
source3/rpc_server/srv_pipe.c

index 0883d36145b7074904b623758d22795ad0291081..2b0c55775b5e6803405b9921c96afa2af945b76e 100644 (file)
@@ -1498,20 +1498,33 @@ static NTSTATUS dcesrv_auth_request(struct pipe_auth_data *auth,
        return NT_STATUS_OK;
 }
 
+struct process_request_pdu_state {
+       bool success;
+};
 /****************************************************************************
  Processes a request pdu. This will do auth processing if needed, and
  appends the data into the complete stream if the LAST flag is not set.
 ****************************************************************************/
 
-static bool process_request_pdu(struct pipes_struct *p, struct ncacn_packet *pkt)
+static struct tevent_req *process_request_pdu_send(struct tevent_context *ev,
+                                                  struct pipes_struct *p,
+                                                  struct ncacn_packet *pkt)
 {
        NTSTATUS status;
        DATA_BLOB data;
+       struct process_request_pdu_state *state;
+       struct tevent_req *req = tevent_req_create(p->mem_ctx, &state,
+                                       struct process_request_pdu_state);
+       if (req == NULL) {
+               return NULL;
+       }
 
        if (!p->pipe_bound) {
                DEBUG(0,("process_request_pdu: rpc request with no bind.\n"));
                set_incoming_fault(p);
-               return False;
+               state->success = false;
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
        }
 
        /* Store the opnum */
@@ -1522,7 +1535,9 @@ static bool process_request_pdu(struct pipes_struct *p, struct ncacn_packet *pkt
                DEBUG(0, ("Failed to check packet auth. (%s)\n",
                          nt_errstr(status)));
                set_incoming_fault(p);
-               return false;
+               state->success = false;
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
        }
 
        data = pkt->u.request.stub_and_verifier;
@@ -1540,7 +1555,9 @@ static bool process_request_pdu(struct pipes_struct *p, struct ncacn_packet *pkt
                          (unsigned int)p->in_data.data.length,
                          (unsigned int)data.length));
                set_incoming_fault(p);
-               return False;
+               state->success = false;
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
        }
 
        /*
@@ -1555,7 +1572,9 @@ static bool process_request_pdu(struct pipes_struct *p, struct ncacn_packet *pkt
                                  (unsigned int)data.length,
                                  (unsigned int)p->in_data.data.length));
                        set_incoming_fault(p);
-                       return False;
+                       state->success = false;
+                       tevent_req_done(req);
+                       return tevent_req_post(req, ev);
                }
        }
 
@@ -1573,10 +1592,24 @@ static bool process_request_pdu(struct pipes_struct *p, struct ncacn_packet *pkt
                        ret = api_pipe_request(p, pkt);
                }
 
-               return ret;
+               state->success = ret;
+               tevent_req_done(req);
+               return tevent_req_post(req, ev);
        }
 
-       return True;
+       state->success = true;
+       tevent_req_done(req);
+       return tevent_req_post(req, ev);
+}
+
+static bool process_request_pdu_recv(struct tevent_req *req)
+{
+       struct process_request_pdu_state *state
+               = tevent_req_data(req, struct process_request_pdu_state);
+       bool ret = state->success;
+
+       tevent_req_received(req);
+       return ret;
 }
 
 struct process_complete_pdu_state {
@@ -1584,6 +1617,7 @@ struct process_complete_pdu_state {
        bool reply;
        NTSTATUS status;
 };
+void process_complete_pdu_done(struct tevent_req *subreq);
 /****************************************************************************
  Processes a finished PDU stored in p->in_data.pdu.
 ****************************************************************************/
@@ -1592,6 +1626,7 @@ struct tevent_req *process_complete_pdu_send(struct tevent_context *ev,
                                             struct pipes_struct *p)
 {
        struct tevent_req *req;
+       struct tevent_req *subreq;
        struct ncacn_packet *pkt;
        NTSTATUS status;
        struct process_complete_pdu_state *state;
@@ -1643,7 +1678,12 @@ struct tevent_req *process_complete_pdu_send(struct tevent_context *ev,
 
        switch (pkt->ptype) {
        case DCERPC_PKT_REQUEST:
-               state->reply = process_request_pdu(p, pkt);
+               subreq = process_request_pdu_send(ev, p, pkt);
+               if (tevent_req_nomem(subreq, req)) {
+                       return tevent_req_post(req, ev);
+               }
+               tevent_req_set_callback(subreq, process_complete_pdu_done, req);
+               return req;
                break;
 
        case DCERPC_PKT_PING: /* CL request - ignore... */
@@ -1759,6 +1799,17 @@ struct tevent_req *process_complete_pdu_send(struct tevent_context *ev,
        return tevent_req_post(req, ev);
 }
 
+void process_complete_pdu_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req
+               = tevent_req_callback_data(subreq, struct tevent_req);
+       struct process_complete_pdu_state *state
+               = tevent_req_data(req, struct process_complete_pdu_state);
+
+       state->reply = process_request_pdu_recv(subreq);
+       tevent_req_done(req);
+}
+
 void process_complete_pdu_recv(struct tevent_req *req)
 {
        struct process_complete_pdu_state *state