sysdb_subdomains.c revision 17195241500e46272018d7897d6e87249870caf2
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin/*
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SSSD
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin System Database - Sub-domain related calls
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin This program is free software; you can redistribute it and/or modify
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin it under the terms of the GNU General Public License as published by
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the Free Software Foundation; either version 3 of the License, or
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (at your option) any later version.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen This program is distributed in the hope that it will be useful,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin but WITHOUT ANY WARRANTY; without even the implied warranty of
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin GNU General Public License for more details.
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen
3f08db06526d6901aa08c110b5bc7dde6bc39905nd You should have received a copy of the GNU General Public License
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin along with this program. If not, see <http://www.gnu.org/licenses/>.
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin*/
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#include "util/util.h"
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin#include "db/sysdb_private.h"
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_update_subdomains(struct sss_domain_info *domain)
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung{
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int i;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin errno_t ret;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin TALLOC_CTX *tmp_ctx;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_result *res;
a7818b8de55671a82b0863d27665713f265af7aeigalic const char *attrs[] = {"cn",
a7818b8de55671a82b0863d27665713f265af7aeigalic SYSDB_SUBDOMAIN_REALM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FLAT,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ID,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_MPG,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ENUM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FOREST,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin NULL};
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct sss_domain_info *dom;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_dn *basedn;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *name;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *realm;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *flat;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *id;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *forest;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin bool mpg;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin bool enumerate;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_ctx = talloc_new(NULL);
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl if (tmp_ctx == NULL) {
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin basedn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, SYSDB_BASE);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (basedn == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EIO;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl goto done;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl }
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin basedn, LDB_SCOPE_ONELEVEL,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EIO;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin /* disable all domains,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin * let the search result refresh any that are still valid */
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin for (dom = domain->subdomains; dom; dom = get_next_domain(dom, false)) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom->disabled = true;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (res->count == 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EOK;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin for (i = 0; i < res->count; i++) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin name = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (name == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_MINOR_FAILURE,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ("The object [%s] doesn't have a name\n",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ldb_dn_get_linearized(res->msgs[i]->dn)));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EINVAL;
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin realm = ldb_msg_find_attr_as_string(res->msgs[i],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_REALM, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin flat = ldb_msg_find_attr_as_string(res->msgs[i],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FLAT, NULL);
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin id = ldb_msg_find_attr_as_string(res->msgs[i],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ID, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf mpg = ldb_msg_find_attr_as_bool(res->msgs[i],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_MPG, false);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin enumerate = ldb_msg_find_attr_as_bool(res->msgs[i],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ENUM, false);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin forest = ldb_msg_find_attr_as_string(res->msgs[i],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FOREST, NULL);
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
e487d6c09669296f94a5190cc34586a98e624a00nd /* explicitly use dom->next as we need to check 'disabled' domains */
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic for (dom = domain->subdomains; dom; dom = dom->next) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (strcasecmp(dom->name, name) == 0) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic dom->disabled = false;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic /* in theory these may change, but it should never happen */
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (strcasecmp(dom->realm, realm) != 0) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic DEBUG(SSSDBG_TRACE_INTERNAL,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ("Realm name changed from [%s] to [%s]!\n",
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic dom->realm, realm));
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic talloc_zfree(dom->realm);
e487d6c09669296f94a5190cc34586a98e624a00nd dom->realm = talloc_strdup(dom, realm);
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf if (dom->realm == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (strcasecmp(dom->flat_name, flat) != 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_TRACE_INTERNAL,
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ("Flat name changed from [%s] to [%s]!\n",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom->flat_name, flat));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_zfree(dom->flat_name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom->flat_name = talloc_strdup(dom, flat);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (dom->flat_name == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (strcasecmp(dom->domain_id, id) != 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_TRACE_INTERNAL,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ("Domain changed from [%s] to [%s]!\n",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom->domain_id, id));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_zfree(dom->domain_id);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom->domain_id = talloc_strdup(dom, id);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (dom->domain_id == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (dom->mpg != mpg) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_TRACE_INTERNAL,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ("MPG state change from [%s] to [%s]!\n",
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf dom->mpg ? "true" : "false",
e04d06603a7abd1090421cbc961685d5468f1039humbedooh mpg ? "true" : "false"));
e04d06603a7abd1090421cbc961685d5468f1039humbedooh dom->mpg = mpg;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh }
e04d06603a7abd1090421cbc961685d5468f1039humbedooh
e04d06603a7abd1090421cbc961685d5468f1039humbedooh if (dom->enumerate != enumerate) {
e04d06603a7abd1090421cbc961685d5468f1039humbedooh DEBUG(SSSDBG_TRACE_INTERNAL,
e04d06603a7abd1090421cbc961685d5468f1039humbedooh ("MPG state change from [%s] to [%s]!\n",
e04d06603a7abd1090421cbc961685d5468f1039humbedooh dom->enumerate ? "true" : "false",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin enumerate ? "true" : "false"));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom->enumerate = enumerate;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf if ((dom->forest == NULL && forest != NULL)
e487d6c09669296f94a5190cc34586a98e624a00nd || (dom->forest != NULL && forest != NULL
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic && strcasecmp(dom->forest, forest) != 0)) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic DEBUG(SSSDBG_TRACE_INTERNAL,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ("Forest changed from [%s] to [%s]!\n",
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic dom->forest, forest));
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic talloc_zfree(dom->forest);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic dom->forest = talloc_strdup(dom, forest);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (dom->forest == NULL) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = ENOMEM;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic goto done;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic break;
e487d6c09669296f94a5190cc34586a98e624a00nd }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin /* If not found in loop it is a new subdomain */
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (dom == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dom = new_subdomain(domain, domain, name, realm,
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl flat, id, mpg, enumerate, forest);
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl if (dom == NULL) {
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DLIST_ADD_END(domain->subdomains, dom, struct sss_domain_info *);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
e04d06603a7abd1090421cbc961685d5468f1039humbedooh }
e04d06603a7abd1090421cbc961685d5468f1039humbedooh
e04d06603a7abd1090421cbc961685d5468f1039humbedooh ret = EOK;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh
e04d06603a7abd1090421cbc961685d5468f1039humbedoohdone:
e04d06603a7abd1090421cbc961685d5468f1039humbedooh talloc_free(tmp_ctx);
e04d06603a7abd1090421cbc961685d5468f1039humbedooh return ret;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh}
e04d06603a7abd1090421cbc961685d5468f1039humbedooh
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_master_domain_update(struct sss_domain_info *domain)
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin{
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin errno_t ret;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin TALLOC_CTX *tmp_ctx;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf const char *tmp_str;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_dn *basedn;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf struct ldb_result *res;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *attrs[] = {"cn",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_REALM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FLAT,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ID,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FOREST,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin NULL};
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_ctx = talloc_new(NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_ctx == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin return ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl SYSDB_DOM_BASE, domain->name);
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl if (basedn == NULL) {
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl ret = EIO;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl goto done;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl }
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin basedn, LDB_SCOPE_BASE, attrs, NULL);
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl if (ret != LDB_SUCCESS) {
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl ret = EIO;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
e487d6c09669296f94a5190cc34586a98e624a00nd }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (res->count == 0) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = ENOENT;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic goto done;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (res->count > 1) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, "
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic "expected 1.\n", res->count));
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = EINVAL;
e487d6c09669296f94a5190cc34586a98e624a00nd goto done;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf }
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_REALM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_str != NULL &&
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin (domain->realm == NULL || strcasecmp(tmp_str, domain->realm) != 0)) {
e04d06603a7abd1090421cbc961685d5468f1039humbedooh talloc_free(domain->realm);
e04d06603a7abd1090421cbc961685d5468f1039humbedooh domain->realm = talloc_strdup(domain, tmp_str);
e04d06603a7abd1090421cbc961685d5468f1039humbedooh if (domain->realm == NULL) {
e04d06603a7abd1090421cbc961685d5468f1039humbedooh ret = ENOMEM;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh goto done;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh }
e04d06603a7abd1090421cbc961685d5468f1039humbedooh }
e04d06603a7abd1090421cbc961685d5468f1039humbedooh
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_str != NULL &&
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin (domain->flat_name == NULL ||
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin strcasecmp(tmp_str, domain->flat_name) != 0)) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_free(domain->flat_name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin domain->flat_name = talloc_strdup(domain, tmp_str);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (domain->flat_name == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_str != NULL &&
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin (domain->domain_id == NULL ||
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin strcasecmp(tmp_str, domain->domain_id) != 0)) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_free(domain->domain_id);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin domain->domain_id = talloc_strdup(domain, tmp_str);
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl if (domain->domain_id == NULL) {
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FOREST,
e04d06603a7abd1090421cbc961685d5468f1039humbedooh NULL);
e04d06603a7abd1090421cbc961685d5468f1039humbedooh if (tmp_str != NULL &&
e04d06603a7abd1090421cbc961685d5468f1039humbedooh (domain->forest == NULL ||
e04d06603a7abd1090421cbc961685d5468f1039humbedooh strcasecmp(tmp_str, domain->forest) != 0)) {
e04d06603a7abd1090421cbc961685d5468f1039humbedooh talloc_free(domain->forest);
e04d06603a7abd1090421cbc961685d5468f1039humbedooh domain->forest = talloc_strdup(domain, tmp_str);
e04d06603a7abd1090421cbc961685d5468f1039humbedooh if (domain->forest == NULL) {
e04d06603a7abd1090421cbc961685d5468f1039humbedooh ret = ENOMEM;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh goto done;
e04d06603a7abd1090421cbc961685d5468f1039humbedooh }
e04d06603a7abd1090421cbc961685d5468f1039humbedooh }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrindone:
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_free(tmp_ctx);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin return ret;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin}
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
47c70d0375af94ba766091e7bc3a7ed93331ae86rbowenerrno_t sysdb_master_domain_add_info(struct sss_domain_info *domain,
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl const char *flat, const char *id,
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf const char* forest)
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin{
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin TALLOC_CTX *tmp_ctx;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_message *msg;
e487d6c09669296f94a5190cc34586a98e624a00nd int ret;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic bool do_update = false;
888e1c11ac3d57919ad538235846188bfbe4fcb1humbedooh
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic tmp_ctx = talloc_new(NULL);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (tmp_ctx == NULL) {
e487d6c09669296f94a5190cc34586a98e624a00nd return ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin msg = ldb_msg_new(tmp_ctx);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (msg == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin msg->dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_DOM_BASE, domain->name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (msg->dn == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EIO;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (flat != NULL && (domain->flat_name == NULL ||
e487d6c09669296f94a5190cc34586a98e624a00nd strcmp(domain->flat_name, flat) != 0)) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic LDB_FLAG_MOD_REPLACE, NULL);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (ret != LDB_SUCCESS) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = sysdb_error_to_errno(ret);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic goto done;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
e487d6c09669296f94a5190cc34586a98e624a00nd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT, flat);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin do_update = true;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (id != NULL && (domain->domain_id == NULL ||
e487d6c09669296f94a5190cc34586a98e624a00nd strcmp(domain->domain_id, id) != 0)) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic LDB_FLAG_MOD_REPLACE, NULL);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (ret != LDB_SUCCESS) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = sysdb_error_to_errno(ret);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic goto done;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
e487d6c09669296f94a5190cc34586a98e624a00nd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, id);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick ret = sysdb_error_to_errno(ret);
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick goto done;
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick }
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick do_update = true;
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick }
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (forest != NULL && (domain->forest == NULL ||
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin strcmp(domain->forest, forest) != 0)) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FOREST,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin LDB_FLAG_MOD_REPLACE, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FOREST, forest);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin do_update = true;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (do_update == false) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EOK;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_modify(domain->sysdb->ldb, msg);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin "[%s]: [%d][%s]!\n", domain->name, ret,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ldb_errstring(domain->sysdb->ldb)));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_master_domain_update(domain);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != EOK) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EOK;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrindone:
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_free(tmp_ctx);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin return ret;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf}
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *name, const char *realm,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *flat_name, const char *domain_id,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin bool mpg, bool enumerate, const char *forest)
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin{
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin TALLOC_CTX *tmp_ctx;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_message *msg;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_dn *dn;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_result *res;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *attrs[] = {"cn",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_REALM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FLAT,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ID,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_MPG,
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen SYSDB_SUBDOMAIN_ENUM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FOREST,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin NULL};
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *tmp_str;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin bool tmp_bool;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin bool store = false;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int realm_flags = 0;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int flat_flags = 0;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int id_flags = 0;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int mpg_flags = 0;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int enum_flags = 0;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int forest_flags = 0;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int ret;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_ctx = talloc_new(NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_ctx == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin return ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, name);
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen if (dn == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EIO;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_search(sysdb->ldb, tmp_ctx, &res,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dn, LDB_SCOPE_BASE, attrs, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EIO;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (res->count == 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_domain_create(sysdb, name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin store = true;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (realm) realm_flags = LDB_FLAG_MOD_ADD;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (flat_name) flat_flags = LDB_FLAG_MOD_ADD;
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen if (domain_id) id_flags = LDB_FLAG_MOD_ADD;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin mpg_flags = LDB_FLAG_MOD_ADD;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin enum_flags = LDB_FLAG_MOD_ADD;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (forest) forest_flags = LDB_FLAG_MOD_ADD;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin } else if (res->count != 1) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EINVAL;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin } else { /* 1 found */
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (realm) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_REALM, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (!tmp_str || strcasecmp(tmp_str, realm) != 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin realm_flags = LDB_FLAG_MOD_REPLACE;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (flat_name) {
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_FLAT, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (!tmp_str || strcasecmp(tmp_str, flat_name) != 0) {
e41ae559e8408edb1c949c1237034f277d423eccminfrin flat_flags = LDB_FLAG_MOD_REPLACE;
e41ae559e8408edb1c949c1237034f277d423eccminfrin }
e41ae559e8408edb1c949c1237034f277d423eccminfrin }
e41ae559e8408edb1c949c1237034f277d423eccminfrin if (domain_id) {
ff4eeb709e3f992376253f506c5d23361bc369ffnilgun tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin SYSDB_SUBDOMAIN_ID, NULL);
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf if (!tmp_str || strcasecmp(tmp_str, domain_id) != 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin id_flags = LDB_FLAG_MOD_REPLACE;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_bool = ldb_msg_find_attr_as_bool(res->msgs[0], SYSDB_SUBDOMAIN_MPG,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin !mpg);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_bool != mpg) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin mpg_flags = LDB_FLAG_MOD_REPLACE;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_bool = ldb_msg_find_attr_as_bool(res->msgs[0], SYSDB_SUBDOMAIN_ENUM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin !enumerate);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_bool != enumerate) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin enum_flags = LDB_FLAG_MOD_REPLACE;
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (forest) {
e41ae559e8408edb1c949c1237034f277d423eccminfrin tmp_str = ldb_msg_find_attr_as_string(res->msgs[0],
e41ae559e8408edb1c949c1237034f277d423eccminfrin SYSDB_SUBDOMAIN_FOREST, NULL);
e41ae559e8408edb1c949c1237034f277d423eccminfrin if (!tmp_str || strcasecmp(tmp_str, forest) != 0) {
e41ae559e8408edb1c949c1237034f277d423eccminfrin forest_flags = LDB_FLAG_MOD_REPLACE;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (!store && realm_flags == 0 && flat_flags == 0 && id_flags == 0
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin && mpg_flags == 0 && enum_flags == 0 && forest_flags == 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = EOK;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin msg = ldb_msg_new(tmp_ctx);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (msg == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen msg->dn = dn;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (store) {
e41ae559e8408edb1c949c1237034f277d423eccminfrin ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
e41ae559e8408edb1c949c1237034f277d423eccminfrin if (ret != LDB_SUCCESS) {
e41ae559e8408edb1c949c1237034f277d423eccminfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_SUBDOMAIN_CLASS);
e487d6c09669296f94a5190cc34586a98e624a00nd if (ret != LDB_SUCCESS) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = sysdb_error_to_errno(ret);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic goto done;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (realm_flags) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, realm_flags, NULL);
e487d6c09669296f94a5190cc34586a98e624a00nd if (ret != LDB_SUCCESS) {
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl }
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM, realm);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (flat_flags) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, flat_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT, flat_name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (id_flags) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, id_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_id);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (mpg_flags) {
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_MPG, mpg_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim goto done;
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_MPG,
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf mpg ? "TRUE" : "FALSE");
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (enum_flags) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ENUM, enum_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ENUM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin enumerate ? "TRUE" : "FALSE");
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (forest_flags) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FOREST, forest_flags,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FOREST, forest);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_error_to_errno(ret);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_modify(sysdb->ldb, msg);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (ret != LDB_SUCCESS) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin "[%s]: [%d][%s]!\n", name, ret,
e487d6c09669296f94a5190cc34586a98e624a00nd ldb_errstring(sysdb->ldb)));
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = sysdb_error_to_errno(ret);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic goto done;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic }
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = EOK;
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalicdone:
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic talloc_free(tmp_ctx);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic return ret;
e487d6c09669296f94a5190cc34586a98e624a00nd}
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_subdomain_delete(struct sysdb_ctx *sysdb, const char *name)
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin{
a29610af88e278144045bfa1bc63b4a1a4b5ff14trawick TALLOC_CTX *tmp_ctx = NULL;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin struct ldb_dn *dn;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin int ret;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_ctx = talloc_new(NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (tmp_ctx == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_TRACE_FUNC, ("Removing sub-domain [%s] from db.\n", name));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, name);
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen if (dn == NULL) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ENOMEM;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = sysdb_delete_recursive(sysdb, dn, true);
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf if (ret != EOK) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_recursive failed.\n"));
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin goto done;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin }
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrindone:
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin talloc_free(tmp_ctx);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin return ret;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin}
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin