summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin@redhat.com>2012-01-24 13:45:50 -0500
committerNalin Dahyabhai <nalin@redhat.com>2012-01-24 13:45:50 -0500
commitfc31cb50a21a7cf851f367e75ae3282b01b9d16c (patch)
tree040eb86af4d3db159d9ff897f784ec06df446b1f
parent0c70b2c9fda067d4fa3ddc160e77c4275b647a62 (diff)
downloadslapi-nis-fc31cb50a21a7cf851f367e75ae3282b01b9d16c.tar.gz
slapi-nis-fc31cb50a21a7cf851f367e75ae3282b01b9d16c.tar.xz
slapi-nis-fc31cb50a21a7cf851f367e75ae3282b01b9d16c.zip
- take steps to avoid making yp_first/yp_next clients loop indefinitely when a single LDAP entry produces multiple copies of the same NIS key for a given map
-rw-r--r--src/map.c14
-rw-r--r--tests/test37-nis-multi/before.txt12
2 files changed, 25 insertions, 1 deletions
diff --git a/src/map.c b/src/map.c
index ced6b73..33543df 100644
--- a/src/map.c
+++ b/src/map.c
@@ -557,7 +557,7 @@ map_next(struct plugin_state *state,
{
struct map *map;
struct map_entry *entry;
- unsigned int key_index;
+ unsigned int key_index, last_instance;
*next_key_len = 0;
*next_key = NULL;
*next_value_len = 0;
@@ -571,6 +571,18 @@ map_next(struct plugin_state *state,
if (entry == NULL) {
return FALSE;
}
+ last_instance = entry->n_keys - 1;
+ while (last_instance > key_index) {
+ if ((prev_len != entry->key_len[last_instance]) ||
+ (memcmp(prev, entry->keys[last_instance], prev_len) != 0)) {
+ last_instance--;
+ } else {
+ break;
+ }
+ }
+ if (last_instance > key_index) {
+ key_index = last_instance;
+ }
if (key_index + 1 < entry->n_keys) {
*next_key_len = entry->key_len[key_index + 1];
*next_key = entry->keys[key_index + 1];
diff --git a/tests/test37-nis-multi/before.txt b/tests/test37-nis-multi/before.txt
index 32c84a2..7c08725 100644
--- a/tests/test37-nis-multi/before.txt
+++ b/tests/test37-nis-multi/before.txt
@@ -25,6 +25,10 @@ testbox3 01:02:03:04:05:09 testbox3
testbox3 01:02:03:04:05:0a testbox3
testbox3 01:02:03:04:05:0b testbox3
testbox3 01:02:03:04:05:0c testbox3
+cat contents of example.com:name2mac:
+testbox1 01:02:03:04:05:06 testbox1
+testbox2 01:02:03:04:05:0c testbox2
+testbox3 01:02:03:04:05:0c testbox3
all contents of example.com:mac2name:
01:02:03:04:05:06 01:02:03:04:05:06 testbox1
01:02:03:04:05:06 01:02:03:04:05:06 testbox2
@@ -47,3 +51,11 @@ all contents of example.com:mac2name:
01:02:03:04:05:0c 01:02:03:04:05:0c testbox1
01:02:03:04:05:0c 01:02:03:04:05:0c testbox2
01:02:03:04:05:0c 01:02:03:04:05:0c testbox3
+cat contents of example.com:mac2name:
+01:02:03:04:05:06 01:02:03:04:05:06 testbox1
+01:02:03:04:05:07 01:02:03:04:05:07 testbox1
+01:02:03:04:05:08 01:02:03:04:05:08 testbox1
+01:02:03:04:05:09 01:02:03:04:05:09 testbox1
+01:02:03:04:05:0a 01:02:03:04:05:0a testbox1
+01:02:03:04:05:0b 01:02:03:04:05:0b testbox1
+01:02:03:04:05:0c 01:02:03:04:05:0c testbox1