summaryrefslogtreecommitdiff
path: root/source3/winbindd/idmap_cache.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-07-13 12:07:40 +0200
committerVolker Lendecke <vl@samba.org>2008-08-12 11:28:29 +0200
commit340ab6a256802a22c11b7f707748397249075b65 (patch)
tree20d297829eb3e27c6c80ad537712627ae845a4ef /source3/winbindd/idmap_cache.c
parent8d4bd2d960ebf11bc85891210c6f72a371e08417 (diff)
downloadsamba-340ab6a256802a22c11b7f707748397249075b65.tar.gz
samba-340ab6a256802a22c11b7f707748397249075b65.tar.bz2
samba-340ab6a256802a22c11b7f707748397249075b65.zip
idmap rewrite
(This used to be commit 30a180f2fce8cf6a3e5548f6bba453272ba70b33)
Diffstat (limited to 'source3/winbindd/idmap_cache.c')
-rw-r--r--source3/winbindd/idmap_cache.c38
1 files changed, 26 insertions, 12 deletions
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);
}
}