8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose Sumit Bose <sbose@redhat.com>
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose Copyright (C) 2013 Red Hat
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose This program is free software; you can redistribute it and/or modify
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose it under the terms of the GNU General Public License as published by
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose the Free Software Foundation; either version 3 of the License, or
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose (at your option) any later version.
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose This program is distributed in the hope that it will be useful,
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose GNU General Public License for more details.
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose You should have received a copy of the GNU General Public License
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bosestatic errno_t ipa_idmap_check_posix_child(struct sdap_idmap_ctx *idmap_ctx,
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose err = sss_idmap_domain_has_algorithmic_mapping(idmap_ctx->map, dom_sid_str,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Idmap of domain [%s] already known, nothing to do.\n",
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose err = sss_idmap_domain_by_name_has_algorithmic_mapping(idmap_ctx->map,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Idmap of domain [%s] already known, nothing to do.\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "Trying to add idmap for domain [%s].\n",
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose if (err != IDMAP_SID_UNKNOWN && err != IDMAP_NAME_UNKNOWN) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "sss_idmap_domain_has_algorithmic_mapping failed.\n");
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(idmap_ctx->id_ctx->be->domain, dom_sid_str);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl "find_domain_by_sid failed with SID [%s].\n", dom_sid_str);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No forest available for domain [%s].\n",
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl forest_root = find_domain_by_name(idmap_ctx->id_ctx->be->domain,
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl "find_domain_by_name failed to find forest root [%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Forest root [%s] does not have a SID.\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose for (c = 0; c < range_count; c++) {
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose && strcmp(r->trusted_dom_sid, forest_root->domain_id) == 0) {
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose || strcmp(r->range_type, IPA_RANGE_AD_TRUST_POSIX) != 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Forest root does not have range type [%s].\n",
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose range_id = talloc_asprintf(tmp_ctx, "%s-%s", dom_sid_str, r->name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx->map, dom_name, dom_sid_str,
dc0ae0f9f516d947b1f3369235f50284e6c0540fSumit Bose if (err != IDMAP_SUCCESS && err != IDMAP_COLLISION) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not add range [%s] to ID map\n", range_id);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No idrange found for forest root [%s].\n",
f69f3581658351003a6d9245045e41d0efb85022Sumit Boseerrno_t get_idmap_data_from_range(struct range_info *r, char *domain_name,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* Older IPA servers might not have the range_type attribute, but
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose * only support local ranges and trusts with algorithmic mapping. */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose if (r->trusted_dom_sid == NULL && r->secondary_base_rid != 0) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* local IPA domain */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* trusted domain */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "Cannot determine range type, " \
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose "for id range [%s].\n",
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose if (strcmp(r->range_type, IPA_RANGE_LOCAL) == 0) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose } else if (strcmp(r->range_type, IPA_RANGE_AD_TRUST_POSIX) == 0) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose } else if (strcmp(r->range_type, IPA_RANGE_AD_TRUST) == 0) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "Range type [%s] of id range " \
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose "[%s] not supported.\n", \
f69f3581658351003a6d9245045e41d0efb85022Sumit Boseerrno_t ipa_idmap_get_ranges_from_sysdb(struct sdap_idmap_ctx *idmap_ctx,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose ret = sysdb_get_ranges(tmp_ctx, idmap_ctx->id_ctx->be->domain->sysdb,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_get_ranges failed.\n");
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose for (c = 0; c < range_count; c++) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_idmap_data_from_range failed for " \
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose "id range [%s], skipping.\n",
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose err = sss_idmap_add_domain_ex(idmap_ctx->map, name, sid, &range,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose if (!allow_collisions || err != IDMAP_COLLISION) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Could not add range [%s] to ID map\n",
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = ipa_idmap_check_posix_child(idmap_ctx, dom_name, dom_sid_str,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_idmap_check_posix_child failed.\n");
f69f3581658351003a6d9245045e41d0efb85022Sumit Boseerrno_t ipa_idmap_find_new_domain(struct sdap_idmap_ctx *idmap_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose return ipa_idmap_get_ranges_from_sysdb(idmap_ctx, dom_name, dom_sid_str,
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose idmap_ctx = talloc_zero(tmp_ctx, struct sdap_idmap_ctx);
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose idmap_ctx->find_new_domain = ipa_idmap_find_new_domain;
8ff0aba893d8da1a8163ccaf9ad2c5b6bccd121fSumit Bose /* Initialize the map */
a473fb88e6015cf0ccbd2e9005c7e6acca18f452Pavel Březina err = sss_idmap_init(sss_idmap_talloc, idmap_ctx,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not initialize the ID map: [%s]\n",
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = ipa_idmap_get_ranges_from_sysdb(idmap_ctx, NULL, NULL, false);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_idmap_get_ranges_from_sysdb failed.\n");