Store the key for a name to sid cache entry in upper case rather than
authorTim Potter <tpot@samba.org>
Tue, 4 Jun 2002 03:44:04 +0000 (03:44 +0000)
committerTim Potter <tpot@samba.org>
Tue, 4 Jun 2002 03:44:04 +0000 (03:44 +0000)
whatever case the request was made in.  This gets rid of duplicate
cache entries.

Also when doing a sid to name, prime the cache with the name to sid
mapping result.  We can't do the reverse as we don't know the correct
case of the name to store in the cache.

source/nsswitch/winbindd_cache.c

index 282a37230b0349043c0a68f605d93c7a15671d2c..407bd60f8a6280a1eae302fcc826fa6d9b43c864 100644 (file)
@@ -423,6 +423,7 @@ static void wcache_save_name_to_sid(struct winbindd_domain *domain, NTSTATUS sta
 {
        struct cache_entry *centry;
        uint32 len;
+       fstring uname;
 
        centry = centry_start(domain, status);
        if (!centry) return;
@@ -431,7 +432,9 @@ static void wcache_save_name_to_sid(struct winbindd_domain *domain, NTSTATUS sta
        centry_put_uint32(centry, type);
        sid_linearize(centry->data + centry->ofs, len, sid);
        centry->ofs += len;
-       centry_end(centry, "NS/%s/%s", domain->name, name);
+       fstrcpy(uname, name);
+       strupper(uname);
+       centry_end(centry, "NS/%s/%s", domain->name, uname);
        centry_free(centry);
 }
 
@@ -610,10 +613,13 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
        struct winbind_cache *cache = get_cache(domain);
        struct cache_entry *centry = NULL;
        NTSTATUS status;
+       fstring uname;
 
        if (!cache->tdb) goto do_query;
 
-       centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, name);
+       fstrcpy(uname, name);
+       strupper(uname);
+       centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, uname);
        if (!centry) goto do_query;
        *type = centry_uint32(centry);
        sid_parse(centry->data + centry->ofs, centry->len - centry->ofs, sid);
@@ -633,6 +639,9 @@ do_query:
        /* and save it */
        wcache_save_name_to_sid(domain, status, name, sid, *type);
 
+       /* We can't save the sid to name mapping as we don't know the
+          correct case of the name without looking it up */
+
        return status;
 }
 
@@ -674,6 +683,7 @@ do_query:
        /* and save it */
        refresh_sequence_number(domain, True);
        wcache_save_sid_to_name(domain, status, sid, *name, *type, rid);
+       wcache_save_name_to_sid(domain, status, *name, sid, *type);
 
        return status;
 }
@@ -891,5 +901,3 @@ struct winbindd_methods cache_methods = {
        trusted_domains,
        domain_sid
 };
-
-