summaryrefslogtreecommitdiff
path: root/source3/lib/util_pw.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/util_pw.c')
-rw-r--r--source3/lib/util_pw.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c
index c0d37f1094..b0baa12c3e 100644
--- a/source3/lib/util_pw.c
+++ b/source3/lib/util_pw.c
@@ -44,30 +44,28 @@ void flush_pwnam_cache(void)
struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
{
- struct passwd *temp, *cached;
+ struct passwd *pw, *for_cache;
- temp = (struct passwd *)memcache_lookup_talloc(
+ pw = (struct passwd *)memcache_lookup_talloc(
NULL, GETPWNAM_CACHE, data_blob_string_const_null(name));
- if (temp != NULL) {
- return tcopy_passwd(mem_ctx, temp);
+ if (pw != NULL) {
+ return tcopy_passwd(mem_ctx, pw);
}
- temp = sys_getpwnam(name);
- if (temp == NULL) {
+ pw = sys_getpwnam(name);
+ if (pw == NULL) {
return NULL;
}
- cached = tcopy_passwd(NULL, temp);
- if (cached == NULL) {
- /*
- * Just don't add this into the cache, ignore the failure
- */
- return temp;
+ for_cache = tcopy_passwd(talloc_autofree_context(), pw);
+ if (for_cache == NULL) {
+ return NULL;
}
- memcache_add_talloc(NULL, GETPWNAM_CACHE, data_blob_string_const_null(name),
- cached);
- return tcopy_passwd(mem_ctx, temp);
+ memcache_add_talloc(NULL, GETPWNAM_CACHE,
+ data_blob_string_const_null(name), &for_cache);
+
+ return tcopy_passwd(mem_ctx, pw);
}
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)