sysdb_ranges.c revision fbd63f8f920a2591310d601b01c7b79aa4023a95
acc039dfc0b0f4588cf2feec04727b61e1c672a1Timo Sirainen System Database - ID ranges related calls
28b8434ca4cba2e310d13ffc55e895d658725f43Timo Sirainen Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
06af65f82453bb976cf8aa6fe2507e3a6253a04fTimo Sirainen This program is free software; you can redistribute it and/or modify
4909421ac41e143fe07a235c0d11e9f0452d716bTimo Sirainen it under the terms of the GNU General Public License as published by
e5d7056b6ef069e228f8ad3c9467662955cab3c6Timo Sirainen the Free Software Foundation; either version 3 of the License, or
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen (at your option) any later version.
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen This program is distributed in the hope that it will be useful,
4909421ac41e143fe07a235c0d11e9f0452d716bTimo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
885a3c2287ae3e5827aa580ea06b231de38abb47Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen GNU General Public License for more details.
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen You should have received a copy of the GNU General Public License
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
8aa6fe58b1832da498b49de4383f9f1ef458945dTimo Sirainenstatic errno_t find_attr_as_uint32_t(const struct ldb_message *msg,
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen val = ldb_msg_find_attr_as_uint64(msg, attr_name, UINT64_MAX);
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainenerrno_t sysdb_get_ranges(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen basedn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_TMPL_RANGE_BASE);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen attrs, "objectclass=%s", SYSDB_ID_RANGE_CLASS);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen list = talloc_zero_array(tmp_ctx, struct range_info *, res->count + 1);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen list[c] = talloc_zero(list, struct range_info);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_NAME, NULL);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen DEBUG(SSSDBG_MINOR_FAILURE, ("The object [%s] doesn't have a name.\n",
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_DOMAIN_ID,
767431e5084a037c4dbefdf30ebfa03c84b1f449Timo Sirainen list[c]->trusted_dom_sid = talloc_strdup(list, tmp_str);
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_BASE_ID,
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen DEBUG(SSSDBG_MINOR_FAILURE, ("find_attr_as_uint32_t failed.\n"));
bd417d416988d11a6b555b9aa57779e7ed976951Timo Sirainen ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_ID_RANGE_SIZE,
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen DEBUG(SSSDBG_MINOR_FAILURE, ("find_attr_as_uint32_t failed.\n"));
767431e5084a037c4dbefdf30ebfa03c84b1f449Timo Sirainen ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_BASE_RID,
767431e5084a037c4dbefdf30ebfa03c84b1f449Timo Sirainen DEBUG(SSSDBG_MINOR_FAILURE, ("find_attr_as_uint32_t failed.\n"));
9f3bb0e10835efb0c9b1eb9e09e16b614ec41b97Timo Sirainen ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_SECONDARY_BASE_RID,
acc039dfc0b0f4588cf2feec04727b61e1c672a1Timo Sirainen DEBUG(SSSDBG_MINOR_FAILURE, ("find_attr_as_uint32_t failed.\n"));
28b8434ca4cba2e310d13ffc55e895d658725f43Timo Sirainenerrno_t sysdb_range_create(struct sysdb_ctx *sysdb, struct range_info *range)
bde78a7bf5f9000f1ae4dc7ce6cabd012e1f8b79Pascal Volk /* if both or none are set, skip */
acc039dfc0b0f4588cf2feec04727b61e1c672a1Timo Sirainen if ((range->trusted_dom_sid == NULL && range->secondary_base_rid == 0) ||
acc039dfc0b0f4588cf2feec04727b61e1c672a1Timo Sirainen (range->trusted_dom_sid != NULL && range->secondary_base_rid != 0)) {
a3a55999bcfe2e57941cb64343f4ea80beabdab7Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, ("Invalid range, skipping. Expected that "
06af65f82453bb976cf8aa6fe2507e3a6253a04fTimo Sirainen "either the secondary base RID or the SID of the trusted "
06af65f82453bb976cf8aa6fe2507e3a6253a04fTimo Sirainen "domain is set, but not both or none of them.\n"));
f2a1955d993f67982bc40ad7bbae9a036dabfd64Timo Sirainen ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_OBJECTCLASS,
f2a1955d993f67982bc40ad7bbae9a036dabfd64Timo Sirainen if (range->trusted_dom_sid == NULL && range->secondary_base_rid != 0) {
f2a1955d993f67982bc40ad7bbae9a036dabfd64Timo Sirainen ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_OBJECTCLASS,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_SECONDARY_BASE_RID,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_OBJECTCLASS,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_DOMAIN_ID,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_NAME, range->name);
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_BASE_ID,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_ID_RANGE_SIZE,
acc039dfc0b0f4588cf2feec04727b61e1c672a1Timo Sirainen ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_BASE_RID,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CREATE_TIME,
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainen DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
542a32ee5f4ca72626ec93b6313f909811c01534Timo Sirainenerrno_t sysdb_update_ranges(struct sysdb_ctx *sysdb,
968b2f633b7405bc2cf0596d04762994ceb279d0Timo Sirainen /* Retrieve all ranges that are currently in sysdb */
968b2f633b7405bc2cf0596d04762994ceb279d0Timo Sirainen ret = sysdb_get_ranges(tmp_ctx, sysdb, &cur_range_count,
968b2f633b7405bc2cf0596d04762994ceb279d0Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, ("sysdb_get_ranges failed.\n"));
968b2f633b7405bc2cf0596d04762994ceb279d0Timo Sirainen keep_range = talloc_zero_array(tmp_ctx, bool, cur_range_count);
968b2f633b7405bc2cf0596d04762994ceb279d0Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero_array failed.\n"));
968b2f633b7405bc2cf0596d04762994ceb279d0Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, ("sysdb_transaction_start failed.\n"));
2e533fb1283b5f06a4063b519e47f1861c910386Timo Sirainen /* Go through a list of retrieved ranges and:
d5ef38077adbff5b3e4d0b3c94a2057581dc78b6Timo Sirainen * - if a range already exists in sysdb, mark it for preservation
d5ef38077adbff5b3e4d0b3c94a2057581dc78b6Timo Sirainen * - if the range doesn't exist in sysdb, create it
ff3337516aad9843599905aeeb29812ea67c09d1Timo Sirainen for (d = 0; d < cur_range_count; d++) {
ff3337516aad9843599905aeeb29812ea67c09d1Timo Sirainen if (strcasecmp(ranges[c]->name, cur_ranges[d]->name) == 0) {
a3a55999bcfe2e57941cb64343f4ea80beabdab7Timo Sirainen /* range already in cache, nothing to do */
ff3337516aad9843599905aeeb29812ea67c09d1Timo Sirainen DEBUG(SSSDBG_TRACE_FUNC, ("Adding range [%s].\n", ranges[c]->name));
75d9024d9409f4710e51dbe40ffb338a84bb1446Timo Sirainen DEBUG(SSSDBG_OP_FAILURE, ("sysdb_range_create failed.\n"));
ff3337516aad9843599905aeeb29812ea67c09d1Timo Sirainen /* Now delete all ranges that have been in sysdb prior to
ff3337516aad9843599905aeeb29812ea67c09d1Timo Sirainen * refreshing the list and are not marked for preservation
a6ab8f00351265e35b79f3a22b1f5a4978ae5c35Timo Sirainen * (i.e. they are not in the new list of ranges)
a672f99363d5f37060c1331d00d2ee3c4626310fTimo Sirainen for (d = 0; d < cur_range_count; d++) {
a672f99363d5f37060c1331d00d2ee3c4626310fTimo Sirainen DEBUG(SSSDBG_TRACE_FUNC, ("Removing range [%s].\n",
a672f99363d5f37060c1331d00d2ee3c4626310fTimo Sirainen DEBUG(SSSDBG_OP_FAILURE, ("sysdb_delete_entry failed.\n"));
72c47a26f4ded49d4827dc64818b34bbc9606fc4Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Could not commit transaction\n"));
5296198635718c9bf5b2f972c9d5be52092d3d58Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Could not cancel transaction\n"));