From 2d6589fb0243cb2b73615de1aaea38a3059c08ed Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 1 Aug 2009 12:16:11 +0200 Subject: s3:winbind: Make wcache_sid_to_name externally visible --- source3/winbindd/winbindd_cache.c | 85 ++++++++++++++++++++------------------- source3/winbindd/winbindd_proto.h | 6 +++ 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c index bec2a714c8..f273f2c8d6 100644 --- a/source3/winbindd/winbindd_cache.c +++ b/source3/winbindd/winbindd_cache.c @@ -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); } diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index f9ef776c5d..182534a1fa 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -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); -- cgit