ipa_subdomains.c revision 66fa032b86f730315b30d62ed58ab17ad065e5ff
97a9a944b5887e91042b019776c41d5dd74557aferikabele/*
97a9a944b5887e91042b019776c41d5dd74557aferikabele SSSD
97a9a944b5887e91042b019776c41d5dd74557aferikabele
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive IPA Subdomains Module
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Authors:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd Sumit Bose <sbose@redhat.com>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd Copyright (C) 2011 Red Hat
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is free software; you can redistribute it and/or modify
fe64b2ba25510d8c9dba5560a2d537763566cf40nd it under the terms of the GNU General Public License as published by
fe64b2ba25510d8c9dba5560a2d537763566cf40nd the Free Software Foundation; either version 3 of the License, or
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (at your option) any later version.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is distributed in the hope that it will be useful,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd but WITHOUT ANY WARRANTY; without even the implied warranty of
fe64b2ba25510d8c9dba5560a2d537763566cf40nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fe64b2ba25510d8c9dba5560a2d537763566cf40nd GNU General Public License for more details.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd You should have received a copy of the GNU General Public License
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd along with this program. If not, see <http://www.gnu.org/licenses/>.
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd*/
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include "providers/ldap/sdap_async.h"
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#include "providers/ldap/sdap_idmap.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include "providers/ipa/ipa_subdomains.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include "providers/ipa/ipa_common.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include <ctype.h>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define SUBDOMAINS_FILTER "objectclass=ipaNTTrustedDomain"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define MASTER_DOMAIN_FILTER "objectclass=ipaNTDomainAttrs"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define RANGE_FILTER "objectclass=ipaIDRange"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_CN "cn"
58699879a562774640b95e9eedfd891f336e38c2nd#define IPA_FLATNAME "ipaNTFlatName"
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd#define IPA_SID "ipaNTSecurityIdentifier"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_TRUSTED_DOMAIN_SID "ipaNTTrustedDomainSID"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_RANGE_TYPE "ipaRangeType"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_BASE_ID "ipaBaseID"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_ID_RANGE_SIZE "ipaIDRangeSize"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_BASE_RID "ipaBaseRID"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_SECONDARY_BASE_RID "ipaSecondaryBaseRID"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define OBJECTCLASS "objectClass"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd/* do not refresh more often than every 5 seconds for now */
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh#define IPA_SUBDOMAIN_REFRESH_LIMIT 5
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define IPA_SUBDOMAIN_DISABLED_PERIOD 3600
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndenum ipa_subdomains_req_type {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd IPA_SUBDOMAINS_MASTER,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd IPA_SUBDOMAINS_SLAVE,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd IPA_SUBDOMAINS_RANGES,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd IPA_SUBDOMAINS_MAX /* Counter */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndstruct ipa_subdomains_req_params {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd tevent_req_fn cb;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd const char *attrs[9];
117c1f888a14e73cdd821dc6c23eb0411144a41cnd};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndstruct ipa_subdomains_ctx {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct be_ctx *be_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct ipa_id_ctx *id_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sdap_id_ctx *sdap_id_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sdap_search_base **search_bases;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sdap_search_base **master_search_bases;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sdap_search_base **ranges_search_bases;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd time_t last_refreshed;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct tevent_timer *timer_event;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool configured_explicit;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd time_t disabled_until;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndstruct be_ctx *ipa_get_subdomains_be_ctx(struct be_ctx *be_ctx)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd{
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct ipa_subdomains_ctx *subdom_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd subdom_ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct ipa_subdomains_ctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (subdom_ctx == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd DEBUG(SSSDBG_TRACE_ALL, ("Subdomains are not configured.\n"));
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return NULL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return subdom_ctx->be_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd}
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t
fe64b2ba25510d8c9dba5560a2d537763566cf40ndipa_ad_ctx_new(struct be_ctx *be_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_id_ctx *id_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *subdom,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ad_id_ctx **_ad_id_ctx)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ad_options *ad_options;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ad_id_ctx *ad_id_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *gc_service_name;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ad_srv_plugin_ctx *srv_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *ad_domain;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sdap_domain *sdom;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno_t ret;
c985aca104389df30d6ec0a637ce0ccaac904362nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ad_options = ad_create_default_options(id_ctx, id_ctx->server_mode->realm,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive id_ctx->server_mode->hostname);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ad_options == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("Cannot initialize AD options\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(ad_options);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ad_domain = subdom->name;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = dp_opt_set_string(ad_options->basic, AD_DOMAIN, ad_domain);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("Cannot set AD domain\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(ad_options);
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = dp_opt_set_string(ad_options->basic, AD_KRB5_REALM,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive id_ctx->server_mode->realm);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("Cannot set AD realm\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(ad_options);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess gc_service_name = talloc_asprintf(ad_options, "%s%s", "gc_", subdom->name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (gc_service_name == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(ad_options);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Set KRB5 realm to same as the one of IPA when IPA
fb77c505254b6e9c925e23e734463e87574f8f40kess * is able to attach PAC. For testing, use hardcoded. */
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ret = ad_failover_init(ad_options, be_ctx, NULL, NULL,
fb77c505254b6e9c925e23e734463e87574f8f40kess id_ctx->server_mode->realm,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive subdom->name, gc_service_name,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive subdom->name, &ad_options->service);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("Cannot initialize AD failover\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess talloc_free(ad_options);
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ad_id_ctx = ad_id_ctx_init(ad_options, be_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ad_id_ctx == NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(ad_options);
130d299c4b2b15be45532a176604c71fdc7bea5bnd return ENOMEM;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd ad_id_ctx->sdap_id_ctx->opts = ad_options->id;
130d299c4b2b15be45532a176604c71fdc7bea5bnd ad_options->id_ctx = ad_id_ctx;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
ef8e89e090461194ecadd31e8796a2c51e0531a2kess /* use AD plugin */
130d299c4b2b15be45532a176604c71fdc7bea5bnd srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
130d299c4b2b15be45532a176604c71fdc7bea5bnd default_host_dbs,
130d299c4b2b15be45532a176604c71fdc7bea5bnd ad_id_ctx->ad_options->id,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd id_ctx->server_mode->hostname,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ad_domain);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (srv_ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE, ("Out of memory?\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd be_fo_set_srv_lookup_plugin(be_ctx, ad_srv_plugin_send,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ad_srv_plugin_recv, srv_ctx, "AD");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sdap_domain_subdom_add(ad_id_ctx->sdap_id_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ad_id_ctx->sdap_id_ctx->opts->sdom,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd subdom->parent);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(SSSDBG_OP_FAILURE, ("Cannot initialize sdap domain\n"));
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive talloc_free(ad_options);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive return ret;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sdom = sdap_domain_get(ad_id_ctx->sdap_id_ctx->opts, subdom);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (sdom == NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return EFAULT;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sdap_id_setup_tasks(ad_id_ctx->sdap_id_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ad_id_ctx->ldap_ctx, sdom,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ldap_enumeration_send,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ldap_enumeration_recv);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(ad_options);
130d299c4b2b15be45532a176604c71fdc7bea5bnd return ret;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* Set up the ID mapping object */
130d299c4b2b15be45532a176604c71fdc7bea5bnd ad_id_ctx->sdap_id_ctx->opts->idmap_ctx =
130d299c4b2b15be45532a176604c71fdc7bea5bnd id_ctx->sdap_id_ctx->opts->idmap_ctx;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *_ad_id_ctx = ad_id_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t
fe64b2ba25510d8c9dba5560a2d537763566cf40ndipa_server_trust_add(struct be_ctx *be_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_id_ctx *id_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *subdom)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_ad_server_ctx *trust_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ad_id_ctx *ad_id_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno_t ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ipa_ad_ctx_new(be_ctx, id_ctx, subdom, &ad_id_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ("Cannot create ad_id_ctx for subdomain %s\n", subdom->name));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive trust_ctx = talloc(id_ctx->server_mode, struct ipa_ad_server_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (trust_ctx == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive trust_ctx->dom = subdom;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive trust_ctx->ad_id_ctx = ad_id_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DLIST_ADD(id_ctx->server_mode->trusts, trust_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return EOK;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndstatic errno_t
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndipa_ad_subdom_refresh(struct be_ctx *be_ctx,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd struct ipa_id_ctx *id_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *parent)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *dom;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_ad_server_ctx *trust_iter;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno_t ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fb77c505254b6e9c925e23e734463e87574f8f40kess if (dp_opt_get_bool(id_ctx->ipa_options->basic,
fb77c505254b6e9c925e23e734463e87574f8f40kess IPA_SERVER_MODE) == false) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd for (dom = get_next_domain(parent, true);
c985aca104389df30d6ec0a637ce0ccaac904362nd dom && IS_SUBDOMAIN(dom); /* if we get back to a parent, stop */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dom = get_next_domain(dom, false)) {
58699879a562774640b95e9eedfd891f336e38c2nd
58699879a562774640b95e9eedfd891f336e38c2nd /* Check if we already have an ID context for this subdomain */
58699879a562774640b95e9eedfd891f336e38c2nd DLIST_FOR_EACH(trust_iter, id_ctx->server_mode->trusts) {
fb77c505254b6e9c925e23e734463e87574f8f40kess if (trust_iter->dom == dom) {
fb77c505254b6e9c925e23e734463e87574f8f40kess break;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
58699879a562774640b95e9eedfd891f336e38c2nd /* Newly detected trust */
58699879a562774640b95e9eedfd891f336e38c2nd if (trust_iter == NULL) {
58699879a562774640b95e9eedfd891f336e38c2nd ret = ipa_server_trust_add(be_ctx, id_ctx, dom);
58699879a562774640b95e9eedfd891f336e38c2nd if (ret != EOK) {
58699879a562774640b95e9eedfd891f336e38c2nd DEBUG(SSSDBG_OP_FAILURE,
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ("Cannot create ad_id_ctx for subdomain %s\n",
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess dom->name));
58699879a562774640b95e9eedfd891f336e38c2nd continue;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
58699879a562774640b95e9eedfd891f336e38c2nd }
58699879a562774640b95e9eedfd891f336e38c2nd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess return EOK;
fb77c505254b6e9c925e23e734463e87574f8f40kess}
58699879a562774640b95e9eedfd891f336e38c2nd
58699879a562774640b95e9eedfd891f336e38c2ndstatic void
58699879a562774640b95e9eedfd891f336e38c2ndipa_ad_subdom_remove(struct ipa_subdomains_ctx *ctx,
58699879a562774640b95e9eedfd891f336e38c2nd struct sss_domain_info *subdom)
58699879a562774640b95e9eedfd891f336e38c2nd{
58699879a562774640b95e9eedfd891f336e38c2nd struct ipa_ad_server_ctx *iter;
58699879a562774640b95e9eedfd891f336e38c2nd struct sdap_domain *sdom;
58699879a562774640b95e9eedfd891f336e38c2nd
58699879a562774640b95e9eedfd891f336e38c2nd if (dp_opt_get_bool(ctx->id_ctx->ipa_options->basic,
58699879a562774640b95e9eedfd891f336e38c2nd IPA_SERVER_MODE) == false) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess return;
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd }
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess DLIST_FOR_EACH(iter, ctx->id_ctx->server_mode->trusts) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (iter->dom == subdom) break;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd if (iter == NULL) {
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd DEBUG(SSSDBG_CRIT_FAILURE, ("No IPA-AD context for subdomain %s\n",
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd subdom->name));
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd return;
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd }
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd sdom = sdap_domain_get(iter->ad_id_ctx->sdap_id_ctx->opts, subdom);
ec9b02c6869b75575ada34c800672162833a2c06nd if (sdom == NULL) return;
58699879a562774640b95e9eedfd891f336e38c2nd be_ptask_destroy(&sdom->enum_task);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd be_ptask_destroy(&sdom->cleanup_task);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd sdap_domain_remove(iter->ad_id_ctx->sdap_id_ctx->opts, subdom);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DLIST_REMOVE(ctx->id_ctx->server_mode->trusts, iter);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* terminate all requests for this subdomain so we can free it */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd be_terminate_domain_requests(ctx->be_ctx, subdom->name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_zfree(sdom);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndconst char *get_flat_name_from_subdomain_name(struct be_ctx *be_ctx,
9583adab6bc4b3758e41963c905d9dad9f067131nd const char *name)
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd{
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct ipa_subdomains_ctx *ctx;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct sss_domain_info *dom;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct ipa_subdomains_ctx);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (ctx == NULL) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd DEBUG(SSSDBG_TRACE_ALL, ("Subdomains are not configured.\n"));
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd return NULL;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd dom = find_subdomain_by_name(ctx->be_ctx->domain, name, true);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (dom) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd return dom->flat_name;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd return NULL;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd}
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndstatic errno_t ipa_ranges_parse_results(TALLOC_CTX *mem_ctx,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd size_t count,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct sysdb_attrs **reply,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct range_info ***_range_list)
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd{
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct range_info **range_list = NULL;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd const char *value;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd size_t c;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd int ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd range_list = talloc_array(mem_ctx, struct range_info *, count + 1);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (range_list == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("talloc_array failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd for (c = 0; c < count; c++) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd range_list[c] = talloc_zero(range_list, struct range_info);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (range_list[c] == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
10673857794a4b3d9568ca2d983722a87ed352f1rbowen goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
f4f4505fedd39d92f787066b0ba8ec912e778784nd range_list[c]->name = talloc_strdup(range_list[c], value);
10673857794a4b3d9568ca2d983722a87ed352f1rbowen if (range_list[c]->name == NULL) {
10673857794a4b3d9568ca2d983722a87ed352f1rbowen DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_string(reply[c], IPA_TRUSTED_DOMAIN_SID, &value);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret == EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive range_list[c]->trusted_dom_sid = talloc_strdup(range_list[c],
fb77c505254b6e9c925e23e734463e87574f8f40kess value);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (range_list[c]->trusted_dom_sid == NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (ret != ENOENT) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_ID,
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end &range_list[c]->base_id);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (ret != EOK && ret != ENOENT) {
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_uint32_t(reply[c], IPA_ID_RANGE_SIZE,
97a9a944b5887e91042b019776c41d5dd74557aferikabele &range_list[c]->id_range_size);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (ret != EOK && ret != ENOENT) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_uint32_t(reply[c], IPA_BASE_RID,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &range_list[c]->base_rid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK && ret != ENOENT) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
97a9a944b5887e91042b019776c41d5dd74557aferikabele goto done;
97a9a944b5887e91042b019776c41d5dd74557aferikabele }
97a9a944b5887e91042b019776c41d5dd74557aferikabele
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_uint32_t(reply[c], IPA_SECONDARY_BASE_RID,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &range_list[c]->secondary_base_rid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK && ret != ENOENT) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_string(reply[c], IPA_RANGE_TYPE, &value);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret == EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive range_list[c]->range_type = talloc_strdup(range_list[c], value);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (range_list[c]->range_type == NULL) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
97a9a944b5887e91042b019776c41d5dd74557aferikabele ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (ret == ENOENT) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Older IPA servers might not have the range_type attribute, but
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd * only support local ranges and trusts with algorithmic mapping. */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (range_list[c]->trusted_dom_sid == NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd range_list[c]->range_type = talloc_strdup(range_list[c],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd IPA_RANGE_LOCAL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd range_list[c]->range_type = talloc_strdup(range_list[c],
fe64b2ba25510d8c9dba5560a2d537763566cf40nd IPA_RANGE_AD_TRUST);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (range_list[c]->range_type == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("talloc_strdup failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd range_list[c] = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *_range_list = range_list;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedone:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(range_list);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
97a9a944b5887e91042b019776c41d5dd74557aferikabele
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end return ret;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic errno_t ipa_subdom_enumerates(struct sss_domain_info *parent,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_attrs *attrs,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool *_enumerates)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd errno_t ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *name;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
1c9f7cdf2e1bc8313e559a96638c3c36e3143791yoshiki ret = sysdb_attrs_get_string(attrs, IPA_CN, &name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *_enumerates = subdomain_enumerates(parent, name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t ipa_subdom_get_forest(TALLOC_CTX *mem_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_context *ldb_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_attrs *attrs,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char **_forest)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *orig_dn;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_dn *dn = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const struct ldb_val *val;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char *forest = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = sysdb_attrs_get_string(attrs, SYSDB_ORIG_DN, &orig_dn);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end goto done;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_TRACE_ALL, ("Checking if we need the forest name for [%s].\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd orig_dn));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dn = ldb_dn_new(mem_ctx, ldb_ctx, orig_dn);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (dn == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("ldb_dn_new failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!ldb_dn_validate(dn)) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("Original DN [%s] is not a valid DN.\n",
fb77c505254b6e9c925e23e734463e87574f8f40kess orig_dn));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ldb_dn_get_comp_num(dn) < 5) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* We are only interested in the member domain objects. In IPA the
c985aca104389df30d6ec0a637ce0ccaac904362nd * forest root object is stored as e.g.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * cn=AD.DOM,cn=ad,cn=trusts,dc=example,dc=com. Member domains in the
70ada6b79498c38ab85985a3d30ee11248ce897byoshiki * forest are children of the forest root object e.g.
fb77c505254b6e9c925e23e734463e87574f8f40kess * cn=SUB.AD.DOM,cn=AD.DOM,cn=ad,cn=trusts,dc=example,dc=com. Since
fb77c505254b6e9c925e23e734463e87574f8f40kess * the forest name is not stored in the member objects we derive it
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess * from the RDN of the forest root object. */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd val = ldb_dn_get_component_val(dn, 3);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (strncasecmp("trusts", (const char *) val->data, val->length) != 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_TRACE_FUNC,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ("4th component is not 'trust', nothing to do.\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EOK;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd val = ldb_dn_get_component_val(dn, 2);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (strncasecmp("ad", (const char *) val->data, val->length) != 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_TRACE_FUNC,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ("3rd component is not 'ad', nothing to do.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive val = ldb_dn_get_component_val(dn, 1);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive forest = talloc_strndup(mem_ctx, (const char *) val->data, val->length);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (forest == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("talloc_strndup failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnddone:
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(dn);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret == EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *_forest = forest;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kessstatic errno_t ipa_subdom_store(struct sss_domain_info *parent,
fb77c505254b6e9c925e23e734463e87574f8f40kess struct sdap_idmap_ctx *sdap_idmap_ctx,
fb77c505254b6e9c925e23e734463e87574f8f40kess struct sysdb_attrs *attrs,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool enumerate)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TALLOC_CTX *tmp_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *name;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *realm;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *flat;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *id;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *forest = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool mpg;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_ctx = talloc_new(parent);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp_ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_string(attrs, IPA_CN, &name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd realm = get_uppercase_realm(tmp_ctx, name);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (!realm) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = ENOMEM;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_string(attrs, IPA_FLATNAME, &flat);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (ret) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_attrs_get_string(attrs, IPA_TRUSTED_DOMAIN_SID, &id);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd mpg = sdap_idmap_domain_has_algorithmic_mapping(sdap_idmap_ctx, name, id);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ipa_subdom_get_forest(tmp_ctx, sysdb_ctx_get_ldb(parent->sysdb),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd attrs, &forest);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive ret = sysdb_subdomain_store(parent->sysdb, name, realm, flat,
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive id, mpg, enumerate, forest);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret) {
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_subdomain_store failed.\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EOK;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslivedone:
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive talloc_free(tmp_ctx);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive return ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bndstatic errno_t ipa_subdomains_refresh(struct ipa_subdomains_ctx *ctx,
130d299c4b2b15be45532a176604c71fdc7bea5bnd int count, struct sysdb_attrs **reply,
130d299c4b2b15be45532a176604c71fdc7bea5bnd bool *changes)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd struct sss_domain_info *parent, *dom;
130d299c4b2b15be45532a176604c71fdc7bea5bnd bool handled[count];
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *value;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int c, h;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd bool enumerate;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
fb77c505254b6e9c925e23e734463e87574f8f40kess parent = ctx->be_ctx->domain;
fb77c505254b6e9c925e23e734463e87574f8f40kess memset(handled, 0, sizeof(bool) * count);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd h = 0;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
b06660a3ed3d885e15d99c0209a46c4657df33fbrbowen /* check existing subdomains */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (dom = get_next_domain(parent, true);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dom && IS_SUBDOMAIN(dom); /* if we get back to a parent, stop */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dom = get_next_domain(dom, false)) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd for (c = 0; c < count; c++) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (handled[c]) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd continue;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sysdb_attrs_get_string(reply[c], IPA_CN, &value);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_get_string failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (strcmp(value, dom->name) == 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive break;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (c >= count) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* ok this subdomain does not exist anymore, let's clean up */
130d299c4b2b15be45532a176604c71fdc7bea5bnd dom->disabled = true;
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = sysdb_subdomain_delete(dom->sysdb, dom->name);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* Remove the AD ID ctx from the list of LDAP domains */
130d299c4b2b15be45532a176604c71fdc7bea5bnd ipa_ad_subdom_remove(ctx, dom);
130d299c4b2b15be45532a176604c71fdc7bea5bnd } else {
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* ok let's try to update it */
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ipa_subdom_enumerates(parent, reply[c], &enumerate);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ipa_subdom_store(parent, ctx->sdap_id_ctx->opts->idmap_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive reply[c], enumerate);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Nothing we can do about the errorr. Let's at least try
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * to reuse the existing domain
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to parse subdom data, "
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess "will try to use cached subdomain\n"));
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess handled[c] = true;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive h++;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (count == h) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* all domains were already accounted for and have been updated */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* if we get here it means we have changes to the subdomains list */
130d299c4b2b15be45532a176604c71fdc7bea5bnd *changes = true;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd for (c = 0; c < count; c++) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (handled[c]) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess continue;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess /* Nothing we can do about the errorr. Let's at least try
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess * to reuse the existing domain.
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess */
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ret = ipa_subdom_enumerates(parent, reply[c], &enumerate);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ipa_subdom_store(parent, ctx->sdap_id_ctx->opts->idmap_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive reply[c], enumerate);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to parse subdom data, "
130d299c4b2b15be45532a176604c71fdc7bea5bnd "will try to use cached subdomain\n"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnddone:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->last_refreshed = 0;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
fb77c505254b6e9c925e23e734463e87574f8f40kess ctx->last_refreshed = time(NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
97a9a944b5887e91042b019776c41d5dd74557aferikabele}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstruct ipa_subdomains_req_ctx {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct be_req *be_req;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct ipa_subdomains_ctx *sd_ctx;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct sdap_id_op *sdap_op;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *current_filter;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sdap_search_base **search_bases;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int search_base_iter;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd size_t reply_count;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct sysdb_attrs **reply;
15ba1801088da1aad6d20609cf3f7b0b1eefce8aslive};
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic void ipa_subdomains_get_conn_done(struct tevent_req *req);
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t
fe64b2ba25510d8c9dba5560a2d537763566cf40ndipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd enum ipa_subdomains_req_type type);
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic void ipa_subdomains_handler_done(struct tevent_req *req);
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic void ipa_subdomains_handler_master_done(struct tevent_req *req);
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic struct ipa_subdomains_req_params subdomain_requests[] = {
97a9a944b5887e91042b019776c41d5dd74557aferikabele { MASTER_DOMAIN_FILTER,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ipa_subdomains_handler_master_done,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd { IPA_CN, IPA_FLATNAME, IPA_SID, NULL }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd },
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd { SUBDOMAINS_FILTER,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ipa_subdomains_handler_done,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { IPA_CN, IPA_FLATNAME, IPA_TRUSTED_DOMAIN_SID, NULL }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { RANGE_FILTER,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ipa_subdomains_handler_ranges_done,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { OBJECTCLASS, IPA_CN,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd IPA_BASE_ID, IPA_BASE_RID, IPA_SECONDARY_BASE_RID,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd IPA_ID_RANGE_SIZE, IPA_TRUSTED_DOMAIN_SID, IPA_RANGE_TYPE, NULL
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess};
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessstatic void ipa_subdomains_retrieve(struct ipa_subdomains_ctx *ctx, struct be_req *be_req)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_subdomains_req_ctx *req_ctx = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct tevent_req *req;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int dp_error = DP_ERR_FATAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd req_ctx = talloc(be_req, struct ipa_subdomains_req_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (req_ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd req_ctx->be_req = be_req;
fb77c505254b6e9c925e23e734463e87574f8f40kess req_ctx->sd_ctx = ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess req_ctx->search_base_iter = 0;
fb77c505254b6e9c925e23e734463e87574f8f40kess req_ctx->search_bases = ctx->ranges_search_bases;
fb77c505254b6e9c925e23e734463e87574f8f40kess req_ctx->current_filter = NULL;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd req_ctx->reply_count = 0;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd req_ctx->reply = NULL;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd req_ctx->sdap_op = sdap_id_op_create(req_ctx,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->sdap_id_ctx->conn->conn_cache);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (req_ctx->sdap_op == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n"));
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess ret = ENOMEM;
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive req = sdap_id_op_connect_send(req_ctx->sdap_op, req_ctx, &ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (req == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_connect_send failed: %d(%s).\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret, strerror(ret)));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tevent_req_set_callback(req, ipa_subdomains_get_conn_done, req_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fb77c505254b6e9c925e23e734463e87574f8f40kess talloc_free(req_ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret == EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dp_error = DP_ERR_OK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd be_req_terminate(be_req, dp_error, ret, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fb77c505254b6e9c925e23e734463e87574f8f40kessstatic void ipa_subdomains_get_conn_done(struct tevent_req *req)
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive{
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive int ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess int dp_error = DP_ERR_FATAL;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ipa_subdomains_req_ctx *ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sdap_id_op_connect_recv(req, &dp_error);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_zfree(req);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (dp_error == DP_ERR_OFFLINE) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_MINOR_FAILURE,
fb77c505254b6e9c925e23e734463e87574f8f40kess ("No IPA server is available, cannot get the "
97a9a944b5887e91042b019776c41d5dd74557aferikabele "subdomain list while offline\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess/* FIXME: return saved results ?? */
fb77c505254b6e9c925e23e734463e87574f8f40kess } else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ("Failed to connect to IPA server: [%d](%s)\n",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret, strerror(ret)));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto fail;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_RANGES);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (ret != EOK && ret != EAGAIN) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh goto fail;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh return;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessfail:
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess be_req_terminate(ctx->be_req, dp_error, ret, NULL);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh}
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t
fe64b2ba25510d8c9dba5560a2d537763566cf40ndipa_subdomains_handler_get(struct ipa_subdomains_req_ctx *ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd enum ipa_subdomains_req_type type)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct tevent_req *req;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sdap_search_base *base;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ipa_subdomains_req_params *params;
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (type >= IPA_SUBDOMAINS_MAX) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
c985aca104389df30d6ec0a637ce0ccaac904362nd params = &subdomain_requests[type];
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fb77c505254b6e9c925e23e734463e87574f8f40kess base = ctx->search_bases[ctx->search_base_iter];
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (base == NULL) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh return EOK;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh talloc_free(ctx->current_filter);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ctx->current_filter = sdap_get_id_specific_filter(ctx, params->filter,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh base->filter);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (ctx->current_filter == NULL) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess return ENOMEM;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh req = sdap_get_generic_send(ctx, ctx->sd_ctx->be_ctx->ev,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ctx->sd_ctx->sdap_id_ctx->opts,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh sdap_id_op_handle(ctx->sdap_op),
9fb925624300c864fe3969a264e52aa83f3c2dd0slive base->basedn, base->scope,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ctx->current_filter, params->attrs, NULL, 0,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess dp_opt_get_int(ctx->sd_ctx->sdap_id_ctx->opts->basic,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess SDAP_SEARCH_TIMEOUT), false);
9fb925624300c864fe3969a264e52aa83f3c2dd0slive
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (req == NULL) {
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send failed.\n"));
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh return ENOMEM;
05201775eaa6b363b8a119c8aea5db246b967591yoshiki }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh tevent_req_set_callback(req, params->cb, ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh return EAGAIN;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh}
fb77c505254b6e9c925e23e734463e87574f8f40kess
9fb925624300c864fe3969a264e52aa83f3c2dd0slivestatic void ipa_subdomains_handler_done(struct tevent_req *req)
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh{
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh int ret;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess size_t reply_count;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct sysdb_attrs **reply = NULL;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct ipa_subdomains_req_ctx *ctx;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct sss_domain_info *domain;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh bool refresh_has_changes = false;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh int dp_error = DP_ERR_FATAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain = ctx->sd_ctx->be_ctx->domain;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_zfree(req);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (reply_count) {
c985aca104389df30d6ec0a637ce0ccaac904362nd ctx->reply = talloc_realloc(ctx, ctx->reply, struct sysdb_attrs *,
c985aca104389df30d6ec0a637ce0ccaac904362nd ctx->reply_count + reply_count);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ctx->reply == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive memcpy(ctx->reply+ctx->reply_count, reply,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive reply_count * sizeof(struct sysdb_attrs *));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->reply_count += reply_count;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->search_base_iter++;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_SLAVE);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret == EAGAIN) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ipa_subdomains_refresh(ctx->sd_ctx, ctx->reply_count, ctx->reply,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &refresh_has_changes);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("Failed to refresh subdomains.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (refresh_has_changes) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_update_subdomains(domain);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_subdomains failed.\n"));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = ipa_ad_subdom_refresh(ctx->sd_ctx->be_ctx, ctx->sd_ctx->id_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive domain);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("ipa_ad_subdom_refresh failed.\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sss_write_domain_mappings(domain,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dp_opt_get_bool(ctx->sd_ctx->id_ctx->ipa_options->basic,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive IPA_SERVER_MODE));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_MINOR_FAILURE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ("sss_krb5_write_mappings failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Just continue */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_master_domain_update(domain);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive if (domain->flat_name == NULL ||
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive domain->domain_id == NULL ||
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive domain->realm == NULL) {
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->search_base_iter = 0;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->search_bases = ctx->sd_ctx->master_search_bases;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_MASTER);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret == EAGAIN) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret == EOK) {
9fc1345bb54ea7f68c2e59ff3a618c1237a30918yoshiki dp_error = DP_ERR_OK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd be_req_terminate(ctx->be_req, dp_error, ret, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic void ipa_subdomains_handler_ranges_done(struct tevent_req *req)
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess{
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess errno_t ret;
fb109b84906e3ee61680aa289953c2f9e859354erbowen int dp_error = DP_ERR_FATAL;
fb109b84906e3ee61680aa289953c2f9e859354erbowen size_t reply_count;
fb109b84906e3ee61680aa289953c2f9e859354erbowen struct sysdb_attrs **reply = NULL;
fb109b84906e3ee61680aa289953c2f9e859354erbowen struct ipa_subdomains_req_ctx *ctx;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct range_info **range_list = NULL;
fb109b84906e3ee61680aa289953c2f9e859354erbowen struct sysdb_ctx *sysdb;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sss_domain_info *domain;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
fb109b84906e3ee61680aa289953c2f9e859354erbowen domain = ctx->sd_ctx->be_ctx->domain;
fb109b84906e3ee61680aa289953c2f9e859354erbowen sysdb = domain->sysdb;
fb109b84906e3ee61680aa289953c2f9e859354erbowen
fb109b84906e3ee61680aa289953c2f9e859354erbowen ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_zfree(req);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ipa_ranges_parse_results(ctx, reply_count, reply, &range_list);
fb109b84906e3ee61680aa289953c2f9e859354erbowen if (ret != EOK) {
fb109b84906e3ee61680aa289953c2f9e859354erbowen DEBUG(SSSDBG_OP_FAILURE,
fb109b84906e3ee61680aa289953c2f9e859354erbowen ("ipa_ranges_parse_results request failed.\n"));
fb109b84906e3ee61680aa289953c2f9e859354erbowen goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_update_ranges(sysdb, range_list);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(range_list);
c023f60e35022146373e40249f0c8c8d623b6fcfnd if (ret != EOK) {
c023f60e35022146373e40249f0c8c8d623b6fcfnd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_update_ranges failed.\n"));
c023f60e35022146373e40249f0c8c8d623b6fcfnd goto done;
c023f60e35022146373e40249f0c8c8d623b6fcfnd }
c023f60e35022146373e40249f0c8c8d623b6fcfnd
c023f60e35022146373e40249f0c8c8d623b6fcfnd ctx->search_base_iter = 0;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->search_bases = ctx->sd_ctx->search_bases;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_SLAVE);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret == EAGAIN) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("No search base for ranges available.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret == EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd dp_error = DP_ERR_OK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd be_req_terminate(ctx->be_req, dp_error, ret, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic void ipa_subdomains_handler_master_done(struct tevent_req *req)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive errno_t ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess int dp_error = DP_ERR_FATAL;
fb77c505254b6e9c925e23e734463e87574f8f40kess size_t reply_count;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct sysdb_attrs **reply = NULL;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ipa_subdomains_req_ctx *ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ctx = tevent_req_callback_data(req, struct ipa_subdomains_req_ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sdap_get_generic_recv(req, ctx, &reply_count, &reply);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_zfree(req);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sdap_get_generic_send request failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (reply_count) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *flat = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *id = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sysdb_attrs_get_string(reply[0], IPA_FLATNAME, &flat);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_get_string(reply[0], IPA_SID, &id);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sysdb_master_domain_add_info(ctx->sd_ctx->be_ctx->domain,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd flat, id);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd } else {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->search_base_iter++;
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd ret = ipa_subdomains_handler_get(ctx, IPA_SUBDOMAINS_MASTER);
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd if (ret == EAGAIN) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (ret != EOK) {
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Right now we know there has been an error
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * and we don't have the master domain record
fe64b2ba25510d8c9dba5560a2d537763566cf40nd */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE, ("Master domain record not found!\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!ctx->sd_ctx->configured_explicit) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->sd_ctx->disabled_until = time(NULL) +
fe64b2ba25510d8c9dba5560a2d537763566cf40nd IPA_SUBDOMAIN_DISABLED_PERIOD;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EIO;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckessdone:
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess if (ret == EOK) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess dp_error = DP_ERR_OK;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess be_req_terminate(ctx->be_req, dp_error, ret, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabelestatic void ipa_subdom_online_cb(void *pvt);
97a9a944b5887e91042b019776c41d5dd74557aferikabele
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic void ipa_subdom_timer_refresh(struct tevent_context *ev,
97a9a944b5887e91042b019776c41d5dd74557aferikabele struct tevent_timer *te,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct timeval current_time,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive void *pvt)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
fb77c505254b6e9c925e23e734463e87574f8f40kess ipa_subdom_online_cb(pvt);
fb77c505254b6e9c925e23e734463e87574f8f40kess}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic void ipa_subdom_be_req_callback(struct be_req *be_req,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int dp_err, int dp_ret,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd const char *errstr)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(be_req);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessstatic void ipa_subdom_reset_timeouts_cb(void *pvt)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
97a9a944b5887e91042b019776c41d5dd74557aferikabele struct ipa_subdomains_ctx *ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE, ("Bad private pointer\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess DEBUG(SSSDBG_TRACE_ALL, ("Resetting last_refreshed and disabled_until.\n"));
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ctx->last_refreshed = 0;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->disabled_until = 0;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic void ipa_subdom_online_cb(void *pvt)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_subdomains_ctx *ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct be_req *be_req;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct timeval tv;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd uint32_t refresh_interval;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!ctx) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE, ("Bad private pointer\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->disabled_until = 0;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd refresh_interval = ctx->be_ctx->domain->subdomain_refresh_interval;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd be_req = be_req_create(ctx, NULL, ctx->be_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ipa_subdom_be_req_callback, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (be_req == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE, ("be_req_create() failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ipa_subdomains_retrieve(ctx, be_req);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tv = tevent_timeval_current_ofs(refresh_interval, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->timer_event = tevent_add_timer(ctx->be_ctx->ev, ctx, tv,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ipa_subdom_timer_refresh, ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!ctx->timer_event) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom timer event\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
c97e8972ab1f4dd167e3dc4db87daf91114009fbnd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic void ipa_subdom_offline_cb(void *pvt)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_subdomains_ctx *ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
c985aca104389df30d6ec0a637ce0ccaac904362nd ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ctx) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele talloc_zfree(ctx->timer_event);
fb77c505254b6e9c925e23e734463e87574f8f40kess }
97a9a944b5887e91042b019776c41d5dd74557aferikabele}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic errno_t get_config_status(struct be_ctx *be_ctx,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd bool *configured_explicit)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
fb77c505254b6e9c925e23e734463e87574f8f40kess int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd TALLOC_CTX *tmp_ctx = NULL;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd char *tmp_str;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tmp_ctx = talloc_new(NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (tmp_ctx == NULL) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(SSSDBG_OP_FAILURE, ("talloc_new failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
7654193c1faf603feec999850322ad79e6c551bcnd
7654193c1faf603feec999850322ad79e6c551bcnd ret = confdb_get_string(be_ctx->cdb, tmp_ctx, be_ctx->conf_path,
c97e8972ab1f4dd167e3dc4db87daf91114009fbnd CONFDB_DOMAIN_SUBDOMAINS_PROVIDER, NULL,
7654193c1faf603feec999850322ad79e6c551bcnd &tmp_str);
7654193c1faf603feec999850322ad79e6c551bcnd if (ret != EOK) {
7654193c1faf603feec999850322ad79e6c551bcnd DEBUG(SSSDBG_OP_FAILURE, ("confdb_get_string failed.\n"));
7654193c1faf603feec999850322ad79e6c551bcnd goto done;
7654193c1faf603feec999850322ad79e6c551bcnd }
7654193c1faf603feec999850322ad79e6c551bcnd
7654193c1faf603feec999850322ad79e6c551bcnd if (tmp_str == NULL) {
7654193c1faf603feec999850322ad79e6c551bcnd *configured_explicit = false;
7654193c1faf603feec999850322ad79e6c551bcnd } else {
7654193c1faf603feec999850322ad79e6c551bcnd *configured_explicit = true;
7654193c1faf603feec999850322ad79e6c551bcnd }
7654193c1faf603feec999850322ad79e6c551bcnd
c97e8972ab1f4dd167e3dc4db87daf91114009fbnd DEBUG(SSSDBG_TRACE_ALL, ("IPA subdomain provider is configured %s.\n",
7654193c1faf603feec999850322ad79e6c551bcnd *configured_explicit ? "explicit" : "implicit"));
7654193c1faf603feec999850322ad79e6c551bcnd
7654193c1faf603feec999850322ad79e6c551bcnd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(tmp_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kessvoid ipa_subdomains_handler(struct be_req *be_req)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct be_ctx *be_ctx = be_req_get_be_ctx(be_req);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_subdomains_ctx *ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd time_t now;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx = talloc_get_type(be_ctx->bet_info[BET_SUBDOMAINS].pvt_bet_data,
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ipa_subdomains_ctx);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (!ctx) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be_req_terminate(be_req, DP_ERR_FATAL, EINVAL, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive now = time(NULL);
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ctx->disabled_until > now) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_TRACE_ALL, ("Subdomain provider disabled.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be_req_terminate(be_req, DP_ERR_OK, EOK, NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess return;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ctx->last_refreshed > now - IPA_SUBDOMAIN_REFRESH_LIMIT) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be_req_terminate(be_req, DP_ERR_OK, EOK, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ipa_subdomains_retrieve(ctx, be_req);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kessstruct bet_ops ipa_subdomains_ops = {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess .handler = ipa_subdomains_handler,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess .finalize = NULL
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess};
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint ipa_subdom_init(struct be_ctx *be_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_id_ctx *id_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct bet_ops **ops,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd void **pvt_data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_subdomains_ctx *ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool configured_explicit = false;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = get_config_status(be_ctx, &configured_explicit);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE, ("get_config_status failed.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx = talloc_zero(id_ctx, struct ipa_subdomains_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ctx == NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->be_ctx = be_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->id_ctx = id_ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->sdap_id_ctx = id_ctx->sdap_id_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->search_bases = id_ctx->ipa_options->subdomains_search_bases;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->master_search_bases = id_ctx->ipa_options->master_domain_search_bases;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->ranges_search_bases = id_ctx->ipa_options->ranges_search_bases;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->configured_explicit = configured_explicit;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->disabled_until = 0;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *ops = &ipa_subdomains_ops;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd *pvt_data = ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = be_add_unconditional_online_cb(ctx, be_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ipa_subdom_reset_timeouts_cb, ctx,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd NULL);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_MINOR_FAILURE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ("Failed to add subdom reset timeouts callback"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = be_add_online_cb(ctx, be_ctx, ipa_subdom_online_cb, ctx, NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom online callback"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = be_add_offline_cb(ctx, be_ctx, ipa_subdom_offline_cb, ctx, NULL);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom offline callback"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd return EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnd}
130d299c4b2b15be45532a176604c71fdc7bea5bnd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint ipa_ad_subdom_init(struct be_ctx *be_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ipa_id_ctx *id_ctx)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *realm;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *hostname;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (dp_opt_get_bool(id_ctx->ipa_options->basic,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd IPA_SERVER_MODE) == false) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* The IPA code relies on the default FQDN format to unparse user
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * names. Warn loudly if the full_name_format was customized on the
fe64b2ba25510d8c9dba5560a2d537763566cf40nd * IPA server
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd */
fb77c505254b6e9c925e23e734463e87574f8f40kess if ((strcmp(be_ctx->domain->names->fq_fmt,
fb77c505254b6e9c925e23e734463e87574f8f40kess CONFDB_DEFAULT_FULL_NAME_FORMAT) != 0)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd && (strcmp(be_ctx->domain->names->fq_fmt,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd CONFDB_DEFAULT_FULL_NAME_FORMAT_INTERNAL) != 0)) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_FATAL_FAILURE, ("%s is set to a non-default value [%s] " \
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "lookups of subdomain users will likely fail!\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_FULL_NAME_FORMAT, be_ctx->domain->names->fq_fmt));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sss_log(SSS_LOG_ERR, "%s is set to a non-default value [%s] " \
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "lookups of subdomain users will likely fail!\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CONFDB_FULL_NAME_FORMAT, be_ctx->domain->names->fq_fmt);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Attempt to continue */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive realm = dp_opt_get_string(id_ctx->ipa_options->basic, IPA_KRB5_REALM);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (realm == NULL) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_CRIT_FAILURE, ("No Kerberos realm for IPA?\n"));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return EINVAL;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive hostname = dp_opt_get_string(id_ctx->ipa_options->basic, IPA_HOSTNAME);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (hostname == NULL) {
bea526116133aa3d7dabd1924bfc580b37fbf22aslive DEBUG(SSSDBG_CRIT_FAILURE, ("No host name for IPA?\n"));
bea526116133aa3d7dabd1924bfc580b37fbf22aslive return EINVAL;
bea526116133aa3d7dabd1924bfc580b37fbf22aslive }
bea526116133aa3d7dabd1924bfc580b37fbf22aslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive id_ctx->server_mode = talloc_zero(id_ctx, struct ipa_server_mode_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (id_ctx->server_mode == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
bea526116133aa3d7dabd1924bfc580b37fbf22aslive id_ctx->server_mode->realm = realm;
bea526116133aa3d7dabd1924bfc580b37fbf22aslive id_ctx->server_mode->hostname = hostname;
bea526116133aa3d7dabd1924bfc580b37fbf22aslive id_ctx->server_mode->trusts = NULL;
fb77c505254b6e9c925e23e734463e87574f8f40kess id_ctx->server_mode->ext_groups = NULL;
bea526116133aa3d7dabd1924bfc580b37fbf22aslive
bea526116133aa3d7dabd1924bfc580b37fbf22aslive return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd