summaryrefslogtreecommitdiffstats
path: root/src/backend.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend.c')
-rw-r--r--src/backend.c87
1 files changed, 69 insertions, 18 deletions
diff --git a/src/backend.c b/src/backend.c
index bb4d38d..a004eae 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -24,6 +24,66 @@ struct backend_map_data {
char *domain, *map, **bases, *filter, *key_fmt, *value_fmt;
};
+/* Read the name of the NIS master. */
+void
+backend_free_master_name(struct plugin_state *state, char *master)
+{
+ free(master);
+}
+
+int
+backend_read_master_name(struct plugin_state *state, char **master)
+{
+ Slapi_DN *config_dn;
+ Slapi_Entry *config;
+ Slapi_ValueSet *values;
+ Slapi_Value *value;
+ char *attrs[] = {"nsslapd-localhost", NULL}, *actual_attr;
+ const char *cvalue;
+ int disposition, buffer_flags;
+ *master = NULL;
+ /* Try to read our name from the top-level configuration node. */
+ config_dn = slapi_sdn_new_dn_byval("cn=config");
+ if (config_dn == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "backend_master_name: "
+ "error parsing \"cn=config\"\n");
+ return -1;
+ }
+ config = NULL;
+ slapi_search_internal_get_entry(config_dn, attrs, &config,
+ state->plugin_identity);
+ if (config == NULL) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "backend_master_name: failure reading "
+ "\"cn=config\"");
+ slapi_sdn_free(&config_dn);
+ return -1;
+ }
+ slapi_sdn_free(&config_dn);
+ /* Pull out the attribute. */
+ if (slapi_vattr_values_get(config, attrs[0], &values,
+ &disposition, &actual_attr,
+ 0, &buffer_flags) == 0) {
+ if (slapi_valueset_first_value(values, &value) == 0) {
+ cvalue = slapi_value_get_string(value);
+ if (cvalue != NULL) {
+ *master = strdup(cvalue);
+ }
+ } else {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ state->plugin_desc->spd_id,
+ "backend_master_name: no \"%s\" value "
+ "for \"cn=config\"",
+ attrs[0]);
+ }
+ slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
+ }
+ slapi_entry_free(config);
+ return (*master != NULL) ? 0 : -1;
+}
static char **
backend_dup_strlist(char **strlist)
{
@@ -363,7 +423,8 @@ backend_startup(struct plugin_state *state)
/* Our postoperation callbacks. */
static PRBool
-backend_entry_matches_map(struct backend_map_data *map_data, Slapi_Entry *e)
+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;
@@ -406,7 +467,7 @@ backend_entry_matches_map(struct backend_map_data *map_data, Slapi_Entry *e)
if (filter == NULL) {
return PR_FALSE;
} else {
- if (slapi_filter_test_simple(e, filter) != 0) {
+ if (slapi_vattr_filter_test(pb, e, filter, 0) != 0) {
/* Didn't match -- return. */
slapi_filter_free(filter, 1);
return PR_FALSE;
@@ -440,7 +501,7 @@ backend_add_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->e)) {
+ if (!backend_entry_matches_map(map_data, cbdata->pb, cbdata->e)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
map_data->state->plugin_desc->spd_id,
"entry \"%s\" does not belong in "
@@ -537,7 +598,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->e)) {
+ if (!backend_entry_matches_map(map_data, cbdata->pb, cbdata->e)) {
slapi_log_error(SLAPI_LOG_PLUGIN,
map_data->state->plugin_desc->spd_id,
"clearing domain/map/id "
@@ -644,8 +705,10 @@ backend_modrdn_entry_cb(const char *domain, const char *map, void *backend_data,
map_data = backend_data;
cbdata = cbdata_ptr;
- matched_pre = backend_entry_matches_map(map_data, cbdata->e_pre);
- matched_post = backend_entry_matches_map(map_data, cbdata->e_post);
+ 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);
/* Pull out the key and value for the old entry. */
key_pre = format_get_data(cbdata->state, cbdata->pb, cbdata->e_pre,
@@ -855,15 +918,3 @@ backend_init(Slapi_PBlock *pb, struct plugin_state *state)
"error hooking up delete callback\n");
}
}
-
-void *
-xmemdup(char *region, int size)
-{
- char *ret;
- ret = malloc(size + 1);
- if (ret != NULL) {
- memcpy(ret, region, size);
- ret[size] = '\0';
- }
- return ret;
-}