sysdb_subdomains.c revision 84c611c1b7c04cc7735ab54d4e5f48284b79e6fb
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer System Database - Sub-domain related calls
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer Copyright (C) 2012 Jan Zeleny <jzeleny@redhat.com>
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian Maeder Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer This program is free software; you can redistribute it and/or modify
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski it under the terms of the GNU General Public License as published by
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski the Free Software Foundation; either version 3 of the License, or
7520452bb30b5abbd471f82352fc4c1c937e02c5Till Mossakowski (at your option) any later version.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer This program is distributed in the hope that it will be useful,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer but WITHOUT ANY WARRANTY; without even the implied warranty of
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer GNU General Public License for more details.
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer You should have received a copy of the GNU General Public License
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer along with this program. If not, see <http://www.gnu.org/licenses/>.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_get_subdomains(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
0193c86704431f83731015a77cb613d67ae4e3c2Thiemo Wiedemeyer basedn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_BASE);
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = ldb_search(sysdb->ldb, tmp_ctx, &res,
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer list = talloc_zero_array(tmp_ctx, struct subdomain_info *, res->count);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer list[i] = talloc_zero(list, struct subdomain_info);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], "cn", NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_MINOR_FAILURE, ("The object [%s] doesn't have a name\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ldb_dn_get_linearized(res->msgs[i]->dn)));
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer list[i]->name = talloc_strdup(list, tmp_str);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_SUBDOMAIN_FLAT, NULL);
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer list[i]->flat_name = talloc_strdup(list, tmp_str);
d5f9a0b274192a496eb8d2fb8ce81c33ac2f1717Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_SUBDOMAIN_ID, NULL);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer list[i]->id = talloc_strdup(list, tmp_str);
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer *subdomain_list = talloc_steal(mem_ctx, list);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_master_domain_get_info(TALLOC_CTX *mem_ctx,
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer info = talloc_zero(tmp_ctx, struct subdomain_info);
331603b37dec12e37e2e1df9634ef0f2c5c73ddfThiemo Wiedemeyer basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_BASE, attrs,
a96ea65117eaf61ed34248bdf76e4e2144288c9dThiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("Base search returned [%d] results, "
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer "expected 1.\n"));
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_FLAT,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer info->flat_name = talloc_strdup(info, tmp_str);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SUBDOMAIN_ID,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer info->flat_name = talloc_strdup(info, tmp_str);
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyererrno_t sysdb_master_domain_add_info(struct sysdb_ctx *sysdb,
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyer ret = sysdb_master_domain_get_info(tmp_ctx, sysdb, ¤t_info);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer msg->dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer strcmp(current_info->flat_name, domain_info->flat_name) != 0) ) {
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_REPLACE,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_FLAT, "%s",
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer strcmp(current_info->flat_name, domain_info->id) != 0) ) {
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_REPLACE,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_ID, "%s",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (do_update == false) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer "[%s]: [%d][%s]!\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerstatic errno_t sysdb_add_subdomain_attributes(struct sysdb_ctx *sysdb,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer msg->dn = ldb_dn_new_fmt(msg, sysdb->ldb, SYSDB_DOM_BASE,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
ddc662fdf0207eae2034d7b68ae5e2225c575207Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_OBJECTCLASS, "%s", SYSDB_SUBDOMAIN_CLASS);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_FLAT, LDB_FLAG_MOD_ADD,
97b8e548427713e0089a30fcc2df84e0f6aa7ffaCui Jian ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_FLAT, "%s",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ldb_msg_add_empty(msg, SYSDB_SUBDOMAIN_ID, LDB_FLAG_MOD_ADD,
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = ldb_msg_add_fmt(msg, SYSDB_SUBDOMAIN_ID, "%s",
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_FATAL_FAILURE, ("Failed to add subdomain attributes to "
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer "[%s]: [%d][%s]!\n",
293b25835a956ece11d20b3dc022df4e1226b16cThiemo Wiedemeyererrno_t sysdb_update_subdomains(struct sysdb_ctx *sysdb,
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer /* Retrieve all subdomains that are currently in sysdb */
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer ret = sysdb_get_subdomains(tmp_ctx, sysdb, &cur_subdomains_count,
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("sysdb_get_subdomains failed.\n"));
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer keep_subdomain = talloc_zero_array(tmp_ctx, bool, cur_subdomains_count);
545d0cd78159cade346b579d06052638b19b0f72Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero_array failed.\n"));
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("sysdb_transaction_start failed.\n"));
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer /* Go through a list of retrieved subdomains and:
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer * - if a subdomain already exists in sysdb, mark it for preservation
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer * - if the subdomain doesn't exist in sysdb, create its bare structure
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer for (d = 0; d < cur_subdomains_count; d++) {
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian if (strcasecmp(subdomains[c]->name, cur_subdomains[d]->name) == 0) {
37e30366abd83c00a5d5447b45694627fd783de8Cui Jian /* sub-domain already in cache, nothing to do */
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer DEBUG(SSSDBG_TRACE_FUNC, ("Adding sub-domain [%s].\n",
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = sysdb_domain_create(sysdb, subdomains[c]->name);
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder DEBUG(SSSDBG_OP_FAILURE, ("sysdb_domain_create failed.\n"));
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ret = sysdb_add_subdomain_attributes(sysdb, subdomains[c]);
8836fa284a241af325aa6f41234b5130b26ec4f9Thiemo Wiedemeyer ("sysdb_add_subdomain_attributes failed.\n"));
40c18e3f63c23085e5bb36ea35efe141a87df8e4Klaus Luettich /* Now delete all subdomains that have been in sysdb prior to
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder * refreshing the list and are not marked for preservation
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer * (i.e. they are not in the new list of subdomains)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer for (d = 0; d < cur_subdomains_count; d++) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_TRACE_FUNC, ("Removing sub-domain [%s].\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE,
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer ret = sysdb_delete_recursive(sysdb, dn, true);
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_recursive failed.\n"));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_MINOR_FAILURE, ("Could not commit transaction\n"));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyererrno_t sysdb_get_subdomain_context(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer new_ctx = talloc_zero(mem_ctx, struct sysdb_ctx);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (dom_info == NULL || dom_info->sysdb == NULL) { \
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, ("Invalid domain info.\n")); \
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_search_domuser_by_name(TALLOC_CTX *mem_ctx,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return sysdb_search_user_by_name(mem_ctx, domain->sysdb, name, attrs, msg);
966a6c024c828387023fccb0cd0049f78687e5dcThiemo Wiedemeyererrno_t sysdb_search_domuser_by_uid(TALLOC_CTX *mem_ctx,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return sysdb_search_user_by_uid(mem_ctx, domain->sysdb, uid, attrs, msg);
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyererrno_t sysdb_store_domuser(struct sss_domain_info *domain,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer return sysdb_store_user(domain->sysdb, name, pwd, uid, gid, gecos, homedir,
c40b7badd217089d8a256dabdf8f7d4e219ca215Thiemo Wiedemeyer shell, attrs, remove_attrs, cache_timeout, now);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_delete_domuser(struct sss_domain_info *domain,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_delete_user(domain->sysdb, name, uid);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_search_domgroup_by_name(TALLOC_CTX *mem_ctx,
da955132262baab309a50fdffe228c9efe68251dCui Jian return sysdb_search_group_by_name(mem_ctx, domain->sysdb, name, attrs, msg);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_search_domgroup_by_gid(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_search_group_by_gid(mem_ctx, domain->sysdb, gid, attrs, msg);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_store_domgroup(struct sss_domain_info *domain,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return sysdb_store_group(domain->sysdb, name, gid, attrs, cache_timeout,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyererrno_t sysdb_delete_domgroup(struct sss_domain_info *domain,