dbutils.c revision 82da9f6027f9bba5379e821f9331f18c4b0ffb15
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Database related utility routines
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <pwd.h>
#include <grp.h>
#include <pthread.h>
#include <assert.h>
#include <sys/u8_textprep.h>
#include "idmapd.h"
#include "adutils.h"
#include "string.h"
#include "idmap_priv.h"
#include "schema.h"
#include "nldaputils.h"
sqlite_vm **, int *, int, const char ***);
idmap_id_res *);
const char *, char **, char **, idmap_rid_t *, int *);
#define DO_NOT_ALLOC_NEW_ID_MAPPING(req)\
#define AVOID_NAMESERVICE(req)\
#define LOCALRID_MIN 1000
typedef enum init_db_option {
FAIL_IF_CORRUPT = 0,
/*
* Data structure to store well-known SIDs and
* associated mappings (if any)
*/
typedef struct wksids_table {
const char *sidprefix;
const char *winname;
int is_wuser;
int is_user;
int direction;
/*
* Thread specfic data to hold the database handles so that the
* databaes are not opened and closed for every request. It also
* contains the sqlite busy handler structure.
*/
struct idmap_busy {
const char *name;
const int *delays;
int delay_size;
int total;
int sec;
};
typedef struct idmap_tsd {
struct idmap_busy cache_busy;
struct idmap_busy db_busy;
} idmap_tsd_t;
static const int cache_delay_table[] =
{ 1, 2, 5, 10, 15, 20, 25, 30, 35, 40,
50, 50, 60, 70, 80, 90, 100};
static const int db_delay_table[] =
{ 5, 10, 15, 20, 30, 40, 55, 70, 100};
static pthread_key_t idmap_tsd_key;
void
idmap_tsd_destroy(void *key)
{
if (tsd) {
}
}
int
idmap_init_tsd_key(void)
{
}
idmap_get_tsd(void)
{
/* No thread specific data so create it */
/* Initialize thread specific data */
/* save the trhread specific data */
/* Can't store key */
}
} else {
}
}
return (tsd);
}
/*
* A simple wrapper around u8_textprep_str() that returns the Unicode
* lower-case version of some string. The result must be freed.
*/
char *
tolower_u8(const char *s)
{
char *outs;
/*
* u8_textprep_str() does not allocate memory. The input and
* output buffers may differ in size (though that would be more
* likely when normalization is done). We have to loop over it...
*
* To improve the chances that we can avoid looping we add 10
* bytes of output buffer room the first go around.
*/
return (NULL);
return (NULL);
s += (inlen - inbytesleft);
/* adjust outbytesleft and outlen */
outlen += inbytesleft;
}
if (rc < 0) {
return (NULL);
}
return (res);
}
const char *while_doing);
/*
* Initialize 'dbname' using 'sql'
*/
static
int
const char *detect_version_sql, char * const *sql,
{
int rc, curr_version;
int tries = 1;
int prio = LOG_NOTICE;
*created = 0;
*upgraded = 0;
if (opt == REMOVE_IF_CORRUPT)
tries = 3;
if (tries == 0) {
return (-1);
}
if (tries-- == 1)
/* Last try, log errors */
if (opt == REMOVE_IF_CORRUPT)
goto rinse_repeat;
}
/* Detect current version of schema in the db, if any */
curr_version = 0;
if (detect_version_sql != NULL) {
int nrow;
#ifdef IDMAPD_DEBUG
#endif /* IDMAPD_DEBUG */
"Error detecting schema version of db %s (%s)",
return (-1);
}
if (nrow != 1) {
"Error detecting schema version of db %s", dbname);
return (-1);
}
}
if (curr_version < 0) {
if (opt == REMOVE_IF_CORRUPT)
goto rinse_repeat;
}
if (curr_version == version)
goto done;
/* Install or upgrade schema */
#ifdef IDMAPD_DEBUG
sql[curr_version]);
#endif /* IDMAPD_DEBUG */
if (rc != 0) {
(curr_version == 0) ? "installing schema" :
"upgrading schema");
if (opt == REMOVE_IF_CORRUPT)
goto rinse_repeat;
}
*upgraded = (curr_version > 0);
*created = (curr_version == 0);
done:
(void) sqlite_close(db);
return (0);
}
/*
* This is the SQLite database busy handler that retries the SQL
* operation until it is successful.
*/
int
/* LINTED E_FUNC_ARG_UNUSED */
{
int delay;
if (count == 1) {
}
"Thread %d waited %d sec for the %s database",
}
} else {
}
return (1);
}
/*
* Get the database handle
*/
{
char *errmsg;
/*
* Retrieve the db handle from thread-specific storage
* If none exists, open and store in thread-specific storage.
*/
"Error getting thread specific data for %s", IDMAP_DBNAME);
return (IDMAP_ERR_MEMORY);
}
return (IDMAP_ERR_DB);
}
sizeof (int);
}
return (IDMAP_SUCCESS);
}
/*
* Get the cache handle
*/
{
char *errmsg;
/*
* Retrieve the db handle from thread-specific storage
* If none exists, open and store in thread-specific storage.
*/
return (IDMAP_ERR_MEMORY);
}
return (IDMAP_ERR_DB);
}
sizeof (int);
&tsd->cache_busy);
}
return (IDMAP_SUCCESS);
}
/*
* Initialize cache and db
*/
int
init_dbs()
{
char *sql[4];
/* name-based mappings; probably OK to blow away in a pinch(?) */
sql[0] = DB_INSTALL_SQL;
return (-1);
sql[0] = CACHE_INSTALL_SQL;
return (-1);
return (0);
}
/*
* Finalize databases
*/
void
fini_dbs()
{
}
/*
* This table is a listing of status codes that will be returned to the
* client when a SQL command fails with the corresponding error message.
*/
static msg_table_t sqlmsgtable[] = {
"columns unixname, is_user, u2w_order are not unique"},
"columns winname, windomain, is_user, is_wuser, w2u_order are not"
" unique"},
{IDMAP_ERR_W2U_NAMERULE_CONFLICT, "Conflicting w2u namerules"},
{-1, NULL}
};
/*
* idmapd's version of string2stat to map SQLite messages to
* status codes
*/
idmapd_string2stat(const char *msg)
{
int i;
for (i = 0; sqlmsgtable[i].msg; i++) {
return (sqlmsgtable[i].retcode);
}
return (IDMAP_ERR_OTHER);
}
/*
* Executes some SQL in a transaction.
*
* Returns 0 on success, -1 if it failed but the rollback succeeded, -2
* if the rollback failed.
*/
static
int
const char *while_doing)
{
int rc;
return (-1);
}
goto rollback;
}
return (0);
}
return (-2);
}
return (-1);
}
/*
* Execute the given SQL statment without using any callbacks
*/
{
int r;
if (r != SQLITE_OK) {
return (retcode);
}
return (IDMAP_SUCCESS);
}
/*
* Generate expression that can be used in WHERE statements.
* Examples:
* <prefix> <col> <op> <value> <suffix>
* "" "unixuser" "=" "foo" "AND"
*/
{
char *s_unixname = NULL;
char *lower_winname;
int retcode = IDMAP_SUCCESS;
return (IDMAP_ERR_ARG);
if (s_windomain == NULL) {
goto out;
}
}
"AND winname = %Q AND is_wuser = %d ",
goto out;
}
}
"AND unixname = %Q AND is_user = %d ",
if (s_unixname == NULL) {
goto out;
}
}
goto out;
}
out:
if (s_windomain != NULL)
if (s_unixname != NULL)
return (retcode);
}
/*
* Generate and execute SQL statement for LIST RPC calls
*/
{
int r;
switch (r) {
case SQLITE_OK:
break;
default:
break;
}
return (retcode);
}
/*
* This routine is called by callbacks that process the results of
* LIST RPC calls to validate data and to allocate memory for
* the result array.
*/
{
void *tmplist;
return (IDMAP_NEXT);
return (IDMAP_ERR_INTERNAL);
}
/* alloc in bulk to reduce number of reallocs */
return (IDMAP_ERR_MEMORY);
}
}
return (IDMAP_SUCCESS);
}
static
{
*w2u_order = 0;
*u2w_order = 0;
/*
* Windows to UNIX lookup order:
* 1. winname@domain (or winname) to ""
* 2. winname@domain (or winname) to unixname
* 3. winname@* to ""
* 4. winname@* to unixname
* 5. *@domain (or *) to *
* 6. *@domain (or *) to ""
* 7. *@domain (or *) to unixname
* 8. *@* to *
* 9. *@* to ""
* 10. *@* to unixname
*
* winname is a special case of winname@domain when domain is the
* default domain. Similarly * is a special case of *@domain when
* domain is the default domain.
*
* Note that "" has priority over specific names because "" inhibits
* mappings and traditionally deny rules always had higher priority.
*/
if (direction != IDMAP_DIRECTION_U2W) {
/* bi-directional or from windows to unix */
return (IDMAP_ERR_W2U_NAMERULE);
return (IDMAP_ERR_W2U_NAMERULE);
else if (EMPTY_NAME(winname))
return (IDMAP_ERR_W2U_NAMERULE);
if (*unixname == '*')
*w2u_order = 8;
else if (EMPTY_NAME(unixname))
*w2u_order = 9;
else /* unixname == name */
*w2u_order = 10;
} else if (*winname == '*') {
if (*unixname == '*')
*w2u_order = 5;
else if (EMPTY_NAME(unixname))
*w2u_order = 6;
else /* name */
*w2u_order = 7;
/* winname == name */
if (*unixname == '*')
return (IDMAP_ERR_W2U_NAMERULE);
else if (EMPTY_NAME(unixname))
*w2u_order = 3;
else /* name */
*w2u_order = 4;
} else {
/* winname == name && windomain == null or name */
if (*unixname == '*')
return (IDMAP_ERR_W2U_NAMERULE);
else if (EMPTY_NAME(unixname))
*w2u_order = 1;
else /* name */
*w2u_order = 2;
}
}
/*
* 1. unixname to "", non-diagonal
* 2. unixname to winname@domain (or winname), non-diagonal
* 3. unixname to "", diagonal
* 4. unixname to winname@domain (or winname), diagonal
* 5. * to *@domain (or *), non-diagonal
* 5. * to *@domain (or *), diagonal
* 7. * to ""
* 8. * to winname@domain (or winname)
* 9. * to "", non-diagonal
* 10. * to winname@domain (or winname), diagonal
*/
if (direction != IDMAP_DIRECTION_W2U) {
/* bi-directional or from unix to windows */
return (IDMAP_ERR_U2W_NAMERULE);
return (IDMAP_ERR_U2W_NAMERULE);
return (IDMAP_ERR_U2W_NAMERULE);
else if (*unixname == '*') {
if (*winname == '*')
else if (EMPTY_NAME(winname))
else
} else {
if (*winname == '*')
return (IDMAP_ERR_U2W_NAMERULE);
else if (EMPTY_NAME(winname))
else
}
}
return (IDMAP_SUCCESS);
}
/*
* Generate and execute SQL statement to add name-based mapping rule
*/
{
if (retcode != IDMAP_SUCCESS)
goto out;
if (w2u_order)
if (u2w_order)
/*
* For the triggers on namerules table to work correctly:
* 1) Use NULL instead of 0 for w2u_order and u2w_order
* 2) Use "" instead of NULL for "no domain"
*/
== IDMAP_SUCCESS) {
/* well-known SIDs don't need domain */
dom = "";
}
else
dom = "";
}
"(is_user, is_wuser, windomain, winname_display, is_nt4, "
"unixname, w2u_order, u2w_order) "
"VALUES(%d, %d, %Q, %Q, %d, %Q, %q, %q);",
goto out;
}
if (retcode == IDMAP_ERR_OTHER)
out:
return (retcode);
}
/*
* Flush name-based mapping rules
*/
{
return (retcode);
}
/*
* Generate and execute SQL statement to remove a name-based mapping rule
*/
{
char buf[80];
return (IDMAP_SUCCESS);
buf[0] = 0;
" AND u2w_order > 0");
" AND (u2w_order = 0 OR u2w_order ISNULL)");
" AND (w2u_order = 0 OR w2u_order ISNULL)");
if (retcode != IDMAP_SUCCESS)
goto out;
buf);
goto out;
}
out:
return (retcode);
}
/*
* Compile the given SQL query and step just once.
*
* Input:
* db - db handle
* sql - SQL statement
*
* Output:
* vm - virtual SQL machine
* ncol - number of columns in the result
* values - column values
*
* Return values:
* IDMAP_SUCCESS
* IDMAP_ERR_NOTFOUND
* IDMAP_ERR_INTERNAL
*/
static
{
int r;
CHECK_NULL(errmsg));
return (IDMAP_ERR_INTERNAL);
}
if (r == SQLITE_ROW) {
return (IDMAP_ERR_INTERNAL);
}
/* Caller will call finalize after using the results */
return (IDMAP_SUCCESS);
} else if (r == SQLITE_DONE) {
return (IDMAP_ERR_NOTFOUND);
}
CHECK_NULL(errmsg));
return (IDMAP_ERR_INTERNAL);
}
/*
* Load config in the state.
*
* nm_siduid and nm_sidgid fields:
* state->nm_siduid represents mode used by sid2uid and uid2sid
* requests for directory-based name mappings. Similarly,
* state->nm_sidgid represents mode used by sid2gid and gid2sid
* requests.
*
* none -> ds_name_mapping_enabled != true
* AD-mode -> !nldap_winname_attr && ad_unixuser_attr
* nldap-mode -> nldap_winname_attr && !ad_unixuser_attr
* mixed-mode -> nldap_winname_attr && ad_unixuser_attr
*
* none -> ds_name_mapping_enabled != true
* AD-mode -> !nldap_winname_attr && ad_unixgroup_attr
* nldap-mode -> nldap_winname_attr && !ad_unixgroup_attr
* mixed-mode -> nldap_winname_attr && ad_unixgroup_attr
*/
{
return (IDMAP_ERR_MEMORY);
}
} else {
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
} else {
? IDMAP_NM_AD : IDMAP_NM_NONE;
? IDMAP_NM_AD : IDMAP_NM_NONE;
}
return (IDMAP_ERR_MEMORY);
}
}
return (IDMAP_ERR_MEMORY);
}
}
return (IDMAP_ERR_MEMORY);
}
}
return (IDMAP_SUCCESS);
}
/*
* Set the rule with sepecified values.
* All the strings are copied.
*/
static void
{
/*
* Only update if they differ because we have to free
* and duplicate the strings
*/
}
}
}
}
}
}
}
/*
* Table for well-known SIDs.
*
* Background:
*
* Some of the well-known principals are stored under:
* cn=WellKnown Security Principals, cn=Configuration, dc=<forestRootDomain>
* They belong to objectClass "foreignSecurityPrincipal". They don't have
* "samAccountName" nor "userPrincipalName" attributes. Their names are
* available in "cn" and "name" attributes. Some of these principals have a
* second entry under CN=ForeignSecurityPrincipals,dc=<forestRootDomain> and
* these duplicate entries have the stringified SID in the "name" and "cn"
* attributes instead of the actual name.
*
* Those of the form S-1-5-32-X are Builtin groups and are stored in the
* cn=builtin container (except, Power Users which is not stored in AD)
*
* These principals are and will remain constant. Therefore doing AD lookups
* provides no benefit. Also, using hard-coded table (and thus avoiding AD
* lookup) improves performance and avoids additional complexity in the
* adutils.c code. Moreover these SIDs can be used when no Active Directory
* is available (such as the CIFS server's "workgroup" mode).
*
* Notes:
* 1. Currently we don't support localization of well-known SID names,
* unlike Windows.
*
* 2. Other well-known SIDs i.e. S-1-5-<domain>-<w-k RID> are not stored
* can be looked up using the existing AD lookup code.
*
* 3. See comments above lookup_wksids_sid2pid() for more information
* on how we lookup the wksids table.
*/
static wksids_table_t wksids[] = {
{"S-1-5-32", 554, "Pre-Windows 2000 Compatible Access", 0,
{"S-1-5-32", 556, "Network Configuration Operators", 0,
{"S-1-5-32", 557, "Incoming Forest Trust Builders", 0,
{"S-1-5-32", 560, "Windows Authorization Access Group", 0,
{"S-1-5-32", 561, "Terminal Server License Servers", 0,
{"S-1-5-32", 574, "Certificate Service DCOM Access", 0,
};
/*
* Lookup well-known SIDs table either by winname or by SID.
* If the given winname or SID is a well-known SID then we set wksid
* variable and then proceed to see if the SID has a hard mapping to
* fixed ephemeral ids). If we find such mapping then we return
* success otherwise notfound. If a well-known SID is mapped to
* SENTINEL_PID and the direction field is set (bi-directional or
* win2unix) then we treat it as inhibited mapping and return no
* mapping (Ex. S-1-0-0).
*/
static
{
int i;
*wksid = 0;
/* this is not our SID */
continue;
return (IDMAP_ERR_MEMORY);
}
/* this is not our winname */
continue;
return (IDMAP_ERR_MEMORY);
}
*wksid = 1;
/* Inhibited */
return (IDMAP_ERR_NOMAPPING);
/* Not mapped */
}
return (IDMAP_ERR_NOTFOUND);
continue;
case IDMAP_UID:
continue;
}
return (IDMAP_SUCCESS);
case IDMAP_GID:
continue;
}
return (IDMAP_SUCCESS);
case IDMAP_POSIXID:
}
return (IDMAP_SUCCESS);
default:
return (IDMAP_ERR_NOTSUPPORTED);
}
}
return (IDMAP_ERR_NOTFOUND);
}
static
{
int i;
return (IDMAP_ERR_NOTFOUND);
}
return (IDMAP_ERR_MEMORY);
}
}
return (IDMAP_SUCCESS);
}
}
return (IDMAP_ERR_NOTFOUND);
}
{
int i;
name += 8;
continue;
return (IDMAP_ERR_MEMORY);
}
}
return (IDMAP_ERR_MEMORY);
}
return (IDMAP_SUCCESS);
}
return (IDMAP_ERR_NOTFOUND);
}
static
{
char *end;
const char **values;
char *is_user_string, *lower_name;
/* Current time */
errno = 0;
goto out;
}
case IDMAP_UID:
is_user_string = "1";
break;
case IDMAP_GID:
is_user_string = "0";
break;
case IDMAP_POSIXID:
/* the non-diagonal mapping */
is_user_string = "is_wuser";
break;
default:
goto out;
}
/* SQL to lookup the cache */
"unixname, u2w, is_wuser, "
"map_type, map_dn, map_attr, map_value, "
"map_windomain, map_winname, map_unixname, map_is_nt4 "
"FROM idmap_cache WHERE is_user = %s AND "
"sidprefix = %Q AND rid = %u AND w2u = 1 AND "
"(pid >= 2147483648 OR "
"(expiration = 0 OR expiration ISNULL OR "
"expiration > %d));",
"unixname, u2w, is_wuser, "
"map_type, map_dn, map_attr, map_value, "
"map_windomain, map_winname, map_unixname, map_is_nt4 "
"FROM idmap_cache WHERE is_user = %s AND "
"winname = %Q AND windomain = %Q AND w2u = 1 AND "
"(pid >= 2147483648 OR "
"(expiration = 0 OR expiration ISNULL OR "
"expiration > %d));",
curtime);
} else {
goto out;
}
goto out;
}
14, &values);
if (retcode == IDMAP_ERR_NOTFOUND) {
goto out;
} else if (retcode == IDMAP_SUCCESS) {
/* sanity checks */
goto out;
}
if (is_user) {
} else {
}
/*
* We may have an expired ephemeral mapping. Consider
* the expired entry as valid if we are not going to
* perform name-based mapping. But do not renew the
* expiration.
* If we will be doing name-based mapping then store the
* ephemeral pid in the result so that we can use it
* if we end up doing dynamic mapping again.
*/
if (!DO_NOT_ALLOC_NEW_ID_MAPPING(req) &&
!AVOID_NAMESERVICE(req) &&
/* Store the ephemeral pid */
}
}
}
out:
if (retcode == IDMAP_SUCCESS) {
else
}
}
case IDMAP_MAP_TYPE_DS_AD:
break;
case IDMAP_MAP_TYPE_DS_NLDAP:
break;
break;
case IDMAP_MAP_TYPE_EPHEMERAL:
break;
case IDMAP_MAP_TYPE_LOCAL_SID:
break;
case IDMAP_MAP_TYPE_KNOWN_SID:
break;
default:
/* Unknow mapping type */
}
}
}
return (retcode);
}
static
{
char *end;
const char **values;
int ncol;
/* Get current time */
errno = 0;
goto out;
}
/* SQL to lookup the cache */
"FROM name_cache WHERE "
"sidprefix = %Q AND rid = %u AND "
"(expiration = 0 OR expiration ISNULL OR "
"expiration > %d);",
goto out;
}
if (retcode == IDMAP_SUCCESS) {
goto out;
}
}
goto out;
}
}
}
goto out;
}
}
}
out:
return (retcode);
}
/*
* Given SID, find winname using name_cache OR
* Given winname, find SID using name_cache.
* Used when mapping win to unix i.e. req->id1 is windows id and
* req->id2 is unix id
*/
static
{
int type = -1;
/* Done if we've both sid and winname */
return (IDMAP_SUCCESS);
/* Lookup sid to winname */
goto out;
}
/* Lookup winame to sid */
out:
if (retcode != IDMAP_SUCCESS) {
return (retcode);
}
}
}
}
return (retcode);
}
/*
* Batch AD lookups
*/
{
char **unixname;
/*
* Since req->id2.idtype is unused, we will use it here
* to retrieve the value of sid_type. But it needs to be
* reset to IDMAP_NONE before we return to prevent xdr
* from mis-interpreting req->id2 when it tries to free
* the input argument. Other option is to allocate an
* array of integers and use it instead for the batched
* call. But why un-necessarily allocate memory. That may
* be an option if req->id2.idtype cannot be re-used in
* future.
*/
if (state->ad_nqueries == 0)
return (IDMAP_SUCCESS);
&qs);
if (retcode != IDMAP_SUCCESS) {
goto retry;
goto out;
}
restore_svc();
/* Skip if not marked for AD lookup */
continue;
if (retries == 0)
continue;
/* win2unix request: */
}
}
add = 1;
/*
* Get how info for DS-based name
* mapping only if AD or MIXED
* mode is enabled.
*/
}
/* Lookup AD by SID */
} else {
/* Lookup AD by winname */
}
/* unix2win request: */
/* Already have SID and winname -- done */
continue;
}
/*
* SID but no winname -- lookup AD by
* SID to get winname.
* how info is not needed here because
* we are not retrieving unixname from
* AD.
*/
add = 1;
/*
* winname but no SID -- lookup AD by
* winname to get SID.
* how info is not needed here because
* we are not retrieving unixname from
* AD.
*/
add = 1;
/*
* No SID and no winname but we've unixname --
* lookup AD by unixname to get SID.
*/
is_wuser = 1;
is_wuser = 0;
else
add = 1;
}
}
if (retcode != IDMAP_SUCCESS) {
break;
}
}
goto retry;
else if (retcode == IDMAP_ERR_RETRIABLE_NET_ERR)
if (retcode != IDMAP_SUCCESS)
out:
/*
* This loop does the following:
* 1. Reset _IDMAP_F_LOOKUP_AD flag from the request.
* 2. Reset req->id2.idtype to IDMAP_NONE
* 3. If batch_start or batch_add failed then set the status
* of each request marked for AD lookup to that error.
* 4. Evaluate the type of the AD object (i.e. user or group) and
* update the idtype in request.
*/
for (i = 0; i < batch->idmap_mapping_batch_len; i++) {
continue;
/* Reset AD lookup flag */
/*
* If batch_start or batch_add failed then set the status
* of each request marked for AD lookup to that error.
*/
if (retcode != IDMAP_SUCCESS) {
continue;
}
if (!add)
continue;
/* Nothing found - remove the preset info */
}
continue;
/* Evaluate result type */
switch (type) {
case _IDMAP_T_USER:
break;
case _IDMAP_T_GROUP:
break;
default:
break;
}
state->nldap_nqueries++;
}
/*
* If AD lookup by unixname failed
* with non fatal error then clear
* the error (i.e set res->retcode
* to success). This allows the next
* pass to process other mapping
* mechanisms for this request.
*/
continue;
}
/* Evaluate result type */
switch (type) {
case _IDMAP_T_USER:
break;
case _IDMAP_T_GROUP:
break;
default:
break;
}
}
}
/* AD lookups done. Reset state->ad_nqueries and return */
state->ad_nqueries = 0;
return (retcode);
}
/*
* Convention when processing win2unix requests:
*
* Windows identity:
* req->id1name =
* winname if given otherwise winname found will be placed
* here.
* req->id1domain =
* windomain if given otherwise windomain found will be
* placed here.
* req->id1.idtype =
* be set to IDMAP_USID/GSID depending upon whether the
* given SID is user or group respectively. The user/group-ness
* is determined either when looking up well-known SIDs table OR
* if the SID is found in namecache OR by ad_lookup_one() OR by
* ad_lookup_batch().
* req->id1..sid.[prefix, rid] =
* SID if given otherwise SID found will be placed here.
*
* Unix identity:
* req->id2name =
* unixname found will be placed here.
* req->id2domain =
* NOT USED
* res->id.idtype =
* Target type initialized from req->id2.idtype. If
* will be placed here.
* res->id..[uid or gid] =
*
* Others:
* res->retcode =
* Return status for this request will be placed here.
* res->direction =
* Direction found will be placed here. Direction
* meaning whether the resultant mapping is valid
* only from win2unix or bi-directional.
* req->direction =
* INTERNAL USE. Used by idmapd to set various
* flags (_IDMAP_F_xxxx) to aid in processing
* of the request.
* req->id2.idtype =
* INTERNAL USE. Initially this is the requested target
* type and is used to initialize res->id.idtype.
* ad_lookup_batch() uses this field temporarily to store
* sid_type obtained by the batched AD lookups and after
* use resets it to IDMAP_NONE to prevent xdr from
* mis-interpreting the contents of req->id2.
* req->id2..[uid or gid or sid] =
* NOT USED
*/
/*
* This function does the following:
* 1. Lookup well-known SIDs table.
* 3. Lookup cache.
* 4. Check if the client does not want new mapping to be allocated
* in which case this pass is the final pass.
* 5. Set AD lookup flag if it determines that the next stage needs
* to do AD lookup.
*/
{
int wksid;
/* Initialize result */
wksid = 0;
goto out;
}
/* sanitize sidprefix */
}
/* Lookup well-known SIDs table */
if (retcode != IDMAP_ERR_NOTFOUND)
goto out;
/* Check if this is a localsid */
if (!wksid) {
if (retcode != IDMAP_ERR_NOTFOUND)
goto out;
}
/* Lookup cache */
if (retcode != IDMAP_ERR_NOTFOUND)
goto out;
goto out;
}
/*
* Failed to find non-expired entry in cache. Next step is
* to determine if this request needs to be batched for AD lookup.
*
* At this point we have either sid or winname or both. If we don't
* have both then lookup name_cache for the sid or winname
* whichever is missing. If not found then this request will be
* batched for AD lookup.
*/
goto out;
/*
* Set the flag to indicate that we are not done yet so that
* subsequent passes considers this request for name-based
* mapping and ephemeral mapping.
*/
/*
* Even if we have both sid and winname, we still may need to batch
* this request for AD lookup if we don't have unixname and
* directory-based name mapping (AD or mixed) is enabled.
* We avoid AD lookup for well-known SIDs because they don't have
* regular AD objects.
*/
if (retcode != IDMAP_SUCCESS ||
state->ad_nqueries++;
state->nldap_nqueries++;
}
out:
/*
* If we are done and there was an error then set fallback pid
* in the result.
*/
return (retcode);
}
/*
* Generate SID using the following convention
* <machine-sid-prefix>-<1000 + uid>
* <machine-sid-prefix>-<2^31 + gid>
*/
static
int fallback)
{
/*
* Diagonal mapping for localSIDs not supported because of the
* way we generate localSIDs.
*/
return (IDMAP_ERR_NOMAPPING);
return (IDMAP_ERR_NOMAPPING);
/* Skip 1000 UIDs */
(INT32_MAX - LOCALRID_MIN))
return (IDMAP_ERR_NOMAPPING);
/*
* machine_sid is never NULL because if it is we won't be here.
* No need to assert because stdrup(NULL) will core anyways.
*/
return (IDMAP_ERR_MEMORY);
}
}
/*
* Don't update name_cache because local sids don't have
* valid windows names.
*/
return (IDMAP_SUCCESS);
}
static
{
char *sidprefix;
int s;
/*
* If the sidprefix == localsid then UID = last RID - 1000 or
* GID = last RID - 2^31.
*/
/* This means we are looking up by winname */
return (IDMAP_ERR_NOTFOUND);
/*
* If the given sidprefix does not match machine_sid then this is
* not a local SID.
*/
if (s != 0)
return (IDMAP_ERR_NOTFOUND);
case IDMAP_UID:
return (IDMAP_ERR_ARG);
break;
case IDMAP_GID:
return (IDMAP_ERR_ARG);
break;
case IDMAP_POSIXID:
} else if (rid < LOCALRID_MIN) {
return (IDMAP_ERR_ARG);
} else {
}
break;
default:
return (IDMAP_ERR_NOTSUPPORTED);
}
}
return (IDMAP_SUCCESS);
}
/*
* Name service lookup by unixname to get pid
*/
static
{
char buf[1024];
int errnum;
const char *me = "ns_lookup_byname";
case IDMAP_UID:
"%s: getpwnam_r(%s) failed (%s).",
if (errnum == 0)
return (IDMAP_ERR_NOTFOUND);
else
return (IDMAP_ERR_INTERNAL);
}
break;
case IDMAP_GID:
"%s: getgrnam_r(%s) failed (%s).",
if (errnum == 0)
return (IDMAP_ERR_NOTFOUND);
else
return (IDMAP_ERR_INTERNAL);
}
break;
default:
return (IDMAP_ERR_ARG);
}
return (IDMAP_SUCCESS);
}
/*
* Name service lookup by pid to get unixname
*/
static
{
char buf[1024];
int errnum;
const char *me = "ns_lookup_bypid";
if (is_user) {
errno = 0;
"%s: getpwuid_r(%u) failed (%s).",
if (errnum == 0)
return (IDMAP_ERR_NOTFOUND);
else
return (IDMAP_ERR_INTERNAL);
}
} else {
errno = 0;
"%s: getgrgid_r(%u) failed (%s).",
if (errnum == 0)
return (IDMAP_ERR_NOTFOUND);
else
return (IDMAP_ERR_INTERNAL);
}
}
return (IDMAP_ERR_MEMORY);
return (IDMAP_SUCCESS);
}
/*
* Name-based mapping
*
* Case 1: If no rule matches do ephemeral
*
* Case 2: If rule matches and unixname is "" then return no mapping.
*
* Case 3: If rule matches and unixname is specified then lookup name
* service using the unixname. If unixname not found then return no mapping.
*
* Case 4: If rule matches and unixname is * then lookup name service
* using winname as the unixname. If unixname not found then process
* other rules using the lookup order. If no other rule matches then do
* ephemeral. Otherwise, based on the matched rule do Case 2 or 3 or 4.
* This allows us to specify a fallback unixname per _domain_ or no mapping
* instead of the default behaviour of doing ephemeral mapping.
*
* Example 1:
* *@sfbay == *
* If looking up windows users foo@sfbay and foo does not exists in
* the name service then foo@sfbay will be mapped to an ephemeral id.
*
* Example 2:
* *@sfbay == *
* *@sfbay => guest
* If looking up windows users foo@sfbay and foo does not exists in
* the name service then foo@sfbay will be mapped to guest.
*
* Example 3:
* *@sfbay == *
* *@sfbay => ""
* If looking up windows users foo@sfbay and foo does not exists in
* the name service then we will return no mapping for foo@sfbay.
*
*/
static
{
const char **values;
int direction;
const char *me = "name_based_mapping_sid2pid";
case IDMAP_USID:
is_wuser = 1;
break;
case IDMAP_GSID:
is_wuser = 0;
break;
default:
"given Windows id is user or group.", me);
return (IDMAP_ERR_INTERNAL);
}
case IDMAP_UID:
is_user = 1;
break;
case IDMAP_GID:
is_user = 0;
break;
case IDMAP_POSIXID:
break;
}
i = 0;
windomain = "";
i = 1;
"SELECT unixname, u2w_order, winname_display, windomain, is_nt4 "
"FROM namerules WHERE "
"w2u_order > 0 AND is_user = %d AND is_wuser = %d AND "
"(winname = %Q OR winname = '*') AND "
"(windomain = %Q OR windomain = '*' %s) "
"ORDER BY w2u_order ASC;",
i ? "OR windomain ISNULL OR windomain = ''" : "");
goto out;
}
CHECK_NULL(errmsg));
goto out;
}
for (;;) {
if (r == SQLITE_ROW) {
if (ncol < 5) {
goto out;
}
goto out;
}
else
if (EMPTY_NAME(values[0])) {
goto out;
}
if (values[0][0] == '*') {
} else {
}
if (retcode == IDMAP_ERR_NOTFOUND) {
if (values[0][0] == '*')
/* Case 4 */
continue;
else {
/* Case 3 */
}
}
goto out;
} else if (r == SQLITE_DONE) {
goto out;
} else {
CHECK_NULL(errmsg));
goto out;
}
}
out:
if (retcode == IDMAP_SUCCESS) {
else
}
}
if (retcode == IDMAP_SUCCESS) {
}
return (retcode);
}
static
int
{
int err;
return (err);
}
return (0);
}
static
int
{
int err;
return (err);
}
return (0);
}
static
int
{
return (0);
}
}
}
static
int
{
return (0);
return (1);
}
}
return (0);
}
static
void
{
next++;
}
return;
}
void
{
}
/* ARGSUSED */
static
{
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
if (get_next_eph_uid(&next_pid) != 0)
return (IDMAP_ERR_INTERNAL);
} else {
if (get_next_eph_gid(&next_pid) != 0)
return (IDMAP_ERR_INTERNAL);
}
return (IDMAP_SUCCESS);
}
{
/* Check if second pass is needed */
/* Get status from previous pass */
if (retcode != IDMAP_SUCCESS)
goto out;
/*
* If directory-based name mapping is enabled then the unixname
* may already have been retrieved from the AD object (AD-mode or
* mixed-mode) or from native LDAP object (nldap-mode) -- done.
*/
/*
* Special case: (1) If the ad_unixuser_attr and
* ad_unixgroup_attr uses the same attribute
* name and (2) if this is a diagonal mapping
* request and (3) the unixname has been retrieved
* from the AD object -- then we ignore it and fallback
* to name-based mapping rules and ephemeral mapping
*
* Example:
* Properties:
* config/ad_unixuser_attr = "unixname"
* config/ad_unixgroup_attr = "unixname"
* AD user object:
* dn: cn=bob ...
* objectclass: user
* sam: bob
* unixname: bob1234
* AD group object:
* dn: cn=winadmins ...
* objectclass: group
* sam: winadmins
* unixname: unixadmins
*
* In this example whether "unixname" refers to a unixuser
* or unixgroup depends upon the AD object.
*
* $idmap show -c winname:bob gid
* AD lookup by "samAccountName=bob" for
* "ad_unixgroup_attr (i.e unixname)" for directory-based
* mapping would get "bob1234" which is not what we want.
* Now why not getgrnam_r("bob1234") and use it if it
* is indeed a unixgroup? That's because Unix can have
* users and groups with the same name and we clearly
* don't know the intention of the admin here.
* Therefore we ignore this and fallback to name-based
* mapping rules or ephemeral mapping.
*/
state->ad_unixgroup_attr) == 0 &&
/* fallback */
} else {
/*
* If ns_lookup_byname() fails that means the
* unixname (req->id2name), which was obtained
* from the AD object by directory-based mapping,
* we return the error to the client instead of
* doing rule-based mapping or ephemeral mapping.
* This way the client can detect the issue.
*/
goto out;
}
}
/* Free any mapping info from Directory based mapping */
/*
* If we don't have unixname then evaluate local name-based
* mapping rules.
*/
if (retcode != IDMAP_ERR_NOTFOUND)
goto out;
/* If not found, do ephemeral mapping */
out:
}
return (retcode);
}
{
char *map_windomain = NULL;
char *map_winname = NULL;
char *map_unixname = NULL;
int map_is_nt4 = FALSE;
/* Check if we need to cache anything */
return (IDMAP_SUCCESS);
/* We don't cache negative entries */
return (IDMAP_SUCCESS);
case IDMAP_MAP_TYPE_DS_AD:
break;
case IDMAP_MAP_TYPE_DS_NLDAP:
break;
break;
case IDMAP_MAP_TYPE_EPHEMERAL:
break;
case IDMAP_MAP_TYPE_LOCAL_SID:
break;
default:
/* Dont cache other mapping types */
}
/*
* Using NULL for u2w instead of 0 so that our trigger allows
* the same pid to be the destination in multiple entries
*/
"(sidprefix, rid, windomain, canon_winname, pid, unixname, "
"is_user, is_wuser, expiration, w2u, u2w, "
"map_type, map_dn, map_attr, map_value, map_windomain, "
"map_winname, map_unixname, map_is_nt4) "
"VALUES(%Q, %u, %Q, %Q, %u, %Q, %d, %d, "
"strftime('%%s','now') + 600, %q, 1, "
"%d, %Q, %Q, %Q, %Q, %Q, %Q, %d); ",
goto out;
}
if (retcode != IDMAP_SUCCESS)
goto out;
/* Check if we need to update namecache */
goto out;
goto out;
"(sidprefix, rid, canon_name, domain, type, expiration) "
"VALUES(%Q, %u, %Q, %Q, %d, strftime('%%s','now') + 3600); ",
goto out;
}
out:
return (retcode);
}
{
int is_eph_user;
char *map_windomain = NULL;
char *map_winname = NULL;
char *map_unixname = NULL;
int map_is_nt4 = FALSE;
/* Check if we need to cache anything */
return (IDMAP_SUCCESS);
/* We don't cache negative entries */
return (IDMAP_SUCCESS);
is_eph_user = 1;
is_eph_user = 0;
else
is_eph_user = -1;
"SET w2u = 0 WHERE "
"sidprefix = %Q AND rid = %u AND w2u = 1 AND "
"pid >= 2147483648 AND is_user = %d;",
goto out;
}
if (retcode != IDMAP_SUCCESS)
goto out;
}
case IDMAP_MAP_TYPE_DS_AD:
break;
case IDMAP_MAP_TYPE_DS_NLDAP:
break;
break;
case IDMAP_MAP_TYPE_EPHEMERAL:
break;
default:
/* Dont cache other mapping types */
}
"(sidprefix, rid, windomain, canon_winname, pid, unixname, "
"is_user, is_wuser, expiration, w2u, u2w, "
"map_type, map_dn, map_attr, map_value, map_windomain, "
"map_winname, map_unixname, map_is_nt4) "
"VALUES(%Q, %u, %Q, %Q, %u, %Q, %d, %d, "
"strftime('%%s','now') + 600, 1, %q, "
"%d, %Q, %Q, %Q, %Q, %Q, %Q, %d);",
goto out;
}
if (retcode != IDMAP_SUCCESS)
goto out;
/* Check if we need to update namecache */
goto out;
goto out;
"(sidprefix, rid, canon_name, domain, type, expiration) "
"VALUES(%Q, %u, %Q, %Q, %d, strftime('%%s','now') + 3600); ",
goto out;
}
out:
return (retcode);
}
static
{
char *end;
const char **values;
int ncol;
/* Current time */
errno = 0;
goto out;
}
/* SQL to lookup the cache by pid or by unixname */
"canon_winname, windomain, w2u, is_wuser, "
"map_type, map_dn, map_attr, map_value, map_windomain, "
"map_winname, map_unixname, map_is_nt4 "
"FROM idmap_cache WHERE "
"pid = %u AND u2w = 1 AND is_user = %d AND "
"(pid >= 2147483648 OR "
"(expiration = 0 OR expiration ISNULL OR "
"expiration > %d));",
"canon_winname, windomain, w2u, is_wuser, "
"map_type, map_dn, map_attr, map_value, map_windomain, "
"map_winname, map_unixname, map_is_nt4 "
"FROM idmap_cache WHERE "
"unixname = %Q AND u2w = 1 AND is_user = %d AND "
"(pid >= 2147483648 OR "
"(expiration = 0 OR expiration ISNULL OR "
"expiration > %d));",
} else {
goto out;
}
goto out;
}
if (retcode == IDMAP_ERR_NOTFOUND)
goto out;
else if (retcode == IDMAP_SUCCESS) {
/* sanity checks */
goto out;
}
case IDMAP_SID:
case IDMAP_USID:
case IDMAP_GSID:
? IDMAP_USID : IDMAP_GSID;
idtype != IDMAP_USID) {
goto out;
idtype != IDMAP_GSID) {
goto out;
}
goto out;
}
else
break;
goto out;
}
break;
goto out;
}
break;
default:
break;
}
case IDMAP_MAP_TYPE_DS_AD:
break;
case IDMAP_MAP_TYPE_DS_NLDAP:
break;
break;
case IDMAP_MAP_TYPE_EPHEMERAL:
break;
case IDMAP_MAP_TYPE_LOCAL_SID:
break;
case IDMAP_MAP_TYPE_KNOWN_SID:
break;
default:
/* Unknow mapping type */
}
}
}
out:
return (retcode);
}
static
{
char *end, *lower_name;
const char **values;
int ncol;
/* Get current time */
errno = 0;
goto out;
}
/* SQL to lookup the cache */
lower_name = (char *)name;
"FROM name_cache WHERE name = %Q AND domain = %Q AND "
"(expiration = 0 OR expiration ISNULL OR "
if (lower_name != name)
goto out;
}
if (retcode == IDMAP_SUCCESS) {
goto out;
}
}
goto out;
}
goto out;
}
}
}
goto out;
}
}
out:
return (retcode);
}
static
char **unixname)
{
int retries = 0;
if (retcode != IDMAP_SUCCESS) {
goto retry;
"by winname");
return (retcode);
}
restore_svc();
if (retcode != IDMAP_SUCCESS)
else
goto retry;
else if (retcode == IDMAP_ERR_RETRIABLE_NET_ERR)
if (retcode != IDMAP_SUCCESS) {
return (retcode);
}
return (rc);
}
{
int type;
/* Lookup well-known SIDs table */
&type);
if (retcode == IDMAP_SUCCESS) {
goto out;
} else if (retcode != IDMAP_ERR_NOTFOUND) {
return (retcode);
}
/* Lookup cache */
if (retcode == IDMAP_SUCCESS) {
goto out;
} else if (retcode != IDMAP_ERR_NOTFOUND) {
return (retcode);
}
/*
* The caller may be using this function to determine if this
* request needs to be marked for AD lookup or not
* (i.e. _IDMAP_F_LOOKUP_AD) and therefore may not want this
* function to AD lookup now.
*/
if (local_only)
return (retcode);
/* Lookup AD */
if (retcode != IDMAP_SUCCESS)
return (retcode);
out:
/*
* Entry found (cache or Windows lookup)
* is_wuser is both input as well as output parameter
*/
else if (*is_wuser == -1) {
/* Caller wants to know if its user or group */
if (type == _IDMAP_T_USER)
*is_wuser = 1;
else if (type == _IDMAP_T_GROUP)
*is_wuser = 0;
else
}
if (retcode != IDMAP_SUCCESS) {
}
}
return (retcode);
}
static
{
char *canonname;
char *end;
const char **values;
int ncol, r;
int is_wuser;
const char *me = "name_based_mapping_pid2sid";
int non_wild_match = FALSE;
int direction;
"SELECT winname_display, windomain, w2u_order, "
"is_wuser, unixname, is_nt4 "
"FROM namerules WHERE "
"u2w_order > 0 AND is_user = %d AND "
"(unixname = %Q OR unixname = '*') "
goto out;
}
CHECK_NULL(errmsg));
goto out;
}
for (;;) {
if (r == SQLITE_ROW) {
if (ncol < 6) {
goto out;
}
/* values [1] and [2] can be null */
goto out;
}
else
if (EMPTY_NAME(values[0])) {
goto out;
}
if (values[0][0] == '*') {
if (non_wild_match) {
/*
* There were non-wildcard rules
* where the Windows identity doesn't
* exist. Return no mapping.
*/
goto out;
}
} else {
/* Save first non-wild match rule */
if (!non_wild_match) {
}
}
: -1;
else {
goto out;
}
if (retcode == IDMAP_ERR_NOTFOUND) {
continue;
}
goto out;
} else if (r == SQLITE_DONE) {
/*
* If there were non-wildcard rules where
* Windows identity doesn't exist
* return no mapping.
*/
if (non_wild_match)
else
goto out;
} else {
CHECK_NULL(errmsg));
goto out;
}
}
out:
if (retcode == IDMAP_SUCCESS) {
else
}
}
if (retcode == IDMAP_SUCCESS) {
}
return (retcode);
}
/*
* Convention when processing unix2win requests:
*
* Unix identity:
* req->id1name =
* unixname if given otherwise unixname found will be placed
* here.
* req->id1domain =
* NOT USED
* req->id1.idtype =
* Given type (IDMAP_UID or IDMAP_GID)
* req->id1..[uid or gid] =
*
* Windows identity:
* req->id2name =
* winname found will be placed here.
* req->id2domain =
* windomain found will be placed here.
* res->id.idtype =
* Target type initialized from req->id2.idtype. If
* it is IDMAP_SID then actual type (IDMAP_USID/GSID) found
* will be placed here.
* req->id..sid.[prefix, rid] =
* SID found will be placed here.
*
* Others:
* res->retcode =
* Return status for this request will be placed here.
* res->direction =
* Direction found will be placed here. Direction
* meaning whether the resultant mapping is valid
* only from unix2win or bi-directional.
* req->direction =
* INTERNAL USE. Used by idmapd to set various
* flags (_IDMAP_F_xxxx) to aid in processing
* of the request.
* req->id2.idtype =
* INTERNAL USE. Initially this is the requested target
* type and is used to initialize res->id.idtype.
* ad_lookup_batch() uses this field temporarily to store
* sid_type obtained by the batched AD lookups and after
* use resets it to IDMAP_NONE to prevent xdr from
* mis-interpreting the contents of req->id2.
* req->id2..[uid or gid or sid] =
* NOT USED
*/
/*
* This function does the following:
* 1. Lookup well-known SIDs table.
* 2. Lookup cache.
* 3. Check if the client does not want new mapping to be allocated
* in which case this pass is the final pass.
*/
{
/* Initialize result */
/* sanitize sidprefix */
}
/* Find pid */
!= IDMAP_SUCCESS) {
goto out;
}
}
/* Lookup well-known SIDs table */
if (retcode != IDMAP_ERR_NOTFOUND)
goto out;
/* Lookup cache */
getname);
if (retcode != IDMAP_ERR_NOTFOUND)
goto out;
/* Ephemeral ids cannot be allocated during pid2sid */
goto out;
}
if (DO_NOT_ALLOC_NEW_ID_MAPPING(req)) {
goto out;
}
if (AVOID_NAMESERVICE(req)) {
goto out;
}
/* Set flags for the next stage */
/*
* If AD-based name mapping is enabled then the next stage
* will need to lookup AD using unixname to get the
* corresponding winname.
*/
/* Get unixname if only pid is given. */
if (retcode != IDMAP_SUCCESS) {
goto out;
}
}
state->ad_nqueries++;
/*
* If native LDAP or mixed mode is enabled for name mapping
* then the next stage will need to lookup native LDAP using
*/
state->nldap_nqueries++;
}
/*
* Failed to find non-expired entry in cache. Set the flag to
* indicate that we are not done yet.
*/
out:
if (gen_localsid_on_err == TRUE)
return (retcode);
}
{
/* Check if second pass is needed */
/* Get status from previous pass */
if (retcode != IDMAP_SUCCESS)
goto out;
/*
* If directory-based name mapping is enabled then the winname
* may already have been retrieved from the AD object (AD-mode)
* or from native LDAP object (nldap-mode or mixed-mode).
* Note that if we have winname but no SID then it's an error
* because this implies that the Native LDAP entry contains
* winname which does not exist and it's better that we return
* an error instead of doing rule-based mapping so that the user
* can detect the issue and take appropriate action.
*/
/* Return notfound if we've winname but no SID. */
goto out;
}
goto out;
/*
* We've SID but no winname. This is fine because
* the caller may have only requested SID.
*/
goto out;
}
/* Free any mapping info from Directory based mapping */
/* Get unixname from name service */
if (retcode != IDMAP_SUCCESS)
goto out;
/* Get pid from name service */
if (retcode != IDMAP_SUCCESS) {
goto out;
}
}
/* Use unixname to evaluate local name-based mapping rules */
if (retcode == IDMAP_ERR_NOTFOUND) {
}
out:
if (gen_localsid_on_err == TRUE)
else
}
return (retcode);
}
static
int
{
goto errout;
}
} else {
}
goto errout;
}
goto errout;
}
/* We don't need the rest of the request i.e request->id2 */
return (0);
return (-1);
}
{
char *cp;
/* Get directory-based name mapping info */
if (retcode != IDMAP_SUCCESS)
goto out;
/*
* Copy data from "request" to "mapping". Note that
* empty strings are not copied from "request" to
* "mapping" and therefore the coresponding strings in
* "mapping" will be NULL. This eliminates having to
* check for empty strings henceforth.
*/
goto out;
}
goto out;
}
/* Need atleast winname or sid to proceed */
goto out;
}
/*
* If domainname is not given but we have a fully qualified
* winname then extract the domainname from the winname,
* otherwise use the default_domain from the config
*/
*cp = '\0';
NULL) != IDMAP_SUCCESS) {
/*
* We have a non-qualified winname which is
* neither the name of a well-known SID nor
* there is a default domain with which we can
* qualify it.
*/
} else {
}
}
if (retcode != IDMAP_SUCCESS)
goto out;
}
/*
* First pass looks up the well-known SIDs table and cache
* and handles localSIDs
*/
goto out;
/* AD lookup */
if (state.ad_nqueries > 0) {
if (IDMAP_ERROR(retcode))
goto out;
}
/* nldap lookup */
if (state.nldap_nqueries > 0) {
if (IDMAP_FATAL_ERROR(retcode))
goto out;
}
/* Next pass performs name-based mapping and ephemeral mapping. */
goto out;
/* Update cache */
out:
/*
* Note that "mapping" is returned to the client. Therefore
* copy whatever we have in "idres" to mapping->id2 and
* free idres.
*/
retcode != IDMAP_SUCCESS)
else
if (retcode != IDMAP_SUCCESS)
return (retcode);
}
{
/*
* In order to re-use the pid2sid code, we convert
* our input data into structs that are expected by
* pid2sid_first_pass.
*/
/* Get directory-based name mapping info */
if (retcode != IDMAP_SUCCESS)
goto out;
/*
* Copy data from "request" to "mapping". Note that
* empty strings are not copied from "request" to
* "mapping" and therefore the coresponding strings in
* "mapping" will be NULL. This eliminates having to
* check for empty strings henceforth.
*/
goto out;
}
/*
* For unix to windows mapping request, we need atleast a
*/
goto out;
}
/* First pass looks up cache and well-known SIDs */
goto out;
/* nldap lookup */
if (state.nldap_nqueries > 0) {
if (IDMAP_FATAL_ERROR(retcode))
goto out;
}
/* AD lookup */
if (state.ad_nqueries > 0) {
if (IDMAP_FATAL_ERROR(retcode))
goto out;
}
/*
* It returns if there's nothing more to be done otherwise it
* evaluates local name-based mapping rules
*/
goto out;
/* Update cache */
out:
/*
* Note that "mapping" is returned to the client. Therefore
* copy whatever we have in "idres" to mapping->id2 and
* free idres.
*/
retcode != IDMAP_SUCCESS)
else
return (retcode);
}
/*ARGSUSED*/
static
{
}