ad_common.c revision 4a1e58d85409fbb7a12ac244c3dbef8c0c1b15df
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn Stephen Gallagher <sgallagh@redhat.com>
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn Copyright (C) 2012 Red Hat
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn This program is free software; you can redistribute it and/or modify
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn it under the terms of the GNU General Public License as published by
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn the Free Software Foundation; either version 3 of the License, or
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn (at your option) any later version.
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn This program is distributed in the hope that it will be useful,
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn but WITHOUT ANY WARRANTY; without even the implied warranty of
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn GNU General Public License for more details.
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn You should have received a copy of the GNU General Public License
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn along with this program. If not, see <http://www.gnu.org/licenses/>.
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn opts = talloc_zero(mem_ctx, struct ad_options);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn /* If the AD domain name wasn't explicitly set, assume that it
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn * matches the SSSD domain name
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn domain = dp_opt_get_string(opts->basic, AD_DOMAIN);
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn ret = dp_opt_set_string(opts->basic, AD_DOMAIN, dom->name);
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber /* Did we get an explicit server name, or are we discovering it? */
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn server = dp_opt_get_string(opts->basic, AD_SERVER);
9313e1e628160ca64f9e7fcec6500056c9a0725fStéphane Graber ("No AD server set, will use service discovery!\n"));
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber /* Set the machine's hostname to the local host name if it
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber * wasn't explicitly specified.
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber ad_hostname = dp_opt_get_string(opts->basic, AD_HOSTNAME);
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber gret = gethostname(hostname, HOST_NAME_MAX);
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber ("gethostname failed [%s].\n",
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber ("Setting ad_hostname to [%s].\n", hostname));
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber ret = dp_opt_set_string(opts->basic, AD_HOSTNAME, hostname);
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber ("Setting ad_hostname failed [%s].\n",
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber /* Always use the upper-case AD domain for the kerberos realm */
0a3673e80732ab83d807d406fb2fd3c3b7f54ad3Stéphane Graber for (i = 0; realm[i]; i++) {
0a3673e80732ab83d807d406fb2fd3c3b7f54ad3Stéphane Graber ret = dp_opt_set_string(opts->basic, AD_KRB5_REALM, realm);
0a3673e80732ab83d807d406fb2fd3c3b7f54ad3Stéphane Graber /* Active Directory is always case-insensitive */
42ff5f0f8767114d060f5031055038a1a1c3759aSerge Hallyn /* Set this in the confdb so that the responders pick it
42ff5f0f8767114d060f5031055038a1a1c3759aSerge Hallyn * up when they start up.
542939c31bb73bab55f2fd71243b98f5559597d1Stéphane Graber ret = confdb_set_bool(cdb, conf_path, "case_sensitive",
42ff5f0f8767114d060f5031055038a1a1c3759aSerge Hallyn ("Could not set domain case-sensitive: [%s]\n",
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ("Setting domain case-insensitive\n"));
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moserad_resolve_callback(void *private_data, struct fo_server *server);
ad3f14ab58ec91ff11d0dcf2cbd5f47f02935344Scott Moser /* Split the server list */
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser ret = split_on_separator(tmp_ctx, servers, ',', true, &list, NULL);
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to parse server list!\n"));
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ad_domain = dp_opt_get_string(options->basic, AD_DOMAIN);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn /* Add each of these servers to the failover service */
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn for (i = 0; list[i]; i++) {
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ("Failed to add server [%s] to failover service: "
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn "SRV resolution only allowed for primary servers!\n",
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn ret = be_fo_add_srv_server(bectx, AD_SERVICE_NAME, "ldap",
8a3c76b24d73ab8a830035e7a66400e2cc2e8334Stéphane Graber ("Failed to add service discovery to failover: [%s]",
52c8f624b5f9ef665f33a7aa80e0aa18b91daa4aSerge Hallyn DEBUG(SSSDBG_CONF_SETTINGS, ("Added service discovery for AD\n"));
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ret = be_fo_add_server(bectx, AD_SERVICE_NAME, list[i], 0, NULL, primary);
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add server\n"));
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn DEBUG(SSSDBG_CONF_SETTINGS, ("Added failover server %s\n", list[i]));
427bffc7a10c9015dc78ef52543f7b8cb9414359Serge Hallynad_failover_init(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser service = talloc_zero(tmp_ctx, struct ad_service);
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe service->sdap = talloc_zero(service, struct sdap_service);
ad3f14ab58ec91ff11d0dcf2cbd5f47f02935344Scott Moser service->krb5_service = talloc_zero(service, struct krb5_service);
ad3f14ab58ec91ff11d0dcf2cbd5f47f02935344Scott Moser ret = be_fo_add_service(bectx, AD_SERVICE_NAME);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to create failover service!\n"));
427bffc7a10c9015dc78ef52543f7b8cb9414359Serge Hallyn service->sdap->name = talloc_strdup(service, AD_SERVICE_NAME);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn service->krb5_service->name = talloc_strdup(service, AD_SERVICE_NAME);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn service->sdap->kinit_service_name = service->krb5_service->name;
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallyn realm = dp_opt_get_string(options->basic, AD_KRB5_REALM);
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("No Kerberos realm set\n"));
9cde0368fbbfa61add2e73f8ccd5b00c1b0f2e08Stéphane Graber ("No primary servers defined but backup are present, "
9cde0368fbbfa61add2e73f8ccd5b00c1b0f2e08Stéphane Graber "setting backup servers as primary\n"));
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ("No primary or backup servers defined but backup are present, "
4b954f12173c382f7104a0e9464fa66dd3cade35Dimitri John Ledkov "setting backup servers as primary\n"));
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn ret = ad_servers_init(mem_ctx, bectx, primary_servers, options, true);
ad3f14ab58ec91ff11d0dcf2cbd5f47f02935344Scott Moser ret = ad_servers_init(mem_ctx, bectx, backup_servers, options, false);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ret = be_fo_service_add_callback(mem_ctx, bectx, AD_SERVICE_NAME,
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn ("Failed to add failover callback! [%s]\n", strerror(ret)));
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallynad_resolve_callback(void *private_data, struct fo_server *server)
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
3eecde703e9ac3af788ac17357f378d6b6d7c658Serge Hallyn service = talloc_get_type(private_data, struct ad_service);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ("No hostent available for server (%s)\n",
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn sockaddr = resolv_get_sockaddr_address(tmp_ctx, srvaddr, LDAP_PORT);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("resolv_get_sockaddr_address failed.\n"));
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn address = resolv_get_string_address(tmp_ctx, srvaddr);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("resolv_get_string_address failed.\n"));
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("Could not get server host name\n"));
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn new_uri = talloc_asprintf(service, "ldap://%s", srv_name);
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to copy URI\n"));
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn DEBUG(SSSDBG_CONF_SETTINGS, ("Constructed uri '%s'\n", new_uri));
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn /* free old one and replace with new one */
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser service->sdap->sockaddr = talloc_steal(service, sockaddr);
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn DEBUG(SSSDBG_CRIT_FAILURE, ("sss_escape_ip_address failed.\n"));
b942e67226af9e690bd63ac440b99aedb6becbb3Scott Moser ret = write_krb5info_file(service->krb5_service->realm, safe_address,
done:
const char *conf_path,
char *krb5_realm;
char *sasl_primary;
char *desired_primary;
char *sasl_realm;
char *desired_realm;
char *keytab_path;
bool primary_requested = true;
bool realm_requested = true;
if (!id_opts) {
goto done;
goto done;
goto done;
if (!krb5_realm) {
goto done;
krb5_realm));
if (!desired_primary) {
primary_requested = false;
if (!desired_realm) {
realm_requested = false;
if (keytab_path) {
keytab_path));
goto done;
sasl_primary));
sasl_realm));
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
char *default_search_base;
size_t o;
if (default_search_base) {
search_base_options[o])) {
goto done;
search_base_options[o])));
done:
return ret;
const char *ad_servers;
const char *krb5_realm;
&krb5_options);
goto done;
ad_servers));
if (!krb5_realm) {
goto done;
krb5_realm));
done:
return ret;