s3-librpc: Leave the epm registration connection open.
authorAndreas Schneider <asn@samba.org>
Wed, 9 Mar 2011 09:17:06 +0000 (10:17 +0100)
committerSimo Sorce <idra@samba.org>
Wed, 23 Mar 2011 16:19:22 +0000 (17:19 +0100)
source3/librpc/rpc/dcerpc_ep.c
source3/librpc/rpc/dcerpc_ep.h
source3/rpc_server/rpc_ep_setup.c

index 764dc17233a52799a596adf47a9bed8389536103..92c01a32bbc6e30c27e53fcf56ccc74b756caa41 100644 (file)
@@ -130,12 +130,14 @@ done:
        return status;
 }
 
-static NTSTATUS ep_register(const struct ndr_interface_table *iface,
+static NTSTATUS ep_register(TALLOC_CTX *mem_ctx,
+                           const struct ndr_interface_table *iface,
                            const struct dcerpc_binding_vector *bind_vec,
                            const struct GUID *object_guid,
                            const char *annotation,
                            uint32_t replace,
-                           uint32_t unregister)
+                           uint32_t unregister,
+                           struct dcerpc_binding_handle **pbh)
 {
        struct rpc_pipe_client *cli = NULL;
        struct dcerpc_binding_handle *h;
@@ -285,33 +287,63 @@ static NTSTATUS ep_register(const struct ndr_interface_table *iface,
                goto done;
        }
 
+       if (pbh != NULL) {
+               *pbh = talloc_move(mem_ctx, &h);
+               talloc_steal(mem_ctx, cli);
+       }
+
 done:
        talloc_free(tmp_ctx);
 
        return status;
 }
 
-NTSTATUS dcerpc_ep_register(const struct ndr_interface_table *iface,
+NTSTATUS dcerpc_ep_register(TALLOC_CTX *mem_ctx,
+                           const struct ndr_interface_table *iface,
                            const struct dcerpc_binding_vector *bind_vec,
                            const struct GUID *object_guid,
-                           const char *annotation)
+                           const char *annotation,
+                           struct dcerpc_binding_handle **ph)
 {
-       return ep_register(iface, bind_vec, object_guid, annotation, 1, 0);
+       return ep_register(mem_ctx,
+                          iface,
+                          bind_vec,
+                          object_guid,
+                          annotation,
+                          1,
+                          0,
+                          ph);
 }
 
-NTSTATUS dcerpc_ep_register_noreplace(const struct ndr_interface_table *iface,
+NTSTATUS dcerpc_ep_register_noreplace(TALLOC_CTX *mem_ctx,
+                                     const struct ndr_interface_table *iface,
                                      const struct dcerpc_binding_vector *bind_vec,
                                      const struct GUID *object_guid,
-                                     const char *annotation)
+                                     const char *annotation,
+                                     struct dcerpc_binding_handle **ph)
 {
-       return ep_register(iface, bind_vec, object_guid, annotation, 0, 0);
+       return ep_register(mem_ctx,
+                          iface,
+                          bind_vec,
+                          object_guid,
+                          annotation,
+                          0,
+                          0,
+                          ph);
 }
 
 NTSTATUS dcerpc_ep_unregister(const struct ndr_interface_table *iface,
                              const struct dcerpc_binding_vector *bind_vec,
                              const struct GUID *object_guid)
 {
-       return ep_register(iface, bind_vec, object_guid, NULL, 0, 1);
+       return ep_register(NULL,
+                          iface,
+                          bind_vec,
+                          object_guid,
+                          NULL,
+                          0,
+                          1,
+                          NULL);
 }
 
 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */
index 99682beb9a3008629a10b9e252061d0fd2de103c..57b1d2744081e12350058c855120426b88e8ffe0 100644 (file)
@@ -34,6 +34,8 @@ NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
 /**
  * @brief Adds server address information in the local endpoint map.
  *
+ * @param[in]  mem_ctx  The memory context to use for the binding handle.
+ *
  * @param[in]  iface    The interface specification to register with the local
  *                      endpoint map.
  *
@@ -55,17 +57,25 @@ NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
  *                         supplied, including an empty annotation string,
  *                         replaces any existing annotation string.
  *
+ * @param[out] ph          A pointer to store the binding handle. The memory
+ *                         context will be the give one. If you free this handle
+ *                         then the connection will be closed.
+ *
  * @return                 An NTSTATUS error code.
  */
