summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/backend.c139
-rw-r--r--src/backend.h3
-rw-r--r--src/format.c36
3 files changed, 150 insertions, 28 deletions
diff --git a/src/backend.c b/src/backend.c
index fd830af..e7d3fdd 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -45,7 +45,7 @@
#include "plugin.h"
#include "map.h"
-#define MAP_CONFIGURATION_FILTER "(objectClass=*)"
+#define MAP_CONFIGURATION_FILTER "(objectClass=*)(base=*)(domain=*)(map=*)"
/* The data we ask the map cache to keep, for us, for each map. */
struct backend_map_data {
@@ -406,6 +406,14 @@ backend_map_config_read_config(struct plugin_state *state, Slapi_Entry *e,
ret->entry_filter = use_entry_filter;
ret->key_format = use_key_format;
ret->value_format = use_value_format;
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "initializing map %s in %s (3): "
+ "filter \"%s\", "
+ "key \"%s\", "
+ "value \"%s\"\n",
+ map, domain,
+ use_entry_filter, use_key_format, use_value_format);
}
/* Given a directory server entry which represents a map's configuration, set
@@ -441,7 +449,7 @@ backend_map_config_entry_add_one(struct plugin_state *state, Slapi_Entry *e,
cb_data.bases[i],
LDAP_SCOPE_SUB,
cb_data.entry_filter,
- NULL, 0,
+ NULL, FALSE,
NULL,
NULL,
state->plugin_identity,
@@ -587,7 +595,7 @@ backend_startup(struct plugin_state *state)
state->plugin_base,
LDAP_SCOPE_ONE,
MAP_CONFIGURATION_FILTER,
- NULL, 0,
+ NULL, FALSE,
NULL,
NULL,
state->plugin_identity,
@@ -629,41 +637,128 @@ backend_map_config_entry_delete_cb(Slapi_Entry *e, void *callback_data)
}
struct backend_get_map_config_cb {
- const char *domain, *map;
- struct backend_map_data *map_data;
+ struct plugin_state *state;
+ char **bases;
+ char *entry_filter;
};
+void
+backend_free_map_config(char **bases, char *entry_filter)
+{
+ int i;
+ if (bases != NULL) {
+ for (i = 0; bases[i] != NULL; i++) {
+ free(bases[i]);
+ }
+ }
+ free(bases);
+ free(entry_filter);
+}
+
static bool_t
-backend_get_map_config_cb(const char *domain, const char *map,
- void *backend_data, void *callback_data)
+backend_get_map_config_entry_cb(Slapi_Entry *e, void *callback_data)
{
+ Slapi_ValueSet *values;
+ Slapi_Value *value;
struct backend_get_map_config_cb *cbdata;
+ char *actual_attr, **ret;
+ const char *cvalue;
+ int disposition, buffer_flags, i, count;
+
cbdata = callback_data;
- if ((strcmp(domain, cbdata->domain) == 0) &&
- (strcmp(map, cbdata->map) == 0)) {
- cbdata->map_data = backend_data;
- return FALSE;
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "reading map configuration from \"%s\"\n",
+ slapi_entry_get_ndn(e));
+
+ values = NULL;
+ value = NULL;
+ if (slapi_vattr_values_get(e, "base", &values,
+ &disposition, &actual_attr,
+ 0, &buffer_flags) == 0) {
+ count = slapi_valueset_count(values);
+ cbdata->bases = malloc(sizeof(char *) * (count + 1));
+ if (cbdata->bases != NULL) {
+ for (i = slapi_valueset_first_value(values, &value);
+ i != -1;
+ i = slapi_valueset_next_value(values, i, &value)) {
+ cvalue = slapi_value_get_string(value);
+ cbdata->bases[i] = strdup(cvalue);
+ }
+ cbdata->bases[count] = NULL;
+ }
+ slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
}
+ if (slapi_vattr_values_get(e, "filter", &values,
+ &disposition, &actual_attr,
+ 0, &buffer_flags) == 0) {
+ if (slapi_valueset_first_value(values, &value) != -1) {
+ cvalue = slapi_value_get_string(value);
+ if (cvalue != NULL) {
+ free(cbdata->entry_filter);
+ cbdata->entry_filter = strdup(cvalue);
+ }
+ }
+ slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
+ }
+
return TRUE;
}
void
backend_get_map_config(struct plugin_state *state,
const char *domain, const char *map,
- const char ***bases, const char **entry_filter)
+ char ***bases, char **entry_filter)
{
+ Slapi_PBlock *pb;
+ char *filter;
+ char *attrs[] = {"filter", "base", NULL};
+ const char *default_filter;
struct backend_get_map_config_cb cbdata;
- cbdata.domain = domain;
- cbdata.map = map;
- cbdata.map_data = NULL;
- map_data_foreach_map(state, NULL, backend_get_map_config_cb, &cbdata);
- if (cbdata.map_data != NULL) {
- *bases = (const char **) cbdata.map_data->bases;
- *entry_filter = cbdata.map_data->entry_filter;
- } else {
- *bases = NULL;
- *entry_filter = NULL;
+
+ /* Build the search filter. */
+ filter = malloc(strlen("(&(domain=)(map=)(base=*))") +
+ strlen(domain) + strlen(map) +
+ strlen(MAP_CONFIGURATION_FILTER) + 1);
+ if (filter == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "out of memory reading configuration for "
+ "\"%s\"/\"%s\"!\n", domain, map);
+ return;
}
+ sprintf(filter, "(&(domain=%s)(map=%s)(base=*)%s)",
+ domain, map, MAP_CONFIGURATION_FILTER);
+
+ /* Perform the search. */
+ pb = slapi_pblock_new();
+ slapi_search_internal_set_pb(pb,
+ state->plugin_base,
+ LDAP_SCOPE_SUB,
+ filter,
+ attrs, FALSE,
+ NULL,
+ NULL,
+ state->plugin_identity,
+ 0);
+ cbdata.bases = NULL;
+ cbdata.state = state;
+ defaults_get_map_config(map, &default_filter, NULL, NULL, NULL);
+ cbdata.entry_filter = strdup(default_filter);
+ slapi_search_internal_callback_pb(pb, &cbdata,
+ NULL,
+ backend_get_map_config_entry_cb,
+ NULL);
+
+ /* Return the results. */
+ *bases = cbdata.bases;
+ *entry_filter = backend_map_config_filter(cbdata.entry_filter,
+ domain, map);
+ free(cbdata.entry_filter);
+
+ /* Clean up. */
+ slapi_pblock_destroy(pb);
+ free(filter);
}
/* Our postoperation callbacks. */
diff --git a/src/backend.h b/src/backend.h
index 8fc4526..2e06f12 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -29,5 +29,6 @@ void backend_startup(struct plugin_state *state);
void backend_init(struct slapi_pblock *pb, struct plugin_state *state);
void backend_get_map_config(struct plugin_state *state,
const char *domain, const char *map,
- const char ***bases, const char **entry_filter);
+ char ***bases, char **entry_filter);
+void backend_free_map_config(char **bases, char *entry_filter);
#endif
diff --git a/src/format.c b/src/format.c
index 66a8940..9eb8978 100644
--- a/src/format.c
+++ b/src/format.c
@@ -410,7 +410,14 @@ format_referred_entry_cb(Slapi_Entry *e, void *callback_data)
int i, j, disposition, buffer_flags, len, slen;
char *actual_attr;
const char *cvalue;
- struct format_referred_cbdata *cbdata = callback_data;
+ struct format_referred_cbdata *cbdata;
+
+ cbdata = callback_data;
+
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "referred: examining \"%s\" in \%s\"\n",
+ cbdata->attr, slapi_entry_get_ndn(e));
/* Iterate through the values for the specified attribute. */
if (slapi_vattr_values_get(e, cbdata->attr, &values,
@@ -434,6 +441,9 @@ format_referred_entry_cb(Slapi_Entry *e, void *callback_data)
if (len == 0) {
continue;
}
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "referred: got value \"%s\"\n", cvalue);
slen = strlen(cbdata->separator);
/* Check if there's space for the value. */
if (len + (cbdata->count ? slen : 0) > cbdata->outbuf_len) {
@@ -454,6 +464,9 @@ format_referred_entry_cb(Slapi_Entry *e, void *callback_data)
cvalue, len);
cbdata->outbuf += (len + (cbdata->count ? slen : 0));
cbdata->outbuf_len -= (len + (cbdata->count ? slen : 0));
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "referred: stored value \"%s\"\n", cvalue);
cbdata->count++;
}
slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
@@ -473,7 +486,8 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
Slapi_PBlock *local_pb;
int disposition, ref_disposition, buffer_flags, ref_buffer_flags;
char **argv, *attrs[2], *actual_attr, *actual_ref_attr, *filter;
- const char *sep, *cvalue, *cref, *map_filter, **map_bases;
+ const char *sep, *cvalue, *cref;
+ char *map_filter, **map_bases;
struct format_referred_cbdata cbdata;
ret = format_parse_args(state, args, &argc, &argv);
@@ -512,10 +526,16 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
/* Retrieve the map-specific paramters. */
map_filter = NULL;
map_bases = NULL;
- backend_get_map_config(state, domain, map, &map_bases, &map_filter);
+ backend_get_map_config(state, domain, argv[1], &map_bases, &map_filter);
if (map_filter == NULL) {
map_filter = "(objectClass=*)";
}
+ if (map_bases == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "no search bases defined for \"%s\"/\"%s\"?\n",
+ domain, argv[1]);
+ }
/* Now just search through the entries used for the map. */
for (i = 0; (map_bases != NULL) && (map_bases[i] != NULL); i++) {
@@ -526,6 +546,7 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
slapi_log_error(SLAPI_LOG_PLUGIN,
state->plugin_desc->spd_id,
"referred: out of memory\n");
+ backend_free_map_config(map_bases, map_filter);
slapi_pblock_destroy(local_pb);
format_free_parsed_args(argv);
return -ENOMEM;
@@ -539,7 +560,11 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
NULL, NULL,
state->plugin_identity, 0);
/* Let the callback do the work. */
- slapi_search_internal_callback_pb(local_pb, state,
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "searching under \"%s\" for \"%s\"\n",
+ map_bases[i], filter);
+ slapi_search_internal_callback_pb(local_pb, &cbdata,
NULL,
format_referred_entry_cb,
NULL);
@@ -550,9 +575,10 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e,
}
}
+ backend_free_map_config(map_bases, map_filter);
slapi_pblock_destroy(local_pb);
format_free_parsed_args(argv);
- return cbdata.ret;
+ return cbdata.outbuf - outbuf;
}
/* Evaluate each argument, after the first, in turn, and merge them, using the