r17323: make better use of the composite api and fix the memory
authorStefan Metzmacher <metze@samba.org>
Sun, 30 Jul 2006 17:50:37 +0000 (17:50 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:15:14 +0000 (14:15 -0500)
hierachy

metze
(This used to be commit a0aa61a8d583ef626d082c47377c87008874e235)

source4/librpc/rpc/dcerpc.c

index 244ac9fdfac693a4933f68bb31dcccc954d33a53..b736826b63901617eea69423829c6684ab6e1d67 100644 (file)
@@ -632,18 +632,10 @@ struct composite_context *dcerpc_bind_send(struct dcerpc_pipe *p,
        DATA_BLOB blob;
        struct rpc_request *req;
 
-       /* we allocate a dcerpc_request so we can be in the same
-          request queue as normal requests, but most of the request
-          fields are not used as there is no call id */
-       req = talloc_zero(mem_ctx, struct rpc_request);
-       if (req == NULL) return NULL;
-
-       c = talloc_zero(mem_ctx, struct composite_context);
+       c = composite_create(mem_ctx,p->conn->event_ctx);
        if (c == NULL) return NULL;
 
-       c->state = COMPOSITE_STATE_IN_PROGRESS;
        c->private_data = p;
-       c->event_ctx = p->conn->event_ctx;
 
        p->syntax = *syntax;
        p->transfer_syntax = *transfer_syntax;
@@ -659,12 +651,8 @@ struct composite_context *dcerpc_bind_send(struct dcerpc_pipe *p,
        pkt.u.bind.max_recv_frag = 5840;
        pkt.u.bind.assoc_group_id = 0;
        pkt.u.bind.num_contexts = 1;
-       pkt.u.bind.ctx_list =
-               talloc_array(mem_ctx, struct dcerpc_ctx_list, 1);
-       if (pkt.u.bind.ctx_list == NULL) {
-               c->status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
+       pkt.u.bind.ctx_list = talloc_array(mem_ctx, struct dcerpc_ctx_list, 1);
+       if (composite_nomem(pkt.u.bind.ctx_list, c)) return c;
        pkt.u.bind.ctx_list[0].context_id = p->context_id;
        pkt.u.bind.ctx_list[0].num_transfer_syntaxes = 1;
        pkt.u.bind.ctx_list[0].abstract_syntax = p->syntax;
@@ -674,36 +662,34 @@ struct composite_context *dcerpc_bind_send(struct dcerpc_pipe *p,
        /* construct the NDR form of the packet */
        c->status = ncacn_push_auth(&blob, c, &pkt,
                                    p->conn->security_state.auth_info);
-       if (!NT_STATUS_IS_OK(c->status)) {
-               goto failed;
-       }
+       if (!composite_is_ok(c)) return c;
 
        p->conn->transport.recv_data = dcerpc_recv_data;
 
+       /*
+        * we allocate a dcerpc_request so we can be in the same
+        * request queue as normal requests
+        */
+       req = talloc_zero(c, struct rpc_request);
+       if (composite_nomem(req, c)) return c;
+
        req->state = RPC_REQUEST_PENDING;
        req->call_id = pkt.call_id;
        req->async.private = c;
        req->async.callback = dcerpc_composite_fail;
        req->p = p;
        req->recv_handler = dcerpc_bind_recv_handler;
-
        DLIST_ADD_END(p->conn->pending, req, struct rpc_request *);
 
        c->status = p->conn->transport.send_request(p->conn, &blob,
                                                    True);
-       if (!NT_STATUS_IS_OK(c->status)) {
-               goto failed;
-       }
+       if (!composite_is_ok(c)) return c;
 
        event_add_timed(c->event_ctx, req,
                        timeval_current_ofs(DCERPC_REQUEST_TIMEOUT, 0),
                        dcerpc_timeout_handler, req);
 
        return c;
-
- failed:
-       composite_error(c, c->status);
-       return c;
 }
 
 /*
@@ -1559,18 +1545,10 @@ struct composite_context *dcerpc_alter_context_send(struct dcerpc_pipe *p,
        DATA_BLOB blob;
        struct rpc_request *req;
 
-       /* we allocate a dcerpc_request so we can be in the same
-          request queue as normal requests, but most of the request
-          fields are not used as there is no call id */
-       req = talloc_zero(mem_ctx, struct rpc_request);
-       if (req == NULL) return NULL;
-
-       c = talloc_zero(req, struct composite_context);
+       c = composite_create(mem_ctx, p->conn->event_ctx);
        if (c == NULL) return NULL;
 
-       c->state = COMPOSITE_STATE_IN_PROGRESS;
        c->private_data = p;
-       c->event_ctx = p->conn->event_ctx;
 
        p->syntax = *syntax;
        p->transfer_syntax = *transfer_syntax;
@@ -1586,12 +1564,8 @@ struct composite_context *dcerpc_alter_context_send(struct dcerpc_pipe *p,
        pkt.u.alter.max_recv_frag = 5840;
        pkt.u.alter.assoc_group_id = 0;
        pkt.u.alter.num_contexts = 1;
-       pkt.u.alter.ctx_list = talloc_array(mem_ctx,
-                                                  struct dcerpc_ctx_list, 1);
-       if (pkt.u.alter.ctx_list == NULL) {
-               c->status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
+       pkt.u.alter.ctx_list = talloc_array(c, struct dcerpc_ctx_list, 1);
+       if (composite_nomem(pkt.u.alter.ctx_list, c)) return c;
        pkt.u.alter.ctx_list[0].context_id = p->context_id;
        pkt.u.alter.ctx_list[0].num_transfer_syntaxes = 1;
        pkt.u.alter.ctx_list[0].abstract_syntax = p->syntax;
@@ -1601,35 +1575,33 @@ struct composite_context *dcerpc_alter_context_send(struct dcerpc_pipe *p,
        /* construct the NDR form of the packet */
        c->status = ncacn_push_auth(&blob, mem_ctx, &pkt,
                                    p->conn->security_state.auth_info);
-       if (!NT_STATUS_IS_OK(c->status)) {
-               goto failed;
-       }
+       if (!composite_is_ok(c)) return c;
 
        p->conn->transport.recv_data = dcerpc_recv_data;
 
+       /*
+        * we allocate a dcerpc_request so we can be in the same
+        * request queue as normal requests
+        */
+       req = talloc_zero(c, struct rpc_request);
+       if (composite_nomem(req, c)) return c;
+
        req->state = RPC_REQUEST_PENDING;
        req->call_id = pkt.call_id;
        req->async.private = c;
        req->async.callback = dcerpc_composite_fail;
        req->p = p;
        req->recv_handler = dcerpc_alter_recv_handler;
-
        DLIST_ADD_END(p->conn->pending, req, struct rpc_request *);
 
        c->status = p->conn->transport.send_request(p->conn, &blob, True);
-       if (!NT_STATUS_IS_OK(c->status)) {
-               goto failed;
-       }
+       if (!composite_is_ok(c)) return c;
 
        event_add_timed(c->event_ctx, req,
                        timeval_current_ofs(DCERPC_REQUEST_TIMEOUT, 0),
                        dcerpc_timeout_handler, req);
 
        return c;
-
- failed:
-       composite_error(c, c->status);
-       return c;
 }
 
 NTSTATUS dcerpc_alter_context_recv(struct composite_context *ctx)