diff options
author | Simo Sorce <simo@redhat.com> | 2012-01-03 00:43:58 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-03-19 09:45:25 -0400 |
commit | c3ef027218fe9a7d16a70ca9d2f53e3d995e369f (patch) | |
tree | 4bb77a6725d882a17c6583d5efeadde12715f5b5 /src/responder/nss/nsssrv_mmap_cache.c | |
parent | 1171986bdc3011555c5b62a9d9ee9f7481f48cdc (diff) | |
download | sssd-c3ef027218fe9a7d16a70ca9d2f53e3d995e369f.tar.gz sssd-c3ef027218fe9a7d16a70ca9d2f53e3d995e369f.tar.bz2 sssd-c3ef027218fe9a7d16a70ca9d2f53e3d995e369f.zip |
nsssrv: add handling of memory cache group map
Diffstat (limited to 'src/responder/nss/nsssrv_mmap_cache.c')
-rw-r--r-- | src/responder/nss/nsssrv_mmap_cache.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c index d1f639fd..18fc8b1c 100644 --- a/src/responder/nss/nsssrv_mmap_cache.c +++ b/src/responder/nss/nsssrv_mmap_cache.c @@ -424,6 +424,76 @@ errno_t sss_mmap_cache_pw_store(struct sss_mc_ctx *mcc, /*************************************************************************** + * group map + ***************************************************************************/ + +int sss_mmap_cache_gr_store(struct sss_mc_ctx *mcc, + struct sized_string *name, + struct sized_string *pw, + gid_t gid, size_t memnum, + char *membuf, size_t memsize) +{ + struct sss_mc_rec *rec; + struct sss_mc_grp_data *data; + struct sized_string gidkey; + char gidstr[11]; + size_t data_len; + size_t rec_len; + size_t pos; + int ret; + + ret = snprintf(gidstr, 11, "%ld", (long)gid); + if (ret > 10) { + return EINVAL; + } + to_sized_string(&gidkey, gidstr); + + data_len = name->len + pw->len + memsize; + rec_len = sizeof(struct sss_mc_rec) + + sizeof(struct sss_mc_grp_data) + + data_len; + if (rec_len > mcc->dt_size) { + return ENOMEM; + } + + rec = sss_mc_get_record(mcc, rec_len, name); + + data = (struct sss_mc_grp_data *)rec->data; + pos = 0; + + MC_RAISE_BARRIER(rec); + + /* header */ + rec->len = rec_len; + rec->expire = time(NULL) + mcc->valid_time_slot; + rec->hash1 = sss_mc_hash(mcc, name->str, name->len); + rec->hash2 = sss_mc_hash(mcc, gidkey.str, gidkey.len); + + /* group struct */ + data->name = MC_PTR_DIFF(data->strs, data); + data->gid = gid; + data->members = memnum; + data->strs_len = data_len; + memcpy(&data->strs[pos], name->str, name->len); + pos += name->len; + memcpy(&data->strs[pos], pw->str, pw->len); + pos += pw->len; + memcpy(&data->strs[pos], membuf, memsize); + pos += memsize; + + MC_LOWER_BARRIER(rec); + + /* finally chain the rec in the hash table */ + /* name hash first */ + sss_mc_add_rec_to_chain(mcc, rec, rec->hash1); + /* then gid */ + sss_mc_add_rec_to_chain(mcc, rec, rec->hash2); + + return EOK; +} + + +/*************************************************************************** * initialization ***************************************************************************/ |