diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/back-sch.c | 112 |
1 files changed, 82 insertions, 30 deletions
diff --git a/src/back-sch.c b/src/back-sch.c index 1a4107e..57c21e2 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -51,7 +51,7 @@ #include "plugin.h" #include "map.h" -#define SCH_CONTAINER_CONFIGURATION_FILTER "(&(objectClass=*)(" SCH_CONTAINER_CONFIGURATION_GROUP_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_BASE_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_FILTER_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_RDN_ATTR "=*))" +#define SCH_CONTAINER_CONFIGURATION_FILTER "(&(" SCH_CONTAINER_CONFIGURATION_GROUP_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_BASE_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_FILTER_ATTR "=*)(" SCH_CONTAINER_CONFIGURATION_RDN_ATTR "=*))" /* The data we ask the map cache to keep, for us, for each set. */ struct backend_set_data { @@ -116,8 +116,8 @@ backend_copy_set_config(const struct backend_set_data *data) } ret->common.self = ret; ret->common.state = data->common.state; - ret->common.group = strdup(data->common.group); - ret->common.set = strdup(data->common.set); + ret->common.group = slapi_dn_normalize(strdup(data->common.group)); + ret->common.set = slapi_dn_normalize(strdup(data->common.set)); ret->common.bases = backend_shr_dup_strlist(data->common.bases); ret->common.ref_attrs = data->common.ref_attrs ? format_dup_attr_list(data->common.ref_attrs) : @@ -443,8 +443,10 @@ backend_set_config_entry_delete_cb(Slapi_Entry *e, void *callback_data) /* Functions for passing information about a container's configuration to the * formatting functions. */ -struct backend_get_set_config_cb { +struct backend_get_set_config_if_matching_cb { struct plugin_state *state; + Slapi_DN *groupdn, *setrdn; + Slapi_DN *search_groupdn, *search_setrdn; char **bases; char *entry_filter; }; @@ -457,19 +459,39 @@ backend_free_set_config(char **bases, char *entry_filter) } static bool_t -backend_get_set_config_entry_cb(Slapi_Entry *e, void *callback_data) +backend_get_set_config_entry_if_matching_cb(Slapi_Entry *e, void *callback_data) { - struct backend_get_set_config_cb *cbdata; + struct backend_get_set_config_if_matching_cb *cbdata; + char **groups, **sets; + int i, j; cbdata = callback_data; - slapi_log_error(SLAPI_LOG_PLUGIN, - cbdata->state->plugin_desc->spd_id, - "reading container configuration from \"%s\"\n", - slapi_entry_get_ndn(e)); - cbdata->bases = backend_shr_get_vattr_strlist(cbdata->state, e, - SCH_CONTAINER_CONFIGURATION_BASE_ATTR); - cbdata->entry_filter = backend_shr_get_vattr_filter(cbdata->state, e, - SCH_CONTAINER_CONFIGURATION_FILTER_ATTR); + groups = backend_shr_get_vattr_strlist(cbdata->state, e, SCH_CONTAINER_CONFIGURATION_GROUP_ATTR); + sets = backend_shr_get_vattr_strlist(cbdata->state, e, SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR); + if ((groups == NULL) || (sets == NULL)) { + backend_shr_free_strlist(groups); + backend_shr_free_strlist(sets); + return TRUE; + } + for (i = 0; (groups[i] != NULL); i++) { + cbdata->groupdn = slapi_sdn_set_dn_byval(cbdata->groupdn, groups[i]); + for (j = 0; (sets[j] != NULL); j++) { + cbdata->setrdn = slapi_sdn_set_dn_byval(cbdata->setrdn, sets[j]); + if ((slapi_sdn_compare(cbdata->groupdn, cbdata->search_groupdn) == 0) && + (slapi_sdn_compare(cbdata->setrdn, cbdata->search_setrdn) == 0)) { + slapi_log_error(SLAPI_LOG_PLUGIN, + cbdata->state->plugin_desc->spd_id, + "reading container configuration from \"%s\"\n", + slapi_entry_get_ndn(e)); + cbdata->bases = backend_shr_get_vattr_strlist(cbdata->state, e, + SCH_CONTAINER_CONFIGURATION_BASE_ATTR); + cbdata->entry_filter = backend_shr_get_vattr_filter(cbdata->state, e, + SCH_CONTAINER_CONFIGURATION_FILTER_ATTR); + } + } + } + backend_shr_free_strlist(groups); + backend_shr_free_strlist(sets); return TRUE; } @@ -479,37 +501,62 @@ backend_get_set_config(struct plugin_state *state, char ***bases, char **entry_filter) { Slapi_PBlock *pb; - char *filter; char *attrs[] = {SCH_CONTAINER_CONFIGURATION_FILTER_ATTR, SCH_CONTAINER_CONFIGURATION_BASE_ATTR, NULL}; - struct backend_get_set_config_cb cbdata; + Slapi_DN *groupdn, *setrdn; + struct backend_get_set_config_if_matching_cb cbdata; /* Build the search filter. */ - filter = malloc(strlen("(&(" - SCH_CONTAINER_CONFIGURATION_GROUP_ATTR "=)(" - SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR "=)" - ")") + - strlen(group) + strlen(container) + - strlen(SCH_CONTAINER_CONFIGURATION_FILTER) + 1); - if (filter == NULL) { + groupdn = slapi_sdn_new_dn_byval(group); + if (groupdn == NULL) { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "out of memory reading configuration for " + "\"%s\"/\"%s\"!\n", group, container); + return; + } + setrdn = slapi_sdn_new_dn_byval(container); + if (setrdn == NULL) { + slapi_sdn_free(&groupdn); + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "out of memory reading configuration for " + "\"%s\"/\"%s\"!\n", group, container); + return; + } + cbdata.groupdn = slapi_sdn_new(); + if (cbdata.groupdn == NULL) { + slapi_sdn_free(&setrdn); + slapi_sdn_free(&groupdn); + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "out of memory reading configuration for " + "\"%s\"/\"%s\"!\n", group, container); + return; + } + cbdata.setrdn = slapi_sdn_new(); + if (cbdata.setrdn == NULL) { + slapi_sdn_free(&cbdata.groupdn); + slapi_sdn_free(&setrdn); + slapi_sdn_free(&groupdn); slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "out of memory reading configuration for " "\"%s\"/\"%s\"!\n", group, container); return; } - sprintf(filter, "(&(" - SCH_CONTAINER_CONFIGURATION_GROUP_ATTR "=%s)(" - SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR "=%s)%s)", - group, container, SCH_CONTAINER_CONFIGURATION_FILTER); /* Perform the search. */ + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "searching from \"%s\" for \"%s\" for configuration\n", + state->plugin_base, SCH_CONTAINER_CONFIGURATION_FILTER); pb = slapi_pblock_new(); slapi_search_internal_set_pb(pb, state->plugin_base, LDAP_SCOPE_SUBTREE, - filter, + SCH_CONTAINER_CONFIGURATION_FILTER, attrs, FALSE, NULL, NULL, @@ -518,9 +565,11 @@ backend_get_set_config(struct plugin_state *state, cbdata.bases = NULL; cbdata.state = state; cbdata.entry_filter = NULL; + cbdata.search_groupdn = groupdn; + cbdata.search_setrdn = setrdn; slapi_search_internal_callback_pb(pb, &cbdata, NULL, - backend_get_set_config_entry_cb, + backend_get_set_config_entry_if_matching_cb, NULL); /* Return the results. */ @@ -528,7 +577,10 @@ backend_get_set_config(struct plugin_state *state, *entry_filter = cbdata.entry_filter; /* Clean up. */ - free(filter); + slapi_sdn_free(&cbdata.setrdn); + slapi_sdn_free(&cbdata.groupdn); + slapi_sdn_free(&setrdn); + slapi_sdn_free(&groupdn); slapi_pblock_destroy(pb); } |