e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny/*
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny SSSD
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny System Database - Sub-domain related calls
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny This program is free software; you can redistribute it and/or modify
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny it under the terms of the GNU General Public License as published by
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny the Free Software Foundation; either version 3 of the License, or
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny (at your option) any later version.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny This program is distributed in the hope that it will be useful,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny GNU General Public License for more details.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny You should have received a copy of the GNU General Public License
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny*/
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny#include "util/util.h"
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny#include "db/sysdb_private.h"
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio#include "db/sysdb_domain_resolution_order.h"
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekstatic errno_t
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekcheck_subdom_config_file(struct confdb_ctx *confdb,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct sss_domain_info *subdomain);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekstruct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct sss_domain_info *parent,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *name,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *realm,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *flat_name,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *id,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bool mpg,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bool enumerate,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek const char *forest,
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek const char **upn_suffixes,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek uint32_t trust_direction,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct confdb_ctx *confdb)
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek{
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek struct sss_domain_info *dom;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek bool inherit_option;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek errno_t ret;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek "Creating [%s] as subdomain of [%s]!\n", name, parent->name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom = talloc_zero(mem_ctx, struct sss_domain_info);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek return NULL;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->parent = parent;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* Sub-domains always have the same view as the parent */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->has_views = parent->has_views;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (parent->view_name != NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->view_name = talloc_strdup(dom, parent->view_name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->view_name == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy parent's view name.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->name = talloc_strdup(dom, name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->name == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy domain name.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->provider = talloc_strdup(dom, parent->provider);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->provider == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy provider name.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->conn_name = talloc_strdup(dom, parent->conn_name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->conn_name == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy connection name.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (realm != NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->realm = talloc_strdup(dom, realm);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->realm == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy realm name.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (flat_name != NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->flat_name = talloc_strdup(dom, flat_name);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->flat_name == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy flat name.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (id != NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->domain_id = talloc_strdup(dom, id);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->domain_id == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy id.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (forest != NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->forest = talloc_strdup(dom, forest);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (dom->forest == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy forest.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek if (upn_suffixes != NULL) {
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek dom->upn_suffixes = dup_string_list(dom, upn_suffixes);
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek if (dom->upn_suffixes == NULL) {
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Failed to copy UPN upn_suffixes.\n");
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek goto fail;
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek }
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek }
8718ff9ccd29f6431bfa8630bfa3576b2692c9eeJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->enumerate = enumerate;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->fqnames = true;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->mpg = mpg;
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek dom->state = DOM_ACTIVE;
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio /* use fully qualified names as output in order to avoid causing
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio * conflicts with users who have the same name and either the
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio * shortname user resolution is enabled or the trusted domain has
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio * been explicitly set to use non-fully qualified names as input.
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio */
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio dom->output_fqnames = true;
86526891366c4bc3e1ee861143b736d2670a6ba8Fabiano Fidêncio
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* If the parent domain filters out group members, the subdomain should
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek * as well if configured */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek inherit_option = string_in_list(CONFDB_DOMAIN_IGNORE_GROUP_MEMBERS,
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek parent->sd_inherit, false);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (inherit_option) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->ignore_group_members = parent->ignore_group_members;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->trust_direction = trust_direction;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek /* If the parent domain explicitly limits ID ranges, the subdomain
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek * should honour the limits as well.
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek */
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->id_min = parent->id_min ? parent->id_min : 0;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->id_max = parent->id_max ? parent->id_max : 0xffffffff;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->pwd_expiration_warning = parent->pwd_expiration_warning;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->cache_credentials = parent->cache_credentials;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->cache_credentials_min_ff_length =
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek parent->cache_credentials_min_ff_length;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->case_sensitive = false;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->user_timeout = parent->user_timeout;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->group_timeout = parent->group_timeout;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->netgroup_timeout = parent->netgroup_timeout;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->service_timeout = parent->service_timeout;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->names = parent->names;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->override_homedir = parent->override_homedir;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->fallback_homedir = parent->fallback_homedir;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->subdomain_homedir = parent->subdomain_homedir;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->override_shell = parent->override_shell;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->default_shell = parent->default_shell;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->homedir_substr = parent->homedir_substr;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek if (parent->sysdb == NULL) {
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Missing sysdb context in parent domain.\n");
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek goto fail;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek }
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek dom->sysdb = parent->sysdb;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek if (confdb != NULL) {
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek /* If confdb was provided, also check for sssd.conf */
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = check_subdom_config_file(confdb, dom);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek if (ret != EOK) {
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek DEBUG(SSSDBG_CRIT_FAILURE,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek "Failed to read subdomain configuration [%d]: %s",
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret, sss_strerror(ret));
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek goto fail;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek }
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek }
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek return dom;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozekfail:
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek talloc_free(dom);
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek return NULL;
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek}
50936fc7230a9b3f01e285e72c4182013542f53eJakub Hrozek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekstatic errno_t
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekcheck_subdom_config_file(struct confdb_ctx *confdb,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct sss_domain_info *subdomain)
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek{
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek char *sd_conf_path;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek TALLOC_CTX *tmp_ctx;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek errno_t ret;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek tmp_ctx = talloc_new(NULL);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek if (tmp_ctx == NULL) {
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek return ENOMEM;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek }
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek sd_conf_path = subdomain_create_conf_path(tmp_ctx, subdomain);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek if (sd_conf_path == NULL) {
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = ENOMEM;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek goto done;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek }
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek /* use_fully_qualified_names */
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = confdb_get_bool(confdb, sd_conf_path, CONFDB_DOMAIN_FQ,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek true, &subdomain->fqnames);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek if (ret != EOK) {
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek DEBUG(SSSDBG_OP_FAILURE,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek "Failed to get %s option for the subdomain: %s\n",
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek CONFDB_DOMAIN_FQ, subdomain->name);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek goto done;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek }
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek DEBUG(SSSDBG_CONF_SETTINGS, "%s/%s has value %s\n",
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek sd_conf_path, CONFDB_DOMAIN_FQ,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek subdomain->fqnames ? "TRUE" : "FALSE");
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = EOK;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekdone:
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek talloc_free(tmp_ctx);
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek return ret;
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek}
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic bool is_forest_root(struct sss_domain_info *d)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek{
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (d->forest == NULL) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek /* IPA subdomain provider saves/saved trusted forest root domains
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * without the forest attribute. Those are automatically forest
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek * roots
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek */
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek return true;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (d->realm && (strcasecmp(d->forest, d->realm) == 0)) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek return true;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek return false;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek}
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic bool is_same_forest(struct sss_domain_info *root,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct sss_domain_info *member)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek{
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (member->forest != NULL
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek && root->realm != NULL
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek && strcasecmp(member->forest, root->realm) == 0) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek return true;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek return false;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek}
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozekstatic void link_forest_roots(struct sss_domain_info *domain)
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek{
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct sss_domain_info *d;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek struct sss_domain_info *dd;
f191a6f9f3313df88eaf3debf52eebfe5d3dee59Michal Židek uint32_t gnd_flags = SSS_GND_ALL_DOMAINS;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (d = domain; d; d = get_next_domain(d, gnd_flags)) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek d->forest_root = NULL;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (d = domain; d; d = get_next_domain(d, gnd_flags)) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (d->forest_root != NULL) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek continue;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (is_forest_root(d) == true) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek d->forest_root = d;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL, "[%s] is a forest root\n", d->name);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (dd = domain; dd; dd = get_next_domain(dd, gnd_flags)) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (dd->forest_root != NULL) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek continue;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek if (is_same_forest(d, dd) == true) {
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek dd->forest_root = d;
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek "[%s] is a forest root of [%s]\n",
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek d->forest_root->name,
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek dd->name);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek }
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek}
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židekerrno_t sysdb_update_subdomains(struct sss_domain_info *domain,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek struct confdb_ctx *confdb)
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny{
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny int i;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny errno_t ret;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny TALLOC_CTX *tmp_ctx;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny struct ldb_result *res;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny const char *attrs[] = {"cn",
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce SYSDB_SUBDOMAIN_REALM,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny SYSDB_SUBDOMAIN_FLAT,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny SYSDB_SUBDOMAIN_ID,
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose SYSDB_SUBDOMAIN_MPG,
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek SYSDB_SUBDOMAIN_ENUM,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose SYSDB_SUBDOMAIN_FOREST,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek SYSDB_SUBDOMAIN_TRUST_DIRECTION,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose SYSDB_UPN_SUFFIXES,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny NULL};
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct sss_domain_info *dom;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny struct ldb_dn *basedn;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose const char *name;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose const char *realm;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose const char *flat;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose const char *id;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose const char *forest;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose bool mpg;
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek bool enumerate;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek uint32_t trust_direction;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose struct ldb_message_element *tmp_el;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose const char **upn_suffixes;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny tmp_ctx = talloc_new(NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (tmp_ctx == NULL) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = ENOMEM;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce basedn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, SYSDB_BASE);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (basedn == NULL) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = EIO;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
98195e591c4d97caa6125e8214879660b740973fSumit Bose basedn, LDB_SCOPE_SUBTREE,
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != LDB_SUCCESS) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = EIO;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* disable all domains,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce * let the search result refresh any that are still valid */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce for (dom = domain->subdomains; dom; dom = get_next_domain(dom, false)) {
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek sss_domain_set_state(dom, DOM_DISABLED);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (res->count == 0) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = EOK;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny for (i = 0; i < res->count; i++) {
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce name = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce if (name == NULL) {
7fe69bb6ec70bce439c6b975a9a0044c98ff502bSimo Sorce DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The object [%s] doesn't have a name\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[i]->dn));
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = EINVAL;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce realm = ldb_msg_find_attr_as_string(res->msgs[i],
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce SYSDB_SUBDOMAIN_REALM, NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce flat = ldb_msg_find_attr_as_string(res->msgs[i],
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce SYSDB_SUBDOMAIN_FLAT, NULL);
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce id = ldb_msg_find_attr_as_string(res->msgs[i],
aab938c5975f0e3b85c7c79a5d718e5fefed7217Simo Sorce SYSDB_SUBDOMAIN_ID, NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose mpg = ldb_msg_find_attr_as_bool(res->msgs[i],
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose SYSDB_SUBDOMAIN_MPG, false);
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek enumerate = ldb_msg_find_attr_as_bool(res->msgs[i],
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek SYSDB_SUBDOMAIN_ENUM, false);
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose forest = ldb_msg_find_attr_as_string(res->msgs[i],
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose SYSDB_SUBDOMAIN_FOREST, NULL);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose upn_suffixes = NULL;
a8a3fcbf6f75a7c2665e8bf503c186e07dfab333Jakub Hrozek tmp_el = ldb_msg_find_element(res->msgs[i], SYSDB_UPN_SUFFIXES);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (tmp_el != NULL) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose upn_suffixes = sss_ldb_el_to_string_list(tmp_ctx, tmp_el);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (upn_suffixes == NULL) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_ldb_el_to_string_list failed.\n");
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose ret = ENOMEM;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose goto done;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek trust_direction = ldb_msg_find_attr_as_int(res->msgs[i],
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek SYSDB_SUBDOMAIN_TRUST_DIRECTION,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek 0);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
2bbc9d6f8d5f2c1b07fd6968314b7f530b7f3a4dMichal Židek for (dom = domain->subdomains; dom;
2bbc9d6f8d5f2c1b07fd6968314b7f530b7f3a4dMichal Židek dom = get_next_domain(dom, SSS_GND_INCLUDE_DISABLED)) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcasecmp(dom->name, name) == 0) {
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek sss_domain_set_state(dom, DOM_ACTIVE);
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* in theory these may change, but it should never happen */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcasecmp(dom->realm, realm) != 0) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Realm name changed from [%s] to [%s]!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov dom->realm, realm);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce talloc_zfree(dom->realm);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom->realm = talloc_strdup(dom, realm);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dom->realm == NULL) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ENOMEM;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcasecmp(dom->flat_name, flat) != 0) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Flat name changed from [%s] to [%s]!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov dom->flat_name, flat);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce talloc_zfree(dom->flat_name);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom->flat_name = talloc_strdup(dom, flat);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dom->flat_name == NULL) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ENOMEM;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (strcasecmp(dom->domain_id, id) != 0) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Domain changed from [%s] to [%s]!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov dom->domain_id, id);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce talloc_zfree(dom->domain_id);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dom->domain_id = talloc_strdup(dom, id);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dom->domain_id == NULL) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ENOMEM;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose if (dom->mpg != mpg) {
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "MPG state change from [%s] to [%s]!\n",
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose dom->mpg ? "true" : "false",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov mpg ? "true" : "false");
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose dom->mpg = mpg;
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose }
9822d4d468ec74e4e173f5adf0db12d02974cd18Sumit Bose
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek if (dom->enumerate != enumerate) {
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek "enumerate state change from [%s] to [%s]!\n",
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek dom->enumerate ? "true" : "false",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov enumerate ? "true" : "false");
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek dom->enumerate = enumerate;
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek }
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if ((dom->forest == NULL && forest != NULL)
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose || (dom->forest != NULL && forest != NULL
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose && strcasecmp(dom->forest, forest) != 0)) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Forest changed from [%s] to [%s]!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov dom->forest, forest);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose talloc_zfree(dom->forest);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose dom->forest = talloc_strdup(dom, forest);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (dom->forest == NULL) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = ENOMEM;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose talloc_zfree(dom->upn_suffixes);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose dom->upn_suffixes = talloc_steal(dom, upn_suffixes);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (!dom->has_views && dom->view_name == NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* maybe views are not initialized, copy from parent */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->has_views = dom->parent->has_views;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (dom->parent->view_name != NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->view_name = talloc_strdup(dom,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->parent->view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (dom->view_name == NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "Failed to copy parent's view name.\n");
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = ENOMEM;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (dom->has_views != dom->parent->has_views
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose || strcmp(dom->view_name,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->parent->view_name) != 0) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "Sub-domain [%s][%s] and parent [%s][%s] " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "views are different.\n",
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->has_views ? "has view" : "has no view",
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->view_name,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->parent->has_views ? "has view" : "has no view",
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose dom->parent->view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = EINVAL;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if (dom->trust_direction != trust_direction) {
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek "Trust direction change from [%d] to [%d]!\n",
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek dom->trust_direction, trust_direction);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek dom->trust_direction = trust_direction;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek }
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce break;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* If not found in loop it is a new subdomain */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dom == NULL) {
a6cca9c284724fafd670a3163812f248ba53ad97Jakub Hrozek dom = new_subdomain(domain, domain, name, realm,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek flat, id, mpg, enumerate, forest,
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek upn_suffixes, trust_direction, confdb);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dom == NULL) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ENOMEM;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DLIST_ADD_END(domain->subdomains, dom, struct sss_domain_info *);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek link_forest_roots(domain);
b50baee36c9ba9e1dd3f6b9c1356482aecd08128Jakub Hrozek
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = EOK;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zelenydone:
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny talloc_free(tmp_ctx);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny return ret;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny}
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorceerrno_t sysdb_master_domain_update(struct sss_domain_info *domain)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny errno_t ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny TALLOC_CTX *tmp_ctx;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *tmp_str;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose struct ldb_message_element *tmp_el;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_dn *basedn;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_result *res;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *attrs[] = {"cn",
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce SYSDB_SUBDOMAIN_REALM,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_SUBDOMAIN_FLAT,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_SUBDOMAIN_ID,
17195241500e46272018d7897d6e87249870caf2Pavel Reichl SYSDB_SUBDOMAIN_FOREST,
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose SYSDB_UPN_SUFFIXES,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny NULL};
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose char *view_name = NULL;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tmp_ctx = talloc_new(NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (tmp_ctx == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
50d9424d38efe2421a60aa622fb342bea29ee4ebJakub Hrozek basedn = sysdb_domain_dn(tmp_ctx, domain);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (basedn == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EIO;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce basedn, LDB_SCOPE_BASE, attrs, NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != LDB_SUCCESS) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EIO;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce if (res->count == 0) {
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce ret = ENOENT;
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce goto done;
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce }
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce
cb388d52f49f54963379cc20a25e14d17fe6e9a3Simo Sorce if (res->count > 1) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Base search returned [%d] results, "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "expected 1.\n", res->count);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EINVAL;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_REALM,
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce NULL);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (tmp_str != NULL &&
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce (domain->realm == NULL || strcasecmp(tmp_str, domain->realm) != 0)) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce talloc_free(domain->realm);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->realm = talloc_strdup(domain, tmp_str);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (domain->realm == NULL) {
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce ret = ENOMEM;
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce goto done;
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny NULL);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (tmp_str != NULL &&
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce (domain->flat_name == NULL ||
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce strcasecmp(tmp_str, domain->flat_name) != 0)) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce talloc_free(domain->flat_name);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->flat_name = talloc_strdup(domain, tmp_str);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (domain->flat_name == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny NULL);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (tmp_str != NULL &&
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce (domain->domain_id == NULL ||
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce strcasecmp(tmp_str, domain->domain_id) != 0)) {
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce talloc_free(domain->domain_id);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce domain->domain_id = talloc_strdup(domain, tmp_str);
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce if (domain->domain_id == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
17195241500e46272018d7897d6e87249870caf2Pavel Reichl tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FOREST,
17195241500e46272018d7897d6e87249870caf2Pavel Reichl NULL);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (tmp_str != NULL &&
17195241500e46272018d7897d6e87249870caf2Pavel Reichl (domain->forest == NULL ||
17195241500e46272018d7897d6e87249870caf2Pavel Reichl strcasecmp(tmp_str, domain->forest) != 0)) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl talloc_free(domain->forest);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl domain->forest = talloc_strdup(domain, tmp_str);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (domain->forest == NULL) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = ENOMEM;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl goto done;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose tmp_el = ldb_msg_find_element(res->msgs[0], SYSDB_UPN_SUFFIXES);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (tmp_el != NULL) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose talloc_free(domain->upn_suffixes);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose domain->upn_suffixes = sss_ldb_el_to_string_list(domain, tmp_el);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (domain->upn_suffixes == NULL) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_ldb_el_to_string_list failed.\n");
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose ret = ENOMEM;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose goto done;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose } else {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose talloc_zfree(domain->upn_suffixes);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = sysdb_get_view_name(tmp_ctx, domain->sysdb, &view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (ret != EOK && ret != ENOENT) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_get_view_name failed.\n");
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* If no view is defined the default view will be used. In this case
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * domain->has_views is FALSE and
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * domain->view_name is set to SYSDB_DEFAULT_VIEW_NAME
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose *
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * If there is a view defined
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * domain->has_views is TRUE and
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * domain->view_name is set to the given view name
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose *
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * Currently changing the view is not supported hence we have to check for
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose * changes and error out accordingly.
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose */
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (ret == ENOENT || is_default_view(view_name)) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* handle default view */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (domain->has_views) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "View name change is currently not supported. " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "New view is the default view while current view is [%s]. " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "View name is not changed!\n", domain->view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (domain->view_name == NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose domain->view_name = talloc_strdup(domain,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose SYSDB_DEFAULT_VIEW_NAME);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (domain->view_name == NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = ENOMEM;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (strcmp(domain->view_name, SYSDB_DEFAULT_VIEW_NAME) != 0) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "Domain [%s] has no view but view name [%s] " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "is not the default view name [%s].\n",
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose domain->name, domain->view_name,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose SYSDB_DEFAULT_VIEW_NAME);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = EINVAL;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose /* handle view other than default */
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (domain->has_views) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (strcmp(domain->view_name, view_name) != 0) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "View name change is currently not supported. " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "New view is [%s] while current view is [%s]. " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "View name is not changed!\n",
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose view_name, domain->view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (domain->view_name == NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose domain->has_views = true;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose domain->view_name = talloc_steal(domain, view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (domain->view_name == NULL) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_steal failed.\n");
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = ENOMEM;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose if (strcmp(domain->view_name, SYSDB_DEFAULT_VIEW_NAME) == 0) {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "View name change is currently not supported. " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "New view is [%s] while current is the default view. " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "View name is not changed!\n", view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose } else {
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "Domain currently has no views, " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "but current view name is set to [%s] " \
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose "and new view name is [%s].\n",
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose domain->view_name, view_name);
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = EINVAL;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose goto done;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose }
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose ret = EOK;
9f734d4c122e37cc3080974342ed9586d05d5f83Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenydone:
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_free(tmp_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny}
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorceerrno_t sysdb_master_domain_add_info(struct sss_domain_info *domain,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek const char *realm,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek const char *flat,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek const char *id,
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose const char *forest,
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose struct ldb_message_element *upn_suffixes)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny TALLOC_CTX *tmp_ctx;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_message *msg;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny int ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny bool do_update = false;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tmp_ctx = talloc_new(NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (tmp_ctx == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny msg = ldb_msg_new(tmp_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (msg == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
50d9424d38efe2421a60aa622fb342bea29ee4ebJakub Hrozek msg->dn = sysdb_domain_dn(tmp_ctx, domain);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (msg->dn == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EIO;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce if (flat != NULL && (domain->flat_name == NULL ||
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce strcmp(domain->flat_name, flat) != 0)) {
7fe69bb6ec70bce439c6b975a9a0044c98ff502bSimo Sorce ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT,
7fe69bb6ec70bce439c6b975a9a0044c98ff502bSimo Sorce LDB_FLAG_MOD_REPLACE, NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != LDB_SUCCESS) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_error_to_errno(ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT, flat);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != LDB_SUCCESS) {
c03b28a38b14fdb59f74864ae4dc56affe256508Simo Sorce ret = sysdb_error_to_errno(ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny do_update = true;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce if (id != NULL && (domain->domain_id == NULL ||
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce strcmp(domain->domain_id, id) != 0)) {
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID,
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce LDB_FLAG_MOD_REPLACE, NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != LDB_SUCCESS) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_error_to_errno(ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, id);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != LDB_SUCCESS) {
c03b28a38b14fdb59f74864ae4dc56affe256508Simo Sorce ret = sysdb_error_to_errno(ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny do_update = true;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (forest != NULL && (domain->forest == NULL ||
17195241500e46272018d7897d6e87249870caf2Pavel Reichl strcmp(domain->forest, forest) != 0)) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FOREST,
17195241500e46272018d7897d6e87249870caf2Pavel Reichl LDB_FLAG_MOD_REPLACE, NULL);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (ret != LDB_SUCCESS) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = sysdb_error_to_errno(ret);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl goto done;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FOREST, forest);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl if (ret != LDB_SUCCESS) {
17195241500e46272018d7897d6e87249870caf2Pavel Reichl ret = sysdb_error_to_errno(ret);
17195241500e46272018d7897d6e87249870caf2Pavel Reichl goto done;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
17195241500e46272018d7897d6e87249870caf2Pavel Reichl do_update = true;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl }
17195241500e46272018d7897d6e87249870caf2Pavel Reichl
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek if (realm != NULL && (domain->realm == NULL ||
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek strcmp(domain->realm, realm) != 0)) {
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek LDB_FLAG_MOD_REPLACE, NULL);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek if (ret != LDB_SUCCESS) {
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = sysdb_error_to_errno(ret);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek goto done;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM, realm);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek if (ret != LDB_SUCCESS) {
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = sysdb_error_to_errno(ret);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek goto done;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek do_update = true;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (upn_suffixes != NULL) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose talloc_free(discard_const(upn_suffixes->name));
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose upn_suffixes->name = talloc_strdup(upn_suffixes, SYSDB_UPN_SUFFIXES);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (upn_suffixes->name == NULL) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose ret = ENOMEM;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose goto done;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose ret = ldb_msg_add(msg, upn_suffixes, LDB_FLAG_MOD_REPLACE);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (ret != LDB_SUCCESS) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose ret = sysdb_error_to_errno(ret);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose goto done;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose do_update = true;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose } else {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose /* Remove alternative_domain_suffixes from the cache */
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (domain->upn_suffixes != NULL) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_UPN_SUFFIXES,
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose LDB_FLAG_MOD_DELETE, NULL);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose if (ret != LDB_SUCCESS) {
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose ret = sysdb_error_to_errno(ret);
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose goto done;
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose
136a07ee4e03984949eb7236e5d0ca3bbaa578a3Sumit Bose do_update = true;
136a07ee4e03984949eb7236e5d0ca3bbaa578a3Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose }
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (do_update == false) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EOK;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = ldb_modify(domain->sysdb->ldb, msg);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != LDB_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add subdomain attributes to "
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce "[%s]: [%d][%s]!\n", domain->name, ret,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_errstring(domain->sysdb->ldb));
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_error_to_errno(ret);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3b0e0352d8076909608d04750d3ea6b0d9ba33f6Jakub Hrozek ret = sysdb_master_domain_update(domain);
3b0e0352d8076909608d04750d3ea6b0d9ba33f6Jakub Hrozek if (ret != EOK) {
3b0e0352d8076909608d04750d3ea6b0d9ba33f6Jakub Hrozek goto done;
3b0e0352d8076909608d04750d3ea6b0d9ba33f6Jakub Hrozek }
3b0e0352d8076909608d04750d3ea6b0d9ba33f6Jakub Hrozek
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EOK;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenydone:
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_free(tmp_ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny}
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorceerrno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce const char *name, const char *realm,
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose const char *flat_name, const char *domain_id,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek bool mpg, bool enumerate, const char *forest,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose uint32_t trust_direction,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose struct ldb_message_element *upn_suffixes)
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny{
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny TALLOC_CTX *tmp_ctx;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny struct ldb_message *msg;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce struct ldb_dn *dn;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce struct ldb_result *res;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce const char *attrs[] = {"cn",
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce SYSDB_SUBDOMAIN_REALM,
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce SYSDB_SUBDOMAIN_FLAT,
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce SYSDB_SUBDOMAIN_ID,
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose SYSDB_SUBDOMAIN_MPG,
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek SYSDB_SUBDOMAIN_ENUM,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose SYSDB_SUBDOMAIN_FOREST,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek SYSDB_SUBDOMAIN_TRUST_DIRECTION,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose SYSDB_UPN_SUFFIXES,
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce NULL};
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce const char *tmp_str;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose struct ldb_message_element *tmp_el;
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose bool tmp_bool;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce bool store = false;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce int realm_flags = 0;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce int flat_flags = 0;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce int id_flags = 0;
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose int mpg_flags = 0;
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek int enum_flags = 0;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose int forest_flags = 0;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek int td_flags = 0;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose int upn_flags = 0;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek uint32_t tmp_td;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny int ret;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny tmp_ctx = talloc_new(NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (tmp_ctx == NULL) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny return ENOMEM;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, name);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (dn == NULL) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = EIO;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce goto done;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_search(sysdb->ldb, tmp_ctx, &res,
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce dn, LDB_SCOPE_BASE, attrs, NULL);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (ret != LDB_SUCCESS) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = EIO;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (res->count == 0) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = sysdb_domain_create(sysdb, name);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (ret) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce goto done;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce store = true;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (realm) realm_flags = LDB_FLAG_MOD_ADD;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (flat_name) flat_flags = LDB_FLAG_MOD_ADD;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (domain_id) id_flags = LDB_FLAG_MOD_ADD;
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose mpg_flags = LDB_FLAG_MOD_ADD;
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek enum_flags = LDB_FLAG_MOD_ADD;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (forest) forest_flags = LDB_FLAG_MOD_ADD;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if (trust_direction) td_flags = LDB_FLAG_MOD_ADD;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (upn_suffixes) upn_flags = LDB_FLAG_MOD_ADD;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce } else if (res->count != 1) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = EINVAL;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce } else { /* 1 found */
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (realm) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce SYSDB_SUBDOMAIN_REALM, NULL);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (!tmp_str || strcasecmp(tmp_str, realm) != 0) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce realm_flags = LDB_FLAG_MOD_REPLACE;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (flat_name) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce SYSDB_SUBDOMAIN_FLAT, NULL);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (!tmp_str || strcasecmp(tmp_str, flat_name) != 0) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce flat_flags = LDB_FLAG_MOD_REPLACE;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (domain_id) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce SYSDB_SUBDOMAIN_ID, NULL);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (!tmp_str || strcasecmp(tmp_str, domain_id) != 0) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce id_flags = LDB_FLAG_MOD_REPLACE;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose tmp_bool = ldb_msg_find_attr_as_bool(res->msgs[0], SYSDB_SUBDOMAIN_MPG,
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose !mpg);
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (tmp_bool != mpg) {
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose mpg_flags = LDB_FLAG_MOD_REPLACE;
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose }
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek tmp_bool = ldb_msg_find_attr_as_bool(res->msgs[0], SYSDB_SUBDOMAIN_ENUM,
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek !enumerate);
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek if (tmp_bool != enumerate) {
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek enum_flags = LDB_FLAG_MOD_REPLACE;
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (forest) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose SYSDB_SUBDOMAIN_FOREST, NULL);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (!tmp_str || strcasecmp(tmp_str, forest) != 0) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose forest_flags = LDB_FLAG_MOD_REPLACE;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek tmp_td = ldb_msg_find_attr_as_uint(res->msgs[0],
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek SYSDB_SUBDOMAIN_TRUST_DIRECTION,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek 0);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if (tmp_td != trust_direction) {
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek td_flags = LDB_FLAG_MOD_REPLACE;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (upn_suffixes) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose tmp_el = ldb_msg_find_element(res->msgs[0], SYSDB_UPN_SUFFIXES);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose /* Luckily ldb_msg_element_compare() only compares the values and
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose * not the name. */
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (tmp_el == NULL
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose || ldb_msg_element_compare(upn_suffixes, tmp_el) != 0) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose upn_flags = LDB_FLAG_MOD_REPLACE;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (!store && realm_flags == 0 && flat_flags == 0 && id_flags == 0
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek && mpg_flags == 0 && enum_flags == 0 && forest_flags == 0
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose && td_flags == 0 && upn_flags == 0) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = EOK;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce msg = ldb_msg_new(tmp_ctx);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (msg == NULL) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ENOMEM;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce msg->dn = dn;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (store) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (ret != LDB_SUCCESS) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = sysdb_error_to_errno(ret);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce goto done;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_SUBDOMAIN_CLASS);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (ret != LDB_SUCCESS) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = sysdb_error_to_errno(ret);
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce goto done;
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (realm_flags) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, realm_flags, NULL);
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce if (ret != LDB_SUCCESS) {
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce ret = sysdb_error_to_errno(ret);
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce goto done;
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM, realm);
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce if (ret != LDB_SUCCESS) {
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce ret = sysdb_error_to_errno(ret);
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce goto done;
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce }
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (flat_flags) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, flat_flags, NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != LDB_SUCCESS) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = sysdb_error_to_errno(ret);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT, flat_name);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != LDB_SUCCESS) {
c03b28a38b14fdb59f74864ae4dc56affe256508Simo Sorce ret = sysdb_error_to_errno(ret);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce if (id_flags) {
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, id_flags, NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != LDB_SUCCESS) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = sysdb_error_to_errno(ret);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_id);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != LDB_SUCCESS) {
c03b28a38b14fdb59f74864ae4dc56affe256508Simo Sorce ret = sysdb_error_to_errno(ret);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (mpg_flags) {
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_MPG, mpg_flags, NULL);
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (ret != LDB_SUCCESS) {
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose ret = sysdb_error_to_errno(ret);
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose goto done;
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose }
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_MPG,
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose mpg ? "TRUE" : "FALSE");
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (ret != LDB_SUCCESS) {
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose ret = sysdb_error_to_errno(ret);
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose goto done;
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose }
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose }
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek if (enum_flags) {
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ENUM, enum_flags, NULL);
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek if (ret != LDB_SUCCESS) {
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek ret = sysdb_error_to_errno(ret);
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek goto done;
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek }
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ENUM,
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek enumerate ? "TRUE" : "FALSE");
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek if (ret != LDB_SUCCESS) {
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek ret = sysdb_error_to_errno(ret);
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek goto done;
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek }
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek }
b3458bbb5315b05d7ac1abc58f1c380761756603Jakub Hrozek
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (forest_flags) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FOREST, forest_flags,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose NULL);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (ret != LDB_SUCCESS) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = sysdb_error_to_errno(ret);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FOREST, forest);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (ret != LDB_SUCCESS) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = sysdb_error_to_errno(ret);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto done;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if (td_flags) {
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_TRUST_DIRECTION,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek td_flags, NULL);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if (ret != LDB_SUCCESS) {
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek ret = sysdb_error_to_errno(ret);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek goto done;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek }
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_TRUST_DIRECTION,
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek "%u", trust_direction);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek if (ret != LDB_SUCCESS) {
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek ret = sysdb_error_to_errno(ret);
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek goto done;
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek }
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek }
ea224c3813a537639778f91ac762732b3c289603Jakub Hrozek
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (upn_flags) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose tmp_el = talloc_zero(tmp_ctx, struct ldb_message_element);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (tmp_el == NULL) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose ret = ENOMEM;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose goto done;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose tmp_el->name = SYSDB_UPN_SUFFIXES;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose tmp_el->num_values = upn_suffixes->num_values;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose tmp_el->values = upn_suffixes->values;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose ret = ldb_msg_add(msg, tmp_el, upn_flags);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose if (ret != LDB_SUCCESS) {
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose ret = sysdb_error_to_errno(ret);
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose goto done;
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose }
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = ldb_modify(sysdb->ldb, msg);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != LDB_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add subdomain attributes to "
1187a07ed4207c1c326fdf83915dddfe472b8620Simo Sorce "[%s]: [%d][%s]!\n", name, ret,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_errstring(sysdb->ldb));
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = sysdb_error_to_errno(ret);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = EOK;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zelenydone:
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny talloc_free(tmp_ctx);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny return ret;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny}
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorceerrno_t sysdb_subdomain_delete(struct sysdb_ctx *sysdb, const char *name)
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny{
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny TALLOC_CTX *tmp_ctx = NULL;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny struct ldb_dn *dn;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce int ret;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny tmp_ctx = talloc_new(NULL);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (tmp_ctx == NULL) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = ENOMEM;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Removing sub-domain [%s] from db.\n", name);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, name);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (dn == NULL) {
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny ret = ENOMEM;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_delete_recursive(sysdb, dn, true);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_delete_recursive failed.\n");
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny goto done;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny }
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zelenydone:
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny talloc_free(tmp_ctx);
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny return ret;
e76d78338026fa47dca32eaf7f5c15eabb1b951aJan Zeleny}
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncioerrno_t
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidênciosysdb_domain_get_domain_resolution_order(TALLOC_CTX *mem_ctx,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio struct sysdb_ctx *sysdb,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio const char *domain_name,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio const char **_domain_resolution_order)
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio{
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio TALLOC_CTX *tmp_ctx;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio struct ldb_dn *dn;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio errno_t ret;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio tmp_ctx = talloc_new(NULL);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio if (tmp_ctx == NULL) {
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio return ENOMEM;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio }
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, domain_name);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio if (dn == NULL) {
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio ret = ENOMEM;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio goto done;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio }
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio ret = sysdb_get_domain_resolution_order(mem_ctx, sysdb, dn,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio _domain_resolution_order);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidênciodone:
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio talloc_free(tmp_ctx);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio return ret;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio}
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncioerrno_t
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidênciosysdb_domain_update_domain_resolution_order(struct sysdb_ctx *sysdb,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio const char *domain_name,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio const char *domain_resolution_order)
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio{
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio TALLOC_CTX *tmp_ctx;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio struct ldb_dn *dn;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio errno_t ret;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio tmp_ctx = talloc_new(NULL);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio if (tmp_ctx == NULL) {
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio return ENOMEM;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio }
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, domain_name);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio if (dn == NULL) {
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio ret = ENOMEM;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio goto done;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio }
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio ret = sysdb_update_domain_resolution_order(sysdb, dn,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio domain_resolution_order);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio if (ret != EOK) {
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio DEBUG(SSSDBG_OP_FAILURE,
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio "sysdb_update_domain_resolution_order() failed [%d]: [%s].\n",
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio ret, sss_strerror(ret));
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio goto done;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio }
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio ret = EOK;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidênciodone:
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio talloc_free(tmp_ctx);
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio return ret;
3cbf0e7b63e8e6888917e9215bbdc5674c2fa852Fabiano Fidêncio}
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březinaerrno_t
e16539779668dacff868999bd59dbf33e3eab872Pavel Březinasysdb_get_site(TALLOC_CTX *mem_ctx,
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina struct sss_domain_info *dom,
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina const char **_site)
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina{
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina TALLOC_CTX *tmp_ctx;
fb0431b13a9fcd8ac31e622503acbd10d2b73ac9Pavel Březina struct ldb_result *res;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina struct ldb_dn *dn;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina const char *attrs[] = { SYSDB_SITE, NULL };
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina errno_t ret;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina tmp_ctx = talloc_new(NULL);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (tmp_ctx == NULL) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina return ENOMEM;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
50d9424d38efe2421a60aa622fb342bea29ee4ebJakub Hrozek dn = sysdb_domain_dn(tmp_ctx, dom);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (dn == NULL) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ENOMEM;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ldb_search(dom->sysdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE,
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina attrs, NULL);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (ret != LDB_SUCCESS) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = sysdb_error_to_errno(ret);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (res->count == 0) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina *_site = NULL;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = EOK;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina } else if (res->count != 1) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE,
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina "Got more than one reply for base search!\n");
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = EIO;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina *_site = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SITE, NULL);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina talloc_steal(mem_ctx, *_site);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = EOK;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březinadone:
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina talloc_free(tmp_ctx);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina return ret;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina}
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březinaerrno_t
e16539779668dacff868999bd59dbf33e3eab872Pavel Březinasysdb_set_site(struct sss_domain_info *dom,
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina const char *site)
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina{
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina TALLOC_CTX *tmp_ctx;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina struct ldb_message *msg;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina struct ldb_dn *dn;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina errno_t ret;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina tmp_ctx = talloc_new(NULL);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (tmp_ctx == NULL) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina return ENOMEM;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
50d9424d38efe2421a60aa622fb342bea29ee4ebJakub Hrozek dn = sysdb_domain_dn(tmp_ctx, dom);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (dn == NULL) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ENOMEM;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina msg = ldb_msg_new(tmp_ctx);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (msg == NULL) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ENOMEM;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina msg->dn = dn;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ldb_msg_add_empty(msg, SYSDB_SITE, LDB_FLAG_MOD_REPLACE, NULL);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (ret != LDB_SUCCESS) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = sysdb_error_to_errno(ret);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (site != NULL) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ldb_msg_add_string(msg, SYSDB_SITE, site);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (ret != LDB_SUCCESS) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = sysdb_error_to_errno(ret);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = ldb_modify(dom->sysdb->ldb, msg);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina if (ret != LDB_SUCCESS) {
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina DEBUG(SSSDBG_OP_FAILURE,
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina "ldb_modify()_failed: [%s][%d][%s]\n",
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ldb_strerror(ret), ret, ldb_errstring(dom->sysdb->ldb));
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = sysdb_error_to_errno(ret);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina goto done;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina }
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina ret = EOK;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina
e16539779668dacff868999bd59dbf33e3eab872Pavel Březinadone:
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina talloc_free(tmp_ctx);
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina return ret;
e16539779668dacff868999bd59dbf33e3eab872Pavel Březina}