sysdb_subdomains.c revision 17195241500e46272018d7897d6e87249870caf2
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin System Database - Sub-domain related calls
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
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 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.
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/>.
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_update_subdomains(struct sss_domain_info *domain)
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *name;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *realm;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *flat;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *id;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *forest;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin basedn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, SYSDB_BASE);
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 name = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ("The object [%s] doesn't have a name\n",
e487d6c09669296f94a5190cc34586a98e624a00nd /* explicitly use dom->next as we need to check 'disabled' domains */
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic for (dom = domain->subdomains; dom; dom = dom->next) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic /* in theory these may change, but it should never happen */
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ("Realm name changed from [%s] to [%s]!\n",
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ("Flat name changed from [%s] to [%s]!\n",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ("Domain changed from [%s] to [%s]!\n",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ("MPG state change from [%s] to [%s]!\n",
e04d06603a7abd1090421cbc961685d5468f1039humbedooh ("MPG state change from [%s] to [%s]!\n",
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ("Forest changed from [%s] to [%s]!\n",
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin /* If not found in loop it is a new subdomain */
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DLIST_ADD_END(domain->subdomains, dom, struct sss_domain_info *);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_master_domain_update(struct sss_domain_info *domain)
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf const char *tmp_str;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, "
016241a6ee9c7b02ff94f30f90e705012ea08e41jsl tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_REALM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin (domain->realm == NULL || strcasecmp(tmp_str, domain->realm) != 0)) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FOREST,
47c70d0375af94ba766091e7bc3a7ed93331ae86rbowenerrno_t sysdb_master_domain_add_info(struct sss_domain_info *domain,
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf const char* forest)
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic bool do_update = false;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin msg->dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
e487d6c09669296f94a5190cc34586a98e624a00nd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT, flat);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FOREST,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FOREST, forest);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (do_update == false) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin const char *tmp_str;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin bool store = false;
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin } else { /* 1 found */
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (!tmp_str || strcasecmp(tmp_str, flat_name) != 0) {
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_bool = ldb_msg_find_attr_as_bool(res->msgs[0], SYSDB_SUBDOMAIN_MPG,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin tmp_bool = ldb_msg_find_attr_as_bool(res->msgs[0], SYSDB_SUBDOMAIN_ENUM,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin if (!store && realm_flags == 0 && flat_flags == 0 && id_flags == 0
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin && mpg_flags == 0 && enum_flags == 0 && forest_flags == 0) {
e41ae559e8408edb1c949c1237034f277d423eccminfrin ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_SUBDOMAIN_CLASS);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, realm_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM, realm);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, flat_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT, flat_name);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, id_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_id);
32d8ef43efe6077a8c34efb5c34bbaa5742ca2bfrbowen ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_MPG, mpg_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ENUM, enum_flags, NULL);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FOREST, forest_flags,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FOREST, forest);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrinerrno_t sysdb_subdomain_delete(struct sysdb_ctx *sysdb, const char *name)
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);
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_recursive failed.\n"));