s3-librpc: Add dcerpc_binding_vector_add_port().
authorAndreas Schneider <asn@samba.org>
Thu, 30 Jun 2011 10:01:10 +0000 (12:01 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 1 Aug 2011 06:50:35 +0000 (08:50 +0200)
source3/librpc/rpc/dcerpc_ep.c
source3/librpc/rpc/dcerpc_ep.h

index bd4e9ee0d90d77042f4595550a4ecefdf08e0364..20936bcbf32cacaaa2b0082db66c2679105c1643 100644 (file)
@@ -133,6 +133,63 @@ NTSTATUS dcerpc_binding_vector_add_np_default(const struct ndr_interface_table *
        return NT_STATUS_OK;
 }
 
+NTSTATUS dcerpc_binding_vector_add_port(const struct ndr_interface_table *iface,
+                                       struct dcerpc_binding_vector *bvec,
+                                       const char *host,
+                                       uint16_t port)
+{
+       uint32_t ep_count = iface->endpoints->count;
+       uint32_t i;
+       NTSTATUS status;
+       bool ok;
+
+       for (i = 0; i < ep_count; i++) {
+               struct dcerpc_binding *b;
+
+               b = talloc_zero(bvec->bindings, struct dcerpc_binding);
+               if (b == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               status = dcerpc_parse_binding(b, iface->endpoints->names[i], &b);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return NT_STATUS_UNSUCCESSFUL;
+               }
+
+               if (b->transport != NCACN_IP_TCP) {
+                       talloc_free(b);
+                       continue;
+               }
+
+               b->object = iface->syntax_id;
+
+               b->host = talloc_strdup(b, host);
+               if (b->host == NULL) {
+                       talloc_free(b);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               b->endpoint = talloc_asprintf(b, "%u", port);
+               if (b->endpoint == NULL) {
+                       talloc_free(b);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               ok = binding_vector_realloc(bvec);
+               if (!ok) {
+                       talloc_free(b);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               bvec->bindings[bvec->count] = *b;
+               bvec->count++;
+
+               break;
+       }
+
+       return NT_STATUS_OK;
+}
+
 NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
                                      const struct ndr_interface_table *iface,
                                      uint16_t port,
index b8ea7abeb438a5cffa0f19cbadfc98115b194c0d..9375589c688a559e3e3ad784c7784dad851aad08 100644 (file)
@@ -50,6 +50,24 @@ NTSTATUS dcerpc_binding_vector_new(TALLOC_CTX *mem_ctx,
 NTSTATUS dcerpc_binding_vector_add_np_default(const struct ndr_interface_table *iface,
                                              struct dcerpc_binding_vector *bvec);
 
+/**
+ * @brief Add a tcpip port to a binding vector.
+ *
+ * @param[in] iface     The rpc interface to add.
+ *
+ * @param[in] bvec      The binding vector to add the intface, host and port.
+ *
+ * @param[in] host      The ip address of the network inteface bound.
+ *
+ * @param[in] port      The port bound.
+ *
+ * @return              An NTSTATUS error code.
+ */
+NTSTATUS dcerpc_binding_vector_add_port(const struct ndr_interface_table *iface,
+                                       struct dcerpc_binding_vector *bvec,
+                                       const char *host,
+                                       uint16_t port);
+
 NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
                                      const struct ndr_interface_table *iface,
                                      uint16_t port,