ad_common.c revision 892ddeb5190dd5c1ffa26a95142a10a0034fc5e3
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen Stephen Gallagher <sgallagh@redhat.com>
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen Copyright (C) 2012 Red Hat
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen This program is free software; you can redistribute it and/or modify
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen it under the terms of the GNU General Public License as published by
e54512a5189192fe72d1e2c53927c98c5ac920b4Timo Sirainen the Free Software Foundation; either version 3 of the License, or
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (at your option) any later version.
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen This program is distributed in the hope that it will be useful,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen GNU General Public License for more details.
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen You should have received a copy of the GNU General Public License
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainenerrno_t ad_set_search_bases(struct sdap_options *id_opts);
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainenstatic errno_t ad_set_sdap_options(struct ad_options *ad_opts,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenad_create_default_sdap_options(TALLOC_CTX *mem_ctx)
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen id_opts = talloc_zero(mem_ctx, struct sdap_options);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Get sdap option maps */
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen /* General Attribute Map */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* User map */
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen /* Group map */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Netgroup map */
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen /* Services map */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ad_options = talloc_zero(mem_ctx, struct ad_options);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ad_options->id = ad_create_default_sdap_options(ad_options);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Cannot initialize AD LDAP options\n");
872b8fd8a8db97dc54067b7ab25bda96ec0aac0dTimo Sirainenset_common_ad_trust_opts(struct ad_options *ad_options,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen ret = dp_opt_set_string(ad_options->basic, AD_KRB5_REALM, realm);
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Cannot set AD krb5 realm\n");
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen ret = dp_opt_set_string(ad_options->basic, AD_DOMAIN, ad_domain);
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Cannot set AD domain\n");
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen ret = dp_opt_set_string(ad_options->basic, AD_HOSTNAME, hostname);
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Cannot set AD hostname\n");
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen ret = dp_opt_set_string(ad_options->basic, AD_KEYTAB, keytab);
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Cannot set keytab\n");
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainenad_create_2way_trust_options(TALLOC_CTX *mem_ctx,
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen ad_options = ad_create_default_options(mem_ctx);
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen ret = set_common_ad_trust_opts(ad_options, realm, ad_domain, hostname,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ret = ad_set_sdap_options(ad_options, ad_options->id);
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainenad_create_1way_trust_options(TALLOC_CTX *mem_ctx,
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen ad_options = ad_create_default_options(mem_ctx);
45b2a27617d8475f71fdfc870690e46cd63849f2Timo Sirainen realm = get_uppercase_realm(ad_options, ad_domain);
45b2a27617d8475f71fdfc870690e46cd63849f2Timo Sirainen ret = set_common_ad_trust_opts(ad_options, realm,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen /* Set SDAP_SASL_AUTHID to the trust principal */
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen ret = dp_opt_set_string(ad_options->id->basic,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen DEBUG(SSSDBG_OP_FAILURE, "Cannot set SASL authid\n");
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen ret = ad_set_sdap_options(ad_options, ad_options->id);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen id_opts = talloc_zero(mem_ctx, struct sdap_options);
97511ac4d7607e1ba64ce151eda3d9b5f9775519Timo Sirainen /* Get sdap option maps */
97511ac4d7607e1ba64ce151eda3d9b5f9775519Timo Sirainen /* General Attribute Map */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* User map */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ret = sdap_extend_map_with_list(id_opts, id_opts,
38d7db318188c4ac9cdc8c6cdb936b36a5258e19Timo Sirainen /* Group map */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Netgroup map */
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen /* Services map */
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen opts = talloc_zero(mem_ctx, struct ad_options);
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen /* If the AD domain name wasn't explicitly set, assume that it
dd0dea1fdd913a04bae16e82dd66d67571a5f6c2Timo Sirainen * matches the SSSD domain name
dd0dea1fdd913a04bae16e82dd66d67571a5f6c2Timo Sirainen domain = dp_opt_get_string(opts->basic, AD_DOMAIN);
dd0dea1fdd913a04bae16e82dd66d67571a5f6c2Timo Sirainen ret = dp_opt_set_string(opts->basic, AD_DOMAIN, dom->name);
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen /* Did we get an explicit server name, or are we discovering it? */
dd0dea1fdd913a04bae16e82dd66d67571a5f6c2Timo Sirainen server = dp_opt_get_string(opts->basic, AD_SERVER);
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen "No AD server set, will use service discovery!\n");
dd0dea1fdd913a04bae16e82dd66d67571a5f6c2Timo Sirainen /* Set the machine's hostname to the local host name if it
dd0dea1fdd913a04bae16e82dd66d67571a5f6c2Timo Sirainen * wasn't explicitly specified.
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainen ad_hostname = dp_opt_get_string(opts->basic, AD_HOSTNAME);
20195ef995a4eb63a282283db63f1dc0605323e0Timo Sirainen "gethostname failed [%s].\n",
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen ret = dp_opt_set_string(opts->basic, AD_HOSTNAME, hostname);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen "Setting ad_hostname failed [%s].\n",
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen /* Always use the upper-case AD domain for the kerberos realm */
20195ef995a4eb63a282283db63f1dc0605323e0Timo Sirainen ret = dp_opt_set_string(opts->basic, AD_KRB5_REALM, realm);
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainen /* Active Directory is always case-insensitive */
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainen ret = confdb_get_string(cdb, mem_ctx, conf_path,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "condb_get_string failed.\n");
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (strcasecmp(case_sensitive_opt, "true") == 0) {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen "Warning: AD domain can not be set as case-sensitive.\n");
20195ef995a4eb63a282283db63f1dc0605323e0Timo Sirainen } else if (strcasecmp(case_sensitive_opt, "false") == 0) {
20195ef995a4eb63a282283db63f1dc0605323e0Timo Sirainen } else if (strcasecmp(case_sensitive_opt, "preserving") == 0) {
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen "Invalid value for %s\n", CONFDB_DOMAIN_CASE_SENSITIVE);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen opt_override = dom->case_preserve ? "preserving" : "false";
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen /* Set this in the confdb so that the responders pick it
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen * up when they start up.
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen ret = confdb_set_string(cdb, conf_path, "case_sensitive", opt_override);
20195ef995a4eb63a282283db63f1dc0605323e0Timo Sirainen "Could not set domain option case_sensitive: [%s]\n",
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen "Setting domain option case_sensitive to [%s]\n", opt_override);
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainenad_resolve_callback(void *private_data, struct fo_server *server);
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen /* Split the server list */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen ret = split_on_separator(tmp_ctx, servers, ',', true, true, &list, NULL);
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Failed to parse server list!\n");
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen /* Add each of these servers to the failover service */
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen for (i = 0; list[i]; i++) {
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen "Failed to add server [%s] to failover service: "
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen "SRV resolution only allowed for primary servers!\n",
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen sdata = talloc(service, struct ad_server_data);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ret = be_fo_add_srv_server(bectx, fo_gc_service, "gc",
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen "Failed to add service discovery to failover: [%s]\n",
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen sdata = talloc(service, struct ad_server_data);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen ret = be_fo_add_srv_server(bectx, fo_service, "ldap",
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen "Failed to add service discovery to failover: [%s]\n",
1e242794e7a4f653f18fbb8edfe9ccec489a3a08Timo Sirainen DEBUG(SSSDBG_CONF_SETTINGS, "Added service discovery for AD\n");
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen /* It could be ipv6 address in square brackets. Remove
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen * the brackets if needed. */
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen sdata = talloc(service, struct ad_server_data);
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen ret = be_fo_add_server(bectx, fo_gc_service, list[i], 0, sdata, primary);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add server\n");
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen sdata = talloc(service, struct ad_server_data);
5dabb8e733a8af2337eb543f782eb6c43ea462dcTimo Sirainen ret = be_fo_add_server(bectx, fo_service, list[i], 0, sdata, primary);
5dabb8e733a8af2337eb543f782eb6c43ea462dcTimo Sirainen DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add server\n");
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen DEBUG(SSSDBG_CONF_SETTINGS, "Added failover server %s\n", list[i]);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenad_primary_servers_init(struct ad_service *service,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen const char *fo_service, const char *fo_gc_service,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen return _ad_servers_init(service, bectx, fo_service,
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainenad_backup_servers_init(struct ad_service *service,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen const char *fo_service, const char *fo_gc_service,
38d7db318188c4ac9cdc8c6cdb936b36a5258e19Timo Sirainen return _ad_servers_init(service, bectx, fo_service,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstatic int ad_user_data_cmp(void *ud1, void *ud2)
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen sd1 = talloc_get_type(ud1, struct ad_server_data);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen sd2 = talloc_get_type(ud2, struct ad_server_data);
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen struct ad_service *service = talloc_get_type(pvt, struct ad_service);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Invalid private pointer\n");
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen DEBUG(SSSDBG_TRACE_FUNC, "The AD provider is online\n");
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainenad_failover_init(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen service = talloc_zero(tmp_ctx, struct ad_service);
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen service->sdap = talloc_zero(service, struct sdap_service);
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen service->gc = talloc_zero(service, struct sdap_service);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen service->sdap->name = talloc_strdup(service->sdap, ad_service);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen service->gc->name = talloc_strdup(service->gc, ad_gc_service);
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen if (!service->sdap->name || !service->gc->name) {
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen service->krb5_service = talloc_zero(service, struct krb5_service);
dce5a2719df4fc64a8762d2aa94ba98dcf9cd6feTimo Sirainen ret = be_fo_add_service(bectx, ad_service, ad_user_data_cmp);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create failover service!\n");
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainen ret = be_fo_add_service(bectx, ad_gc_service, ad_user_data_cmp);
185ed0142fbbfb86e7a98519e7c6f11ec00723cdTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create GC failover service!\n");
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen service->krb5_service->name = talloc_strdup(service->krb5_service,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen service->sdap->kinit_service_name = service->krb5_service->name;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen service->gc->kinit_service_name = service->krb5_service->name;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "No Kerberos realm set\n");
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen talloc_strdup(service->krb5_service, krb5_realm);
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen "No primary servers defined, using service discovery\n");
185ed0142fbbfb86e7a98519e7c6f11ec00723cdTimo Sirainen ret = be_add_online_cb(bectx, bectx, ad_online_cb, service, NULL);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up AD online callback\n");
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen ret = be_fo_service_add_callback(mem_ctx, bectx, ad_service,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen "Failed to add failover callback! [%s]\n", strerror(ret));
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen ret = be_fo_service_add_callback(mem_ctx, bectx, ad_gc_service,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen "Failed to add failover callback! [%s]\n", strerror(ret));
042e2b8447b34051f0380baafcf0073704430239Timo Sirainenad_resolve_callback(void *private_data, struct fo_server *server)
042e2b8447b34051f0380baafcf0073704430239Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
042e2b8447b34051f0380baafcf0073704430239Timo Sirainen if (fo_is_srv_lookup(server) == false && sdata == NULL) {
042e2b8447b34051f0380baafcf0073704430239Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "No user data?\n");
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen service = talloc_get_type(private_data, struct ad_service);
goto done;
goto done;
goto done;
if (!new_uri) {
goto done;
goto done;
new_port);
sizeof(struct sockaddr_storage));
goto done;
goto done;
address);
goto done;
done:
static errno_t
char *krb5_realm;
char *keytab_path;
goto done;
if (!krb5_realm) {
goto done;
if (keytab_path) {
goto done;
done:
return ret;
const char *conf_path,
return ENOMEM;
return ret;
NULL);
return ret;
return ret;
return EOK;
const char *conf_path)
cdb,
return ret;
cdb,
return ret;
return EOK;
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;
if (!krb5_realm) {
goto done;
done:
return ret;
return ret;
return EOK;
struct ad_id_ctx *
return NULL;
return NULL;
return NULL;
return ad_ctx;
struct sdap_id_conn_ctx *
return NULL;
return conn;
struct sdap_id_conn_ctx **
int cindex = 0;
cindex++;
return clist;
struct sdap_id_conn_ctx **
return NULL;
return clist;
struct sdap_id_conn_ctx **
int cindex = 0;
return NULL;
cindex++;
return clist;