diff options
author | Volker Lendecke <vl@samba.org> | 2008-07-07 22:09:39 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-08-12 11:28:28 +0200 |
commit | 08f7c2d0fc69f58cbe4dc077f609818d3afe07cd (patch) | |
tree | fcc41b2a55273081a4c2bfb416f95a3ebed7cc92 /source3/winbindd/idmap_cache.c | |
parent | 0f3de7f93e6c42d3aee6501641490004ba953e75 (diff) | |
download | samba-08f7c2d0fc69f58cbe4dc077f609818d3afe07cd.tar.gz samba-08f7c2d0fc69f58cbe4dc077f609818d3afe07cd.tar.bz2 samba-08f7c2d0fc69f58cbe4dc077f609818d3afe07cd.zip |
Move the uid2sid cache to the parent winbind process
(This used to be commit 6e885aeabba2265a06b726f567cb14dde12c8ccb)
Diffstat (limited to 'source3/winbindd/idmap_cache.c')
-rw-r--r-- | source3/winbindd/idmap_cache.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/source3/winbindd/idmap_cache.c b/source3/winbindd/idmap_cache.c index f7e1d4e6d1..027ce3b619 100644 --- a/source3/winbindd/idmap_cache.c +++ b/source3/winbindd/idmap_cache.c @@ -521,3 +521,83 @@ done: return ret; } +bool idmap_cache_find_sid2uid(const struct dom_sid *sid, uid_t *puid, + bool *expired) +{ + fstring sidstr; + char *key; + char *value; + char *endptr; + time_t timeout; + uid_t uid; + bool ret; + + key = talloc_asprintf(talloc_tos(), "IDMAP/SID2UID/%s", + sid_to_fstring(sidstr, sid)); + if (key == NULL) { + return false; + } + ret = gencache_get(key, &value, &timeout); + TALLOC_FREE(key); + if (!ret) { + return false; + } + uid = strtol(value, &endptr, 10); + ret = (*endptr == '\0'); + SAFE_FREE(value); + if (ret) { + *puid = uid; + *expired = (timeout <= time(NULL)); + } + return ret; +} + +bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) +{ + char *key; + char *value; + time_t timeout; + bool ret; + + key = talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid); + if (key == NULL) { + return false; + } + ret = gencache_get(key, &value, &timeout); + TALLOC_FREE(key); + if (!ret) { + return false; + } + ZERO_STRUCTP(sid); + ret = string_to_sid(sid, value); + SAFE_FREE(value); + if (ret) { + *expired = (timeout <= time(NULL)); + } + return ret; +} + +void idmap_cache_set_sid2uid(const struct dom_sid *sid, uid_t uid) +{ + time_t now = time(NULL); + time_t timeout; + fstring sidstr, key, value; + + if (!is_null_sid(sid)) { + fstr_sprintf(key, "IDMAP/SID2UID/%s", + sid_to_fstring(sidstr, sid)); + fstr_sprintf(value, "%d", (int)uid); + timeout = (uid == -1) + ? lp_idmap_negative_cache_time() + : lp_idmap_cache_time(); + gencache_set(key, value, now + timeout); + } + 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(); + gencache_set(key, value, now + timeout); + } +} |