s3:winbind: Make wcache_sid_to_name externally visible
authorVolker Lendecke <vl@samba.org>
Sat, 1 Aug 2009 10:16:11 +0000 (12:16 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 5 Aug 2009 07:21:19 +0000 (03:21 -0400)
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_proto.h

index bec2a714c80a8c18c318025fcb8ea927e4f344d3..f273f2c8d644f47293f7b923679276e764724a0d 100644 (file)
@@ -1678,42 +1678,65 @@ do_query:
        return status;
 }
 
-/* convert a sid to a user or group name. The sid is guaranteed to be in the domain
-   given */
-static NTSTATUS sid_to_name(struct winbindd_domain *domain,
+NTSTATUS wcache_sid_to_name(struct winbindd_domain *domain,
+                           const struct dom_sid *sid,
                            TALLOC_CTX *mem_ctx,
-                           const DOM_SID *sid,
                            char **domain_name,
                            char **name,
                            enum lsa_SidType *type)
 {
        struct winbind_cache *cache = get_cache(domain);
-       struct cache_entry *centry = NULL;
+       struct cache_entry *centry;
+       char *sid_string;
        NTSTATUS status;
-       fstring sid_string;
 
-       if (!cache->tdb)
-               goto do_query;
+       if (cache->tdb == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
 
-       centry = wcache_fetch(cache, domain, "SN/%s",
-                             sid_to_fstring(sid_string, sid));
-       if (!centry)
-               goto do_query;
+       sid_string = sid_string_tos(sid);
+       if (sid_string == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
-       status = centry->status;
-       if (NT_STATUS_IS_OK(status)) {
+       centry = wcache_fetch(cache, domain, "SN/%s", sid_string);
+       TALLOC_FREE(sid_string);
+       if (centry == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
+
+       if (NT_STATUS_IS_OK(centry->status)) {
                *type = (enum lsa_SidType)centry_uint32(centry);
                *domain_name = centry_string(centry, mem_ctx);
                *name = centry_string(centry, mem_ctx);
        }
 
-       DEBUG(10,("sid_to_name: [Cached] - cached name for domain %s status: %s\n",
-               domain->name, nt_errstr(status) ));
-
+       status = centry->status;
        centry_free(centry);
+
+       DEBUG(10,("sid_to_name: [Cached] - cached name for domain %s status: "
+                 "%s\n", domain->name, nt_errstr(status) ));
+
        return status;
+}
+
+/* convert a sid to a user or group name. The sid is guaranteed to be in the domain
+   given */
+static NTSTATUS sid_to_name(struct winbindd_domain *domain,
+                           TALLOC_CTX *mem_ctx,
+                           const DOM_SID *sid,
+                           char **domain_name,
+                           char **name,
+                           enum lsa_SidType *type)
+{
+       NTSTATUS status;
+
+       status = wcache_sid_to_name(domain, sid, mem_ctx, domain_name, name,
+                                   type);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               return status;
+       }
 
-do_query:
        *name = NULL;
        *domain_name = NULL;
 
@@ -2625,36 +2648,14 @@ bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
                       enum lsa_SidType *type)
 {
        struct winbindd_domain *domain;
-       struct winbind_cache *cache;
-       struct cache_entry *centry = NULL;
        NTSTATUS status;
-       fstring tmp;
 
        domain = find_lookup_domain_from_sid(sid);
        if (domain == NULL) {
                return false;
        }
-
-       cache = get_cache(domain);
-
-       if (cache->tdb == NULL) {
-               return false;
-       }
-
-       centry = wcache_fetch(cache, domain, "SN/%s",
-                             sid_to_fstring(tmp, sid));
-       if (centry == NULL) {
-               return false;
-       }
-
-       if (NT_STATUS_IS_OK(centry->status)) {
-               *type = (enum lsa_SidType)centry_uint32(centry);
-               *domain_name = centry_string(centry, mem_ctx);
-               *name = centry_string(centry, mem_ctx);
-       }
-
-       status = centry->status;
-       centry_free(centry);
+       status = wcache_sid_to_name(domain, sid, mem_ctx, domain_name, name,
+                                   type);
        return NT_STATUS_IS_OK(status);
 }
 
index f9ef776c5dc9ba913fead574f611301b9ebcdfcf..182534a1fa6fb7b7ef9f52794000ebc51f6068a9 100644 (file)
@@ -149,6 +149,12 @@ bool wcache_invalidate_cache(void);
 bool init_wcache(void);
 bool initialize_winbindd_cache(void);
 void close_winbindd_cache(void);
+NTSTATUS wcache_sid_to_name(struct winbindd_domain *domain,
+                           const struct dom_sid *sid,
+                           TALLOC_CTX *mem_ctx,
+                           char **domain_name,
+                           char **name,
+                           enum lsa_SidType *type);
 bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
                       char **domain_name, char **name,
                       enum lsa_SidType *type);