/*
* 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 <smbsrv/smb_kproto.h>
#include <smbsrv/smb_vops.h>
int smb_open_dsize_check = 0;
/*
* Client Request Description
* ================================== =================================
*
* UCHAR WordCount; Count of parameter words = 15
* UCHAR AndXCommand; Secondary (X) command; 0xFF =
* none
* UCHAR AndXReserved; Reserved (must be 0)
* USHORT AndXOffset; Offset to next command WordCount
* USHORT Flags; Additional information: bit set-
* 0 - return additional info
* 1 - exclusive oplock requested
* 2 - batch oplock requested
* USHORT DesiredAccess; File open mode
* USHORT SearchAttributes;
* USHORT FileAttributes;
* UTIME CreationTime; Creation timestamp for file if it
* gets created
* USHORT OpenFunction; Action to take if file exists
* ULONG AllocationSize; Bytes to reserve on create or
* truncate
* ULONG Reserved[2]; Must be 0
* USHORT ByteCount; Count of data bytes; min = 1
* UCHAR BufferFormat 0x04
* STRING FileName;
*
* Server Response Description
* ================================== =================================
*
* UCHAR WordCount; Count of parameter words = 15
* UCHAR AndXCommand; Secondary (X) command; 0xFF =
* none
* UCHAR AndXReserved; Reserved (must be 0)
* USHORT AndXOffset; Offset to next command WordCount
* USHORT Fid; File handle
* USHORT FileAttributes;
* UTIME LastWriteTime;
* ULONG DataSize; Current file size
* USHORT GrantedAccess; Access permissions actually
* allowed
* USHORT FileType; Type of file opened
* USHORT DeviceState; State of the named pipe
* USHORT Action; Action taken
* ULONG ServerFid; Server unique file id
* USHORT Reserved; Reserved (must be 0)
* USHORT ByteCount; Count of data bytes = 0
*
* DesiredAccess describes the access the client desires for the file (see
* section 3.6 - Access Mode Encoding).
*
* OpenFunction specifies the action to be taken depending on whether or
* not the file exists (see section 3.8 - Open Function Encoding). Action
*
* in the response specifies the action as a result of the Open request
* (see section 3.9 - Open Action Encoding).
*
* SearchAttributes indicates the attributes that the file must have to be
* found while searching to see if it exists. The encoding of this field
* is described in the "File Attribute Encoding" section elsewhere in this
* document. If SearchAttributes is zero then only normal files are
* returned. If the system file, hidden or directory attributes are
* specified then the search is inclusive -- both the specified type(s) of
* files and normal files are returned.
*
* FileType returns the kind of resource actually opened:
*
* Name Value Description
* ========================== ====== ==================================
*
* FileTypeDisk 0 Disk file or directory as defined
* in the attribute field
* FileTypeByteModePipe 1 Named pipe in byte mode
* FileTypeMessageModePipe 2 Named pipe in message mode
* FileTypePrinter 3 Spooled printer
* FileTypeUnknown 0xFFFF Unrecognized resource type
*
* If bit0 of Flags is clear, the FileAttributes, LastWriteTime, DataSize,
* FileType, and DeviceState have indeterminate values in the response.
*
* This SMB can request an oplock on the opened file. Oplocks are fully
* described in the "Oplocks" section elsewhere in this document, and there
* is also discussion of oplocks in the SMB_COM_LOCKING_ANDX SMB
* description. Bit1 and bit2 of the Flags field are used to request
* oplocks during open.
*
* The following SMBs may follow SMB_COM_OPEN_ANDX:
*
* SMB_COM_READ SMB_COM_READ_ANDX
* SMB_COM_IOCTL
*/
/*
* This message is sent to obtain a file handle for a data file. This
* returned Fid is used in subsequent client requests such as read, write,
* close, etc.
*
* Client Request Description
* ================================== =================================
*
* UCHAR WordCount; Count of parameter words = 2
* USHORT SearchAttributes;
* USHORT ByteCount; Count of data bytes; min = 2
* UCHAR BufferFormat; 0x04
* STRING FileName[]; File name
*
* FileName is the fully qualified file name, relative to the root of the
* share specified in the Tid field of the SMB header. If Tid in the SMB
* header refers to a print share, this SMB creates a new file which will
* be spooled to the printer when closed. In this case, FileName is
* ignored.
*
* SearchAttributes specifies the type of file desired. The encoding is
* described in the "File Attribute Encoding" section.
*
* DesiredAccess controls the mode under which the file is opened, and the
* file will be opened only if the client has the appropriate permissions.
* The encoding of DesiredAccess is discussed in the section entitled
* "Access Mode Encoding".
*
* Server Response Description
* ================================== =================================
*
* UCHAR WordCount; Count of parameter words = 7
* USHORT Fid; File handle
* USHORT FileAttributes; Attributes of opened file
* UTIME LastWriteTime; Time file was last written
* ULONG DataSize; File size
* USHORT GrantedAccess; Access allowed
* USHORT ByteCount; Count of data bytes = 0
*
* Fid is the handle value which should be used for subsequent file
* operations.
*
* FileAttributes specifies the type of file obtained. The encoding is
* described in the "File Attribute Encoding" section.
*
* GrantedAccess indicates the access permissions actually allowed, and may
* have one of the following values:
*
* 0 read-only
* 1 write-only
*
* File Handles (Fids) are scoped per client. A Pid may reference any Fid
* established by itself or any other Pid on the client (so far as the
* server is concerned). The actual accesses allowed through the Fid
* depends on the open and deny modes specified when the file was opened
* (see below).
*
* The MS-DOS compatibility mode of file open provides exclusion at the
* client level. A file open in compatibility mode may be opened (also in
* compatibility mode) any number of times for any combination of reading
* and writing (subject to the user's permissions) by any Pid on the same
* client. If the first client has the file open for writing, then the
* file may not be opened in any way by any other client. If the first
* client has the file open only for reading, then other clients may open
* the file, in compatibility mode, for reading.. The above
* notwithstanding, if the filename has an extension of .EXE, .DLL, .SYM,
* or .COM other clients are permitted to open the file regardless of
* multiple clients have the file open for reading, no client is permitted
* to open the file for writing and no other client may open the file in
* any mode other than compatibility mode.
*
* Deny none) provide exclusion at the file level. A file opened in any
* "Deny" mode may be opened again only for the accesses allowed by the
* Deny mode (subject to the user's permissions). This is true regardless
* of the identity of the second opener -a different client, a Pid from the
* same client, or the Pid that already has the file open. For example, if
* a file is open in "Deny write" mode a second open may only obtain read
* permission to the file.
*
* Although Fids are available to all Pids on a client, Pids other than the
* owner may not have the full access rights specified in the open mode by
* the Fid's creator. If the open creating the Fid specified a deny mode,
* then any Pid using the Fid, other than the creating Pid, will have only
* those access rights determined by "anding" the open mode rights and the
* deny mode rights, i.e., the deny mode is checked on all file accesses.
* other clients may only read the file and cannot write; if a file is
* opened for Read in Deny read mode, then the other clients can neither
* read nor write the file.
*/
{
int rc;
if (rc == 0)
struct open_param *, op);
}
void
{
}
{
int rc;
else
} else {
}
return (SDRC_ERROR);
}
if (status != NT_STATUS_SUCCESS) {
return (SDRC_ERROR);
}
/*
* NB: after the above smb_common_open() success,
* we have a handle allocated (sr->fid_ofile).
* If we don't return success, we must close it.
*/
}
if (rc != 0) {
goto errout;
}
7,
(uint16_t)0); /* bcc */
if (rc == 0)
return (SDRC_SUCCESS);
smb_ofile_close(of, 0);
return (SDRC_ERROR);
}
/*
* smb_pre_open_andx
* For compatibility with windows servers, the search attributes
* specified in the request are ignored.
*/
{
int rc;
if (rc == 0) {
if (flags & 2)
else if (flags & 4)
else
}
struct open_param *, op);
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (status != NT_STATUS_SUCCESS) {
return (SDRC_ERROR);
}
/*
* NB: after the above smb_common_open() success,
* we have a handle allocated (sr->fid_ofile).
* If we don't return success, we must close it.
*/
else
case STYPE_DISKTREE:
case STYPE_PRINTQ:
if (rc != 0) {
goto errout;
}
"bb.wwwllwwwwl2.w",
15,
0);
break;
case STYPE_IPC:
"bb.wwwllwwwwl2.w",
15,
0L,
0L,
0);
break;
default:
goto errout;
}
if (rc == 0)
return (SDRC_SUCCESS);
smb_ofile_close(of, 0);
return (SDRC_ERROR);
}
{
int rc;
if (rc != 0)
return (SDRC_ERROR);
else
} else {
}
if (status != NT_STATUS_SUCCESS) {
return (SDRC_ERROR);
}
else
(uint32_t)0, /* creation time */
(uint16_t)0, /* EA error offset */
(uint32_t)0); /* EA list length */
return (SDRC_SUCCESS);
}