summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-04 16:24:55 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-04 16:24:55 -0400
commita0f030ecbe34d9157a842bbc443f5909d8334b4f (patch)
tree76fbaaa6ef555e3e460eb73b82a26eb6874184d2 /src
parentbcfed65587720a0235848e8baf52ab7dbdfb2277 (diff)
- track attributes which entries in a map use to refer to other entries
- factor out code which sets a map entry based on a directory server entry
Diffstat (limited to 'src')
-rw-r--r--src/backend.c446
1 files changed, 213 insertions, 233 deletions
diff --git a/src/backend.c b/src/backend.c
index f06ef2b..f7111ac 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -51,6 +51,7 @@
struct backend_map_data {
struct plugin_state *state;
char *domain, *map, **bases, *entry_filter, *key_format, *value_format;
+ char **referred;
};
/* Read the name of the NIS master. */
@@ -158,6 +159,7 @@ backend_free_map_data_contents(void *data)
free(map_data->domain);
free(map_data->map);
free(map_data->bases);
+ free(map_data->referred);
free(map_data->entry_filter);
free(map_data->key_format);
free(map_data->value_format);
@@ -182,6 +184,9 @@ backend_copy_cb_data(const struct backend_map_data *data)
ret->domain = strdup(data->domain);
ret->map = strdup(data->map);
ret->bases = backend_dup_strlist(data->bases);
+ ret->referred = data->referred ?
+ backend_dup_strlist(data->referred) :
+ NULL;
ret->entry_filter = strdup(data->entry_filter);
ret->key_format = strdup(data->key_format);
ret->value_format = strdup(data->value_format);
@@ -203,7 +208,7 @@ static int
backend_map_config_entry_add_one_cb(Slapi_Entry *e, void *callback_data)
{
struct backend_map_data *data;
- char *key, *value, *dn, **visited_dn_list;
+ char *key, *value, *ndn, **visited_dn_list;
int i, j;
data = callback_data;
/* Pull out the key and value for the entry. */
@@ -213,7 +218,7 @@ backend_map_config_entry_add_one_cb(Slapi_Entry *e, void *callback_data)
value = format_get_data(data->state, NULL, e,
data->value_format, &visited_dn_list);
/* Pull out the NDN of this entry. */
- dn = slapi_entry_get_ndn(e);
+ ndn = slapi_entry_get_ndn(e);
/* If we actually generated a value, then set it, otherwise clear it in
* case there was one set before. */
if ((key != NULL) && (value != NULL)) {
@@ -222,23 +227,20 @@ backend_map_config_entry_add_one_cb(Slapi_Entry *e, void *callback_data)
"setting domain/map/key/value "
"\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
data->domain, data->map,
- key, dn, value);
+ key, ndn, value);
map_data_set_entry(data->state, data->domain, data->map,
- dn, (const char **) visited_dn_list,
+ ndn, (const char **) visited_dn_list,
-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"
+ "no value for %s, unsetting domain/map/id"
"\"%s\"/\"%s\"/(\"%s\")\n",
- data->domain, data->map, dn);
+ ndn, data->domain, data->map, ndn);
map_data_unset_entry_id(data->state,
data->domain, data->map,
- dn);
+ ndn);
}
format_free_ndn_list(visited_dn_list);
format_free_data(value);
@@ -246,6 +248,13 @@ backend_map_config_entry_add_one_cb(Slapi_Entry *e, void *callback_data)
return 0;
}
+static void
+backend_map_config_entry_set_one_cb(Slapi_Entry *e,
+ struct backend_map_data *map_data)
+{
+ backend_map_config_entry_add_one_cb(e, map_data);
+}
+
/*
* Generate a copy of the filter string, with specific sequences replaced:
* %d -> name of the domain
@@ -320,13 +329,17 @@ backend_map_config_read_config(struct plugin_state *state, Slapi_Entry *e,
struct backend_map_data *ret)
{
const char *default_filter, *default_key_format, *default_value_format;
- char **bases, *entry_filter, *key_format, *value_format;
+ const char **default_referred;
+ char **bases, *entry_filter, *key_format, *value_format, **referred;
char **use_bases, *use_entry_filter, *use_key_format, *use_value_format;
+ char **use_referred;
/* Read the hard-coded defaults for a map with this name. */
defaults_get_map_config(map, &default_filter,
- &default_key_format, &default_value_format);
+ &default_key_format, &default_value_format,
+ &default_referred);
/* Read the values from the configuration entry. */
bases = slapi_entry_attr_get_charray(e, "base");
+ referred = slapi_entry_attr_get_charray(e, "referred");
entry_filter = slapi_entry_attr_get_charptr(e, "filter");
key_format = slapi_entry_attr_get_charptr(e, "keyFormat");
value_format = slapi_entry_attr_get_charptr(e, "valueFormat");
@@ -345,16 +358,23 @@ backend_map_config_read_config(struct plugin_state *state, Slapi_Entry *e,
strdup(value_format) :
strdup(default_value_format);
use_bases = backend_dup_strlist(bases);
+ use_referred = referred ?
+ backend_dup_strlist(referred) :
+ (default_referred ?
+ backend_dup_strlist((char **) default_referred) :
+ NULL);
/* Free the values we read from the entry. */
slapi_ch_free_string(&value_format);
slapi_ch_free_string(&key_format);
slapi_ch_free_string(&entry_filter);
+ slapi_ch_array_free(referred);
slapi_ch_array_free(bases);
/* Populate the returned structure. */
ret->state = state;
ret->domain = strdup(domain);
ret->map = strdup(map);
ret->bases = use_bases;
+ ret->referred = use_referred;
ret->entry_filter = use_entry_filter;
ret->key_format = use_key_format;
ret->value_format = use_value_format;
@@ -698,6 +718,69 @@ backend_entry_is_a_map(struct plugin_state *state,
return ret;
}
+/* Update any entries to which the passed-in entry in the passed-in map refers
+ * to, if the referred-to entry is in this map. Everybody got that? */
+struct backend_update_referred_to_entries_cbdata {
+ struct backend_map_data *map_data;
+ Slapi_Entry *e;
+};
+static bool_t
+backend_update_referred_to_entries_cb(const char *domain, const char *map,
+ void *backend_data, void *cbdata_ptr)
+{
+ struct backend_map_data *map_data;
+ struct backend_update_referred_to_entries_cbdata *cbdata;
+ Slapi_DN *referred_to_sdn;
+ Slapi_ValueSet *values;
+ Slapi_Value *value;
+ char **referred_to_dn, **referred, *actual_attr;
+ const char *ndn, *dn;
+ int i, j, disposition, buffer_flags;
+
+ map_data = backend_data;
+ cbdata = cbdata_ptr;
+
+ /* Allocate the DN we'll use to hold values. */
+ referred_to_sdn = slapi_sdn_new();
+ if (referred_to_sdn == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ map_data->state->plugin_desc->spd_id,
+ "error updating entries referred to by %s\n",
+ slapi_entry_get_ndn(cbdata->e));
+ return TRUE;
+ }
+
+ /* For every attribute name which is used to refer to another entry.. */
+ referred = cbdata->map_data->referred;
+ for (i = 0; (referred != NULL) && (referred[i] != NULL); i++) {
+ values = NULL;
+ if (slapi_vattr_values_get(cbdata->e, referred[i], &values,
+ &disposition, &actual_attr,
+ 0, &buffer_flags) == 0) {
+ /* For each value of those attributes.. */
+ for (j = slapi_valueset_first_value(values, &value);
+ j != -1;
+ j = slapi_valueset_next_value(values, j, &value)) {
+ dn = slapi_value_get_string(value);
+ if (dn != NULL) {
+ slapi_sdn_set_dn_byref(referred_to_sdn,
+ dn);
+ ndn = slapi_sdn_get_ndn(referred_to_sdn);
+ if (map_data_check_entry(map_data->state,
+ map_data->domain,
+ map_data->map,
+ ndn)) {
+ backend_map_config_entry_set_one_cb(cbdata->e, map_data);
+ }
+ }
+ }
+ slapi_vattr_values_free(&values, &actual_attr,
+ buffer_flags);
+ }
+ }
+ return TRUE;
+}
+
/* Add any map entries which correspond to a directory server entry in this
* map. */
@@ -705,7 +788,7 @@ struct backend_add_entry_cbdata {
struct plugin_state *state;
Slapi_PBlock *pb;
Slapi_Entry *e;
- char *dn;
+ char *ndn;
};
static bool_t
@@ -714,9 +797,9 @@ backend_add_entry_cb(const char *domain, const char *map, void *backend_data,
{
Slapi_DN *base_sdn, *entry_sdn;
Slapi_Filter *filter;
- char **visited_dn_list, *key, *value;
struct backend_map_data *map_data;
struct backend_add_entry_cbdata *cbdata;
+ struct backend_update_referred_to_entries_cbdata rcbdata;
map_data = backend_data;
cbdata = cbdata_ptr;
@@ -727,49 +810,27 @@ backend_add_entry_cb(const char *domain, const char *map, void *backend_data,
map_data->state->plugin_desc->spd_id,
"entry \"%s\" does not belong in "
"\"%s\"/\"%s\"\n",
- cbdata->dn, domain, map);
- map_data_unset_entry_id(map_data->state,
- map_data->domain, map_data->map,
- cbdata->dn);
+ cbdata->ndn, domain, map);
return TRUE;
}
- /* Pull out the key and value. */
- visited_dn_list = NULL;
- key = format_get_data(cbdata->state, cbdata->pb, cbdata->e,
- map_data->key_format, &visited_dn_list);
- value = format_get_data(cbdata->state, cbdata->pb, cbdata->e,
- map_data->value_format, &visited_dn_list);
+ /* Set the entry in the map which corresponds to this entry, or clear
+ * any that might if this entry doesn't have a key and value. */
+ backend_map_config_entry_set_one_cb(cbdata->e, map_data);
- /* If we actually generated a value, then set it for all keys. */
- if ((key != NULL) && (value != NULL)) {
- /* For each key, set the value. */
+ /* Update entries which need to be updated in case this entry now
+ * refers to a set of entries. */
+ rcbdata.map_data = map_data;
+ rcbdata.e = cbdata->e;
+ if (!map_data_foreach_map(cbdata->state, NULL,
+ backend_update_referred_to_entries_cb,
+ &rcbdata)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "setting domain/map/key/value "
- "\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
- domain, map,
- key, cbdata->dn, value);
- map_data_set_entry(map_data->state, domain, map,
- cbdata->dn, (const char **) visited_dn_list,
- -1, key,
- -1, value);
- } else {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "no value for \"%s\"\n", cbdata->dn);
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "unsetting domain/map/id"
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->domain, map_data->map, cbdata->dn);
- map_data_unset_entry_id(map_data->state,
- map_data->domain, map_data->map,
- cbdata->dn);
+ cbdata->state->plugin_desc->spd_id,
+ "error updating referred-to entries for "
+ "\"%s\"\n", cbdata->ndn);
}
- format_free_ndn_list(visited_dn_list);
- format_free_data(value);
- format_free_data(key);
+
return TRUE;
}
@@ -779,18 +840,21 @@ backend_add_cb(Slapi_PBlock *pb)
struct backend_add_entry_cbdata cbdata;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
- slapi_pblock_get(pb, SLAPI_ADD_TARGET, &cbdata.dn);
+ slapi_pblock_get(pb, SLAPI_ADD_TARGET, &cbdata.ndn);
slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &cbdata.e);
cbdata.pb = pb;
slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,
- "added \"%s\"\n", cbdata.dn);
+ "added \"%s\"\n", cbdata.ndn);
- /* Check for NULL entries. */
+ /* Check for NULL entries, indicative of a failure elsewhere (?). */
if (cbdata.e == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "added entry is NULL\n");
- return 0;
+ slapi_pblock_get(pb, SLAPI_ADD_EXISTING_DN_ENTRY, &cbdata.e);
+ if (cbdata.e == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata.state->plugin_desc->spd_id,
+ "added entry is NULL\n");
+ return 0;
+ }
}
/* Add map entries which corresponded to this directory server
@@ -801,14 +865,15 @@ backend_add_cb(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
"error adding map entries corresponding to "
- "\"%s\"\n", cbdata.dn);
+ "\"%s\"\n", cbdata.ndn);
}
+
/* If it's a map configuration entry, add and populate the maps it
* describes. */
if (backend_entry_is_a_map(cbdata.state, pb, cbdata.e)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
- "new entry \"%s\" is a map\n", cbdata.dn);
+ "new entry \"%s\" is a map\n", cbdata.ndn);
backend_map_config_entry_add_cb(cbdata.e, cbdata.state);
}
map_unlock();
@@ -820,7 +885,7 @@ struct backend_modify_entry_cbdata {
Slapi_PBlock *pb;
LDAPMod **mods;
Slapi_Entry *e_pre, *e_post;
- char *dn;
+ char *ndn;
};
static bool_t
@@ -829,73 +894,54 @@ backend_modify_entry_cb(const char *domain, const char *map, void *backend_data,
{
Slapi_DN *base_sdn, *entry_sdn;
Slapi_Filter *filter;
- char **visited_dn_list, *key, *value;
struct backend_map_data *map_data;
struct backend_modify_entry_cbdata *cbdata;
+ struct backend_update_referred_to_entries_cbdata rcbdata;
map_data = backend_data;
cbdata = cbdata_ptr;
- /* If the entry doesn't match the map, skip it. */
- if (!backend_entry_matches_map(map_data, cbdata->pb, cbdata->e_post)) {
+ /* If the entry used to match the map, remove it. */
+ if (backend_entry_matches_map(map_data, cbdata->pb, cbdata->e_pre)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
map_data->state->plugin_desc->spd_id,
"clearing domain/map/id "
"\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->domain, map_data->map, cbdata->dn);
+ map_data->domain, map_data->map, cbdata->ndn);
map_data_unset_entry_id(map_data->state,
map_data->domain, map_data->map,
- cbdata->dn);
- } else {
- /* Pull out the key and value. */
- visited_dn_list = NULL;
- key = format_get_data(cbdata->state, cbdata->pb,
- cbdata->e_post,
- map_data->key_format, &visited_dn_list);
- value = format_get_data(cbdata->state, cbdata->pb,
- cbdata->e_post,
- map_data->value_format, &visited_dn_list);
- /* If we actually generated a value, then set it for all keys.
- * */
- if ((key != NULL) && (value != NULL)) {
- /* For each key, set the value. */
+ cbdata->ndn);
+ /* Update entries which need to be updated in case this entry
+ * no longer refers to them. */
+ rcbdata.map_data = map_data;
+ rcbdata.e = cbdata->e_pre;
+ if (!map_data_foreach_map(cbdata->state, NULL,
+ backend_update_referred_to_entries_cb,
+ &rcbdata)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "setting domain/map/key/value "
- "\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
- domain, map,
- key, cbdata->dn, value);
- map_data_set_entry(map_data->state, domain, map,
- cbdata->dn,
- (const char **) visited_dn_list,
- -1, key,
- -1, value);
- } else {
- if (key == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "no key for \"%s\"\n",
- cbdata->dn);
- }
- if (value == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "no value for \"%s\"\n",
- cbdata->dn);
- }
+ cbdata->state->plugin_desc->spd_id,
+ "error updating referred-to entries "
+ "for \"%s\"\n", cbdata->ndn);
+ }
+ }
+ /* If the entry now matches the map, add it (or re-add it). */
+ if (backend_entry_matches_map(map_data, cbdata->pb, cbdata->e_post)) {
+ /* Set the entry in the map which corresponds to this entry, or
+ * clear any that might if this entry doesn't have a key and
+ * value. */
+ backend_map_config_entry_set_one_cb(cbdata->e_post, map_data);
+ /* Update entries which need to be updated in case this entry
+ * no longer refers to them. */
+ rcbdata.map_data = map_data;
+ rcbdata.e = cbdata->e_post;
+ if (!map_data_foreach_map(cbdata->state, NULL,
+ backend_update_referred_to_entries_cb,
+ &rcbdata)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "unsetting domain/map/id"
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->domain, map_data->map,
- cbdata->dn);
- map_data_unset_entry_id(map_data->state,
- map_data->domain, map_data->map,
- cbdata->dn);
+ cbdata->state->plugin_desc->spd_id,
+ "error updating referred-to entries "
+ "for \"%s\"\n", cbdata->ndn);
}
- format_free_ndn_list(visited_dn_list);
- format_free_data(value);
- format_free_data(key);
}
return TRUE;
}
@@ -905,14 +951,14 @@ backend_modify_cb(Slapi_PBlock *pb)
{
struct backend_modify_entry_cbdata cbdata;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
- slapi_pblock_get(pb, SLAPI_MODIFY_TARGET, &cbdata.dn);
+ slapi_pblock_get(pb, SLAPI_MODIFY_TARGET, &cbdata.ndn);
slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &cbdata.mods);
slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &cbdata.e_pre);
slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &cbdata.e_post);
cbdata.pb = pb;
slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,
- "modified \"%s\"\n", cbdata.dn);
- /* Check for NULL entries. */
+ "modified \"%s\"\n", cbdata.ndn);
+ /* Check for NULL entries, indicative of a failure elsewhere (?). */
if (cbdata.e_pre == NULL) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
@@ -933,7 +979,7 @@ backend_modify_cb(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
"error modifying map entries corresponding to "
- "\"%s\"\n", cbdata.dn);
+ "\"%s\"\n", cbdata.ndn);
}
map_unlock();
/* If it's a map configuration entry, reconfigure, clear, and
@@ -941,14 +987,15 @@ backend_modify_cb(Slapi_PBlock *pb)
if (backend_entry_is_a_map(cbdata.state, pb, cbdata.e_pre)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
- "modified entry \"%s\" was a map\n", cbdata.dn);
+ "modified entry \"%s\" was a map\n",
+ cbdata.ndn);
backend_map_config_entry_delete_cb(cbdata.e_pre, cbdata.state);
}
if (backend_entry_is_a_map(cbdata.state, pb, cbdata.e_post)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
"modified entry \"%s\" is now a map\n",
- cbdata.dn);
+ cbdata.ndn);
backend_map_config_entry_add_cb(cbdata.e_post, cbdata.state);
}
return 0;
@@ -958,16 +1005,13 @@ struct backend_modrdn_entry_cbdata {
struct plugin_state *state;
Slapi_PBlock *pb;
Slapi_Entry *e_pre, *e_post;
- char *dn_pre, *dn_post;
+ char *ndn_pre, *ndn_post;
};
static bool_t
backend_modrdn_entry_cb(const char *domain, const char *map, void *backend_data,
void *cbdata_ptr)
{
- Slapi_DN *base_sdn, *entry_sdn;
- Slapi_Filter *filter;
- char **visited_dn_list, *key_pre, *value_pre, *key_post, *value_post;
struct backend_map_data *map_data;
struct backend_modrdn_entry_cbdata *cbdata;
bool_t matched_pre, matched_post;
@@ -980,106 +1024,24 @@ backend_modrdn_entry_cb(const char *domain, const char *map, void *backend_data,
matched_post = backend_entry_matches_map(map_data,
cbdata->pb, cbdata->e_post);
- /* Pull out the key and value for the old entry. */
- key_pre = format_get_data(cbdata->state, cbdata->pb, cbdata->e_pre,
- map_data->key_format, NULL);
- value_pre = format_get_data(cbdata->state, cbdata->pb, cbdata->e_pre,
- map_data->value_format, NULL);
-
- /* Pull out the key and value for the new entry. */
- visited_dn_list = NULL;
- key_post = format_get_data(cbdata->state, cbdata->pb, cbdata->e_post,
- map_data->key_format, &visited_dn_list);
- value_post = format_get_data(cbdata->state, cbdata->pb, cbdata->e_post,
- map_data->value_format, &visited_dn_list);
-
/* Now decide what to set, or unset, in this map. */
- if (!matched_post || (key_post == NULL) || (value_post == NULL)) {
- /* If it's no longer a match for the map (it might never have
- * been), clear the entry. */
+ if (matched_pre) {
+ /* If it was a match for the map, clear the entry. */
slapi_log_error(SLAPI_LOG_PLUGIN,
map_data->state->plugin_desc->spd_id,
"clearing domain/map/id "
"\"%s\"/\"%s\"/(\"%s\")\n",
map_data->domain, map_data->map,
- cbdata->dn_pre);
+ cbdata->ndn_pre);
map_data_unset_entry_id(map_data->state,
map_data->domain, map_data->map,
- cbdata->dn_pre);
- } else {
- if (!matched_pre || (key_pre == NULL) || (value_pre == NULL)) {
- if ((key_post != NULL) && (value_post != NULL)) {
- /* If it's suddenly become a match, set it. */
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "setting domain/map/key/value "
- "\"%s\"/\"%s\"/\"%s\"(\"%s\")="
- "\"%s\"\n",
- domain, map,
- key_post, cbdata->dn_post,
- value_post);
- map_data_set_entry(map_data->state, domain, map,
- cbdata->dn_post,
- (const char **) visited_dn_list,
- -1, key_post,
- -1, value_post);
- } else {
- /* Not a match then, not a match now. */
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "clearing domain/map/id "
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->domain, map_data->map,
- cbdata->dn_pre);
- map_data_unset_entry_id(map_data->state,
- map_data->domain,
- map_data->map,
- cbdata->dn_pre);
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "clearing domain/map/id "
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->domain, map_data->map,
- cbdata->dn_post);
- map_data_unset_entry_id(map_data->state,
- map_data->domain,
- map_data->map,
- cbdata->dn_post);
- }
- } else {
- /* Unset the old entry, set the new entry. */
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "unsetting domain/map/id "
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->domain, map_data->map,
- cbdata->dn_pre);
- map_data_unset_entry_id(map_data->state,
- map_data->domain,
- map_data->map,
- cbdata->dn_pre);
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "setting domain/map/key/value "
- "\"%s\"/\"%s\"/\"%s\"(\"%s\")="
- "\"%s\"\n",
- domain, map,
- key_post, cbdata->dn_post,
- value_post);
- map_data_set_entry(map_data->state, domain, map,
- cbdata->dn_post,
- (const char **) visited_dn_list,
- -1, key_post,
- -1, value_post);
- }
+ cbdata->ndn_pre);
+ }
+ /* Set the entry in the map which corresponds to this entry, or clear
+ * any that might if this entry doesn't have a key and value. */
+ if (matched_post) {
+ backend_map_config_entry_set_one_cb(cbdata->e_post, map_data);
}
-
- format_free_ndn_list(visited_dn_list);
- format_free_data(value_pre);
- format_free_data(key_pre);
- format_free_data(value_post);
- format_free_data(key_post);
-
return TRUE;
}
@@ -1090,13 +1052,13 @@ backend_modrdn_cb(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &cbdata.e_pre);
slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &cbdata.e_post);
- cbdata.dn_pre = slapi_entry_get_ndn(cbdata.e_pre);
- cbdata.dn_post = slapi_entry_get_ndn(cbdata.e_post);
+ cbdata.ndn_pre = slapi_entry_get_ndn(cbdata.e_pre);
+ cbdata.ndn_post = slapi_entry_get_ndn(cbdata.e_post);
cbdata.pb = pb;
slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,
"renamed \"%s\" to \"%s\"\n",
- cbdata.dn_pre, cbdata.dn_post);
- /* Check for NULL entries. */
+ cbdata.ndn_pre, cbdata.ndn_post);
+ /* Check for NULL entries, indicative of a failure elsewhere (?). */
if (cbdata.e_pre == NULL) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
@@ -1117,7 +1079,7 @@ backend_modrdn_cb(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
"error renaming map entries corresponding to "
- "\"%s\"\n", cbdata.dn_post);
+ "\"%s\"\n", cbdata.ndn_post);
}
/* If it's a map configuration entry, reconfigure, clear, and
* repopulate the map. */
@@ -1146,7 +1108,7 @@ struct backend_delete_entry_cbdata {
struct plugin_state *state;
Slapi_PBlock *pb;
Slapi_Entry *e;
- char *dn;
+ char *ndn;
};
static bool_t
@@ -1155,16 +1117,34 @@ backend_delete_entry_cb(const char *domain, const char *map, void *backend_data,
{
struct backend_map_data *map_data;
struct backend_delete_entry_cbdata *cbdata;
+ struct backend_update_referred_to_entries_cbdata rcbdata;
map_data = backend_data;
cbdata = cbdata_ptr;
- slapi_log_error(SLAPI_LOG_PLUGIN,
- map_data->state->plugin_desc->spd_id,
- "unsetting domain/map/id"
- "\"%s\"/\"%s\"=\"%s\"/\"%s\"/(\"%s\")\n",
- domain, map,
- map_data->domain, map_data->map,
- cbdata->dn);
- map_data_unset_entry_id(map_data->state, domain, map, cbdata->dn);
+ /* If it was in the map, remove it. */
+ if (backend_entry_matches_map(map_data, cbdata->pb, cbdata->e)) {
+ /* Remove this entry from the map. */
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ map_data->state->plugin_desc->spd_id,
+ "unsetting domain/map/id"
+ "\"%s\"/\"%s\"=\"%s\"/\"%s\"/(\"%s\")\n",
+ domain, map,
+ map_data->domain, map_data->map,
+ cbdata->ndn);
+ map_data_unset_entry_id(map_data->state, domain, map,
+ cbdata->ndn);
+ /* Update entries which need to be updated in case this entry
+ * no longer refers to them. */
+ rcbdata.map_data = map_data;
+ rcbdata.e = cbdata->e;
+ if (!map_data_foreach_map(cbdata->state, NULL,
+ backend_update_referred_to_entries_cb,
+ &rcbdata)) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata->state->plugin_desc->spd_id,
+ "error updating referred-to entries "
+ "for \"%s\"\n", cbdata->ndn);
+ }
+ }
return TRUE;
}
@@ -1174,12 +1154,12 @@ backend_delete_cb(Slapi_PBlock *pb)
{
struct backend_delete_entry_cbdata cbdata;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
- slapi_pblock_get(pb, SLAPI_DELETE_TARGET, &cbdata.dn);
+ slapi_pblock_get(pb, SLAPI_DELETE_TARGET, &cbdata.ndn);
slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &cbdata.e);
cbdata.pb = pb;
slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,
- "deleted \"%s\"\n", cbdata.dn);
- /* Check for NULL entries. */
+ "deleted \"%s\"\n", cbdata.ndn);
+ /* Check for NULL entries, indicative of a failure elsewhere (?). */
if (cbdata.e == NULL) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
@@ -1194,13 +1174,13 @@ backend_delete_cb(Slapi_PBlock *pb)
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
"error removing map entries corresponding to "
- "\"%s\"\n", cbdata.dn);
+ "\"%s\"\n", cbdata.ndn);
}
/* If it's a map configuration entry, remove the map. */
if (backend_entry_is_a_map(cbdata.state, pb, cbdata.e)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
cbdata.state->plugin_desc->spd_id,
- "deleted entry \"%s\" is a map\n", cbdata.dn);
+ "deleted entry \"%s\" is a map\n", cbdata.ndn);
backend_map_config_entry_delete_cb(cbdata.e, cbdata.state);
}
map_unlock();