smb_tree.c revision 037cac007b685e7ea79f6ef7e8e62bfd342a4d56
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 |
* +-------+ +------+ +------+
*
*
* Tree State Machine
* ------------------
*
* +-----------------------------+ T0
* | SMB_TREE_STATE_CONNECTED |<----------- Creation/Allocation
* +-----------------------------+
* |
* | T1
* |
* v
* +------------------------------+
* | SMB_TREE_STATE_DISCONNECTING |
* +------------------------------+
* |
* | T2
* |
* v
* +-----------------------------+ T3
* +-----------------------------+
*
* SMB_TREE_STATE_CONNECTED
*
* While in this state:
* - The tree is queued in the list of trees of its user.
* - References will be given out if the tree is looked up.
* - Files under that tree can be accessed.
*
* SMB_TREE_STATE_DISCONNECTING
*
* While in this state:
* - The tree is queued in the list of trees of its user.
* - References will not be given out if the tree is looked up.
* - The files and directories open under the tree are being closed.
* - The resources associated with the tree remain.
*
* SMB_TREE_STATE_DISCONNECTED
*
* While in this state:
* - The tree is queued in the list of trees of its user.
* - References will not be given out if the tree is looked up.
* - The tree has no more files and directories opened.
* - The resources associated with the tree remain.
*
* Transition T0
*
* This transition occurs in smb_tree_connect(). A new tree is created and
* added to the list of trees of a user.
*
* Transition T1
*
* This transition occurs in smb_tree_disconnect().
*
* Transition T2
*
* This transition occurs in smb_tree_release(). The resources associated
* with the tree are freed as well as the tree structure. For the transition
* to occur, the tree must be in the SMB_TREE_STATE_DISCONNECTED state and
* the reference count be zero.
*
* Comments
* --------
*
* The state machine of the tree structures is controlled by 3 elements:
* - The list of trees of the user it belongs to.
* - The mutex embedded in the structure itself.
* - The reference count.
*
* There's a mutex embedded in the tree structure used to protect its fields
* and there's a lock embedded in the list of trees of a user. To
* increment or to decrement the reference count the mutex must be entered.
* To insert the tree into the list of trees of the user and to remove
* the tree from it, the lock must be entered in RW_WRITER mode.
*
* Rules of access to a tree structure:
*
* 1) In order to avoid deadlocks, when both (mutex and lock of the user
* list) have to be entered, the lock must be entered first.
*
* 2) All actions applied to a tree require a reference count.
*
* 3) There are 2 ways of getting a reference count: when a tree is
* connected and when a tree is looked up.
*
* It should be noted that the reference count of a tree registers the
* number of references to the tree in other structures (such as an smb
* request). The reference count is not incremented in these 2 instances:
*
* 1) The tree is connected. An tree is anchored by his state. If there's
* no activity involving a tree currently connected, the reference
* count of that tree is zero.
*
* 2) The tree is queued in the list of trees of the user. The fact of
* being queued in that list is NOT registered by incrementing the
* reference count.
*/
#include <sys/refstr_impl.h>
#include <sys/feature_tests.h>
#include <sys/cred_impl.h>
#include <smbsrv/smb_incl.h>
#include <smbsrv/smb_fsops.h>
#include <smbsrv/smb_door_svc.h>
#include <smbsrv/smb_share.h>
#include <sys/pathname.h>
int smb_tcon_mute = 0;
static void smb_tree_dealloc(smb_tree_t *);
static const char *smb_tree_get_sharename(const char *);
static int smb_tree_get_stype(const char *, const char *, int32_t *);
static void smb_tree_log(smb_request_t *, const char *, const char *, ...);
/*
* Extract the share name and share type and connect as appropriate.
* Share names are case insensitive so we map the share name to
* lower-case as a convenience for internal processing.
*/
{
const char *name;
(void) utf8_strlwr(unc_path);
return (NULL);
}
return (NULL);
}
switch (stype & STYPE_MASK) {
case STYPE_DISKTREE:
break;
case STYPE_IPC:
break;
default:
break;
}
return (tree);
}
/*
* Disconnect a tree.
*/
void
{
if (smb_tree_is_connected_locked(tree)) {
/*
* Indicate that the disconnect process has started.
*/
if (do_exec) {
/*
* The files opened under this tree are closed.
*/
/*
* The directories opened under this tree are closed.
*/
smb_tree_close_odirs(tree, 0);
}
}
}
}
/*
* Take a reference on a tree.
*/
{
if (smb_tree_is_connected_locked(tree)) {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Release a reference on a tree. If the tree is disconnected and the
* reference count falls to zero, the tree will be deallocated.
*/
void
{
return;
}
}
/*
* Close ofiles and odirs that match pid.
*/
void
{
}
/*
* Check whether or not a tree supports the features identified by flags.
*/
{
}
/* *************************** Static Functions ***************************** */
#define SHARES_DIR ".zfs/shares/"
static void
{
int rc;
char *sharepath;
/*
* Using the vnode of the share path, we then find the root
* directory of the mounted file system. We will then look to
* check against the cred.
*/
else
if (rc != 0)
return;
/*
* Find the share object, if there is one. Need to construct
* up. root is called held but will be released by
* lookuppnvp().
*/
/*
* Now get the effective access value based on cred and ACL
* values.
*/
if (rc == 0) {
}
}
/*
* Connect a share for use with files and directories.
*/
static smb_tree_t *
{
char last_component[MAXNAMELEN];
int rc;
return (NULL);
}
return (NULL);
}
"access denied: guest disabled");
return (NULL);
}
}
/*
* Handle the default administration shares: C$, D$ etc.
* Only a user with admin rights is allowed to map these
* shares.
*/
if (!smb_user_is_admin(user)) {
return (NULL);
}
}
/*
* Set up the OptionalSupport for this share.
*/
case SMB_SHRF_CSC_DISABLED:
break;
case SMB_SHRF_CSC_AUTO:
break;
case SMB_SHRF_CSC_VDO:
break;
case SMB_SHRF_CSC_MANUAL:
default:
/*
* Default to SMB_CSC_CACHE_MANUAL_REINT.
*/
break;
}
if (access == SMB_SHRF_ACC_RO) {
} else if (access == SMB_SHRF_ACC_NONE) {
return (NULL);
}
/*
* Check that the shared directory exists.
*/
if (rc == 0) {
&snode);
}
if (rc) {
if (snode)
return (NULL);
}
/*
* Find share level ACL if it exists in the designated
* location. Needs to be done after finding a valid path but
* before the tree is allocated.
*/
if ((aclaccess & ACE_ALL_PERMS) == 0) {
return (NULL);
}
/*
* Set tree ACL access to the minimum ACL permissions based on
* hostaccess (those allowed by host based access) and
* aclaccess (those from the ACL object for the share). This
* is done during the alloc.
*/
hostaccess & aclaccess);
else {
return (NULL);
}
}
}
return (tree);
}
/*
* Connect an IPC share for use with named pipes.
*/
static smb_tree_t *
{
return (NULL);
}
}
return (tree);
}
/*
* Allocate a tree.
*/
static smb_tree_t *
const smb_share_t *si,
{
return (NULL);
if (STYPE_ISDSK(stype)) {
return (NULL);
}
}
return (NULL);
}
return (NULL);
}
sizeof (tree->t_sharename));
sizeof (tree->t_resource));
/* if FS is readonly, enforce that here */
if (STYPE_ISDSK(stype)) {
}
return (tree);
}
/*
* Deallocate a tree: release all resources associated with a tree and
* remove the tree from the user's tree list.
*
* The tree being destroyed must be in the "destroying" state and the
* reference count must be zero. This function assumes it's single threaded
* i.e. only one thread will attempt to destroy a specific tree, which
* should be the case if the tree is in disconnected and has a reference
* count of zero.
*/
static void
{
/*
* Remove the tree from the user's tree list. This must be done
* before any resources associated with the tree are released.
*/
/*
* The list of open files and open directories should be empty.
*/
}
/*
* Determine whether or not a tree is connected.
* This function must be called with the tree mutex held.
*/
static boolean_t
{
case SMB_TREE_STATE_CONNECTED:
return (B_TRUE);
/*
* The tree exists but being diconnected or destroyed.
*/
return (B_FALSE);
default:
ASSERT(0);
return (B_FALSE);
}
}
/*
* Determine whether or not a tree is disconnected.
* This function must be called with the tree mutex held.
*/
static boolean_t
{
return (B_TRUE);
case SMB_TREE_STATE_CONNECTED:
return (B_FALSE);
default:
ASSERT(0);
return (B_FALSE);
}
}
/*
* Return a pointer to the share name within a share resource path.
*
* The share path may be a Uniform Naming Convention (UNC) string
* (\\server\share) or simply the share name. We validate the UNC
* format but we don't look at the server name.
*/
static const char *
smb_tree_get_sharename(const char *unc_path)
{
if (sharename[0] == '\\') {
/*
* Looks like a UNC path, validate the format.
*/
return (NULL);
return (NULL);
++sharename;
/*
* This should be a share name (no embedded \'s).
*/
return (NULL);
}
return (sharename);
}
/*
* Map the service to a resource type. Valid values for service are:
*
* A: Disk share
* LPT1: Printer
* IPC Named pipe
* COMM Communications device
* ????? Any type of device (wildcard)
*
* We support IPC and disk shares; anything else is currently treated
* as an error. IPC$ is reserved as the named pipe share.
*/
static int
{
const char *any = "?????";
return (0);
}
}
return (-1);
return (0);
}
return (-1);
}
/*
* Obtain the tree attributes: volume name, typename and flags.
*/
static int
{
return (ESTALE);
return (0);
}
/*
* Extract the volume name.
*/
static void
{
const char *s;
char *name;
s = vfs_mntpoint->rs_string;
s += strspn(s, "/");
}
/*
* Always set ACL support because the VFS will fake ACLs for file systems
* that don't support them.
*
* Some flags are dependent on the typename, which is also set up here.
* File system types are hardcoded in uts/common/os/vfs_conf.c.
*/
static void
{
typedef struct smb_mtype {
char *mt_name;
} smb_mtype_t;
static smb_mtype_t smb_mtype[] = {
};
char *name;
int i;
flags |= SMB_TREE_CATIA;
}
flags |= SMB_TREE_XVATTR;
}
/*
* Report share access result to syslog.
*/
static void
{
char buf[128];
if (smb_tcon_mute)
return;
/*
* Only report normal users, i.e. ignore W2K misuse
* of the IPC connection by filtering out internal
* names such as nobody and root.
*/
return;
}
}
}
/*
* smb_tree_lookup_odir
*
* Find the specified odir in the tree's list of odirs, and
* attempt to obtain a hold on the odir.
*
* Returns NULL if odir not found or a hold cannot be obtained.
*/
{
smb_odir_t *od;
while (od) {
if (!smb_odir_hold(od))
break;
}
}
return (od);
}
{
return (rb);
}
/*
* smb_tree_get_odir
*
* Find the next odir in the tree's list of odirs, and obtain a
* hold on it.
* If the specified odir is NULL the search starts at the beginning
* of the tree's odir list, otherwise the search starts after the
* specified odir.
*/
static smb_odir_t *
{
if (od) {
} else {
}
while (od) {
if (smb_odir_hold(od))
break;
}
return (od);
}
/*
* smb_tree_close_odirs
*
* Close all open odirs in the tree's list which were opened by
* the process identified by pid.
* If pid is zero, close all open odirs in the tree's list.
*/
static void
{
while (od) {
}
}
static void
{
}