summaryrefslogtreecommitdiffstats
path: root/src/back-shr.c
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-10-24 13:54:46 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-10-24 13:54:46 -0400
commit316ece9f122d3ee63e84734cf4b790c691963e04 (patch)
tree9f06d9ff8e13a68220d6d2e012d07338f7a005ca /src/back-shr.c
parentaf009c9d84d37ab5880f575efcddbae782fe64d1 (diff)
downloadslapi-nis-316ece9f122d3ee63e84734cf4b790c691963e04.tar.gz
slapi-nis-316ece9f122d3ee63e84734cf4b790c691963e04.tar.xz
slapi-nis-316ece9f122d3ee63e84734cf4b790c691963e04.zip
- add referredx, as derefx
Diffstat (limited to 'src/back-shr.c')
-rw-r--r--src/back-shr.c187
1 files changed, 183 insertions, 4 deletions
diff --git a/src/back-shr.c b/src/back-shr.c
index e43b155..3db9420 100644
--- a/src/back-shr.c
+++ b/src/back-shr.c
@@ -784,14 +784,17 @@ backend_shr_update_references_cb(const char *group, const char *set,
struct backend_shr_update_references_cbdata *cbdata;
struct backend_shr_note_entry_sdn_cbdata note_cbdata;
Slapi_DN *referred_to_sdn, **these_entries, **prev_entries;
- Slapi_DN **these_bases, **prev_bases;
+ Slapi_DN **next_entries, **these_bases, **prev_bases;
+ Slapi_Entry *this_entry;
Slapi_ValueSet *values;
Slapi_Value *value;
char **ref_attrs, *actual_attr, *filter, **set_bases;
- char *these_attrs[2], *prev_attrs[2];
+ char *these_attrs[2], *prev_attrs[2], *next_attrs[2];
struct format_inref_attr **inref_attrs;
struct format_ref_attr_list **ref_attr_list, *ref_attr;
+ struct format_ref_attr_list **inref_attr_list, *inref_attr;
struct format_ref_attr_list_link *this_attr_link, *prev_attr_link;
+ struct format_ref_attr_list_link *next_attr_link;
const char *ndn, *dn, *map_filter;
int i, j, k, l, disposition, buffer_flags, n_ref_attrs;
@@ -892,7 +895,10 @@ backend_shr_update_references_cb(const char *group, const char *set,
slapi_sdn_free(&referred_to_sdn);
/* Determine if there are any entries in this map which directly (or
- * indirectly) pull in data from this entry. */
+ * indirectly) pull in data from this entry. If there are, update
+ * them. */
+
+ /* Walk the set of reference-attribute chains. */
ref_attr_list = set_data->ref_attr_list;
for (i = 0;
(ref_attr_list != NULL) && (ref_attr_list[i] != NULL);
@@ -907,7 +913,7 @@ backend_shr_update_references_cb(const char *group, const char *set,
/* Start with this entry. */
format_add_sdn_list(&these_entries,
slapi_entry_get_dn(cbdata->e));
- /* Walk backwards. */
+ /* Walk the chain backwards. */
for (j = ref_attr->n_links - 1;
(j >= 0) && (these_entries != NULL);
j--) {
@@ -1055,6 +1061,179 @@ backend_shr_update_references_cb(const char *group, const char *set,
}
format_free_sdn_list(these_entries);
}
+
+ /* Determine if there are any entries in this map which are referred to
+ * (directly or indirectly) by this entry. If there are, update them.
+ */
+
+ /* Walk the set of reference-attribute chains. */
+ inref_attr_list = set_data->inref_attr_list;
+ for (i = 0;
+ (inref_attr_list != NULL) && (inref_attr_list[i] != NULL);
+ i++) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "updating referredx[%d] references for "
+ "\"%s\"\n",
+ i, slapi_entry_get_ndn(cbdata->e));
+ inref_attr = inref_attr_list[i];
+ these_entries = NULL;
+ next_entries = NULL;
+ /* Start with this entry. */
+ format_add_sdn_list(&these_entries,
+ slapi_entry_get_dn(cbdata->e));
+ /* Walk the chain, backwards. */
+ for (j = inref_attr->n_links - 2;
+ (j >= 0) && (these_entries != NULL);
+ j--) {
+ /* For each link in the chain (except the last, which
+ * we skip because it's not an attribute which is used
+ * to link to other entries), build the set of entries
+ * which are referred to by the entry. */
+ this_attr_link = &inref_attr->links[j];
+ these_attrs[0] = this_attr_link->attribute;
+ these_attrs[1] = NULL;
+ if (j > 0) {
+ next_attr_link = &inref_attr->links[j - 1];
+ next_attrs[0] = next_attr_link->attribute;
+ next_attrs[1] = NULL;
+ } else {
+ next_attr_link = NULL;
+ next_attrs[0] = NULL;
+ next_attrs[1] = NULL;
+ }
+ /* Read the entries at this stage. */
+ for (k = 0;
+ (these_entries != NULL) &&
+ (these_entries[k] != NULL);
+ k++) {
+ /* Read the linked-to DN from the named
+ * attribute in the entry. */
+ values = NULL;
+ wrap_search_internal_get_entry(these_entries[k],
+ these_attrs,
+ &this_entry,
+ state->plugin_identity);
+ if (this_entry == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "failure reading entry "
+ "\"%s\"\n",
+ slapi_sdn_get_ndn(these_entries[k]));
+ continue;
+ }
+ if (slapi_vattr_values_get(this_entry,
+ these_attrs[0],
+ &values,
+ &disposition,
+ &actual_attr,
+ 0, &buffer_flags) != 0) {
+ slapi_entry_free(this_entry);
+ continue;
+ }
+ /* For each value of this attribute... */
+ for (l = slapi_valueset_first_value(values,
+ &value);
+ l != -1;
+ l = slapi_valueset_next_value(values, l,
+ &value)) {
+ /* Pull out the value, which is a
+ * referred-to entry's DN. */
+ dn = slapi_value_get_string(value);
+ if (dn == NULL) {
+ continue;
+ }
+ /* Add it to the list of entries which
+ * we'll examine this go-round. */
+ format_add_sdn_list(&these_entries, dn);
+ }
+ slapi_vattr_values_free(&values, &actual_attr,
+ buffer_flags);
+ slapi_entry_free(this_entry);
+ }
+ /* Read the entries for the next stage. */
+ for (k = 0;
+ (next_attrs[0] != NULL) &&
+ (these_entries != NULL) &&
+ (these_entries[k] != NULL);
+ k++) {
+ /* Read the linked-to DN from the named
+ * attribute in the entry. */
+ values = NULL;
+ wrap_search_internal_get_entry(these_entries[k],
+ next_attrs,
+ &this_entry,
+ state->plugin_identity);
+ if (this_entry == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "failure reading entry "
+ "\"%s\"\n",
+ slapi_sdn_get_ndn(these_entries[k]));
+ continue;
+ }
+ if (slapi_vattr_values_get(this_entry,
+ next_attrs[0],
+ &values,
+ &disposition,
+ &actual_attr,
+ 0, &buffer_flags) != 0) {
+ slapi_entry_free(this_entry);
+ continue;
+ }
+ /* For each value of this attribute... */
+ for (l = slapi_valueset_first_value(values,
+ &value);
+ l != -1;
+ l = slapi_valueset_next_value(values, l,
+ &value)) {
+ /* Pull out the value, which is a
+ * referred-to entry's DN. */
+ dn = slapi_value_get_string(value);
+ if (dn == NULL) {
+ continue;
+ }
+ /* Add it to the list of entries which
+ * we'll examine next time. */
+ format_add_sdn_list(&next_entries, dn);
+ }
+ slapi_vattr_values_free(&values, &actual_attr,
+ buffer_flags);
+ slapi_entry_free(this_entry);
+ }
+ /* Back up to process the list of predecessors, unless
+ * this was the last link, in which case it's become
+ * our list of candidates. */
+ if (j > 0) {
+ format_free_sdn_list(these_entries);
+ these_entries = next_entries;
+ next_entries = NULL;
+ }
+ }
+ /* Walk the last list of entries and update any related
+ * entries in this map. */
+ for (j = 0;
+ (these_entries != NULL) && (these_entries[j] != NULL);
+ j++) {
+ ndn = slapi_sdn_get_ndn(these_entries[j]);
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "possible dependent entry: \"%s\"\n",
+ ndn);
+ if (!map_data_check_entry(state, group, set, ndn)) {
+ continue;
+ }
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "dependent entry: \"%s\"\n",
+ ndn);
+ backend_shr_set_config_entry_set_one_dn(state,
+ ndn,
+ set_data->self);
+ }
+ format_free_sdn_list(these_entries);
+ }
+
return TRUE;
}