effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher/*
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SSSD
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Authors:
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Copyright (C) 2012 Red Hat
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher This program is free software; you can redistribute it and/or modify
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher it under the terms of the GNU General Public License as published by
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher (at your option) any later version.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher This program is distributed in the hope that it will be useful,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher GNU General Public License for more details.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher You should have received a copy of the GNU General Public License
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher*/
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include <ctype.h>
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include "providers/ad/ad_common.h"
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include "providers/ad/ad_opts.h"
892ddeb5190dd5c1ffa26a95142a10a0034fc5e3Pavel Březina#include "providers/be_dyndns.h"
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozekstruct ad_server_data {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek bool gc;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek};
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
4c49edbd8df651b1737c59459637962c117212c6Michal Židekerrno_t ad_set_search_bases(struct sdap_options *id_opts,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek struct sdap_domain *sdap);
44ba573582072823d8760d0f18e5b3195cecc182Jakub Hrozekstatic errno_t ad_set_sdap_options(struct ad_options *ad_opts,
44ba573582072823d8760d0f18e5b3195cecc182Jakub Hrozek struct sdap_options *id_opts);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekstatic struct sdap_options *
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozekad_create_default_sdap_options(TALLOC_CTX *mem_ctx,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek struct data_provider *dp)
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek{
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct sdap_options *id_opts;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek errno_t ret;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek id_opts = talloc_zero(mem_ctx, struct sdap_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (!id_opts) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek id_opts->dp = dp;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ret = dp_copy_defaults(id_opts,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek ad_def_ldap_opts,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek SDAP_OPTS_BASIC,
90afedb00608547ae1f32aa7aafd552c4b306909Jakub Hrozek &id_opts->basic);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek goto fail;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* Get sdap option maps */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* General Attribute Map */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sdap_copy_map(id_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_2008r2_attr_map,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek SDAP_AT_GENERAL,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek &id_opts->gen_map);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek goto fail;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* User map */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sdap_copy_map(id_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_2008r2_user_map,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek SDAP_OPTS_USER,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek &id_opts->user_map);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek goto fail;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
35d420c5d4609b6e999920e38a9b2ec40a0e1ac4Jakub Hrozek id_opts->user_map_cnt = SDAP_OPTS_USER;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* Group map */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sdap_copy_map(id_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_2008r2_group_map,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek SDAP_OPTS_GROUP,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek &id_opts->group_map);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek goto fail;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* Netgroup map */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sdap_copy_map(id_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_netgroup_map,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek SDAP_OPTS_NETGROUP,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek &id_opts->netgroup_map);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek goto fail;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* Services map */
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sdap_copy_map(id_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_service_map,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek SDAP_OPTS_SERVICES,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek &id_opts->service_map);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek goto fail;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return id_opts;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekfail:
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(id_opts);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek}
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židekstatic errno_t
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židekad_create_sdap_options(TALLOC_CTX *mem_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct confdb_ctx *cdb,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek const char *conf_path,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek struct data_provider *dp,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct sdap_options **_id_opts)
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek{
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct sdap_options *id_opts;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek errno_t ret = EOK;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (cdb == NULL || conf_path == NULL) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Fallback to defaults if there is no confdb */
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek id_opts = ad_create_default_sdap_options(mem_ctx, dp);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (id_opts == NULL) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek "Failed to initialize default sdap options\n");
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = EIO;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Nothing to do without cdb */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek id_opts = talloc_zero(mem_ctx, struct sdap_options);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (!id_opts) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = ENOMEM;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = dp_get_options(id_opts, cdb, conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_def_ldap_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_OPTS_BASIC,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->basic);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Get sdap option maps */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* General Attribute Map */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = sdap_get_map(id_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb, conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_2008r2_attr_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_AT_GENERAL,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->gen_map);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* User map */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = sdap_get_map(id_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb, conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_2008r2_user_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_OPTS_USER,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->user_map);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = sdap_extend_map_with_list(id_opts, id_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_USER_EXTRA_ATTRS,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek id_opts->user_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_OPTS_USER,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->user_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->user_map_cnt);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Group map */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = sdap_get_map(id_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb, conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_2008r2_group_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_OPTS_GROUP,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->group_map);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Netgroup map */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = sdap_get_map(id_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb, conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_netgroup_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_OPTS_NETGROUP,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->netgroup_map);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Services map */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = sdap_get_map(id_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb, conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_service_map,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek SDAP_OPTS_SERVICES,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &id_opts->service_map);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek goto done;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = EOK;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židekdone:
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret == EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek *_id_opts = id_opts;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek } else {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek talloc_free(id_opts);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek return ret;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek}
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekstruct ad_options *
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židekad_create_options(TALLOC_CTX *mem_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct confdb_ctx *cdb,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek const char *conf_path,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek struct data_provider *dp,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct sss_domain_info *subdom)
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek{
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct ad_options *ad_options;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek errno_t ret;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_options = talloc_zero(mem_ctx, struct ad_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ad_options == NULL) return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (cdb != NULL && conf_path != NULL) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = dp_get_options(ad_options,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek conf_path,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_basic_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek AD_OPTS_BASIC,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &ad_options->basic);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek } else {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek /* Fallback to reading the defaults only if no confdb
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek * is available */
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = dp_copy_defaults(ad_options,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ad_basic_opts,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek AD_OPTS_BASIC,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &ad_options->basic);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get basic AD options\n");
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = ad_create_sdap_options(ad_options,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek cdb,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek conf_path,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek dp,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek &ad_options->id);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot initialize AD LDAP options\n");
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek return ad_options;
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek}
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozekstatic errno_t
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozekset_common_ad_trust_opts(struct ad_options *ad_options,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *realm,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *ad_domain,
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose const char *hostname,
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose const char *keytab)
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek{
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek errno_t ret;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ret = dp_opt_set_string(ad_options->basic, AD_KRB5_REALM, realm);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek if (ret != EOK) {
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot set AD krb5 realm\n");
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return ret;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek }
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ret = dp_opt_set_string(ad_options->basic, AD_DOMAIN, ad_domain);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek if (ret != EOK) {
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot set AD domain\n");
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return ret;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek }
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ret = dp_opt_set_string(ad_options->basic, AD_HOSTNAME, hostname);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek if (ret != EOK) {
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot set AD hostname\n");
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return ret;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek }
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose if (keytab != NULL) {
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose ret = dp_opt_set_string(ad_options->basic, AD_KEYTAB, keytab);
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose if (ret != EOK) {
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Cannot set keytab\n");
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose return ret;
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose }
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose }
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return EOK;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek}
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
933314e53fac878d1a9b126af216454172cb945aJakub Hrozekstruct ad_options *
933314e53fac878d1a9b126af216454172cb945aJakub Hrozekad_create_2way_trust_options(TALLOC_CTX *mem_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct confdb_ctx *cdb,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek const char *conf_path,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek struct data_provider *dp,
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek const char *realm,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct sss_domain_info *subdom,
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose const char *hostname,
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose const char *keytab)
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek{
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek struct ad_options *ad_options;
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek errno_t ret;
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek
b4ca0da4d8d70bcfbd4f809f3b3b094d43d64cfcMichal Židek DEBUG(SSSDBG_TRACE_FUNC, "2way trust is defined to domain '%s'\n",
b4ca0da4d8d70bcfbd4f809f3b3b094d43d64cfcMichal Židek subdom->name);
b4ca0da4d8d70bcfbd4f809f3b3b094d43d64cfcMichal Židek
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek ad_options = ad_create_options(mem_ctx, cdb, conf_path, dp, subdom);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ad_options == NULL) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "ad_create_options failed\n");
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek return NULL;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
933314e53fac878d1a9b126af216454172cb945aJakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret = set_common_ad_trust_opts(ad_options, realm, subdom->name, hostname,
cc4caf88344210ea9777d618f0f71935ca5e7f8bSumit Bose keytab);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "set_common_ad_trust_opts failed\n");
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ret = ad_set_sdap_options(ad_options, ad_options->id);
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "ad_set_sdap_options failed");
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek talloc_free(ad_options);
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek return NULL;
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek }
de2bad8ae08f09964834bda0f88db9de39f47c5cJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return ad_options;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek}
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozekstruct ad_options *
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozekad_create_1way_trust_options(TALLOC_CTX *mem_ctx,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct confdb_ctx *cdb,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek const char *subdom_conf_path,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek struct data_provider *dp,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek struct sss_domain_info *subdom,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *hostname,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *keytab,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *sasl_authid)
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek{
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek struct ad_options *ad_options;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek const char *realm;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek errno_t ret;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
b4ca0da4d8d70bcfbd4f809f3b3b094d43d64cfcMichal Židek DEBUG(SSSDBG_TRACE_FUNC, "1way trust is defined to domain '%s'\n",
b4ca0da4d8d70bcfbd4f809f3b3b094d43d64cfcMichal Židek subdom->name);
b4ca0da4d8d70bcfbd4f809f3b3b094d43d64cfcMichal Židek
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek ad_options = ad_create_options(mem_ctx, cdb, subdom_conf_path, dp, subdom);
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek if (ad_options == NULL) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "ad_create_options failed\n");
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek return NULL;
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek }
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek realm = get_uppercase_realm(ad_options, subdom->name);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek if (!realm) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to get uppercase realm\n");
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek talloc_free(ad_options);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return NULL;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek }
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ret = set_common_ad_trust_opts(ad_options, realm,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek subdom->name, hostname, keytab);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE,
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek "set_common_ad_trust_opts failed [%d]: %s\n",
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret, sss_strerror(ret));
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek talloc_free(ad_options);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek return NULL;
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek }
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek /* Set SDAP_SASL_AUTHID to the trust principal */
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek ret = dp_opt_set_string(ad_options->id->basic,
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek SDAP_SASL_AUTHID, sasl_authid);
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek if (ret != EOK) {
30dd3f3e063dded0ec9f58bc2535a94727d8e96dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot set SASL authid\n");
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
44ba573582072823d8760d0f18e5b3195cecc182Jakub Hrozek ret = ad_set_sdap_options(ad_options, ad_options->id);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ret != EOK) {
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "ad_set_sdap_options failed [%d]: %s\n",
231bd1b34023daa3080cf461085e6e4aa7f4d733Michal Židek ret, sss_strerror(ret));
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_options);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ad_options;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek}
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallaghererrno_t
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherad_get_common_options(TALLOC_CTX *mem_ctx,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct confdb_ctx *cdb,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher const char *conf_path,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct sss_domain_info *dom,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct ad_options **_opts)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher{
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher errno_t ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher int gret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct ad_options *opts = NULL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *domain;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *server;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *realm;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *ad_hostname;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char hostname[HOST_NAME_MAX + 1];
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek char *case_sensitive_opt;
5b4c6f22cb576a11037c7fa940fe0ba09e643e77Michal Zidek const char *opt_override;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher opts = talloc_zero(mem_ctx, struct ad_options);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!opts) return ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_get_options(opts, cdb, conf_path,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ad_basic_opts,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher AD_OPTS_BASIC,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher &opts->basic);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* If the AD domain name wasn't explicitly set, assume that it
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher * matches the SSSD domain name
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher domain = dp_opt_get_string(opts->basic, AD_DOMAIN);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!domain) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_opt_set_string(opts->basic, AD_DOMAIN, dom->name);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher domain = dom->name;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Did we get an explicit server name, or are we discovering it? */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher server = dp_opt_get_string(opts->basic, AD_SERVER);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!server) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "No AD server set, will use service discovery!\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Set the machine's hostname to the local host name if it
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher * wasn't explicitly specified.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ad_hostname = dp_opt_get_string(opts->basic, AD_HOSTNAME);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ad_hostname == NULL) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher gret = gethostname(hostname, HOST_NAME_MAX);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (gret != 0) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = errno;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "gethostname failed [%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov strerror(ret));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher hostname[HOST_NAME_MAX] = '\0';
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Setting ad_hostname to [%s].\n", hostname);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_opt_set_string(opts->basic, AD_HOSTNAME, hostname);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Setting ad_hostname failed [%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov strerror(ret));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Always use the upper-case AD domain for the kerberos realm */
e4c29d1f8e3b2c2b268105f169e5156a0a36aebfOndrej Kos realm = get_uppercase_realm(opts, domain);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!realm) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_opt_set_string(opts->basic, AD_KRB5_REALM, realm);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher /* Active Directory is always case-insensitive */
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek ret = confdb_get_string(cdb, mem_ctx, conf_path,
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek CONFDB_DOMAIN_CASE_SENSITIVE, "false",
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek &case_sensitive_opt);
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek if (ret != EOK) {
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE, "condb_get_string failed.\n");
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek goto done;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek }
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek if (strcasecmp(case_sensitive_opt, "true") == 0) {
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE,
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek "Warning: AD domain can not be set as case-sensitive.\n");
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek dom->case_sensitive = false;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek dom->case_preserve = false;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek } else if (strcasecmp(case_sensitive_opt, "false") == 0) {
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek dom->case_sensitive = false;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek dom->case_preserve = false;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek } else if (strcasecmp(case_sensitive_opt, "preserving") == 0) {
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek dom->case_sensitive = false;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek dom->case_preserve = true;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek } else {
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek DEBUG(SSSDBG_FATAL_FAILURE,
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek "Invalid value for %s\n", CONFDB_DOMAIN_CASE_SENSITIVE);
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek goto done;
ff22e829fd73fc53027d1e6ca005a9ac334086ddMichal Zidek }
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher
5b4c6f22cb576a11037c7fa940fe0ba09e643e77Michal Zidek opt_override = dom->case_preserve ? "preserving" : "false";
5b4c6f22cb576a11037c7fa940fe0ba09e643e77Michal Zidek
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher /* Set this in the confdb so that the responders pick it
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher * up when they start up.
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher */
5b4c6f22cb576a11037c7fa940fe0ba09e643e77Michal Zidek ret = confdb_set_string(cdb, conf_path, "case_sensitive", opt_override);
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher if (ret != EOK) {
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
5b4c6f22cb576a11037c7fa940fe0ba09e643e77Michal Zidek "Could not set domain option case_sensitive: [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov strerror(ret));
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher goto done;
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher }
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
5b4c6f22cb576a11037c7fa940fe0ba09e643e77Michal Zidek "Setting domain option case_sensitive to [%s]\n", opt_override);
346f41f1ede975cb2db0af570f5b454b9b306704Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EOK;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher *_opts = opts;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherdone:
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher talloc_zfree(opts);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher return ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher}
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherstatic void
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherad_resolve_callback(void *private_data, struct fo_server *server);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zelenystatic errno_t
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnik_ad_servers_init(struct ad_service *service,
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek struct be_ctx *bectx,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *fo_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *fo_gc_service,
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek const char *servers,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *ad_domain,
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek bool primary)
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny{
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny size_t i;
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson size_t j;
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek errno_t ret = 0;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny char **list;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek struct ad_server_data *sdata;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny TALLOC_CTX *tmp_ctx;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny tmp_ctx = talloc_new(NULL);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (!tmp_ctx) return ENOMEM;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny /* Split the server list */
04759b59e71c78ab23b84d13dd29d9c6dd680adbMichal Zidek ret = split_on_separator(tmp_ctx, servers, ',', true, true, &list, NULL);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to parse server list!\n");
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny goto done;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny }
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson for (j = 0; list[j]; j++) {
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson if (resolv_is_address(list[j])) {
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson DEBUG(SSSDBG_IMPORTANT_INFO,
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson "ad_server [%s] is detected as IP address, "
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson "this can cause GSSAPI problems\n", list[j]);
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson }
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson }
e915f42093add45a11208e871c9abdf7ab2bfbdcJustin Stephenson
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny /* Add each of these servers to the failover service */
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny for (i = 0; list[i]; i++) {
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (be_fo_is_srv_identifier(list[i])) {
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek if (!primary) {
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to add server [%s] to failover service: "
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek "SRV resolution only allowed for primary servers!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov list[i]);
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek continue;
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek }
4a1e58d85409fbb7a12ac244c3dbef8c0c1b15dfMichal Zidek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata = talloc(service, struct ad_server_data);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sdata == NULL) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = ENOMEM;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata->gc = true;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_add_srv_server(bectx, fo_gc_service, "gc",
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ad_domain, BE_FO_PROTO_TCP,
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek false, sdata);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (ret != EOK) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Failed to add service discovery to failover: [%s]\n",
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik strerror(ret));
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata = talloc(service, struct ad_server_data);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sdata == NULL) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = ENOMEM;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata->gc = false;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_add_srv_server(bectx, fo_service, "ldap",
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny ad_domain, BE_FO_PROTO_TCP,
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek false, sdata);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (ret != EOK) {
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny DEBUG(SSSDBG_FATAL_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Failed to add service discovery to failover: [%s]\n",
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik strerror(ret));
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny goto done;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny }
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS, "Added service discovery for AD\n");
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny continue;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny }
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek /* It could be ipv6 address in square brackets. Remove
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek * the brackets if needed. */
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek ret = remove_ipv6_brackets(list[i]);
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek if (ret != EOK) {
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek goto done;
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek }
b096321a5a02dda0b6b71ba0f9c4d8feacd979e4Michal Zidek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata = talloc(service, struct ad_server_data);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sdata == NULL) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = ENOMEM;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata->gc = true;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
9a9a813906472ffff3911b6006d023e1c6cbff8aSumit Bose ret = be_fo_add_server(bectx, fo_gc_service, list[i], 0, sdata, primary);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (ret && ret != EEXIST) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add server\n");
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata = talloc(service, struct ad_server_data);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sdata == NULL) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = ENOMEM;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata->gc = false;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_add_server(bectx, fo_service, list[i], 0, sdata, primary);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (ret && ret != EEXIST) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add server\n");
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny goto done;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny }
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS, "Added failover server %s\n", list[i]);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny }
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zelenydone:
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny talloc_free(tmp_ctx);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny return ret;
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny}
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozekstatic inline errno_t
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnikad_primary_servers_init(struct ad_service *service,
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek struct be_ctx *bectx, const char *servers,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *fo_service, const char *fo_gc_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *ad_domain)
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek{
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnik return _ad_servers_init(service, bectx, fo_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek fo_gc_service, servers, ad_domain, true);
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek}
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozekstatic inline errno_t
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnikad_backup_servers_init(struct ad_service *service,
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek struct be_ctx *bectx, const char *servers,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *fo_service, const char *fo_gc_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *ad_domain)
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek{
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnik return _ad_servers_init(service, bectx, fo_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek fo_gc_service, servers, ad_domain, false);
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek}
7119f0c483049a8850d3075c0b1062f35200a538Jakub Hrozek
9ab243b369ba317cc964080786dbcdebaf23d6beMichal Zidekstatic int ad_user_data_cmp(void *ud1, void *ud2)
9ab243b369ba317cc964080786dbcdebaf23d6beMichal Zidek{
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek struct ad_server_data *sd1, *sd2;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sd1 = talloc_get_type(ud1, struct ad_server_data);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sd2 = talloc_get_type(ud2, struct ad_server_data);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sd1 == NULL || sd2 == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No user data\n");
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek return sd1 == sd2 ? 0 : 1;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sd1->gc == sd2->gc) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek return 0;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek return 1;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek}
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozekstatic void ad_online_cb(void *pvt)
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek{
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek struct ad_service *service = talloc_get_type(pvt, struct ad_service);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (service == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Invalid private pointer\n");
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek return;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "The AD provider is online\n");
9ab243b369ba317cc964080786dbcdebaf23d6beMichal Zidek}
9ab243b369ba317cc964080786dbcdebaf23d6beMichal Zidek
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallaghererrno_t
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherad_failover_init(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny const char *primary_servers,
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny const char *backup_servers,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *krb5_realm,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *ad_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *ad_gc_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek const char *ad_domain,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct ad_service **_service)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher{
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher errno_t ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher TALLOC_CTX *tmp_ctx;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct ad_service *service;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher tmp_ctx = talloc_new(mem_ctx);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!tmp_ctx) return ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service = talloc_zero(tmp_ctx, struct ad_service);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!service) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service->sdap = talloc_zero(service, struct sdap_service);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->gc = talloc_zero(service, struct sdap_service);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (!service->sdap || !service->gc) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = ENOMEM;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek service->sdap->name = talloc_strdup(service->sdap, ad_service);
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek service->gc->name = talloc_strdup(service->gc, ad_gc_service);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (!service->sdap->name || !service->gc->name) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service->krb5_service = talloc_zero(service, struct krb5_service);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!service->krb5_service) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_add_service(bectx, ad_service, ad_user_data_cmp);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create failover service!\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_add_service(bectx, ad_gc_service, ad_user_data_cmp);
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create GC failover service!\n");
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek goto done;
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek }
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->krb5_service->name = talloc_strdup(service->krb5_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ad_service);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!service->krb5_service->name) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service->sdap->kinit_service_name = service->krb5_service->name;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->gc->kinit_service_name = service->krb5_service->name;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek if (!krb5_realm) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No Kerberos realm set\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EINVAL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service->krb5_service->realm =
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek talloc_strdup(service->krb5_service, krb5_realm);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!service->krb5_service->realm) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (!primary_servers) {
b1caacb098ae99ad65144120fdec4d0fd98ad9d5Pavel Březina DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "No primary servers defined, using service discovery\n");
b1caacb098ae99ad65144120fdec4d0fd98ad9d5Pavel Březina primary_servers = BE_SRV_IDENTIFIER;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnik ret = ad_primary_servers_init(service, bectx,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek primary_servers, ad_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ad_gc_service, ad_domain);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (backup_servers) {
113debb7297f0c02b5be0dd404badeef78841a83Lukas Slebodnik ret = ad_backup_servers_init(service, bectx,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek backup_servers, ad_service,
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ad_gc_service, ad_domain);
016e0d7202ff965018e41869c5ab501f86b0d081Jan Zeleny if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = be_add_online_cb(bectx, bectx, ad_online_cb, service, NULL);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not set up AD online callback\n");
12440d2acbeb7ea6e5c0e4182d00377c8d01185bPavel Reichl goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_service_add_callback(mem_ctx, bectx, ad_service,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ad_resolve_callback, service);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to add failover callback! [%s]\n", strerror(ret));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
59415636c92c6e9764ddc65a85ad61002310519dJakub Hrozek ret = be_fo_service_add_callback(mem_ctx, bectx, ad_gc_service,
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek ad_resolve_callback, service);
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek if (ret != EOK) {
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to add failover callback! [%s]\n", strerror(ret));
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek goto done;
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek }
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher *_service = talloc_steal(mem_ctx, service);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EOK;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherdone:
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher talloc_free(tmp_ctx);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher return ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher}
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherstatic void
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherad_resolve_callback(void *private_data, struct fo_server *server)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher{
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher errno_t ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher TALLOC_CTX *tmp_ctx;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct ad_service *service;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct resolv_hostent *srvaddr;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct sockaddr_storage *sockaddr;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *address;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher const char *safe_address;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *new_uri;
3a3fd60043234038c6ff6584a5b92fb757c4afe1Lukas Slebodnik int new_port;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher const char *srv_name;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek struct ad_server_data *sdata = NULL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher tmp_ctx = talloc_new(NULL);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!tmp_ctx) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher return;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sdata = fo_get_server_user_data(server);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (fo_is_srv_lookup(server) == false && sdata == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "No user data?\n");
12440d2acbeb7ea6e5c0e4182d00377c8d01185bPavel Reichl ret = EINVAL;
12440d2acbeb7ea6e5c0e4182d00377c8d01185bPavel Reichl goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service = talloc_get_type(private_data, struct ad_service);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!service) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EINVAL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher srvaddr = fo_get_server_hostent(server);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!srvaddr) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "No hostent available for server (%s)\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov fo_get_server_str_name(server));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EINVAL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher address = resolv_get_string_address(tmp_ctx, srvaddr);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (address == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "resolv_get_string_address failed.\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EIO;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher srv_name = fo_get_server_name(server);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (srv_name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not get server host name\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EINVAL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek new_uri = talloc_asprintf(service->sdap, "ldap://%s", srv_name);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!new_uri) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to copy URI\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS, "Constructed uri '%s'\n", new_uri);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sockaddr = resolv_get_sockaddr_address(tmp_ctx, srvaddr, LDAP_PORT);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sockaddr == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "resolv_get_sockaddr_address failed.\n");
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = EIO;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* free old one and replace with new one */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher talloc_zfree(service->sdap->uri);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher service->sdap->uri = new_uri;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher talloc_zfree(service->sdap->sockaddr);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->sdap->sockaddr = talloc_steal(service->sdap, sockaddr);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek talloc_zfree(service->gc->uri);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek talloc_zfree(service->gc->sockaddr);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (sdata && sdata->gc) {
3a3fd60043234038c6ff6584a5b92fb757c4afe1Lukas Slebodnik new_port = fo_get_server_port(server);
3a3fd60043234038c6ff6584a5b92fb757c4afe1Lukas Slebodnik new_port = (new_port == 0) ? AD_GC_PORT : new_port;
3a3fd60043234038c6ff6584a5b92fb757c4afe1Lukas Slebodnik
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->gc->uri = talloc_asprintf(service->gc, "%s:%d",
3a3fd60043234038c6ff6584a5b92fb757c4afe1Lukas Slebodnik new_uri, new_port);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->gc->sockaddr = resolv_get_sockaddr_address(service->gc,
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek srvaddr,
3a3fd60043234038c6ff6584a5b92fb757c4afe1Lukas Slebodnik new_port);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek } else {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek /* Make sure there always is an URI even if we know that this
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek * server doesn't support GC. That way the lookup would go through
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek * just not return anything
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek */
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->gc->uri = talloc_strdup(service->gc, service->sdap->uri);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek service->gc->sockaddr = talloc_memdup(service->gc, service->sdap->sockaddr,
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek sizeof(struct sockaddr_storage));
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (!service->gc->uri) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to append to URI\n");
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = ENOMEM;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS, "Constructed GC uri '%s'\n", service->gc->uri);
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek if (service->gc->sockaddr == NULL) {
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "resolv_get_sockaddr_address failed.\n");
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek ret = EIO;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek goto done;
55d80b1301fe969fb4ba2b9481027887b9462dbbJakub Hrozek }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek /* Only write kdcinfo files for local servers */
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek if ((sdata == NULL || sdata->gc == false) &&
ba95f1c434b430f0db7fddbd865af10488ecab17Jakub Hrozek service->krb5_service->write_kdcinfo) {
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek /* Write krb5 info files */
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek safe_address = sss_escape_ip_address(tmp_ctx,
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek srvaddr->family,
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek address);
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek if (safe_address == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sss_escape_ip_address failed.\n");
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek ret = ENOMEM;
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek goto done;
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek ret = write_krb5info_file(service->krb5_service->realm, safe_address,
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek SSS_KRB5KDC_FO_SRV);
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek if (ret != EOK) {
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "write_krb5info_file failed, authentication might fail.\n");
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EOK;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherdone:
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Error: [%s]\n", strerror(ret));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher talloc_free(tmp_ctx);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher return;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher}
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekstatic errno_t
44ba573582072823d8760d0f18e5b3195cecc182Jakub Hrozekad_set_sdap_options(struct ad_options *ad_opts,
44ba573582072823d8760d0f18e5b3195cecc182Jakub Hrozek struct sdap_options *id_opts)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher{
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher errno_t ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *krb5_realm;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher char *keytab_path;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* We only support Kerberos password policy with AD, so
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher * force that on.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_opt_set_string(id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_PWD_POLICY,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher PWD_POL_OPT_MIT);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Could not set password policy\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Set the Kerberos Realm for GSSAPI */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher krb5_realm = dp_opt_get_string(ad_opts->basic, AD_KRB5_REALM);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (!krb5_realm) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Should be impossible, this is set in ad_get_common_options() */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "No Kerberos realm\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EINVAL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_opt_set_string(id_opts->basic, SDAP_KRB5_REALM, krb5_realm);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Option %s set to %s\n",
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher id_opts->basic[SDAP_KRB5_REALM].opt_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov krb5_realm);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher keytab_path = dp_opt_get_string(ad_opts->basic, AD_KEYTAB);
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher if (keytab_path) {
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher ret = dp_opt_set_string(id_opts->basic, SDAP_KRB5_KEYTAB,
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher keytab_path);
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher if (ret != EOK) goto done;
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Option %s set to %s\n",
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher id_opts->basic[SDAP_KRB5_KEYTAB].opt_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov keytab_path);
4e2d9fe30bf8b692972a9654c60d2d90ed355815Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek ret = sdap_set_sasl_options(id_opts,
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek dp_opt_get_string(ad_opts->basic,
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek AD_HOSTNAME),
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek dp_opt_get_string(ad_opts->basic,
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek AD_KRB5_REALM),
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek keytab_path);
e0d861963e10c5aba79ad87f8c48b0ce1bec06caJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot set the SASL-related options\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* fix schema to AD */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher id_opts->schema_type = SDAP_SCHEMA_AD;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_opts->id = id_opts;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = EOK;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekdone:
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ret;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek}
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekerrno_t
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekad_get_id_options(struct ad_options *ad_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct confdb_ctx *cdb,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek const char *conf_path,
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek struct data_provider *dp,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct sdap_options **_opts)
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek{
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct sdap_options *id_opts;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek errno_t ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
d2633d922eeed68f92be4248b9172b928c189920Jakub Hrozek ret = ad_create_sdap_options(ad_opts, cdb, conf_path, dp, &id_opts);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ENOMEM;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
44ba573582072823d8760d0f18e5b3195cecc182Jakub Hrozek ret = ad_set_sdap_options(ad_opts, id_opts);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(id_opts);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ret = sdap_domain_add(id_opts,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_opts->id_ctx->sdap_id_ctx->be->domain,
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek NULL);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(id_opts);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek /* Set up search bases if they were assigned explicitly */
4c49edbd8df651b1737c59459637962c117212c6Michal Židek ret = ad_set_search_bases(id_opts, NULL);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(id_opts);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher *_opts = id_opts;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return EOK;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher}
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozekerrno_t
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozekad_get_autofs_options(struct ad_options *ad_opts,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek struct confdb_ctx *cdb,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek const char *conf_path)
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek{
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek errno_t ret;
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek /* autofs maps */
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek ret = sdap_get_map(ad_opts->id,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek cdb,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek conf_path,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek ad_autofs_mobject_map,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek SDAP_OPTS_AUTOFS_MAP,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek &ad_opts->id->autofs_mobject_map);
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek if (ret != EOK) {
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek return ret;
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek }
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek ret = sdap_get_map(ad_opts->id,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek cdb,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek conf_path,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek ad_autofs_entry_map,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek SDAP_OPTS_AUTOFS_ENTRY,
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek &ad_opts->id->autofs_entry_map);
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek if (ret != EOK) {
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek return ret;
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek }
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek return EOK;
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek}
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallaghererrno_t
4c49edbd8df651b1737c59459637962c117212c6Michal Židekad_set_search_bases(struct sdap_options *id_opts,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek struct sdap_domain *sdom)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher{
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher errno_t ret;
4c49edbd8df651b1737c59459637962c117212c6Michal Židek char *default_search_base = NULL;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher size_t o;
4c49edbd8df651b1737c59459637962c117212c6Michal Židek struct sdap_domain *sdap_dom;
4c49edbd8df651b1737c59459637962c117212c6Michal Židek bool has_default;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher const int search_base_options[] = { SDAP_USER_SEARCH_BASE,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_GROUP_SEARCH_BASE,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_NETGROUP_SEARCH_BASE,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_SERVICE_SEARCH_BASE,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher -1 };
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* AD servers provide defaultNamingContext, so we will
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher * rely on that to specify the search base unless it has
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher * been specifically overridden.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
4c49edbd8df651b1737c59459637962c117212c6Michal Židek if (sdom != NULL) {
4c49edbd8df651b1737c59459637962c117212c6Michal Židek sdap_dom = sdom;
4c49edbd8df651b1737c59459637962c117212c6Michal Židek } else {
4c49edbd8df651b1737c59459637962c117212c6Michal Židek /* If no specific sdom was given, use the first in the list. */
4c49edbd8df651b1737c59459637962c117212c6Michal Židek sdap_dom = id_opts->sdom;
4c49edbd8df651b1737c59459637962c117212c6Michal Židek }
4c49edbd8df651b1737c59459637962c117212c6Michal Židek
4c49edbd8df651b1737c59459637962c117212c6Michal Židek has_default = sdap_dom->search_bases != NULL;
4c49edbd8df651b1737c59459637962c117212c6Michal Židek
4c49edbd8df651b1737c59459637962c117212c6Michal Židek if (has_default == false) {
4c49edbd8df651b1737c59459637962c117212c6Michal Židek default_search_base =
4c49edbd8df651b1737c59459637962c117212c6Michal Židek dp_opt_get_string(id_opts->basic, SDAP_SEARCH_BASE);
4c49edbd8df651b1737c59459637962c117212c6Michal Židek }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
4c49edbd8df651b1737c59459637962c117212c6Michal Židek if (default_search_base && has_default == false) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* set search bases if they are not */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher for (o = 0; search_base_options[o] != -1; o++) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (NULL == dp_opt_get_string(id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher search_base_options[o])) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = dp_opt_set_string(id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher search_base_options[o],
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher default_search_base);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK) {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Option %s set to %s\n",
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher id_opts->basic[search_base_options[o]].opt_name,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher dp_opt_get_string(id_opts->basic,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov search_base_options[o]));
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher } else {
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Search base not set. SSSD will attempt to discover it later, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "when connecting to the LDAP server.\n");
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher }
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Default search */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = sdap_parse_search_base(id_opts, id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_SEARCH_BASE,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek &sdap_dom->search_bases);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK && ret != ENOENT) goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* User search */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = sdap_parse_search_base(id_opts, id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_USER_SEARCH_BASE,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek &sdap_dom->user_search_bases);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK && ret != ENOENT) goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Group search base */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = sdap_parse_search_base(id_opts, id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_GROUP_SEARCH_BASE,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek &sdap_dom->group_search_bases);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK && ret != ENOENT) goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Netgroup search */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = sdap_parse_search_base(id_opts, id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_NETGROUP_SEARCH_BASE,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek &sdap_dom->netgroup_search_bases);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK && ret != ENOENT) goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher /* Service search */
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = sdap_parse_search_base(id_opts, id_opts->basic,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SDAP_SERVICE_SEARCH_BASE,
4c49edbd8df651b1737c59459637962c117212c6Michal Židek &sdap_dom->service_search_bases);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher if (ret != EOK && ret != ENOENT) goto done;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher ret = EOK;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagherdone:
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher return ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher}
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallaghererrno_t
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagherad_get_auth_options(TALLOC_CTX *mem_ctx,
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher struct ad_options *ad_opts,
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher struct be_ctx *bectx,
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher struct dp_option **_opts)
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher{
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher errno_t ret;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher struct dp_option *krb5_options;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher const char *ad_servers;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher const char *krb5_realm;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher TALLOC_CTX *tmp_ctx = talloc_new(NULL);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher if (!tmp_ctx) return ENOMEM;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher /* Get krb5 options */
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ret = dp_get_options(tmp_ctx, bectx->cdb, bectx->conf_path,
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ad_def_krb5_opts, KRB5_OPTS,
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher &krb5_options);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher if (ret != EOK) {
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not read Kerberos options from the configuration\n");
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher goto done;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher }
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ad_servers = dp_opt_get_string(ad_opts->basic, AD_SERVER);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher /* Force the krb5_servers to match the ad_servers */
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ret = dp_opt_set_string(krb5_options, KRB5_KDC, ad_servers);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher if (ret != EOK) goto done;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Option %s set to %s\n",
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher krb5_options[KRB5_KDC].opt_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ad_servers);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher /* Set krb5 realm */
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher /* Set the Kerberos Realm for GSSAPI */
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher krb5_realm = dp_opt_get_string(ad_opts->basic, AD_KRB5_REALM);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher if (!krb5_realm) {
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher /* Should be impossible, this is set in ad_get_common_options() */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "No Kerberos realm\n");
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ret = EINVAL;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher goto done;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher }
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher /* Force the kerberos realm to match the AD_KRB5_REALM (which may have
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher * been upper-cased in ad_common_options()
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher */
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ret = dp_opt_set_string(krb5_options, KRB5_REALM, krb5_realm);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher if (ret != EOK) goto done;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher DEBUG(SSSDBG_CONF_SETTINGS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Option %s set to %s\n",
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher krb5_options[KRB5_REALM].opt_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov krb5_realm);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek /* Set flag that controls whether we want to write the
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek * kdcinfo files at all
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek */
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek ad_opts->service->krb5_service->write_kdcinfo = \
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek dp_opt_get_bool(krb5_options, KRB5_USE_KDCINFO);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS, "Option %s set to %s\n",
bb4172259e04925ffc3a92e4450029634d295134Jakub Hrozek krb5_options[KRB5_USE_KDCINFO].opt_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ad_opts->service->krb5_service->write_kdcinfo ? "true" : "false");
14452cd066b51e32ca0ebad6c45ae909a1debe57Jakub Hrozek
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher *_opts = talloc_steal(mem_ctx, krb5_options);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher ret = EOK;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagherdone:
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher talloc_free(tmp_ctx);
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher return ret;
d92c50f6d75ae980b0d130134112a33e1584724cStephen Gallagher}
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozekerrno_t ad_get_dyndns_options(struct be_ctx *be_ctx,
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek struct ad_options *ad_opts)
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek{
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek errno_t ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek ret = be_nsupdate_init(ad_opts, be_ctx, ad_dyndns_opts,
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek &ad_opts->dyndns_ctx);
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek if (ret != EOK) {
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot initialize AD dyndns opts [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, sss_strerror(ret));
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return ret;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek }
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek return EOK;
74e95cfd9d3939dfe9417d79d2f6fc79b361405fJakub Hrozek}
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekstruct ad_id_ctx *
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozekad_id_ctx_init(struct ad_options *ad_opts, struct be_ctx *bectx)
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek{
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct sdap_id_ctx *sdap_ctx;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek struct ad_id_ctx *ad_ctx;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_ctx = talloc_zero(ad_opts, struct ad_id_ctx);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ad_ctx == NULL) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_ctx->ad_options = ad_opts;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek sdap_ctx = sdap_id_ctx_new(ad_ctx, bectx, ad_opts->service->sdap);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (sdap_ctx == NULL) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_ctx);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_ctx->sdap_id_ctx = sdap_ctx;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_ctx->ldap_ctx = sdap_ctx->conn;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek ad_ctx->gc_ctx = sdap_id_ctx_conn_add(sdap_ctx, ad_opts->service->gc);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek if (ad_ctx->gc_ctx == NULL) {
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek talloc_free(ad_ctx);
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return NULL;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek }
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek return ad_ctx;
ebc6ab564dc2a0a2b08c42d727fc403dde4a2dc9Jakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekstruct sdap_id_conn_ctx *
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekad_get_dom_ldap_conn(struct ad_id_ctx *ad_ctx, struct sss_domain_info *dom)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sdap_id_conn_ctx *conn;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sdap_domain *sdom;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct ad_id_ctx *subdom_id_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher sdom = sdap_domain_get(ad_ctx->sdap_id_ctx->opts, dom);
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher if (sdom == NULL || sdom->pvt == NULL) {
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE, "No ID ctx available for [%s].\n",
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher dom->name);
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher return NULL;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek }
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher subdom_id_ctx = talloc_get_type(sdom->pvt, struct ad_id_ctx);
e2bd4f8a41b72aea0712ad21ad02ccebb707f536Stephen Gallagher conn = subdom_id_ctx->ldap_ctx;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek if (IS_SUBDOMAIN(sdom->dom) == true && conn != NULL) {
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek /* Regardless of connection types, a subdomain error must not be
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek * allowed to set the whole back end offline, rather report an error
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek * and let the caller deal with it (normally disable the subdomain
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek */
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek conn->ignore_mark_offline = true;
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek }
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek return conn;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekstruct sdap_id_conn_ctx **
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozekad_gc_conn_list(TALLOC_CTX *mem_ctx, struct ad_id_ctx *ad_ctx,
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sss_domain_info *dom)
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek{
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek struct sdap_id_conn_ctx **clist;
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek int cindex = 0;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek clist = talloc_zero_array(mem_ctx, struct sdap_id_conn_ctx *, 3);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek if (clist == NULL) return NULL;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek /* Always try GC first */
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek if (dp_opt_get_bool(ad_ctx->ad_options->basic, AD_ENABLE_GC)) {
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek clist[cindex] = ad_ctx->gc_ctx;
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek clist[cindex]->ignore_mark_offline = true;
ba4a81e933deebb416603369b447ead6ebaa040dJakub Hrozek cindex++;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek }
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
266110fa0f6eb086f8f88787bb167cea416fe108Jakub Hrozek clist[cindex] = ad_get_dom_ldap_conn(ad_ctx, dom);
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek return clist;
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek}
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozekstruct sdap_id_conn_ctx **
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozekad_ldap_conn_list(TALLOC_CTX *mem_ctx,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek struct ad_id_ctx *ad_ctx,
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek struct sss_domain_info *dom)
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek{
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek struct sdap_id_conn_ctx **clist;
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek clist = talloc_zero_array(mem_ctx, struct sdap_id_conn_ctx *, 2);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek if (clist == NULL) {
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek return NULL;
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek }
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek clist[0] = ad_get_dom_ldap_conn(ad_ctx, dom);
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek clist[1] = NULL;
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek return clist;
309aa83d16b5919f727af04850bcd0799ba0962fJakub Hrozek}
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozekstruct sdap_id_conn_ctx **
e6ad16e05f42a1678a8c6cd14eb54ca75b8d775eSumit Bosead_user_conn_list(TALLOC_CTX *mem_ctx,
e6ad16e05f42a1678a8c6cd14eb54ca75b8d775eSumit Bose struct ad_id_ctx *ad_ctx,
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek struct sss_domain_info *dom)
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek{
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek struct sdap_id_conn_ctx **clist;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek int cindex = 0;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
e6ad16e05f42a1678a8c6cd14eb54ca75b8d775eSumit Bose clist = talloc_zero_array(mem_ctx, struct sdap_id_conn_ctx *, 3);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek if (clist == NULL) {
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek return NULL;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek }
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek /* Try GC first for users from trusted domains, but go to LDAP
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek * for users from non-trusted domains to get all POSIX attrs
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek */
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek if (dp_opt_get_bool(ad_ctx->ad_options->basic, AD_ENABLE_GC)
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek && IS_SUBDOMAIN(dom)) {
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek clist[cindex] = ad_ctx->gc_ctx;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek clist[cindex]->ignore_mark_offline = true;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek cindex++;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek }
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek /* Users from primary domain can be just downloaded from LDAP.
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek * The domain's LDAP connection also works as a fallback
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek */
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek clist[cindex] = ad_get_dom_ldap_conn(ad_ctx, dom);
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek return clist;
afb21fd06690a0bec288a7970abf74ed2ea7dfdcJakub Hrozek}