The branch, v3-6-test has been updated
       via  17fe342 s3-epmapper: fix vars init and return errors
       via  8a8f4df librpc: Return an error if we a broken floor.
       via  e41b818 cleanup: fix some trailing spaces
       via  7ae0d64 s3-epmapper: Fix allocation of data on the wrong context
       via  409e67e s3-epmapper: Make sure we work on a description duplicate.
       via  bdd17bb librpc: Added a dcerpc_binding_dup() function.
       via  5f47e57 s3-epmapper: Refactor the cleanup of endpoints.
       via  824f65c s3-epmapper: Use strcmp instead of strequal and check IPv6.
      from  2896698 s3: Fix some errno assignments in SMBC_opendir_ctx

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test


- Log -----------------------------------------------------------------
commit 17fe34287e582f804cc139a6164563699877d440
Author: Simo Sorce <i...@samba.org>
Date:   Thu Mar 24 11:49:27 2011 -0400

    s3-epmapper: fix vars init and return errors
    
    Properly initialize variables at each cycle.
    Convert to the right error when returning EPMAPPER ones.
    
    Autobuild-User: Simo Sorce <i...@samba.org>
    Autobuild-Date: Thu Mar 24 20:43:49 CET 2011 on sn-devel-104

commit 8a8f4dfe617d4d9625e3788c33f788e140e37f06
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Mar 24 13:45:32 2011 +0100

    librpc: Return an error if we a broken floor.
    
    Pair-Programmed-With: Simo Sorce <i...@samba.org>

commit e41b8186557bef3b2205fa998be514d7c9f61f1f
Author: Simo Sorce <i...@samba.org>
Date:   Thu Mar 24 09:21:11 2011 -0400

    cleanup: fix some trailing spaces

commit 7ae0d6404ed4a02702be139329939b2d7f0c9c5d
Author: Simo Sorce <i...@samba.org>
Date:   Thu Mar 24 08:23:48 2011 -0400

    s3-epmapper: Fix allocation of data on the wrong context
    
    p->mem_ctx is the short-lived per request context, while this data is long
    lived, allocate on p instead.

commit 409e67e780ad8b90d7d7a1a11f8c920e9a86381b
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Mar 24 14:39:56 2011 +0100

    s3-epmapper: Make sure we work on a description duplicate.

commit bdd17bb4b2785988f8f546ef60b54d655712a946
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Mar 24 14:39:37 2011 +0100

    librpc: Added a dcerpc_binding_dup() function.

commit 5f47e5763459fa2582a609074b448201854b4fa7
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Mar 24 13:07:54 2011 +0100

    s3-epmapper: Refactor the cleanup of endpoints.

commit 824f65c5e3dede8a2f29fe3bb92f89c03f3d4070
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Mar 24 13:07:05 2011 +0100

    s3-epmapper: Use strcmp instead of strequal and check IPv6.

-----------------------------------------------------------------------

Summary of changes:
 librpc/rpc/binding.c                       |  101 +++++++++++++++++++++++++--
 librpc/rpc/rpc_common.h                    |    2 +
 source3/rpc_server/epmapper/srv_epmapper.c |   62 ++++++++++-------
 3 files changed, 132 insertions(+), 33 deletions(-)


Changeset truncated at 500 lines:

diff --git a/librpc/rpc/binding.c b/librpc/rpc/binding.c
index 2a0295b..422537e 100644
--- a/librpc/rpc/binding.c
+++ b/librpc/rpc/binding.c
@@ -646,13 +646,22 @@ _PUBLIC_ const char 
*derpc_transport_string_by_transport(enum dcerpc_transport_t
        return NULL;
 }
 
-_PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, 
-                                  struct epm_tower *tower, 
-                                  struct dcerpc_binding **b_out)
+_PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
+                                           struct epm_tower *tower,
+                                           struct dcerpc_binding **b_out)
 {
        NTSTATUS status;
        struct dcerpc_binding *binding;
 
+       /*
+        * A tower needs to have at least 4 floors to carry useful
+        * information. Floor 3 is the transport identifier which defines
+        * how many floors are required at least.
+        */
+       if (tower->num_floors < 4) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
        binding = talloc_zero(mem_ctx, struct dcerpc_binding);
        NT_STATUS_HAVE_NO_MEMORY(binding);
 
@@ -669,15 +678,11 @@ _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX 
*mem_ctx,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       if (tower->num_floors < 1) {
-               return NT_STATUS_OK;
-       }
-
        /* Set object uuid */
        status = dcerpc_floor_get_lhs_data(&tower->floors[0], &binding->object);
 
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(1, ("Error pulling object uuid and version: %s", 
nt_errstr(status)));     
+               DEBUG(1, ("Error pulling object uuid and version: %s", 
nt_errstr(status)));
                return status;
        }
 
