/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <strings.h>
extern int smb_pwd_num(void);
extern int smb_lgrp_numbydomain(smb_domain_type_t, int *);
/*
* Local well-known accounts data structure table and prototypes
*/
typedef struct smb_lwka {
char *lwka_name;
} smb_lwka_t;
};
static smb_lwka_t *smb_lwka_lookup_name(char *);
/*
* Looks up the given name in local account databases:
*
* SMB Local groups are looked up in /var/smb/smbgroup.db
*
* If the account is found, its information is populated
* in the passed smb_account_t structure. Caller must free
* allocated memories by calling smb_account_free() upon
* successful return.
*
* The type of account is specified by 'type', which can be user,
* alias (local group) or unknown. If the caller doesn't know
* whether the name is a user or group name then SidTypeUnknown
* should be passed.
*
* If a local user and group have the same name, the user will
* always be picked. Note that this situation cannot happen on
* Windows systems.
*
* failed and NT_STATUS_NONE_MAPPED is returned.
*
* Return status:
*
* NT_STATUS_NOT_FOUND This is not a local account
* NT_STATUS_NONE_MAPPED It's a local account but cannot be
* translated.
* other error status codes.
*/
{
return (NT_STATUS_NOT_FOUND);
/* Only Netbios hostname is accepted */
return (NT_STATUS_NONE_MAPPED);
} else {
return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
}
/* This is the local domain name */
if (!smb_account_validate(account)) {
return (NT_STATUS_NO_MEMORY);
}
return (NT_STATUS_SUCCESS);
}
} else {
switch (type) {
case SidTypeUser:
if (status != NT_STATUS_SUCCESS)
return (status);
break;
case SidTypeAlias:
if (status != NT_STATUS_SUCCESS)
return (status);
break;
case SidTypeUnknown:
type = SidTypeUser;
if (status == NT_STATUS_SUCCESS)
break;
if (status == NT_STATUS_NONE_MAPPED)
return (status);
type = SidTypeAlias;
if (status != NT_STATUS_SUCCESS)
return (status);
break;
default:
return (NT_STATUS_INVALID_PARAMETER);
}
}
if (!smb_account_validate(account)) {
return (NT_STATUS_NO_MEMORY);
}
return (NT_STATUS_SUCCESS);
}
/*
* Looks up the given SID in local account databases:
*
* SMB Local groups are looked up in /var/smb/smbgroup.db
*
* If the account is found, its information is populated
* in the passed smb_account_t structure. Caller must free
* allocated memories by calling smb_account_free() upon
* successful return.
*
* Return status:
*
* NT_STATUS_NOT_FOUND This is not a local account
* NT_STATUS_NONE_MAPPED It's a local account but cannot be
* translated.
* other error status codes.
*/
{
int id_type;
int rc;
return (NT_STATUS_CANT_ACCESS_DOMAIN_INFO);
/* This is the local domain SID */
if (!smb_account_validate(account)) {
return (NT_STATUS_NO_MEMORY);
}
return (NT_STATUS_SUCCESS);
}
/* This is not a local SID */
return (NT_STATUS_NOT_FOUND);
}
} else {
return (NT_STATUS_NONE_MAPPED);
switch (id_type) {
case SMB_IDMAP_USER:
return (NT_STATUS_NO_SUCH_USER);
break;
case SMB_IDMAP_GROUP:
if (rc != SMB_LGRP_SUCCESS)
return (NT_STATUS_NO_SUCH_ALIAS);
smb_lgrp_free(&grp);
break;
default:
return (NT_STATUS_NONE_MAPPED);
}
}
if (!smb_account_validate(account)) {
return (NT_STATUS_NO_MEMORY);
}
return (NT_STATUS_SUCCESS);
}
/*
* Returns number of SMB users, i.e. users who have entry
*/
int
smb_sam_usr_cnt(void)
{
return (smb_pwd_num());
}
/*
* Updates a list of groups in which the given user is a member
* by adding any local (SAM) groups.
*
* We are a member of local groups where the local group
* contains either the user's primary SID, or any of their
* other SIDs such as from domain groups, SID history, etc.
* We can have indirect membership via domain groups.
*/
{
/*
* First pass: count groups to be added (gcnt)
*/
gcnt = 0;
return (NT_STATUS_INTERNAL_ERROR);
break;
}
}
/* Careful: only count lgrp once */
if (member)
gcnt++;
}
if (gcnt == 0)
return (NT_STATUS_SUCCESS);
/*
* Second pass: add to groups list.
* Do not modify gcnt after here.
*/
return (NT_STATUS_INTERNAL_ERROR);
/*
* Expand the list (copy to a new, larger one)
* Note: were're copying pointers from the old
* array to the new (larger) array, and then
* adding new pointers after what we copied.
*/
ret = 0;
goto out;
}
/*
* Add group SIDs starting at the end of the
* previous list. (new_ids)
*/
break;
}
}
goto out;
}
new_ids++;
}
}
out:
if (ret != 0) {
/*
* Free only the new sids we added.
* The old ones were copied ptrs.
*/
}
}
return (ret);
}
/*
* Success! Update passed gids and
* free the old array.
*/
return (NT_STATUS_SUCCESS);
}
/*
* Returns the number of built-in or local groups stored
* in /var/smb/smbgroup.db
*/
int
{
int grpcnt;
int rc;
switch (dtype) {
case SMB_DOMAIN_BUILTIN:
break;
case SMB_DOMAIN_LOCAL:
break;
default:
}
}
/*
* Determines whether the given SID is a member of the group
* specified by gname.
*/
{
smb_lgrp_free(&grp);
}
return (ismember);
}
/*
* Frees memories allocated for the passed account fields.
*/
void
{
}
/*
* Validates the given account.
*/
{
}
/*
* if there's a match query its SID from idmap service and make
* sure the SID is a local SID.
*
* The memory for the returned SID must be freed by the caller.
*/
static uint32_t
{
return (NT_STATUS_NO_SUCH_USER);
!= IDMAP_SUCCESS)
return (NT_STATUS_NONE_MAPPED);
if (!smb_sid_islocal(*sid)) {
smb_sid_free(*sid);
return (NT_STATUS_NONE_MAPPED);
}
return (NT_STATUS_SUCCESS);
}
/*
* Lookup local SMB group account database (/var/smb/smbgroup.db)
* The memory for the returned SID must be freed by the caller.
*/
static uint32_t
{
return (NT_STATUS_NO_SUCH_ALIAS);
smb_lgrp_free(&grp);
}
static smb_lwka_t *
{
int i;
for (i = 0; i < SMB_LWKA_NUM; i++) {
return (&lwka_tbl[i]);
}
return (NULL);
}
static smb_lwka_t *
{
int i;
if (rid > 999)
return (NULL);
for (i = 0; i < SMB_LWKA_NUM; i++) {
return (&lwka_tbl[i]);
}
return (NULL);
}
/*
* smb_sid_islocal
*
* Check a SID to see if it belongs to the local domain.
*/
{
return (islocal);
}
void
{
int i;
}
}