From 0c9d67d8154069c76e04e838bb30114080481cd2 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 7 Aug 2013 10:26:32 -0400 Subject: Handle locking failures Handle cases where we fail to acquire locks. --- src/back-sch.c | 101 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/src/back-sch.c b/src/back-sch.c index 0b90ff6..a2ea291 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -1291,8 +1291,7 @@ backend_search_cb(Slapi_PBlock *pb) } else { slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id, - "unable to acquire read lock, " - "ignoring search\n"); + "unable to acquire read lock\n"); } wrap_dec_call_level(); #ifdef USE_NSSWITCH @@ -1313,48 +1312,76 @@ backend_search_cb(Slapi_PBlock *pb) } staged = staged->next; } + cbdata.nsswitch_buffer_len = 0; + free(cbdata.nsswitch_buffer); /* Add the entries to the map cache */ wrap_inc_call_level(); - map_wrlock(); - staged = cbdata.staged; - while (staged != NULL) { - if (staged->entries != NULL) { - cbdata.cur_staged = staged; - /* We actually need to find the original set first */ - map_data_foreach_domain(cbdata.state, backend_search_find_set_data_cb, &cbdata); - for (i = 0; i < staged->count ; i++) { - if (staged->entries[i] != NULL) { - if ((cbdata.cur_staged->set_data != NULL) && - !map_data_check_entry(cbdata.state, - staged->map_group, staged->map_set, - slapi_sdn_get_ndn(slapi_entry_get_sdn(staged->entries[i])))) { - backend_set_entry_from(cbdata.pb, backend_entry_source_nsswitch, - staged->entries[i], staged->set_data); + if (map_wrlock() == 0) { + staged = cbdata.staged; + while (staged != NULL) { + if (staged->entries != NULL) { + cbdata.cur_staged = staged; + /* We actually need to find the original set first */ + map_data_foreach_domain(cbdata.state, backend_search_find_set_data_cb, &cbdata); + for (i = 0; i < staged->count; i++) { + if (staged->entries[i] != NULL) { + if ((cbdata.cur_staged->set_data != NULL) && + !map_data_check_entry(cbdata.state, + staged->map_group, staged->map_set, + slapi_sdn_get_ndn(slapi_entry_get_sdn(staged->entries[i])))) { + backend_set_entry_from(cbdata.pb, backend_entry_source_nsswitch, + staged->entries[i], staged->set_data); + } + slapi_entry_free(staged->entries[i]); + staged->entries[i] = NULL; } - slapi_entry_free(staged->entries[i]); - staged->entries[i] = NULL; } + free(staged->entries); + staged->count = 0; + staged->entries = NULL; + } + slapi_ch_free_string(&staged->map_group); + slapi_ch_free_string(&staged->map_set); + slapi_ch_free_string(&staged->name); + slapi_ch_free_string(&staged->container_sdn); + next = staged->next; + free(staged); + staged = next; + } + cbdata.staged = NULL; + map_unlock(); + } else { + slapi_log_error(SLAPI_LOG_PLUGIN, + cbdata.state->plugin_desc->spd_id, + "unable to acquire write lock\n"); + while (staged != NULL) { + for (i = 0; + (i < staged->count) && + (staged->entries != NULL) && + (staged->entries[i] != NULL); + i++) { + slapi_entry_free(staged->entries[i]); + staged->entries[i] = NULL; } - free(staged->entries); - staged->count = 0; - staged->entries = NULL; + slapi_ch_free_string(&staged->map_group); + slapi_ch_free_string(&staged->map_set); + slapi_ch_free_string(&staged->name); + slapi_ch_free_string(&staged->container_sdn); + next = staged->next; + free(staged); + staged = next; } - slapi_ch_free_string(&staged->map_group); - slapi_ch_free_string(&staged->map_set); - slapi_ch_free_string(&staged->name); - slapi_ch_free_string(&staged->container_sdn); - next = staged->next; - free(staged); - staged = next; } - cbdata.staged = NULL; - map_unlock(); - cbdata.nsswitch_buffer_len = 0; - free(cbdata.nsswitch_buffer); /* Perform search again, this time to collect the data added by the NSSWITCH search */ - map_rdlock(); - map_data_foreach_domain(cbdata.state, backend_search_group_cb, &cbdata); - map_unlock(); + if (map_rdlock() == 0) { + map_data_foreach_domain(cbdata.state, backend_search_group_cb, &cbdata); + map_unlock(); + } else { + slapi_log_error(SLAPI_LOG_PLUGIN, + cbdata.state->plugin_desc->spd_id, + "unable to acquire read lock, " + "ignoring search\n"); + } wrap_dec_call_level(); } #endif @@ -1691,8 +1718,8 @@ backend_bind_cb(Slapi_PBlock *pb) slapi_ch_free_string(&group); slapi_ch_free_string(&username); } else { -done_with_lock: map_unlock(); +done_with_lock: wrap_dec_call_level(); if (backend_check_scope_pb(pb)) { slapi_send_ldap_result(pb, LDAP_INVALID_CREDENTIALS, -- cgit