s3-librpc: Add dcerpc_binding_vector_add_np_default().
authorAndreas Schneider <asn@samba.org>
Thu, 30 Jun 2011 09:56:11 +0000 (11:56 +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 cd8b656a7b72e21356b1bca7505c7b1267a2d2e8..bd4e9ee0d90d77042f4595550a4ecefdf08e0364 100644 (file)
 
 #define EPM_MAX_ANNOTATION_SIZE 64
 
+static bool binding_vector_realloc(struct dcerpc_binding_vector *bvec)
+{
+       if (bvec->count >= bvec->allocated) {
+               struct dcerpc_binding *tmp;
+
+               tmp = talloc_realloc(bvec,
+                                    bvec->bindings,
+                                    struct dcerpc_binding,
+                                    bvec->allocated * 2);
+               if (tmp == NULL) {
+                       return false;
+               }
+               bvec->bindings = tmp;
+               bvec->allocated = bvec->allocated * 2;
+       }
+
+       return true;
+}
+
 NTSTATUS dcerpc_binding_vector_new(TALLOC_CTX *mem_ctx,
                                   struct dcerpc_binding_vector **pbvec)
 {
@@ -66,6 +85,54 @@ done:
        return status;
 }
 
+NTSTATUS dcerpc_binding_vector_add_np_default(const struct ndr_interface_table *iface,
+                                             struct dcerpc_binding_vector *bvec)
+{
+       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;
+               }
+
+               /* Only add the named pipes defined in the iface endpoints */
+               if (b->transport != NCACN_NP) {
+                       talloc_free(b);
+                       continue;
+               }
+
+               b->object = iface->syntax_id;
+
+               b->host = talloc_asprintf(b, "\\\\%s", lp_netbios_name());
+               if (b->host == 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++;
+       }
+
+       return NT_STATUS_OK;
+}
+
 NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
                                      const struct ndr_interface_table *iface,
                                      uint16_t port,
index 61b85e23dc0ac34f61d4b7fa4a267ec0c4d9a84b..b8ea7abeb438a5cffa0f19cbadfc98115b194c0d 100644 (file)
@@ -38,6 +38,18 @@ struct dcerpc_binding_vector {
 NTSTATUS dcerpc_binding_vector_new(TALLOC_CTX *mem_ctx,
                                   struct dcerpc_binding_vector **pbvec);
 
+/**
+ * @brief Add default named pipes to the binding vector.
+ *
+ * @param[in] iface     The rpc interface to add.
+ *
+ * @param[in] bvec      The binding vector to add the interface.
+ *
+ * @return              An NTSTATUS error code.
+ */
+NTSTATUS dcerpc_binding_vector_add_np_default(const struct ndr_interface_table *iface,
+                                             struct dcerpc_binding_vector *bvec);
+
 NTSTATUS dcerpc_binding_vector_create(TALLOC_CTX *mem_ctx,
                                      const struct ndr_interface_table *iface,
                                      uint16_t port,