ipa_hosts.c revision ad07ed37b6b51ef134d4524edaf2259e19ac984f
842ae4bd224140319ae7feec1872b93dfd491143fielding/*
842ae4bd224140319ae7feec1872b93dfd491143fielding SSSD
842ae4bd224140319ae7feec1872b93dfd491143fielding
842ae4bd224140319ae7feec1872b93dfd491143fielding Authors:
842ae4bd224140319ae7feec1872b93dfd491143fielding Jan Zeleny <jzeleny@redhat.com>
842ae4bd224140319ae7feec1872b93dfd491143fielding
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb Copyright (C) 2012 Red Hat
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb This program is free software; you can redistribute it and/or modify
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd it under the terms of the GNU General Public License as published by
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd the Free Software Foundation; either version 3 of the License, or
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd (at your option) any later version.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This program is distributed in the hope that it will be useful,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb but WITHOUT ANY WARRANTY; without even the implied warranty of
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb GNU General Public License for more details.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh You should have received a copy of the GNU General Public License
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb along with this program. If not, see <http://www.gnu.org/licenses/>.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh*/
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util/util.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "db/sysdb.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "providers/ldap/sdap_async.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "providers/ipa/ipa_hosts.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* FIXME: this is temporary, use proper map instead */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "providers/ipa/ipa_hbac_private.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstruct ipa_host_state {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct tevent_context *ev;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sysdb_ctx *sysdb;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sdap_handle *sh;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sdap_options *opts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char **attrs;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sdap_search_base **search_bases;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int search_base_iter;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *cur_filter;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *host_filter;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *hostname;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Return values */
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames size_t host_count;
750d12c59545dbbac70390988de94f7e901b08f2niq struct sysdb_attrs **hosts;
82632a19f2f9c346fee2b28a65920ba9737b3973minfrin
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb bool fetch_hostgroups;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb size_t hostgroup_count;
db455cbc662c98dbbf53175393c50086ff63370cchrisd struct sysdb_attrs **hostgroups;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sdap_attr_map_info *hostgroup_map;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb};
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define HOSTGROUP_MAP_ATTRS_COUNT 5
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic struct sdap_attr_map hostgroup_map[] = {
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf {"objectclass", "ipahostgroup", "hostgroup", NULL},
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf {"name_attr", IPA_CN, IPA_CN, NULL},
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb {"member", IPA_MEMBER, SYSDB_ORIG_MEMBER, NULL},
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz {"memberof", IPA_MEMBEROF, SYSDB_ORIG_MEMBEROF, NULL},
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz {"ipa_id", IPA_UNIQUE_ID, IPA_UNIQUE_ID, NULL}
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz};
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzstatic void
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzipa_host_info_done(struct tevent_req *subreq);
18b5268e013574026b2503b1641baf3299045f45sf
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzstatic void
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzipa_hostgroup_info_done(struct tevent_req *subreq);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic errno_t
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbipa_host_info_next(struct tevent_req *req,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct ipa_host_state *state);
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerstatic errno_t
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweipa_hostgroup_info_next(struct tevent_req *req,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker struct ipa_host_state *state);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerstruct tevent_req *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbipa_host_info_send(TALLOC_CTX *mem_ctx,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker struct tevent_context *ev,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sysdb_ctx *sysdb,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker struct sdap_handle *sh,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sdap_options *opts,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker const char *hostname,
18b5268e013574026b2503b1641baf3299045f45sf const char **attrs,
18b5268e013574026b2503b1641baf3299045f45sf bool fetch_hostgroups,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct sdap_search_base **search_bases)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb errno_t ret;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker struct ipa_host_state *state;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker struct tevent_req *req;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd req = tevent_req_create(mem_ctx, &state, struct ipa_host_state);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (req == NULL) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return NULL;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi state->ev = ev;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe state->sysdb = sysdb;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe state->sh = sh;
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick state->opts = opts;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar state->hostname = hostname;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe state->search_bases = search_bases;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe state->search_base_iter = 0;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar state->cur_filter = NULL;
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf state->attrs = attrs;
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf state->fetch_hostgroups = fetch_hostgroups;
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (hostname == NULL) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar state->host_filter = talloc_asprintf(state, "(objectClass=%s)",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe IPA_HOST);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe } else {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe state->host_filter = talloc_asprintf(state, "(&(objectClass=%s)(%s=%s))",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe IPA_HOST, IPA_HOST_FQDN, hostname);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (state->host_filter == NULL) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ret = ENOMEM;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe goto immediate;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ret = ipa_host_info_next(req, state);
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf if (ret == EOK) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe DEBUG(SSSDBG_CRIT_FAILURE, ("No host search base configured?\n"));
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ret = EINVAL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar if (ret != EAGAIN) {
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar goto immediate;
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar return req;
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzimmediate:
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar if (ret == EOK) {
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar tevent_req_done(req);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar } else {
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar tevent_req_error(req, ret);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar tevent_req_post(req, ev);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar return req;
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar}
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzstatic errno_t ipa_host_info_next(struct tevent_req *req,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe struct ipa_host_state *state)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe struct sdap_search_base *base;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe struct tevent_req *subreq;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker base = state->search_bases[state->search_base_iter];
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames if (base == NULL) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return EOK;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe talloc_zfree(state->cur_filter);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe state->cur_filter = sdap_get_id_specific_filter(state, state->host_filter,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe base->filter);
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf if (state->cur_filter == NULL) {
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf return ENOMEM;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf }
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf subreq = sdap_get_generic_send(state, state->ev, state->opts,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe state->sh, base->basedn,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe base->scope, state->cur_filter,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe state->attrs, NULL, 0,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe dp_opt_get_int(state->opts->basic,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe SDAP_ENUM_SEARCH_TIMEOUT));
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (subreq == NULL) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe DEBUG(SSSDBG_CRIT_FAILURE, ("Error requesting host info\n"));
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe talloc_zfree(state->cur_filter);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return EIO;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe tevent_req_set_callback(subreq, ipa_host_info_done, req);
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return EAGAIN;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
11a0edf478ca9c59d80bf73491d89cf019259feeniq
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic void
11a0edf478ca9c59d80bf73491d89cf019259feeniqipa_host_info_done(struct tevent_req *subreq)
11a0edf478ca9c59d80bf73491d89cf019259feeniq{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe errno_t ret;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe struct tevent_req *req =
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf tevent_req_callback_data(subreq, struct tevent_req);
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf struct ipa_host_state *state =
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf tevent_req_data(req, struct ipa_host_state);
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf const char *host_dn;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf int i;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ret = sdap_get_generic_recv(subreq, state,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe &state->host_count,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe &state->hosts);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe talloc_zfree(subreq);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ret != EOK) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe tevent_req_error(req, ret);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (state->host_count == 0) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe state->search_base_iter++;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ret = ipa_host_info_next(req, state);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (ret == EOK) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* No more search bases to try */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe tevent_req_error(req, ENOENT);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd } else if (ret != EAGAIN) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd tevent_req_error(req, ret);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes ret = replace_attribute_name(IPA_MEMBEROF, SYSDB_ORIG_MEMBEROF,
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes state->host_count,
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes state->hosts);
18b5268e013574026b2503b1641baf3299045f45sf if (ret != EOK) {
18b5268e013574026b2503b1641baf3299045f45sf DEBUG(SSSDBG_CRIT_FAILURE, ("Could not replace attribute names\n"));
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes tevent_req_error(req, ret);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return;
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf
18b5268e013574026b2503b1641baf3299045f45sf /* Complete the map */
18b5268e013574026b2503b1641baf3299045f45sf for (i = 0; i < HOSTGROUP_MAP_ATTRS_COUNT; i++) {
d9cc5de428947d5c7221d7d42ceefea649bcab48sf /* These are allocated on the state, so the next time they'll
18b5268e013574026b2503b1641baf3299045f45sf * have to be allocated again
18b5268e013574026b2503b1641baf3299045f45sf */
18b5268e013574026b2503b1641baf3299045f45sf hostgroup_map[i].name = talloc_strdup(state,
18b5268e013574026b2503b1641baf3299045f45sf hostgroup_map[i].def_name);
18b5268e013574026b2503b1641baf3299045f45sf if (hostgroup_map[i].name == NULL) {
18b5268e013574026b2503b1641baf3299045f45sf tevent_req_error(req, ret);
404381a78d109fd3a4a7702e69815e4d7ff6d93asf return;
404381a78d109fd3a4a7702e69815e4d7ff6d93asf }
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq }
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq if (state->fetch_hostgroups) {
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq /* Look up host groups */
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq if (state->hostname == NULL) {
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq talloc_zfree(state->host_filter);
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq state->host_filter = talloc_asprintf(state, "(objectClass=%s)",
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq IPA_HOSTGROUP);
18b5268e013574026b2503b1641baf3299045f45sf if (state->host_filter == NULL) {
18b5268e013574026b2503b1641baf3299045f45sf tevent_req_error(req, ENOMEM);
18b5268e013574026b2503b1641baf3299045f45sf return;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes state->search_base_iter = 0;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes
18b5268e013574026b2503b1641baf3299045f45sf ret = ipa_hostgroup_info_next(req, state);
18b5268e013574026b2503b1641baf3299045f45sf if (ret == EOK) {
18b5268e013574026b2503b1641baf3299045f45sf DEBUG(SSSDBG_CRIT_FAILURE, ("No host search base configured?\n"));
18b5268e013574026b2503b1641baf3299045f45sf tevent_req_error(req, EINVAL);
18b5268e013574026b2503b1641baf3299045f45sf return;
18b5268e013574026b2503b1641baf3299045f45sf } else if (ret != EAGAIN) {
18b5268e013574026b2503b1641baf3299045f45sf tevent_req_error(req, ret);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return;
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf } else {
18b5268e013574026b2503b1641baf3299045f45sf state->hostgroup_map = talloc_zero(state, struct sdap_attr_map_info);
18b5268e013574026b2503b1641baf3299045f45sf if (state->hostgroup_map == NULL) {
d9cc5de428947d5c7221d7d42ceefea649bcab48sf tevent_req_error(req, ENOMEM);
18b5268e013574026b2503b1641baf3299045f45sf return;
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf state->hostgroup_map->map = hostgroup_map;
18b5268e013574026b2503b1641baf3299045f45sf state->hostgroup_map->num_attrs = HOSTGROUP_MAP_ATTRS_COUNT;
18b5268e013574026b2503b1641baf3299045f45sf
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes ret = sysdb_attrs_get_string(state->hosts[0], SYSDB_ORIG_DN, &host_dn);
18b5268e013574026b2503b1641baf3299045f45sf if (ret != EOK) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes tevent_req_error(req, ret);
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf return;
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf }
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf subreq = sdap_deref_search_send(state, state->ev, state->opts, state->sh,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf host_dn, IPA_MEMBEROF, state->attrs,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf 1, state->hostgroup_map,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf dp_opt_get_int(state->opts->basic,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf SDAP_ENUM_SEARCH_TIMEOUT));
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if (subreq == NULL) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes DEBUG(SSSDBG_CRIT_FAILURE, ("Error requesting host info\n"));
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes tevent_req_error(req, EIO);
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes return;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe tevent_req_set_callback(subreq, ipa_hostgroup_info_done, req);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe } else {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Nothing else to do, just complete the req */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe tevent_req_done(req);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
d176cb9e596e4603f76490f9211f62b5581b3091rooneg}
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic errno_t ipa_hostgroup_info_next(struct tevent_req *req,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe struct ipa_host_state *state)
d176cb9e596e4603f76490f9211f62b5581b3091rooneg{
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf struct sdap_search_base *base;
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf struct tevent_req *subreq;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe base = state->search_bases[state->search_base_iter];
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (base == NULL) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return EOK;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe talloc_zfree(state->cur_filter);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe state->cur_filter = sdap_get_id_specific_filter(state, state->host_filter,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe base->filter);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (state->cur_filter == NULL) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return ENOMEM;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe base->basedn, base->scope,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe state->cur_filter, state->attrs, hostgroup_map,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe HOSTGROUP_MAP_ATTRS_COUNT,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe dp_opt_get_int(state->opts->basic,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe SDAP_ENUM_SEARCH_TIMEOUT));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (subreq == NULL) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe DEBUG(SSSDBG_CRIT_FAILURE, ("Error requesting hostgroup info\n"));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe talloc_zfree(state->cur_filter);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return EIO;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker tevent_req_set_callback(subreq, ipa_hostgroup_info_done, req);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return EAGAIN;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdstatic void
cc9582e53aead2a044077c4a92f3dfc3605590b3wroweipa_hostgroup_info_done(struct tevent_req *subreq)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp errno_t ret;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe struct tevent_req *req =
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd tevent_req_callback_data(subreq, struct tevent_req);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd struct ipa_host_state *state =
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd tevent_req_data(req, struct ipa_host_state);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd size_t hostgroups_total;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd size_t hostgroup_count;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd struct sysdb_attrs **hostgroups;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd struct sdap_deref_attrs **deref_result;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char *hostgroup_name;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char *hostgroup_dn;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int i, j;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp if (state->hostname == NULL) {
f46cb698a1b32d16a0107566568f67d8c3f8ee9csf ret = sdap_get_generic_recv(subreq, state,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker &hostgroup_count,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd &hostgroups);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd talloc_zfree(subreq);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Merge the two arrays */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (hostgroup_count > 0) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd hostgroups_total = hostgroup_count + state->hostgroup_count;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd state->hostgroups = talloc_realloc(state, state->hostgroups,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd struct sysdb_attrs *,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd hostgroups_total);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (state->hostgroups == NULL) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd tevent_req_error(req, ENOMEM);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd i = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd while(state->hostgroup_count < hostgroups_total) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe state->hostgroups[state->hostgroup_count] =
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd talloc_steal(state->hostgroups, hostgroups[i]);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker state->hostgroup_count++;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd i++;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Now look in the next base */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd state->search_base_iter++;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ret = ipa_hostgroup_info_next(req, state);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (ret != EOK && ret != EAGAIN) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd tevent_req_error(req, ret);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (ret != EOK) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Only continue if no error occurred
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * and no req was created */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ret = sdap_deref_search_recv(subreq, state,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &state->hostgroup_count,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &deref_result);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb talloc_zfree(subreq);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ret != EOK) goto done;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (state->hostgroup_count == 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb DEBUG(SSSDBG_FUNC_DATA, ("No host groups were dereferenced\n"));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb state->hostgroups = talloc_zero_array(state, struct sysdb_attrs *,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb state->hostgroup_count);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (state->hostgroups == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ret = ENOMEM;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb goto done;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe j = 0;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker for (i = 0; i < state->hostgroup_count; i++) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ret = sysdb_attrs_get_string(deref_result[i]->attrs,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe SYSDB_ORIG_DN, &hostgroup_dn);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (ret != EOK) goto done;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!sss_ldap_dn_in_search_bases(state, hostgroup_dn,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe state->search_bases,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe NULL)) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe continue;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ret = sysdb_attrs_get_string(deref_result[i]->attrs,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe IPA_CN, &hostgroup_name);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (ret != EOK) goto done;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz DEBUG(SSSDBG_FUNC_DATA, ("Dereferenced host group: %s\n",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe hostgroup_name));
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar state->hostgroups[j] = talloc_steal(state->hostgroups,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe deref_result[i]->attrs);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar j++;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz state->hostgroup_count = j;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz }
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz }
1e911973bcb9df6701a4c16c037771ecf25ade13niq
1e911973bcb9df6701a4c16c037771ecf25ade13niqdone:
c3e233736c4a453cbb2166a041f779e86230630asf if (ret == EOK) {
c3e233736c4a453cbb2166a041f779e86230630asf tevent_req_done(req);
c3e233736c4a453cbb2166a041f779e86230630asf } else {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe DEBUG(SSSDBG_OP_FAILURE, ("Error [%d][%s]\n", ret, strerror(ret)));
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar tevent_req_error(req, ret);
11fb2f3611e6ff9a541e10b13e3108934f828141gregames }
11fb2f3611e6ff9a541e10b13e3108934f828141gregames}
11fb2f3611e6ff9a541e10b13e3108934f828141gregames
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantzerrno_t ipa_host_info_recv(struct tevent_req *req,
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz TALLOC_CTX *mem_ctx,
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz size_t *host_count,
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz struct sysdb_attrs ***hosts,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker size_t *hostgroup_count,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe struct sysdb_attrs ***hostgroups)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe size_t c;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker struct ipa_host_state *state =
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe tevent_req_data(req, struct ipa_host_state);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe TEVENT_REQ_RETURN_ON_ERROR(req);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
c3e233736c4a453cbb2166a041f779e86230630asf *host_count = state->host_count;
c3e233736c4a453cbb2166a041f779e86230630asf *hosts = talloc_steal(mem_ctx, state->hosts);
c3e233736c4a453cbb2166a041f779e86230630asf for (c = 0; c < state->host_count; c++) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Guarantee the memory heirarchy of the list */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar talloc_steal(state->hosts, state->hosts[c]);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
c3e233736c4a453cbb2166a041f779e86230630asf *hostgroup_count = state->hostgroup_count;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *hostgroups = talloc_steal(mem_ctx, state->hostgroups);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return EOK;
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe