summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-30 16:56:51 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-06-30 16:56:51 -0400
commit91a5c2e9ef1e66d7c846a2f944b889f23ec92f11 (patch)
tree7acace5a6186515aa2592b1ec242ab08301f06b9 /src
parent89516c787c3fcd041a0867472382c37529339f71 (diff)
downloadslapi-nis-91a5c2e9ef1e66d7c846a2f944b889f23ec92f11.tar.gz
slapi-nis-91a5c2e9ef1e66d7c846a2f944b889f23ec92f11.tar.xz
slapi-nis-91a5c2e9ef1e66d7c846a2f944b889f23ec92f11.zip
- get schema compatibility linking correctly
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/back-sch.c1043
-rw-r--r--src/back-shr.c14
3 files changed, 150 insertions, 911 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ee6bad1..442f3b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,7 +40,9 @@ schemacompat_plugin_la_SOURCES = \
map.c \
map.h \
plug-sch.c \
- plugin.h
+ plugin.h \
+ wrap.c \
+ wrap.h
schemacompat_plugin_la_LIBADD = $(RUNTIME_LIBS) $(LIBPTHREAD)
noinst_LTLIBRARIES = dummy-nis-plugin.la
diff --git a/src/back-sch.c b/src/back-sch.c
index 704e653..1e63c60 100644
--- a/src/back-sch.c
+++ b/src/back-sch.c
@@ -45,14 +45,15 @@
#include "backend.h"
#include "back-sch.h"
+#include "back-shr.h"
#include "format.h"
#include "plugin.h"
#include "map.h"
#define SCH_CONTAINER_CONFIGURATION_FILTER "(&(objectClass=*)(" SCH_CONTAINER_CONFIGURATION_BASE_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_GROUP_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_FILTER_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_ENTRY_FORMAT_ATTR "=*))"
-/* The data we ask the map cache to keep, for us, for each map. */
-struct backend_map_data {
+/* The data we ask the map cache to keep, for us, for each set. */
+struct backend_set_data {
struct plugin_state *state;
char *group, *container, **bases, *entry_filter, *entry_format;
char **ref_attrs;
@@ -73,86 +74,66 @@ backend_read_master_name(struct plugin_state *state, char **master)
return -1;
}
-/* Manipulate string lists. */
-static void
-backend_free_strlist(char **strlist)
+/* Manipulate a backend map configuration. */
+struct plugin_state *
+backend_set_config_get_state(struct backend_set_data *set_data)
{
- if (strlist) {
- free(strlist);
- }
+ return set_data->state;
}
-static char **
-backend_dup_strlist_n(char **strlist, int n)
+char **
+backend_set_config_get_bases(struct backend_set_data *set_data)
{
- int i, l;
- char **ret, *s;
- /* Handle the NULL case. */
- if (strlist == NULL) {
- return NULL;
- }
- /* No strings = no list. */
- if (n == 0) {
- return NULL;
- }
- /* Count the amount of space needed for the strings. */
- for (i = 0, l = 0; i < n; i++) {
- l += (strlen(strlist[i]) + 1);
- }
- /* Allocate space for the array of pointers (with NULL terminator) and
- * then the string data. */
- ret = malloc(((n + 1) * sizeof(char *)) + l);
- if (ret != NULL) {
- /* Figure out where the string data will start. */
- s = (char *) ret;
- s += ((n + 1) * sizeof(char *));
- for (i = 0; i < n; i++) {
- /* Set the address of this string, copy the data
- * around, and then prepare the address of the next
- * string. */
- ret[i] = s;
- strcpy(s, strlist[i]);
- s += (strlen(strlist[i]) + 1);
- }
- /* NULL-terminate the array. */
- ret[i] = NULL;
- }
- return ret;
+ return set_data->bases;
}
-static char **
-backend_dup_strlist(char **strlist)
+char *
+backend_set_config_get_filter(struct backend_set_data *set_data)
{
- int i;
- for (i = 0; (strlist != NULL) && (strlist[i] != NULL); i++) {
- continue;
- }
- return backend_dup_strlist_n(strlist, i);
+ return set_data->entry_filter;
+}
+char *
+backend_set_config_get_group(struct backend_set_data *set_data)
+{
+ return set_data->group;
+}
+char *
+backend_set_config_get_set(struct backend_set_data *set_data)
+{
+ return set_data->container;
+}
+struct format_inref_attr **
+backend_set_config_get_inref_attrs(struct backend_set_data *set_data)
+{
+ return set_data->inref_attrs;
+}
+char **
+backend_set_config_get_ref_attrs(struct backend_set_data *set_data)
+{
+ return set_data->ref_attrs;
}
-
-/* Manipulate a backend map configuration. */
static void
-backend_free_map_data_contents(void *data)
+backend_set_config_free_config_contents(void *data)
{
- struct backend_map_data *map_data = data;
- if (map_data != NULL) {
- free(map_data->group);
- free(map_data->container);
- free(map_data->bases);
- format_free_attr_list(map_data->ref_attrs);
- format_free_inref_attrs(map_data->inref_attrs);
- free(map_data->entry_filter);
- free(map_data->entry_format);
+ struct backend_set_data *set_data = data;
+ if (set_data != NULL) {
+ free(set_data->group);
+ free(set_data->container);
+ free(set_data->bases);
+ format_free_attr_list(set_data->ref_attrs);
+ format_free_inref_attrs(set_data->inref_attrs);
+ free(set_data->entry_filter);
+ free(set_data->entry_format);
}
}
-static void
-backend_free_map_data(void *data)
+void
+backend_set_config_free_config(struct backend_set_data *data)
{
- backend_free_map_data_contents(data);
+ backend_set_config_free_config_contents(data);
free(data);
}
-static struct backend_map_data *
-backend_copy_map_data(const struct backend_map_data *data)
+static struct backend_set_data *
+backend_copy_set_config(const struct backend_set_data *data)
{
- struct backend_map_data *ret;
+ struct backend_set_data *ret;
ret = malloc(sizeof(*ret));
if (ret == NULL) {
return NULL;
@@ -160,7 +141,7 @@ backend_copy_map_data(const struct backend_map_data *data)
ret->state = data->state;
ret->group = strdup(data->group);
ret->container = strdup(data->container);
- ret->bases = backend_dup_strlist(data->bases);
+ ret->bases = backend_shr_dup_strlist(data->bases);
ret->ref_attrs = data->ref_attrs ?
format_dup_attr_list(data->ref_attrs) :
NULL;
@@ -174,100 +155,18 @@ backend_copy_map_data(const struct backend_map_data *data)
(ret->bases == NULL) ||
(ret->entry_filter == NULL) ||
(ret->entry_format == NULL)) {
- backend_free_map_data(ret);
+ backend_set_config_free_config(ret);
return NULL;
}
return ret;
}
-/* Given a map-entry directory entry, determine a key, a value, and extra data
- * to be stored in the map cache, and add them to the map cache. */
-static int
-backend_map_config_entry_add_one_cb(Slapi_Entry *e, void *callback_data)
-{
- struct backend_map_data *data;
- char *ldif, *ndn, *plugin_id, *ndns[2];
- int i, j, k, n_key_sets;
- data = callback_data;
- plugin_id = data->state->plugin_desc->spd_id;
- /* Pull out the NDN of this entry. */
- ndn = slapi_entry_get_ndn(e);
- ndns[0] = ndn;
- ndns[1] = NULL;
- /* Pull out the keys and value for the entry. */
- ldif = format_get_data(data->state, e, data->group, data->container,
- data->entry_format, NULL,
- &data->ref_attrs, &data->inref_attrs);
- /* If we actually generated a new entry for this entry, then set it,
- * otherwise clear it in case there was one set before. */
- if (ldif == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id,
- "setting group/container/key/value "
- "\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
- data->group, data->container, ndn, ndn, ldif);
- map_data_set_entry(data->state, data->group, data->container,
- ndn, NULL, ndns, -1, ldif, NULL, NULL);
- } else {
- slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id,
- "no value for %s, unsetting domain/map/id"
- "\"%s\"/\"%s\"/(\"%s\")\n",
- ndn, data->group, data->container, ndn);
- map_data_unset_entry_id(data->state,
- data->group, data->container,
- ndn);
- }
- format_free_data(ldif);
- return 0;
-}
-
-static int
-backend_map_config_entry_set_one_cb(Slapi_Entry *e, void *cbdata)
-{
- backend_map_config_entry_add_one_cb(e, cbdata);
- return 0;
-}
-
-static void
-backend_map_config_entry_set_one(Slapi_Entry *e,
- struct backend_map_data *map_data)
-{
- backend_map_config_entry_set_one_cb(e, map_data);
-}
-
-static void
-backend_map_config_entry_set_one_dn(struct plugin_state *state, const char *dn,
- struct backend_map_data *map_data)
-{
- Slapi_DN *sdn;
- Slapi_Entry *entry;
- sdn = slapi_sdn_new_dn_byval(dn);
- if (sdn == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "error parsing DN \"%s\"\n", dn);
- return;
- } else {
- entry = NULL;
- slapi_search_internal_get_entry(sdn, NULL, &entry,
- state->plugin_identity);
- if (entry == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "failure reading entry \"%s\"\n", dn);
- } else {
- backend_map_config_entry_set_one(entry, map_data);
- slapi_entry_free(entry);
- }
- slapi_sdn_free(&sdn);
- }
-}
-
-/* Given an entry, read the map configuration for the given group and container
- * name. */
-static void
-backend_map_config_read_config(struct plugin_state *state, Slapi_Entry *e,
+/* Given a configuration entry, read the map configuration for the given group
+ * and container name from the entry. */
+void
+backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e,
const char *group, const char *container,
- struct backend_map_data *ret)
+ bool_t *flag, struct backend_set_data **pret)
{
char **bases, *entry_filter, *entry_format;
char **entrykey_formats, **keys_formats, *value_format, *actual_attr;
@@ -277,8 +176,10 @@ backend_map_config_read_config(struct plugin_state *state, Slapi_Entry *e,
char *use_value_format, *use_disallowed_chars;
const char *cvalue;
int i, j, disposition, buffer_flags, count;
+ struct backend_set_data ret;
Slapi_ValueSet *values;
Slapi_Value *value;
+
/* Read the values from the configuration entry. */
bases = NULL;
if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_BASE_ATTR,
@@ -337,86 +238,71 @@ backend_map_config_read_config(struct plugin_state *state, Slapi_Entry *e,
slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
}
/* Populate the returned structure. */
- ret->state = state;
- ret->group = strdup(group);
- ret->container = strdup(container);
- ret->bases = backend_dup_strlist(bases);
- if (bases != NULL) {
- for (i = 0; bases[i] != NULL; i++) {
- free(bases[i]);
+ ret.state = state;
+ ret.group = strdup(group);
+ ret.container = strdup(container);
+ ret.bases = bases;
+ ret.entry_filter = entry_filter;
+ ret.entry_format = entry_format;
+ ret.ref_attrs = NULL;
+ ret.inref_attrs = NULL;
+ *pret = backend_copy_set_config(&ret);
+ free(ret.group);
+ free(ret.container);
+ if (ret.bases != NULL) {
+ for (i = 0; ret.bases[i] != NULL; i++) {
+ free(ret.bases[i]);
}
- free(bases);
+ free(ret.bases);
}
- ret->entry_filter = entry_filter;
- ret->entry_format = entry_format;
- ret->ref_attrs = NULL;
- ret->inref_attrs = NULL;
+ free(ret.entry_filter);
+ free(ret.entry_format);
}
-/* Given a directory server entry which represents a container's configuration,
- * set up and populate the container. */
-static int
-backend_map_config_entry_add_one(struct plugin_state *state, Slapi_Entry *e,
- const char *group, const char *container)
+/* Given a map-entry directory entry, determine a key, a value, and extra data
+ * to be stored in the map cache, and add them to the map cache. */
+void
+backend_set_entry_one(Slapi_Entry *e, struct backend_set_data *data)
{
- Slapi_PBlock *pb;
- int i;
- struct backend_map_data cb_data, *map_cb_data;
-
- pb = slapi_pblock_new();
- backend_map_config_read_config(state, e, group, container, &cb_data);
- map_cb_data = backend_copy_map_data(&cb_data);
- backend_free_map_data_contents(&cb_data);
- if (map_cb_data == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "incomplete container definition %s in %s "
- "(2)\n", container, group);
- slapi_pblock_destroy(pb);
- return 0;
- }
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "initializing container %s in %s (2)\n",
- group, container);
- map_data_set_map(state, group, container, FALSE,
- map_cb_data, &backend_free_map_data);
- map_data_clear_map(state, group, container);
- /* Search under each base in turn, adding the matching directory
- * entries to the containers. */
- for (i = 0;
- (map_cb_data->bases != NULL) && (map_cb_data->bases[i] != NULL);
- i++) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "searching '%s' for '%s'\n",
- map_cb_data->bases[i],
- map_cb_data->entry_filter);
- slapi_search_internal_set_pb(pb,
- map_cb_data->bases[i],
- LDAP_SCOPE_SUB,
- map_cb_data->entry_filter,
- NULL, FALSE,
- NULL,
- NULL,
- state->plugin_identity,
- 0);
- slapi_search_internal_callback_pb(pb, map_cb_data,
- NULL,
- backend_map_config_entry_add_one_cb,
- NULL);
- slapi_free_search_results_internal(pb);
+ char *ldif, *ndn, *plugin_id, *ndns[2];
+ int i, j, k, n_key_sets;
+ plugin_id = data->state->plugin_desc->spd_id;
+ /* Pull out the NDN of this entry. */
+ ndn = slapi_entry_get_ndn(e);
+ ndns[0] = ndn;
+ ndns[1] = NULL;
+ /* Generate the LDIF for the entry. */
+ ldif = format_get_data(data->state, e, data->group, data->container,
+ data->entry_format, NULL,
+ &data->ref_attrs, &data->inref_attrs);
+ /* If we actually generated a new entry for this entry, then set it,
+ * otherwise clear it in case there was one set before. */
+ if (ldif == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id,
+ "setting group/container/key/value "
+ "\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
+ data->group, data->container, ndn, ndn, ldif);
+ map_data_set_entry(data->state,
+ data->group, data->container, ndn,
+ NULL, ndns, -1, ldif,
+ NULL, NULL);
+ } else {
+ slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id,
+ "no value for %s, unsetting domain/map/id"
+ "\"%s\"/\"%s\"/(\"%s\")\n",
+ ndn, data->group, data->container, ndn);
+ map_data_unset_entry_id(data->state,
+ data->group, data->container,
+ ndn);
}
- /* Clean up. */
- slapi_pblock_destroy(pb);
- return 0;
+ format_free_data(ldif);
}
-/* Process a map configuration directory entry. Pull out the group and
+/* Process a set configuration directory entry. Pull out the group and
* container names which are valid for this configuration and configure such a
* container for each in turn. */
-static int
-backend_map_config_entry_add_cb(Slapi_Entry *e, void *callback_data)
+int
+backend_set_config_entry_add_cb(Slapi_Entry *e, void *callback_data)
{
char **groups, **containers, *actual_attr;
const char *cvalue;
@@ -466,9 +352,9 @@ backend_map_config_entry_add_cb(Slapi_Entry *e, void *callback_data)
for (j = 0;
(containers != NULL) && (containers[j] != NULL);
j++) {
- ret = backend_map_config_entry_add_one(state, e,
- groups[i],
- containers[j]);
+ ret = backend_shr_set_config_entry_add_one(state, e,
+ groups[i],
+ containers[j]);
}
}
if (groups != NULL) {
@@ -488,68 +374,20 @@ backend_map_config_entry_add_cb(Slapi_Entry *e, void *callback_data)
return 0;
}
-/* Scan for the list of configured groups and containers. */
-void
-backend_startup(struct plugin_state *state)
-{
- Slapi_PBlock *pb;
-
- pb = slapi_pblock_new();
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "searching \"%s\" for containers\n",
- state->plugin_base);
- slapi_search_internal_set_pb(pb,
- state->plugin_base,
- LDAP_SCOPE_ONE,
- SCH_CONTAINER_CONFIGURATION_FILTER,
- NULL, FALSE,
- NULL,
- NULL,
- state->plugin_identity,
- 0);
- map_wrlock();
- slapi_search_internal_callback_pb(pb, state,
- NULL,
- backend_map_config_entry_add_cb,
- NULL);
- map_unlock();
- slapi_free_search_results_internal(pb);
- slapi_pblock_destroy(pb);
-}
-
-/* Process a map configuration directory entry. Pull out the domain and map
+/* Process a set configuration directory entry. Pull out the domain and map
* names which are specified in the entry and delete each in turn. */
-static int
-backend_map_config_entry_delete_cb(Slapi_Entry *e, void *callback_data)
+int
+backend_set_config_entry_delete_cb(Slapi_Entry *e, void *callback_data)
{
- char **groups, **containers;
- int i, j;
struct plugin_state *state;
-
state = callback_data;
- groups = slapi_entry_attr_get_charray(e,
- SCH_CONTAINER_CONFIGURATION_GROUP_ATTR);
- containers = slapi_entry_attr_get_charray(e,
- SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR);
- for (i = 0; (groups != NULL) && (groups[i] != NULL); i++) {
- for (j = 0;
- (containers != NULL) && (containers[j] != NULL);
- j++) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "removing container %s in %s\n",
- containers[j], groups[i]);
- map_data_unset_map(state, groups[i], containers[j]);
- }
- }
- slapi_ch_array_free(containers);
- slapi_ch_array_free(groups);
- return 0;
+ return backend_shr_set_config_entry_delete(state, e,
+ SCH_CONTAINER_CONFIGURATION_GROUP_ATTR,
+ SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR);
}
-/* Functions for passing information about a container's configuration to a
- * caller. */
+/* Functions for passing information about a container's configuration to the
+ * formatting functions. */
struct backend_get_map_config_cb {
struct plugin_state *state;
char **bases;
@@ -559,7 +397,7 @@ struct backend_get_map_config_cb {
void
backend_free_map_config(char **bases, char *entry_filter)
{
- backend_free_strlist(bases);
+ backend_shr_free_strlist(bases);
free(entry_filter);
}
@@ -674,68 +512,9 @@ backend_get_map_config(struct plugin_state *state,
slapi_pblock_destroy(pb);
}
-/* Our postoperation callbacks. */
-
-/* Given a map configuration, return true if an entry corresponding to the
- * entry is supposed to be in the container. */
-static bool_t
-backend_entry_matches_map(struct backend_map_data *map_data,
- Slapi_PBlock *pb, Slapi_Entry *e)
-{
- Slapi_DN *base_sdn;
- const Slapi_DN *entry_sdn;
- Slapi_Filter *filter;
- int i;
- /* 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_byref(slapi_entry_get_ndn(e));
- if (entry_sdn == NULL) {
- return FALSE;
- } else {
- /* Check each base in turn. */
- for (i = 0;
- (map_data->bases != NULL) && (map_data->bases[i] != NULL);
- i++) {
- base_sdn = slapi_sdn_new_dn_byval(map_data->bases[i]);
- if (base_sdn == NULL) {
- return FALSE;
- } else {
- if (slapi_sdn_scope_test(entry_sdn,
- base_sdn,
- LDAP_SCOPE_SUB) == 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;
- }
- }
- /* If we ran out of bases to check, it doesn't match. */
- if ((map_data->bases == NULL) || (map_data->bases[i] == NULL)) {
- return FALSE;
- }
- }
- /* If it's contained by a search base, compare it to the filter. */
- filter = slapi_str2filter(map_data->entry_filter);
- if (filter == NULL) {
- return FALSE;
- } else {
- if (slapi_vattr_filter_test(pb, e, filter, 0) != 0) {
- /* Didn't match -- return. */
- slapi_filter_free(filter, 1);
- return FALSE;
- }
- slapi_filter_free(filter, 1);
- }
- return TRUE;
-}
-
/* Given an entry, return true if it describes a compatibility container. */
-static bool_t
-backend_entry_is_a_map(struct plugin_state *state,
+bool_t
+backend_entry_is_a_set(struct plugin_state *state,
Slapi_PBlock *pb, Slapi_Entry *e)
{
Slapi_DN *entry_sdn, *plugin_sdn;
@@ -743,7 +522,8 @@ backend_entry_is_a_map(struct plugin_state *state,
bool_t ret;
char configuration_filter[] = SCH_CONTAINER_CONFIGURATION_FILTER;
- /* First, just do the scope test. */
+ /* First, just do the scope test. The item should be a direct child of
+ * our plugin entry. */
entry_sdn = slapi_sdn_new_ndn_byref(slapi_entry_get_ndn(e));
if (entry_sdn == NULL) {
return FALSE;
@@ -769,8 +549,9 @@ backend_entry_is_a_map(struct plugin_state *state,
}
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 it's actually in our configuration tree, check if it's a valid
+ * entry. */
if (ret) {
filter = slapi_str2filter(configuration_filter);
if (filter != NULL) {
@@ -793,564 +574,22 @@ 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_references_cbdata {
- Slapi_PBlock *pb;
- Slapi_Entry *e;
-};
-
-static bool_t
-backend_update_references_cb(const char *domain, const char *map, bool_t secure,
- void *backend_data, void *cbdata_ptr)
-{
- struct plugin_state *state;
- struct backend_map_data *map_data;
- struct backend_update_references_cbdata *cbdata;
- Slapi_DN *referred_to_sdn;
- Slapi_ValueSet *values;
- Slapi_Value *value;
- char **ref_attrs, *actual_attr, *filter, *tndn;
- struct format_inref_attr **inref_attrs;
- const char *ndn, *dn;
- int i, j, disposition, buffer_flags, filter_size, n_ref_attrs;
-
- map_data = backend_data;
- cbdata = cbdata_ptr;
- state = map_data->state;
-
- /* For every entry in this map which refers to this entry using
- * a DN stored in an attribute, update that entry. */
-
- /* Build a filter with all of these attributes and this entry's DN. */
- ref_attrs = map_data->ref_attrs;
- for (i = 0; (ref_attrs != NULL) && (ref_attrs[i] != NULL); i++) {
- continue;
- }
- n_ref_attrs = i;
- if (n_ref_attrs > 0) {
- filter_size = strlen("(&(|))") +
- strlen(map_data->entry_filter) +
- 1;
- ndn = slapi_entry_get_ndn(cbdata->e);
- tndn = format_escape_for_filter(ndn);
- if (tndn == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "error building filter for "
- "updating entries\n");
- return TRUE;
- }
- for (i = 0;
- (ref_attrs != NULL) && (ref_attrs[i] != NULL);
- i++) {
- filter_size += (strlen("(=)") +
- strlen(ref_attrs[i]) +
- strlen(ndn));
- }
- filter = malloc(filter_size);
- if (filter == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "error building filter for "
- "updating entries\n");
- free(tndn);
- return TRUE;
- }
- sprintf(filter, "(&%s(|", map_data->entry_filter);
- for (i = 0;
- (ref_attrs != NULL) && (ref_attrs[i] != NULL);
- i++) {
- sprintf(filter + strlen(filter),
- "(%s=%s)", ref_attrs[i], tndn);
- }
- strcat(filter, "))");
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "searching for referrers using filter \"%s\"\n",
- filter);
- free(tndn);
- /* Update any matching entry. */
- for (i = 0;
- (map_data->bases != NULL) && (map_data->bases[i] != NULL);
- i++) {
- slapi_search_internal_set_pb(cbdata->pb,
- map_data->bases[i],
- LDAP_SCOPE_SUB,
- filter,
- NULL, FALSE,
- NULL,
- NULL,
- state->plugin_identity,
- 0);
- slapi_search_internal_callback_pb(cbdata->pb, map_data,
- NULL,
- backend_map_config_entry_set_one_cb,
- NULL);
- }
- free(filter);
- }
-
- /* Allocate the DN we'll use to hold values for comparison. */
- referred_to_sdn = slapi_sdn_new();
- if (referred_to_sdn == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "error updating entries referred to by %s\n",
- slapi_entry_get_ndn(cbdata->e));
- return TRUE;
- }
-
- /* For every directory entry to which this directory entry refers and
- * which also has a corresponding entry in this map, update it. */
- inref_attrs = map_data->inref_attrs;
- for (i = 0; (inref_attrs != NULL) && (inref_attrs[i] != NULL); i++) {
- /* We're only processing inref attributes for this map. */
- if ((strcmp(inref_attrs[i]->domain, domain) != 0) ||
- (strcmp(inref_attrs[i]->map, map) != 0)) {
- continue;
- }
- /* Extract the named attribute from the entry. */
- values = NULL;
- if (slapi_vattr_values_get(cbdata->e,
- inref_attrs[i]->attribute,
- &values, &disposition, &actual_attr,
- 0, &buffer_flags) != 0) {
- continue;
- }
- /* For each value of this attributes.. */
- for (j = slapi_valueset_first_value(values, &value);
- j != -1;
- j = slapi_valueset_next_value(values, j, &value)) {
- /* Pull out the value, which is a referred-to entry's
- * DN. */
- dn = slapi_value_get_string(value);
- if (dn == NULL) {
- continue;
- }
- /* Normalize the DN. */
- slapi_sdn_set_dn_byref(referred_to_sdn, dn);
- ndn = slapi_sdn_get_ndn(referred_to_sdn);
- /* If the named entry corresponds to an entry that's
- * already in this map. */
- if (map_data_check_entry(state, domain, map, ndn)) {
- /* ...update it. */
- backend_map_config_entry_set_one_dn(state, ndn,
- map_data);
- }
- }
- slapi_vattr_values_free(&values, &actual_attr,
- buffer_flags);
- }
- slapi_sdn_free(&referred_to_sdn);
- return TRUE;
-}
-
-static void
-backend_update_references(struct plugin_state *state, Slapi_Entry *e)
-{
- struct backend_update_references_cbdata cbdata;
- cbdata.e = e;
- cbdata.pb = slapi_pblock_new();
- if (!map_data_foreach_map(state, NULL,
- backend_update_references_cb, &cbdata)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- state->plugin_desc->spd_id,
- "error updating references for \"%s\"\n",
- slapi_entry_get_ndn(cbdata.e));
- }
- slapi_pblock_destroy(cbdata.pb);
-}
-
-/* Add any map entries which correspond to a directory server entry in this
- * map. */
-
-struct backend_add_entry_cbdata {
- struct plugin_state *state;
- Slapi_PBlock *pb;
- Slapi_Entry *e;
- char *ndn;
-};
-
-static bool_t
-backend_add_entry_cb(const char *domain, const char *map, bool_t secure,
- void *backend_data, void *cbdata_ptr)
-{
- struct backend_map_data *map_data;
- struct backend_add_entry_cbdata *cbdata;
-
- 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)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata->state->plugin_desc->spd_id,
- "entry \"%s\" does not belong in "
- "\"%s\"/\"%s\"\n",
- cbdata->ndn, domain, map);
- return TRUE;
- }
-
- /* 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(cbdata->e, map_data);
-
- return TRUE;
-}
-
-static int
-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.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.ndn);
-
- /* Check for NULL entries, indicative of a failure elsewhere (?). */
- if (cbdata.e == NULL) {
- 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
- * entry. */
- map_wrlock();
- if (!map_data_foreach_map(cbdata.state, NULL,
- backend_add_entry_cb, &cbdata)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "error adding map entries corresponding to "
- "\"%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.ndn);
- backend_map_config_entry_add_cb(cbdata.e, cbdata.state);
- }
-
- /* Update entries which need to be updated in case this new entry
- * refers to them. */
- backend_update_references(cbdata.state, cbdata.e);
-
- map_unlock();
- return 0;
-}
-
-struct backend_modify_entry_cbdata {
- struct plugin_state *state;
- Slapi_PBlock *pb;
- LDAPMod **mods;
- Slapi_Entry *e_pre, *e_post;
- char *ndn;
-};
-
-static bool_t
-backend_modify_entry_cb(const char *domain, const char *map, bool_t secure,
- void *backend_data, void *cbdata_ptr)
-{
- struct backend_map_data *map_data;
- struct backend_modify_entry_cbdata *cbdata;
-
- map_data = backend_data;
- cbdata = cbdata_ptr;
-
- /* 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,
- cbdata->state->plugin_desc->spd_id,
- "clearing group/container/id "
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->group, map_data->container,
- cbdata->ndn);
- map_data_unset_entry_id(cbdata->state,
- map_data->group, map_data->container,
- 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(cbdata->e_post, map_data);
- }
- return TRUE;
-}
-
-static int
-backend_modify_cb(Slapi_PBlock *pb)
-{
- Slapi_DN *sdn;
- struct backend_modify_entry_cbdata cbdata;
- slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
- 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.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,
- "pre-modify entry is NULL\n");
- return 0;
- }
- if (cbdata.e_post == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "post-modify entry is NULL\n");
- return 0;
- }
- /* Modify map entries which corresponded to this directory server
- * entry. */
- map_wrlock();
- if (!map_data_foreach_map(cbdata.state, NULL,
- backend_modify_entry_cb, &cbdata)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "error modifying map entries corresponding to "
- "\"%s\"\n", cbdata.ndn);
- }
- /* Update entries which need to be updated in case this entry
- * no longer refers to them. */
- backend_update_references(cbdata.state, cbdata.e_pre);
- /* Update entries which need to be updated in case this entry
- * now refers to them. */
- backend_update_references(cbdata.state, cbdata.e_post);
- /* If it's a map configuration entry, reconfigure, clear, and
- * 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.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.ndn);
- backend_map_config_entry_add_cb(cbdata.e_post, cbdata.state);
- }
- map_unlock();
- return 0;
-}
-
-struct backend_modrdn_entry_cbdata {
- struct plugin_state *state;
- Slapi_PBlock *pb;
- Slapi_Entry *e_pre, *e_post;
- char *ndn_pre, *ndn_post;
-};
-
-static bool_t
-backend_modrdn_entry_cb(const char *domain, const char *map, bool_t secure,
- void *backend_data, void *cbdata_ptr)
-{
- struct backend_map_data *map_data;
- struct backend_modrdn_entry_cbdata *cbdata;
- bool_t matched_pre, matched_post;
-
- map_data = backend_data;
- cbdata = cbdata_ptr;
-
- matched_pre = backend_entry_matches_map(map_data,
- cbdata->pb, cbdata->e_pre);
- matched_post = backend_entry_matches_map(map_data,
- cbdata->pb, cbdata->e_post);
-
- /* Now decide what to set, or unset, in this map. */
- if (matched_pre) {
- /* If it was a match for the map, clear the entry. */
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata->state->plugin_desc->spd_id,
- "clearing group/container/id "
- "\"%s\"/\"%s\"/(\"%s\")\n",
- map_data->group, map_data->container,
- cbdata->ndn_pre);
- map_data_unset_entry_id(cbdata->state,
- map_data->group, map_data->container,
- 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(cbdata->e_post, map_data);
- }
- return TRUE;
-}
-
-static int
-backend_modrdn_cb(Slapi_PBlock *pb)
-{
- struct backend_modrdn_entry_cbdata cbdata;
- 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.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.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,
- "pre-modrdn entry is NULL\n");
- return 0;
- }
- if (cbdata.e_post == NULL) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "post-modrdn entry is NULL\n");
- return 0;
- }
- /* Modify map entries which corresponded to this directory server
- * entry. */
- map_wrlock();
- if (!map_data_foreach_map(cbdata.state, NULL,
- backend_modrdn_entry_cb, &cbdata)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "error renaming map entries corresponding to "
- "\"%s\"\n", cbdata.ndn_post);
- }
- /* If it's a map configuration entry, reconfigure, clear, and
- * 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);
- 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,
- "renamed entry \"%s\" is now a map\n",
- cbdata.e_post);
- backend_map_config_entry_add_cb(cbdata.e_post, cbdata.state);
- }
- map_unlock();
- return 0;
-}
-
-/* Delete any map entries which correspond to a directory server entry in this
- * map. */
-
-struct backend_delete_entry_cbdata {
- struct plugin_state *state;
- Slapi_PBlock *pb;
- Slapi_Entry *e;
- char *ndn;
-};
-
-static bool_t
-backend_delete_entry_cb(const char *group, const char *container, bool_t secure,
- void *backend_data, void *cbdata_ptr)
+/* Re-read plugin-wide settings that may have changed. Nothing to do. */
+void
+backend_update_params(struct plugin_state *state)
{
- struct backend_map_data *map_data;
- struct backend_delete_entry_cbdata *cbdata;
- map_data = backend_data;
- cbdata = cbdata_ptr;
- /* 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,
- cbdata->state->plugin_desc->spd_id,
- "unsetting group/container/id"
- "\"%s\"/\"%s\"=\"%s\"/\"%s\"/(\"%s\")\n",
- group, container,
- map_data->group, map_data->container,
- cbdata->ndn);
- map_data_unset_entry_id(cbdata->state, group, container,
- cbdata->ndn);
- }
- return TRUE;
}
-/* Called by the server when a directory server entry is deleted. */
-static int
-backend_delete_cb(Slapi_PBlock *pb)
+/* Populate our data. */
+void
+backend_startup(struct plugin_state *state)
{
- struct backend_delete_entry_cbdata cbdata;
- slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &cbdata.state);
- 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.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,
- "deleted entry is NULL\n");
- return 0;
- }
- /* Remove map entries which corresponded to this directory server
- * entry. */
- map_wrlock();
- if (!map_data_foreach_map(cbdata.state, NULL,
- backend_delete_entry_cb, &cbdata)) {
- slapi_log_error(SLAPI_LOG_PLUGIN,
- cbdata.state->plugin_desc->spd_id,
- "error removing map entries corresponding to "
- "\"%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.ndn);
- backend_map_config_entry_delete_cb(cbdata.e, cbdata.state);
- }
- /* Update entries which need to be updated in case this entry no longer
- * refers to them. */
- backend_update_references(cbdata.state, cbdata.e);
- map_unlock();
- return 0;
+ backend_shr_startup(state, SCH_CONTAINER_CONFIGURATION_FILTER);
}
-/* Set our post-op callbacks. */
+/* Set up our post-op callbacks. */
void
backend_init(Slapi_PBlock *pb, struct plugin_state *state)
{
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "hooking up postoperation callbacks\n");
- if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN,
- backend_add_cb) != 0) {
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "error hooking up add callback\n");
- }
- if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
- backend_modify_cb) != 0) {
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "error hooking up modify callback\n");
- }
- if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN,
- backend_modrdn_cb) != 0) {
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "error hooking up modrdn callback\n");
- }
- if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
- backend_delete_cb) != 0) {
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "error hooking up delete callback\n");
- }
+ backend_shr_postop_init(pb, state);
}
diff --git a/src/back-shr.c b/src/back-shr.c
index 84f6a3b..2c6f358 100644
--- a/src/back-shr.c
+++ b/src/back-shr.c
@@ -250,8 +250,7 @@ backend_shr_set_config_free_config(void *cb_data)
{
struct backend_set_data *set_data;
set_data = cb_data;
- backend_set_config_free_config(backend_set_config_get_state(set_data),
- set_data);
+ backend_set_config_free_config(set_data);
}
int
@@ -344,16 +343,15 @@ backend_shr_startup(struct plugin_state *state, const char *filter)
/* Process a set configuration directory entry. Pull out the group and set
* names which are specified in the entry and delete each in turn. */
-static int
-backend_shr_set_config_entry_delete_cb(Slapi_Entry *e, void *callback_data,
- const char *group_attr,
- const char *set_attr)
+int
+backend_shr_set_config_entry_delete(struct plugin_state *state,
+ Slapi_Entry *e,
+ const char *group_attr,
+ const char *set_attr)
{
char **groups, **sets;
int i, j;
- struct plugin_state *state;
- state = callback_data;
groups = slapi_entry_attr_get_charray(e, group_attr);
sets = slapi_entry_attr_get_charray(e, set_attr);
for (i = 0; (groups != NULL) && (groups[i] != NULL); i++) {