xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_nt_create_andx.c (revision 94047d49916b669576decf2f622a1ee718646882)
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 /*
22cb174861Sjoyce mcintosh  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2393bc28dbSGordon Ross  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
24da6c28aaSamw  */
25da6c28aaSamw 
26da6c28aaSamw /*
27da6c28aaSamw  * This command is used to create or open a file or directory.
28da6c28aaSamw  */
29da6c28aaSamw 
30da6c28aaSamw 
31bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
32da6c28aaSamw #include <smbsrv/smb_fsops.h>
33da6c28aaSamw #include <smbsrv/smb_vops.h>
34da6c28aaSamw 
35c5f48fa5SGordon Ross int smb_nt_create_enable_extended_response = 1;
36c5f48fa5SGordon Ross 
37da6c28aaSamw /*
38da6c28aaSamw  * smb_com_nt_create_andx
39da6c28aaSamw  *
40da6c28aaSamw  * This command is used to create or open a file or directory.
41da6c28aaSamw  *
42da6c28aaSamw  *  Client Request                     Description
43da6c28aaSamw  *  =================================  ==================================
44da6c28aaSamw  *
45da6c28aaSamw  *  UCHAR WordCount;                   Count of parameter words = 24
46da6c28aaSamw  *  UCHAR AndXCommand;                 Secondary command;  0xFF = None
47da6c28aaSamw  *  UCHAR AndXReserved;                Reserved (must be 0)
48da6c28aaSamw  *  USHORT AndXOffset;                 Offset to next command WordCount
49da6c28aaSamw  *  UCHAR Reserved;                    Reserved (must be 0)
50da6c28aaSamw  *  USHORT NameLength;                 Length of Name[] in bytes
51da6c28aaSamw  *  ULONG Flags;                       Create bit set:
52da6c28aaSamw  *                                     0x02 - Request an oplock
53da6c28aaSamw  *                                     0x04 - Request a batch oplock
54da6c28aaSamw  *                                     0x08 - Target of open must be
55da6c28aaSamw  *                                     directory
56da6c28aaSamw  *  ULONG RootDirectoryFid;            If non-zero, open is relative to
57da6c28aaSamw  *                                     this directory
58da6c28aaSamw  *  ACCESS_MASK DesiredAccess;         access desired
59da6c28aaSamw  *  LARGE_INTEGER AllocationSize;      Initial allocation size
60da6c28aaSamw  *  ULONG ExtFileAttributes;           File attributes
61da6c28aaSamw  *  ULONG ShareAccess;                 Type of share access
62da6c28aaSamw  *  ULONG CreateDisposition;           Action to take if file exists or
63da6c28aaSamw  *                                     not
64da6c28aaSamw  *  ULONG CreateOptions;               Options to use if creating a file
65da6c28aaSamw  *  ULONG ImpersonationLevel;          Security QOS information
66da6c28aaSamw  *  UCHAR SecurityFlags;               Security tracking mode flags:
67da6c28aaSamw  *                                     0x1 - SECURITY_CONTEXT_TRACKING
68da6c28aaSamw  *                                     0x2 - SECURITY_EFFECTIVE_ONLY
69da6c28aaSamw  *  USHORT ByteCount;                  Length of byte parameters
70da6c28aaSamw  *  STRING Name[];                     File to open or create
71da6c28aaSamw  *
72da6c28aaSamw  * The DesiredAccess parameter is specified in section 3.7 on  Access Mask
73da6c28aaSamw  * Encoding.
74da6c28aaSamw  *
75da6c28aaSamw  * If no value is specified, it still allows an application to query
76da6c28aaSamw  * attributes without actually accessing the file.
77da6c28aaSamw  *
78da6c28aaSamw  * The ExtFIleAttributes parameter specifies the file attributes and flags
79da6c28aaSamw  * for the file. The parameter's value is the sum of allowed attributes and
80da6c28aaSamw  * flags defined in section 3.11 on  Extended File Attribute Encoding
81da6c28aaSamw  *
82da6c28aaSamw  * The ShareAccess field Specifies how this file can be shared. This
83da6c28aaSamw  * parameter must be some combination of the following values:
84da6c28aaSamw  *
85da6c28aaSamw  * Name              Value      Meaning
86da6c28aaSamw  *                   0          Prevents the file from being shared.
87da6c28aaSamw  * FILE_SHARE_READ   0x00000001 Other open operations can be performed on
88da6c28aaSamw  *                               the file for read access.
89da6c28aaSamw  * FILE_SHARE_WRITE  0x00000002 Other open operations can be performed on
90da6c28aaSamw  *                               the file for write access.
91da6c28aaSamw  * FILE_SHARE_DELETE 0x00000004 Other open operations can be performed on
92da6c28aaSamw  *                               the file for delete access.
93da6c28aaSamw  *
94da6c28aaSamw  * The CreateDisposition parameter can contain one of the following values:
95da6c28aaSamw  *
96da6c28aaSamw  * CREATE_NEW        Creates a new file. The function fails if the
97da6c28aaSamw  *                   specified file already exists.
98da6c28aaSamw  * CREATE_ALWAYS     Creates a new file. The function overwrites the file
99da6c28aaSamw  *                   if it exists.
100da6c28aaSamw  * OPEN_EXISTING     Opens the file. The function fails if the file does
101da6c28aaSamw  *                   not exist.
102da6c28aaSamw  * OPEN_ALWAYS       Opens the file, if it exists. If the file does not
103da6c28aaSamw  *                   exist, act like CREATE_NEW.
104da6c28aaSamw  * TRUNCATE_EXISTING Opens the file. Once opened, the file is truncated so
105da6c28aaSamw  *                   that its size is zero bytes. The calling process must
106da6c28aaSamw  *                   open the file with at least GENERIC_WRITE access. The
107da6c28aaSamw  *                   function fails if the file does not exist.
108da6c28aaSamw  *
109da6c28aaSamw  * The ImpersonationLevel parameter can contain one or more of the
110da6c28aaSamw  * following values:
111da6c28aaSamw  *
112da6c28aaSamw  * SECURITY_ANONYMOUS        Specifies to impersonate the client at the
113da6c28aaSamw  *                           Anonymous impersonation level.
114da6c28aaSamw  * SECURITY_IDENTIFICATION   Specifies to impersonate the client at the
115da6c28aaSamw  *                           Identification impersonation level.
116da6c28aaSamw  * SECURITY_IMPERSONATION    Specifies to impersonate the client at the
117da6c28aaSamw  *                           Impersonation impersonation level.
118da6c28aaSamw  * SECURITY_DELEGATION       Specifies to impersonate the client at the
119da6c28aaSamw  *                           Delegation impersonation level.
120da6c28aaSamw  *
121da6c28aaSamw  * The SecurityFlags parameter can have either of the following two flags
122da6c28aaSamw  * set:
123da6c28aaSamw  *
124da6c28aaSamw  * SECURITY_CONTEXT_TRACKING  Specifies that the security tracking mode is
125da6c28aaSamw  *                            dynamic. If this flag is not specified,
126da6c28aaSamw  *                            Security Tracking Mode is static.
127da6c28aaSamw  * SECURITY_EFFECTIVE_ONLY    Specifies that only the enabled aspects of
128da6c28aaSamw  *                            the client's security context are available
129da6c28aaSamw  *                            to the server. If you do not specify this
130da6c28aaSamw  *                            flag, all aspects of the client's security
131da6c28aaSamw  *                            context are available. This flag allows the
132da6c28aaSamw  *                            client to limit the groups and privileges
133da6c28aaSamw  *                            that a server can use while impersonating the
134da6c28aaSamw  *                            client.
135da6c28aaSamw  *
136da6c28aaSamw  * The response is as follows:
137da6c28aaSamw  *
138da6c28aaSamw  *  Server Response                    Description
139da6c28aaSamw  *  =================================  ==================================
140da6c28aaSamw  *
141da6c28aaSamw  *  UCHAR WordCount;                   Count of parameter words = 26
142da6c28aaSamw  *  UCHAR AndXCommand;  Secondary      0xFF = None
143da6c28aaSamw  *  command;
144da6c28aaSamw  *  UCHAR AndXReserved;                MBZ
145da6c28aaSamw  *  USHORT AndXOffset;                 Offset to next command WordCount
146da6c28aaSamw  *  UCHAR OplockLevel;                 The oplock level granted
147da6c28aaSamw  *                                     0 - No oplock granted
148da6c28aaSamw  *                                     1 - Exclusive oplock granted
149da6c28aaSamw  *                                     2 - Batch oplock granted
150da6c28aaSamw  *                                     3 - Level II oplock granted
151da6c28aaSamw  *  USHORT Fid;                        The file ID
152da6c28aaSamw  *  ULONG CreateAction;                The action taken
153da6c28aaSamw  *  TIME CreationTime;                 The time the file was created
154da6c28aaSamw  *  TIME LastAccessTime;               The time the file was accessed
155da6c28aaSamw  *  TIME LastWriteTime;                The time the file was last written
156da6c28aaSamw  *  TIME ChangeTime;                   The time the file was last changed
157da6c28aaSamw  *  ULONG ExtFileAttributes;           The file attributes
158da6c28aaSamw  *  LARGE_INTEGER AllocationSize;      The number of bytes allocated
159da6c28aaSamw  *  LARGE_INTEGER EndOfFile;           The end of file offset
160da6c28aaSamw  *  USHORT FileType;
161da6c28aaSamw  *  USHORT DeviceState;                state of IPC device (e.g. pipe)
162da6c28aaSamw  *  BOOLEAN Directory;                 TRUE if this is a directory
163da6c28aaSamw  *  USHORT ByteCount;                  = 0
164da6c28aaSamw  *
165da6c28aaSamw  * The following SMBs may follow SMB_COM_NT_CREATE_ANDX:
166da6c28aaSamw  *
167da6c28aaSamw  *    SMB_COM_READ    SMB_COM_READ_ANDX
168da6c28aaSamw  *    SMB_COM_IOCTL
169da6c28aaSamw  */
1707b59d02dSjb150015 smb_sdrc_t
smb_pre_nt_create_andx(smb_request_t * sr)171faa1795aSjb150015 smb_pre_nt_create_andx(smb_request_t *sr)
172da6c28aaSamw {
173da6c28aaSamw 	struct open_param *op = &sr->arg.open;
174faa1795aSjb150015 	uint8_t SecurityFlags;
175da6c28aaSamw 	uint32_t ImpersonationLevel;
176faa1795aSjb150015 	uint16_t NameLength;
177da6c28aaSamw 	int rc;
178da6c28aaSamw 
179faa1795aSjb150015 	bzero(op, sizeof (sr->arg.open));
180da6c28aaSamw 
181da6c28aaSamw 	rc = smbsr_decode_vwv(sr, "5.wlllqlllllb",
182da6c28aaSamw 	    &NameLength,
1832c2961f8Sjose borrego 	    &op->nt_flags,
184faa1795aSjb150015 	    &op->rootdirfid,
185da6c28aaSamw 	    &op->desired_access,
186da6c28aaSamw 	    &op->dsize,
187faa1795aSjb150015 	    &op->dattr,
188da6c28aaSamw 	    &op->share_access,
189da6c28aaSamw 	    &op->create_disposition,
190da6c28aaSamw 	    &op->create_options,
191da6c28aaSamw 	    &ImpersonationLevel,
192da6c28aaSamw 	    &SecurityFlags);
193da6c28aaSamw 
194faa1795aSjb150015 	if (rc == 0) {
195faa1795aSjb150015 		if (NameLength == 0) {
196eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			op->fqi.fq_path.pn_path = "\\";
197b24e356bSPeer Dampmann 		} else if (NameLength >= SMB_MAXPATHLEN) {
198b24e356bSPeer Dampmann 			smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
199faa1795aSjb150015 			    ERRDOS, ERROR_PATH_NOT_FOUND);
200faa1795aSjb150015 			rc = -1;
201faa1795aSjb150015 		} else {
202faa1795aSjb150015 			rc = smbsr_decode_data(sr, "%#u", sr, NameLength,
203eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 			    &op->fqi.fq_path.pn_path);
204da6c28aaSamw 		}
205da6c28aaSamw 	}
206da6c28aaSamw 
2072c2961f8Sjose borrego 	op->op_oplock_level = SMB_OPLOCK_NONE;
2082c2961f8Sjose borrego 	if (op->nt_flags & NT_CREATE_FLAG_REQUEST_OPLOCK) {
2092c2961f8Sjose borrego 		if (op->nt_flags & NT_CREATE_FLAG_REQUEST_OPBATCH)
2102c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_BATCH;
2112c2961f8Sjose borrego 		else
2122c2961f8Sjose borrego 			op->op_oplock_level = SMB_OPLOCK_EXCLUSIVE;
213da6c28aaSamw 	}
214da6c28aaSamw 
21593bc28dbSGordon Ross 	DTRACE_SMB_START(op__NtCreateX, smb_request_t *, sr); /* arg.open */
216faa1795aSjb150015 
217faa1795aSjb150015 	return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
218faa1795aSjb150015 }
219faa1795aSjb150015 
220faa1795aSjb150015 void
smb_post_nt_create_andx(smb_request_t * sr)221faa1795aSjb150015 smb_post_nt_create_andx(smb_request_t *sr)
222faa1795aSjb150015 {
22393bc28dbSGordon Ross 	DTRACE_SMB_DONE(op__NtCreateX, smb_request_t *, sr);
224bbf6f00cSJordan Brown 
225bbf6f00cSJordan Brown 	if (sr->arg.open.dir != NULL) {
226bbf6f00cSJordan Brown 		smb_ofile_release(sr->arg.open.dir);
227bbf6f00cSJordan Brown 		sr->arg.open.dir = NULL;
228bbf6f00cSJordan Brown 	}
229faa1795aSjb150015 }
230faa1795aSjb150015 
231c5f48fa5SGordon Ross /*
232c5f48fa5SGordon Ross  * A lot like smb_nt_transact_create
233c5f48fa5SGordon Ross  */
234faa1795aSjb150015 smb_sdrc_t
smb_com_nt_create_andx(struct smb_request * sr)235faa1795aSjb150015 smb_com_nt_create_andx(struct smb_request *sr)
236faa1795aSjb150015 {
237faa1795aSjb150015 	struct open_param	*op = &sr->arg.open;
2385fd03bc0SGordon Ross 	smb_attr_t		*ap = &op->fqi.fq_fattr;
2395fd03bc0SGordon Ross 	smb_ofile_t		*of;
240faa1795aSjb150015 	int			rc;
241c5f48fa5SGordon Ross 	uint8_t			DirFlag;
242a90cf9f2SGordon Ross 	uint32_t		status;
243faa1795aSjb150015 
244c5f48fa5SGordon Ross 	if (op->create_options & ~SMB_NTCREATE_VALID_OPTIONS) {
245c5f48fa5SGordon Ross 		smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
246c5f48fa5SGordon Ross 		    ERRDOS, ERROR_INVALID_PARAMETER);
247c5f48fa5SGordon Ross 		return (SDRC_ERROR);
248c5f48fa5SGordon Ross 	}
249c5f48fa5SGordon Ross 
250c5f48fa5SGordon Ross 	if (op->create_options & FILE_OPEN_BY_FILE_ID) {
251c5f48fa5SGordon Ross 		smbsr_error(sr, NT_STATUS_NOT_SUPPORTED,
252c5f48fa5SGordon Ross 		    ERRDOS, ERROR_NOT_SUPPORTED);
253c5f48fa5SGordon Ross 		return (SDRC_ERROR);
254c5f48fa5SGordon Ross 	}
255c5f48fa5SGordon Ross 
256faa1795aSjb150015 	if ((op->create_options & FILE_DELETE_ON_CLOSE) &&
257faa1795aSjb150015 	    !(op->desired_access & DELETE)) {
2582c2961f8Sjose borrego 		smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
2592c2961f8Sjose borrego 		    ERRDOS, ERRbadaccess);
2602c2961f8Sjose borrego 		return (SDRC_ERROR);
2612c2961f8Sjose borrego 	}
2622c2961f8Sjose borrego 
2632c2961f8Sjose borrego 	if (op->create_disposition > FILE_MAXIMUM_DISPOSITION) {
2642c2961f8Sjose borrego 		smbsr_error(sr, NT_STATUS_INVALID_PARAMETER,
2652c2961f8Sjose borrego 		    ERRDOS, ERRbadaccess);
266faa1795aSjb150015 		return (SDRC_ERROR);
267faa1795aSjb150015 	}
268faa1795aSjb150015 
269faa1795aSjb150015 	if (op->dattr & FILE_FLAG_WRITE_THROUGH)
270da6c28aaSamw 		op->create_options |= FILE_WRITE_THROUGH;
271da6c28aaSamw 
272faa1795aSjb150015 	if (op->dattr & FILE_FLAG_DELETE_ON_CLOSE)
273da6c28aaSamw 		op->create_options |= FILE_DELETE_ON_CLOSE;
274da6c28aaSamw 
275b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (op->dattr & FILE_FLAG_BACKUP_SEMANTICS)
276b89a8333Snatalie li - Sun Microsystems - Irvine United States 		op->create_options |= FILE_OPEN_FOR_BACKUP_INTENT;
277b89a8333Snatalie li - Sun Microsystems - Irvine United States 
278b89a8333Snatalie li - Sun Microsystems - Irvine United States 	if (op->create_options & FILE_OPEN_FOR_BACKUP_INTENT)
279b89a8333Snatalie li - Sun Microsystems - Irvine United States 		sr->user_cr = smb_user_getprivcred(sr->uid_user);
280b89a8333Snatalie li - Sun Microsystems - Irvine United States 
281faa1795aSjb150015 	if (op->rootdirfid == 0) {
282eb1d736bSafshin salek ardakani - Sun Microsystems - Irvine United States 		op->fqi.fq_dnode = sr->tid_tree->t_snode;
283da6c28aaSamw 	} else {
2843b13a1efSThomas Keiser 		op->dir = smb_ofile_lookup_by_fid(sr, (uint16_t)op->rootdirfid);
285bbf6f00cSJordan Brown 		if (op->dir == NULL) {
286dc20a302Sas200622 			smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
287da6c28aaSamw 			    ERRDOS, ERRbadfid);
288faa1795aSjb150015 			return (SDRC_ERROR);
289da6c28aaSamw 		}
290bbf6f00cSJordan Brown 		op->fqi.fq_dnode = op->dir->f_node;
291da6c28aaSamw 	}
292da6c28aaSamw 
293a90cf9f2SGordon Ross 	status = smb_common_open(sr);
294a90cf9f2SGordon Ross 	if (status != NT_STATUS_SUCCESS) {
295a90cf9f2SGordon Ross 		smbsr_status(sr, status, 0, 0);
296faa1795aSjb150015 		return (SDRC_ERROR);
297a90cf9f2SGordon Ross 	}
298*94047d49SGordon Ross 	if (op->op_oplock_level != SMB_OPLOCK_NONE) {
299*94047d49SGordon Ross 		/* Oplock req. in op->op_oplock_level etc. */
300*94047d49SGordon Ross 		smb1_oplock_acquire(sr, B_TRUE);
301*94047d49SGordon Ross 	}
302da6c28aaSamw 
3035fd03bc0SGordon Ross 	/*
3045fd03bc0SGordon Ross 	 * NB: after the above smb_common_open() success,
3055fd03bc0SGordon Ross 	 * we have a handle allocated (sr->fid_ofile).
3065fd03bc0SGordon Ross 	 * If we don't return success, we must close it.
3075fd03bc0SGordon Ross 	 */
3085fd03bc0SGordon Ross 	of = sr->fid_ofile;
3095fd03bc0SGordon Ross 
310f96bd5c8SAlan Wright 	switch (sr->tid_tree->t_res_type & STYPE_MASK) {
311f96bd5c8SAlan Wright 	case STYPE_DISKTREE:
312f96bd5c8SAlan Wright 	case STYPE_PRINTQ:
313da6c28aaSamw 		if (op->create_options & FILE_DELETE_ON_CLOSE)
314*94047d49SGordon Ross 			smb_ofile_set_delete_on_close(sr, of);
3155fd03bc0SGordon Ross 		DirFlag = smb_node_is_dir(of->f_node) ? 1 : 0;
316f96bd5c8SAlan Wright 		break;
317f96bd5c8SAlan Wright 
318f96bd5c8SAlan Wright 	case STYPE_IPC:
319c5f48fa5SGordon Ross 		DirFlag = 0;
320f96bd5c8SAlan Wright 		break;
321f96bd5c8SAlan Wright 
322f96bd5c8SAlan Wright 	default:
323f96bd5c8SAlan Wright 		smbsr_error(sr, NT_STATUS_INVALID_DEVICE_REQUEST,
324f96bd5c8SAlan Wright 		    ERRDOS, ERROR_INVALID_FUNCTION);
3255fd03bc0SGordon Ross 		goto errout;
326da6c28aaSamw 	}
327c5f48fa5SGordon Ross 
328c5f48fa5SGordon Ross 	if ((op->nt_flags & NT_CREATE_FLAG_EXTENDED_RESPONSE) != 0 &&
329c5f48fa5SGordon Ross 	    smb_nt_create_enable_extended_response != 0) {
330c5f48fa5SGordon Ross 		uint32_t MaxAccess = 0;
331c5f48fa5SGordon Ross 		if (of->f_node != NULL) {
332c5f48fa5SGordon Ross 			smb_fsop_eaccess(sr, of->f_cr, of->f_node, &MaxAccess);
333c5f48fa5SGordon Ross 		}
334c5f48fa5SGordon Ross 		MaxAccess |= of->f_granted_access;
335c5f48fa5SGordon Ross 
336c5f48fa5SGordon Ross 		/*
337c5f48fa5SGordon Ross 		 * Here is a really ugly protocol wart in SMB1:
338c5f48fa5SGordon Ross 		 *
339c5f48fa5SGordon Ross 		 * [MS-SMB] Sec. 2.2.4.9.2: Windows-based SMB servers
340c5f48fa5SGordon Ross 		 * send 50 (0x32) words in the extended response although
341c5f48fa5SGordon Ross 		 * they set the WordCount field to 0x2A.
342c5f48fa5SGordon Ross 		 *
343c5f48fa5SGordon Ross 		 * In other words, THEY LIE!  We really do need to encode
344c5f48fa5SGordon Ross 		 * 50 words here, but lie and say we encoded 42 words.
345c5f48fa5SGordon Ross 		 * This means we can't use smbsr_encode_result() to
346c5f48fa5SGordon Ross 		 * build this response, because the rules it breaks
347c5f48fa5SGordon Ross 		 * would cause errors in smbsr_check_result().
348c5f48fa5SGordon Ross 		 *
349c5f48fa5SGordon Ross 		 * And that's not all (it gets worse...)
350c5f48fa5SGordon Ross 		 * Because of the bogus word count, some clients will
351c5f48fa5SGordon Ross 		 * read the byte count from within what should be the
352c5f48fa5SGordon Ross 		 * fileid field below.  Leave that zero, like Win7.
353c5f48fa5SGordon Ross 		 *
354c5f48fa5SGordon Ross 		 * Apparently the only really useful thing in this
355c5f48fa5SGordon Ross 		 * extended response is MaxAccess.
356c5f48fa5SGordon Ross 		 */
357c5f48fa5SGordon Ross 		sr->smb_wct = 50; /* real word count */
358c5f48fa5SGordon Ross 		sr->smb_bcc = 0;
359c5f48fa5SGordon Ross 		rc = smb_mbc_encodef(&sr->reply,
360c5f48fa5SGordon Ross 		    "bb.wbwlTTTTlqqwwb16.qllw",
361c5f48fa5SGordon Ross 		    42,		/* fake word count (b) */
362c5f48fa5SGordon Ross 		    sr->andx_com,		/* (b.) */
363c5f48fa5SGordon Ross 		    0x87,	/* andx offset	   (w) */
364c5f48fa5SGordon Ross 		    op->op_oplock_level,	/* (b) */
365c5f48fa5SGordon Ross 		    sr->smb_fid,		/* (w) */
366c5f48fa5SGordon Ross 		    op->action_taken,		/* (l) */
367c5f48fa5SGordon Ross 		    &ap->sa_crtime,		/* (T) */
368c5f48fa5SGordon Ross 		    &ap->sa_vattr.va_atime,	/* (T) */
369c5f48fa5SGordon Ross 		    &ap->sa_vattr.va_mtime,	/* (T) */
370c5f48fa5SGordon Ross 		    &ap->sa_vattr.va_ctime,	/* (T) */
371c5f48fa5SGordon Ross 		    op->dattr & FILE_ATTRIBUTE_MASK, /* (l) */
372c5f48fa5SGordon Ross 		    ap->sa_allocsz,		/* (q) */
373c5f48fa5SGordon Ross 		    ap->sa_vattr.va_size,	/* (q) */
374c5f48fa5SGordon Ross 		    op->ftype,			/* (w) */
375c5f48fa5SGordon Ross 		    op->devstate,		/* (w) */
376c5f48fa5SGordon Ross 		    DirFlag,			/* (b) */
377c5f48fa5SGordon Ross 		    /* volume guid		  (16.) */
378c5f48fa5SGordon Ross 		    0,	/* file ID (see above)	   (q) */
379c5f48fa5SGordon Ross 		    MaxAccess,			/* (l) */
380c5f48fa5SGordon Ross 		    0,		/* guest access	   (l) */
381c5f48fa5SGordon Ross 		    0);		/* byte count	   (w) */
382c5f48fa5SGordon Ross 	} else {
383c5f48fa5SGordon Ross 		rc = smbsr_encode_result(
384c5f48fa5SGordon Ross 		    sr, 34, 0, "bb.wbwlTTTTlqqwwbw",
385c5f48fa5SGordon Ross 		    34,		/* word count	   (b) */
386c5f48fa5SGordon Ross 		    sr->andx_com,		/* (b.) */
387c5f48fa5SGordon Ross 		    0x67,	/* andx offset	   (w) */
388c5f48fa5SGordon Ross 		    op->op_oplock_level,	/* (b) */
389c5f48fa5SGordon Ross 		    sr->smb_fid,		/* (w) */
390c5f48fa5SGordon Ross 		    op->action_taken,		/* (l) */
391c5f48fa5SGordon Ross 		    &ap->sa_crtime,		/* (T) */
392c5f48fa5SGordon Ross 		    &ap->sa_vattr.va_atime,	/* (T) */
393c5f48fa5SGordon Ross 		    &ap->sa_vattr.va_mtime,	/* (T) */
394c5f48fa5SGordon Ross 		    &ap->sa_vattr.va_ctime,	/* (T) */
395c5f48fa5SGordon Ross 		    op->dattr & FILE_ATTRIBUTE_MASK, /* (l) */
396c5f48fa5SGordon Ross 		    ap->sa_allocsz,		/* (q) */
397c5f48fa5SGordon Ross 		    ap->sa_vattr.va_size,	/* (q) */
398c5f48fa5SGordon Ross 		    op->ftype,			/* (w) */
399c5f48fa5SGordon Ross 		    op->devstate,		/* (w) */
400c5f48fa5SGordon Ross 		    DirFlag,			/* (b) */
401c5f48fa5SGordon Ross 		    0);		/* byte count	   (w) */
402c5f48fa5SGordon Ross 	}
403c5f48fa5SGordon Ross 
4045fd03bc0SGordon Ross 	if (rc == 0)
4055fd03bc0SGordon Ross 		return (SDRC_SUCCESS);
406da6c28aaSamw 
4075fd03bc0SGordon Ross errout:
4085fd03bc0SGordon Ross 	smb_ofile_close(of, 0);
4095fd03bc0SGordon Ross 	return (SDRC_ERROR);
410da6c28aaSamw }
411