The branch, master has been updated
       via  72bd60b s3-epmapper: fix vars init and return errors
       via  edc2600 librpc: Return an error if we a broken floor.
       via  95daebe cleanup: fix some trailing spaces
       via  dbe957e s3-epmapper: Fix allocation of data on the wrong context
       via  5ebf007 s3-epmapper: Make sure we work on a description duplicate.
       via  f534dcd librpc: Added a dcerpc_binding_dup() function.
       via  e8912b9 s3-epmapper: Refactor the cleanup of endpoints.
       via  fd89e29 s3-epmapper: Use strcmp instead of strequal and check IPv6.
       via  bf1e330 s3-epmapper: Increase debug levels.
      from  155c4fb s3: Fix some errno assignments in SMBC_opendir_ctx

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 72bd60b2fee20dc85c1cc88d5d4e2efdfb74b701
Author: Simo Sorce <[email protected]>
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 <[email protected]>
    Autobuild-Date: Thu Mar 24 20:43:49 CET 2011 on sn-devel-104

commit edc26007bf50ce165b8f8dfba5e1c7f86f6918e6
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 24 13:45:32 2011 +0100

    librpc: Return an error if we a broken floor.
    
    Pair-Programmed-With: Simo Sorce <[email protected]>

commit 95daebe1c339cefe87bcb5d4e2afc79a45af3b62
Author: Simo Sorce <[email protected]>
Date:   Thu Mar 24 09:21:11 2011 -0400

    cleanup: fix some trailing spaces

commit dbe957e48fec13aec39b7c2675cd4b7cde55d9d0
Author: Simo Sorce <[email protected]>
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 5ebf0072336ece5acf120bcdeb6612445fa059f1
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 24 14:39:56 2011 +0100

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

commit f534dcdca3184a342df2d702663088a4afba6571
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 24 14:39:37 2011 +0100

    librpc: Added a dcerpc_binding_dup() function.

commit e8912b9ad31154adca4d2065b2986661a956a959
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 24 13:07:54 2011 +0100

    s3-epmapper: Refactor the cleanup of endpoints.

commit fd89e29e7ee5065b6f4349e391c90c5f81e7c476
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 24 13:07:05 2011 +0100

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

commit bf1e330f69951400f12ecb17c82adadd1e901a58
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 24 10:44:14 2011 +0100

    s3-epmapper: Increase debug levels.

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

Summary of changes:
 librpc/rpc/binding.c                       |  101 +++++++++++++++++++++++++--
 librpc/rpc/rpc_common.h                    |    2 +
 source3/rpc_server/epmapper/srv_epmapper.c |   78 ++++++++++++---------
 3 files changed, 140 insertions(+), 41 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..4fc8ecd 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,
@@ -509,14 +521,14 @@ error_status_t _epm_Lookup(struct pipes_struct *p,
                return EPMAPPER_STATUS_NO_MEMORY;
        }
 
-       DEBUG(3, ("_epm_Lookup: Trying to lookup max. %u entries.\n",
+       DEBUG(5, ("_epm_Lookup: Trying to lookup max. %u entries.\n",
                  r->in.max_ents));
 
        if (r->in.entry_handle == NULL ||
            policy_handle_empty(r->in.entry_handle)) {
                struct GUID *obj;
 
-               DEBUG(5, ("_epm_Lookup: No entry_handle found, creating 
it.\n"));
+               DEBUG(7, ("_epm_Lookup: No entry_handle found, creating 
it.\n"));
 
                eps = talloc_zero(tmp_ctx, struct rpc_eps);
                if (eps == NULL) {
@@ -600,7 +612,7 @@ error_status_t _epm_Lookup(struct pipes_struct *p,
                }
                entry_handle = r->out.entry_handle;
        } else {
-               DEBUG(5, ("_epm_Lookup: Trying to find entry_handle.\n"));
+               DEBUG(7, ("_epm_Lookup: Trying to find entry_handle.\n"));
 
                ok = find_policy_by_hnd(p, r->in.entry_handle, (void **)(void*) 
&eps);
                if (!ok) {
@@ -621,7 +633,7 @@ error_status_t _epm_Lookup(struct pipes_struct *p,
                count = eps->count;
        }
 
-       DEBUG(3, ("_epm_Lookup: Find %u entries\n", count));
+       DEBUG(5, ("_epm_Lookup: Find %u entries\n", count));
 
        if (count == 0) {
                close_policy_hnd(p, entry_handle);
@@ -846,7 +858,7 @@ error_status_t _epm_Map(struct pipes_struct *p,
 
        ZERO_STRUCTP(r->out.entry_handle);
 
-       DEBUG(3, ("_epm_Map: Trying to map max. %u towers.\n",
+       DEBUG(5, ("_epm_Map: Trying to map max. %u towers.\n",
                  r->in.max_towers));
 
        /*
@@ -897,7 +909,7 @@ error_status_t _epm_Map(struct pipes_struct *p,
            policy_handle_empty(r->in.entry_handle)) {
                struct GUID *obj;
 
-               DEBUG(5, ("_epm_Map: No entry_handle found, creating it.\n"));
+               DEBUG(7, ("_epm_Map: No entry_handle found, creating it.\n"));
 
                eps = talloc_zero(tmp_ctx, struct rpc_eps);
                if (eps == NULL) {
@@ -986,7 +998,7 @@ error_status_t _epm_Map(struct pipes_struct *p,
                }
                entry_handle = r->out.entry_handle;
        } else {
-               DEBUG(5, ("_epm_Map: Trying to find entry_handle.\n"));
+               DEBUG(7, ("_epm_Map: Trying to find entry_handle.\n"));
 
                ok = find_policy_by_hnd(p, r->in.entry_handle, (void **)(void*) 
&eps);
                if (!ok) {
@@ -1022,7 +1034,7 @@ error_status_t _epm_Map(struct pipes_struct *p,
        }
 
        for (i = 0; i < count; i++) {
-               DEBUG(5, ("_epm_Map: Map tower for '%s'\n",
+               DEBUG(7, ("_epm_Map: Map tower for '%s'\n",
                           eps->e[i].name));
 
                r->out.towers[num_towers].twr = talloc(r->out.towers,


-- 
Samba Shared Repository

Reply via email to