diff options
author | Michal Zidek <mzidek@redhat.com> | 2013-08-14 18:01:30 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-09-03 16:23:33 +0200 |
commit | d24e56b78c13d6e4f65786edf2d45ac9a7735f33 (patch) | |
tree | 408a3df135d33e7474427b63e453f17258e10037 | |
parent | 8c2a70fe35d0c4489048b54143ee2ee9c13fe3d7 (diff) | |
download | sssd-d24e56b78c13d6e4f65786edf2d45ac9a7735f33.tar.gz sssd-d24e56b78c13d6e4f65786edf2d45ac9a7735f33.tar.xz sssd-d24e56b78c13d6e4f65786edf2d45ac9a7735f33.zip |
mmap_cache: Remove triple checks in client code.
We had pattern in client code with 3 conditions
that can be replaced with one.
-rw-r--r-- | src/sss_client/nss_mc_group.c | 30 | ||||
-rw-r--r-- | src/sss_client/nss_mc_passwd.c | 30 |
2 files changed, 20 insertions, 40 deletions
diff --git a/src/sss_client/nss_mc_group.c b/src/sss_client/nss_mc_group.c index be2cb2eee..871857b07 100644 --- a/src/sss_client/nss_mc_group.c +++ b/src/sss_client/nss_mc_group.c @@ -118,16 +118,11 @@ errno_t sss_nss_mc_getgrnam(const char *name, size_t name_len, /* hashes are calculated including the NULL terminator */ hash = sss_nss_mc_hash(&gr_mc_ctx, name, name_len + 1); slot = gr_mc_ctx.hash_table[hash]; - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - return ENOENT; - } - - while (slot != MC_INVALID_VAL) { - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - /* This probably means that the memory cache was corrupted. */ - return ENOENT; - } + /* If slot is not within the bounds of mmaped region and + * it's value is not MC_INVALID_VAL, then the cache is + * probbably corrupted. */ + while (slot < MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = sss_nss_mc_get_record(&gr_mc_ctx, slot, &rec); if (ret) { goto done; @@ -161,7 +156,7 @@ errno_t sss_nss_mc_getgrnam(const char *name, size_t name_len, slot = rec->next; } - if (slot == MC_INVALID_VAL) { + if (slot >= MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = ENOENT; goto done; } @@ -198,16 +193,11 @@ errno_t sss_nss_mc_getgrgid(gid_t gid, /* hashes are calculated including the NULL terminator */ hash = sss_nss_mc_hash(&gr_mc_ctx, gidstr, len+1); slot = gr_mc_ctx.hash_table[hash]; - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - return ENOENT; - } - - while (slot != MC_INVALID_VAL) { - if (slot > MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { - /* This probably means that the memory cache was corrupted. */ - return ENOENT; - } + /* If slot is not within the bounds of mmaped region and + * it's value is not MC_INVALID_VAL, then the cache is + * probbably corrupted. */ + while (slot < MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = sss_nss_mc_get_record(&gr_mc_ctx, slot, &rec); if (ret) { goto done; @@ -228,7 +218,7 @@ errno_t sss_nss_mc_getgrgid(gid_t gid, slot = rec->next; } - if (slot == MC_INVALID_VAL) { + if (slot >= MC_SIZE_TO_SLOTS(gr_mc_ctx.dt_size)) { ret = ENOENT; goto done; } diff --git a/src/sss_client/nss_mc_passwd.c b/src/sss_client/nss_mc_passwd.c index e5bc32206..e412fb404 100644 --- a/src/sss_client/nss_mc_passwd.c +++ b/src/sss_client/nss_mc_passwd.c @@ -119,16 +119,11 @@ errno_t sss_nss_mc_getpwnam(const char *name, size_t name_len, /* hashes are calculated including the NULL terminator */ hash = sss_nss_mc_hash(&pw_mc_ctx, name, name_len + 1); slot = pw_mc_ctx.hash_table[hash]; - if (slot > MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { - return ENOENT; - } - - while (slot != MC_INVALID_VAL) { - if (slot > MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { - /* This probably means that the memory cache was corrupted */ - return ENOENT; - } + /* If slot is not within the bounds of mmaped region and + * it's value is not MC_INVALID_VAL, then the cache is + * probbably corrupted. */ + while (slot < MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { ret = sss_nss_mc_get_record(&pw_mc_ctx, slot, &rec); if (ret) { goto done; @@ -163,7 +158,7 @@ errno_t sss_nss_mc_getpwnam(const char *name, size_t name_len, slot = rec->next; } - if (slot == MC_INVALID_VAL) { + if (slot >= MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { ret = ENOENT; goto done; } @@ -200,16 +195,11 @@ errno_t sss_nss_mc_getpwuid(uid_t uid, /* hashes are calculated including the NULL terminator */ hash = sss_nss_mc_hash(&pw_mc_ctx, uidstr, len+1); slot = pw_mc_ctx.hash_table[hash]; - if (slot > MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { - return ENOENT; - } - - while (slot != MC_INVALID_VAL) { - if (slot > MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { - /* This probably means that the memory cache was corrupted */ - return ENOENT; - } + /* If slot is not within the bounds of mmaped region and + * it's value is not MC_INVALID_VAL, then the cache is + * probbably corrupted. */ + while (slot < MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { ret = sss_nss_mc_get_record(&pw_mc_ctx, slot, &rec); if (ret) { goto done; @@ -230,7 +220,7 @@ errno_t sss_nss_mc_getpwuid(uid_t uid, slot = rec->next; } - if (slot == MC_INVALID_VAL) { + if (slot >= MC_SIZE_TO_SLOTS(pw_mc_ctx.dt_size)) { ret = ENOENT; goto done; } |