@@ -702,6 +707,86 @@ _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX 
*mem_ctx,
        return NT_STATUS_OK;
 }
 
+_PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
+                                                  const struct dcerpc_binding 
*b)
+{
+       struct dcerpc_binding *n;
+       uint32_t count;
+
+       n = talloc_zero(mem_ctx, struct dcerpc_binding);
+       if (n == NULL) {
+               return NULL;
+       }
+
+       n->transport = b->transport;
+       n->object = b->object;
+       n->flags = b->flags;
+       n->assoc_group_id = b->assoc_group_id;
+
+       if (b->host != NULL) {
+               n->host = talloc_strdup(n, b->host);
+               if (n->host == NULL) {
+                       talloc_free(n);
+                       return NULL;
+               }
+       }
+
+       if (b->target_hostname != NULL) {
+               n->target_hostname = talloc_strdup(n, b->target_hostname);
+               if (n->target_hostname == NULL) {
+                       talloc_free(n);
+                       return NULL;
+               }
+       }
+
+       if (b->target_principal != NULL) {
+               n->target_principal = talloc_strdup(n, b->target_principal);
+               if (n->target_principal == NULL) {
+                       talloc_free(n);
+                       return NULL;
+               }
+       }
+
+       if (b->localaddress != NULL) {
+               n->localaddress = talloc_strdup(n, b->localaddress);
+               if (n->localaddress == NULL) {
+                       talloc_free(n);
+                       return NULL;
+               }
+       }
+
+       if (b->endpoint != NULL) {
+               n->endpoint = talloc_strdup(n, b->endpoint);
+               if (n->endpoint == NULL) {
+                       talloc_free(n);
+                       return NULL;
+               }
+       }
+
+       for (count = 0; b->options && b->options[count]; count++);
+
+       if (count > 0) {
+               uint32_t i;
+
+               n->options = talloc_array(n, const char *, count + 1);
+               if (n->options == NULL) {
+                       talloc_free(n);
+                       return NULL;
+               }
+
+               for (i = 0; i < count; i++) {
+                       n->options[i] = talloc_strdup(n->options, 
b->options[i]);
+                       if (n->options[i] == NULL) {
+                               talloc_free(n);
+                               return NULL;
+                       }
+               }
+               n->options[count] = NULL;
+       }
+
+       return n;
+}
+
 _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
                                             const struct dcerpc_binding 
*binding,
                                             struct epm_tower *tower)
diff --git a/librpc/rpc/rpc_common.h b/librpc/rpc/rpc_common.h
index d0ffe61..44c3cfd 100644
--- a/librpc/rpc/rpc_common.h
+++ b/librpc/rpc/rpc_common.h
@@ -117,6 +117,8 @@ NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor 
*epm_floor);
 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
+struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
+                                         const struct dcerpc_binding *b);
 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
                                    const struct dcerpc_binding *binding,
                                    struct epm_tower *tower);
diff --git a/source3/rpc_server/epmapper/srv_epmapper.c 
b/source3/rpc_server/epmapper/srv_epmapper.c
index da998eb..b96c9d4 100644
--- a/source3/rpc_server/epmapper/srv_epmapper.c
+++ b/source3/rpc_server/epmapper/srv_epmapper.c
@@ -192,17 +192,22 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
                                                        iface->iface->name);
                        eps[total].syntax_id = iface->iface->syntax_id;
 
-                       description = d->ep_description;
+                       description = dcerpc_binding_dup(mem_ctx, 
d->ep_description);
+                       if (description == NULL) {
+                               return 0;
+                       }
                        description->object = iface->iface->syntax_id;
                        if (description->transport == NCACN_IP_TCP &&
                            srv_addr != NULL &&
-                           strequal(description->host, "0.0.0.0")) {
+                           (strcmp(description->host, "0.0.0.0") == 0 ||
+                            strcmp(description->host, "::") == 0)) {
                                description->host = srv_addr;
                        }
 
                        status = dcerpc_binding_build_tower(eps,
                                                            description,
                                                            &eps[total].ep);
+                       TALLOC_FREE(description);
                        if (NT_STATUS_IS_ERR(status)) {
                                DEBUG(1, ("Unable to build tower for %s\n",
                                          iface->iface->name));
@@ -230,16 +235,12 @@ static bool is_priviledged_pipe(struct 
auth_serversupplied_info *info) {
 bool srv_epmapper_delete_endpoints(struct pipes_struct *p)
 {
        struct epm_Delete r;
-       struct dcesrv_ep_entry_list *el;
+       struct dcesrv_ep_entry_list *el = p->ep_entries;
        error_status_t result;
 
-       if (p->ep_entries == NULL) {
-               return true;
-       }
+       while (el) {
+               struct dcesrv_ep_entry_list *next = el->next;
 
-       for (el = p->ep_entries;
-            el != NULL;
-            el = p->ep_entries) {
                r.in.num_ents = el->num_ents;
                r.in.entries = el->entries;
 
@@ -253,6 +254,8 @@ bool srv_epmapper_delete_endpoints(struct pipes_struct *p)
 
                DLIST_REMOVE(p->ep_entries, el);
                TALLOC_FREE(el);
+
+               el = next;
        }
 
        return true;
@@ -260,13 +263,15 @@ bool srv_epmapper_delete_endpoints(struct pipes_struct *p)
 
 void srv_epmapper_cleanup(void)
 {
-       struct dcesrv_endpoint *ep;
+       struct dcesrv_endpoint *ep = endpoint_table;
+
+       while (ep) {
+               struct dcesrv_endpoint *next = ep->next;
 
-       for (ep = endpoint_table;
-            ep != NULL;
-            ep = endpoint_table) {
                DLIST_REMOVE(endpoint_table, ep);
                TALLOC_FREE(ep);
+
+               ep = next;
        }
 }
 
@@ -282,6 +287,11 @@ error_status_t _epm_Insert(struct pipes_struct *p,
        error_status_t rc;
        NTSTATUS status;
        uint32_t i;
+       struct dcerpc_binding *b;
+       struct dcesrv_endpoint *ep;
+       struct dcesrv_iface_list *iflist;
+       struct dcesrv_iface *iface;
+       bool add_ep;
 
        /* If this is not a priviledged users, return */
        if (p->transport != NCALRPC ||
@@ -298,19 +308,20 @@ error_status_t _epm_Insert(struct pipes_struct *p,
                  r->in.num_ents));
 
        for (i = 0; i < r->in.num_ents; i++) {
-               struct dcerpc_binding *b = NULL;
-               struct dcesrv_endpoint *ep;
-               struct dcesrv_iface_list *iflist;
-               struct dcesrv_iface *iface;
-               bool add_ep = false;
+               add_ep = false;
+               b = NULL;
 
                status = dcerpc_binding_from_tower(tmp_ctx,
                                                   
&r->in.entries[i].tower->tower,
                                                   &b);
-               if (!NT_STATUS_IS_OK(status)) {
+               if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MEMORY)) {
                        rc = EPMAPPER_STATUS_NO_MEMORY;
                        goto done;
                }
+               if (!NT_STATUS_IS_OK(status)) {
+                       rc = EPMAPPER_STATUS_CANT_PERFORM_OP;
+                       goto done;
+               }
 
                DEBUG(3, ("_epm_Insert: Adding transport %s for %s\n",
                          derpc_transport_string_by_transport(b->transport),
@@ -322,7 +333,7 @@ error_status_t _epm_Insert(struct pipes_struct *p,
                        /* No entry found, create it */
                        ep = talloc_zero(NULL, struct dcesrv_endpoint);
                        if (ep == NULL) {
-                               rc = EPMAPPER_STATUS_CANT_PERFORM_OP;
+                               rc = EPMAPPER_STATUS_NO_MEMORY;
                                goto done;
                        }
                        add_ep = true;
@@ -379,7 +390,7 @@ error_status_t _epm_Insert(struct pipes_struct *p,
        if (r->in.num_ents > 0) {
                struct dcesrv_ep_entry_list *el;
 
-               el = talloc_zero(p->mem_ctx, struct dcesrv_ep_entry_list);
+               el = talloc_zero(p, struct dcesrv_ep_entry_list);
                if (el == NULL) {
                        rc = EPMAPPER_STATUS_NO_MEMORY;
                        goto done;
@@ -410,6 +421,10 @@ error_status_t _epm_Delete(struct pipes_struct *p,
        error_status_t rc;
        NTSTATUS status;
        uint32_t i;
+       struct dcerpc_binding *b;
+       struct dcesrv_endpoint *ep;
+       struct dcesrv_iface iface;
+       struct dcesrv_iface_list *iflist;
 
        DEBUG(3, ("_epm_Delete: Trying to delete %u entries.\n",
                  r->in.num_ents));
@@ -426,10 +441,7 @@ error_status_t _epm_Delete(struct pipes_struct *p,
        }
 
        for (i = 0; i < r->in.num_ents; i++) {
-               struct dcerpc_binding *b = NULL;
-               struct dcesrv_endpoint *ep;
-               struct dcesrv_iface iface;
-               struct dcesrv_iface_list *iflist;
+               b = NULL;
 
                status = dcerpc_binding_from_tower(tmp_ctx,
                                                   
&r->in.entries[i].tower->tower,


-- 
Samba Shared Repository

Reply via email to