sdap_idmap.c revision d6f283302268520c1506fb3da4f2a22f5a741be5
/*
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"
static void *
{
}
static void
{
}
struct sdap_id_ctx *id_ctx,
struct sdap_idmap_ctx **_idmap_ctx)
{
enum idmap_error_code err;
size_t i;
struct ldb_result *res;
const char *dom_name;
const char *sid_str;
if (!idmap_ctx) {
goto done;
}
/* Initialize the map */
if (err != IDMAP_SUCCESS) {
("Could not initialize the ID map: [%s]\n",
if (err == IDMAP_OUT_OF_MEMORY) {
} else {
}
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;
}
("Could not add domain [%s][%s][%u] 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) {
/* 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,
{
struct sdap_idmap_slice *new_slice;
struct sdap_idmap_slice *s;
struct sss_idmap_range range;
enum idmap_error_code err;
/* Validate that the values make sense */
if (rangesize <= 0
|| idmap_upper <= idmap_lower
{
("Invalid settings for range selection: [%d][%d][%d]\n",
return EINVAL;
}
("Range size does not divide evenly. Uppermost range will "
"not be used\n"));
}
if (slice != -1) {
/* The slice is being set explicitly.
* This may happen at system startup when we're loading
* previously-determined slices. In the future, we may also
* permit configuration to select the slice for a domain
* explicitly.
*/
} else {
/* If slice is -1, we're being asked to pick a new slice */
/* In autorid compatibility mode, always start at 0 and find the first
* free value.
*/
orig_slice = 0;
} else {
/* Hash the domain sid string */
/* Now get take the modulus of the hash val and the max_slices
* to determine its optimal position in the range.
*/
}
/* Verify that this slice is not already in use */
do {
/* This slice number matches one already registered
* We'll try the next available slot
*/
/* loop around to the beginning if necessary */
}
break;
}
}
/* Keep trying until s is NULL (meaning we got to the end
* without matching) or we have run out of slices and gotten
* back to the first one we tried.
*/
if (s) {
/* We looped all the way through and found no empty slots */
("Could not add domain [%s]: no free slices\n",
dom_name));
goto done;
}
}
("Adding domain [%s] as slice [%d]\n",
/* Not adding a destructor to remove from this list, because it
* should never be possible. Removal from this list can only
* destabilize the system.
*/
/* Create a range object to add to the mapping */
/* This should never happen */
("BUG: Range maximum exceeds the global maximum: %d > %d\n",
goto done;
}
/* Add this domain to the map */
if (err != IDMAP_SUCCESS) {
("Could not add domain [%s] to the map: [%d]\n",
goto done;
}
/* Add this domain to the SYSDB cache so it will survive reboot */
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,
{
enum idmap_error_code err;
char *dom_sid_str = NULL;
/* 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;
}
-1);
("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;
default:
("Could not convert objectSID [%s] to a UNIX ID\n",
sid_str));
goto done;
}
done:
return ret;
}