From efad6a64030a7586a65e57697305141eddf63f81 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Tue, 6 Aug 2013 16:51:02 -0400 Subject: Renames and fix a memory leak Rename backend_staged_data to backend_staged_search. Fix some formatting. Change how we walk the list of entries retrieved using a staged search so that if the map's been removed since the search was staged, we still free the temporary entry structures. --- src/back-sch-nss.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/back-sch-nss.c') diff --git a/src/back-sch-nss.c b/src/back-sch-nss.c index a45d42d..c8aaa20 100644 --- a/src/back-sch-nss.c +++ b/src/back-sch-nss.c @@ -465,20 +465,20 @@ repeat: return entries; } -/* Check filter for a component like (uid=) and if found, - * stage NSSWITCH lookup. Lookup will be performed later, with call to backend_retrieve_from_nsswitch */ +/* Check if the filter is one (like uid=) that should trigger an + * nsswitch lookup, and if it is, make a note that we should perform such a + * lookup. */ void backend_search_nsswitch(struct backend_set_data *set_data, struct backend_search_cbdata *cbdata) { int result, rc; struct backend_search_filter_config config = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL}; - struct backend_staged_data *staged = NULL; + struct backend_staged_search *staged = NULL; char *idptr = NULL; unsigned long id; - /* There was no match but we asked to check NSSWITCH */ - /* First, we search the filter to see if it includes cn|uid= check */ + /* First, we search the filter to see if it includes a cn|uid= test. */ result = slapi_filter_apply(cbdata->filter, backend_search_filter_has_cn_uid, &config, &rc); if ((result != SLAPI_FILTER_SCAN_STOP)) { @@ -515,22 +515,21 @@ backend_search_nsswitch(struct backend_set_data *set_data, } } - - staged = malloc(sizeof(struct backend_staged_data)); + staged = malloc(sizeof(*staged)); if (staged == NULL) { goto fail; } staged->map_group = slapi_ch_strdup(set_data->common.group); staged->map_set = slapi_ch_strdup(set_data->common.set); - staged->set_data_fixup = NULL; + staged->set_data = NULL; staged->count = 0; staged->entries = NULL; staged->container_sdn = slapi_ch_strdup(slapi_sdn_get_dn(set_data->container_sdn)); staged->type = cbdata->check_nsswitch; - staged->name = config.name; + staged->name = config.name; /* takes ownership */ staged->is_id = config.search_gid || config.search_uid; staged->search_members = config.search_members; @@ -543,9 +542,10 @@ fail: return; } - /* perform look up against NSSWITCH and create entry based on that */ + /* Actually look up the information that we previously noted that we should, + * then convert whatever we find into one or more Slapi_Entry pointers. */ bool_t -backend_retrieve_from_nsswitch(struct backend_staged_data *staged, +backend_retrieve_from_nsswitch(struct backend_staged_search *staged, struct backend_search_cbdata *cbdata) { Slapi_Entry *entry, **entries; @@ -554,7 +554,7 @@ backend_retrieve_from_nsswitch(struct backend_staged_data *staged, if (((staged->type == SCH_NSSWITCH_GROUP) && staged->search_members) && (NULL != staged->name)) { entries = backend_retrieve_group_list_from_nsswitch(staged->name, staged->container_sdn, - cbdata, &staged->count); + cbdata, &staged->count); if (entries != NULL) { staged->entries = entries; for (i = 0; i < staged->count; i++) { @@ -567,11 +567,11 @@ backend_retrieve_from_nsswitch(struct backend_staged_data *staged, if ((staged->type == SCH_NSSWITCH_GROUP) && (NULL != staged->name)) { entry = backend_retrieve_group_entry_from_nsswitch(staged->name, staged->is_id, - staged->container_sdn, - cbdata); - if (entry) { + staged->container_sdn, + cbdata); + if (entry != NULL) { slapi_entry_add_string(entry, "schema-compat-origin", "nsswitch"); - staged->entries = malloc(sizeof(Slapi_Entry *)); + staged->entries = malloc(sizeof(staged->entries[0])); if (staged->entries != NULL) { staged->entries[0] = entry; staged->count = 1; @@ -585,11 +585,11 @@ backend_retrieve_from_nsswitch(struct backend_staged_data *staged, if ((staged->type == SCH_NSSWITCH_USER) && (NULL != staged->name)) { entry = backend_retrieve_user_entry_from_nsswitch(staged->name, staged->is_id, - staged->container_sdn, - cbdata); - if (entry) { + staged->container_sdn, + cbdata); + if (entry != NULL) { slapi_entry_add_string(entry, "schema-compat-origin", "nsswitch"); - staged->entries = malloc(sizeof(Slapi_Entry *)); + staged->entries = malloc(sizeof(staged->entries[0])); if (staged->entries != NULL) { staged->entries[0] = entry; staged->count = 1; -- cgit