sysdb_subdomains.c revision 9ac2a33f4cdc4941fa63118dcffe8058854f33c4
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht System Database - Sub-domain related calls
da4b55f4795a4b585f513eaceb67cda10485febfChristian Maeder Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht This program is free software; you can redistribute it and/or modify
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht it under the terms of the GNU General Public License as published by
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht the Free Software Foundation; either version 3 of the License, or
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht (at your option) any later version.
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht This program is distributed in the hope that it will be useful,
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht but WITHOUT ANY WARRANTY; without even the implied warranty of
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht GNU General Public License for more details.
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht You should have received a copy of the GNU General Public License
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht along with this program. If not, see <http://www.gnu.org/licenses/>.
8600e22385bce13c5d1048f7b955f9394a5d94d6Simon Ulbrichtstruct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx,
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht const char *id,
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht "Creating [%s] as subdomain of [%s]!\n", name, parent->name);
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht dom = talloc_zero(mem_ctx, struct sss_domain_info);
94968509d2764786208bd34b59a93c7cbe3aa6dbSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht /* Sub-domains always have the same view as the parent */
5212c904eb65bed7c08f5c6e54df9618125d2939Simon Ulbricht dom->view_name = talloc_strdup(dom, parent->view_name);
21f01439b3d87ccc385d3bce73afb2d187d14d05Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy parent's view name.\n");
765f0ff34c8f2354a4e8a4fbb4467ec5e788c55fSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy domain name.\n");
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht dom->provider = talloc_strdup(dom, parent->provider);
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy provider name.\n");
e90b8ee3fac5c932d83af2061579c6b57d528885Christian Maeder dom->conn_name = talloc_strdup(dom, parent->conn_name);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy connection name.\n");
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy realm name.\n");
8600e22385bce13c5d1048f7b955f9394a5d94d6Simon Ulbricht dom->flat_name = talloc_strdup(dom, flat_name);
846ef0914b29a4806ca0444c116fd3cf267c4fb7Christian Maeder DEBUG(SSSDBG_OP_FAILURE, "Failed to copy flat name.\n");
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy id.\n");
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Failed to copy forest.\n");
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht /* If the parent domain filters out group members, the subdomain should
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht * as well if configured */
8600e22385bce13c5d1048f7b955f9394a5d94d6Simon Ulbricht inherit_option = string_in_list(CONFDB_DOMAIN_IGNORE_GROUP_MEMBERS,
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht dom->ignore_group_members = parent->ignore_group_members;
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht /* If the parent domain explicitly limits ID ranges, the subdomain
1c258a97f602cf389ed2aed3924108889dbef512Simon Ulbricht * should honour the limits as well.
403c7e517cea70c01c7dd15695867fe4f8820ab4Simon Ulbricht dom->id_min = parent->id_min ? parent->id_min : 0;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht dom->id_max = parent->id_max ? parent->id_max : 0xffffffff;
5b93337fb97e848522fcc277e384f694595bc42cSimon Ulbricht dom->pwd_expiration_warning = parent->pwd_expiration_warning;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht dom->cache_credentials = parent->cache_credentials;
5ea7ec7c1a5dead365687d6b0270837522c0e6feSimon Ulbricht dom->netgroup_timeout = parent->netgroup_timeout;
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht dom->service_timeout = parent->service_timeout;
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht dom->override_homedir = parent->override_homedir;
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht dom->fallback_homedir = parent->fallback_homedir;
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht dom->subdomain_homedir = parent->subdomain_homedir;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht dom->override_shell = parent->override_shell;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht dom->homedir_substr = parent->homedir_substr;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_OP_FAILURE, "Missing sysdb context in parent domain.\n");
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbrichtstatic bool is_forest_root(struct sss_domain_info *d)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* IPA subdomain provider saves/saved trusted forest root domains
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht * without the forest attribute. Those are automatically forest
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht if (d->realm && (strcasecmp(d->forest, d->realm) == 0)) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht return false;
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbrichtstatic bool is_same_forest(struct sss_domain_info *root,
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht && strcasecmp(member->forest, root->realm) == 0) {
04641e4ea004e422b32d3e6359f68a3326b4aa8bSimon Ulbricht return false;
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbrichtstatic void link_forest_roots(struct sss_domain_info *domain)
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht for (d = domain; d; d = get_next_domain(d, true)) {
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht for (d = domain; d; d = get_next_domain(d, true)) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht if (is_forest_root(d) == true) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht DEBUG(SSSDBG_TRACE_INTERNAL, "[%s] is a forest root\n", d->name);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht for (dd = domain; dd; dd = get_next_domain(dd, true)) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht "[%s] is a forest root of [%s]\n",
55be4caff6a01e4c32ec47ee27fe00b67dfd3db5Simon Ulbrichterrno_t sysdb_update_subdomains(struct sss_domain_info *domain)
4d1df661384f74cd15d2ceba8a9a3c4760e9ddfbSimon Ulbricht const char *id;
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht basedn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, SYSDB_BASE);
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
96a17035df49356b70d7ac14bd9f4d52a5f0308dSimon Ulbricht attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* disable all domains,
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht * let the search result refresh any that are still valid */
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht for (dom = domain->subdomains; dom; dom = get_next_domain(dom, false)) {
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht name = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht "The object [%s] doesn't have a name\n",
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht realm = ldb_msg_find_attr_as_string(res->msgs[i],
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht flat = ldb_msg_find_attr_as_string(res->msgs[i],
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht id = ldb_msg_find_attr_as_string(res->msgs[i],
67c57fe89afed0947d5ff8fc8b04c4ace0b9595eSimon Ulbricht mpg = ldb_msg_find_attr_as_bool(res->msgs[i],
67c57fe89afed0947d5ff8fc8b04c4ace0b9595eSimon Ulbricht enumerate = ldb_msg_find_attr_as_bool(res->msgs[i],
4bf72807172000becf65e11bd225efc1dfd99713Simon Ulbricht forest = ldb_msg_find_attr_as_string(res->msgs[i],
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht trust_direction = ldb_msg_find_attr_as_int(res->msgs[i],
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht /* explicitly use dom->next as we need to check 'disabled' domains */
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht for (dom = domain->subdomains; dom; dom = dom->next) {
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht /* in theory these may change, but it should never happen */
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht "Realm name changed from [%s] to [%s]!\n",
da4b55f4795a4b585f513eaceb67cda10485febfChristian Maeder if (strcasecmp(dom->flat_name, flat) != 0) {
e4d1479434761dc3eb8d17b6c75de4eb24866f0bSimon Ulbricht "Flat name changed from [%s] to [%s]!\n",
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht "Domain changed from [%s] to [%s]!\n",
8fa27254f463e2c958a10dc513450b992f80137bSimon Ulbricht "MPG state change from [%s] to [%s]!\n",
fe6a19b07759bc4190e88dda76a211d86bf32062Simon Ulbricht "enumerate state change from [%s] to [%s]!\n",
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht "Forest changed from [%s] to [%s]!\n",
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht if (!dom->has_views && dom->view_name == NULL) {
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht /* maybe views are not initialized, copy from parent */
7577ca4229962db6f297853d160c2e0214bd2034Simon Ulbricht "Failed to copy parent's view name.\n");
c3b1c9fa0aa53167405eb9a004137fb5e327fd4fSimon Ulbricht "Sub-domain [%s][%s] and parent [%s][%s] " \
c3b1c9fa0aa53167405eb9a004137fb5e327fd4fSimon Ulbricht "views are different.\n",
689c36560d1509e6f040c096b719a31b31d2d84cSimon Ulbricht dom->parent->has_views ? "has view" : "has no view",
goto done;
done:
return ret;
const char *tmp_str;
NULL};
return ENOMEM;
goto done;
goto done;
goto done;
goto done;
NULL);
goto done;
NULL);
goto done;
NULL);
goto done;
NULL);
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
const char *realm,
const char *flat,
const char *id,
const char* forest)
int ret;
bool do_update = false;
return ENOMEM;
goto done;
goto done;
goto done;
goto done;
do_update = true;
goto done;
goto done;
do_update = true;
goto done;
goto done;
do_update = true;
goto done;
goto done;
do_update = true;
if (do_update == false) {
goto done;
goto done;
goto done;
done:
return ret;
NULL};
const char *tmp_str;
bool tmp_bool;
bool store = false;
int realm_flags = 0;
int flat_flags = 0;
int id_flags = 0;
int mpg_flags = 0;
int enum_flags = 0;
int forest_flags = 0;
int td_flags = 0;
int ret;
return ENOMEM;
goto done;
goto done;
if (ret) {
goto done;
store = true;
goto done;
if (realm) {
if (flat_name) {
if (domain_id) {
!mpg);
!enumerate);
if (forest) {
&& td_flags == 0) {
goto done;
goto done;
if (store) {
goto done;
goto done;
if (realm_flags) {
goto done;
goto done;
if (flat_flags) {
goto done;
goto done;
if (id_flags) {
goto done;
goto done;
if (mpg_flags) {
goto done;
goto done;
if (enum_flags) {
goto done;
goto done;
if (forest_flags) {
NULL);
goto done;
goto done;
if (td_flags) {
goto done;
goto done;
goto done;
done:
return ret;
int ret;
goto done;
goto done;
goto done;
done:
return ret;