386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose System Database - ID ranges related calls
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose Copyright (C) 2012 Sumit Bose <sbose@redhat.com>
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose This program is free software; you can redistribute it and/or modify
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose it under the terms of the GNU General Public License as published by
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose the Free Software Foundation; either version 3 of the License, or
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose (at your option) any later version.
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose This program is distributed in the hope that it will be useful,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose GNU General Public License for more details.
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose You should have received a copy of the GNU General Public License
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bosestatic errno_t find_attr_as_uint32_t(const struct ldb_message *msg,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose val = ldb_msg_find_attr_as_uint64(msg, attr_name, UINT64_MAX);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Boseerrno_t sysdb_get_ranges(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
62dbfd0596aa15ddf0d9384f426814edcf627331Simo Sorce basedn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_TMPL_RANGE_BASE);
6a8999bf933f72923a271831d85a01ef88a81f39Jakub Hrozek list = talloc_zero_array(tmp_ctx, struct range_info *, res->count + 1);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_NAME, NULL);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "The object [%s] doesn't have a name.\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[c]->dn));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_DOMAIN_ID,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose list[c]->trusted_dom_sid = talloc_strdup(list, tmp_str);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_BASE_ID,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "find_attr_as_uint32_t failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_ID_RANGE_SIZE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "find_attr_as_uint32_t failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_BASE_RID,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "find_attr_as_uint32_t failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = find_attr_as_uint32_t(res->msgs[c], SYSDB_SECONDARY_BASE_RID,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "find_attr_as_uint32_t failed.\n");
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[c], SYSDB_ID_RANGE_TYPE,
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose list[c]->range_type = talloc_strdup(list, tmp_str);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Boseerrno_t sysdb_range_create(struct sysdb_ctx *sysdb, struct range_info *range)
fbd63f8f920a2591310d601b01c7b79aa4023a95Ondrej Kos /* if both or none are set, skip */
fbd63f8f920a2591310d601b01c7b79aa4023a95Ondrej Kos if ((range->trusted_dom_sid == NULL && range->secondary_base_rid == 0) ||
fbd63f8f920a2591310d601b01c7b79aa4023a95Ondrej Kos (range->trusted_dom_sid != NULL && range->secondary_base_rid != 0)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Invalid range, skipping. Expected that "
fbd63f8f920a2591310d601b01c7b79aa4023a95Ondrej Kos "either the secondary base RID or the SID of the trusted "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "domain is set, but not both or none of them.\n");
a928f7a6bd7681db6e26cba3eb7da22d14288737Fabiano FidĂȘncio ret = sysdb_add_string(msg, SYSDB_OBJECTCLASS, SYSDB_ID_RANGE_CLASS);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (range->trusted_dom_sid == NULL && range->secondary_base_rid != 0) {
a928f7a6bd7681db6e26cba3eb7da22d14288737Fabiano FidĂȘncio ret = sysdb_add_string(msg, SYSDB_OBJECTCLASS,
49d84c926b00ba1368372cdec255bceb58d66f43Fabiano FidĂȘncio ret = sysdb_add_ulong(msg, SYSDB_SECONDARY_BASE_RID,
49d84c926b00ba1368372cdec255bceb58d66f43Fabiano FidĂȘncio (unsigned long) range->secondary_base_rid);
a928f7a6bd7681db6e26cba3eb7da22d14288737Fabiano FidĂȘncio ret = sysdb_add_string(msg, SYSDB_OBJECTCLASS,
a928f7a6bd7681db6e26cba3eb7da22d14288737Fabiano FidĂȘncio ret = sysdb_add_string(msg, SYSDB_DOMAIN_ID, range->trusted_dom_sid);
a928f7a6bd7681db6e26cba3eb7da22d14288737Fabiano FidĂȘncio ret = sysdb_add_string(msg, SYSDB_NAME, range->name);
49d84c926b00ba1368372cdec255bceb58d66f43Fabiano FidĂȘncio ret = sysdb_add_ulong(msg, SYSDB_BASE_ID, (unsigned long) range->base_id);
49d84c926b00ba1368372cdec255bceb58d66f43Fabiano FidĂȘncio ret = sysdb_add_ulong(msg, SYSDB_ID_RANGE_SIZE,
49d84c926b00ba1368372cdec255bceb58d66f43Fabiano FidĂȘncio ret = sysdb_add_ulong(msg, SYSDB_BASE_RID,
49d84c926b00ba1368372cdec255bceb58d66f43Fabiano FidĂȘncio ret = sysdb_add_ulong(msg, SYSDB_CREATE_TIME, (unsigned long)time(NULL));
a928f7a6bd7681db6e26cba3eb7da22d14288737Fabiano FidĂȘncio ret = sysdb_add_string(msg, SYSDB_ID_RANGE_TYPE, range->range_type);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Error: %d (%s)\n", ret, strerror(ret));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Boseerrno_t sysdb_update_ranges(struct sysdb_ctx *sysdb,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* Retrieve all ranges that are currently in sysdb */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sysdb_get_ranges(tmp_ctx, sysdb, &cur_range_count,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_get_ranges failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose keep_range = talloc_zero_array(tmp_ctx, bool, cur_range_count);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_transaction_start failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* Go through a list of retrieved ranges and:
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * - if a range already exists in sysdb, mark it for preservation
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * - if the range doesn't exist in sysdb, create it
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (d = 0; d < cur_range_count; d++) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (strcasecmp(ranges[c]->name, cur_ranges[d]->name) == 0) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* range already in cache, nothing to do */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Adding range [%s].\n", ranges[c]->name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_range_create failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* Now delete all ranges that have been in sysdb prior to
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * refreshing the list and are not marked for preservation
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * (i.e. they are not in the new list of ranges)
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (d = 0; d < cur_range_count; d++) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Removing range [%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_delete_entry failed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not commit transaction\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not cancel transaction\n");