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"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagheripa_hbac_rule_info_done(struct tevent_req *subreq);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagheripa_hbac_rule_info_send(TALLOC_CTX *mem_ctx,
b054e7d8c43b024ee33e9343b4a15e124861f68cFabiano Fidêncio req = tevent_req_create(mem_ctx, &state, struct ipa_hbac_rule_state);
b054e7d8c43b024ee33e9343b4a15e124861f68cFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create failed.\n");
b054e7d8c43b024ee33e9343b4a15e124861f68cFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Missing host\n");
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = sysdb_attrs_get_string(ipa_host, SYSDB_ORIG_DN, &host_dn);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not identify IPA hostname\n");
b054e7d8c43b024ee33e9343b4a15e124861f68cFabiano Fidêncio ret = sss_filter_sanitize(state, host_dn, &host_dn_clean);
71ad247500b417836a1a2edec257a4433a7c415fJan Zeleny state->attrs = talloc_zero_array(state, const char *, 15);
6dff95bdfe437afc0b62b5270d0d84140981c786Jakub Hrozek "(&(objectclass=%s)"
6dff95bdfe437afc0b62b5270d0d84140981c786Jakub Hrozek "(%s=%s)(%s=%s)"
6dff95bdfe437afc0b62b5270d0d84140981c786Jakub Hrozek "(|(%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,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik DEBUG(SSSDBG_CRIT_FAILURE, "Could not identify.\n");
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* This host is not a member of any hostgroups */
b054e7d8c43b024ee33e9343b4a15e124861f68cFabiano Fidêncio memberof_list = talloc_array(state, 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);
dd6a4fb9ae4825caf4ccb835f8b8221c96bbb6f5Fabiano Fidêncio /* ipa_hbac_rule_info_next should always have a search base when
dd6a4fb9ae4825caf4ccb835f8b8221c96bbb6f5Fabiano Fidêncio * called for the first time.
dd6a4fb9ae4825caf4ccb835f8b8221c96bbb6f5Fabiano Fidêncio * For the subsequent iterations, not finding any more search bases
dd6a4fb9ae4825caf4ccb835f8b8221c96bbb6f5Fabiano Fidêncio * is fine though (thus the function returns EOK).
dd6a4fb9ae4825caf4ccb835f8b8221c96bbb6f5Fabiano Fidêncio * As, here, it's the first case happening, let's return EINVAL.
85a93ca67ae020607006cd035170c9360fb0a450Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "No search base found\n");
71ad247500b417836a1a2edec257a4433a7c415fJan Zeleny base = state->search_bases[state->search_base_iter];
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->cur_filter = sdap_combine_filters(state, state->rules_filter,
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,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "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) {
85517b57685809ff96818bbd3e3b4678ac74b461Fabiano Fidêncio DEBUG(SSSDBG_TRACE_FUNC, "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);