diff options
Diffstat (limited to 'src/back-sch.c')
-rw-r--r-- | src/back-sch.c | 270 |
1 files changed, 48 insertions, 222 deletions
diff --git a/src/back-sch.c b/src/back-sch.c index 29216c8..f93cb14 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -155,100 +155,17 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e, Slapi_Value *value; /* Read the values from the configuration entry. */ - bases = NULL; - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_BASE_ATTR, - &values, - &disposition, &actual_attr, - 0, &buffer_flags) == 0) { - count = slapi_valueset_count(values); - bases = malloc(sizeof(char *) * (count + 1)); - if (bases != 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); - bases[i++] = strdup(cvalue); - } - bases[i] = NULL; - } - slapi_vattr_values_free(&values, &actual_attr, buffer_flags); - } - entry_filter = NULL; - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_FILTER_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); - if (strlen(cvalue) > 1) { - if ((cvalue[0] != '(') || - (cvalue[strlen(cvalue) - 1] != ')')) { - entry_filter = malloc(strlen(cvalue) + - 3); - if (entry_filter != NULL) { - sprintf(entry_filter, "(%s)", - cvalue); - } - } - } - if (entry_filter == NULL) { - entry_filter = strdup(cvalue); - } - } - 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); - } - check_access = TRUE; - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_ACCESS_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); - /* FIXME: use nl_langinfo(YESEXPR) here? */ - if ((strcasecmp(cvalue, "yes") == 0) || - (strcasecmp(cvalue, "on") == 0) || - (strcasecmp(cvalue, "1") == 0)) { - check_access = TRUE; - } else { - check_access = FALSE; - } - } - 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); - } + bases = backend_shr_get_vattr_strlist(state, e, + SCH_CONTAINER_CONFIGURATION_BASE_ATTR); + entry_filter = backend_shr_get_vattr_filter(state, e, + SCH_CONTAINER_CONFIGURATION_FILTER_ATTR); + rdn_format = backend_shr_get_vattr_str(state, e, + SCH_CONTAINER_CONFIGURATION_RDN_ATTR); + check_access = backend_shr_get_vattr_boolean(state, e, + SCH_CONTAINER_CONFIGURATION_ACCESS_ATTR, + TRUE); + attributes = backend_shr_get_vattr_strlist(state, e, + SCH_CONTAINER_CONFIGURATION_ATTR_ATTR); /* Populate the returned structure. */ ret.common.state = state; ret.common.group = strdup(group); @@ -265,20 +182,10 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e, *pret = backend_copy_set_config(&ret); free(ret.common.group); free(ret.common.set); - if (ret.common.bases != NULL) { - for (i = 0; ret.common.bases[i] != NULL; i++) { - free(ret.common.bases[i]); - } - free(ret.common.bases); - } + backend_shr_free_strlist(ret.common.bases); free(ret.common.entry_filter); slapi_sdn_free(&ret.container_sdn); - if (ret.attribute_format != NULL) { - for (i = 0; ret.attribute_format[i] != NULL; i++) { - free(ret.attribute_format[i]); - } - free(ret.attribute_format); - } + backend_shr_free_strlist(ret.attribute_format); free(ret.rdn_format); } @@ -312,11 +219,13 @@ void backend_set_entry(Slapi_Entry *e, struct backend_set_data *data) { char *dn, *rdn, *ndn, *ldif, *plugin_id, *keys[2], **ava, *val; + unsigned int rdn_len, *ava_lens; const char *rdnstr; int len, i, j; Slapi_Entry *entry; Slapi_DN *e_dn; Slapi_RDN *srdn; + Slapi_Value *value; plugin_id = data->common.state->plugin_desc->spd_id; e_dn = slapi_entry_get_sdn(e); @@ -326,13 +235,15 @@ backend_set_entry(Slapi_Entry *e, struct backend_set_data *data) data->common.group, data->common.set, data->rdn_format, NULL, &data->common.ref_attrs, - &data->common.inref_attrs); + &data->common.inref_attrs, + &rdn_len); /* Now build the entry itself, and set the DN first. */ entry = slapi_entry_alloc(); dn = slapi_dn_plus_rdn(slapi_sdn_get_ndn(data->container_sdn), 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) { + value = slapi_value_new(); for (i = 0; data->attribute_format[i] != NULL; i++) { ava = format_get_data_set(data->common.state, e, data->common.group, @@ -340,21 +251,31 @@ backend_set_entry(Slapi_Entry *e, struct backend_set_data *data) data->attribute_format[i], NULL, &data->common.ref_attrs, - &data->common.inref_attrs); - if (ava != NULL) { + &data->common.inref_attrs, + &ava_lens); + if ((ava != NULL) && + (ava_lens != NULL) && + (value != NULL)) { for (j = 0; ava[j] != NULL; j++) { - val = strchr(ava[j], '='); + val = memchr(ava[j], '=', + ava_lens[j]); if ((val != NULL) && (val[1] != '\0')) { *val = '\0'; - slapi_entry_add_string(entry, - ava[j], - val + 1); + slapi_value_set(value, + val + 1, + ava_lens[j] - + (val - ava[j]) - + 1); + slapi_entry_add_value(entry, + ava[j], + value); *val = '='; } } - format_free_data_set(ava); + format_free_data_set(ava, ava_lens); } } + slapi_value_free(&value); } /* Try to make the entry look "right". */ if (!slapi_entry_rdn_values_present(entry)) { @@ -393,7 +314,8 @@ backend_set_entry(Slapi_Entry *e, struct backend_set_data *data) keys[1] = NULL; map_data_set_entry(data->common.state, data->common.group, data->common.set, ndn, - NULL, keys, -1, slapi_entry_get_ndn(entry), + &rdn_len, keys, + -1, slapi_entry_get_ndn(entry), backend_entry_make_entry_data(e_dn, entry), backend_entry_free_entry_data); } else { @@ -423,42 +345,10 @@ backend_set_config_entry_add_cb(Slapi_Entry *e, void *callback_data) struct plugin_state *state; state = callback_data; - groups = NULL; - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_GROUP_ATTR, - &values, - &disposition, &actual_attr, - 0, &buffer_flags) == 0) { - count = slapi_valueset_count(values); - groups = malloc(sizeof(char *) * (count + 1)); - if (groups != NULL) { - for (i = slapi_valueset_first_value(values, &value); - i != -1; - i = slapi_valueset_next_value(values, i, &value)) { - cvalue = slapi_value_get_string(value); - groups[i] = strdup(cvalue); - } - groups[count] = NULL; - } - slapi_vattr_values_free(&values, &actual_attr, buffer_flags); - } - containers = NULL; - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR, - &values, - &disposition, &actual_attr, - 0, &buffer_flags) == 0) { - count = slapi_valueset_count(values); - containers = malloc(sizeof(char *) * (count + 1)); - if (containers != NULL) { - for (i = slapi_valueset_first_value(values, &value); - i != -1; - i = slapi_valueset_next_value(values, i, &value)) { - cvalue = slapi_value_get_string(value); - containers[i] = strdup(cvalue); - } - containers[count] = NULL; - } - slapi_vattr_values_free(&values, &actual_attr, buffer_flags); - } + groups = backend_shr_get_vattr_strlist(state, e, + SCH_CONTAINER_CONFIGURATION_GROUP_ATTR); + containers = backend_shr_get_vattr_strlist(state, e, + SCH_CONTAINER_CONFIGURATION_CONTAINER_ATTR); for (i = 0; (groups != NULL) && (groups[i] != NULL); i++) { for (j = 0; (containers != NULL) && (containers[j] != NULL); @@ -468,20 +358,8 @@ backend_set_config_entry_add_cb(Slapi_Entry *e, void *callback_data) containers[j]); } } - if (groups != NULL) { - for (i = 0; (groups != NULL) && (groups[i] != NULL); i++) { - free(groups[i]); - } - free(groups); - } - if (containers != NULL) { - for (i = 0; - (containers != NULL) && (containers[i] != NULL); - i++) { - free(containers[i]); - } - free(containers); - } + backend_shr_free_strlist(containers); + backend_shr_free_strlist(groups); return 0; } @@ -509,76 +387,24 @@ void backend_free_set_config(char **bases, char *entry_filter) { int i; - if (bases != NULL) { - for (i = 0; bases[i] != NULL; i++) { - free(bases[i]); - } - free(bases); - } + backend_shr_free_strlist(bases); free(entry_filter); } static bool_t backend_get_set_config_entry_cb(Slapi_Entry *e, void *callback_data) { - Slapi_ValueSet *values; - Slapi_Value *value; struct backend_get_set_config_cb *cbdata; - char *actual_attr; - const char *cvalue; - int disposition, buffer_flags, i, count, len; 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)); - - values = NULL; - value = NULL; - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_BASE_ATTR, - &values, - &disposition, &actual_attr, - 0, &buffer_flags) == 0) { - count = slapi_valueset_count(values); - cbdata->bases = malloc(sizeof(char *) * (count + 1)); - if (cbdata->bases != NULL) { - for (i = slapi_valueset_first_value(values, &value); - i != -1; - i = slapi_valueset_next_value(values, i, &value)) { - cvalue = slapi_value_get_string(value); - cbdata->bases[i] = strdup(cvalue); - } - cbdata->bases[count] = NULL; - } - slapi_vattr_values_free(&values, &actual_attr, buffer_flags); - } - if (slapi_vattr_values_get(e, SCH_CONTAINER_CONFIGURATION_FILTER_ATTR, - &values, - &disposition, &actual_attr, - 0, &buffer_flags) == 0) { - if (slapi_valueset_first_value(values, &value) != -1) { - cvalue = slapi_value_get_string(value); - if (cvalue != NULL) { - free(cbdata->entry_filter); - cbdata->entry_filter = NULL; - if ((cvalue[0] != '(') || - (cvalue[strlen(cvalue) - 1] != ')')) { - len = strlen(cvalue) + 3; - cbdata->entry_filter = malloc(len); - if (cbdata->entry_filter != NULL) { - sprintf(cbdata->entry_filter, - "(%s)", cvalue); - } - } - if (cbdata->entry_filter == NULL) { - cbdata->entry_filter = strdup(cvalue); - } - } - } - slapi_vattr_values_free(&values, &actual_attr, buffer_flags); - } - + 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_BASE_ATTR); return TRUE; } |