ipa_subdomains.c revision 58dd26b1c5b60ee992dd5d1214bb168aebb42d54
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"
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce#include <ctype.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
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce/* do not refresh more often than every 5 seconds for now */
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce#define IPA_SUBDOMAIN_REFRESH_LIMIT 5
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce/* refresh automatically every 4 hours */
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce#define IPA_SUBDOMAIN_REFRESH_PERIOD (3600 * 4)
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose#define IPA_SUBDOMAIN_DISABLED_PERIOD 3600
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
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
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorcestruct ipa_subdomains_ctx {
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct be_ctx *be_ctx;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct sdap_id_ctx *sdap_id_ctx;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct sdap_search_base **search_bases;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct sdap_search_base **master_search_bases;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct sdap_search_base **ranges_search_bases;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce time_t last_refreshed;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce struct tevent_timer *timer_event;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose bool configured_explicit;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose time_t disabled_until;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce};
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bosestruct be_ctx *ipa_get_subdomains_be_ctx(struct be_ctx *be_ctx)
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose{
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose struct ipa_subdomains_ctx *subdom_ctx;
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose subdom_ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose struct ipa_subdomains_ctx);
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose if (subdom_ctx == NULL) {
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose DEBUG(SSSDBG_TRACE_ALL, ("Subdomains are not configured.\n"));
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose return NULL;
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose }
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose return subdom_ctx->be_ctx;
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose}
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Boseconst char *get_flat_name_from_subdomain_name(struct be_ctx *be_ctx,
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose const char *name)
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose{
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose struct ipa_subdomains_ctx *ctx;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct sss_domain_info *dom;
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose struct ipa_subdomains_ctx);
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose if (ctx == NULL) {
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose DEBUG(SSSDBG_TRACE_ALL, ("Subdomains are not configured.\n"));
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose return NULL;
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose }
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom = find_subdomain_by_name(ctx->be_ctx->domain, name, true);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dom) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce return dom->flat_name;
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose }
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose return NULL;
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit Bose}
70eaade10feedd7845e39170d0b7eebf3a030af1Sumit 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
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcestatic errno_t ipa_subdom_store(struct sss_domain_info *domain,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct sysdb_attrs *attrs)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce TALLOC_CTX *tmp_ctx;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const char *name;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce char *realm;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const char *flat;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const char *id;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce tmp_ctx = talloc_new(domain);
5627532b81802c2654ced8edac07f420bd677930Jakub Hrozek if (tmp_ctx == NULL) {
5627532b81802c2654ced8edac07f420bd677930Jakub Hrozek return ENOMEM;
5627532b81802c2654ced8edac07f420bd677930Jakub Hrozek }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_attrs_get_string(attrs, IPA_CN, &name);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != EOK) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce realm = get_uppercase_realm(tmp_ctx, name);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (!realm) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ENOMEM;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_attrs_get_string(attrs, IPA_FLATNAME, &flat);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_attrs_get_string(attrs, IPA_TRUSTED_DOMAIN_SID, &id);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_subdomain_store(domain->sysdb, name, realm, flat, id);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("sysdb_subdomain_store failed.\n"));
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek ret = EOK;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorcedone:
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce talloc_free(tmp_ctx);
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek return ret;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce}
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorcestatic errno_t ipa_subdomains_refresh(struct ipa_subdomains_ctx *ctx,
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce int count, struct sysdb_attrs **reply,
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce bool *changes)
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce{
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct sss_domain_info *domain, *dom;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce bool handled[count];
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce const char *value;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce int c, h;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce int ret;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
95e94691178297f2b8225a83d43ae388cab04b45Simo Sorce domain = ctx->be_ctx->domain;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce memset(handled, 0, sizeof(bool) * count);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce h = 0;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
95e94691178297f2b8225a83d43ae388cab04b45Simo Sorce /* check existing subdomains */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce for (dom = get_next_domain(domain, true);
4f118e3e6a25762f40a43e6dbefb09f44adbef32Simo Sorce dom && IS_SUBDOMAIN(dom); /* if we get back to a parent, stop */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom = get_next_domain(dom, false)) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce for (c = 0; c < count; c++) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (handled[c]) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce continue;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != EOK) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcmp(value, dom->name) == 0) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce break;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (c >= count) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* ok this subdomain does not exist anymore, let's clean up */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom->disabled = true;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_subdomain_delete(dom->sysdb, dom->name);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != EOK) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce } else {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* ok let's try to update it */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ipa_subdom_store(domain, reply[c]);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret) {
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek /* Nothing we can do about the errorr. Let's at least try
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek * to reuse the existing domain
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek */
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to parse subdom data, "
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek "will try to use cached subdomain\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce handled[c] = true;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce h++;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (count == h) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* all domains were already accounted for and have been updated */
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = EOK;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* if we get here it means we have changes to the subdomains list */
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce *changes = true;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce for (c = 0; c < count; c++) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (handled[c]) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce continue;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek /* Nothing we can do about the errorr. Let's at least try
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek * to reuse the existing domain.
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ipa_subdom_store(domain, reply[c]);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret) {
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to parse subdom data, "
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek "will try to use cached subdomain\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = EOK;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != EOK) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ctx->last_refreshed = 0;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce } else {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ctx->last_refreshed = time(NULL);
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
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[] = {
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce { MASTER_DOMAIN_FILTER,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce ipa_subdomains_handler_master_done,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce { IPA_CN, IPA_FLATNAME, IPA_SID, NULL }
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce },
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce { SUBDOMAINS_FILTER,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce ipa_subdomains_handler_done,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce { IPA_CN, IPA_FLATNAME, IPA_TRUSTED_DOMAIN_SID, NULL }
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce },
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce { RANGE_FILTER,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce ipa_subdomains_handler_ranges_done,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce { OBJECTCLASS, IPA_CN,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce IPA_BASE_ID, IPA_BASE_RID, IPA_SECONDARY_BASE_RID,
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce IPA_ID_RANGE_SIZE, IPA_TRUSTED_DOMAIN_SID, NULL
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce }
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny};
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorcestatic void ipa_subdomains_retrieve(struct ipa_subdomains_ctx *ctx, struct be_req *be_req)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce struct ipa_subdomains_req_ctx *req_ctx = NULL;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct tevent_req *req;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce int dp_error = DP_ERR_FATAL;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx = talloc(be_req, struct ipa_subdomains_req_ctx);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (req_ctx == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->be_req = be_req;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->sd_ctx = ctx;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->search_base_iter = 0;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->search_bases = ctx->search_bases;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->current_filter = NULL;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->reply_count = 0;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->reply = NULL;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req_ctx->sdap_op = sdap_id_op_create(req_ctx,
dcb44c39dda9699cdd6488fd116a51ced0687de3Jakub Hrozek ctx->sdap_id_ctx->conn->conn_cache);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (req_ctx->sdap_op == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce req = sdap_id_op_connect_send(req_ctx->sdap_op, req_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)));
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce tevent_req_set_callback(req, ipa_subdomains_get_conn_done, req_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorcedone:
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce talloc_free(req_ctx);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (ret == EOK) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce dp_error = DP_ERR_OK;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce }
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(be_req, dp_error, ret, NULL);
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;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ipa_subdomains_req_ctx *ctx;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce
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:
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(ctx->be_req, dp_error, ret, NULL);
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);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ctx->current_filter = sdap_get_id_specific_filter(ctx, params->filter,
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce base->filter);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ctx->current_filter == NULL) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce req = sdap_get_generic_send(ctx, ctx->sd_ctx->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;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ipa_subdomains_req_ctx *ctx;
1e6f2180724de4722a5218826c9401181168d9d4Simo Sorce struct sss_domain_info *domain;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce bool refresh_has_changes = false;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
ccc2af010bbbe6d8a7496fb717216135bc4c1993Simo Sorce domain = ctx->sd_ctx->be_ctx->domain;
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
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = ipa_subdomains_refresh(ctx->sd_ctx, ctx->reply_count, ctx->reply,
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce &refresh_has_changes);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("Failed to refresh subdomains.\n"));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (refresh_has_changes) {
95e94691178297f2b8225a83d43ae388cab04b45Simo Sorce ret = sysdb_update_subdomains(domain);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != EOK) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_subdomains failed.\n"));
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
7197ce636c2b92152f5f6180bef6bda3752d148dJakub Hrozek
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ret = sss_write_domain_mappings(domain);
7197ce636c2b92152f5f6180bef6bda3752d148dJakub Hrozek if (ret != EOK) {
7197ce636c2b92152f5f6180bef6bda3752d148dJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek ("sss_krb5_write_mappings failed.\n"));
58dd26b1c5b60ee992dd5d1214bb168aebb42d54Jakub Hrozek /* Just continue */
7197ce636c2b92152f5f6180bef6bda3752d148dJakub Hrozek }
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:
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(ctx->be_req, DP_ERR_FATAL, ret, NULL);
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;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce int dp_error = DP_ERR_FATAL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose size_t reply_count;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct sysdb_attrs **reply = NULL;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ipa_subdomains_req_ctx *ctx;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct range_info **range_list = NULL;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct sysdb_ctx *sysdb;
0754ff886f909f0404038eb9c99dd61be1acf5b9Simo Sorce struct sss_domain_info *domain;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
ccc2af010bbbe6d8a7496fb717216135bc4c1993Simo Sorce domain = ctx->sd_ctx->be_ctx->domain;
ccc2af010bbbe6d8a7496fb717216135bc4c1993Simo Sorce sysdb = domain->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) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ("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
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce ret = sysdb_master_domain_update(domain);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (domain->flat_name == NULL ||
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->domain_id == NULL ||
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->realm == 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:
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce if (ret == EOK) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce dp_error = DP_ERR_OK;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce }
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(ctx->be_req, dp_error, ret, NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny}
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic void ipa_subdomains_handler_master_done(struct tevent_req *req)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny errno_t ret;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce int dp_error = DP_ERR_FATAL;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny size_t reply_count;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct sysdb_attrs **reply = NULL;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ipa_subdomains_req_ctx *ctx;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce
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) {
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce const char *flat = NULL;
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce const char *id = NULL;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = sysdb_attrs_get_string(reply[0], IPA_FLATNAME, &flat);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce if (ret != EOK) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce goto done;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = sysdb_attrs_get_string(reply[0], IPA_SID, &id);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = sysdb_master_domain_add_info(ctx->sd_ctx->be_ctx->domain,
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce NULL, flat, id);
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"));
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (!ctx->sd_ctx->configured_explicit) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ctx->sd_ctx->disabled_until = time(NULL) +
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose IPA_SUBDOMAIN_DISABLED_PERIOD;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EIO;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce if (ret == EOK) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce dp_error = DP_ERR_OK;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce }
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(ctx->be_req, dp_error, ret, NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorcestatic void ipa_subdom_online_cb(void *pvt);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorcestatic void ipa_subdom_timer_refresh(struct tevent_context *ev,
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce struct tevent_timer *te,
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce struct timeval current_time,
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce void *pvt)
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce{
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ipa_subdom_online_cb(pvt);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce}
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorcestatic void ipa_subdom_be_req_callback(struct be_req *be_req,
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce int dp_err, int dp_ret,
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce const char *errstr)
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce{
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce talloc_free(be_req);
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce}
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorcestatic void ipa_subdom_online_cb(void *pvt)
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce{
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct ipa_subdomains_ctx *ctx;
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce struct be_req *be_req;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce struct timeval tv;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce if (!ctx) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce DEBUG(SSSDBG_CRIT_FAILURE, ("Bad private pointer\n"));
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce return;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ctx->disabled_until = 0;
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce
99151f2217ddaa179543b89b49f836f29f7dcd2aSimo Sorce be_req = be_req_create(ctx, NULL, ctx->be_ctx,
99151f2217ddaa179543b89b49f836f29f7dcd2aSimo Sorce ipa_subdom_be_req_callback, NULL);
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek if (be_req == NULL) {
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek DEBUG(SSSDBG_CRIT_FAILURE, ("be_req_create() failed.\n"));
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek return;
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek }
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce ipa_subdomains_retrieve(ctx, be_req);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce tv = tevent_timeval_current_ofs(IPA_SUBDOMAIN_REFRESH_PERIOD, 0);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ctx->timer_event = tevent_add_timer(ctx->be_ctx->ev, ctx, tv,
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ipa_subdom_timer_refresh, ctx);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce if (!ctx->timer_event) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom timer event\n"));
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce}
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorcestatic void ipa_subdom_offline_cb(void *pvt)
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce{
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce struct ipa_subdomains_ctx *ctx;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce if (ctx) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce talloc_zfree(ctx->timer_event);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce}
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bosestatic errno_t get_config_status(struct be_ctx *be_ctx,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose bool *configured_explicit)
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose{
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose int ret;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose TALLOC_CTX *tmp_ctx = NULL;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose char *tmp_str;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose tmp_ctx = talloc_new(NULL);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (tmp_ctx == NULL) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("talloc_new failed.\n"));
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose return ENOMEM;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = confdb_get_string(be_ctx->cdb, tmp_ctx, be_ctx->conf_path,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose CONFDB_DOMAIN_SUBDOMAINS_PROVIDER, NULL,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose &tmp_str);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ret != EOK) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("confdb_get_string failed.\n"));
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose goto done;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (tmp_str == NULL) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose *configured_explicit = false;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose } else {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose *configured_explicit = true;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_TRACE_ALL, ("IPA subdomain provider is configured %s.\n",
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose *configured_explicit ? "explicit" : "implicit"));
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = EOK;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bosedone:
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose talloc_free(tmp_ctx);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose return ret;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose}
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorcevoid ipa_subdomains_handler(struct be_req *be_req)
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce{
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce struct be_ctx *be_ctx = be_req_get_be_ctx(be_req);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct ipa_subdomains_ctx *ctx;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose time_t now;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct ipa_subdomains_ctx);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (!ctx) {
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(be_req, DP_ERR_FATAL, EINVAL, NULL);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce return;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose now = time(NULL);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ctx->disabled_until > now) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_TRACE_ALL, ("Subdomain provider disabled.\n"));
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(be_req, DP_ERR_OK, EOK, NULL);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose return;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ctx->last_refreshed > now - IPA_SUBDOMAIN_REFRESH_LIMIT) {
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce be_req_terminate(be_req, DP_ERR_OK, EOK, NULL);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce return;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce ipa_subdomains_retrieve(ctx, be_req);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce}
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorcestruct bet_ops ipa_subdomains_ops = {
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce .handler = ipa_subdomains_handler,
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce .finalize = NULL
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce};
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorceint ipa_subdom_init(struct be_ctx *be_ctx,
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct ipa_id_ctx *id_ctx,
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct bet_ops **ops,
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce void **pvt_data)
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce{
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct ipa_subdomains_ctx *ctx;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce int ret;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose bool configured_explicit = false;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = get_config_status(be_ctx, &configured_explicit);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ret != EOK) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_OP_FAILURE, ("get_config_status failed.\n"));
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose return ret;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ctx = talloc_zero(id_ctx, struct ipa_subdomains_ctx);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce if (ctx == NULL) {
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce return ENOMEM;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce }
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce ctx->be_ctx = be_ctx;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ctx->sdap_id_ctx = id_ctx->sdap_id_ctx;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ctx->search_bases = id_ctx->ipa_options->subdomains_search_bases;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ctx->master_search_bases = id_ctx->ipa_options->master_domain_search_bases;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ctx->ranges_search_bases = id_ctx->ipa_options->ranges_search_bases;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ctx->configured_explicit = configured_explicit;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ctx->disabled_until = 0;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce *ops = &ipa_subdomains_ops;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce *pvt_data = ctx;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce ret = be_add_online_cb(ctx, be_ctx, ipa_subdom_online_cb, ctx, NULL);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (ret != EOK) {
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom online callback"));
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = be_add_offline_cb(ctx, be_ctx, ipa_subdom_offline_cb, ctx, NULL);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce if (ret != EOK) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom offline callback"));
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce return EOK;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce}