summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-30 18:54:05 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-05-30 18:54:05 -0400
commitc9ad0149295a99d832c39e5d8ef43294d06e39ee (patch)
tree20c5454b18e3c99b023211501ce2c104e45fbe42 /src
parent1fc0629626382c33f562a55c8b9b7a0d0bb0ac88 (diff)
- start laying some groundwork for reconfiguring maps dynamically
Diffstat (limited to 'src')
-rw-r--r--src/backend.c116
1 files changed, 105 insertions, 11 deletions
diff --git a/src/backend.c b/src/backend.c
index 99d2f55..a634c9f 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -44,6 +44,8 @@
#include "plugin.h"
#include "map.h"
+#define MAP_CONFIGURATION_FILTER "(objectClass=*)"
+
/* The data we ask the map cache to keep, for us, for each map. */
struct backend_map_data {
struct plugin_state *state;
@@ -427,7 +429,7 @@ backend_startup(struct plugin_state *state)
slapi_search_internal_set_pb(pb,
state->plugin_base,
LDAP_SCOPE_ONE,
- "(objectclass=*)",
+ MAP_CONFIGURATION_FILTER,
NULL, 0,
NULL,
NULL,
@@ -444,6 +446,9 @@ backend_startup(struct plugin_state *state)
}
/* Our postoperation callbacks. */
+
+/* Given a map configuration, return true if the entry is supposed to be in the
+ * map. */
static bool_t
backend_entry_matches_map(struct backend_map_data *map_data,
Slapi_PBlock *pb, Slapi_Entry *e)
@@ -499,6 +504,51 @@ backend_entry_matches_map(struct backend_map_data *map_data,
return TRUE;
}
+/* Given an entry, return true if it describes a NIS map. */
+static bool_t
+backend_entry_is_a_map(struct plugin_state *state,
+ Slapi_PBlock *pb, Slapi_Entry *e)
+{
+ Slapi_DN *entry_sdn, *plugin_sdn;
+ Slapi_Filter *filter;
+ bool_t ret;
+
+ /* First, just do the scope test. */
+ entry_sdn = slapi_sdn_new_ndn_byref(slapi_entry_get_ndn(e));
+ if (entry_sdn == NULL) {
+ return FALSE;
+ } else {
+ plugin_sdn = slapi_sdn_new_ndn_byref(state->plugin_base);
+ if (plugin_sdn == NULL) {
+ slapi_sdn_free(&entry_sdn);
+ return FALSE;
+ }
+ }
+ if (slapi_sdn_scope_test(entry_sdn,
+ plugin_sdn,
+ LDAP_SCOPE_SUB) == 0) {
+ ret = FALSE;
+ } else {
+ ret = TRUE;
+ }
+ slapi_sdn_free(&plugin_sdn);
+ slapi_sdn_free(&entry_sdn);
+ /* If it's actually part of our configuration tree, check if it's a
+ * valid entry. */
+ if (ret) {
+ filter = slapi_str2filter(MAP_CONFIGURATION_FILTER);
+ if (filter != NULL) {
+ if (slapi_vattr_filter_test(pb, e, filter, 0) != 0) {
+ /* Didn't match. */
+ slapi_filter_free(filter, 1);
+ ret = FALSE;
+ }
+ slapi_filter_free(filter, 1);
+ }
+ }
+ return ret;
+}
+
/* Add any map entries which correspond to a directory server entry in this
* map. */
@@ -595,8 +645,14 @@ backend_add_cb(Slapi_PBlock *pb)
"error adding map entries corresponding to "
"\"%s\"\n", cbdata.dn);
}
+ /* If it's a map configuration entry, add and populate 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,
+ "new entry \"%s\" is a map\n", cbdata.dn);
+ /* XXX */
+ }
map_unlock();
- /* If it's a map configuration entry, add and populate the map. XXX */
return 0;
}
@@ -604,7 +660,7 @@ struct backend_modify_entry_cbdata {
struct plugin_state *state;
Slapi_PBlock *pb;
LDAPMod **mods;
- Slapi_Entry *e;
+ Slapi_Entry *e_pre, *e_post;
char *dn;
};
@@ -622,7 +678,7 @@ backend_modify_entry_cb(const char *domain, const char *map, void *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)) {
+ if (!backend_entry_matches_map(map_data, cbdata->pb, cbdata->e_post)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
map_data->state->plugin_desc->spd_id,
"clearing domain/map/id "
@@ -634,9 +690,11 @@ backend_modify_entry_cb(const char *domain, const char *map, void *backend_data,
} else {
/* Pull out the key and value. */
visited_dn_list = NULL;
- key = format_get_data(cbdata->state, cbdata->pb, cbdata->e,
+ key = format_get_data(cbdata->state, cbdata->pb,
+ cbdata->e_post,
map_data->key_fmt, &visited_dn_list);
- value = format_get_data(cbdata->state, cbdata->pb, cbdata->e,
+ value = format_get_data(cbdata->state, cbdata->pb,
+ cbdata->e_post,
map_data->value_fmt, &visited_dn_list);
/* If we actually generated a value, then set it for all keys.
* */
@@ -690,7 +748,8 @@ backend_modify_cb(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
slapi_pblock_get(pb, SLAPI_MODIFY_TARGET, &cbdata.dn);
slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &cbdata.mods);
- slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &cbdata.e);
+ slapi_pblock_get(pb, SLAPI_MODIFY_EXISTING_ENTRY, &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);
@@ -706,7 +765,20 @@ backend_modify_cb(Slapi_PBlock *pb)
}
map_unlock();
/* If it's a map configuration entry, reconfigure, clear, and
- * repopulate the map. XXX */
+ * repopulate the map. */
+ 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);
+ /* XXX */
+ }
+ 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);
+ /* XXX */
+ }
return 0;
}
@@ -862,9 +934,23 @@ backend_modrdn_cb(Slapi_PBlock *pb)
"error renaming map entries corresponding to "
"\"%s\"\n", cbdata.dn_post);
}
- map_unlock();
/* If it's a map configuration entry, reconfigure, clear, and
- * repopulate the map. XXX */
+ * repopulate the map. */
+ if (backend_entry_is_a_map(cbdata.state, pb, cbdata.e_pre)) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata.state->plugin_desc->spd_id,
+ "renamed entry \"%s\" was a map\n",
+ cbdata.e_pre);
+ /* XXX */
+ }
+ if (backend_entry_is_a_map(cbdata.state, pb, cbdata.e_post)) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ cbdata.state->plugin_desc->spd_id,
+ "renamed entry \"%s\" is now a map\n",
+ cbdata.e_post);
+ /* XXX */
+ }
+ map_unlock();
return 0;
}
@@ -874,6 +960,7 @@ backend_modrdn_cb(Slapi_PBlock *pb)
struct backend_delete_entry_cbdata {
struct plugin_state *state;
Slapi_PBlock *pb;
+ Slapi_Entry *e;
char *dn;
};
@@ -903,6 +990,7 @@ 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_EXISTING_ENTRY, &cbdata.e);
cbdata.pb = pb;
slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id,
"deleted \"%s\"\n", cbdata.dn);
@@ -916,8 +1004,14 @@ backend_delete_cb(Slapi_PBlock *pb)
"error removing map entries corresponding to "
"\"%s\"\n", cbdata.dn);
}
+ /* 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);
+ /* XXX */
+ }
map_unlock();
- /* If it's a map configuration entry, remove the map. XXX */
return 0;
}