summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-07-01 13:42:31 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-07-01 13:42:31 -0400
commita1da2533b6bc0828ff49d459c0ba316a159f6497 (patch)
tree0499bf371b4bcd35e3dcc031e10f7fd41fd556d4 /src
parentaecb9050e5d95383fea2622090691fe63f99697c (diff)
downloadslapi-nis-a1da2533b6bc0828ff49d459c0ba316a159f6497.tar.gz
slapi-nis-a1da2533b6bc0828ff49d459c0ba316a159f6497.tar.xz
slapi-nis-a1da2533b6bc0828ff49d459c0ba316a159f6497.zip
- we're generating proper entries now. not storing them anywhere, but one thing
at a time
Diffstat (limited to 'src')
-rw-r--r--src/back-sch.c131
-rw-r--r--src/backend.h2
2 files changed, 114 insertions, 19 deletions
diff --git a/src/back-sch.c b/src/back-sch.c
index e7e582b..c141551 100644
--- a/src/back-sch.c
+++ b/src/back-sch.c
@@ -56,6 +56,9 @@
struct backend_set_data {
struct backend_shr_set_data common;
/* Schema compatibility-specific data. */
+ char *container_dn;
+ char *rdn_format;
+ char **attribute_format;
};
/* Read the name of the NIS master. A dummy function for the schema
@@ -84,6 +87,8 @@ backend_set_config_free_config_contents(void *data)
format_free_attr_list(set_data->common.ref_attrs);
format_free_inref_attrs(set_data->common.inref_attrs);
free(set_data->common.entry_filter);
+ free(set_data->rdn_format);
+ backend_shr_free_strlist(set_data->attribute_format);
}
}
void
@@ -112,10 +117,14 @@ backend_copy_set_config(const struct backend_set_data *data)
format_dup_inref_attrs(data->common.inref_attrs) :
NULL;
ret->common.entry_filter = strdup(data->common.entry_filter);
+ ret->container_dn = strdup(data->container_dn);
+ ret->rdn_format = strdup(data->rdn_format);
+ ret->attribute_format = backend_shr_dup_strlist(data->attribute_format);
if ((ret->common.group == NULL) ||
(ret->common.set == NULL) ||
(ret->common.bases == NULL) ||
- (ret->common.entry_filter == NULL)) {
+ (ret->common.entry_filter == NULL) ||
+ (ret->container_dn == NULL)) {
backend_set_config_free_config(&ret->common);
return NULL;
}
@@ -129,7 +138,7 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e,
const char *group, const char *container,
bool_t *flag, struct backend_shr_set_data **pret)
{
- char **bases, *entry_filter;
+ char **bases, *entry_filter, **attributes, *rdn_format;
char *actual_attr;
const char *cvalue;
int i, j, disposition, buffer_flags, count;
@@ -182,6 +191,37 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e,
}
slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
}
+ rdn_format = NULL;
+ if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_RDN_ATTR,
+ &values,
+ &disposition, &actual_attr,
+ 0, &buffer_flags) == 0) {
+ i = slapi_valueset_first_value(values, &value);
+ if (i != -1) {
+ cvalue = slapi_value_get_string(value);
+ rdn_format = strdup(cvalue);
+ }
+ slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
+ }
+ attributes = NULL;
+ if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_ATTR_ATTR,
+ &values,
+ &disposition, &actual_attr,
+ 0, &buffer_flags) == 0) {
+ count = slapi_valueset_count(values);
+ attributes = malloc(sizeof(char *) * (count + 1));
+ if (attributes != NULL) {
+ i = 0;
+ for (j = slapi_valueset_first_value(values, &value);
+ j != -1;
+ j = slapi_valueset_next_value(values, j, &value)) {
+ cvalue = slapi_value_get_string(value);
+ attributes[i++] = strdup(cvalue);
+ }
+ attributes[i] = NULL;
+ }
+ slapi_vattr_values_free(&values, &actual_attr, buffer_flags);
+ }
/* Populate the returned structure. */
ret.common.state = state;
ret.common.group = strdup(group);
@@ -190,6 +230,9 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e,
ret.common.entry_filter = entry_filter;
ret.common.ref_attrs = NULL;
ret.common.inref_attrs = NULL;
+ ret.container_dn = slapi_dn_plus_rdn(ret.common.group, ret.common.set);
+ ret.rdn_format = rdn_format;
+ ret.attribute_format = attributes;
*pret = backend_copy_set_config(&ret);
free(ret.common.group);
free(ret.common.set);
@@ -200,6 +243,14 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e,
free(ret.common.bases);
}
free(ret.common.entry_filter);
+ slapi_ch_free((void **) &ret.container_dn);
+ if (ret.attribute_format != NULL) {
+ for (i = 0; ret.attribute_format[i] != NULL; i++) {
+ free(ret.attribute_format[i]);
+ }
+ free(ret.attribute_format);
+ }
+ free(ret.rdn_format);
}
/* Given a map-entry directory entry, determine a key, a value, and extra data
@@ -207,29 +258,71 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e,
void
backend_set_entry_one(Slapi_Entry *e, struct backend_set_data *data)
{
- char *ldif, *ndn, *plugin_id, *ndns[2];
+ char *dn, *rdn, *ndn, *ldif, *plugin_id, *keys[2], **ava, *val;
+ int len, i, j;
+ Slapi_Entry *entry;
+
plugin_id = data->common.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->common.state, e,
- data->common.group, data->common.set,
- "", NULL,
- &data->common.ref_attrs,
- &data->common.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) {
+ /* Generate the RDN for the entry. */
+ rdn = format_get_data(data->common.state, e,
+ data->common.group, data->common.set,
+ data->rdn_format, NULL,
+ &data->common.ref_attrs,
+ &data->common.inref_attrs);
+ /* Now build the entry itself, and set the DN first. */
+ entry = slapi_entry_alloc();
+ dn = slapi_dn_plus_rdn(data->container_dn, rdn);
+ slapi_entry_set_dn(entry, dn); /* NOTE: the entry now owns the dn */
+ /* Iterate through the set of attributes. */
+ if (data->attribute_format != NULL) {
+ for (i = 0; data->attribute_format[i] != NULL; i++) {
+ ava = format_get_data_set(data->common.state, e,
+ data->common.group,
+ data->common.set,
+ data->attribute_format[i],
+ NULL,
+ &data->common.ref_attrs,
+ &data->common.inref_attrs);
+ if (ava != NULL) {
+ for (j = 0; ava[j] != NULL; j++) {
+ val = strchr(ava[j], '=');
+ if (val != NULL) {
+ *val = '\0';
+ slapi_entry_add_string(entry,
+ ava[j],
+ val + 1);
+ *val = '=';
+ }
+ }
+ format_free_data_set(ava);
+ }
+ }
+ }
+ /* Try to make the entry look "right". */
+ if (!slapi_entry_rdn_values_present(entry)) {
+ slapi_entry_add_rdn_values(entry);
+ }
+ /* Perform a schema check. */
+ if (slapi_entry_schema_check(NULL, entry) != 0) {
+ slapi_entry_add_string(entry,
+ "objectClass", "extensibleObject");
+ }
+ /* Produce some LDIF. */
+ ldif = slapi_entry2str(entry, &len);
+ /* If we actually generated a useful new entry for this entry, then set
+ * it, otherwise clear it in case there was one set before. */
+ if ((rdn != NULL) && (ldif != NULL)) {
slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id,
"setting group/container/key/value "
"\"%s\"/\"%s\"/\"%s\"(\"%s\")=\"%s\"\n",
data->common.group, data->common.set,
- ndn, ndn, ldif);
+ rdn, ndn, ldif);
+ keys[0] = rdn;
+ keys[1] = NULL;
map_data_set_entry(data->common.state,
data->common.group, data->common.set, ndn,
- NULL, ndns, -1, ldif,
+ NULL, keys, len, ldif,
NULL, NULL);
} else {
slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id,
@@ -239,8 +332,10 @@ backend_set_entry_one(Slapi_Entry *e, struct backend_set_data *data)
map_data_unset_entry_id(data->common.state,
data->common.group, data->common.set,
ndn);
+ slapi_entry_free(entry);
}
- format_free_data(ldif);
+ slapi_ch_free((void **) &ldif);
+ format_free_data(rdn);
}
/* Process a set configuration directory entry. Pull out the group and
diff --git a/src/backend.h b/src/backend.h
index a216f2d..5924d78 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -4,7 +4,7 @@ struct backend_set_data;
struct plugin_state;
struct inref_attr;
-/* Common data. */
+/* Configuration data common to all backends. */
struct backend_shr_set_data {
struct plugin_state *state;
char *group, *set, **bases, *entry_filter;