/*
* 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 2015 Nexenta Systems, Inc. All rights reserved.
*/
#include <unistd.h>
#include <strings.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <syslog.h>
#include <assert.h>
#include <synch.h>
#include <smbsrv/libmlsvc.h>
#include <smbsrv/smb_token.h>
#include <lsalib.h>
smb_passwd_t *);
static void smb_guest_account(char *, size_t);
/* Consolidation private function from Network Repository */
extern int _getgroupsbymember(const char *, gid_t[], int, int);
static idmap_stat
{
int i;
return (IDMAP_ERR_ARG);
} else {
/* User SID */
if (stat != IDMAP_SUCCESS)
return (stat);
/* Owner SID */
if (stat != IDMAP_SUCCESS)
return (stat);
}
/* Primary Group SID */
if (stat != IDMAP_SUCCESS)
return (stat);
/* Other Windows Group SIDs */
if (stat != IDMAP_SUCCESS)
break;
}
return (stat);
}
/*
* smb_token_sids2ids
*
*
* Returns 0 upon success. Otherwise, returns -1.
*/
static int
{
int nmaps;
/*
* Number of idmap lookups: user SID, owner SID, primary group SID,
*/
else
if (stat != IDMAP_SUCCESS)
return (-1);
if (stat != IDMAP_SUCCESS) {
return (-1);
}
}
/*
* smb_token_create_pxgrps
*
* Setup the POSIX group membership of the access token if the given UID is
* a POSIX UID (non-ephemeral). Both the user's primary group and
* supplementary groups will be added to the POSIX group array of the access
* token.
*/
static smb_posix_grps_t *
{
return (NULL);
}
return (NULL);
return (pgrps);
}
return (NULL);
return (pgrps);
}
return (NULL);
}
/*
* Setup the groups starting at index 1 (the last arg)
* of gids array.
*/
if (num == -1) {
"to get user's supplementary groups");
num = 1;
}
if (pgrps) {
}
return (pgrps);
}
/*
* smb_token_destroy
*
* Release all of the memory associated with a token structure. Ensure
* that the token has been unlinked before calling.
*/
void
{
}
}
/*
* Token owner should be set to local Administrators group
* in two cases:
* 1. The logged on user is a member of Domain Admins group
*/
static void
{
#ifdef SMB_SUPPORT_GROUP_OWNER
} else {
}
#endif
}
static smb_privset_t *
{
int rc;
privs = smb_privset_new();
return (NULL);
return (NULL);
}
smb_lgrp_free(&grp);
}
if (rc == SMB_LGRP_SUCCESS) {
smb_lgrp_free(&grp);
}
/*
*/
}
return (privs);
}
static void
{
}
/*
* Common token setup for both local and domain users.
* This function must be called after the initial setup
* has been done.
*
* Note that the order of calls in this function are important.
*
* Returns B_TRUE for success.
*/
{
return (B_FALSE);
/* Privileges */
return (B_FALSE);
if (smb_token_sids2ids(token) != 0) {
return (B_FALSE);
}
/* Solaris Groups */
return (smb_token_valid(token));
}
smb_logon_init(void)
{
(void) rw_wrlock(&smb_logoninit_rwl);
if (status != NT_STATUS_SUCCESS) {
(void) rw_unlock(&smb_logoninit_rwl);
return (status);
}
&smb_domusers);
if (status != NT_STATUS_SUCCESS) {
(void) rw_unlock(&smb_logoninit_rwl);
return (status);
}
(void) rw_unlock(&smb_logoninit_rwl);
return (status);
}
void
smb_logon_fini(void)
{
(void) rw_wrlock(&smb_logoninit_rwl);
(void) rw_unlock(&smb_logoninit_rwl);
}
/*
* Perform user authentication.
*
* The dispatched functions must only update the user_info status if they
* attempt to authenticate the user.
*
* On success, a pointer to a new access token is returned.
*/
{
};
int i;
else
return (NULL);
}
for (i = 0; i < n_op; ++i) {
break;
}
if (smb_token_setup_common(token))
return (token);
}
return (NULL);
}
/*
* If the user has an entry in the local database, attempt local authentication.
*
* In domain mode, we try to exclude domain accounts, which we do by only
* accepting local or null (blank) domain names here. Some clients (Mac OS)
* don't always send the domain name.
*
* If we are not going to attempt authentication, this function must return
* without updating the status.
*/
static void
{
return;
}
/*
* If the requested account name is "guest" (or whatever
* our guest account is named) then don't handle it here.
* Let this request fall through to smb_logon_guest().
*/
return;
if (status == NT_STATUS_SUCCESS)
}
/*
* Guest authentication. This may be a local guest account or the guest
* account may be mapped to a local account. These accounts are regular
* accounts with normal password protection.
*
* Only proceed with a guest logon if previous logon options have resulted
* in NO_SUCH_USER.
*
* If we are not going to attempt authentication, this function must return
* without updating the status.
*/
static void
{
char *temp;
return;
/* Get the name of the guest account. */
/* Does the guest account exist? */
return;
/* Is it enabled? (empty p/w is OK) */
return;
/*
* OK, give the client a guest logon. Note that on entry,
* lg_e_username is typically something other than "guest"
* so we need to set the effective username when createing
* the guest token.
*/
}
/*
* If user_info represents an anonymous user then setup the token.
* Otherwise return without updating the status.
*/
static void
{
}
/*
* Try both LM hash and NT hashes with user's password(s) to authenticate
* the user.
*/
static uint32_t
{
return (NT_STATUS_NO_SUCH_USER);
return (NT_STATUS_ACCOUNT_DISABLED);
/*
* The SMB passwords have not been set.
* Return an error that suggests the
* password needs to be set.
*/
return (NT_STATUS_PASSWORD_EXPIRED);
}
return (NT_STATUS_NO_MEMORY);
if (ok)
return (NT_STATUS_SUCCESS);
return (status);
}
/*
* Setup an access token for the specified local user.
*/
static uint32_t
{
return (NT_STATUS_NO_MEMORY);
return (NT_STATUS_NO_SUCH_USER);
/* Get the SID for user's uid & gid */
if (stat != IDMAP_SUCCESS)
return (NT_STATUS_INTERNAL_ERROR);
if (stat != IDMAP_SUCCESS) {
return (NT_STATUS_INTERNAL_ERROR);
}
if (stat != IDMAP_SUCCESS) {
return (NT_STATUS_INTERNAL_ERROR);
}
return (NT_STATUS_INTERNAL_ERROR);
return (NT_STATUS_NO_MEMORY);
return (smb_token_setup_wingrps(token));
}
/*
* Setup access token for guest connections
*/
static uint32_t
{
(void) rw_rdlock(&smb_logoninit_rwl);
(void) rw_unlock(&smb_logoninit_rwl);
return (NT_STATUS_NO_MEMORY);
return (smb_token_setup_wingrps(token));
}
/*
* Setup access token for anonymous connections
*/
static uint32_t
{
return (NT_STATUS_NO_MEMORY);
return (smb_token_setup_wingrps(token));
}
/*
* smb_token_user_sid
*
* Return a pointer to the user SID in the specified token. A null
* pointer indicates an error.
*/
static smb_sid_t *
{
}
/*
* smb_token_group_sid
*
* Return a pointer to the group SID as indicated by the iterator.
* Setting the iterator to 0 before calling this function will return
* the first group, which will always be the primary group. The
* iterator will be incremented before returning the SID so that this
* function can be used to cycle through the groups. The caller can
* adjust the iterator as required between calls to obtain any specific
* group.
*
* On success a pointer to the appropriate group SID will be returned.
* Otherwise a null pointer will be returned.
*/
static smb_sid_t *
{
int index;
return (NULL);
return (NULL);
return (NULL);
++(*iterator);
}
/*
* smb_token_is_member
*
* This function will determine whether or not the specified SID is a
* member of a token. The user SID and all group SIDs are tested.
* Returns 1 if the SID is a member of the token. Otherwise returns 0.
*/
static boolean_t
{
int iterator = 0;
return (B_FALSE);
while (tsid) {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* smb_token_log
*
* Diagnostic routine to write the contents of a token to the log.
*/
void
{
int i;
return;
" Grp[%d].Sid: %s (id=%u)", i, sidstr,
}
}
} else {
}
if (x_grps) {
} else {
}
if (token->tkn_privileges)
else
}
/*
* Sets up local and well-known group membership for the given
* token. Two assumptions have been made here:
*
* a) token already contains a valid user SID so that group
* memberships can be established
*
* b) token belongs to a local or anonymous user
*/
static uint32_t
{
/*
* We always want the user's primary group in the list
* of groups.
*/
return (NT_STATUS_NO_MEMORY);
return (NT_STATUS_NO_MEMORY);
}
if (status != NT_STATUS_SUCCESS) {
return (status);
}
if (status != NT_STATUS_SUCCESS) {
return (status);
}
return (status);
}
/*
* Returns the guest account name in the provided buffer.
*
* By default the name would be "guest" unless there's
* a idmap name-based rule which maps the guest to a local
* Solaris user in which case the name of that user is
* returned.
*/
static void
{
int idtype;
/* default Guest account name */
(void) rw_rdlock(&smb_logoninit_rwl);
(void) rw_unlock(&smb_logoninit_rwl);
if (stat != IDMAP_SUCCESS)
return;
/* If Ephemeral ID return the default name */
return;
return;
}