idmap_api.c revision 9581d9f4f3b1515f88149f920c7e786b4fb901d4
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* libidmap API
*/
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <strings.h>
#include <ctype.h>
#include <dlfcn.h>
#include <libintl.h>
#include "idmap_impl.h"
static int idmap_stat2errno(idmap_stat);
return (IDMAP_ERR_ARG);\
}\
return (IDMAP_ERR_MEMORY);\
}\
return (IDMAP_ERR_MEMORY);\
}\
if (argu) {\
}\
if (itera)\
return (iretcod);
return (IDMAP_ERR_ARG);\
}\
return (IDMAP_ERR_ARG);\
}
/*
* Free memory allocated by libidmap API
*
* Input:
* ptr - memory to be freed
*/
void
idmap_free(void *ptr) {
}
/*
*
* Output:
* handle - idmap handle
*/
struct idmap_handle *hptr;
return (IDMAP_ERR_MEMORY);
return (IDMAP_ERR_RPC);
}
return (IDMAP_SUCCESS);
}
/*
* Finalize idmap handle
*
* Input:
* handle - idmap handle
*/
struct idmap_handle *hptr;
return (IDMAP_SUCCESS);
case _IDMAP_HANDLE_RPC_DOORS:
if (clnt) {
}
break;
default:
break;
}
return (IDMAP_SUCCESS);
}
/*
* Create/Initialize handle for updates
*
* Output:
* udthandle - update handle
*/
return (IDMAP_ERR_ARG);
}
return (IDMAP_ERR_MEMORY);
}
return (IDMAP_SUCCESS);
}
/*
* All the updates specified by the update handle are committed
* in a single transaction. i.e either all succeed or none.
*
* Input:
* udthandle - update handle with the update requests
*
* Return value:
* Status of the commit
*/
return (IDMAP_ERR_ARG);
}
TIMEOUT);
if (clntstat != RPC_SUCCESS) {
return (IDMAP_ERR_RPC);
}
if (retcode != IDMAP_SUCCESS)
return (retcode);
}
/*
* Destroy the update handle
*/
void
return;
}
if (retcode != IDMAP_SUCCESS)
goto errout;
if (windomain) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (winname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (unixname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
return (IDMAP_SUCCESS);
return (retcode);
}
/* ARGSUSED */
if (retcode != IDMAP_SUCCESS)
goto errout;
if (windomain) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (winname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (unixname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
return (IDMAP_SUCCESS);
return (retcode);
}
/* ARGSUSED */
if (retcode != IDMAP_SUCCESS)
goto errout;
return (IDMAP_SUCCESS);
return (retcode);
}
/*
* Set the number of entries requested per batch by the iterator
*
* Input:
* iter - iterator
* limit - number of entries requested per batch
*/
return (IDMAP_ERR_ARG);
}
return (IDMAP_SUCCESS);
}
/*
* Create iterator to get name-based mapping rules
*
* Input:
* windomain - Windows domain
* is_user - user or group rules
* winname - Windows user or group name
* unixname - Unix user or group name
*
* Output:
* iter - iterator
*/
if (windomain) {
if (retcode != IDMAP_SUCCESS) {
goto errout;
}
}
if (winname) {
if (retcode != IDMAP_SUCCESS) {
goto errout;
}
}
if (unixname) {
if (retcode != IDMAP_SUCCESS) {
goto errout;
}
}
return (IDMAP_SUCCESS);
}
/*
* Iterate through the name-based mapping rules
*
* Input:
* iter - iterator
*
* Output:
* windomain - Windows domain
* winname - Windows user or group name
* unixname - Unix user or group name
* is_nt4 - NT4 or AD
* direction - bi(0), win2unix(1), unix2win(2)
*
* Return value:
* 0 - done
* 1 - more results available
* < 0 - error
*/
int *direction) {
if (windomain)
if (winname)
if (unixname)
if (is_nt4)
*is_nt4 = 0;
if (direction)
*direction = -1;
return (IDMAP_ERR_ARG);
}
if (retcode != IDMAP_SUCCESS)
return (retcode);
return (retcode);
}
}
return (IDMAP_SUCCESS);
return (IDMAP_ERR_ARG);
}
if (windomain) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (winname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (unixname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (is_nt4)
if (direction)
else
return (IDMAP_NEXT);
return (retcode);
}
/*
*
* Input:
* is_user - user or group
*
* Output:
* iter - iterator
*/
idmap_iter_t **iter) {
return (IDMAP_SUCCESS);
}
/*
*
* Input:
* iter - iterator
*
* Output:
* sid - SID in canonical form
* pid - UID or GID
*
* Return value:
* 0 - done
* 1 - more results available
* < 0 - error
*/
char *str;
if (sidprefix)
if (rid)
*rid = UINT32_MAX;
if (winname)
if (windomain)
if (unixname)
if (pid)
*pid = UINT32_MAX;
if (direction)
*direction = -1;
return (IDMAP_ERR_ARG);
}
if (retcode != IDMAP_SUCCESS)
return (retcode);
return (retcode);
}
}
return (IDMAP_SUCCESS);
return (IDMAP_ERR_ARG);
}
if (sidprefix) {
if (str) {
goto errout;
}
}
}
if (rid)
if (winname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (windomain) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (unixname) {
if (retcode != IDMAP_SUCCESS)
goto errout;
}
if (pid)
if (direction)
else
return (IDMAP_NEXT);
return (retcode);
}
/*
* Destroy the iterator
*/
void
return;
case IDMAP_LIST_NAMERULES:
break;
case IDMAP_LIST_MAPPINGS:
break;
default:
return;
};
}
}
}
/*
*
* Input:
* gh - "get mapping" handle
*/
/* sanity checks */
return (IDMAP_ERR_ARG);
}
/* allocate the handle */
return (IDMAP_ERR_MEMORY);
}
return (IDMAP_SUCCESS);
}
/*
* Given SID, get UID
*
* Input:
* sidprefix - SID prefix
* rid - RID
* flag - flag
*
* Output:
* stat - status of the get request
* uid - POSIX UID if stat = 0
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
/* sanity checks */
return (IDMAP_ERR_ARG);
return (IDMAP_ERR_ARG);
/* Extend the request array and the return list */
goto errout;
/* Setup the request */
goto errout;
}
/* Setup pointers for the result */
return (IDMAP_SUCCESS);
return (retcode);
}
/*
* Given SID, get GID
*
* Input:
* sidprefix - SID prefix
* rid - rid
* flag - flag
*
* Output:
* stat - status of the get request
* gid - POSIX GID if stat = 0
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
/* sanity checks */
return (IDMAP_ERR_ARG);
return (IDMAP_ERR_ARG);
/* Extend the request array and the return list */
goto errout;
/* Setup the request */
goto errout;
}
/* Setup pointers for the result */
return (IDMAP_SUCCESS);
return (retcode);
}
/*
*
* Input:
* sidprefix - SID prefix
* rid - rid
* flag - flag
*
* Output:
* stat - status of the get request
* is_user - user or group
* pid - POSIX UID if stat = 0 and is_user = 1
* POSIX GID if stat = 0 and is_user = 0
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
/* sanity checks */
return (IDMAP_ERR_ARG);
return (IDMAP_ERR_ARG);
/* Extend the request array and the return list */
goto errout;
/* Setup the request */
goto errout;
}
/* Setup pointers for the result */
return (IDMAP_SUCCESS);
return (retcode);
}
/*
* Given UID, get SID
*
* Input:
* uid - POSIX UID
* flag - flag
*
* Output:
* stat - status of the get request
* sid - SID prefix (if stat == 0)
* rid - rid
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
/* sanity checks */
return (IDMAP_ERR_ARG);
return (IDMAP_ERR_ARG);
/* Extend the request array and the return list */
goto errout;
/* Setup the request */
/* Setup pointers for the result */
return (IDMAP_SUCCESS);
return (retcode);
}
/*
* Given GID, get SID
*
* Input:
* gid - POSIX GID
* flag - flag
*
* Output:
* stat - status of the get request
* sidprefix - SID prefix (if stat == 0)
* rid - rid
*
* Note: The output parameters will be set by idmap_get_mappings()
*/
/* sanity checks */
return (IDMAP_ERR_ARG);
return (IDMAP_ERR_ARG);
/* Extend the request array and the return list */
goto errout;
/* Setup the request */
/* Setup pointers for the result */
return (IDMAP_SUCCESS);
return (retcode);
}
/*
* Process the batched "get mapping" requests. The results (i.e.
* status and identity) will be available in the data areas
* provided by individual requests.
*/
int i;
return (IDMAP_ERR_ARG);
}
TIMEOUT);
if (clntstat != RPC_SUCCESS) {
goto out;
}
goto out;
}
continue;
}
case IDMAP_UID:
break;
case IDMAP_GID:
break;
case IDMAP_SID:
break;
}
}
break;
case IDMAP_NONE:
break;
default:
break;
}
}
out:
return (retcode);
}
/*
* Destroy the "get mapping" handle
*/
void
return;
}
/*
* Get windows to unix mapping
*/
return (IDMAP_ERR_ARG);
}
if (pid)
*pid = UINT32_MAX;
if (unixname)
if (direction)
*direction = -1;
} else if (winname) {
if (retcode != IDMAP_SUCCESS)
goto out;
if (windomain) {
if (retcode != IDMAP_SUCCESS)
return (retcode);
}
} else {
return (IDMAP_ERR_ARG);
}
else if (*is_user == 1)
else if (*is_user == 0)
else
TIMEOUT);
if (clntstat != RPC_SUCCESS) {
return (IDMAP_ERR_RPC);
}
if (retcode == IDMAP_SUCCESS)
goto out;
}
if (is_user)
if (direction)
if (pid)
if (unixname) {
if (rc != IDMAP_SUCCESS)
}
out:
if (retcode != IDMAP_SUCCESS)
return (retcode);
}
/*
* Get unix to windows mapping
*/
int *direction) {
return (IDMAP_ERR_ARG);
}
if (sidprefix)
if (winname)
if (windomain)
if (rid)
*rid = UINT32_MAX;
if (direction)
*direction = -1;
} else if (unixname) {
if (retcode != IDMAP_SUCCESS)
goto out;
} else {
return (IDMAP_ERR_ARG);
}
TIMEOUT);
if (clntstat != RPC_SUCCESS) {
return (IDMAP_ERR_RPC);
}
if (retcode == IDMAP_SUCCESS)
goto out;
}
if (direction)
if (sidprefix) {
goto errout;
}
}
if (rid)
if (winname) {
if (rc != IDMAP_SUCCESS) {
goto errout;
}
}
if (windomain) {
if (rc != IDMAP_SUCCESS) {
goto errout;
}
}
goto out;
}
}
}
out:
if (retcode != IDMAP_SUCCESS)
return (retcode);
}
/*
* utf8str to string
*/
int len;
return (IDMAP_ERR_ARG);
if (outsize == 0) {
return (IDMAP_SUCCESS);
return (IDMAP_ERR_ARG);
len++;
return (IDMAP_ERR_MEMORY);
} else {
return (IDMAP_ERR_ARG);
return (IDMAP_SUCCESS);
return (IDMAP_ERR_ARG);
len++;
return (IDMAP_ERR_ARG);
}
return (IDMAP_SUCCESS);
}
/*
* string to utf8str
*/
return (IDMAP_ERR_ARG);
return (IDMAP_ERR_MEMORY);
} else {
}
tmp->idmap_utf8str_len = 0;
return (IDMAP_SUCCESS);
}
/* include the null terminator */
if (flag == 1) {
/* Don't malloc, simply assign */
return (IDMAP_SUCCESS);
}
tmp->idmap_utf8str_len = 0;
return (IDMAP_ERR_MEMORY);
}
return (IDMAP_SUCCESS);
}
#define gettext(s) s
static stat_table_t stattable[] = {
{-1, NULL, 0}
};
/*
* Get description of status code
*
* Input:
* status - Status code returned by libidmap API call
*
* Return Value:
* human-readable localized description of idmap_stat
*/
/* ARGSUSED */
const char *
int i;
}
return (gettext("Unknown error"));
}
static int
int i;
}
return (EINVAL);
}
/*
* Get status code from string
*/
idmap_string2stat(const char *str) {
return (IDMAP_ERR_INTERNAL);
#define return_cmp(a) \
return (IDMAP_ERR_ ## a);
return_cmp(DB);
return (IDMAP_ERR_OTHER);
}
/*
* Map the given status to one that can be returned by the protocol
*/
switch (status) {
case IDMAP_ERR_MEMORY:
case IDMAP_ERR_CACHE:
return (IDMAP_ERR_INTERNAL);
}
return (status);
}