/*
SSSD
Authors:
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2012 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "util/dlinklist.h"
#include "util/murmurhash3.h"
#include "providers/ldap/sdap_idmap.h"
#include "util/util_sss_idmap.h"
static errno_t
struct sss_idmap_range *range)
{
int int_id;
return EINVAL;
}
if (int_id < 0) {
return EINVAL;
}
if (int_id < 0) {
return EINVAL;
}
"either must be 0 (not set) " \
"or positive integers.\n");
return EINVAL;
}
/* ldap_min_id and ldap_max_id not set, using min_id and max_id */
if (max == 0) {
max = UINT32_MAX;
}
}
return EOK;
}
static errno_t
{
int ret;
"sdap_idmap_get_configured_external_range failed.\n");
return ret;
}
if (err != IDMAP_SUCCESS) {
"Could not add domain [%s] to the map: [%d]\n",
return EIO;
}
return EOK;
}
const char *dom_name,
const char *dom_sid_str)
{
int ret;
-1);
"Could not add new domain [%s]\n", dom_name);
return ret;
}
return EOK;
}
struct sdap_id_ctx *id_ctx,
struct sdap_idmap_ctx **_idmap_ctx)
{
size_t i;
const char *dom_name;
const char *sid_str;
bool autorid_mode;
int extra_slice_init;
if (!idmap_ctx) {
goto done;
}
/* Validate that the values make sense */
if (rangesize <= 0
|| idmap_upper <= idmap_lower
{
"Invalid settings for range selection: "
goto done;
}
"Range size does not divide evenly. Uppermost range will "
"not be used\n");
}
/* Initialize the map */
if (err != IDMAP_SUCCESS) {
"Could not initialize the ID map: [%s]\n",
if (err == IDMAP_OUT_OF_MEMORY) {
} else {
}
goto done;
}
if (err != IDMAP_SUCCESS) {
/* This should never happen */
goto done;
}
/* Setup range for externally managed IDs, i.e. IDs are read from the
* ldap_user_uid_number and ldap_group_gid_number attributes. */
"sdap_idmap_add_configured_external_range failed.\n");
goto done;
}
}
/* Read in any existing mappings from the cache */
"Could not read ID mappings from the cache: [%s]\n",
goto done;
}
NULL);
if (!dom_name) {
/* This should never happen */
goto done;
}
NULL);
if (!sid_str) {
/* This should never happen */
goto done;
}
-1);
if (slice_num == -1) {
/* This should never happen */
goto done;
}
"to ID map: [%s]\n",
goto done;
}
}
} else {
/* This is the first time we're setting up id-mapping
* Store the default domain as slice 0
*/
if (!dom_name) {
/* If it's not explicitly specified, use the SSSD domain name */
dom_name);
}
if (sid_str) {
goto done;
}
/* Set the default domain as slice 0 */
sid_str, 0);
"Could not add domain [%s][%s][%u] to ID map: [%s]\n",
goto done;
}
} else {
/* In autorid compatibility mode, we MUST have a slice 0 */
"WARNING: Autorid compatibility mode selected, "
"between clients.\n",
}
/* Otherwise, we'll just fall back to hash values as they are seen */
}
}
done:
return ret;
}
const char *dom_name,
const char *dom_sid,
{
bool external_mapping = true;
if (ret != IDMAP_SUCCESS) {
"Failed to get upper bound of available ID range.\n");
goto done;
}
external_mapping = false;
if (ret != IDMAP_SUCCESS) {
"Failed to calculate range for domain [%s]: [%d]\n", dom_name,
ret);
goto done;
}
/* This should never happen */
"BUG: Range maximum exceeds the global maximum: "
goto done;
}
} else {
"sdap_idmap_get_configured_external_range failed.\n");
return ret;
}
}
/* Add this domain to the map */
if (err != IDMAP_SUCCESS) {
"Could not add domain [%s] to the map: [%d]\n",
goto done;
}
/* If algorithmic mapping is used add this domain to the SYSDB cache so it
* will survive reboot */
if (!external_mapping) {
slice);
goto done;
}
}
done:
return ret;
}
const char *object_sid,
char **dom_sid_str)
{
const char *p;
long long a;
size_t c;
char *endptr;
if (object_sid == NULL
return EINVAL;
}
p = object_sid + DOM_SID_PREFIX_LEN;
c = 0;
do {
errno = 0;
if (errno != 0 || a > UINT32_MAX) {
return EINVAL;
}
if (*endptr == '-') {
p = endptr + 1;
} else {
return EINVAL;
}
c++;
} while(c < 3);
/* If we made it here, we are now one character past
* the last hyphen in the object-sid.
* Copy the dom-sid substring.
*/
(endptr-object_sid));
if (!*dom_sid_str) return ENOMEM;
return EOK;
}
const char *sid_str,
{
/* Convert the SID into a UNIX ID */
switch (err) {
case IDMAP_SUCCESS:
break;
case IDMAP_NO_DOMAIN:
/* This is the first time we've seen this domain
* Create a new domain for it. We'll use the dom-sid
* as the domain name for now, since we don't have
* any way to get the real name.
*/
&dom_sid_str);
"Could not parse domain SID from [%s]\n", sid_str);
goto done;
}
"Could not add new domain for sid [%s]\n", sid_str);
goto done;
}
/* Now try converting to a UNIX ID again */
if (err != IDMAP_SUCCESS) {
"Could not convert objectSID [%s] to a UNIX ID\n",
sid_str);
goto done;
}
break;
case IDMAP_BUILTIN_SID:
"Object SID [%s] is a built-in one.\n", sid_str);
/* ENOTSUP indicates built-in SID */
goto done;
break;
case IDMAP_NO_RANGE:
"Object SID [%s] has a RID that is larger than the "
"ldap_idmap_range_size. See the \"ID MAPPING\" section of "
"sssd-ad(5) for an explanation of how to resolve this issue.\n",
sid_str);
/* Fall through intentionally */
default:
"Could not convert objectSID [%s] to a UNIX ID\n",
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;
return true;
}
switch (err){
case IDMAP_SUCCESS:
return has_algorithmic_mapping;
case IDMAP_SID_INVALID: /* FALLTHROUGH */
case IDMAP_SID_UNKNOWN: /* FALLTHROUGH */
case IDMAP_NO_DOMAIN: /* FALLTHROUGH */
/* continue with idmap_domain_by_name */
break;
default:
return false;
}
if (err == IDMAP_SUCCESS) {
return has_algorithmic_mapping;
return false;
}
/* If there is no SID, e.g. IPA without enabled trust support, we cannot
* have algorithmic mapping */
return false;
}
/* This is the first time we've seen this domain
* Create a new domain for it. We'll use the dom-sid
* as the domain name for now, since we don't have
* any way to get the real name.
*/
if (is_domain_sid(dom_sid)) {
} else {
return false;
}
&new_dom_sid);
"Could not parse domain SID from [%s]\n", dom_sid);
return false;
}
}
"Could not add new domain for sid [%s]\n", dom_sid);
return false;
}
if (err == IDMAP_SUCCESS) {
return has_algorithmic_mapping;
}
return false;
}