ipa_subdomains.c revision b58460076fe843c11d736ae244c1ac979a6473a4
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose/*
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose SSSD
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose IPA Subdomains Module
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Authors:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Sumit Bose <sbose@redhat.com>
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Copyright (C) 2011 Red Hat
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose This program is free software; you can redistribute it and/or modify
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose it under the terms of the GNU General Public License as published by
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose the Free Software Foundation; either version 3 of the License, or
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose (at your option) any later version.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose This program is distributed in the hope that it will be useful,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose GNU General Public License for more details.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose You should have received a copy of the GNU General Public License
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose*/
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#include "providers/ldap/sdap_async.h"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#include "providers/ipa/ipa_subdomains.h"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#include "providers/ipa/ipa_common.h"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain"
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny#define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define RANGE_FILTER "objectclass=ipaIDRange"
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#define IPA_CN "cn"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#define IPA_FLATNAME "ipaNTFlatName"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_SID "ipaNTSecurityIdentifier"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_TRUSTED_DOMAIN_SID "ipaNTTrustedDomainSID"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_BASE_ID "ipaBaseID"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_ID_RANGE_SIZE "ipaIDRangeSize"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_BASE_RID "ipaBaseRID"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define IPA_SECONDARY_BASE_RID "ipaSecondaryBaseRID"
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose#define OBJECTCLASS "objectClass"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenyenum ipa_subdomains_req_type {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny IPA_SUBDOMAINS_MASTER,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny IPA_SUBDOMAINS_SLAVE,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose IPA_SUBDOMAINS_RANGES,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny IPA_SUBDOMAINS_MAX /* Counter */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny};
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystruct ipa_subdomains_req_params {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *filter;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tevent_req_fn cb;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *attrs[8];
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny};
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_reply(struct be_req *be_req, int dp_err, int result)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose be_req->fn(be_req, dp_err, result, NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic errno_t ipa_ranges_parse_results(TALLOC_CTX *mem_ctx,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose size_t count,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct sysdb_attrs **reply,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct range_info ***_range_list)
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose{
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct range_info **range_list = NULL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *value;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose size_t c;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose int ret;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list = talloc_array(mem_ctx, struct range_info *, count + 1);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (range_list == NULL) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_array failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose return ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (c = 0; c < count; c++) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c] = talloc_zero(range_list, struct range_info);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (range_list[c] == NULL) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c]->name = talloc_strdup(range_list[c], value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (range_list[c]->name == NULL) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_TRUSTED_DOMAIN_SID, &value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret == EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c]->trusted_dom_sid = talloc_strdup(range_list[c],
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose value);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (range_list[c]->trusted_dom_sid == NULL) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose } else if (ret != ENOENT) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_ID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose &range_list[c]->base_id);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK && ret != ENOENT) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_ID_RANGE_SIZE,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose &range_list[c]->id_range_size);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK && ret != ENOENT) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_RID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose &range_list[c]->base_rid);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK && ret != ENOENT) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_uint32_t(reply[c], IPA_SECONDARY_BASE_RID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose &range_list[c]->secondary_base_rid);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK && ret != ENOENT) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose range_list[c] = NULL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose *_range_list = range_list;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = EOK;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosedone:
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose talloc_free(range_list);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose return ret;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose}
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic errno_t ipa_subdomains_parse_results(
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct be_get_subdomains_req *sd_data,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose size_t count,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct sysdb_attrs **reply)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
b58460076fe843c11d736ae244c1ac979a6473a4Simo Sorce struct sysdb_subdom **new_domain_list = NULL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose const char *value;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose size_t c;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
b58460076fe843c11d736ae244c1ac979a6473a4Simo Sorce new_domain_list = talloc_array(sd_data, struct sysdb_subdom *, count + 1);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (new_domain_list == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_array failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose for (c = 0; c < count; c++) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c] = talloc_zero(new_domain_list,
b58460076fe843c11d736ae244c1ac979a6473a4Simo Sorce struct sysdb_subdom);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (new_domain_list[c] == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c]->name = talloc_strdup(new_domain_list[c], value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (new_domain_list[c]->name == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_FLATNAME, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret == EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c]->flat_name = talloc_strdup(new_domain_list[c],
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (new_domain_list[c]->flat_name == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose } else if (ret != ENOENT) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_attrs_get_string(reply[c], IPA_TRUSTED_DOMAIN_SID, &value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret == EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c]->id = talloc_strdup(new_domain_list[c], value);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (new_domain_list[c]->id == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose } else if (ret != ENOENT) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose new_domain_list[c] = NULL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = EOK;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret == EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(sd_data->domain_list);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose sd_data->domain_list = new_domain_list;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose } else {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(new_domain_list);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestruct ipa_subdomains_req_ctx {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct be_req *be_req;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_ctx *sd_ctx;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct sdap_id_op *sdap_op;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct be_get_subdomains_req *sd_data;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose char *current_filter;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct sdap_search_base **search_bases;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int search_base_iter;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose size_t reply_count;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct sysdb_attrs **reply;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose};
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_get_conn_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic errno_t
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenyipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny enum ipa_subdomains_req_type type);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_handler_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_master_done(struct tevent_req *req);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic struct ipa_subdomains_req_params subdomain_requests[] = {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose { MASTER_DOMAIN_FILTER, ipa_subdomains_handler_master_done,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose {IPA_CN, IPA_FLATNAME, IPA_SID, NULL }},
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose { SUBDOMAINS_FILTER, ipa_subdomains_handler_done,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose {IPA_CN, IPA_FLATNAME, IPA_TRUSTED_DOMAIN_SID, NULL }},
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose { RANGE_FILTER, ipa_subdomains_handler_ranges_done,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose {OBJECTCLASS, IPA_CN, IPA_BASE_ID, IPA_ID_RANGE_SIZE, IPA_BASE_RID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose IPA_SECONDARY_BASE_RID, IPA_TRUSTED_DOMAIN_SID, NULL }}
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny};
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosevoid ipa_subdomains_handler(struct be_req *be_req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct tevent_req *req;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx *ctx = NULL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx = talloc(be_req, struct ipa_subdomains_req_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ctx == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto fail;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->be_req = be_req;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->sd_ctx = talloc_get_type(
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose be_req->be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->sd_data = talloc_get_type(be_req->req_data,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct be_get_subdomains_req);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->search_base_iter = 0;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->search_bases = ctx->sd_ctx->search_bases;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->current_filter = NULL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->reply_count = 0;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->reply = NULL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->sdap_op = sdap_id_op_create(ctx,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->sd_ctx->sdap_id_ctx->conn_cache);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ctx->sdap_op == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto fail;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose req = sdap_id_op_connect_send(ctx->sdap_op, ctx, &ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (req == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_connect_send failed: %d(%s).\n",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret, strerror(ret)));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto fail;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose tevent_req_set_callback(req, ipa_subdomains_get_conn_done, ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosefail:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ipa_subdomains_reply(be_req, DP_ERR_FATAL, ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_get_conn_done(struct tevent_req *req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int dp_error = DP_ERR_FATAL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct be_req *be_req;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sdap_id_op_connect_recv(req, &dp_error);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_zfree(req);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (dp_error == DP_ERR_OFFLINE) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("No IPA server is available, cannot get the "
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose "subdomain list while offline\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose/* FIXME: return saved results ?? */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose } else {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ("Failed to connect to IPA server: [%d](%s)\n",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret, strerror(ret)));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto fail;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_SLAVE);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK && ret != EAGAIN) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto fail;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosefail:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose be_req = ctx->be_req;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ipa_subdomains_reply(be_req, dp_error, ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic errno_t
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenyipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny enum ipa_subdomains_req_type type)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct tevent_req *req;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct sdap_search_base *base;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ipa_subdomains_req_params *params;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (type >= IPA_SUBDOMAINS_MAX) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return EINVAL;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny params = &subdomain_requests[type];
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose base = ctx->search_bases[ctx->search_base_iter];
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (base == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return EOK;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(ctx->current_filter);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ctx->current_filter = sdap_get_id_specific_filter(ctx, params->filter, base->filter);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ctx->current_filter == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose req = sdap_get_generic_send(ctx, ctx->be_req->be_ctx->ev,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->sd_ctx->sdap_id_ctx->opts,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose sdap_id_op_handle(ctx->sdap_op),
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose base->basedn, base->scope,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx->current_filter, params->attrs, NULL, 0,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose dp_opt_get_int(ctx->sd_ctx->sdap_id_ctx->opts->basic,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose SDAP_SEARCH_TIMEOUT), false);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (req == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tevent_req_set_callback(req, params->cb, ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return EAGAIN;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosestatic void ipa_subdomains_handler_done(struct tevent_req *req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose size_t reply_count;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct sysdb_attrs **reply = NULL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ipa_subdomains_req_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct be_req *be_req = ctx->be_req;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct sysdb_ctx *sysdb;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny sysdb = (be_req->sysdb)?be_req->sysdb:be_req->be_ctx->sysdb;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_zfree(req);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (reply_count) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->reply = talloc_realloc(ctx, ctx->reply, struct sysdb_attrs *,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->reply_count + reply_count);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ctx->reply == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose memcpy(ctx->reply+ctx->reply_count, reply,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose reply_count * sizeof(struct sysdb_attrs *));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->reply_count += reply_count;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->search_base_iter++;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_SLAVE);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret == EAGAIN) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose } else if (ret != EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ipa_subdomains_parse_results(ctx->sd_data, ctx->reply_count, ctx->reply);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("ipa_subdomains_parse_results request failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_update_subdomains(sysdb, ctx->sd_data->domain_list);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_subdomains failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx->search_base_iter = 0;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx->search_bases = ctx->sd_ctx->ranges_search_bases;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_RANGES);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret == EAGAIN) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose return;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose } else if (ret != EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("No search base for ranges available.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = EINVAL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosedone:
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose talloc_free(ctx);
a56156c13c71a96166b0a8f3921e67f36470f8d7Sumit Bose ipa_subdomains_reply(be_req, DP_ERR_FATAL, ret);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose}
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req)
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose{
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose errno_t ret;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose size_t reply_count;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct sysdb_attrs **reply = NULL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ipa_subdomains_req_ctx);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct be_req *be_req = ctx->be_req;
b58460076fe843c11d736ae244c1ac979a6473a4Simo Sorce struct sysdb_subdom *domain_info;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct range_info **range_list = NULL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct sysdb_ctx *sysdb;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose sysdb = (be_req->sysdb)?be_req->sysdb:be_req->be_ctx->sysdb;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose talloc_zfree(req);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ipa_ranges_parse_results(ctx, reply_count, reply, &range_list);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("ipa_ranges_parse_results request failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_update_ranges(sysdb, range_list);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose talloc_free(range_list);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_ranges failed.\n"));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_master_domain_get_info(ctx, sysdb, &domain_info);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (domain_info->flat_name == NULL ||
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info->id == NULL ||
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info->name == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ctx->search_base_iter = 0;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ctx->search_bases = ctx->sd_ctx->master_search_bases;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_MASTER);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret == EAGAIN) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny } else if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny } else {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EOK;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenydone:
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_free(ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ipa_subdomains_reply(be_req, (ret == EOK ? DP_ERR_OK : DP_ERR_FATAL), ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny}
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_master_done(struct tevent_req *req)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny errno_t ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny size_t reply_count;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct sysdb_attrs **reply = NULL;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ipa_subdomains_req_ctx *ctx = tevent_req_callback_data(req,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ipa_subdomains_req_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct be_req *be_req = ctx->be_req;
b58460076fe843c11d736ae244c1ac979a6473a4Simo Sorce struct sysdb_subdom *domain_info;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *tmp_str;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_zfree(req);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (reply_count) {
b58460076fe843c11d736ae244c1ac979a6473a4Simo Sorce domain_info = talloc_zero(ctx, struct sysdb_subdom);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (domain_info == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_attrs_get_string(reply[0], IPA_FLATNAME, &tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info->flat_name = talloc_strdup(domain_info, tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (domain_info->flat_name == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_attrs_get_string(reply[0], IPA_SID, &tmp_str);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny domain_info->id = talloc_strdup(domain_info, tmp_str);
c929c213c91b2f9d55f96d6964b9390636178991Simo Sorce if (domain_info->flat_name == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_master_domain_add_info(be_req->be_ctx->sysdb, domain_info);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny } else {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ctx->search_base_iter++;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_MASTER);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret == EAGAIN) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny } else if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Right now we know there has been an error
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny * and we don't have the master domain record
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_CRIT_FAILURE, ("Master domain record not found!\n"));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EIO;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ipa_subdomains_reply(be_req, (ret == EOK ? DP_ERR_OK : DP_ERR_FATAL), ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}