sysdb_subdomains.c revision 99c0cfdc5f065ba38f1ee91701d1d27f9e4fdb96
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive System Database - Sub-domain related calls
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is free software; you can redistribute it and/or modify
fe64b2ba25510d8c9dba5560a2d537763566cf40nd it under the terms of the GNU General Public License as published by
fe64b2ba25510d8c9dba5560a2d537763566cf40nd the Free Software Foundation; either version 3 of the License, or
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (at your option) any later version.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is distributed in the hope that it will be useful,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd but WITHOUT ANY WARRANTY; without even the implied warranty of
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fe64b2ba25510d8c9dba5560a2d537763566cf40nd GNU General Public License for more details.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd You should have received a copy of the GNU General Public License
4b5981e276e93df97c34e4da05ca5cf8bbd937dand along with this program. If not, see <http://www.gnu.org/licenses/>.
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowenerrno_t sysdb_get_subdomains(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd const char *tmp_str;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd list = talloc_zero_array(tmp_ctx, struct sysdb_subdom *, res->count + 1);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ("The object [%s] doesn't have a name\n",
031bbbc0d1189b07330e38d0c126820a9ab7795egryzorerrno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe const char *tmp_str;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_BASE, attrs,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, "
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_REALM,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
fb77c505254b6e9c925e23e734463e87574f8f40kesserrno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool do_update = false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_master_domain_get_info(tmp_ctx, sysdb, ¤t_info);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive msg->dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
fb77c505254b6e9c925e23e734463e87574f8f40kess strcmp(current_info->realm, domain_info->realm) != 0) ) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd strcmp(current_info->flat_name, domain_info->flat_name) != 0) ) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_REPLACE,
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_info->id);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (do_update == false) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "[%s]: [%d][%s]!\n",
5224ff8eae5156a05f676f1dad8add2e2f2efe1dndstatic errno_t sysdb_add_subdomain_attributes(struct sysdb_ctx *sysdb,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd msg->dn = ldb_dn_new_fmt(msg, sysdb->ldb, SYSDB_DOM_BASE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_SUBDOMAIN_CLASS);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, LDB_FLAG_MOD_ADD,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_ADD,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_ADD,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_info->id);
fb77c505254b6e9c925e23e734463e87574f8f40kess DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
ed0dae472b518c553c923a86fb4322d4c50d86a6nd "[%s]: [%d][%s]!\n",
06ba4a61654b3763ad65f52283832ebf058fdf1csliveerrno_t sysdb_update_subdomains(struct sysdb_ctx *sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool in_transaction = false;
604c89126c27104f659d7a51b0113e3bd435faf8fielding /* Retrieve all subdomains that are currently in sysdb */
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = sysdb_get_subdomains(tmp_ctx, sysdb, &cur_subdomains_count,
909ce17e2bd0faef7b1c294f2307f009793fd493nd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_get_subdomains failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive keep_subdomain = talloc_zero_array(tmp_ctx, bool, cur_subdomains_count);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero_array failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_transaction_start failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Go through a list of retrieved subdomains and:
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak * - if a subdomain already exists in sysdb, mark it for preservation
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * - if the subdomain doesn't exist in sysdb, create its bare structure
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (c = 0; c < num_subdoms; c++) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele for (d = 0; d < cur_subdomains_count; d++) {
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener /* sub-domain already in cache, nothing to do */
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener DEBUG(SSSDBG_TRACE_FUNC, ("Adding sub-domain [%s].\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_domain_create failed.\n"));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sysdb_add_subdomain_attributes(sysdb, &subdoms[c]);
ed0dae472b518c553c923a86fb4322d4c50d86a6nd ("sysdb_add_subdomain_attributes failed.\n"));
da637bcae7b6e150470e701af29da5604a34a17erbowen /* Now delete all subdomains that have been in sysdb prior to
da637bcae7b6e150470e701af29da5604a34a17erbowen * refreshing the list and are not marked for preservation
da637bcae7b6e150470e701af29da5604a34a17erbowen * (i.e. they are not in the new list of subdomains)
da637bcae7b6e150470e701af29da5604a34a17erbowen for (d = 0; d < cur_subdomains_count; d++) {
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_recursive failed.\n"));
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_MINOR_FAILURE, ("Could not commit transaction\n"));
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nderrno_t sysdb_delete_domuser(struct sss_domain_info *domain,