144 lines
5.3 KiB
Diff
144 lines
5.3 KiB
Diff
From e61044d99ce1e68057fda236f04a731f1f3f299a Mon Sep 17 00:00:00 2001
|
|
From: Michal Zidek <mzidek@redhat.com>
|
|
Date: Wed, 14 Aug 2013 18:01:30 +0200
|
|
Subject: [PATCH 2/4] mmap_cache: Remove triple checks in client code.
|
|
|
|
We had pattern in client code with 3 conditions
|
|
that can be replaced with one.
|
|
---
|
|
src/sss_client/nss_mc_group.c | 30 ++++++++++--------------------
|
|
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 da5da0411e556c30c4a3db6faf80139d65ae817c..9fe72a60e58e0c94f0c38f243276060b70f28aa9 100644
|
|
--- a/src/sss_client/nss_mc_group.c
|
|
+++ b/src/sss_client/nss_mc_group.c
|
|
@@ -117,16 +117,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;
|
|
@@ -160,7 +155,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;
|
|
}
|
|
@@ -197,16 +192,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;
|
|
@@ -227,7 +217,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 4b08766857d5013e6f13c3dbe574c5a88fa915b0..7aca4a04b6b19b50b883960229083b688639ee4f 100644
|
|
--- a/src/sss_client/nss_mc_passwd.c
|
|
+++ b/src/sss_client/nss_mc_passwd.c
|
|
@@ -118,16 +118,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;
|
|
@@ -162,7 +157,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;
|
|
}
|
|
@@ -199,16 +194,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;
|
|
@@ -229,7 +219,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;
|
|
}
|
|
--
|
|
1.8.3.1
|
|
|