xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_open_andx.c (revision eb1d736b1c19f6abeee90c921a9320b67fedd016)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
222c2961f8Sjose borrego  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw #include <smbsrv/smb_vops.h>
272c2961f8Sjose borrego #include <smbsrv/smb_incl.h>
282c2961f8Sjose borrego 
292c2961f8Sjose borrego int smb_open_dsize_check = 0;
30da6c28aaSamw 
31da6c28aaSamw /*
32da6c28aaSamw  *  Client Request                     Description
33da6c28aaSamw  *  ================================== =================================
34da6c28aaSamw  *
35da6c28aaSamw  *  UCHAR WordCount;                   Count of parameter words = 15
36da6c28aaSamw  *  UCHAR AndXCommand;                 Secondary (X) command;  0xFF =
37da6c28aaSamw  *                                      none
38da6c28aaSamw  *  UCHAR AndXReserved;                Reserved (must be 0)
39da6c28aaSamw  *  USHORT AndXOffset;                 Offset to next command WordCount
40da6c28aaSamw  *  USHORT Flags;                      Additional information: bit set-
41da6c28aaSamw  *                                      0 - return additional info
42da6c28aaSamw  *                                      1 - exclusive oplock requested
43da6c28aaSamw  *                                      2 - batch oplock requested
44da6c28aaSamw  *  USHORT DesiredAccess;              File open mode
45da6c28aaSamw  *  USHORT SearchAttributes;
46da6c28aaSamw  *  USHORT FileAttributes;
47da6c28aaSamw  *  UTIME CreationTime;                Creation timestamp for file if it
48da6c28aaSamw  *                                      gets created
49da6c28aaSamw  *  USHORT OpenFunction;               Action to take if file exists
50da6c28aaSamw  *  ULONG AllocationSize;              Bytes to reserve on create or
51da6c28aaSamw  *                                      truncate
52da6c28aaSamw  *  ULONG Reserved[2];                 Must be 0
53da6c28aaSamw  *  USHORT ByteCount;                  Count of data bytes;    min = 1
54da6c28aaSamw  *  UCHAR BufferFormat                 0x04
55da6c28aaSamw  *  STRING FileName;
56da6c28aaSamw  *
57da6c28aaSamw  *  Server Response                    Description
58da6c28aaSamw  *  ================================== =================================
59da6c28aaSamw  *
60da6c28aaSamw  *  UCHAR WordCount;                   Count of parameter words = 15
61da6c28aaSamw  *  UCHAR AndXCommand;                 Secondary (X) command;  0xFF =
62da6c28aaSamw  *                                      none
63da6c28aaSamw  *  UCHAR AndXReserved;                Reserved (must be 0)
64da6c28aaSamw  *  USHORT AndXOffset;                 Offset to next command WordCount
65da6c28aaSamw  *  USHORT Fid;                        File handle
66da6c28aaSamw  *  USHORT FileAttributes;
67da6c28aaSamw  *  UTIME LastWriteTime;
68da6c28aaSamw  *  ULONG DataSize;                    Current file size
69da6c28aaSamw  *  USHORT GrantedAccess;              Access permissions actually
70da6c28aaSamw  *                                      allowed
71da6c28aaSamw  *  USHORT FileType;                   Type of file opened
72da6c28aaSamw  *  USHORT DeviceState;                State of the named pipe
73da6c28aaSamw  *  USHORT Action;                     Action taken
74da6c28aaSamw  *  ULONG ServerFid;                   Server unique file id
75da6c28aaSamw  *  USHORT Reserved;                   Reserved (must be 0)
76da6c28aaSamw  *  USHORT ByteCount;                  Count of data bytes = 0
77da6c28aaSamw  *
78da6c28aaSamw  * DesiredAccess describes the access the client desires for the file (see
79da6c28aaSamw  * section 3.6 -  Access Mode Encoding).
80da6c28aaSamw  *
81da6c28aaSamw  * OpenFunction specifies the action to be taken depending on whether or
82da6c28aaSamw  * not the file exists (see section 3.8 -  Open Function Encoding).  Action
83da6c28aaSamw  *
84da6c28aaSamw  * in the response specifies the action as a result of the Open request
85da6c28aaSamw  * (see section 3.9 -  Open Action Encoding).
86da6c28aaSamw  *
87da6c28aaSamw  * SearchAttributes indicates the attributes that the file must have to be
88da6c28aaSamw  * found while searching to see if it exists.  The encoding of this field
89da6c28aaSamw  * is described in the "File Attribute Encoding" section elsewhere in this
90da6c28aaSamw  * document.  If SearchAttributes is zero then only normal files are
91da6c28aaSamw  * returned.  If the system file, hidden or directory attributes are
92da6c28aaSamw  * specified then the search is inclusive -- both the specified type(s) of
93da6c28aaSamw  * files and normal files are returned.
94da6c28aaSamw  *
95da6c28aaSamw  * FileType returns the kind of resource actually opened:
96da6c28aaSamw  *
97da6c28aaSamw  *  Name                       Value  Description
98da6c28aaSamw  *  ========================== ====== ==================================
99da6c28aaSamw  *
100da6c28aaSamw  *  FileTypeDisk               0      Disk file or directory as defined
101da6c28aaSamw  *                                     in the attribute field
102da6c28aaSamw  *  FileTypeByteModePipe       1      Named pipe in byte mode
103da6c28aaSamw  *  FileTypeMessageModePipe    2      Named pipe in message mode
104da6c28aaSamw  *  FileTypePrinter            3      Spooled printer
105da6c28aaSamw  *  FileTypeUnknown            0xFFFF Unrecognized resource type
106da6c28aaSamw  *
107da6c28aaSamw  * If bit0 of Flags is clear, the FileAttributes, LastWriteTime, DataSize,
108da6c28aaSamw  * FileType, and DeviceState have indeterminate values in the response.
109da6c28aaSamw  *
110da6c28aaSamw  * This SMB can request an oplock on the opened file.  Oplocks are fully
111da6c28aaSamw  * described in the "Oplocks" section elsewhere in this document, and there
112da6c28aaSamw  * is also discussion of oplocks in the SMB_COM_LOCKING_ANDX SMB
113da6c28aaSamw  * description.  Bit1 and bit2 of the Flags field are used to request
114da6c28aaSamw  * oplocks during open.
115da6c28aaSamw  *
116da6c28aaSamw  * The following SMBs may follow SMB_COM_OPEN_ANDX:
117da6c28aaSamw  *
118da6c28aaSamw  *    SMB_COM_READ    SMB_COM_READ_ANDX
119da6c28aaSamw  *    SMB_COM_IOCTL
120da6c28aaSamw  */
121da6c28aaSamw 
122da6c28aaSamw /*
123da6c28aaSamw  * This message is sent to obtain a file handle for a data file.  This
124da6c28aaSamw  * returned Fid is used in subsequent client requests such as read, write,
125da6c28aaSamw  * close, etc.
126da6c28aaSamw  *
127da6c28aaSamw  * Client Request                     Description
128da6c28aaSamw  * ================================== =================================
129da6c28aaSamw  *
130da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 2
131da6c28aaSamw  * USHORT DesiredAccess;              Mode - read/write/share
132da6c28aaSamw  * USHORT SearchAttributes;
133da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes;    min = 2
134da6c28aaSamw  * UCHAR BufferFormat;                0x04
135da6c28aaSamw  * STRING FileName[];                 File name
136da6c28aaSamw  *
137da6c28aaSamw  * FileName is the fully qualified file name, relative to the root of the
138da6c28aaSamw  * share specified in the Tid field of the SMB header.  If Tid in the SMB
139da6c28aaSamw  * header refers to a print share, this SMB creates a new file which will
140da6c28aaSamw  * be spooled to the printer when closed.  In this case, FileName is
141da6c28aaSamw  * ignored.
142da6c28aaSamw  *
143da6c28aaSamw  * SearchAttributes specifies the type of file desired.  The encoding is
144da6c28aaSamw  * described in the "File Attribute Encoding" section.
145da6c28aaSamw  *
146da6c28aaSamw  * DesiredAccess controls the mode under which the file is opened, and the
147da6c28aaSamw  * file will be opened only if the client has the appropriate permissions.
148da6c28aaSamw  * The encoding of DesiredAccess is discussed in the section entitled
149da6c28aaSamw  * "Access Mode Encoding".
150da6c28aaSamw  *
151da6c28aaSamw  * Server Response                    Description
152da6c28aaSamw  * ================================== =================================
153da6c28aaSamw  *
154da6c28aaSamw  * UCHAR WordCount;                   Count of parameter words = 7
155da6c28aaSamw  * USHORT Fid;                        File handle
156da6c28aaSamw  * USHORT FileAttributes;             Attributes of opened file
157da6c28aaSamw  * UTIME LastWriteTime;               Time file was last written
158da6c28aaSamw  * ULONG DataSize;                    File size
159da6c28aaSamw  * USHORT GrantedAccess;              Access allowed
160da6c28aaSamw  * USHORT ByteCount;                  Count of data bytes = 0
161da6c28aaSamw  *
162da6c28aaSamw  * Fid is the handle value which should be used for subsequent file
163da6c28aaSamw  * operations.
164da6c28aaSamw  *
165da6c28aaSamw  * FileAttributes specifies the type of file obtained.  The encoding is
166da6c28aaSamw  * described in the "File Attribute Encoding" section.
167da6c28aaSamw  *
168da6c28aaSamw  * GrantedAccess indicates the access permissions actually allowed, and may
169da6c28aaSamw  * have one of the following values:
170da6c28aaSamw  *
171da6c28aaSamw  *    0  read-only
172da6c28aaSamw  *    1  write-only
173da6c28aaSamw  *    2 read/write
174da6c28aaSamw  *
175da6c28aaSamw  * File Handles (Fids) are scoped per client.  A Pid may reference any Fid
176da6c28aaSamw  * established by itself or any other Pid on the client (so far as the
177da6c28aaSamw  * server is concerned).  The actual accesses allowed through the Fid
178da6c28aaSamw  * depends on the open and deny modes specified when the file was opened
179da6c28aaSamw  * (see below).
180da6c28aaSamw  *
181da6c28aaSamw  * The MS-DOS compatibility mode of file open provides exclusion at the
182da6c28aaSamw  * client level.  A file open in compatibility mode may be opened (also in
183da6c28aaSamw  * compatibility mode) any number of times for any combination of reading
184da6c28aaSamw  * and writing (subject to the user's permissions) by any Pid on the same
185da6c28aaSamw  * client.  If the first client has the file open for writing, then the
186da6c28aaSamw  * file may not be opened in any way by any other client.  If the first
187da6c28aaSamw  * client has the file open only for reading, then other clients may open
188da6c28aaSamw  * the file, in compatibility mode, for reading..  The above
189da6c28aaSamw  * notwithstanding, if the filename has an extension of .EXE, .DLL, .SYM,
190da6c28aaSamw  * or .COM other clients are permitted to open the file regardless of
191da6c28aaSamw  * read/write open modes of other compatibility mode opens.  However, once
192da6c28aaSamw  * multiple clients have the file open for reading, no client is permitted
193da6c28aaSamw  * to open the file for writing and no other client may open the file in
194da6c28aaSamw  * any mode other than compatibility mode.
195da6c28aaSamw  *
196da6c28aaSamw  * The other file exclusion modes (Deny read/write, Deny write, Deny read,
197da6c28aaSamw  * Deny none) provide exclusion at the file level.  A file opened in any
198da6c28aaSamw  * "Deny" mode may be opened again only for the accesses allowed by the
199da6c28aaSamw  * Deny mode (subject to the user's permissions).  This is true regardless
200da6c28aaSamw  * of the identity of the second opener -a different client, a Pid from the
201da6c28aaSamw  * same client, or the Pid that already has the file open.  For example, if
202da6c28aaSamw  * a file is open in "Deny write" mode a second open may only obtain read
203da6c28aaSamw  * permission to the file.
204da6c28aaSamw  *
205da6c28aaSamw  * Although Fids are available to all Pids on a client, Pids other than the
206da6c28aaSamw  * owner may not have the full access rights specified in the open mode by
207da6c28aaSamw  * the Fid's creator.  If the open creating the Fid specified a deny mode,
208da6c28aaSamw  * then any Pid using the Fid, other than the creating Pid, will have only
209da6c28aaSamw  * those access rights determined by "anding" the open mode rights and the
210da6c28aaSamw  * deny mode rights, i.e., the deny mode is checked on all file accesses.
211da6c28aaSamw  * For example, if a file is opened for Read/Write in Deny write mode, then
212da6c28aaSamw  * other clients may only read the file and cannot write; if a file is
213da6c28aaSamw  * opened for Read in Deny read mode, then the other clients can neither
214da6c28aaSamw  * read nor write the file.
215da6c28aaSamw  */
216da6c28aaSamw 
2177b59d02dSjb150015 smb_sdrc_t
218faa1795aSjb150015 smb_pre_open(smb_request_t *sr)
219faa1795aSjb150015 {
220faa1795aSjb150015 	struct open_param *op = &sr->arg.open;
221faa1795aSjb150015 	int rc;
222faa1795aSjb150015 
223faa1795aSjb150015 	bzero(op, sizeof (sr->arg.open));
224faa1795aSjb150015 
225*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	rc = smbsr_decode_vwv(sr, "ww", &op->omode, &op->fqi.fq_sattr);
226faa1795aSjb150015 	if (rc == 0)
227*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		rc = smbsr_decode_data(sr, "%S", sr, &op->fqi.fq_path.pn_path);
228faa1795aSjb150015 
229faa1795aSjb150015 	DTRACE_SMB_2(op__Open__start, smb_request_t *, sr,
230faa1795aSjb150015 	    struct open_param *, op);
231faa1795aSjb150015 
232faa1795aSjb150015 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
233faa1795aSjb150015 }
234faa1795aSjb150015 
235faa1795aSjb150015 void
236faa1795aSjb150015 smb_post_open(smb_request_t *sr)
237faa1795aSjb150015 {
238faa1795aSjb150015 	DTRACE_SMB_1(op__Open__done, smb_request_t *, sr);
239faa1795aSjb150015 }
240faa1795aSjb150015 
241faa1795aSjb150015 smb_sdrc_t
242faa1795aSjb150015 smb_com_open(smb_request_t *sr)
243da6c28aaSamw {
244da6c28aaSamw 	struct open_param *op = &sr->arg.open;
2458c10a865Sas200622 	smb_node_t *node;
246da6c28aaSamw 	uint16_t file_attr;
2477b59d02dSjb150015 	int rc;
248da6c28aaSamw 
249da6c28aaSamw 	op->desired_access = smb_omode_to_amask(op->omode);
250*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	op->share_access = smb_denymode_to_sharemode(op->omode,
251*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    op->fqi.fq_path.pn_path);
2528c10a865Sas200622 	op->crtime.tv_sec = op->crtime.tv_nsec = 0;
253da6c28aaSamw 	op->create_disposition = FILE_OPEN;
2542c1b14e5Sjose borrego 	op->create_options = FILE_NON_DIRECTORY_FILE;
2552c1b14e5Sjose borrego 	if (op->omode & SMB_DA_WRITE_THROUGH)
2562c1b14e5Sjose borrego 		op->create_options |= FILE_WRITE_THROUGH;
257da6c28aaSamw 
258da6c28aaSamw 	if (sr->smb_flg & SMB_FLAGS_OPLOCK) {
2592c2961f8Sjose borrego 		if (sr->smb_flg & SMB_FLAGS_OPLOCK_NOTIFY_ANY)
2602c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_BATCH;
2612c2961f8Sjose borrego 		else
2622c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
263da6c28aaSamw 	} else {
2642c2961f8Sjose borrego 		op->op_oplock_level = SMB_OPLOCK_NONE;
265da6c28aaSamw 	}
266da6c28aaSamw 
2677b59d02dSjb150015 	if (smb_common_open(sr) != NT_STATUS_SUCCESS)
268faa1795aSjb150015 		return (SDRC_ERROR);
269da6c28aaSamw 
2702c2961f8Sjose borrego 	if (op->op_oplock_level == SMB_OPLOCK_NONE) {
271da6c28aaSamw 		sr->smb_flg &=
272da6c28aaSamw 		    ~(SMB_FLAGS_OPLOCK | SMB_FLAGS_OPLOCK_NOTIFY_ANY);
273da6c28aaSamw 	}
274da6c28aaSamw 
2752c2961f8Sjose borrego 	if (smb_open_dsize_check && op->dsize > UINT_MAX) {
2762c2961f8Sjose borrego 		smbsr_error(sr, 0, ERRDOS, ERRbadaccess);
277faa1795aSjb150015 		return (SDRC_ERROR);
2787b59d02dSjb150015 	}
279da6c28aaSamw 
280da6c28aaSamw 	file_attr = op->dattr  & FILE_ATTRIBUTE_MASK;
2818c10a865Sas200622 	node = sr->fid_ofile->f_node;
282da6c28aaSamw 
2837b59d02dSjb150015 	rc = smbsr_encode_result(sr, 7, 0, "bwwllww",
284da6c28aaSamw 	    7,
285da6c28aaSamw 	    sr->smb_fid,
286da6c28aaSamw 	    file_attr,
2878c10a865Sas200622 	    smb_gmt2local(sr, node->attr.sa_vattr.va_mtime.tv_sec),
288da6c28aaSamw 	    (uint32_t)op->dsize,
2892c2961f8Sjose borrego 	    op->omode,
290da6c28aaSamw 	    (uint16_t)0);	/* bcc */
291da6c28aaSamw 
292faa1795aSjb150015 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
293da6c28aaSamw }
294da6c28aaSamw 
2952c1b14e5Sjose borrego /*
2962c1b14e5Sjose borrego  * smb_pre_open_andx
2972c1b14e5Sjose borrego  * For compatibility with windows servers, the search attributes
2982c1b14e5Sjose borrego  * specified in the request are ignored.
2992c1b14e5Sjose borrego  */
3007b59d02dSjb150015 smb_sdrc_t
301faa1795aSjb150015 smb_pre_open_andx(smb_request_t *sr)
302da6c28aaSamw {
303da6c28aaSamw 	struct open_param *op = &sr->arg.open;
304da6c28aaSamw 	uint16_t flags;
3058c10a865Sas200622 	uint32_t creation_time;
3062c1b14e5Sjose borrego 	uint16_t file_attr, sattr;
307da6c28aaSamw 	int rc;
308da6c28aaSamw 
309da6c28aaSamw 	bzero(op, sizeof (sr->arg.open));
310faa1795aSjb150015 
311da6c28aaSamw 	rc = smbsr_decode_vwv(sr, "b.wwwwwlwll4.", &sr->andx_com,
3122c1b14e5Sjose borrego 	    &sr->andx_off, &flags, &op->omode, &sattr,
3132c2961f8Sjose borrego 	    &file_attr, &creation_time, &op->ofun, &op->dsize, &op->timeo);
314da6c28aaSamw 
315faa1795aSjb150015 	if (rc == 0) {
316*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		rc = smbsr_decode_data(sr, "%u", sr, &op->fqi.fq_path.pn_path);
317faa1795aSjb150015 
318faa1795aSjb150015 		op->dattr = file_attr;
319faa1795aSjb150015 
320faa1795aSjb150015 		if (flags & 2)
3212c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
322faa1795aSjb150015 		else if (flags & 4)
3232c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_BATCH;
3242c2961f8Sjose borrego 		else
3252c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_NONE;
326faa1795aSjb150015 
3278c10a865Sas200622 		if ((creation_time != 0) && (creation_time != UINT_MAX))
3288c10a865Sas200622 			op->crtime.tv_sec = smb_local2gmt(sr, creation_time);
3298c10a865Sas200622 		op->crtime.tv_nsec = 0;
330faa1795aSjb150015 
3312c2961f8Sjose borrego 		op->create_disposition = smb_ofun_to_crdisposition(op->ofun);
332faa1795aSjb150015 	}
333faa1795aSjb150015 
334faa1795aSjb150015 	DTRACE_SMB_2(op__OpenX__start, smb_request_t *, sr,
335faa1795aSjb150015 	    struct open_param *, op);
336faa1795aSjb150015 
337faa1795aSjb150015 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
338faa1795aSjb150015 }
339faa1795aSjb150015 
340faa1795aSjb150015 void
341faa1795aSjb150015 smb_post_open_andx(smb_request_t *sr)
342faa1795aSjb150015 {
343faa1795aSjb150015 	DTRACE_SMB_1(op__OpenX__done, smb_request_t *, sr);
344faa1795aSjb150015 }
345faa1795aSjb150015 
346faa1795aSjb150015 smb_sdrc_t
347faa1795aSjb150015 smb_com_open_andx(smb_request_t *sr)
348faa1795aSjb150015 {
349faa1795aSjb150015 	struct open_param	*op = &sr->arg.open;
350faa1795aSjb150015 	uint16_t		file_attr;
351faa1795aSjb150015 	int rc;
352da6c28aaSamw 
353da6c28aaSamw 	op->desired_access = smb_omode_to_amask(op->omode);
354*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	op->share_access = smb_denymode_to_sharemode(op->omode,
355*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    op->fqi.fq_path.pn_path);
356da6c28aaSamw 
3572c2961f8Sjose borrego 	if (op->create_disposition > FILE_MAXIMUM_DISPOSITION) {
3582c2961f8Sjose borrego 		smbsr_error(sr, 0, ERRDOS, ERRbadaccess);
359faa1795aSjb150015 		return (SDRC_ERROR);
360da6c28aaSamw 	}
361da6c28aaSamw 
3622c1b14e5Sjose borrego 	op->create_options = FILE_NON_DIRECTORY_FILE;
3632c1b14e5Sjose borrego 	if (op->omode & SMB_DA_WRITE_THROUGH)
3642c1b14e5Sjose borrego 		op->create_options |= FILE_WRITE_THROUGH;
365da6c28aaSamw 
3667b59d02dSjb150015 	if (smb_common_open(sr) != NT_STATUS_SUCCESS)
367faa1795aSjb150015 		return (SDRC_ERROR);
368da6c28aaSamw 
3692c2961f8Sjose borrego 	if (smb_open_dsize_check && op->dsize > UINT_MAX) {
3702c2961f8Sjose borrego 		smbsr_error(sr, 0, ERRDOS, ERRbadaccess);
371faa1795aSjb150015 		return (SDRC_ERROR);
3727b59d02dSjb150015 	}
373da6c28aaSamw 
3742c2961f8Sjose borrego 	if (op->op_oplock_level != SMB_OPLOCK_NONE)
375da6c28aaSamw 		op->action_taken |= SMB_OACT_LOCK;
3762c2961f8Sjose borrego 	else
377da6c28aaSamw 		op->action_taken &= ~SMB_OACT_LOCK;
378da6c28aaSamw 
379da6c28aaSamw 	file_attr = op->dattr & FILE_ATTRIBUTE_MASK;
380da6c28aaSamw 	if (STYPE_ISDSK(sr->tid_tree->t_res_type)) {
381da6c28aaSamw 		smb_node_t *node = sr->fid_ofile->f_node;
3827b59d02dSjb150015 		rc = smbsr_encode_result(sr, 15, 0,
383da6c28aaSamw 		    "bb.wwwllwwwwl2.w",
384da6c28aaSamw 		    15,
385da6c28aaSamw 		    sr->andx_com, VAR_BCC,
386da6c28aaSamw 		    sr->smb_fid,
387da6c28aaSamw 		    file_attr,
388faa1795aSjb150015 		    smb_gmt2local(sr, node->attr.sa_vattr.va_mtime.tv_sec),
389da6c28aaSamw 		    (uint32_t)op->dsize,
3902c2961f8Sjose borrego 		    op->omode, op->ftype,
391da6c28aaSamw 		    op->devstate,
392da6c28aaSamw 		    op->action_taken, op->fileid,
393da6c28aaSamw 		    0);
394da6c28aaSamw 	} else {
3957b59d02dSjb150015 		rc = smbsr_encode_result(sr, 15, 0,
396da6c28aaSamw 		    "bb.wwwllwwwwl2.w",
397da6c28aaSamw 		    15,
398da6c28aaSamw 		    sr->andx_com, VAR_BCC,
399da6c28aaSamw 		    sr->smb_fid,
400da6c28aaSamw 		    file_attr,
401da6c28aaSamw 		    0L,
402da6c28aaSamw 		    0L,
4032c2961f8Sjose borrego 		    op->omode, op->ftype,
404da6c28aaSamw 		    op->devstate,
405da6c28aaSamw 		    op->action_taken, op->fileid,
406da6c28aaSamw 		    0);
407da6c28aaSamw 	}
408da6c28aaSamw 
409faa1795aSjb150015 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
410da6c28aaSamw }
4112c2961f8Sjose borrego 
4122c2961f8Sjose borrego smb_sdrc_t
4132c2961f8Sjose borrego smb_com_trans2_open2(smb_request_t *sr, smb_xa_t *xa)
4142c2961f8Sjose borrego {
4152c2961f8Sjose borrego 	struct open_param *op = &sr->arg.open;
4162c2961f8Sjose borrego 	uint32_t	creation_time;
4172c2961f8Sjose borrego 	uint32_t	alloc_size;
4182c2961f8Sjose borrego 	uint16_t	flags;
4192c2961f8Sjose borrego 	uint16_t	file_attr;
4202c2961f8Sjose borrego 	int		rc;
4212c2961f8Sjose borrego 
4222c2961f8Sjose borrego 	bzero(op, sizeof (sr->arg.open));
4232c2961f8Sjose borrego 
4242c2961f8Sjose borrego 	rc = smb_mbc_decodef(&xa->req_param_mb, "%wwwwlwl10.u",
425*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    sr, &flags, &op->omode, &op->fqi.fq_sattr, &file_attr,
426*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    &creation_time, &op->ofun, &alloc_size, &op->fqi.fq_path.pn_path);
4272c2961f8Sjose borrego 	if (rc != 0)
4282c2961f8Sjose borrego 		return (SDRC_ERROR);
4292c2961f8Sjose borrego 
4302c2961f8Sjose borrego 	if ((creation_time != 0) && (creation_time != UINT_MAX))
4312c2961f8Sjose borrego 		op->crtime.tv_sec = smb_local2gmt(sr, creation_time);
4322c2961f8Sjose borrego 	op->crtime.tv_nsec = 0;
4332c2961f8Sjose borrego 
4342c2961f8Sjose borrego 	op->dattr = file_attr;
4352c2961f8Sjose borrego 	op->dsize = alloc_size;
4362c2961f8Sjose borrego 	op->create_options = FILE_NON_DIRECTORY_FILE;
4372c2961f8Sjose borrego 
4382c2961f8Sjose borrego 	op->desired_access = smb_omode_to_amask(op->omode);
439*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	op->share_access = smb_denymode_to_sharemode(op->omode,
440*eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 	    op->fqi.fq_path.pn_path);
4412c2961f8Sjose borrego 
4422c2961f8Sjose borrego 	op->create_disposition = smb_ofun_to_crdisposition(op->ofun);
4432c2961f8Sjose borrego 	if (op->create_disposition > FILE_MAXIMUM_DISPOSITION)
4442c2961f8Sjose borrego 		op->create_disposition = FILE_CREATE;
4452c2961f8Sjose borrego 
4462c2961f8Sjose borrego 	if (op->omode & SMB_DA_WRITE_THROUGH)
4472c2961f8Sjose borrego 		op->create_options |= FILE_WRITE_THROUGH;
4482c2961f8Sjose borrego 
4492c2961f8Sjose borrego 	if (sr->smb_flg & SMB_FLAGS_OPLOCK) {
4502c2961f8Sjose borrego 		if (sr->smb_flg & SMB_FLAGS_OPLOCK_NOTIFY_ANY)
4512c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_BATCH;
4522c2961f8Sjose borrego 		else
4532c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
4542c2961f8Sjose borrego 	} else {
4552c2961f8Sjose borrego 		op->op_oplock_level = SMB_OPLOCK_NONE;
4562c2961f8Sjose borrego 	}
4572c2961f8Sjose borrego 
4582c2961f8Sjose borrego 	if (smb_common_open(sr) != NT_STATUS_SUCCESS)
4592c2961f8Sjose borrego 		return (SDRC_ERROR);
4602c2961f8Sjose borrego 
4612c2961f8Sjose borrego 	if (op->op_oplock_level != SMB_OPLOCK_NONE)
4622c2961f8Sjose borrego 		op->action_taken |= SMB_OACT_LOCK;
4632c2961f8Sjose borrego 	else
4642c2961f8Sjose borrego 		op->action_taken &= ~SMB_OACT_LOCK;
4652c2961f8Sjose borrego 
4662c2961f8Sjose borrego 	file_attr = op->dattr & FILE_ATTRIBUTE_MASK;
4672c2961f8Sjose borrego 
4682c2961f8Sjose borrego 	if (!STYPE_ISDSK(sr->tid_tree->t_res_type))
4692c2961f8Sjose borrego 		op->dsize = 0;
4702c2961f8Sjose borrego 
4712c2961f8Sjose borrego 	(void) smb_mbc_encodef(&xa->rep_param_mb, "wwllwwwwlwl",
4722c2961f8Sjose borrego 	    sr->smb_fid,
4732c2961f8Sjose borrego 	    file_attr,
4742c2961f8Sjose borrego 	    (uint32_t)0,	/* creation time */
4752c2961f8Sjose borrego 	    (uint32_t)op->dsize,
4762c2961f8Sjose borrego 	    op->omode,
4772c2961f8Sjose borrego 	    op->ftype,
4782c2961f8Sjose borrego 	    op->devstate,
4792c2961f8Sjose borrego 	    op->action_taken,
4802c2961f8Sjose borrego 	    op->fileid,
4812c2961f8Sjose borrego 	    (uint16_t)0,	/* EA error offset */
4822c2961f8Sjose borrego 	    (uint32_t)0);	/* EA list length */
4832c2961f8Sjose borrego 
4842c2961f8Sjose borrego 	return (SDRC_SUCCESS);
4852c2961f8Sjose borrego }
486