ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny/*
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny SSSD
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Authors:
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Jan Zeleny <jzeleny@redhat.com>
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny Copyright (C) 2012 Red Hat
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
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
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
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*/
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "util/util.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "db/sysdb.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "providers/ldap/sdap_async.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "providers/ipa/ipa_hosts.h"
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include "providers/ipa/ipa_common.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystruct ipa_host_state {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_context *ev;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_ctx *sysdb;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_handle *sh;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_options *opts;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char **attrs;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny struct sdap_attr_map *host_map;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny struct sdap_attr_map *hostgroup_map;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_search_base **search_bases;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int search_base_iter;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char *cur_filter;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char *host_filter;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *hostname;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Return values */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t host_count;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs **hosts;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t hostgroup_count;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs **hostgroups;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny struct sdap_attr_map_info *ipa_hostgroup_map;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny};
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_host_info_done(struct tevent_req *subreq);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_hostgroup_info_done(struct tevent_req *subreq);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_host_info_next(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_hostgroup_info_next(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny/**
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
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystruct tevent_req *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_host_info_send(TALLOC_CTX *mem_ctx,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_context *ev,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_handle *sh,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_options *opts,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *hostname,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny struct sdap_attr_map *host_map,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny struct sdap_attr_map *hostgroup_map,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_search_base **search_bases)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny errno_t ret;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_req *req;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny req = tevent_req_create(mem_ctx, &state, struct ipa_host_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (req == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->ev = ev;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->sh = sh;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->opts = opts;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostname = hostname;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->search_bases = search_bases;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->search_base_iter = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->cur_filter = NULL;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->host_map = host_map;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map = hostgroup_map;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
ca4b7b92738f3dd463914e3de5757cd98d37a983Stephen Gallagher ret = build_attrs_from_map(state, host_map, IPA_OPTS_HOST,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny NULL, &state->attrs, NULL);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if (ret != EOK) {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny goto immediate;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (hostname == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->host_filter = talloc_asprintf(state, "(objectClass=%s)",
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny host_map[IPA_OC_HOST].name);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->host_filter = talloc_asprintf(state, "(&(objectClass=%s)(%s=%s))",
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny host_map[IPA_OC_HOST].name,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny host_map[IPA_AT_HOST_FQDN].name,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny hostname);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->host_filter == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = ENOMEM;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny goto immediate;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = ipa_host_info_next(req, state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret == EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No host search base configured?\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = EINVAL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EAGAIN) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny goto immediate;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return req;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyimmediate:
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret == EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_done(req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_post(req, ev);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return req;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t ipa_host_info_next(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_search_base *base;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_req *subreq;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny base = state->search_bases[state->search_base_iter];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (base == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EOK;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(state->cur_filter);
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->cur_filter = sdap_combine_filters(state, state->host_filter,
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina base->filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->cur_filter == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return ENOMEM;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_get_generic_send(state, state->ev, state->opts,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->sh, base->basedn,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny base->scope, state->cur_filter,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->attrs, state->host_map,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny IPA_OPTS_HOST,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny dp_opt_get_int(state->opts->basic,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher SDAP_ENUM_SEARCH_TIMEOUT),
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher true);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error requesting host info\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(state->cur_filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EIO;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_set_callback(subreq, ipa_host_info_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EAGAIN;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_host_info_done(struct tevent_req *subreq)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny errno_t ret;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_req *req =
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state =
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_data(req, struct ipa_host_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *host_dn;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sdap_get_generic_recv(subreq, state,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny &state->host_count,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny &state->hosts);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(subreq);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->host_count == 0) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->search_base_iter++;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = ipa_host_info_next(req, state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret == EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* No more search bases to try */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ENOENT);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else if (ret != EAGAIN) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if (state->hostgroup_map) {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny talloc_free(state->attrs);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny ret = build_attrs_from_map(state, state->hostgroup_map,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny IPA_OPTS_HOSTGROUP, NULL,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny &state->attrs, NULL);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if (ret != EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Look up host groups */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->hostname == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(state->host_filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->host_filter = talloc_asprintf(state, "(objectClass=%s)",
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map[IPA_OC_HOSTGROUP].name);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->host_filter == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ENOMEM);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->search_base_iter = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = ipa_hostgroup_info_next(req, state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret == EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No host search base configured?\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, EINVAL);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else if (ret != EAGAIN) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->ipa_hostgroup_map = talloc_zero(state, struct sdap_attr_map_info);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if (state->ipa_hostgroup_map == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ENOMEM);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->ipa_hostgroup_map->map = state->hostgroup_map;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->ipa_hostgroup_map->num_attrs = IPA_OPTS_HOSTGROUP;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sysdb_attrs_get_string(state->hosts[0], SYSDB_ORIG_DN, &host_dn);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta if (!sdap_has_deref_support(state->sh, state->opts)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Server does not support deref\n");
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta tevent_req_error(req, EIO);
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta return;
4709ff46db0dbe073aef061b796d2fd7adeaf18fJan Cholasta }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_deref_search_send(state, state->ev, state->opts, state->sh,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny host_dn,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map[IPA_AT_HOSTGROUP_MEMBER_OF].name,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->attrs,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny 1, state->ipa_hostgroup_map,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny dp_opt_get_int(state->opts->basic,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny SDAP_ENUM_SEARCH_TIMEOUT));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error requesting host info\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, EIO);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
74f857536411b46712f9b3dc0f1c53924b36dc02Stephen Gallagher tevent_req_set_callback(subreq, ipa_hostgroup_info_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Nothing else to do, just complete the req */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_done(req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic errno_t ipa_hostgroup_info_next(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_search_base *base;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_req *subreq;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny base = state->search_bases[state->search_base_iter];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (base == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EOK;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(state->cur_filter);
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina state->cur_filter = sdap_combine_filters(state, state->host_filter,
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina base->filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->cur_filter == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return ENOMEM;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny base->basedn, base->scope,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->cur_filter, state->attrs,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny IPA_OPTS_HOSTGROUP,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny dp_opt_get_int(state->opts->basic,
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher SDAP_ENUM_SEARCH_TIMEOUT),
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher true);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error requesting hostgroup info\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(state->cur_filter);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EIO;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_set_callback(subreq, ipa_hostgroup_info_done, req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EAGAIN;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyipa_hostgroup_info_done(struct tevent_req *subreq)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny errno_t ret;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct tevent_req *req =
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_callback_data(subreq, struct tevent_req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state =
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_data(req, struct ipa_host_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t hostgroups_total;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t hostgroup_count;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs **hostgroups;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sdap_deref_attrs **deref_result;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *hostgroup_name;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *hostgroup_dn;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int i, j;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->hostname == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sdap_get_generic_recv(subreq, state,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny &hostgroup_count,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny &hostgroups);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(subreq);
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek if (ret != EOK) {
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "sdap_get_generic_recv failed: [%d]\n", ret);
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek tevent_req_error(req, ret);
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek return;
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Merge the two arrays */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (hostgroup_count > 0) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny hostgroups_total = hostgroup_count + state->hostgroup_count;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups = talloc_realloc(state, state->hostgroups,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs *,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny hostgroups_total);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->hostgroups == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ENOMEM);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny i = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny while(state->hostgroup_count < hostgroups_total) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups[state->hostgroup_count] =
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_steal(state->hostgroups, hostgroups[i]);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroup_count++;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny i++;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Now look in the next base */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->search_base_iter++;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = ipa_hostgroup_info_next(req, state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK && ret != EAGAIN) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Only continue if no error occurred
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * and no req was created */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sdap_deref_search_recv(subreq, state,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny &state->hostgroup_count,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny &deref_result);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_zfree(subreq);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK) goto done;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->hostgroup_count == 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "No host groups were dereferenced\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups = talloc_zero_array(state, struct sysdb_attrs *,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroup_count);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (state->hostgroups == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = ENOMEM;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny goto done;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny j = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (i = 0; i < state->hostgroup_count; i++) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sysdb_attrs_get_string(deref_result[i]->attrs,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny SYSDB_ORIG_DN, &hostgroup_dn);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK) goto done;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (!sss_ldap_dn_in_search_bases(state, hostgroup_dn,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->search_bases,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny NULL)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny continue;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ret = sysdb_attrs_get_string(deref_result[i]->attrs,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny state->hostgroup_map[IPA_AT_HOSTGROUP_NAME].sys_name,
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny &hostgroup_name);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret != EOK) goto done;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "Dereferenced host group: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov hostgroup_name);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroups[j] = talloc_steal(state->hostgroups,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny deref_result[i]->attrs);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny j++;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny state->hostgroup_count = j;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenydone:
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (ret == EOK) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_done(req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Error [%d][%s]\n", ret, strerror(ret));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_error(req, ret);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyerrno_t ipa_host_info_recv(struct tevent_req *req,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny TALLOC_CTX *mem_ctx,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t *host_count,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs ***hosts,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t *hostgroup_count,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct sysdb_attrs ***hostgroups)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t c;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny struct ipa_host_state *state =
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny tevent_req_data(req, struct ipa_host_state);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *host_count = state->host_count;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *hosts = talloc_steal(mem_ctx, state->hosts);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (c = 0; c < state->host_count; c++) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Guarantee the memory heirarchy of the list */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny talloc_steal(state->hosts, state->hosts[c]);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
1a7d1977037864e52858058777af8ff8401547ddJan Cholasta if (hostgroup_count) *hostgroup_count = state->hostgroup_count;
1a7d1977037864e52858058777af8ff8401547ddJan Cholasta if (hostgroups) *hostgroups = talloc_steal(mem_ctx, state->hostgroups);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return EOK;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}