bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina Pavel Březina <pbrezina@redhat.com>
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina Copyright (C) 2016 Red Hat
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina This program is free software; you can redistribute it and/or modify
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina it under the terms of the GNU General Public License as published by
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina the Free Software Foundation; either version 3 of the License, or
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina (at your option) any later version.
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina This program is distributed in the hope that it will be useful,
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina GNU General Public License for more details.
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina You should have received a copy of the GNU General Public License
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina#include "providers/data_provider/dp_private.h"
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinadp_failover_list_services_ldap(struct be_ctx *be_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina services[count] = talloc_strdup(services, svc->name);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinadp_failover_list_services_ad(struct be_ctx *be_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fo_svc_name = talloc_asprintf(services, "sd_%s", domain->name);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina /* Drop each sd_gc_* since this service is not used with AD at all,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * we only connect to AD_GC for global catalog. */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (strncasecmp(svc->name, "sd_gc_", strlen("sd_gc_")) == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina /* Drop all subdomain services for different domain. */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (strncasecmp(svc->name, "sd_", strlen("sd_")) == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (strcasecmp(svc->name, fo_svc_name) != 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina /* Drop AD since we connect to subdomain.com for LDAP. */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina services[count] = talloc_strdup(services, svc->name);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinadp_failover_list_services_ipa(struct be_ctx *be_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fo_svc_name = talloc_asprintf(services, "sd_%s", domain->name);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fo_gc_name = talloc_asprintf(services, "sd_gc_%s", domain->name);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina /* Drop all subdomain services for different domain. */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (strncasecmp(svc->name, "sd_", strlen("sd_")) == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina services[count] = talloc_strdup(services, svc->name);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DP_FO_SVC_MIXED = DP_FO_SVC_AD | DP_FO_SVC_IPA
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březinaerrno_t dp_failover_list_services(struct sbus_request *sbus_req,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina enum dp_fo_svc_type svc_type = DP_FO_SVC_LDAP;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina domain = find_domain_by_name(be_ctx->domain, domname, false);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * Returning list of failover services is currently rather difficult
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * since there is only one failover context for the whole backend.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * The list of services for the given domain depends on whether it is
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * a master domain or a subdomain and whether we are using IPA, AD or
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * LDAP backend.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * For LDAP we just return everything we have.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * For AD master domain we return AD, AD_GC.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * For AD subdomain we return subdomain.com, AD_GC.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * For IPA in client mode we return IPA.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * For IPA in server mode we return IPA for master domain and
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * subdomain.com, gc_subdomain.com for subdomain.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * We also return everything else for all cases if any other service
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina * such as kerberos is configured separately.
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina /* Allocate enough space. */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina } else if (strcasecmp(svc->name, "IPA") == 0) {
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina services = talloc_zero_array(sbus_req, const char *, num_services);
bf83a0faacf16196ab9bd37dcf6190b4209ccaf7Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina /* Fill the list. */
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = dp_failover_list_services_ldap(be_ctx, services, &num_services);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = dp_failover_list_services_ad(be_ctx, domain,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = dp_failover_list_services_ipa(be_ctx, domain,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create service list [%d]: %s\n",
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina iface_dp_failover_ListServices_finish(sbus_req, services, num_services);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaerrno_t dp_failover_active_server(struct sbus_request *sbus_req,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get server name\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_NOT_FOUND,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina "Unknown service name");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina server = fo_get_server_name(svc->last_good_srv);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get server name\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_INTERNAL,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina "Unable to get server name");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina iface_dp_failover_ActiveServer_finish(sbus_req, server);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinaerrno_t dp_failover_list_servers(struct sbus_request *sbus_req,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get server list\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sbus_request_reply_error(sbus_req, SBUS_ERROR_NOT_FOUND,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina "Unknown service name");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina servers = fo_svc_server_list(sbus_req, svc->fo_service, &count);