s3:winbind: Make wcache_query_user externally visible
authorVolker Lendecke <vl@samba.org>
Sat, 1 Aug 2009 14:20:13 +0000 (10:20 -0400)
committerVolker Lendecke <vl@samba.org>
Wed, 5 Aug 2009 07:21:22 +0000 (03:21 -0400)
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_proto.h

index 87594542cf47d7a0224d1367a90bdb6d035770fe..270b9f310d03f80ff6d18671a44c9674d5e6288f 100644 (file)
@@ -1939,38 +1939,46 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain,
        return result;
 }
 
-/* Lookup user information from a rid */
-static NTSTATUS query_user(struct winbindd_domain *domain, 
-                          TALLOC_CTX *mem_ctx, 
-                          const DOM_SID *user_sid, 
-                          WINBIND_USERINFO *info)
+NTSTATUS wcache_query_user(struct winbindd_domain *domain,
+                          TALLOC_CTX *mem_ctx,
+                          const struct dom_sid *user_sid,
+                          struct winbind_userinfo *info)
 {
        struct winbind_cache *cache = get_cache(domain);
        struct cache_entry *centry = NULL;
        NTSTATUS status;
-       fstring tmp;
+       char *sid_string;
 
-       if (!cache->tdb)
-               goto do_query;
+       if (cache->tdb == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
 
-       centry = wcache_fetch(cache, domain, "U/%s",
-                             sid_to_fstring(tmp, user_sid));
+       sid_string = sid_string_tos(user_sid);
+       if (sid_string == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
-       /* If we have an access denied cache entry and a cached info3 in the
-           samlogon cache then do a query.  This will force the rpc back end
-           to return the info3 data. */
+       centry = wcache_fetch(cache, domain, "U/%s", sid_string);
+       TALLOC_FREE(sid_string);
+       if (centry == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
 
-       if (NT_STATUS_V(domain->last_status) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED) &&
+       /*
+        * If we have an access denied cache entry and a cached info3
+        * in the samlogon cache then do a query.  This will force the
+        * rpc back end to return the info3 data.
+        */
+
+       if (NT_STATUS_EQUAL(domain->last_status, NT_STATUS_ACCESS_DENIED) &&
            netsamlogon_cache_have(user_sid)) {
-               DEBUG(10, ("query_user: cached access denied and have cached info3\n"));
+               DEBUG(10, ("query_user: cached access denied and have cached "
+                          "info3\n"));
                domain->last_status = NT_STATUS_OK;
                centry_free(centry);
-               goto do_query;
+               return NT_STATUS_NOT_FOUND;
        }
 
-       if (!centry)
-               goto do_query;
-
        /* if status is not ok then this is a negative hit
           and the rest of the data doesn't matter */
        status = centry->status;
@@ -1984,13 +1992,26 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
                centry_sid(centry, &info->group_sid);
        }
 
-       DEBUG(10,("query_user: [Cached] - cached info for domain %s status: %s\n",
-               domain->name, nt_errstr(status) ));
+       DEBUG(10,("query_user: [Cached] - cached info for domain %s status: "
+                 "%s\n", domain->name, nt_errstr(status) ));
 
        centry_free(centry);
        return status;
+}
+
+/* Lookup user information from a rid */
+static NTSTATUS query_user(struct winbindd_domain *domain,
+                          TALLOC_CTX *mem_ctx,
+                          const DOM_SID *user_sid,
+                          WINBIND_USERINFO *info)
+{
+       NTSTATUS status;
+
+       status = wcache_query_user(domain, mem_ctx, user_sid, info);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               return status;
+       }
 
-do_query:
        ZERO_STRUCTP(info);
 
        /* Return status value returned by seq number check */
index 38d5200aae94ac0d2b4f1e244860555df4dc8727..1f0d5b5d5bf10d9b1f25701c44c23d9a6bc6f10e 100644 (file)
@@ -171,6 +171,10 @@ NTSTATUS wcache_name_to_sid(struct winbindd_domain *domain,
                            const char *name,
                            struct dom_sid *sid,
                            enum lsa_SidType *type);
+NTSTATUS wcache_query_user(struct winbindd_domain *domain,
+                          TALLOC_CTX *mem_ctx,
+                          const struct dom_sid *user_sid,
+                          struct winbind_userinfo *info);
 void wcache_flush_cache(void);
 NTSTATUS wcache_count_cached_creds(struct winbindd_domain *domain, int *count);
 NTSTATUS wcache_remove_oldest_cached_creds(struct winbindd_domain *domain, const DOM_SID *sid) ;