ipa_hbac_rules.c revision 71ad247500b417836a1a2edec257a4433a7c415f
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Copyright (C) 2011 Red Hat
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher This program is free software; you can redistribute it and/or modify
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher it under the terms of the GNU General Public License as published by
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher (at your option) any later version.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher This program is distributed in the hope that it will be useful,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher GNU General Public License for more details.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher You should have received a copy of the GNU General Public License
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include "providers/ipa/ipa_hbac_private.h"
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek const char **attrs;
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozekipa_hbac_rule_info_done(struct tevent_req *subreq);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sysdb_attrs_get_string(ipa_host, SYSDB_ORIG_DN, &host_dn);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek DEBUG(1, ("Could not identify IPA hostname\n"));
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sss_filter_sanitize(tmp_ctx, host_dn, &host_dn_clean);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ipa_hbac_rule_state);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek state->attrs = talloc_zero_array(state, const char *, 15);
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek "(&(objectclass=%s)"
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek "(%s=%s)(|(%s=%s)(%s=%s)",
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek "(&(objectclass=%s)"
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek "(%s=%s)(%s=%s)"
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek "(|(%s=%s)(%s=%s)",
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* Add all parent groups of ipa_hostname to the filter */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sysdb_attrs_get_string_array(ipa_host, SYSDB_ORIG_MEMBEROF,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* This host is not a member of any hostgroups */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek memberof_list = talloc_array(tmp_ctx, const char *, 1);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek for (i = 0; memberof_list[i]; i++) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek rule_filter = talloc_asprintf_append(rule_filter, "(%s=%s)",
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek rule_filter = talloc_asprintf_append(rule_filter, "))");
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek state->rules_filter = talloc_steal(state, rule_filter);
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek base = state->search_bases[state->search_base_iter];
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek state->cur_filter = sdap_get_id_specific_filter(state,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, ("Sending request for next search base: "
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, ("sdap_get_generic_send failed.\n"));
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek tevent_req_set_callback(subreq, ipa_hbac_rule_info_done, req);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekipa_hbac_rule_info_done(struct tevent_req *subreq)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher tevent_req_callback_data(subreq, struct tevent_req);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher tevent_req_data(req, struct ipa_hbac_rule_state);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = sdap_get_generic_recv(subreq, state,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(3, ("Could not retrieve HBAC rules\n"));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher total_count = rule_count + state->rule_count;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher state->rules = talloc_realloc(state, state->rules,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher target = &state->rules[state->rule_count];
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher *target = talloc_steal(state->rules, rules[i]);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ipa_hbac_rule_info_next(req, state);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher } else if (ret == EOK && state->rule_count == 0) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(3, ("No rules apply to this host\n"));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* We went through all search bases and we have some results */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagheripa_hbac_rule_info_recv(struct tevent_req *req,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher tevent_req_data(req, struct ipa_hbac_rule_state);