-NTSTATUS dcerpc_ep_register(const struct ndr_interface_table *iface,
+NTSTATUS dcerpc_ep_register(TALLOC_CTX *mem_ctx,
+                           const struct ndr_interface_table *iface,
                            const struct dcerpc_binding_vector *bind_vec,
                            const struct GUID *object_guid,
-                           const char *annotation);
+                           const char *annotation,
+                           struct dcerpc_binding_handle **ph);
 
-NTSTATUS dcerpc_ep_register_noreplace(const struct ndr_interface_table *iface,
+NTSTATUS dcerpc_ep_register_noreplace(TALLOC_CTX *mem_ctx,
+                                     const struct ndr_interface_table *iface,
                                      const struct dcerpc_binding_vector *bind_vec,
                                      const struct GUID *object_guid,
-                                     const char *annotation);
+                                     const char *annotation,
+                                     struct dcerpc_binding_handle **ph);
 
 NTSTATUS dcerpc_ep_unregister(const struct ndr_interface_table *iface,
                              const struct dcerpc_binding_vector *bind_vec,
index 19eba17ef589c5bd120f81acbb70fd9252007fb6..6ffcf10b9b62b37a376f15095d6dabfa5282715b 100644 (file)
@@ -149,14 +149,16 @@ static NTSTATUS _rpc_ep_unregister(const struct ndr_interface_table *iface)
 }
 
 static void rpc_ep_setup_register_loop(struct tevent_req *subreq);
-static NTSTATUS rpc_ep_setup_try_register(struct tevent_context *ev_ctx,
+static NTSTATUS rpc_ep_setup_try_register(TALLOC_CTX *mem_ctx,
+                                         struct tevent_context *ev_ctx,
                                          struct messaging_context *msg_ctx,
                                          const struct ndr_interface_table *iface,
                                          const char *name,
-                                         uint16_t port);
+                                         uint16_t port,
+                                         struct dcerpc_binding_handle **pbh);
 
 struct rpc_ep_regsiter_state {
-       uint32_t wait_time;
+       struct dcerpc_binding_handle *h;
 
        struct tevent_context *ev_ctx;
        struct messaging_context *msg_ctx;
@@ -165,6 +167,8 @@ struct rpc_ep_regsiter_state {
 
        const char *ncalrpc;
        uint16_t port;
+
+       uint32_t wait_time;
 };
 
 static NTSTATUS rpc_ep_setup_register(struct tevent_context *ev_ctx,
@@ -209,14 +213,17 @@ static void rpc_ep_setup_register_loop(struct tevent_req *req)
        ok = tevent_wakeup_recv(req);
        TALLOC_FREE(req);
        if (!ok) {
+               talloc_free(state);
                return;
        }
 
-       status = rpc_ep_setup_try_register(state->ev_ctx,
+       status = rpc_ep_setup_try_register(state,
+                                          state->ev_ctx,
                                           state->msg_ctx,
                                           state->iface,
                                           state->ncalrpc,
-                                          state->port);
+                                          state->port,
+                                          &state->h);
        if (NT_STATUS_IS_OK(status)) {
                talloc_free(state);
                return;
@@ -240,16 +247,18 @@ static void rpc_ep_setup_register_loop(struct tevent_req *req)
        return;
 }
 
-static NTSTATUS rpc_ep_setup_try_register(struct tevent_context *ev_ctx,
+static NTSTATUS rpc_ep_setup_try_register(TALLOC_CTX *mem_ctx,
+                                         struct tevent_context *ev_ctx,
                                          struct messaging_context *msg_ctx,
                                          const struct ndr_interface_table *iface,
                                          const char *name,
-                                         uint16_t port)
+                                         uint16_t port,
+                                         struct dcerpc_binding_handle **pbh)
 {
        struct dcerpc_binding_vector *v = NULL;
        NTSTATUS status;
 
-       status = dcerpc_binding_vector_create(talloc_tos(),
+       status = dcerpc_binding_vector_create(mem_ctx,
                                              iface,
                                              port,
                                              name,
@@ -258,10 +267,13 @@ static NTSTATUS rpc_ep_setup_try_register(struct tevent_context *ev_ctx,
                return status;
        }
 
-       status = dcerpc_ep_register(iface,
+       status = dcerpc_ep_register(mem_ctx,
+                                   iface,
                                    v,
                                    &iface->syntax_id.uuid,
-                                   name);
+                                   name,
+                                   pbh);
+       talloc_free(v);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }