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