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