idmap_kapi.c revision 9d0aba9223380be5042b63aef9767fa367b2a2ec
/*
* 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.
*/
/*
* Windows to Solaris Identity Mapping kernel API
* This module provides an API to map Windows SIDs to
* Solaris UID and GIDs.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <rpc/rpc_sztypes.h>
#ifdef DEBUG
#endif /* DEBUG */
#include <sys/sysmacros.h>
#include "idmap_prot.h"
#include "kidmap_priv.h"
/*
* Defined types
*/
/*
* This structure holds pointers for the
* batch mapping results.
*/
typedef struct idmap_get_res {
int *is_user;
const char **sid_prefix;
/* Batch mapping handle structure */
struct idmap_get_handle {
struct idmap_zone_specific *zs;
int mapping_num;
int mapping_size;
};
/* Zone specific data */
typedef struct idmap_zone_specific {
int door_valid;
/*
* Module global data
*/
static kmutex_t idmap_zone_mutex;
static zone_key_t idmap_zone_key;
/*
* Local function definitions
*/
static int
static int
static idmap_zone_specific_t *
int
{
if (zs->door_valid)
return (0);
}
/*
* idmap_unreg_dh
*
* This routine is called by system call idmap_unreg().
* idmap_unreg() calls door_ki_rele() on the supplied
* door handle after this routine returns. We only
* need to perform one door release on zs->door_handle
*/
int
{
if (!zs->door_valid) {
return (EINVAL);
}
return (EINVAL);
}
zs->door_valid = 0;
return (0);
}
static int
{
int status = 0;
if (!zs->door_valid) {
return (-1);
}
#ifdef DEBUG
if (status != 0)
#endif /* DEBUG */
/*
* If we get EBADF we will most likely not get an
* idmap_unreg_dh().
*/
if (zs->door_valid) {
zs->door_valid = 0;
}
}
return (status);
}
static idmap_zone_specific_t *
{
return (zs);
return (zs);
}
return (zs);
}
static void
/* ARGSUSED */
{
if (zs->door_valid) {
}
}
}
int
kidmap_start(void)
{
return (0);
}
int
kidmap_stop(void)
{
return (EBUSY);
}
/*
* idmap_get_door
*
* This is called by the system call allocids() to get the door for the
* given zone.
*/
{
if (zs->door_valid) {
}
return (dh);
}
/*
* idmap_purge_cache
*
* This is called by the system call allocids() to purge the cache for the
* given zone.
*/
void
{
}
/*
* Given Domain SID and RID, get UID
*
* Input:
* sid_prefix - Domain SID in canonical form
* rid - RID
*
* Output:
* uid - POSIX UID if return == IDMAP_SUCCESS
*
* Return:
* Success return IDMAP_SUCCESS else IDMAP error
*/
{
const char *new_sid_prefix;
return (IDMAP_ERR_ARG);
== IDMAP_SUCCESS)
return (IDMAP_SUCCESS);
/* Door call succeded */
*uid = UID_NOBODY;
if (status == IDMAP_SUCCESS) {
}
} else {
*uid = UID_NOBODY;
}
} else {
/* Door call failed */
*uid = UID_NOBODY;
}
return (status);
}
/*
* Given Domain SID and RID, get GID
*
* Input:
* sid_prefix - Domain SID in canonical form
* rid - RID
*
* Output:
* gid - POSIX UID if return == IDMAP_SUCCESS
*
* Return:
* Success return IDMAP_SUCCESS else IDMAP error
*/
{
const char *new_sid_prefix;
return (IDMAP_ERR_ARG);
== IDMAP_SUCCESS)
return (IDMAP_SUCCESS);
/* Door call succeded */
*gid = GID_NOBODY;
if (status == IDMAP_SUCCESS) {
}
} else {
*gid = GID_NOBODY;
}
} else {
/* Door call failed */
*gid = GID_NOBODY;
}
return (status);
}
/*
* Given Domain SID and RID, get Posix ID
*
* Input:
* sid_prefix - Domain SID in canonical form
* rid - RID
*
* Output:
* pid - POSIX ID if return == IDMAP_SUCCESS
* is_user - 1 == UID, 0 == GID if return == IDMAP_SUCCESS
*
* Return:
* Success return IDMAP_SUCCESS else IDMAP error
*/
{
const char *new_sid_prefix;
return (IDMAP_ERR_ARG);
is_user) == IDMAP_SUCCESS)
return (IDMAP_SUCCESS);
/* Door call succeded */
*is_user = 1;
*pid = UID_NOBODY;
*is_user = 1;
} else {
*is_user = 0;
}
if (status == IDMAP_SUCCESS) {
*is_user);
}
} else {
*is_user = 1;
*pid = UID_NOBODY;
}
} else {
/* Door call failed */
*is_user = 1;
*pid = UID_NOBODY;
}
return (status);
}
/*
* Given UID, get Domain SID and RID
*
* Input:
* uid - Posix UID
*
* Output:
* sid_prefix - Domain SID if return == IDMAP_SUCCESS
* rid - RID if return == IDMAP_SUCCESS
*
* Return:
* Success return IDMAP_SUCCESS else IDMAP error
*/
{
return (IDMAP_ERR_ARG);
== IDMAP_SUCCESS) {
return (IDMAP_SUCCESS);
}
/* Door call succeded */
*rid = 0;
*sid_prefix = NULL;
if (status == IDMAP_SUCCESS) {
}
} else {
*rid = 0;
*sid_prefix = NULL;
}
} else {
/* Door call failed */
*rid = 0;
*sid_prefix = NULL;
}
return (status);
}
/*
* Given GID, get Domain SID and RID
*
* Input:
* gid - Posix GID
*
* Output:
* sid_prefix - Domain SID if return == IDMAP_SUCCESS
* rid - RID if return == IDMAP_SUCCESS
*
* Return:
* Success return IDMAP_SUCCESS else IDMAP error
*/
{
return (IDMAP_ERR_ARG);
== IDMAP_SUCCESS) {
return (IDMAP_SUCCESS);
}
/* Door call succeded */
*rid = 0;
*sid_prefix = NULL;
if (status == IDMAP_SUCCESS) {
}
} else {
*rid = 0;
*sid_prefix = NULL;
}
} else {
/* Door call failed */
*rid = 0;
*sid_prefix = NULL;
}
return (status);
}
/*
*
* Input:
* none
* Return:
* get_handle
*
*/
{
#define INIT_MAPPING_SIZE 32
return (handle);
}
/*
* Internal routine to extend a "get_handle"
*/
static void
{
}
/*
* Given Domain SID and RID, get UID
*
* Input:
* sid_prefix - Domain SID in canonical form
* rid - RID
*
* Output:
* stat - status of the get request
* uid - POSIX UID if stat == IDMAP_SUCCESS
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
{
return (IDMAP_ERR_ARG);
*stat = IDMAP_SUCCESS;
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
/*
* Given Domain SID and RID, get GID
*
* Input:
* sid_prefix - Domain SID in canonical form
* rid - RID
*
* Output:
* stat - status of the get request
* gid - POSIX GID if stat == IDMAP_SUCCESS
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
{
return (IDMAP_ERR_ARG);
*stat = IDMAP_SUCCESS;
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
/*
* Given Domain SID and RID, get Posix ID
*
* Input:
* sid_prefix - Domain SID in canonical form
* rid - RID
*
* Output:
* stat - status of the get request
* is_user - user or group
* pid - POSIX UID if stat == IDMAP_SUCCESS and is_user == 1
* POSIX GID if stat == IDMAP_SUCCESS and is_user == 0
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
{
return (IDMAP_ERR_ARG);
*stat = IDMAP_SUCCESS;
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
/*
* Given UID, get SID and RID
*
* Input:
* uid - POSIX UID
*
* Output:
* stat - status of the get request
* sid - SID in canonical form (if stat == IDMAP_SUCCESS)
* rid - RID (if stat == IDMAP_SUCCESS)
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
{
return (IDMAP_ERR_ARG);
*stat = IDMAP_SUCCESS;
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
/*
* Given GID, get SID and RID
*
* Input:
* gid - POSIX GID
*
* Output:
* stat - status of the get request
* sid - SID in canonical form (if stat == IDMAP_SUCCESS)
* rid - RID (if stat == IDMAP_SUCCESS)
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
{
return (IDMAP_ERR_ARG);
*stat = IDMAP_SUCCESS;
return (IDMAP_SUCCESS);
}
return (IDMAP_SUCCESS);
}
/*
* Process the batched "get mapping" requests. The results (i.e.
* status and identity) will be available in the data areas
* provided by individual requests.
*
* If the door call fails the status IDMAP_ERR_NOMAPPING is
* return and the UID or UID result is set to "nobody"
*/
{
int status;
int i;
const char *sid_prefix;
int is_user;
if (get_handle == NULL)
return (IDMAP_ERR_ARG);
if (get_handle->mapping_num == 0)
return (IDMAP_SUCCESS);
/* Door call failed */
goto error;
}
if (status != IDMAP_SUCCESS) {
/* RPC returned idmap error code */
goto error;
}
for (i = 0; i < get_handle->mapping_num; i++) {
if (result->sid_prefix)
continue;
}
case IDMAP_UID:
break;
case IDMAP_GID:
break;
case IDMAP_SID:
case IDMAP_USID:
case IDMAP_GSID:
}
break;
default:
if (result->sid_prefix)
break;
}
}
/* Reset get_handle for new resquests */
get_handle->mapping_num = 0;
return (status);
for (i = 0; i < get_handle->mapping_num; i++) {
if (result->sid_prefix)
}
/* Reset get_handle for new resquests */
get_handle->mapping_num = 0;
return (status);
}
/*
* Destroy the "get mapping" handle
*/
void
{
if (get_handle == NULL)
return;
}
static int
{
char *outbuf_ptr = NULL;
int status = 0;
int retry = 0;
#ifdef DEBUG
#endif /* DEBUG */
status = -1;
goto exit;
}
/* Auth none */
/* RPC args */
#ifdef DEBUG
#endif /* DEBUG */
if (retry > 2) {
status = -1;
goto exit;
}
retry++;
if (inbuf_ptr) {
}
if (outbuf_ptr) {
outbuf_ptr = NULL;
}
#ifdef DEBUG
#endif /* DEBUG */
status = -1;
goto exit;
}
goto retry;
}
status = -1;
goto exit;
}
status = -1;
goto exit;
}
} else {
#ifdef DEBUG
#endif /* DEBUG */
status = -1;
}
exit:
if (inbuf_ptr)
if (outbuf_ptr)
return (status);
}