sdap_async_sudo.c revision 6ea68b049dd507409d454100978ee125febc69ea
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Async LDAP Helper routines for sudo
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Pavel Březina <pbrezina@redhat.com>
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Copyright (C) 2012 Red Hat
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny This program is free software; you can redistribute it and/or modify
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny it under the terms of the GNU General Public License as published by
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny the Free Software Foundation; either version 3 of the License, or
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny (at your option) any later version.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny This program is distributed in the hope that it will be useful,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny GNU General Public License for more details.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny You should have received a copy of the GNU General Public License
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs **ldap_rules; /* search result will be stored here */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t ldap_rules_count; /* search result will be stored here */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char **attrs;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *filter;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic int sdap_sudo_refresh_retry(struct tevent_req *req);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenystatic void sdap_sudo_refresh_connect_done(struct tevent_req *subreq);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenystatic struct tevent_req * sdap_sudo_load_sudoers_send(TALLOC_CTX *mem_ctx,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t sdap_sudo_load_sudoers_next_base(struct tevent_req *req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void sdap_sudo_load_sudoers_process(struct tevent_req *subreq);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenystatic int sdap_sudo_load_sudoers_recv(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void sdap_sudo_load_sudoers_done(struct tevent_req *subreq);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic int sdap_sudo_purge_sudoers(struct sysdb_ctx *sysdb_ctx,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *filter,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic int sdap_sudo_store_sudoers(TALLOC_CTX *mem_ctx,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenystruct tevent_req *sdap_sudo_refresh_send(TALLOC_CTX *mem_ctx,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny req = tevent_req_create(mem_ctx, &state, struct sdap_sudo_refresh_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* if we don't have a search filter, this request is meaningless */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->ldap_filter = talloc_strdup(state, ldap_filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->sysdb_filter = talloc_strdup(state, sysdb_filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (sysdb_filter != NULL && state->sysdb_filter == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* asynchronous processing */
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher state = tevent_req_data(req, struct sdap_sudo_refresh_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *usn = talloc_steal(mem_ctx, state->highest_usn);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic int sdap_sudo_refresh_retry(struct tevent_req *req)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state = tevent_req_data(req, struct sdap_sudo_refresh_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->sdap_op = sdap_id_op_create(state, state->sdap_conn_cache);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny DEBUG(SSSDBG_CRIT_FAILURE, ("sdap_id_op_create() failed\n"));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_id_op_connect_send(state->sdap_op, state, &ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ("sdap_id_op_connect_send() failed: %d(%s)\n", ret, strerror(ret)));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_set_callback(subreq, sdap_sudo_refresh_connect_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void sdap_sudo_refresh_connect_done(struct tevent_req *subreq)
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny struct tevent_req *req = NULL; /* req from sdap_sudo_refresh_send() */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny req = tevent_req_callback_data(subreq, struct tevent_req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state = tevent_req_data(req, struct sdap_sudo_refresh_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sdap_id_op_connect_recv(subreq, &dp_error);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ("SUDO LDAP connection failed - %s\n", strerror(ret)));
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny DEBUG(SSSDBG_TRACE_FUNC, ("SUDO LDAP connection successful\n"));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_sudo_load_sudoers_send(state, state->be_ctx->ev,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny tevent_req_set_callback(subreq, sdap_sudo_load_sudoers_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic struct tevent_req * sdap_sudo_load_sudoers_send(TALLOC_CTX *mem_ctx,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_sudo_load_sudoers_state *state = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny req = tevent_req_create(mem_ctx, &state, struct sdap_sudo_load_sudoers_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->timeout = dp_opt_get_int(opts->basic, SDAP_SEARCH_TIMEOUT);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ("SUDOERS lookup request without a search base\n"));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* create attrs from map */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = build_attrs_from_map(state, opts->sudorule_map, SDAP_OPTS_SUDO,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* begin search */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t sdap_sudo_load_sudoers_next_base(struct tevent_req *req)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_sudo_load_sudoers_state *state = NULL;
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek state = tevent_req_data(req, struct sdap_sudo_load_sudoers_state);
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek search_base = state->search_bases[state->base_iter];
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek /* should not happen */
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, ("search_base is null\n"));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* create filter */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny filter = sdap_get_id_specific_filter(state, state->filter,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* send request */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ("Searching for sudo rules with base [%s]\n",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_set_callback(subreq, sdap_sudo_load_sudoers_process, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void sdap_sudo_load_sudoers_process(struct tevent_req *subreq)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_sudo_load_sudoers_state *state = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny req = tevent_req_callback_data(subreq, struct tevent_req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state = tevent_req_data(req, struct sdap_sudo_load_sudoers_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny search_base = state->search_bases[state->base_iter];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ("Receiving sudo rules with base [%s]\n",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sdap_get_generic_recv(subreq, state, &count, &attrs);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* add rules to result */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->ldap_rules = talloc_realloc(state, state->ldap_rules,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (i = 0; i < count; i++) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->ldap_rules[state->ldap_rules_count + i] = talloc_steal(
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* go to next base */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* we are done */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic int sdap_sudo_load_sudoers_recv(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_sudo_load_sudoers_state *state = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state = tevent_req_data(req, struct sdap_sudo_load_sudoers_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *rules = talloc_steal(mem_ctx, state->ldap_rules);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void sdap_sudo_load_sudoers_done(struct tevent_req *subreq)
int ret;
bool in_transaction = false;
goto done;
goto done;
in_transaction = true;
goto done;
goto done;
in_transaction = false;
done:
if (in_transaction) {
const char *filter,
const char *name;
return EOK;
for (i = 0; i < rules_count; i++) {
&name);
goto done;
done:
return ret;
int cache_timeout,
char **_usn)
return EOK;
_usn);
return ret;
return EOK;