]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
r15306: Be consistent between rpc and ads winbind backend: let the ads backend
authorGünther Deschner <gd@samba.org>
Fri, 28 Apr 2006 14:48:22 +0000 (14:48 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:16:33 +0000 (11:16 -0500)
query the samlogon cache first as well.

Guenther
(This used to be commit aa52b11dd450ca3ec1f156e17822b1c4971ef915)

source3/nsswitch/winbindd_ads.c
source3/nsswitch/winbindd_rpc.c
source3/nsswitch/winbindd_util.c

index 336f27e6a12ba24ccda669de73e0245c6ee61f9a..ede176527365eded0f3cc6cf27dd523edb8482b9 100644 (file)
@@ -626,6 +626,12 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
        DEBUG(3,("ads: lookup_usergroups\n"));
        *p_num_groups = 0;
 
+       status = lookup_usergroups_cached(domain, mem_ctx, sid, 
+                                         p_num_groups, user_sids);
+       if (NT_STATUS_IS_OK(status)) {
+               return NT_STATUS_OK;
+       }
+
        ads = ads_cached_connection(domain);
        
        if (!ads) {
@@ -681,10 +687,12 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
 
        /* there must always be at least one group in the token, 
           unless we are talking to a buggy Win2k server */
+
        if (count == 0) {
+
                status = lookup_usergroups_alt(domain, mem_ctx, user_dn, 
-                                            &primary_group,
-                                            &num_groups, user_sids);
+                                              &primary_group,
+                                              &num_groups, user_sids);
                *p_num_groups = (uint32)num_groups;
                return status;
        }
index 669b5b923b970817ec5e0b87efc000ac83b5a6c4..22df8d4db967ed3636a92a0036b262441c234542 100644 (file)
@@ -412,7 +412,6 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
        unsigned int i;
        fstring sid_string;
        uint32 user_rid;
-       NET_USER_INFO_3 *user;
        struct rpc_pipe_client *cli;
 
        DEBUG(3,("rpc: lookup_usergroups sid=%s\n",
@@ -425,23 +424,10 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
        *user_grpsids = NULL;
 
        /* so lets see if we have a cached user_info_3 */
-       
-       if ( (user = netsamlogon_cache_get( mem_ctx, user_sid )) != NULL )
-       {
-               DEBUG(5,("lookup_usergroups: Cache lookup succeeded for %s\n", 
-                       sid_string_static(user_sid)));
-                       
-               *num_groups = user->num_groups;
-                               
-               (*user_grpsids) = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_groups);
-               for (i=0;i<(*num_groups);i++) {
-                       sid_copy(&((*user_grpsids)[i]), &domain->sid);
-                       sid_append_rid(&((*user_grpsids)[i]),
-                                      user->gids[i].g_rid);
-               }
-                               
-               SAFE_FREE(user);
-                               
+       result = lookup_usergroups_cached(domain, mem_ctx, user_sid, 
+                                         num_groups, user_grpsids);
+
+       if (NT_STATUS_IS_OK(result)) {
                return NT_STATUS_OK;
        }
 
index d64345a36f3a8f127196eb2b2d5222e910d2a32a..82fd1e128b631f47f4c4ec38962b7039e18f95a2 100644 (file)
@@ -1232,3 +1232,49 @@ void winbindd_flush_nscd_cache(void)
 #endif
 }
 
+NTSTATUS lookup_usergroups_cached(struct winbindd_domain *domain,
+                                 TALLOC_CTX *mem_ctx,
+                                 const DOM_SID *user_sid,
+                                 uint32 *p_num_groups, DOM_SID **user_sids)
+{
+       NET_USER_INFO_3 *info3 = NULL;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+       int i;
+       size_t num_groups = 0;
+       DOM_SID group_sid, primary_group;
+       
+       DEBUG(3,(": lookup_usergroups_cached\n"));
+       
+       *user_sids = NULL;
+       num_groups = 0;
+
+       info3 = netsamlogon_cache_get(mem_ctx, user_sid);
+
+       if (info3 == NULL) {
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       }
+
+       if (info3->num_groups == 0) {
+               SAFE_FREE(info3);
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+       
+       /* always add the primary group to the sid array */
+       sid_compose(&primary_group, &info3->dom_sid.sid, info3->user_rid);
+       
+       add_sid_to_array(mem_ctx, &primary_group, user_sids, &num_groups);
+
+       for (i=0; i<info3->num_groups; i++) {
+               sid_copy(&group_sid, &info3->dom_sid.sid);
+               sid_append_rid(&group_sid, info3->gids[i].g_rid);
+
+               add_sid_to_array(mem_ctx, &group_sid, user_sids,
+                                &num_groups);
+       }
+
+       SAFE_FREE(info3);
+       *p_num_groups = num_groups;
+       status = (user_sids != NULL) ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
+               
+       return status;
+}