/*
* 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.
* Copyright 2016 Syneto S.R.L. All rights reserved.
*/
/*
* 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 |
* +-------+ +------+ +------+
*
*
* Ofile State Machine
* ------------------
*
* +-------------------------+ T0
* | SMB_OFILE_STATE_OPEN |<----------- Creation/Allocation
* +-------------------------+
* |
* | T1
* |
* v
* +-------------------------+
* | SMB_OFILE_STATE_CLOSING |
* +-------------------------+
* |
* | T2
* |
* v
* +-------------------------+ T3
* +-------------------------+
*
* SMB_OFILE_STATE_OPEN
*
* While in this state:
* - The ofile is queued in the list of ofiles of its tree.
* - References will be given out if the ofile is looked up.
*
* SMB_OFILE_STATE_CLOSING
*
* While in this state:
* - The ofile is queued in the list of ofiles of its tree.
* - References will not be given out if the ofile is looked up.
* - The file is closed and the locks held are being released.
* - The resources associated with the ofile remain.
*
* SMB_OFILE_STATE_CLOSED
*
* While in this state:
* - The ofile is queued in the list of ofiles of its tree.
* - References will not be given out if the ofile is looked up.
* - The resources associated with the ofile remain.
*
* Transition T0
*
* This transition occurs in smb_ofile_open(). A new ofile is created and
* added to the list of ofiles of a tree.
*
* Transition T1
*
* This transition occurs in smb_ofile_close().
*
* Transition T2
*
* This transition occurs in smb_ofile_release(). The resources associated
* with the ofile are freed as well as the ofile structure. For the
* transition to occur, the ofile must be in the SMB_OFILE_STATE_CLOSED
* state and the reference count be zero.
*
* Comments
* --------
*
* The state machine of the ofile structures is controlled by 3 elements:
* - The list of ofiles of the tree it belongs to.
* - The mutex embedded in the structure itself.
* - The reference count.
*
* There's a mutex embedded in the ofile structure used to protect its fields
* and there's a lock embedded in the list of ofiles of a tree. To
* increment or to decrement the reference count the mutex must be entered.
* To insert the ofile into the list of ofiles of the tree and to remove
* the ofile from it, the lock must be entered in RW_WRITER mode.
*
* Rules of access to a ofile structure:
*
* 1) In order to avoid deadlocks, when both (mutex and lock of the ofile
* list) have to be entered, the lock must be entered first.
*
* 2) All actions applied to an ofile require a reference count.
*
* 3) There are 2 ways of getting a reference count. One is when the ofile
* is opened. The other one when the ofile is looked up. This translates
* into 2 functions: smb_ofile_open() and smb_ofile_lookup_by_fid().
*
* It should be noted that the reference count of an ofile registers the
* number of references to the ofile in other structures (such as an smb
* request). The reference count is not incremented in these 2 instances:
*
* 1) The ofile is open. An ofile is anchored by his state. If there's
* no activity involving an ofile currently open, the reference count
* of that ofile is zero.
*
* 2) The ofile is queued in the list of ofiles of its tree. The fact of
* being queued in that list is NOT registered by incrementing the
* reference count.
*/
#include <smbsrv/smb_kproto.h>
#include <smbsrv/smb_fsops.h>
uint32_t *);
static void smb_ofile_netinfo_fini(smb_netfileinfo_t *);
/*
* smb_ofile_open
*/
struct open_param *op,
{
int rc;
return (NULL);
}
/*
* grab a ref for of->f_user
* released in smb_ofile_delete()
*/
if (ftype == SMB_FTYPE_MESG_PIPE) {
/* See smb_opipe_open. */
} else {
/*
* Note that the common open path often adds bits like
* READ_CONTROL, so the logic "is this open exec-only"
* needs to look at only the FILE_DATA_ALL bits.
*/
if (rc != 0) {
goto errout;
}
/*
* Add this bit for the file's owner even if it's not
* specified in the request (Windows behavior).
*/
}
if (smb_node_is_file(node)) {
goto errout;
}
}
/*
* Note that if we created_readonly, that
* will _not_ yet show in attr.sa_dosattr
* so creating a readonly file gives the
* caller a writable handle as it should.
*/
}
return (of);
switch (state) {
case MUTEXINIT:
/*FALLTHROUGH*/
case CRHELD:
/*FALLTHROUGH*/
case FIDALLOC:
/*FALLTHROUGH*/
case EMPTY:
break;
}
return (NULL);
}
/*
* smb_ofile_close
*/
void
{
return;
}
case SMB_FTYPE_BYTE_PIPE:
case SMB_FTYPE_MESG_PIPE:
break;
case SMB_FTYPE_DISK:
case SMB_FTYPE_PRINTER:
/*
* In here we make changes to of->f_pending_attr
* while not holding of->f_mutex. This is OK
* because we've changed f_state to CLOSING,
* so no more threads will take this path.
*/
if (mtime_sec != 0) {
}
/*
* If we have ever modified data via this handle
* (write or truncate) and if the mtime was not
* set via this handle, update the mtime again
* during the close. Windows expects this.
* [ MS-FSA 2.1.5.4 "Update Timestamps" ]
*/
gethrestime(&now);
}
SMB_TREE_CATIA)) {
}
}
} else {
/*
* If there was an odir, close it.
*/
}
/*
* Last close. The f_pending_attr has
* only times (atime,ctime,mtime) so
* we can borrow it to commit the
* n_pending_dosattr from the node.
*/
pa->sa_dosattr =
if (pa->sa_dosattr != 0)
/* Let's leave this zero when not in use. */
}
/*
* Commit any pending attributes from
* the ofile we're closing. Note that
* we pass NULL as the ofile to setattr
* so it will write to the file system
* and not keep anything on the ofile.
* This clears n_pending_dosattr if
* there are no opens, otherwise the
* dosattr will be pending again.
*/
}
/*
* Cancel any notify change requests that
* may be using this open instance.
*/
break;
}
}
/*
* smb_ofile_close_all
*
*
*/
void
{
while (of) {
}
}
/*
* smb_ofiles_close_by_pid
*
*
*/
void
{
while (of) {
} else {
}
}
}
/*
* If the enumeration request is for ofile data, handle it here.
* Otherwise, return.
*
* This function should be called with a hold on the ofile.
*/
int
{
int rc;
return (0);
return (0);
}
return (0);
}
&nbytes);
if (rc == 0) {
}
return (rc);
}
/*
* Take a reference on an open file.
*/
{
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Release a reference on a file. If the reference count falls to
* zero and the file has been closed, post the object for deletion.
* Object deletion is deferred to avoid modifying a list while an
* iteration may be in progress.
*/
void
{
case SMB_OFILE_STATE_OPEN:
case SMB_OFILE_STATE_CLOSING:
break;
case SMB_OFILE_STATE_CLOSED:
break;
default:
ASSERT(0);
break;
}
}
/*
* smb_ofile_request_complete
*
* During oplock acquisition, all other oplock requests on the node
* are blocked until the acquire request completes and the response
* is on the wire.
* Call smb_oplock_broadcast to notify the node that the request
* has completed.
*
* THIS MECHANISM RELIES ON THE FACT THAT THE OFILE IS NOT REMOVED
* FROM THE SR UNTIL REQUEST COMPLETION (when the sr is destroyed)
*/
void
{
case SMB_FTYPE_DISK:
break;
case SMB_FTYPE_MESG_PIPE:
break;
default:
break;
}
}
/*
* smb_ofile_lookup_by_fid
*
* Find the open file whose fid matches the one specified in the request.
* If we can't find the fid or the shares (trees) don't match, we have a
* bad fid.
*/
{
while (of) {
break;
}
goto out;
/*
* Only allow use of a given FID with the same UID that
* was used to open it. MS-CIFS 3.3.5.14
*/
goto out;
}
goto out;
}
out:
return (of);
}
/*
* smb_ofile_lookup_by_uniqid
*
* Find the open file whose uniqid matches the one specified in the request.
*/
{
while (of) {
if (smb_ofile_hold(of)) {
return (of);
}
}
}
return (NULL);
}
/*
* Disallow NetFileClose on certain ofiles to avoid side-effects.
* Closing a tree root is not allowed: use NetSessionDel or NetShareDel.
* Closing SRVSVC connections is not allowed because this NetFileClose
* request may depend on this ofile.
*/
{
case SMB_FTYPE_DISK:
case SMB_FTYPE_MESG_PIPE:
return (B_TRUE);
break;
default:
break;
}
return (B_FALSE);
}
/*
* smb_ofile_set_flags
*
* Return value:
*
* Current flags value
*
*/
void
{
}
/*
* smb_ofile_seek
*
* Return value:
*
* 0 Success
* EINVAL Unknown mode
* EOVERFLOW offset too big
*
*/
int
{
int rc = 0;
switch (mode) {
case SMB_SEEK_SET:
if (off < 0)
newoff = 0;
else
break;
case SMB_SEEK_CUR:
newoff = 0;
else
break;
case SMB_SEEK_END:
if (rc != 0) {
return (rc);
}
newoff = 0;
else
break;
default:
return (EINVAL);
}
/*
* See comments at the beginning of smb_seek.c.
* If the offset is greater than UINT_MAX, we will return an error.
*/
} else {
}
return (rc);
}
/*
* smb_ofile_flush
*
* If writes on this file are not synchronous, flush it using the NFSv3
* commit interface.
*
* XXX - todo: Flush named pipe should drain writes.
*/
void
{
case SMB_FTYPE_DISK:
break;
default:
break;
}
}
/*
* smb_ofile_is_open
*/
{
return (rc);
}
/* *************************** Static Functions ***************************** */
/*
* Determine whether or not an ofile is open.
* This function must be called with the mutex held.
*/
static boolean_t
{
case SMB_OFILE_STATE_OPEN:
return (B_TRUE);
case SMB_OFILE_STATE_CLOSING:
case SMB_OFILE_STATE_CLOSED:
return (B_FALSE);
default:
ASSERT(0);
return (B_FALSE);
}
}
/*
* This function closes the file passed in (if appropriate) and returns the
* next open file in the list of open files of the tree of the open file passed
* in. It requires that the list of open files of the tree be entered in
* RW_READER mode before being called.
*/
static smb_ofile_t *
{
case SMB_OFILE_STATE_OPEN:
/* The file is still open. */
smb_ofile_close(of, 0);
break;
case SMB_OFILE_STATE_CLOSING:
case SMB_OFILE_STATE_CLOSED:
/*
* The ofile exists but is closed or
* in the process being closed.
*/
break;
default:
ASSERT(0);
break;
}
return (next_of);
}
/*
* Delete an ofile.
*
* Remove the ofile from the tree list before freeing resources
* associated with the ofile.
*/
void
{
case SMB_FTYPE_BYTE_PIPE:
case SMB_FTYPE_MESG_PIPE:
break;
case SMB_FTYPE_DISK:
break;
default:
ASSERT(!"f_ftype");
break;
}
}
/*
* smb_ofile_access
*
* This function will check to see if the access requested is granted.
* Returns NT status codes.
*/
{
return (NT_STATUS_SUCCESS);
/*
* If the request is for something
* I don't grant it is an error
*/
(access & ACCESS_SYSTEM_SECURITY)) {
return (NT_STATUS_PRIVILEGE_NOT_HELD);
}
return (NT_STATUS_ACCESS_DENIED);
}
return (NT_STATUS_SUCCESS);
}
/*
* smb_ofile_share_check
*
* Check if ofile was opened with share access NONE (0).
* Returns: B_TRUE - share access non-zero
* B_FALSE - share access NONE
*/
{
}
/*
* check file sharing rules for current open request
* against existing open instances of the same file
*
* Returns NT_STATUS_SHARING_VIOLATION if there is any
* sharing conflict, otherwise returns NT_STATUS_SUCCESS.
*/
{
return (NT_STATUS_INVALID_HANDLE);
}
/* if it's just meta data */
return (NT_STATUS_SUCCESS);
}
/*
* Check requested share access against the
* open granted (desired) access
*/
return (NT_STATUS_SHARING_VIOLATION);
}
if (SMB_DENY_READ(share_access) &&
return (NT_STATUS_SHARING_VIOLATION);
}
if (SMB_DENY_WRITE(share_access) &&
return (NT_STATUS_SHARING_VIOLATION);
}
/* check requested desired access against the open share access */
return (NT_STATUS_SHARING_VIOLATION);
}
return (NT_STATUS_SHARING_VIOLATION);
}
return (NT_STATUS_SHARING_VIOLATION);
}
return (NT_STATUS_SUCCESS);
}
/*
* smb_ofile_rename_check
*
* An open file can be renamed if
*
* 1. isn't opened for data writing or deleting
*
* 2. Opened with "Deny Delete" share mode
* But not opened for data reading or executing
* (opened for accessing meta data)
*/
{
return (NT_STATUS_INVALID_HANDLE);
}
if (of->f_granted_access &
return (NT_STATUS_SHARING_VIOLATION);
}
if (of->f_granted_access &
(FILE_READ_DATA | FILE_EXECUTE)) {
return (NT_STATUS_SHARING_VIOLATION);
}
}
return (NT_STATUS_SUCCESS);
}
/*
* smb_ofile_delete_check
*
* An open file can be deleted only if opened for
* accessing meta data. Share modes aren't important
* in this case.
*
* NOTE: there is another mechanism for deleting an
* open file that NT clients usually use.
* That's setting "Delete on close" flag for an open
* file. In this way the file will be deleted after
* last close. This flag can be set by SmbTrans2SetFileInfo
* with FILE_DISPOSITION_INFO information level.
* For setting this flag, the file should be opened by
* DELETE access in the FID that is passed in the Trans2
* request.
*/
{
return (NT_STATUS_INVALID_HANDLE);
}
if (of->f_granted_access &
return (NT_STATUS_SHARING_VIOLATION);
}
return (NT_STATUS_SUCCESS);
}
cred_t *
{
}
/*
* smb_ofile_set_delete_on_close
*
* Set the DeleteOnClose flag on the smb file. When the file is closed,
* the flag will be transferred to the smb node, which will commit the
* delete operation and inhibit subsequent open requests.
*
* When DeleteOnClose is set on an smb_node, the common open code will
* reject subsequent open requests for the file. Observation of Windows
* 2000 indicates that subsequent opens should be allowed (assuming
* there would be no sharing violation) until the file is closed using
* the fid on which the DeleteOnClose was requested.
*/
void
{
}
/*
* Encode open file information into a buffer; needed in user space to
* support RPC requests.
*/
static int
{
int rc;
if (rc == 0) {
}
return (rc);
}
static int
{
char *path;
char *buf;
int rc;
case SMB_FTYPE_DISK:
if (rc != 0)
}
path);
break;
case SMB_FTYPE_MESG_PIPE:
fi->fi_numlocks = 0;
break;
default:
return (-1);
}
return (0);
}
static void
{
return;
if (fi->fi_username)
}
/*
* A query of user and group quotas may span multiple requests.
* f_quota_resume is used to determine where the query should
* be resumed, in a subsequent request. f_quota_resume contains
* the SID of the last quota entry returned to the client.
*/
void
{
else
}
void
{
}