diff options
| author | Volker Lendecke <vl@samba.org> | 2013-12-04 15:37:21 +0000 |
|---|---|---|
| committer | Michael Adam <obnox@samba.org> | 2013-12-05 03:06:10 +0100 |
| commit | 97e8b56250f30e73ad4bdcae292fe5c0df65e69a (patch) | |
| tree | 0aee586a68cd7aa9590376b50bcf5c3e06c5c96c /source3/lib | |
| parent | 89013af15aa45311510318b517de8986580f4e2f (diff) | |
| download | samba-97e8b56250f30e73ad4bdcae292fe5c0df65e69a.tar.gz samba-97e8b56250f30e73ad4bdcae292fe5c0df65e69a.tar.xz samba-97e8b56250f30e73ad4bdcae292fe5c0df65e69a.zip | |
idmap_cache: Use gencache_parse
This avoids a few tallocs and brings down user CPU a bit more
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Autobuild-User(master): Michael Adam <obnox@samba.org>
Autobuild-Date(master): Thu Dec 5 03:06:10 CET 2013 on sn-devel-104
Diffstat (limited to 'source3/lib')
| -rw-r--r-- | source3/lib/idmap_cache.c | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/source3/lib/idmap_cache.c b/source3/lib/idmap_cache.c index 4564bebfa3..884417193f 100644 --- a/source3/lib/idmap_cache.c +++ b/source3/lib/idmap_cache.c @@ -188,6 +188,39 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid, return true; } +struct idmap_cache_xid2sid_state { + struct dom_sid *sid; + bool *expired; + bool ret; +}; + +static void idmap_cache_xid2sid_parser(time_t timeout, DATA_BLOB blob, + void *private_data) +{ + struct idmap_cache_xid2sid_state *state = + (struct idmap_cache_xid2sid_state *)private_data; + char *value; + + ZERO_STRUCTP(state->sid); + state->ret = false; + + if ((blob.length == 0) || (blob.data[blob.length-1] != 0)) { + /* + * Not a string, can't be a valid mapping + */ + return; + } + + value = (char *)blob.data; + + if (value[0] != '-') { + state->ret = string_to_sid(state->sid, value); + } + if (state->ret) { + *state->expired = (timeout <= time(NULL)); + } +} + /** * Find a uid2sid mapping * @param[in] uid the uid to map @@ -201,25 +234,16 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid, bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) { fstring key; - char *value; - time_t timeout; - bool ret = true; + struct idmap_cache_xid2sid_state state; fstr_sprintf(key, "IDMAP/UID2SID/%d", (int)uid); - ret = gencache_get(key, talloc_tos(), &value, &timeout); - if (!ret) { - return false; - } - ZERO_STRUCTP(sid); - if (value[0] != '-') { - ret = string_to_sid(sid, value); - } - TALLOC_FREE(value); - if (ret) { - *expired = (timeout <= time(NULL)); - } - return ret; + state.sid = sid; + state.expired = expired; + state.ret = false; + + gencache_parse(key, idmap_cache_xid2sid_parser, &state); + return state.ret; } /** @@ -235,25 +259,16 @@ bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired) { fstring key; - char *value; - time_t timeout; - bool ret = true; + struct idmap_cache_xid2sid_state state; fstr_sprintf(key, "IDMAP/GID2SID/%d", (int)gid); - ret = gencache_get(key, talloc_tos(), &value, &timeout); - if (!ret) { - return false; - } - ZERO_STRUCTP(sid); - if (value[0] != '-') { - ret = string_to_sid(sid, value); - } - TALLOC_FREE(value); - if (ret) { - *expired = (timeout <= time(NULL)); - } - return ret; + state.sid = sid; + state.expired = expired; + state.ret = false; + + gencache_parse(key, idmap_cache_xid2sid_parser, &state); + return state.ret; } /** |
