sdap_idmap.c revision 3d9bafcbb5c0fbf23351004ded4dea6aa13127fc
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster Stephen Gallagher <sgallagh@redhat.com>
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster Copyright (C) 2012 Red Hat
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster This program is free software; you can redistribute it and/or modify
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster it under the terms of the GNU General Public License as published by
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster the Free Software Foundation; either version 3 of the License, or
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster (at your option) any later version.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster This program is distributed in the hope that it will be useful,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster but WITHOUT ANY WARRANTY; without even the implied warranty of
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster GNU General Public License for more details.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster You should have received a copy of the GNU General Public License
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster along with this program. If not, see <http://www.gnu.org/licenses/>.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fostersdap_idmap_get_configured_external_range(struct sdap_idmap_ctx *idmap_ctx,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster int_id = dp_opt_get_int(id_ctx->opts->basic, SDAP_MIN_ID);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster DEBUG(SSSDBG_CONF_SETTINGS, ("ldap_min_id must be greater than 0.\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster int_id = dp_opt_get_int(id_ctx->opts->basic, SDAP_MAX_ID);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster DEBUG(SSSDBG_CONF_SETTINGS, ("ldap_max_id must be greater than 0.\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if ((min == 0 && max != 0) || (min != 0 && max == 0)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster DEBUG(SSSDBG_CONF_SETTINGS, ("Both ldap_min_id and ldap_max_id " \
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster "either must be 0 (not set) " \
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster "or positive integers.\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster /* ldap_min_id and ldap_max_id not set, using min_id and max_id */
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fostersdap_idmap_add_configured_external_range(struct sdap_idmap_ctx *idmap_ctx)
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ret = sdap_idmap_get_configured_external_range(idmap_ctx, &range);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("sdap_idmap_get_configured_external_range failed.\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster err = sss_idmap_add_domain_ex(idmap_ctx->map, id_ctx->be->domain->name,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Could not add domain [%s] to the map: [%d]\n",
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fostererrno_t sdap_idmap_find_new_domain(struct sdap_idmap_ctx *idmap_ctx,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Could not add new domain [%s]\n", dom_name));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster struct sysdb_ctx *sysdb = id_ctx->be->domain->sysdb;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster idmap_ctx = talloc_zero(tmp_ctx, struct sdap_idmap_ctx);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster idmap_ctx->find_new_domain = sdap_idmap_find_new_domain;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster idmap_lower = dp_opt_get_int(idmap_ctx->id_ctx->opts->basic,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster idmap_upper = dp_opt_get_int(idmap_ctx->id_ctx->opts->basic,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster rangesize = dp_opt_get_int(idmap_ctx->id_ctx->opts->basic,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster autorid_mode = dp_opt_get_bool(idmap_ctx->id_ctx->opts->basic,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster /* Validate that the values make sense */
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Invalid settings for range selection: "
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if (((idmap_upper - idmap_lower) % rangesize) != 0) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Range size does not divide evenly. Uppermost range will "
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster "not be used\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster /* Initialize the map */
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster err = sss_idmap_init(sss_idmap_talloc, idmap_ctx,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Could not initialize the ID map: [%s]\n",
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster err = sss_idmap_ctx_set_autorid(idmap_ctx->map, autorid_mode);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster err |= sss_idmap_ctx_set_lower(idmap_ctx->map, idmap_lower);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster err |= sss_idmap_ctx_set_upper(idmap_ctx->map, idmap_upper);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster err |= sss_idmap_ctx_set_rangesize(idmap_ctx->map, rangesize);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster /* This should never happen */
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster DEBUG(SSSDBG_CRIT_FAILURE, ("sss_idmap_ctx corrupted\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster /* Setup range for externally managed IDs, i.e. IDs are read from the
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * ldap_user_uid_number and ldap_group_gid_number attributes. */
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if (!dp_opt_get_bool(idmap_ctx->id_ctx->opts->basic, SDAP_ID_MAPPING)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ret = sdap_idmap_add_configured_external_range(idmap_ctx);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("sdap_idmap_add_configured_external_range failed.\n"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster /* Read in any existing mappings from the cache */
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ret = sysdb_idmap_get_mappings(tmp_ctx, sysdb, id_ctx->be->domain, &res);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Could not read ID mappings from the cache: [%s]\n",
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster ("Initializing [%d] domains for ID-mapping\n", res->count));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster dom_name = ldb_msg_find_attr_as_string(res->msgs[i],
NULL);
if (!dom_name) {
goto done;
NULL);
if (!sid_str) {
goto done;
goto done;
goto done;
if (!dom_name) {
dom_name);
if (sid_str) {
sid_str, 0);
goto done;
done:
return ret;
const char *dom_name,
const char *dom_sid,
goto done;
ret));
goto done;
goto done;
goto done;
slice);
done:
return ret;
const char *object_sid,
char **dom_sid_str)
size_t c;
char *endptr;
return EINVAL;
errno = 0;
return EINVAL;
return EINVAL;
return EOK;
const char *sid_str,
switch (err) {
case IDMAP_SUCCESS:
case IDMAP_NO_DOMAIN:
&dom_sid_str);
goto done;
goto done;
sid_str));
goto done;
case IDMAP_BUILTIN_SID:
goto done;
sid_str));
goto done;
done:
return ret;
const char *dom_sid)
bool has_algorithmic_mapping;
char *new_dom_sid;
int ret;
return has_algorithmic_mapping;
&new_dom_sid);
return has_algorithmic_mapping;