sysdb_subdomains.c revision 99c0cfdc5f065ba38f1ee91701d1d27f9e4fdb96
97a9a944b5887e91042b019776c41d5dd74557aferikabele/*
97a9a944b5887e91042b019776c41d5dd74557aferikabele SSSD
97a9a944b5887e91042b019776c41d5dd74557aferikabele
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive System Database - Sub-domain related calls
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
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
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
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/>.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd*/
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#include "util/util.h"
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include "db/sysdb_private.h"
4aa805f8500255bc52a4c03259fe46df10a1d07cyoshiki
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowenerrno_t sysdb_get_subdomains(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
dfb59c684345700bf9186b8d44936f8b1ba082ffgryzor size_t *subdomain_count,
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi struct sysdb_subdom ***subdomain_list)
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi{
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd int i;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno_t ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TALLOC_CTX *tmp_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_result *res;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *attrs[] = {"cn",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd SYSDB_SUBDOMAIN_REALM,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd SYSDB_SUBDOMAIN_FLAT,
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna SYSDB_SUBDOMAIN_ID,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd NULL};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sysdb_subdom **list;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct ldb_dn *basedn;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd const char *tmp_str;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
bed3c2e56e8f3328e780200466b9d009093db468sf tmp_ctx = talloc_new(NULL);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (tmp_ctx == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
9597f440430d8c876dd64f5f78066804650a18ecnoodl }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd basedn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_BASE);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (basedn == NULL) {
8559a67073808d84d85bb5dd552d4247caafe709sf ret = EIO;
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = ldb_search(sysdb->ldb, tmp_ctx, &res,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick basedn, LDB_SCOPE_ONELEVEL,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (ret != LDB_SUCCESS) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = EIO;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd list = talloc_zero_array(tmp_ctx, struct sysdb_subdom *, res->count + 1);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (list == NULL) {
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd for (i = 0; i < res->count; i++) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd list[i] = talloc_zero(list, struct sysdb_subdom);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (list[i] == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (tmp_str == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd DEBUG(SSSDBG_MINOR_FAILURE,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ("The object [%s] doesn't have a name\n",
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ldb_dn_get_linearized(res->msgs[i]->dn)));
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = EINVAL;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd list[i]->name = talloc_strdup(list, tmp_str);
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim if (list[i]->name == NULL) {
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim ret = ENOMEM;
6beba165aeced2ca77a6f1593ee08c47a32099efcovener goto done;
709e3a21ba73b8433462959cd56c773454b34441trawick }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd tmp_str = ldb_msg_find_attr_as_string(res->msgs[i],
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen SYSDB_SUBDOMAIN_REALM, NULL);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (tmp_str != NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd list[i]->realm = talloc_strdup(list, tmp_str);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (list[i]->realm == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = ENOMEM;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd tmp_str = ldb_msg_find_attr_as_string(res->msgs[i],
117c1f888a14e73cdd821dc6c23eb0411144a41cnd SYSDB_SUBDOMAIN_FLAT, NULL);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (tmp_str != NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd list[i]->flat_name = talloc_strdup(list, tmp_str);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (list[i]->flat_name == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd goto done;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
b00fe3c3354db01001b8eddfd9b88441380f837dwrowe }
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
117c1f888a14e73cdd821dc6c23eb0411144a41cnd tmp_str = ldb_msg_find_attr_as_string(res->msgs[i],
a38b5f73e7f0f3b8726fb47d27b145f37036ead0jim SYSDB_SUBDOMAIN_ID, NULL);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (tmp_str != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd list[i]->id = talloc_strdup(list, tmp_str);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (list[i]->id == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna list[res->count] = NULL;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna *subdomain_count = res->count;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen *subdomain_list = talloc_steal(mem_ctx, list);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen ret = EOK;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowendone:
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen talloc_free(tmp_ctx);
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen return ret;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen}
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen
031bbbc0d1189b07330e38d0c126820a9ab7795egryzorerrno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe struct sysdb_ctx *sysdb,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe struct sysdb_subdom **_info)
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe{
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor errno_t ret;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe TALLOC_CTX *tmp_ctx;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe const char *tmp_str;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe struct ldb_dn *basedn;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct sysdb_subdom *info;
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener struct ldb_result *res;
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener const char *attrs[] = {"cn",
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener SYSDB_SUBDOMAIN_REALM,
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener SYSDB_SUBDOMAIN_FLAT,
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener SYSDB_SUBDOMAIN_ID,
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener NULL};
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna tmp_ctx = talloc_new(NULL);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (tmp_ctx == NULL) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna return ENOMEM;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna info = talloc_zero(tmp_ctx, struct sysdb_subdom);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (info == NULL) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = ENOMEM;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna sysdb->domain->name);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (basedn == NULL) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = EIO;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_BASE, attrs,
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna NULL);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != LDB_SUCCESS) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = EIO;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna goto done;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (res->count == 0) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = ENOENT;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (res->count > 1) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, "
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe "expected 1.\n", res->count));
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = EINVAL;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_REALM,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe NULL);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (tmp_str != NULL) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe info->realm = talloc_strdup(info, tmp_str);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (info->realm == NULL) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe ret = ENOMEM;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe goto done;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor NULL);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (tmp_str != NULL) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna info->flat_name = talloc_strdup(info, tmp_str);
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen if (info->flat_name == NULL) {
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen ret = ENOMEM;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen goto done;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (tmp_str != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd info->id = talloc_strdup(info, tmp_str);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (info->id == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *_info = talloc_steal(mem_ctx, info);
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedone:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(tmp_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kesserrno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb,
fb77c505254b6e9c925e23e734463e87574f8f40kess struct sysdb_subdom *domain_info)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TALLOC_CTX *tmp_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_message *msg;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool do_update = false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_subdom *current_info;
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tmp_ctx = talloc_new(NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (tmp_ctx == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_master_domain_get_info(tmp_ctx, sysdb, &current_info);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess msg = ldb_msg_new(tmp_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (msg == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive msg->dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
fb77c505254b6e9c925e23e734463e87574f8f40kess sysdb->domain->name);
bc4b55ec8f31569d606d5680d50189a355bcd7a6rbowen if (msg->dn == NULL) {
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = EIO;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (domain_info->realm != NULL &&
fb77c505254b6e9c925e23e734463e87574f8f40kess (current_info->realm == NULL ||
fb77c505254b6e9c925e23e734463e87574f8f40kess strcmp(current_info->realm, domain_info->realm) != 0) ) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM,
fb77c505254b6e9c925e23e734463e87574f8f40kess LDB_FLAG_MOD_REPLACE, NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != LDB_SUCCESS) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_error_to_errno(ret);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM,
130d299c4b2b15be45532a176604c71fdc7bea5bnd domain_info->realm);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != LDB_SUCCESS) {
ef8e89e090461194ecadd31e8796a2c51e0531a2kess ret = sysdb_error_to_errno(ret);
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd do_update = true;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (domain_info->flat_name != NULL &&
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (current_info->flat_name == NULL ||
fe64b2ba25510d8c9dba5560a2d537763566cf40nd strcmp(current_info->flat_name, domain_info->flat_name) != 0) ) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd LDB_FLAG_MOD_REPLACE, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_error_to_errno(ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT,
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive domain_info->flat_name);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive if (ret != LDB_SUCCESS) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ret = sysdb_error_to_errno(ret);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd do_update = true;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (domain_info->id != NULL &&
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (current_info->id == NULL ||
06ba4a61654b3763ad65f52283832ebf058fdf1cslive strcmp(current_info->id, domain_info->id) != 0) ) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_REPLACE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive NULL);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != LDB_SUCCESS) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = sysdb_error_to_errno(ret);
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_info->id);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != LDB_SUCCESS) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = sysdb_error_to_errno(ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd do_update = true;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (do_update == false) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = ldb_modify(sysdb->ldb, msg);
627c978514c54179736d152923478be7c8707f9bnd if (ret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "[%s]: [%d][%s]!\n",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain_info->name, ret,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ldb_errstring(sysdb->ldb)));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_error_to_errno(ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = EOK;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
888b616027180cc8aaa4d2bee5ecc6acec175bc5nddone:
b95ae799514ad86a15610ad75808d7065e9847c9kess talloc_free(tmp_ctx);
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd return ret;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd}
5224ff8eae5156a05f676f1dad8add2e2f2efe1dndstatic errno_t sysdb_add_subdomain_attributes(struct sysdb_ctx *sysdb,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd struct sysdb_subdom *domain_info)
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd{
604c89126c27104f659d7a51b0113e3bd435faf8fielding TALLOC_CTX *tmp_ctx;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd struct ldb_message *msg;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tmp_ctx = talloc_new(NULL);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (tmp_ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd msg = ldb_msg_new(tmp_ctx);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (msg == NULL) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = ENOMEM;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd msg->dn = ldb_dn_new_fmt(msg, sysdb->ldb, SYSDB_DOM_BASE,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd domain_info->name);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (msg->dn == NULL) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = ENOMEM;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd goto done;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_error_to_errno(ret);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd goto done;
9583adab6bc4b3758e41963c905d9dad9f067131nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_SUBDOMAIN_CLASS);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (ret != LDB_SUCCESS) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_error_to_errno(ret);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd goto done;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (domain_info->realm != NULL) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_REALM, LDB_FLAG_MOD_ADD,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd NULL);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (ret != LDB_SUCCESS) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_error_to_errno(ret);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier goto done;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_REALM,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier domain_info->realm);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (ret != LDB_SUCCESS) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = sysdb_error_to_errno(ret);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier goto done;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (domain_info->flat_name != NULL) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_ADD,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd NULL);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (ret != LDB_SUCCESS) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier ret = sysdb_error_to_errno(ret);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier goto done;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_FLAT,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd domain_info->flat_name);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (ret != LDB_SUCCESS) {
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_error_to_errno(ret);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd goto done;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (domain_info->id != NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_ADD,
627c978514c54179736d152923478be7c8707f9bnd NULL);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != LDB_SUCCESS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_error_to_errno(ret);
6f7c18e70781deff3d1129774221de81b43c828end goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ldb_msg_add_string(msg, SYSDB_SUBDOMAIN_ID, domain_info->id);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != LDB_SUCCESS) {
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sysdb_error_to_errno(ret);
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = ldb_modify(sysdb->ldb, msg);
10673857794a4b3d9568ca2d983722a87ed352f1rbowen if (ret != LDB_SUCCESS) {
fb77c505254b6e9c925e23e734463e87574f8f40kess DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
ed0dae472b518c553c923a86fb4322d4c50d86a6nd "[%s]: [%d][%s]!\n",
ed0dae472b518c553c923a86fb4322d4c50d86a6nd domain_info->name, ret,
10673857794a4b3d9568ca2d983722a87ed352f1rbowen ldb_errstring(sysdb->ldb)));
10673857794a4b3d9568ca2d983722a87ed352f1rbowen ret = sysdb_error_to_errno(ret);
bed3c2e56e8f3328e780200466b9d009093db468sf goto done;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf ret = EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedone:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(tmp_ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveerrno_t sysdb_update_subdomains(struct sysdb_ctx *sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int num_subdoms,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_subdom *subdoms)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int sret;
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz size_t c;
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz size_t d;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end TALLOC_CTX *tmp_ctx = NULL;
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl size_t cur_subdomains_count;
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl struct sysdb_subdom **cur_subdomains;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_dn *dn;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool in_transaction = false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive bool *keep_subdomain;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
604c89126c27104f659d7a51b0113e3bd435faf8fielding tmp_ctx = talloc_new(NULL);
604c89126c27104f659d7a51b0113e3bd435faf8fielding if (tmp_ctx == NULL) {
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = ENOMEM;
604c89126c27104f659d7a51b0113e3bd435faf8fielding goto done;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding /* Retrieve all subdomains that are currently in sysdb */
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = sysdb_get_subdomains(tmp_ctx, sysdb, &cur_subdomains_count,
604c89126c27104f659d7a51b0113e3bd435faf8fielding &cur_subdomains);
909ce17e2bd0faef7b1c294f2307f009793fd493nd if (ret != EOK) {
909ce17e2bd0faef7b1c294f2307f009793fd493nd DEBUG(SSSDBG_OP_FAILURE, ("sysdb_get_subdomains failed.\n"));
909ce17e2bd0faef7b1c294f2307f009793fd493nd goto done;
909ce17e2bd0faef7b1c294f2307f009793fd493nd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive keep_subdomain = talloc_zero_array(tmp_ctx, bool, cur_subdomains_count);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (keep_subdomain == NULL) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero_array failed.\n"));
97a9a944b5887e91042b019776c41d5dd74557aferikabele goto done;
97a9a944b5887e91042b019776c41d5dd74557aferikabele }
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele ret = sysdb_transaction_start(sysdb);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_transaction_start failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive in_transaction = true;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end
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 */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (c = 0; c < num_subdoms; c++) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele for (d = 0; d < cur_subdomains_count; d++) {
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak if (strcasecmp(subdoms[c].name,
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak cur_subdomains[d]->name) == 0) {
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener keep_subdomain[d] = true;
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener /* sub-domain already in cache, nothing to do */
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener break;
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim }
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener }
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener if (d == cur_subdomains_count) {
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener DEBUG(SSSDBG_TRACE_FUNC, ("Adding sub-domain [%s].\n",
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener subdoms[c].name));
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener ret = sysdb_domain_create(sysdb, subdoms[c].name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_OP_FAILURE, ("sysdb_domain_create failed.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sysdb_add_subdomain_attributes(sysdb, &subdoms[c]);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_OP_FAILURE,
ed0dae472b518c553c923a86fb4322d4c50d86a6nd ("sysdb_add_subdomain_attributes failed.\n"));
ed0dae472b518c553c923a86fb4322d4c50d86a6nd goto done;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd }
ed0dae472b518c553c923a86fb4322d4c50d86a6nd }
da637bcae7b6e150470e701af29da5604a34a17erbowen }
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
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 */
da637bcae7b6e150470e701af29da5604a34a17erbowen for (d = 0; d < cur_subdomains_count; d++) {
da637bcae7b6e150470e701af29da5604a34a17erbowen if (!keep_subdomain[d]) {
7802d43d20007fa575e43b6ae77d5177ceffdb71sf DEBUG(SSSDBG_TRACE_FUNC, ("Removing sub-domain [%s].\n",
7802d43d20007fa575e43b6ae77d5177ceffdb71sf cur_subdomains[d]->name));
7802d43d20007fa575e43b6ae77d5177ceffdb71sf dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
7802d43d20007fa575e43b6ae77d5177ceffdb71sf cur_subdomains[d]->name);
7802d43d20007fa575e43b6ae77d5177ceffdb71sf if (dn == NULL) {
7802d43d20007fa575e43b6ae77d5177ceffdb71sf ret = ENOMEM;
7802d43d20007fa575e43b6ae77d5177ceffdb71sf goto done;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf ret = sysdb_delete_recursive(sysdb, dn, true);
bed3c2e56e8f3328e780200466b9d009093db468sf if (ret != EOK) {
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_recursive failed.\n"));
bed3c2e56e8f3328e780200466b9d009093db468sf goto done;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf ret = sysdb_transaction_commit(sysdb);
bed3c2e56e8f3328e780200466b9d009093db468sf if (ret != EOK) {
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_MINOR_FAILURE, ("Could not commit transaction\n"));
bed3c2e56e8f3328e780200466b9d009093db468sf goto done;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf in_transaction = false;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sfdone:
bed3c2e56e8f3328e780200466b9d009093db468sf if (in_transaction) {
bed3c2e56e8f3328e780200466b9d009093db468sf sret = sysdb_transaction_cancel(sysdb);
bed3c2e56e8f3328e780200466b9d009093db468sf if (sret != EOK) {
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(tmp_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf return ret;
bed3c2e56e8f3328e780200466b9d009093db468sf}
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sferrno_t sysdb_get_subdomain_context(TALLOC_CTX *mem_ctx,
bed3c2e56e8f3328e780200466b9d009093db468sf struct sysdb_ctx *sysdb,
bed3c2e56e8f3328e780200466b9d009093db468sf struct sss_domain_info *subdomain,
bed3c2e56e8f3328e780200466b9d009093db468sf struct sysdb_ctx **subdomain_ctx)
bed3c2e56e8f3328e780200466b9d009093db468sf{
bed3c2e56e8f3328e780200466b9d009093db468sf struct sysdb_ctx *new_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf new_ctx = talloc_zero(mem_ctx, struct sysdb_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf if (new_ctx == NULL) {
bed3c2e56e8f3328e780200466b9d009093db468sf return ENOMEM;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf new_ctx->domain = subdomain;
bed3c2e56e8f3328e780200466b9d009093db468sf new_ctx->mpg = true;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf new_ctx->ldb = sysdb->ldb;
bed3c2e56e8f3328e780200466b9d009093db468sf new_ctx->ldb_file = sysdb->ldb_file;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf *subdomain_ctx = new_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf return EOK;
bed3c2e56e8f3328e780200466b9d009093db468sf}
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf#define CHECK_DOMAIN_INFO(dom_info) do { \
bed3c2e56e8f3328e780200466b9d009093db468sf if (dom_info == NULL || dom_info->sysdb == NULL) { \
bed3c2e56e8f3328e780200466b9d009093db468sf DEBUG(SSSDBG_OP_FAILURE, ("Invalid domain info.\n")); \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EINVAL; \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } \
fe64b2ba25510d8c9dba5560a2d537763566cf40nd} while(0)
bed3c2e56e8f3328e780200466b9d009093db468sf
fe64b2ba25510d8c9dba5560a2d537763566cf40nderrno_t sysdb_delete_domuser(struct sss_domain_info *domain,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *name, uid_t uid)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CHECK_DOMAIN_INFO(domain);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return sysdb_delete_user(domain->sysdb, name, uid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nderrno_t sysdb_delete_domgroup(struct sss_domain_info *domain,
fb77c505254b6e9c925e23e734463e87574f8f40kess const char *name, gid_t gid)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CHECK_DOMAIN_INFO(domain);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return sysdb_delete_group(domain->sysdb, name, gid);
c985aca104389df30d6ec0a637ce0ccaac904362nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd