winbind: Return queried domain name from name_to_sid
authorChristof Schmitt <cs@samba.org>
Mon, 11 Mar 2019 23:11:01 +0000 (16:11 -0700)
committerChristof Schmitt <cs@samba.org>
Thu, 18 Apr 2019 17:21:18 +0000 (17:21 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13831

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/winbindd/winbindd.h
source3/winbindd/winbindd_ads.c
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_msrpc.c
source3/winbindd/winbindd_reconnect.c
source3/winbindd/winbindd_reconnect_ads.c
source3/winbindd/winbindd_rpc.c
source3/winbindd/winbindd_rpc.h
source3/winbindd/winbindd_samr.c

index 7490d62..a72d6aa 100644 (file)
@@ -225,6 +225,7 @@ struct winbindd_methods {
                                const char *domain_name,
                                const char *name,
                                uint32_t flags,
+                               const char **pdom_name,
                                struct dom_sid *sid,
                                enum lsa_SidType *type);
 
index 4b5966d..5f20cfb 100644 (file)
@@ -558,11 +558,12 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            const char *domain_name,
                            const char *name,
                            uint32_t flags,
+                           const char **pdom_name,
                            struct dom_sid *sid,
                            enum lsa_SidType *type)
 {
        return msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
-                                        flags, sid, type);
+                                        flags, pdom_name, sid, type);
 }
 
 /* convert a domain SID to a user or group name - use rpc methods */
index c686089..92a5e1d 100644 (file)
@@ -1820,7 +1820,7 @@ NTSTATUS wb_cache_name_to_sid(struct winbindd_domain *domain,
 
        winbindd_domain_init_backend(domain);
        status = domain->backend->name_to_sid(domain, mem_ctx, domain_name,
-                                             name, flags, sid, type);
+                                             name, flags, NULL, sid, type);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT) ||
                NT_STATUS_EQUAL(status, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND)) {
index 69a0495..342f22c 100644 (file)
@@ -218,6 +218,7 @@ static NTSTATUS msrpc_name_to_sid(struct winbindd_domain *domain,
                                  const char *domain_name,
                                  const char *name,
                                  uint32_t flags,
+                                 const char **pdom_name,
                                  struct dom_sid *sid,
                                  enum lsa_SidType *type)
 {
@@ -268,6 +269,17 @@ static NTSTATUS msrpc_name_to_sid(struct winbindd_domain *domain,
 
        /* Return rid and type if lookup successful */
 
+       if (pdom_name != NULL) {
+               const char *dom_name;
+
+               dom_name = talloc_strdup(mem_ctx, domains[0]);
+               if (dom_name == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               *pdom_name = dom_name;
+       }
+
        sid_copy(sid, &sids[0]);
        *type = types[0];
 
index 1d0e8e6..56741d4 100644 (file)
@@ -131,18 +131,19 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            const char *domain_name,
                            const char *name,
                            uint32_t flags,
+                           const char **pdom_name,
                            struct dom_sid *sid,
                            enum lsa_SidType *type)
 {
        NTSTATUS result;
 
        result = msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
-                                          flags, sid, type);
+                                          flags, pdom_name, sid, type);
 
        if (reconnect_need_retry(result, domain))
                result = msrpc_methods.name_to_sid(domain, mem_ctx,
                                                   domain_name, name, flags,
-                                                  sid, type);
+                                                  pdom_name, sid, type);
 
        return result;
 }
index 0a0a14f..f774305 100644 (file)
@@ -137,18 +137,19 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            const char *domain_name,
                            const char *name,
                            uint32_t flags,
+                           const char **pdom_name,
                            struct dom_sid *sid,
                            enum lsa_SidType *type)
 {
        NTSTATUS result;
 
        result = ads_methods.name_to_sid(domain, mem_ctx, domain_name, name,
-                                        flags, sid, type);
+                                        flags, pdom_name, sid, type);
 
        if (reconnect_need_retry(result, domain)) {
                result = ads_methods.name_to_sid(domain, mem_ctx,
                                                 domain_name, name, flags,
-                                                sid, type);
+                                                pdom_name, sid, type);
        }
 
        return result;
index 81f9f98..ffbaabc 100644 (file)
@@ -247,6 +247,7 @@ NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
                         const char *domain_name,
                         const char *name,
                         uint32_t flags,
+                        const char **pdom_name,
                         struct dom_sid *sid,
                         enum lsa_SidType *type)
 {
@@ -301,6 +302,17 @@ NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
                return status;
        }
 
+       if (pdom_name != NULL) {
+               const char *dom_name;
+
+               dom_name = talloc_strdup(mem_ctx, domains[0]);
+               if (dom_name == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               *pdom_name = dom_name;
+       }
+
        sid_copy(sid, &sids[0]);
        *type = types[0];
 
index 162f1ef..a5cfe77 100644 (file)
@@ -53,6 +53,7 @@ NTSTATUS rpc_name_to_sid(TALLOC_CTX *mem_ctx,
                         const char *domain_name,
                         const char *name,
                         uint32_t flags,
+                        const char **pdom_name,
                         struct dom_sid *psid,
                         enum lsa_SidType *ptype);
 
index 35e7feb..396e2c9 100644 (file)
@@ -581,6 +581,7 @@ static NTSTATUS sam_name_to_sid(struct winbindd_domain *domain,
                                   const char *domain_name,
                                   const char *name,
                                   uint32_t flags,
+                                  const char **pdom_name,
                                   struct dom_sid *psid,
                                   enum lsa_SidType *ptype)
 {
@@ -629,6 +630,14 @@ again:
                goto done;
        }
 
+       if (pdom_name != NULL) {
+               *pdom_name = talloc_strdup(mem_ctx, dom_name);
+               if (*pdom_name == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
+       }
+
        if (psid) {
                sid_copy(psid, &sid);
        }