Refactor 9b78af1f: Fix lookupname recursion
authorVolker Lendecke <vl@samba.org>
Sun, 2 Aug 2009 08:43:05 +0000 (10:43 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 2 Aug 2009 09:24:48 +0000 (11:24 +0200)
Pass a "flags" argument instead of the original winbind command down the
name_to_sid chain. This way we are independent of the winbind commands and
can take the decision at a much higher level

source3/winbindd/winbindd.h
source3/winbindd/winbindd_ads.c
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_passdb.c
source3/winbindd/winbindd_reconnect.c
source3/winbindd/winbindd_rpc.c
source3/winbindd/winbindd_util.c

index 732b9a3614a8698dab7be1ecb6f7895fb53c2ed1..64fb8851df77de96c6f8250ca67570fe8c2004a8 100644 (file)
@@ -247,9 +247,9 @@ struct winbindd_methods {
        /* convert one user or group name to a sid */
        NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
                                TALLOC_CTX *mem_ctx,
-                               enum winbindd_cmd orig_cmd,
                                const char *domain_name,
                                const char *name,
+                               uint32_t flags,
                                DOM_SID *sid,
                                enum lsa_SidType *type);
 
index 08afb46674c48c595f4f024370a44c4672586fb9..137a88505ccf1bb144109bdbcb707880aaf785f0 100644 (file)
@@ -404,14 +404,14 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
 /* convert a single name to a sid in a domain - use rpc methods */
 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            TALLOC_CTX *mem_ctx,
-                           enum winbindd_cmd orig_cmd,
                            const char *domain_name,
                            const char *name,
+                           uint32_t flags,
                            DOM_SID *sid,
                            enum lsa_SidType *type)
 {
-       return reconnect_methods.name_to_sid(domain, mem_ctx, orig_cmd,
-                                            domain_name, name,
+       return reconnect_methods.name_to_sid(domain, mem_ctx,
+                                            domain_name, name, flags,
                                             sid, type);
 }
 
index 6c14f9d76a4d2976baaed11f780d27ea2ac36c97..b8872a18d4bf6d7f0f0d196be96dbb7bf53d2bf6 100644 (file)
@@ -1608,9 +1608,9 @@ skip_save:
 /* convert a single name to a sid in a domain */
 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            TALLOC_CTX *mem_ctx,
-                           enum winbindd_cmd orig_cmd,
                            const char *domain_name,
                            const char *name,
+                           uint32_t flags,
                            DOM_SID *sid,
                            enum lsa_SidType *type)
 {
@@ -1657,8 +1657,8 @@ do_query:
        DEBUG(10,("name_to_sid: [Cached] - doing backend query for name for domain %s\n",
                domain->name ));
 
-       status = domain->backend->name_to_sid(domain, mem_ctx, orig_cmd, 
-                                             domain_name, name, sid, type);
+       status = domain->backend->name_to_sid(domain, mem_ctx, domain_name,
+                                             name, flags, sid, type);
 
        /* and save it */
        refresh_sequence_number(domain, false);
index b959bfc9ad0d8cb6da308bec9525f8d534592988..b6e572d19714844f08f4f45aeec40875c6ad641a 100644 (file)
@@ -88,25 +88,15 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
 /* convert a single name to a sid in a domain */
 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            TALLOC_CTX *mem_ctx,
-                           enum winbindd_cmd original_cmd,
                            const char *domain_name,
                            const char *name,
+                           uint32_t flags,
                            DOM_SID *sid,
                            enum lsa_SidType *type)
 {
        const char *fullname;
-       uint32 flags = LOOKUP_NAME_ALL;
-
-       switch ( original_cmd ) {
-       case WINBINDD_LOOKUPNAME:
-               /* This call is ok */
-               break;
-       default:
-               /* Avoid any NSS calls in the lookup_name by default */
-               flags |= LOOKUP_NAME_NO_NSS;
-               DEBUG(10,("winbindd_passdb: limiting name_to_sid() to explicit mappings\n"));
-               break;
-       }
+
+       flags |= LOOKUP_NAME_ALL;
 
        if (domain_name && domain_name[0] && strchr_m(name, '\\') == NULL) {
                fullname = talloc_asprintf(mem_ctx, "%s\\%s",
index 25debccc5a64a58f9237b262a29bbbfcaeba31ef..1d71a754586e4e3c9a48a567f9ee03715a53fc1f 100644 (file)
@@ -83,21 +83,20 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
 /* convert a single name to a sid in a domain */
 static NTSTATUS name_to_sid(struct winbindd_domain *domain,
                            TALLOC_CTX *mem_ctx,
-                           enum winbindd_cmd orig_cmd,
                            const char *domain_name,
                            const char *name,
+                           uint32_t flags,
                            DOM_SID *sid,
                            enum lsa_SidType *type)
 {
        NTSTATUS result;
 
-       result = msrpc_methods.name_to_sid(domain, mem_ctx, orig_cmd,
-                                          domain_name, name,
-                                          sid, type);
+       result = msrpc_methods.name_to_sid(domain, mem_ctx, domain_name, name,
+                                          flags, sid, type);
 
        if (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))
-               result = msrpc_methods.name_to_sid(domain, mem_ctx, orig_cmd,
-                                                  domain_name, name,
+               result = msrpc_methods.name_to_sid(domain, mem_ctx,
+                                                  domain_name, name, flags,
                                                   sid, type);
 
        return result;
index 50ccbae6b226315d04ebcad3cafdfd0ee0017d6c..17ffffe5da27b86a9c850c8ff881d247bc1bc663 100644 (file)
@@ -267,9 +267,9 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain,
 /* convert a single name to a sid in a domain */
 static NTSTATUS msrpc_name_to_sid(struct winbindd_domain *domain,
                                  TALLOC_CTX *mem_ctx,
-                                 enum winbindd_cmd original_cmd,
                                  const char *domain_name,
                                  const char *name,
+                                 uint32_t flags,
                                  DOM_SID *sid,
                                  enum lsa_SidType *type)
 {
index 99b4542f0bdf2199cdd8e74cdb0099f0ed704d15..c564ef9f51ee69330bcd24ef810789861b024c4d 100644 (file)
@@ -886,9 +886,14 @@ bool winbindd_lookup_sid_by_name(TALLOC_CTX *mem_ctx,
 {
        NTSTATUS result;
 
-       /* Lookup name */
-       result = domain->methods->name_to_sid(domain, mem_ctx, orig_cmd,
-                                             domain_name, name, sid, type);
+       /*
+        * For all but LOOKUPNAME we have to avoid nss calls to avoid
+        * recursion
+        */
+       result = domain->methods->name_to_sid(
+               domain, mem_ctx, domain_name, name,
+               orig_cmd == WINBINDD_LOOKUPNAME ? 0 : LOOKUP_NAME_NO_NSS,
+               sid, type);
 
        /* Return sid and type if lookup successful */
        if (!NT_STATUS_IS_OK(result)) {