summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-13 15:04:21 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-13 15:04:21 -0400
commit574704d91c3c05a81ea04dd203087a7d290f2cc8 (patch)
tree52d832c8e6ce7f4b89d466e799eb74bbd89e6246 /src
parent6dec108a9e26edce33feda9e67b7372a3cb9c643 (diff)
downloadslapi-nis-574704d91c3c05a81ea04dd203087a7d290f2cc8.tar.gz
slapi-nis-574704d91c3c05a81ea04dd203087a7d290f2cc8.tar.xz
slapi-nis-574704d91c3c05a81ea04dd203087a7d290f2cc8.zip
- use search-by-id interfaces when handling nis_all requests
Diffstat (limited to 'src')
-rw-r--r--src/nis.c113
1 files changed, 59 insertions, 54 deletions
diff --git a/src/nis.c b/src/nis.c
index 237bd5e..4ae38b2 100644
--- a/src/nis.c
+++ b/src/nis.c
@@ -96,6 +96,7 @@ nis_match(struct plugin_state *state,
{
struct ypreq_key req_key;
bool_t map_supported, map_secure;
+ const char *entry_id;
memset(&req_key, 0, sizeof(req_key));
memset(reply_val, 0, sizeof(*reply_val));
@@ -105,7 +106,8 @@ nis_match(struct plugin_state *state,
req_key.keydat.keydat_len,
req_key.keydat.keydat_val,
&reply_val->valdat.valdat_len,
- &reply_val->valdat.valdat_val) &&
+ &reply_val->valdat.valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE)) {
reply_val->status = YP_TRUE;
slapi_log_error(SLAPI_LOG_PLUGIN,
@@ -140,6 +142,7 @@ nis_first(struct plugin_state *state,
{
struct ypreq_nokey req_nokey;
bool_t map_supported, map_secure;
+ const char *entry_id;
memset(&req_nokey, 0, sizeof(req_nokey));
memset(reply_key_val, 0, sizeof(*reply_key_val));
@@ -150,7 +153,8 @@ nis_first(struct plugin_state *state,
&reply_key_val->keydat.keydat_len,
&reply_key_val->keydat.keydat_val,
&reply_key_val->valdat.valdat_len,
- &reply_key_val->valdat.valdat_val) &&
+ &reply_key_val->valdat.valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE)) {
reply_key_val->status = YP_TRUE;
slapi_log_error(SLAPI_LOG_PLUGIN,
@@ -183,6 +187,7 @@ nis_next(struct plugin_state *state,
struct ypresp_key_val *reply_key_val)
{
struct ypreq_key req_key;
+ const char *entry_id;
bool_t map_secure;
memset(&req_key, 0, sizeof(req_key));
memset(reply_key_val, 0, sizeof(*reply_key_val));
@@ -194,7 +199,8 @@ nis_next(struct plugin_state *state,
&reply_key_val->keydat.keydat_len,
&reply_key_val->keydat.keydat_val,
&reply_key_val->valdat.valdat_len,
- &reply_key_val->valdat.valdat_val) &&
+ &reply_key_val->valdat.valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE)) {
reply_key_val->status = YP_TRUE;
slapi_log_error(SLAPI_LOG_PLUGIN,
@@ -211,7 +217,8 @@ nis_next(struct plugin_state *state,
req_key.keydat.keydat_len,
req_key.keydat.keydat_val,
&reply_key_val->valdat.valdat_len,
- &reply_key_val->valdat.valdat_val) &&
+ &reply_key_val->valdat.valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE)) {
/* Have data for this key, but not the next. */
reply_key_val->status = YP_NOMORE;
@@ -396,8 +403,8 @@ struct nis_all_cookie {
cookie_end1,
cookie_end2,
} state;
- unsigned int key_length;
- char key[1];
+ unsigned int id_length;
+ char id[1];
};
static void
nis_all_free_cookie(struct nis_all_cookie *cookie)
@@ -405,11 +412,12 @@ nis_all_free_cookie(struct nis_all_cookie *cookie)
free(cookie);
}
static struct nis_all_cookie *
-nis_all_make_cookie(enum nis_all_cookie_state state,
- unsigned int length, const char *value)
+nis_all_make_cookie(enum nis_all_cookie_state state, const char *id)
{
struct nis_all_cookie *cookie;
- cookie = malloc(sizeof(*cookie) + ((length > 0) ? length : 0));
+ int length;
+ length = id ? strlen(id) : 0;
+ cookie = malloc(sizeof(*cookie) + length + 1);
if (cookie != NULL) {
cookie->state = state;
switch (cookie->state) {
@@ -421,9 +429,12 @@ nis_all_make_cookie(enum nis_all_cookie_state state,
break;
case cookie_this:
case cookie_next:
- cookie->key_length = length;
- if ((length > 0) && (value != NULL)) {
- memcpy(&cookie->key, value, length);
+ cookie->id_length = length;
+ if (length > 0) {
+ memcpy(&cookie->id, id, cookie->id_length);
+ cookie->id[length] = '\0';
+ } else {
+ cookie->id[0] = '\0';
}
break;
}
@@ -446,6 +457,7 @@ nis_all(struct plugin_state *state,
struct nis_all_cookie *cookie;
enum nis_all_cookie_state next_state;
bool_t map_supported, map_secure, stop;
+ const char *entry_id;
memset(&req_nokey, 0, sizeof(req_nokey));
reply_key = &reply_all->ypresp_all_u.val.keydat;
@@ -456,13 +468,11 @@ nis_all(struct plugin_state *state,
if (*continuation_cookie != NULL) {
cookie = *continuation_cookie;
} else {
- cookie = nis_all_make_cookie(cookie_bad,
- 0, NULL);
+ cookie = nis_all_make_cookie(cookie_bad, NULL);
}
*continuation_cookie = NULL;
} else {
- cookie = nis_all_make_cookie(cookie_bad,
- 0, NULL);
+ cookie = nis_all_make_cookie(cookie_bad, NULL);
}
/* Check if we even support the map. */
map_rdlock();
@@ -515,7 +525,8 @@ nis_all(struct plugin_state *state,
&reply_key->keydat_len,
&reply_key->keydat_val,
&reply_val->valdat_len,
- &reply_val->valdat_val) &&
+ &reply_val->valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE);
if (found) {
/* Next time grab the entry after this
@@ -553,13 +564,12 @@ nis_all(struct plugin_state *state,
* entry or send end0 or end1,
* whichever is appropriate. */
cookie = nis_all_make_cookie(next_state,
- reply_key->keydat_len,
- reply_key->keydat_val);
+ entry_id);
} else {
/* Leave a note to try sending the
* first entry again. */
cookie = nis_all_make_cookie(cookie_first,
- 0, NULL);
+ NULL);
stop = TRUE;
}
break;
@@ -567,16 +577,16 @@ nis_all(struct plugin_state *state,
/* Read the next key in the map, and set up the
* cookie to note that we're queuing a not-
* first item. */
- found = map_next(state,
- req_nokey.domain,
- req_nokey.map,
- &map_secure,
- cookie->key_length,
- cookie->key,
- &reply_key->keydat_len,
- &reply_key->keydat_val,
- &reply_val->valdat_len,
- &reply_val->valdat_val) &&
+ found = map_next_id(state,
+ req_nokey.domain,
+ req_nokey.map,
+ &map_secure,
+ cookie->id,
+ &reply_key->keydat_len,
+ &reply_key->keydat_val,
+ &reply_val->valdat_len,
+ &reply_val->valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE);
if (found) {
slapi_log_error(SLAPI_LOG_PLUGIN,
@@ -615,15 +625,13 @@ nis_all(struct plugin_state *state,
* appropriate. */
nis_all_free_cookie(cookie);
cookie = nis_all_make_cookie(next_state,
- reply_key->keydat_len,
- reply_key->keydat_val);
+ entry_id);
} else {
/* Leave a note to retry sending this
* entry the next time. */
nis_all_free_cookie(cookie);
cookie = nis_all_make_cookie(cookie_this,
- reply_key->keydat_len,
- reply_key->keydat_val);
+ entry_id);
stop = TRUE;
}
break;
@@ -631,28 +639,27 @@ nis_all(struct plugin_state *state,
/* Read the matching key in the map, and set up
* the cookie to note that we're queuing a not-
* first item. */
- reply_key->keydat_len = cookie->key_length;
- reply_key->keydat_val = cookie->key;
- found = map_match(state,
- req_nokey.domain,
- req_nokey.map,
- &map_secure,
- reply_key->keydat_len,
- reply_key->keydat_val,
- &reply_val->valdat_len,
- &reply_val->valdat_val) &&
+ found = map_match_id(state,
+ req_nokey.domain,
+ req_nokey.map,
+ &map_secure,
+ cookie->id,
+ &reply_key->keydat_len,
+ &reply_key->keydat_val,
+ &reply_val->valdat_len,
+ &reply_val->valdat_val,
+ &entry_id) &&
(map_secure ? client_secure : TRUE);
if (found) {
/* Next time grab the entry after this
* one. */
slapi_log_error(SLAPI_LOG_PLUGIN,
state->plugin_desc->spd_id,
- "all(%s/%s) \"%.*s\" "
+ "all(%s/%s) \"%s\" "
"(retry)\n",
req_nokey.domain,
req_nokey.map,
- cookie->key_length,
- cookie->key);
+ cookie->id);
skip = FALSE;
reply_all->more = TRUE;
reply_all->ypresp_all_u.val.status = YP_TRUE;
@@ -662,12 +669,11 @@ nis_all(struct plugin_state *state,
* state. */
slapi_log_error(SLAPI_LOG_PLUGIN,
state->plugin_desc->spd_id,
- "all(%s/%s) \"%.*s\" "
+ "all(%s/%s) \"%s\" "
"(disappeared?)\n",
req_nokey.domain,
req_nokey.map,
- cookie->key_length,
- cookie->key);
+ cookie->id);
skip = TRUE;
next_state = cookie_end1;
}
@@ -686,8 +692,7 @@ nis_all(struct plugin_state *state,
* stuck. */
nis_all_free_cookie(cookie);
cookie = nis_all_make_cookie(next_state,
- reply_key->keydat_len,
- reply_key->keydat_val);
+ entry_id);
break;
case cookie_end0:
/* Send the end-of-map message as the first
@@ -708,7 +713,7 @@ nis_all(struct plugin_state *state,
/* Leave a note to finish the reply. */
nis_all_free_cookie(cookie);
cookie = nis_all_make_cookie(cookie_end2,
- 0, NULL);
+ NULL);
} else {
/* Leave the note alone, so that we'll
* have to try again. */
@@ -735,7 +740,7 @@ nis_all(struct plugin_state *state,
/* Leave a note to finish the reply. */
nis_all_free_cookie(cookie);
cookie = nis_all_make_cookie(cookie_end2,
- 0, NULL);
+ NULL);
} else {
/* Leave the note alone, so that we'll
* have to try again. */