summaryrefslogtreecommitdiff
path: root/src/responder/nss
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2012-10-16 15:21:50 -0400
committerSimo Sorce <simo@redhat.com>2012-11-10 18:00:28 -0500
commitb294d4c50ec4431bc07ad7ec5a73e8af0e53c54f (patch)
tree3aab044f57089c3d11da90240ed6f32bb9278ef6 /src/responder/nss
parentccd24ff9e5c6417f85bf654d8650689506dffa0b (diff)
downloadsssd-b294d4c50ec4431bc07ad7ec5a73e8af0e53c54f.tar.gz
sssd-b294d4c50ec4431bc07ad7ec5a73e8af0e53c54f.tar.bz2
sssd-b294d4c50ec4431bc07ad7ec5a73e8af0e53c54f.zip
Add helpers to set common mc record fields
Les copy/paste and chance of errors when setting basic record fields that are shared among all object types.
Diffstat (limited to 'src/responder/nss')
-rw-r--r--src/responder/nss/nsssrv_mmap_cache.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c
index 524aa47c..1aeac022 100644
--- a/src/responder/nss/nsssrv_mmap_cache.c
+++ b/src/responder/nss/nsssrv_mmap_cache.c
@@ -346,6 +346,26 @@ static struct sss_mc_rec *sss_mc_get_record(struct sss_mc_ctx *mcc,
return rec;
}
+static inline void sss_mmap_set_rec_header(struct sss_mc_ctx *mcc,
+ struct sss_mc_rec *rec,
+ size_t len, int ttl,
+ const char *key1, size_t key1_len,
+ const char *key2, size_t key2_len)
+{
+ rec->len = len;
+ rec->expire = time(NULL) + ttl;
+ rec->hash1 = sss_mc_hash(mcc, key1, key1_len);
+ rec->hash2 = sss_mc_hash(mcc, key2, key2_len);
+}
+
+static inline void sss_mmap_chain_in_rec(struct sss_mc_ctx *mcc,
+ struct sss_mc_rec *rec)
+{
+ /* name first */
+ sss_mc_add_rec_to_chain(mcc, rec, rec->hash1);
+ /* then uid/gid */
+ sss_mc_add_rec_to_chain(mcc, rec, rec->hash2);
+}
/***************************************************************************
* passwd map
@@ -390,10 +410,8 @@ errno_t sss_mmap_cache_pw_store(struct sss_mc_ctx *mcc,
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, uidkey.str, uidkey.len);
+ sss_mmap_set_rec_header(mcc, rec, rec_len, mcc->valid_time_slot,
+ name->str, name->len, uidkey.str, uidkey.len);
/* passwd struct */
data->name = MC_PTR_DIFF(data->strs, data);
@@ -414,10 +432,7 @@ errno_t sss_mmap_cache_pw_store(struct sss_mc_ctx *mcc,
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 uid */
- sss_mc_add_rec_to_chain(mcc, rec, rec->hash2);
+ sss_mmap_chain_in_rec(mcc, rec);
return EOK;
}
@@ -464,10 +479,8 @@ int sss_mmap_cache_gr_store(struct sss_mc_ctx *mcc,
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);
+ sss_mmap_set_rec_header(mcc, rec, rec_len, mcc->valid_time_slot,
+ name->str, name->len, gidkey.str, gidkey.len);
/* group struct */
data->name = MC_PTR_DIFF(data->strs, data);
@@ -484,10 +497,7 @@ int sss_mmap_cache_gr_store(struct sss_mc_ctx *mcc,
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);
+ sss_mmap_chain_in_rec(mcc, rec);
return EOK;
}