diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-07-01 14:35:43 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-07-01 14:35:43 -0400 |
| commit | 3edb8fbfbf5fa9ae86bfb787a30b30813409d36e (patch) | |
| tree | 216dcf4a6d116d2a192504f2e5e444a91aabed3a /src | |
| parent | a1da2533b6bc0828ff49d459c0ba316a159f6497 (diff) | |
| download | slapi-nis-3edb8fbfbf5fa9ae86bfb787a30b30813409d36e.tar.gz slapi-nis-3edb8fbfbf5fa9ae86bfb787a30b30813409d36e.tar.xz slapi-nis-3edb8fbfbf5fa9ae86bfb787a30b30813409d36e.zip | |
- format_referrer: don't try to free a non-heap string if we can't find a
configuration for the referred-to map
- free map configurations correctly
- if needed, wrap a user-supplied filter in "()" when the formatter asks for
the filter
Diffstat (limited to 'src')
| -rw-r--r-- | src/back-nis.c | 24 | ||||
| -rw-r--r-- | src/back-sch.c | 55 | ||||
| -rw-r--r-- | src/format.c | 30 |
3 files changed, 84 insertions, 25 deletions
diff --git a/src/back-nis.c b/src/back-nis.c index ced47db..1361cb0 100644 --- a/src/back-nis.c +++ b/src/back-nis.c @@ -801,7 +801,13 @@ struct backend_get_set_config_cb { void backend_free_set_config(char **bases, char *entry_filter) { - backend_shr_free_strlist(bases); + int i; + if (bases != NULL) { + for (i = 0; bases[i] != NULL; i++) { + free(bases[i]); + } + free(bases); + } free(entry_filter); } @@ -813,7 +819,7 @@ backend_get_set_config_entry_cb(Slapi_Entry *e, void *callback_data) struct backend_get_set_config_cb *cbdata; char *actual_attr; const char *cvalue; - int disposition, buffer_flags, i, count; + int disposition, buffer_flags, i, count, len; cbdata = callback_data; slapi_log_error(SLAPI_LOG_PLUGIN, @@ -846,7 +852,19 @@ backend_get_set_config_entry_cb(Slapi_Entry *e, void *callback_data) cvalue = slapi_value_get_string(value); if (cvalue != NULL) { free(cbdata->entry_filter); - cbdata->entry_filter = strdup(cvalue); + 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); diff --git a/src/back-sch.c b/src/back-sch.c index c141551..a744681 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -60,6 +60,9 @@ struct backend_set_data { char *rdn_format; char **attribute_format; }; +struct backend_entry_data { + Slapi_Entry *e; +}; /* Read the name of the NIS master. A dummy function for the schema * compatibility plugin. */ @@ -253,6 +256,28 @@ backend_set_config_read_config(struct plugin_state *state, Slapi_Entry *e, free(ret.rdn_format); } +/* Create and destroy entry-specific data. */ +static struct backend_entry_data * +backend_entry_make_entry_data(Slapi_Entry *e) +{ + struct backend_entry_data *ret; + ret = malloc(sizeof(*ret)); + if (ret != NULL) { + ret->e = e; + } else { + slapi_entry_free(e); + } + return ret; +} +static void +backend_entry_free_entry_data(void *p) +{ + struct backend_entry_data *data; + data = p; + slapi_entry_free(data->e); + free(data); +} + /* 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 @@ -287,7 +312,7 @@ backend_set_entry_one(Slapi_Entry *e, struct backend_set_data *data) if (ava != NULL) { for (j = 0; ava[j] != NULL; j++) { val = strchr(ava[j], '='); - if (val != NULL) { + if ((val != NULL) && (val[1] != '\0')) { *val = '\0'; slapi_entry_add_string(entry, ava[j], @@ -303,7 +328,6 @@ backend_set_entry_one(Slapi_Entry *e, struct backend_set_data *data) 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"); @@ -323,7 +347,8 @@ backend_set_entry_one(Slapi_Entry *e, struct backend_set_data *data) map_data_set_entry(data->common.state, data->common.group, data->common.set, ndn, NULL, keys, len, ldif, - NULL, NULL); + backend_entry_make_entry_data(entry), + backend_entry_free_entry_data); } else { slapi_log_error(SLAPI_LOG_PLUGIN, plugin_id, "no value for %s, unsetting domain/map/id" @@ -437,7 +462,13 @@ struct backend_get_set_config_cb { void backend_free_set_config(char **bases, char *entry_filter) { - backend_shr_free_strlist(bases); + int i; + if (bases != NULL) { + for (i = 0; bases[i] != NULL; i++) { + free(bases[i]); + } + free(bases); + } free(entry_filter); } @@ -449,7 +480,7 @@ backend_get_set_config_entry_cb(Slapi_Entry *e, void *callback_data) struct backend_get_set_config_cb *cbdata; char *actual_attr; const char *cvalue; - int disposition, buffer_flags, i, count; + int disposition, buffer_flags, i, count, len; cbdata = callback_data; slapi_log_error(SLAPI_LOG_PLUGIN, @@ -484,7 +515,19 @@ backend_get_set_config_entry_cb(Slapi_Entry *e, void *callback_data) cvalue = slapi_value_get_string(value); if (cvalue != NULL) { free(cbdata->entry_filter); - cbdata->entry_filter = strdup(cvalue); + 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); diff --git a/src/format.c b/src/format.c index 82dac70..8366af9 100644 --- a/src/format.c +++ b/src/format.c @@ -712,7 +712,7 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, int i, ret, argc; Slapi_PBlock *local_pb; char **argv, *attrs[2], *filter, *tndn; - char *map_filter, **map_bases; + char *set_filter, **set_bases, *use_filter; struct format_referred_cbdata cbdata; ret = format_parse_args(state, args, &argc, &argv); @@ -749,13 +749,10 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, cbdata.ret = 0; /* Retrieve the map-specific paramters. */ - map_filter = NULL; - map_bases = NULL; - backend_get_set_config(state, group, argv[1], &map_bases, &map_filter); - if (map_filter == NULL) { - map_filter = "(objectClass=*)"; - } - if (map_bases == NULL) { + set_filter = NULL; + set_bases = NULL; + backend_get_set_config(state, group, argv[1], &set_bases, &set_filter); + if (set_bases == NULL) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "no search bases defined for \"%s\"/\"%s\"?\n", @@ -772,30 +769,31 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "referred: out of memory\n"); - backend_free_set_config(map_bases, map_filter); + backend_free_set_config(set_bases, set_filter); slapi_pblock_destroy(local_pb); format_free_parsed_args(argv); return -ENOMEM; } /* Now just search through the entries used for the map. */ - for (i = 0; (map_bases != NULL) && (map_bases[i] != NULL); i++) { + use_filter = set_filter ? set_filter : "(objectClass=*)"; + for (i = 0; (set_bases != NULL) && (set_bases[i] != NULL); i++) { /* Build the search filter. */ - filter = malloc(strlen(map_filter) + strlen(argv[2]) + + filter = malloc(strlen(use_filter) + strlen(argv[2]) + strlen(tndn) + 7); if (filter == NULL) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "referred: out of memory\n"); - backend_free_set_config(map_bases, map_filter); + backend_free_set_config(set_bases, set_filter); slapi_pblock_destroy(local_pb); format_free_parsed_args(argv); return -ENOMEM; } - sprintf(filter, "(&(%s=%s)%s)", argv[2], tndn, map_filter); + sprintf(filter, "(&(%s=%s)%s)", argv[2], tndn, use_filter); /* Set up the search. */ slapi_search_internal_set_pb(local_pb, - map_bases[i], LDAP_SCOPE_SUB, + set_bases[i], LDAP_SCOPE_SUB, filter, attrs, FALSE, NULL, NULL, state->plugin_identity, 0); @@ -803,7 +801,7 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "searching under \"%s\" for \"%s\"\n", - map_bases[i], filter); + set_bases[i], filter); slapi_search_internal_callback_pb(local_pb, &cbdata, NULL, format_referred_entry_cb, @@ -816,7 +814,7 @@ format_referred(struct plugin_state *state, Slapi_PBlock *pb, Slapi_Entry *e, } free(tndn); - backend_free_set_config(map_bases, map_filter); + backend_free_set_config(set_bases, set_filter); slapi_pblock_destroy(local_pb); format_free_parsed_args(argv); return cbdata.ret ? cbdata.ret : cbdata.outbuf - outbuf; |
