smb_user.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* 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"
/*
* General Structures Layout
* -------------------------
*
* This is a simplified diagram showing the relationship between most of the
* main structures.
*
* +-------------------+
* | SMB_INFO |
* +-------------------+
* |
* |
* v
* +-------------------+ +-------------------+ +-------------------+
* | SESSION |<----->| SESSION |......| SESSION |
* +-------------------+ +-------------------+ +-------------------+
* |
* |
* v
* +-------------------+ +-------------------+ +-------------------+
* | USER |<----->| USER |......| USER |
* +-------------------+ +-------------------+ +-------------------+
* |
* |
* v
* +-------------------+ +-------------------+ +-------------------+
* | TREE |<----->| TREE |......| TREE |
* +-------------------+ +-------------------+ +-------------------+
* | |
* | |
* | v
* | +-------+ +-------+ +-------+
* | | OFILE |<----->| OFILE |......| OFILE |
* | +-------+ +-------+ +-------+
* |
* |
* v
* +-------+ +------+ +------+
* | ODIR |<----->| ODIR |......| ODIR |
* +-------+ +------+ +------+
*
*
* User State Machine
* ------------------
*
* +-----------------------------+ T0
* | SMB_USER_STATE_LOGGED_IN |<----------- Creation/Allocation
* +-----------------------------+
* |
* | T1
* |
* v
* +-----------------------------+
* | SMB_USER_STATE_LOGGING_OFF |
* +-----------------------------+
* |
* | T2
* |
* v
* +-----------------------------+ T3
* +-----------------------------+
*
* SMB_USER_STATE_LOGGED_IN
*
* While in this state:
* - The user is queued in the list of users of his session.
* - References will be given out if the user is looked up.
* - The user can access files and pipes.
*
* SMB_USER_STATE_LOGGING_OFF
*
* While in this state:
* - The user is queued in the list of users of his session.
* - References will not be given out if the user is looked up.
* - The trees the user connected are being disconnected.
* - The resources associated with the user remain.
*
* SMB_USER_STATE_LOGGING_OFF
*
* While in this state:
* - The user is queued in the list of users of his session.
* - References will not be given out if the user is looked up.
* - The user has no more trees connected.
* - The resources associated with the user remain.
*
* Transition T0
*
* This transition occurs in smb_user_login(). A new user is created and
* added to the list of users of a session.
*
* Transition T1
*
* This transition occurs in smb_user_logoff().
*
* Transition T2
*
* This transition occurs in smb_user_release(). The resources associated
* with the user are deleted as well as the user. For the transition to
* occur, the user must be in the SMB_USER_STATE_LOGGED_OFF state and the
* reference count be zero.
*
* Comments
* --------
*
* The state machine of the user structures is controlled by 3 elements:
* - The list of users of the session he belongs to.
* - The mutex embedded in the structure itself.
* - The reference count.
*
* There's a mutex embedded in the user structure used to protect its fields
* and there's a lock embedded in the list of users of a session. To
* increment or to decrement the reference count the mutex must be entered.
* To insert the user into the list of users of the session and to remove
* the user from it, the lock must be entered in RW_WRITER mode.
*
* Rules of access to a user structure:
*
* 1) In order to avoid deadlocks, when both (mutex and lock of the session
* list) have to be entered, the lock must be entered first.
*
* 2) All actions applied to a user require a reference count.
*
* 3) There are 2 ways of getting a reference count. One is when the user
* logs in. The other when the user is looked up. This translates into
* 3 functions: smb_user_login(), smb_user_lookup_by_uid() and
* smb_user_lookup_by_credentials.
*
* It should be noted that the reference count of a user registers the
* number of references to the user in other structures (such as an smb
* request). The reference count is not incremented in these 2 instances:
*
* 1) The user is logged in. An user is anchored by his state. If there's
* no activity involving a user currently logged in, the reference
* count of that user is zero.
*
* 2) The user is queued in the list of users of the session. The fact of
* being queued in that list is NOT registered by incrementing the
* reference count.
*/
#include <smbsrv/smb_incl.h>
#include <smbsrv/smb_door_svc.h>
/* Static functions defined further down this file. */
/*
* smb_user_login
*
*
*/
char *domain_name,
char *account_name,
{
return (user);
}
}
return (NULL);
}
/*
* Create a new user based on an existing user, used to support
* additional SessionSetupX requests for a user on a session.
*
* Assumes the caller has a reference on the original user from
* a user_lookup_by_x call.
*/
{
if (user)
return (user);
}
/*
* smb_user_logoff
*
*
*/
void
{
case SMB_USER_STATE_LOGGED_IN: {
/*
* The user is moved into a state indicating that the log off
* process has started.
*/
/*
* All the trees hanging off of this user are disconnected.
*/
break;
}
break;
default:
ASSERT(0);
break;
}
}
/*
* smb_user_logoff_all
*
*
*/
void
{
while (user) {
case SMB_USER_STATE_LOGGED_IN:
/* The user is still logged in. */
break;
/*
* The user is logged off or logging off.
*/
break;
default:
ASSERT(0);
break;
}
}
}
/*
* smb_user_release
*
*
*/
void
{
return;
}
break;
case SMB_USER_STATE_LOGGED_IN:
break;
default:
ASSERT(0);
break;
}
}
/*
* smb_user_lookup_by_uid
*
* Find the appropriate user for this request. The request credentials
* set here may be overridden by the tree credentials. In domain mode,
* the user and tree credentials should be the same. In share mode, the
* tree credentials (defined in the share definition) should override
* the user credentials.
*/
{
while (user) {
case SMB_USER_STATE_LOGGED_IN:
/* The user exists and is still logged in. */
return (user);
/*
* The user exists but has logged off or is in
* the process of logging off.
*/
return (NULL);
default:
ASSERT(0);
return (NULL);
}
}
}
return (NULL);
}
/*
* smb_user_lookup_by_name
*/
{
while (user) {
break;
}
}
}
return (user);
}
/*
* smb_user_lookup_by_state
*
* This function returns the first user in the logged in state. If the user
* provided is NULL the search starts from the beginning of the list passed
* in. It a user is provided the search starts just after that user.
*/
{
if (user) {
} else {
}
while (next) {
break;
} else {
}
}
return (next);
}
/*
* smb_user_disconnect_share
*
* This function disconnects all the trees that have the sharename passed in.
*/
void
char *sharename)
{
while (tree) {
tree);
}
}
/*
* smb_user_disconnect_share
*
* This function disconnects all the trees that match fsd passed in.
*/
void
{
while (tree) {
}
}
/* *************************** Static Functions ***************************** */
/*
* smb_user_delete
*
*
*/
static void
{
/*
* Let's remove the user from the list of users of the session. This
* has to be done before any resources associated with the user are
* deleted.
*/
}