ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Jan Zeleny <jzeleny@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 /* Return values */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_hostgroup_info_done(struct tevent_req *subreq);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * hostname == NULL -> look up all hosts / host groups
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * hostname != NULL -> look up only given host and groups
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * it's member of
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * hostgroup_map == NULL -> skip looking up hostgroups
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny req = tevent_req_create(mem_ctx, &state, struct ipa_host_state);
60a715a0dd79873d2d2607eab8fdfaf0ffd2e7d3Hristo Venev subreq = sdap_host_info_send(mem_ctx, ev, sh, opts, hostname, host_map,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_set_callback(subreq, ipa_host_info_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny ret = build_attrs_from_map(state, state->hostgroup_map,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Look up host groups */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->host_filter = talloc_asprintf(state, "(objectClass=%s)",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No host search base configured?\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sysdb_attrs_get_string(state->hosts[0], SYSDB_ORIG_DN, &host_dn);
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta if (!sdap_has_deref_support(state->sh, state->opts)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Server does not support deref\n");
60a715a0dd79873d2d2607eab8fdfaf0ffd2e7d3Hristo Venev maps = talloc_array(state, struct sdap_attr_map_info, num_maps + 1);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_deref_search_send(state, state->ev, state->opts, state->sh,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map[IPA_AT_HOSTGROUP_MEMBER_OF].name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error requesting host info\n");
74f857536411b46712f9b3dc0f1c53924b36dc02Stephen Gallagher tevent_req_set_callback(subreq, ipa_hostgroup_info_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Nothing else to do, just complete the req */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t ipa_hostgroup_info_next(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny base = state->search_bases[state->search_base_iter];
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->cur_filter = sdap_combine_filters(state, state->host_filter,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error requesting hostgroup info\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_set_callback(subreq, ipa_hostgroup_info_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_hostgroup_info_done(struct tevent_req *subreq)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "sdap_get_generic_recv failed: [%d]\n", ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Merge the two arrays */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny hostgroups_total = hostgroup_count + state->hostgroup_count;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups = talloc_realloc(state, state->hostgroups,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny while(state->hostgroup_count < hostgroups_total) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Now look in the next base */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Only continue if no error occurred
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * and no req was created */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "No host groups were dereferenced\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups = talloc_zero_array(state, struct sysdb_attrs *,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sysdb_attrs_get_string(deref_result[i]->attrs,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (!sss_ldap_dn_in_search_bases(state, hostgroup_dn,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sysdb_attrs_get_string(deref_result[i]->attrs,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map[IPA_AT_HOSTGROUP_NAME].sys_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "Dereferenced host group: %s\n",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups[j] = talloc_steal(state->hostgroups,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Error [%d][%s]\n", ret, strerror(ret));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyerrno_t ipa_host_info_recv(struct tevent_req *req,
1a7d1977037864e52858058777af8ff8401547ddJan Cholasta if (hostgroup_count) *hostgroup_count = state->hostgroup_count;