s3-includes: only include ntdomain.h where needed.
[samba.git] / source3 / rpc_server / epmapper / srv_epmapper.c
index 2e3e5d2173ff6d62a6ecf44183e404623ea48914..d96fd1e929fab1c11b44b7858668025194340db7 100644 (file)
@@ -24,6 +24,8 @@
 #include "librpc/gen_ndr/ndr_epmapper.h"
 #include "librpc/gen_ndr/srv_epmapper.h"
 #include "srv_epmapper.h"
+#include "auth.h"
+#include "ntdomain.h"
 
 typedef uint32_t error_status_t;
 
@@ -192,7 +194,10 @@ 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 &&
@@ -204,6 +209,7 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
                        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));
@@ -283,6 +289,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 ||
@@ -299,19 +310,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),
@@ -323,7 +335,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;
@@ -380,7 +392,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;
@@ -411,6 +423,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));
@@ -427,10 +443,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,