diff options
author | Volker Lendecke <vl@samba.org> | 2008-07-11 13:58:31 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-08-12 11:28:28 +0200 |
commit | 1bdbe772ada5aeb1eeb98e78759ae7235d098085 (patch) | |
tree | 1ad7f7953e2ee6b83a372a982d88c07e07727473 /source3/winbindd/idmap_cache.c | |
parent | 08f7c2d0fc69f58cbe4dc077f609818d3afe07cd (diff) | |
download | samba-1bdbe772ada5aeb1eeb98e78759ae7235d098085.tar.gz samba-1bdbe772ada5aeb1eeb98e78759ae7235d098085.tar.bz2 samba-1bdbe772ada5aeb1eeb98e78759ae7235d098085.zip |
Move the gid2sid cache to the parent winbind process
(This used to be commit a86a6835e2737fdbdf1f36bcd594d4b01a60acb9)
Diffstat (limited to 'source3/winbindd/idmap_cache.c')
-rw-r--r-- | source3/winbindd/idmap_cache.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/source3/winbindd/idmap_cache.c b/source3/winbindd/idmap_cache.c index 027ce3b619..e54d02784f 100644 --- a/source3/winbindd/idmap_cache.c +++ b/source3/winbindd/idmap_cache.c @@ -601,3 +601,84 @@ void idmap_cache_set_sid2uid(const struct dom_sid *sid, uid_t uid) gencache_set(key, value, now + timeout); } } + +bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid, + bool *expired) +{ + fstring sidstr; + char *key; + char *value; + char *endptr; + time_t timeout; + gid_t gid; + bool ret; + + key = talloc_asprintf(talloc_tos(), "IDMAP/SID2GID/%s", + sid_to_fstring(sidstr, sid)); + if (key == NULL) { + return false; + } + ret = gencache_get(key, &value, &timeout); + TALLOC_FREE(key); + if (!ret) { + return false; + } + gid = strtol(value, &endptr, 10); + ret = (*endptr == '\0'); + SAFE_FREE(value); + if (ret) { + *pgid = gid; + *expired = (timeout <= time(NULL)); + } + return ret; +} + +bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) +{ + char *key; + char *value; + time_t timeout; + bool ret; + + key = talloc_asprintf(talloc_tos(), "IDMAP/GID2SID/%d", (int)gid); + 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_sid2gid(const struct dom_sid *sid, gid_t gid) +{ + time_t now = time(NULL); + time_t timeout; + fstring sidstr, key, value; + + if (!is_null_sid(sid)) { + fstr_sprintf(key, "IDMAP/SID2GID/%s", + sid_to_fstring(sidstr, sid)); + fstr_sprintf(value, "%d", (int)gid); + timeout = (gid == -1) + ? lp_idmap_negative_cache_time() + : lp_idmap_cache_time(); + gencache_set(key, value, now + timeout); + } + 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(); + gencache_set(key, value, now + timeout); + } +} |