From 340ab6a256802a22c11b7f707748397249075b65 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 13 Jul 2008 12:07:40 +0200 Subject: idmap rewrite (This used to be commit 30a180f2fce8cf6a3e5548f6bba453272ba70b33) --- source3/winbindd/idmap_cache.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'source3/winbindd/idmap_cache.c') diff --git a/source3/winbindd/idmap_cache.c b/source3/winbindd/idmap_cache.c index 1e82314440..b818d0dafb 100644 --- a/source3/winbindd/idmap_cache.c +++ b/source3/winbindd/idmap_cache.c @@ -59,7 +59,7 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) char *key; char *value; time_t timeout; - bool ret; + bool ret = true; key = talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid); if (key == NULL) { @@ -71,7 +71,9 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) return false; } ZERO_STRUCTP(sid); - ret = string_to_sid(sid, value); + if (value[0] != '-') { + ret = string_to_sid(sid, value); + } SAFE_FREE(value); if (ret) { *expired = (timeout <= time(NULL)); @@ -96,10 +98,15 @@ void idmap_cache_set_sid2uid(const struct dom_sid *sid, uid_t uid) } if (uid != -1) { fstr_sprintf(key, "IDMAP/UID2SID/%d", (int)uid); - sid_to_fstring(value, sid); - timeout = is_null_sid(sid) - ? lp_idmap_negative_cache_time() - : lp_idmap_cache_time(); + if (is_null_sid(sid)) { + /* negative uid mapping */ + fstrcpy(value, "-"); + timeout = lp_idmap_negative_cache_time(); + } + else { + sid_to_fstring(value, sid); + timeout = lp_idmap_cache_time(); + } gencache_set(key, value, now + timeout); } } @@ -140,7 +147,7 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) char *key; char *value; time_t timeout; - bool ret; + bool ret = true; key = talloc_asprintf(talloc_tos(), "IDMAP/GID2SID/%d", (int)gid); if (key == NULL) { @@ -152,7 +159,9 @@ bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) return false; } ZERO_STRUCTP(sid); - ret = string_to_sid(sid, value); + if (value[0] != '-') { + ret = string_to_sid(sid, value); + } SAFE_FREE(value); if (ret) { *expired = (timeout <= time(NULL)); @@ -177,10 +186,15 @@ void idmap_cache_set_sid2gid(const struct dom_sid *sid, gid_t gid) } if (gid != -1) { fstr_sprintf(key, "IDMAP/GID2SID/%d", (int)gid); - sid_to_fstring(value, sid); - timeout = is_null_sid(sid) - ? lp_idmap_negative_cache_time() - : lp_idmap_cache_time(); + if (is_null_sid(sid)) { + /* negative gid mapping */ + fstrcpy(value, "-"); + timeout = lp_idmap_negative_cache_time(); + } + else { + sid_to_fstring(value, sid); + timeout = lp_idmap_cache_time(); + } gencache_set(key, value, now + timeout); } } -- cgit