summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-09 18:09:12 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-09 18:09:12 -0400
commit96959aa8532d33f82476af0abf8cdee99d2c9b4b (patch)
tree9e6fff2bd1d3175b53b45ec3d10859cf136356dc /src
parent85231a962d194bebd40357e9efc4a14859ff483d (diff)
- start on handling addition/removal of map entries corresponding to directory entries
Diffstat (limited to 'src')
-rw-r--r--src/backend.c115
1 files changed, 105 insertions, 10 deletions
diff --git a/src/backend.c b/src/backend.c
index adb81e9..6e9bf1e 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -358,19 +358,110 @@ backend_startup(struct plugin_state *state)
slapi_pblock_destroy(pb);
}
-/* Our postop callbacks. */
+/* Our postoperation callbacks. */
/* Add any map entries which correspond to a directory server entry in this
* map. */
+struct backend_add_entry_cbdata {
+ Slapi_PBlock *pb;
+ Slapi_Entry *e;
+ char *dn;
+};
+
static PRBool
backend_add_entry_cb(const char *domain, const char *map, void *backend_data,
- void *cbdata)
+ void *cbdata_ptr)
{
- char *dn;
+ Slapi_DN *base_sdn, *entry_sdn;
+ Slapi_Filter *filter;
+ char *dn, **visited_dn, *key, *value;
+ int i;
struct backend_map_entry_cb_data *data;
+ struct backend_add_entry_cbdata *cbdata;
+
data = backend_data;
- dn = cbdata;
- /* Decide if the directory server entry belongs in this map. */
+ cbdata = cbdata_ptr;
+ dn = cbdata->dn;
+ /* Decide if the directory server entry belongs in this map. That
+ * means that it must be contained by one of the bases of the map. */
+ entry_sdn = slapi_sdn_new_ndn_byval(dn);
+ if (entry_sdn == NULL) {
+ /* XXX */
+ } else {
+ /* Check each base in turn. */
+ for (i = 0;
+ (data->bases != NULL) && (data->bases[i] != NULL);
+ i++) {
+ base_sdn = slapi_sdn_new_ndn_byval(data->bases[i]);
+ if (base_sdn == NULL) {
+ /* XXX */
+ } else {
+ if (slapi_sdn_issuffix(entry_sdn,
+ base_sdn) != 0) {
+ /* The entry is not contained by the
+ * base -- go on to try the next one. */
+ slapi_sdn_free(&base_sdn);
+ continue;
+ }
+ /* The entry is contained by the base. */
+ slapi_sdn_free(&base_sdn);
+ break;
+ }
+ }
+ slapi_sdn_free(&entry_sdn);
+ /* If we ran out of bases to check, it doesn't match. */
+ if ((data->bases == NULL) || (data->bases[i] == NULL)) {
+ return PR_TRUE;
+ }
+ }
+ /* If it's contained by a search base, compare it to the filter. */
+ filter = slapi_str2filter(data->filter);
+ if (filter == NULL) {
+ /* XXX */
+ } else {
+ if (slapi_filter_test(cbdata->pb, cbdata->e, filter, 0) != 0) {
+ /* Didn't match -- return. */
+ slapi_filter_free(filter, 1);
+ return PR_TRUE;
+ }
+ slapi_filter_free(filter, 1);
+ }
+ /* It's contained by the search base and it matches the filter, so add
+ * it to the map. */
+ /* Pull out the name of the attribute which holds the key. */
+ key = slapi_entry_attr_get_charptr(cbdata->e, data->key_attr);
+ /* Pull out the value format string and generate the value. XXX */
+ value = slapi_entry_attr_get_charptr(cbdata->e, data->value_fmt);
+ /* Pull together the DN of this entry and the others we peeked at. */
+ visited_dn = NULL;
+ /* If we actually generated a value, then set it for all keys. */
+ if ((key != NULL) && (value != NULL)) {
+ /* For each key, set the value. */
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ data->state->plugin_desc->spd_id,
+ "setting domain/map/key/value "
+ "\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
+ domain, map,
+ key, dn, value);
+ map_data_set_entry(data->state, domain, map,
+ dn, (const char **) visited_dn,
+ -1, key,
+ -1, value);
+ } else {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ data->state->plugin_desc->spd_id,
+ "no value for %s\n", dn);
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ data->state->plugin_desc->spd_id,
+ "unsetting domain/map/id"
+ "\"%s\"/\"%s\"/(\"%s\")\n",
+ data->domain, data->map, dn);
+ map_data_unset_entry_id(data->state,
+ data->domain, data->map,
+ dn);
+ }
+ slapi_ch_free_string(&value);
+ slapi_ch_free_string(&key);
return PR_TRUE;
}
@@ -378,18 +469,22 @@ int
backend_add_cb(Slapi_PBlock *pb)
{
struct plugin_state *state;
- char *dn;
+ struct backend_add_entry_cbdata cbdata;
+
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
- slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
+ slapi_pblock_get(pb, SLAPI_ADD_TARGET, &cbdata.dn);
+ slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &cbdata.e);
+ cbdata.pb = pb;
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "added \"%s\"\n", dn);
+ "added \"%s\"\n", cbdata.dn);
/* Add map entries which corresponded to this directory server
* entry. */
- if (!map_data_foreach_map(state, NULL, backend_add_entry_cb, dn)) {
+ if (!map_data_foreach_map(state, NULL, backend_add_entry_cb, &cbdata)) {
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
"error adding map entries corresponding to "
- "\"%s\"\n", dn);
+ "\"%s\"\n", cbdata.dn);
}
+ /* If it's a map configuration entry, add and populate the map. XXX */
return 0;
}