xref: /titanic_44/usr/src/uts/common/fs/smbsrv/smb_dispatch.c (revision 56b2bdd1f04d465cfe4a95b88ae5cba5884154e4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
24  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
25  */
26 
27 /*
28  * SMB requests.
29  *
30  * Request
31  *   Header
32  *	Magic		0xFF 'S' 'M' 'B'
33  *	smb_com 	a byte, the "first" command
34  *	Error		a 4-byte union, ignored in a request
35  *	smb_flg		a one byte set of eight flags
36  *	smb_flg2	a two byte set of 16 flags
37  *	.		twelve reserved bytes, have a role
38  *			in connectionless transports (IPX, UDP?)
39  *	smb_tid		a 16-bit tree ID, a mount point sorta,
40  *			0xFFFF is this command does not have
41  *			or require a tree context
42  *	smb_pid		a 16-bit process ID
43  *	smb_uid		a 16-bit user ID, specific to this "session"
44  *			and mapped to a system (bona-fide) UID
45  *	smb_mid		a 16-bit multiplex ID, used to differentiate
46  *			multiple simultaneous requests from the same
47  *			process (pid) (ref RPC "xid")
48  *
49  *   Chained (AndX) commands (0 or more)
50  *	smb_wct		a byte, number of 16-bit words containing
51  *			command parameters, min 2 for chained command
52  *	andx_com	a byte, the "next" command, 0xFF for none
53  *	.		an unused byte
54  *	andx_off	a 16-bit offset, byte displacement from &Magic
55  *			to the smb_wct field of the "next" command,
56  *			ignore if andx_com is 0xFF, s/b 0 if no next
57  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
58  *			"this" command (i.e. smb_com if this is the
59  *			first parameters, or the andx_com of the just
60  *			previous block.
61  *	smb_bcc		a 16-bit count of smb_data[] bytes
62  *	smb_data[]	0 or more bytes, format specific to commands
63  *	padding[]	Optional padding
64  *
65  *   Last command
66  *	smb_wct		a byte, number of 16-bit words containing
67  *			command parameters, min 0 for chained command
68  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
69  *			"this" command (i.e. smb_com if this is the
70  *			first parameters, or the andx_com of the just
71  *			previous block.
72  *	smb_bcc		a 16-bit count of smb_data[] bytes
73  *	smb_data[]	0 or more bytes, format specific to commands
74  *
75  * Reply
76  *   Header
77  *	Magic		0xFF 'S' 'M' 'B'
78  *	smb_com 	a byte, the "first" command, corresponds
79  *			to request
80  *	Error		a 4-byte union, coding depends on dialect in use
81  *			for "DOS" errors
82  *				a byte for error class
83  *				an unused byte
84  *				a 16-bit word for error code
85  *			for "NT" errors
86  *				a 32-bit error code which
87  *				is a packed class and specifier
88  *			for "OS/2" errors
89  *				I don't know
90  *			The error information is specific to the
91  *			last command in the reply chain.
92  *	smb_flg		a one byte set of eight flags, 0x80 bit set
93  *			indicating this message is a reply
94  *	smb_flg2	a two byte set of 16 flags
95  *	.		twelve reserved bytes, have a role
96  *			in connectionless transports (IPX, UDP?)
97  *	smb_tid		a 16-bit tree ID, a mount point sorta,
98  *			should be the same as the request
99  *	smb_pid		a 16-bit process ID, MUST BE the same as request
100  *	smb_uid		a 16-bit user ID, specific to this "session"
101  *			and mapped to a system (bona-fide) UID,
102  *			should be the same as request
103  *	smb_mid		a 16-bit multiplex ID, used to differentiate
104  *			multiple simultaneous requests from the same
105  *			process (pid) (ref RPC "xid"), MUST BE the
106  *			same as request
107  *	padding[]	Optional padding
108  *
109  *   Chained (AndX) commands (0 or more)
110  *	smb_wct		a byte, number of 16-bit words containing
111  *			command parameters, min 2 for chained command,
112  *	andx_com	a byte, the "next" command, 0xFF for none,
113  *			corresponds to request, if this is the chained
114  *			command that had an error set to 0xFF
115  *	.		an unused byte
116  *	andx_off	a 16-bit offset, byte displacement from &Magic
117  *			to the smb_wct field of the "next" command,
118  *			ignore if andx_com is 0xFF, s/b 0 if no next
119  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
120  *			"this" command (i.e. smb_com if this is the
121  *			first parameters, or the andx_com of the just
122  *			previous block. Empty if an error.
123  *	smb_bcc		a 16-bit count of smb_data[] bytes
124  *	smb_data[]	0 or more bytes, format specific to commands
125  *			empty if an error.
126  *
127  *   Last command
128  *	smb_wct		a byte, number of 16-bit words containing
129  *			command parameters, min 0 for chained command
130  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
131  *			"this" command (i.e. smb_com if this is the
132  *			first parameters, or the andx_com of the just
133  *			previous block, empty if an error.
134  *	smb_bcc		a 16-bit count of smb_data[] bytes
135  *	smb_data[]	0 or more bytes, format specific to commands,
136  *			empty if an error.
137  */
138 
139 #include <smbsrv/smb_kproto.h>
140 #include <smbsrv/smb_kstat.h>
141 #include <sys/sdt.h>
142 #include <sys/spl.h>
143 
144 static int smb_legacy_dispatch_stats_update(kstat_t *, int);
145 static int is_andx_com(unsigned char);
146 static int smbsr_check_result(struct smb_request *, int, int);
147 
148 static kstat_t *smb_legacy_dispatch_ksp = NULL;
149 static kmutex_t smb_legacy_dispatch_ksmtx;
150 
151 static smb_disp_entry_t	smb_disp_table[SMB_COM_NUM] = {
152 	{ "SmbCreateDirectory", SMB_SDT_OPS(create_directory),  /* 0x00 000 */
153 	    0x00, PC_NETWORK_PROGRAM_1_0 },
154 	{ "SmbDeleteDirectory", SMB_SDT_OPS(delete_directory),	/* 0x01 001 */
155 	    0x01, PC_NETWORK_PROGRAM_1_0 },
156 	{ "SmbOpen", SMB_SDT_OPS(open),				/* 0x02 002 */
157 	    0x02, PC_NETWORK_PROGRAM_1_0 },
158 	{ "SmbCreate", SMB_SDT_OPS(create),			/* 0x03 003 */
159 	    0x03, PC_NETWORK_PROGRAM_1_0 },
160 	{ "SmbClose", SMB_SDT_OPS(close),			/* 0x04 004 */
161 	    0x04, PC_NETWORK_PROGRAM_1_0 },
162 	{ "SmbFlush", SMB_SDT_OPS(flush),			/* 0x05 005 */
163 	    0x05, PC_NETWORK_PROGRAM_1_0 },
164 	{ "SmbDelete", SMB_SDT_OPS(delete),			/* 0x06 006 */
165 	    0x06, PC_NETWORK_PROGRAM_1_0 },
166 	{ "SmbRename", SMB_SDT_OPS(rename),			/* 0x07 007 */
167 	    0x07, PC_NETWORK_PROGRAM_1_0 },
168 	{ "SmbQueryInformation", SMB_SDT_OPS(query_information), /* 0x08 008 */
169 	    0x08, PC_NETWORK_PROGRAM_1_0 },
170 	{ "SmbSetInformation", SMB_SDT_OPS(set_information),	/* 0x09 009 */
171 	    0x09, PC_NETWORK_PROGRAM_1_0 },
172 	{ "SmbRead", SMB_SDT_OPS(read),				/* 0x0A 010 */
173 	    0x0A, PC_NETWORK_PROGRAM_1_0 },
174 	{ "SmbWrite", SMB_SDT_OPS(write),			/* 0x0B 011 */
175 	    0x0B, PC_NETWORK_PROGRAM_1_0 },
176 	{ "SmbLockByteRange", SMB_SDT_OPS(lock_byte_range),	/* 0x0C 012 */
177 	    0x0C, PC_NETWORK_PROGRAM_1_0 },
178 	{ "SmbUnlockByteRange", SMB_SDT_OPS(unlock_byte_range),	/* 0x0D 013 */
179 	    0x0D, PC_NETWORK_PROGRAM_1_0 },
180 	{ "SmbCreateTemporary", SMB_SDT_OPS(create_temporary),	/* 0x0E 014 */
181 	    0x0E, PC_NETWORK_PROGRAM_1_0 },
182 	{ "SmbCreateNew", SMB_SDT_OPS(create_new),		/* 0x0F 015 */
183 	    0x0F, PC_NETWORK_PROGRAM_1_0 },
184 	{ "SmbCheckDirectory", SMB_SDT_OPS(check_directory),	/* 0x10 016 */
185 	    0x10, PC_NETWORK_PROGRAM_1_0 },
186 	{ "SmbProcessExit", SMB_SDT_OPS(process_exit),		/* 0x11 017 */
187 	    0x11, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
188 	    0, 0, { 0 } },
189 	{ "SmbSeek", SMB_SDT_OPS(seek),				/* 0x12 018 */
190 	    0x12, PC_NETWORK_PROGRAM_1_0 },
191 	{ "SmbLockAndRead", SMB_SDT_OPS(lock_and_read),		/* 0x13 019 */
192 	    0x13, LANMAN1_0 },
193 	{ "SmbWriteAndUnlock", SMB_SDT_OPS(write_and_unlock),	/* 0x14 020 */
194 	    0x14, LANMAN1_0 },
195 	{ "Invalid", SMB_SDT_OPS(invalid), 0x15, 0 },		/* 0x15	021 */
196 	{ "Invalid", SMB_SDT_OPS(invalid), 0x16, 0 },		/* 0x16 022 */
197 	{ "Invalid", SMB_SDT_OPS(invalid), 0x17, 0 },		/* 0x17 023 */
198 	{ "Invalid", SMB_SDT_OPS(invalid), 0x18, 0 },		/* 0x18 024 */
199 	{ "Invalid", SMB_SDT_OPS(invalid), 0x19, 0 },		/* 0x19 025 */
200 	{ "SmbReadRaw", SMB_SDT_OPS(read_raw),			/* 0x1A 026 */
201 	    0x1A, LANMAN1_0 },
202 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1B, 0 },		/* 0x1B 027 */
203 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1C, 0 },		/* 0x1C 028 */
204 	{ "SmbWriteRaw", SMB_SDT_OPS(write_raw),		/* 0x1D 029 */
205 	    0x1D, LANMAN1_0 },
206 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1E, 0 },		/* 0x1E 030 */
207 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1F, 0 },		/* 0x1F 031 */
208 	{ "Invalid", SMB_SDT_OPS(invalid), 0x20, 0 },		/* 0x20 032 */
209 	{ "Invalid", SMB_SDT_OPS(invalid), 0x21, 0 },		/* 0x21 033 */
210 	{ "SmbSetInformation2", SMB_SDT_OPS(set_information2),	/* 0x22 034 */
211 	    0x22, LANMAN1_0 },
212 	{ "SmbQueryInformation2",
213 	    SMB_SDT_OPS(query_information2),			/* 0x23 035 */
214 	    0x23, LANMAN1_0 },
215 	{ "SmbLockingX", SMB_SDT_OPS(locking_andx),		/* 0x24 036 */
216 	    0x24, LANMAN1_0 },
217 	{ "SmbTransaction", SMB_SDT_OPS(transaction),		/* 0x25 037 */
218 	    0x25, LANMAN1_0 },
219 	{ "SmbTransactionSecondary",
220 	    SMB_SDT_OPS(transaction_secondary),			/* 0x26 038 */
221 	    0x26, LANMAN1_0 },
222 	{ "SmbIoctl", SMB_SDT_OPS(ioctl),			/* 0x27 039 */
223 	    0x27, LANMAN1_0 },
224 	{ "Invalid", SMB_SDT_OPS(invalid), 0x28, 0 },	/* 0x28 040 */
225 	{ "Invalid", SMB_SDT_OPS(invalid), 0x29, 0 },	/* 0x29 041 */
226 	{ "Invalid", SMB_SDT_OPS(invalid), 0x2A, 0 },	/* 0x2A 042 */
227 	{ "SmbEcho", SMB_SDT_OPS(echo),				/* 0x2B 043 */
228 	    0x2B, LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID },
229 	{ "SmbWriteAndClose", SMB_SDT_OPS(write_and_close),	/* 0x2C 044 */
230 	    0x2C, LANMAN1_0 },
231 	{ "SmbOpenX", SMB_SDT_OPS(open_andx),			/* 0x2D 045 */
232 	    0x2D, LANMAN1_0 },
233 	{ "SmbReadX", SMB_SDT_OPS(read_andx),			/* 0x2E 046 */
234 	    0x2E, LANMAN1_0 },
235 	{ "SmbWriteX", SMB_SDT_OPS(write_andx),			/* 0x2F 047 */
236 	    0x2F, LANMAN1_0 },
237 	{ "Invalid", SMB_SDT_OPS(invalid), 0x30, 0 },	/* 0x30 048 */
238 	{ "SmbCloseAndTreeDisconnect",
239 	    SMB_SDT_OPS(close_and_tree_disconnect),		/* 0x31 049 */
240 	    0x31, LANMAN1_0 },
241 	{ "SmbTransaction2", SMB_SDT_OPS(transaction2),		/* 0x32 050 */
242 	    0x32, LM1_2X002 },
243 	{ "SmbTransaction2Secondary",
244 	    SMB_SDT_OPS(transaction2_secondary),		/* 0x33 051 */
245 	    0x33, LM1_2X002 },
246 	{ "SmbFindClose2", SMB_SDT_OPS(find_close2),		/* 0x34 052 */
247 	    0x34, LM1_2X002 },
248 	{ "Invalid", SMB_SDT_OPS(invalid), 0x35, 0 },	/* 0x35 053 */
249 	{ "Invalid", SMB_SDT_OPS(invalid), 0x36, 0 },	/* 0x36 054 */
250 	{ "Invalid", SMB_SDT_OPS(invalid), 0x37, 0 },	/* 0x37 055 */
251 	{ "Invalid", SMB_SDT_OPS(invalid), 0x38, 0 },	/* 0x38 056 */
252 	{ "Invalid", SMB_SDT_OPS(invalid), 0x39, 0 },	/* 0x39 057 */
253 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3A, 0 },	/* 0x3A 058 */
254 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3B, 0 },	/* 0x3B 059 */
255 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3C, 0 },	/* 0x3C 060 */
256 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3D, 0 },	/* 0x3D 061 */
257 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3E, 0 },	/* 0x3E 062 */
258 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3F, 0 },	/* 0x3F 063 */
259 	{ "Invalid", SMB_SDT_OPS(invalid), 0x40, 0 },	/* 0x40 064 */
260 	{ "Invalid", SMB_SDT_OPS(invalid), 0x47, 0 },	/* 0x47 065 */
261 	{ "Invalid", SMB_SDT_OPS(invalid), 0x48, 0 },	/* 0x48 066 */
262 	{ "Invalid", SMB_SDT_OPS(invalid), 0x49, 0 },	/* 0x49 067 */
263 	{ "Invalid", SMB_SDT_OPS(invalid), 0x44, 0 },	/* 0x44 068 */
264 	{ "Invalid", SMB_SDT_OPS(invalid), 0x45, 0 },	/* 0x45 069 */
265 	{ "Invalid", SMB_SDT_OPS(invalid), 0x46, 0 },	/* 0x46 070 */
266 	{ "Invalid", SMB_SDT_OPS(invalid), 0x47, 0 },	/* 0x47 071 */
267 	{ "Invalid", SMB_SDT_OPS(invalid), 0x48, 0 },	/* 0x48 072 */
268 	{ "Invalid", SMB_SDT_OPS(invalid), 0x49, 0 },	/* 0x49 073 */
269 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4A, 0 },	/* 0x4A 074 */
270 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4B, 0 },	/* 0x4B 075 */
271 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4C, 0 },	/* 0x4C 076 */
272 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4D, 0 },	/* 0x4D 077 */
273 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4E, 0 },	/* 0x4E 078 */
274 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4F, 0 },	/* 0x4F 079 */
275 	{ "Invalid", SMB_SDT_OPS(invalid), 0x50, 0 },	/* 0x50 080 */
276 	{ "Invalid", SMB_SDT_OPS(invalid), 0x51, 0 },	/* 0x51 081 */
277 	{ "Invalid", SMB_SDT_OPS(invalid), 0x52, 0 },	/* 0x52 082 */
278 	{ "Invalid", SMB_SDT_OPS(invalid), 0x53, 0 },	/* 0x53 083 */
279 	{ "Invalid", SMB_SDT_OPS(invalid), 0x54, 0 },	/* 0x54 084 */
280 	{ "Invalid", SMB_SDT_OPS(invalid), 0x55, 0 },	/* 0x55 085 */
281 	{ "Invalid", SMB_SDT_OPS(invalid), 0x56, 0 },	/* 0x56 086 */
282 	{ "Invalid", SMB_SDT_OPS(invalid), 0x57, 0 },	/* 0x57 087 */
283 	{ "Invalid", SMB_SDT_OPS(invalid), 0x58, 0 },	/* 0x58 088 */
284 	{ "Invalid", SMB_SDT_OPS(invalid), 0x59, 0 },	/* 0x59 089 */
285 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5A, 0 },	/* 0x5A 090 */
286 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5B, 0 },	/* 0x5B 091 */
287 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5C, 0 },	/* 0x5C 092 */
288 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5D, 0 },	/* 0x5D 093 */
289 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5E, 0 },	/* 0x5E 094 */
290 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5F, 0 },	/* 0x5F 095 */
291 	{ "Invalid", SMB_SDT_OPS(invalid), 0x60, 0 },	/* 0x60 096 */
292 	{ "Invalid", SMB_SDT_OPS(invalid), 0x61, 0 },	/* 0x61 097 */
293 	{ "Invalid", SMB_SDT_OPS(invalid), 0x62, 0 },	/* 0x62 098 */
294 	{ "Invalid", SMB_SDT_OPS(invalid), 0x63, 0 },	/* 0x63 099 */
295 	{ "Invalid", SMB_SDT_OPS(invalid), 0x64, 0 },	/* 0x64 100 */
296 	{ "Invalid", SMB_SDT_OPS(invalid), 0x65, 0 },	/* 0x65 101 */
297 	{ "Invalid", SMB_SDT_OPS(invalid), 0x66, 0 },	/* 0x66 102 */
298 	{ "Invalid", SMB_SDT_OPS(invalid), 0x67, 0 },	/* 0x67 103 */
299 	{ "Invalid", SMB_SDT_OPS(invalid), 0x68, 0 },	/* 0x68 104 */
300 	{ "Invalid", SMB_SDT_OPS(invalid), 0x69, 0 },	/* 0x69 105 */
301 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6A, 0 },	/* 0x6A 106 */
302 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6B, 0 },	/* 0x6B 107 */
303 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6C, 0 },	/* 0x6C 108 */
304 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6D, 0 },	/* 0x6D 109 */
305 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6E, 0 },	/* 0x6E 110 */
306 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6F, 0 },	/* 0x6F 111 */
307 	{ "SmbTreeConnect", SMB_SDT_OPS(tree_connect),		/* 0x70 112 */
308 	    0x70, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID },
309 	{ "SmbTreeDisconnect", SMB_SDT_OPS(tree_disconnect),	/* 0x71 113 */
310 	    0x71, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
311 	    NULL },
312 	{ "SmbNegotiate", SMB_SDT_OPS(negotiate),		/* 0x72 114 */
313 	    0x72, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
314 	    NULL },
315 	{ "SmbSessionSetupX", SMB_SDT_OPS(session_setup_andx),	/* 0x73 115 */
316 	    0x73, LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID },
317 	{ "SmbLogoffX", SMB_SDT_OPS(logoff_andx),		/* 0x74 116 */
318 	    0x74, LM1_2X002, SDDF_SUPPRESS_TID },
319 	{ "SmbTreeConnectX", SMB_SDT_OPS(tree_connect_andx),	/* 0x75 117 */
320 	    0x75, LANMAN1_0, SDDF_SUPPRESS_TID },
321 	{ "Invalid", SMB_SDT_OPS(invalid), 0x76, 0, 0 },	/* 0x76 118 */
322 	{ "Invalid", SMB_SDT_OPS(invalid), 0x77, 0, 0 },	/* 0x77 119 */
323 	{ "Invalid", SMB_SDT_OPS(invalid), 0x78, 0, 0 },	/* 0x78 120 */
324 	{ "Invalid", SMB_SDT_OPS(invalid), 0x79, 0, 0 },	/* 0x79 121 */
325 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7A, 0, 0 },	/* 0x7A 122 */
326 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7B, 0, 0 },	/* 0x7B 123 */
327 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7C, 0, 0 },	/* 0x7C 124 */
328 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7D, 0, 0 },	/* 0x7D 125 */
329 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7E, 0, 0 },	/* 0x7E 126 */
330 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7F, 0, 0 },	/* 0x7F 127 */
331 	{ "SmbQueryInformationDisk",
332 	    SMB_SDT_OPS(query_information_disk),		/* 0x80 128 */
333 	    0x80, PC_NETWORK_PROGRAM_1_0, 0 },
334 	{ "SmbSearch", SMB_SDT_OPS(search),			/* 0x81 129 */
335 	    0x81, PC_NETWORK_PROGRAM_1_0, 0 },
336 	{ "SmbFind", SMB_SDT_OPS(find),				/* 0x82 130 */
337 	    0x82, LANMAN1_0, 0 },
338 	{ "SmbFindUnique", SMB_SDT_OPS(find_unique),		/* 0x83 131 */
339 	    0x83, LANMAN1_0, 0 },
340 	{ "SmbFindClose", SMB_SDT_OPS(find_close),		/* 0x84 132 */
341 	    0x84, LANMAN1_0, 0 },
342 	{ "Invalid", SMB_SDT_OPS(invalid), 0x85, 0, 0 },	/* 0x85 133 */
343 	{ "Invalid", SMB_SDT_OPS(invalid), 0x86, 0, 0 },	/* 0x86 134 */
344 	{ "Invalid", SMB_SDT_OPS(invalid), 0x87, 0, 0 },	/* 0x87 135 */
345 	{ "Invalid", SMB_SDT_OPS(invalid), 0x88, 0, 0 },	/* 0x88 136 */
346 	{ "Invalid", SMB_SDT_OPS(invalid), 0x89, 0, 0 },	/* 0x89 137 */
347 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8A, 0, 0 },	/* 0x8A 138 */
348 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8B, 0, 0 },	/* 0x8B 139 */
349 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8C, 0, 0 },	/* 0x8C 140 */
350 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8D, 0, 0 },	/* 0x8D 141 */
351 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8E, 0, 0 },	/* 0x8E 142 */
352 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8F, 0, 0 },	/* 0x8F 143 */
353 	{ "Invalid", SMB_SDT_OPS(invalid), 0x90, 0, 0 },	/* 0x90 144 */
354 	{ "Invalid", SMB_SDT_OPS(invalid), 0x91, 0, 0 },	/* 0x91 145 */
355 	{ "Invalid", SMB_SDT_OPS(invalid), 0x92, 0, 0 },	/* 0x92 146 */
356 	{ "Invalid", SMB_SDT_OPS(invalid), 0x93, 0, 0 },	/* 0x93 147 */
357 	{ "Invalid", SMB_SDT_OPS(invalid), 0x94, 0, 0 },	/* 0x94 148 */
358 	{ "Invalid", SMB_SDT_OPS(invalid), 0x95, 0, 0 },	/* 0x95 149 */
359 	{ "Invalid", SMB_SDT_OPS(invalid), 0x96, 0, 0 },	/* 0x96 150 */
360 	{ "Invalid", SMB_SDT_OPS(invalid), 0x97, 0, 0 },	/* 0x97 151 */
361 	{ "Invalid", SMB_SDT_OPS(invalid), 0x98, 0, 0 },	/* 0x98 152 */
362 	{ "Invalid", SMB_SDT_OPS(invalid), 0x99, 0, 0 },	/* 0x99 153 */
363 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9A, 0, 0 },	/* 0x9A 154 */
364 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9B, 0, 0 },	/* 0x9B 155 */
365 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9C, 0, 0 },	/* 0x9C 156 */
366 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9D, 0, 0 },	/* 0x9D 157 */
367 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9E, 0, 0 },	/* 0x9E 158 */
368 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9F, 0, 0 },	/* 0x9F 159 */
369 	{ "SmbNtTransact", SMB_SDT_OPS(nt_transact),	/* 0xA0 160 */
370 	    0xA0, NT_LM_0_12, 0 },
371 	{ "SmbNtTransactSecondary",
372 	    SMB_SDT_OPS(nt_transact_secondary),			/* 0xA1 161 */
373 	    0xA1, NT_LM_0_12, 0 },
374 	{ "SmbNtCreateX", SMB_SDT_OPS(nt_create_andx),		/* 0xA2 162 */
375 	    0xA2, NT_LM_0_12, 0 },
376 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA3, 0, 0 },	/* 0xA3 163 */
377 	{ "SmbNtCancel", SMB_SDT_OPS(nt_cancel),		/* 0xA4 164 */
378 	    0xA4, NT_LM_0_12, 0 },
379 	{ "SmbNtRename", SMB_SDT_OPS(nt_rename),		/* 0xA5 165 */
380 	    0xA5, NT_LM_0_12, 0 },
381 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA6, 0, 0 },	/* 0xA6 166 */
382 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA7, 0, 0 },	/* 0xA7 167 */
383 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA8, 0, 0 },	/* 0xA8 168 */
384 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA9, 0, 0 },	/* 0xA9 169 */
385 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAA, 0, 0 },	/* 0xAA 170 */
386 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAB, 0, 0 },	/* 0xAB 171 */
387 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAC, 0, 0 },	/* 0xAC 172 */
388 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAD, 0, 0 },	/* 0xAD 173 */
389 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAE, 0, 0 },	/* 0xAE 174 */
390 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAF, 0, 0 },	/* 0xAF 175 */
391 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB0, 0, 0 },	/* 0xB0 176 */
392 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB1, 0, 0 },	/* 0xB1 177 */
393 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB2, 0, 0 },	/* 0xB2 178 */
394 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB3, 0, 0 },	/* 0xB3 179 */
395 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB4, 0, 0 },	/* 0xB4 180 */
396 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB5, 0, 0 },	/* 0xB5 181 */
397 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB6, 0, 0 },	/* 0xB6 182 */
398 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB7, 0, 0 },	/* 0xB7 183 */
399 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB8, 0, 0 },	/* 0xB8 184 */
400 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB9, 0, 0 },	/* 0xB9 185 */
401 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBA, 0, 0 },	/* 0xBA 186 */
402 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBB, 0, 0 },	/* 0xBB 187 */
403 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBC, 0, 0 },	/* 0xBC 188 */
404 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBD, 0, 0 },	/* 0xBD 189 */
405 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBE, 0, 0 },	/* 0xBE 190 */
406 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBF, 0, 0 },	/* 0xBF 191 */
407 	{ "SmbOpenPrintFile", SMB_SDT_OPS(open_print_file),	/* 0xC0 192 */
408 	    0xC0, PC_NETWORK_PROGRAM_1_0, 0 },
409 	{ "SmbWritePrintFile", SMB_SDT_OPS(write_print_file),	/* 0xC1 193 */
410 	    0xC1, PC_NETWORK_PROGRAM_1_0, 0 },
411 	{ "SmbClosePrintFile", SMB_SDT_OPS(close_print_file),	/* 0xC2 194 */
412 	    0xC2, PC_NETWORK_PROGRAM_1_0, 0 },
413 	{ "SmbGetPrintQueue", SMB_SDT_OPS(get_print_queue),	/* 0xC3 195 */
414 	    0xC3, PC_NETWORK_PROGRAM_1_0, 0 },
415 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC4, 0, 0 },	/* 0xC4 196 */
416 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC5, 0, 0 },	/* 0xC5 197 */
417 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC6, 0, 0 },	/* 0xC6 198 */
418 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC7, 0, 0 },	/* 0xC7 199 */
419 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC8, 0, 0 },	/* 0xC8 200 */
420 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC9, 0, 0 },	/* 0xC9 201 */
421 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCA, 0, 0 },	/* 0xCA 202 */
422 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCB, 0, 0 },	/* 0xCB 203 */
423 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCC, 0, 0 },	/* 0xCC 204 */
424 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCD, 0, 0 },	/* 0xCD 205 */
425 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCE, 0, 0 },	/* 0xCE 206 */
426 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCF, 0, 0 },	/* 0xCF 207 */
427 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD0, 0, 0 },	/* 0xD0 208 */
428 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD1, 0, 0 },	/* 0xD1 209 */
429 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD2, 0, 0 },	/* 0xD2 210 */
430 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD3, 0, 0 },	/* 0xD3 211 */
431 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD4, 0, 0 },	/* 0xD4 212 */
432 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD5, 0, 0 },	/* 0xD5 213 */
433 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD6, 0, 0 },	/* 0xD6 214 */
434 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD7, 0, 0 },	/* 0xD7 215 */
435 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD8, 0, 0 },	/* 0xD8 216 */
436 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD9, 0, 0 },	/* 0xD9 217 */
437 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDA, 0, 0 },	/* 0xDA 218 */
438 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDB, 0, 0 },	/* 0xDB 219 */
439 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDC, 0, 0 },	/* 0xDC 220 */
440 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDD, 0, 0 },	/* 0xDD 221 */
441 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDE, 0, 0 },	/* 0xDE 222 */
442 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDF, 0, 0 },	/* 0xDF 223 */
443 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE0, 0, 0 },	/* 0xE0 224 */
444 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE1, 0, 0 },	/* 0xE1 225 */
445 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE2, 0, 0 },	/* 0xE2 226 */
446 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE3, 0, 0 },	/* 0xE3 227 */
447 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE4, 0, 0 },	/* 0xE4 228 */
448 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE5, 0, 0 },	/* 0xE5 229 */
449 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE6, 0, 0 },	/* 0xE6 230 */
450 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE7, 0, 0 },	/* 0xE7 231 */
451 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE8, 0, 0 },	/* 0xE8 232 */
452 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE9, 0, 0 },	/* 0xE9 233 */
453 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEA, 0, 0 },	/* 0xEA 234 */
454 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEB, 0, 0 },	/* 0xEB 235 */
455 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEC, 0, 0 },	/* 0xEC 236 */
456 	{ "Invalid", SMB_SDT_OPS(invalid), 0xED, 0, 0 },	/* 0xED 237 */
457 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEE, 0, 0 },	/* 0xEE 238 */
458 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEF, 0, 0 },	/* 0xEF 239 */
459 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF0, 0, 0 },	/* 0xF0 240 */
460 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF1, 0, 0 },	/* 0xF1 241 */
461 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF2, 0, 0 },	/* 0xF2 242 */
462 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF3, 0, 0 },	/* 0xF3 243 */
463 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF4, 0, 0 },	/* 0xF4 244 */
464 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF5, 0, 0 },	/* 0xF5 245 */
465 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF6, 0, 0 },	/* 0xF6 246 */
466 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF7, 0, 0 },	/* 0xF7 247 */
467 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF8, 0, 0 },	/* 0xF8 248 */
468 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF9, 0, 0 },	/* 0xF9 249 */
469 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFA, 0, 0 },	/* 0xFA 250 */
470 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFB, 0, 0 },	/* 0xFB 251 */
471 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFC, 0, 0 },	/* 0xFC 252 */
472 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFD, 0, 0 },	/* 0xFD 253 */
473 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFE, 0, 0 },	/* 0xFE 254 */
474 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFF, 0, 0 }	/* 0xFF	255 */
475 };
476 
477 /*
478  * smbsr_cleanup
479  *
480  * If any user/tree/file is used by given request then
481  * the reference count for that resource has been incremented.
482  * This function decrements the reference count and close
483  * the resource if it's needed.
484  */
485 
486 void
487 smbsr_cleanup(smb_request_t *sr)
488 {
489 	ASSERT((sr->sr_state != SMB_REQ_STATE_CLEANED_UP) &&
490 	    (sr->sr_state != SMB_REQ_STATE_COMPLETED));
491 
492 	if (sr->r_xa) {
493 		if (sr->r_xa->xa_flags & SMB_XA_FLAG_COMPLETE)
494 			smb_xa_close(sr->r_xa);
495 		smb_xa_rele(sr->session, sr->r_xa);
496 		sr->r_xa = NULL;
497 	}
498 
499 	/*
500 	 * Mark this request so we know that we've already cleaned it up.
501 	 * A request should only get cleaned up once so multiple calls to
502 	 * smbsr_cleanup for the same request indicate a bug.
503 	 */
504 	mutex_enter(&sr->sr_mutex);
505 	if (sr->sr_state != SMB_REQ_STATE_CANCELED)
506 		sr->sr_state = SMB_REQ_STATE_CLEANED_UP;
507 	mutex_exit(&sr->sr_mutex);
508 }
509 /*
510  * smb_dispatch_request
511  *
512  * Returns:
513  *
514  *    B_TRUE	The caller must free the smb request passed in.
515  *    B_FALSE	The caller must not access the smb request passed in. It has
516  *		been kept in an internal queue and may have already been freed.
517  */
518 boolean_t
519 smb_dispatch_request(struct smb_request *sr)
520 {
521 	smb_sdrc_t		sdrc;
522 	smb_disp_entry_t	*sdd;
523 	boolean_t		disconnect = B_FALSE;
524 	smb_session_t		*session;
525 	uint32_t		capabilities;
526 	uint32_t		byte_count;
527 	uint32_t		max_bytes;
528 
529 	session = sr->session;
530 	capabilities = session->capabilities;
531 
532 	ASSERT(sr->tid_tree == 0);
533 	ASSERT(sr->uid_user == 0);
534 	ASSERT(sr->fid_ofile == 0);
535 	sr->smb_fid = (uint16_t)-1;
536 
537 	/* temporary until we identify a user */
538 	sr->user_cr = kcred;
539 	sr->orig_request_hdr = sr->command.chain_offset;
540 
541 	/* If this connection is shutting down just kill request */
542 	if (smb_mbc_decodef(&sr->command, SMB_HEADER_ED_FMT,
543 	    &sr->smb_com,
544 	    &sr->smb_rcls,
545 	    &sr->smb_reh,
546 	    &sr->smb_err,
547 	    &sr->smb_flg,
548 	    &sr->smb_flg2,
549 	    &sr->smb_pid_high,
550 	    sr->smb_sig,
551 	    &sr->smb_tid,
552 	    &sr->smb_pid,
553 	    &sr->smb_uid,
554 	    &sr->smb_mid) != 0) {
555 		disconnect = B_TRUE;
556 		goto drop_connection;
557 	}
558 
559 	/*
560 	 * The reply "header" is filled in now even though it will,
561 	 * most likely, be rewritten under reply_ready below.  We
562 	 * could reserve the space but this is convenient in case
563 	 * the dialect dispatcher has to send a special reply (like
564 	 * TRANSACT).
565 	 *
566 	 * Ensure that the 32-bit error code flag is turned off.
567 	 * Clients seem to set it in transact requests and they may
568 	 * get confused if we return success or a 16-bit SMB code.
569 	 */
570 	sr->smb_rcls = 0;
571 	sr->smb_reh = 0;
572 	sr->smb_err = 0;
573 	sr->smb_flg2 &= ~SMB_FLAGS2_NT_STATUS;
574 
575 	(void) smb_mbc_encodef(&sr->reply, SMB_HEADER_ED_FMT,
576 	    sr->smb_com,
577 	    sr->smb_rcls,
578 	    sr->smb_reh,
579 	    sr->smb_err,
580 	    sr->smb_flg,
581 	    sr->smb_flg2,
582 	    sr->smb_pid_high,
583 	    sr->smb_sig,
584 	    sr->smb_tid,
585 	    sr->smb_pid,
586 	    sr->smb_uid,
587 	    sr->smb_mid);
588 	sr->first_smb_com = sr->smb_com;
589 
590 	/*
591 	 * Verify SMB signature if signing is enabled, dialect is NT LM 0.12,
592 	 * signing was negotiated and authentication has occurred.
593 	 */
594 	if (session->signing.flags & SMB_SIGNING_ENABLED) {
595 		if (smb_sign_check_request(sr) != 0) {
596 			smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
597 			    ERRDOS, ERROR_ACCESS_DENIED);
598 			disconnect = B_TRUE;
599 			goto report_error;
600 		}
601 	}
602 
603 andx_more:
604 	sdd = &smb_disp_table[sr->smb_com];
605 	ASSERT(sdd->sdt_function);
606 
607 	if (smb_mbc_decodef(&sr->command, "b", &sr->smb_wct) != 0) {
608 		disconnect = B_TRUE;
609 		goto report_error;
610 	}
611 
612 	(void) MBC_SHADOW_CHAIN(&sr->smb_vwv, &sr->command,
613 	    sr->command.chain_offset, sr->smb_wct * 2);
614 
615 	if (smb_mbc_decodef(&sr->command, "#.w", sr->smb_wct*2, &sr->smb_bcc)) {
616 		disconnect = B_TRUE;
617 		goto report_error;
618 	}
619 
620 	atomic_add_64(&sdd->sdt_rxb,
621 	    (int64_t)(sr->smb_wct * 2 + sr->smb_bcc + 1));
622 	sr->sr_txb = sr->reply.chain_offset;
623 
624 	/*
625 	 * Ignore smb_bcc if CAP_LARGE_READX/CAP_LARGE_WRITEX
626 	 * and this is SmbReadX/SmbWriteX since this enables
627 	 * large reads/write and bcc is only 16-bits.
628 	 */
629 	max_bytes = sr->command.max_bytes - sr->command.chain_offset;
630 	if (((sr->smb_com == SMB_COM_READ_ANDX) &&
631 	    (capabilities & CAP_LARGE_READX)) ||
632 	    ((sr->smb_com == SMB_COM_WRITE_ANDX) &&
633 	    (capabilities & CAP_LARGE_WRITEX))) {
634 		/* May be > BCC */
635 		byte_count = max_bytes;
636 	} else if (max_bytes < (uint32_t)sr->smb_bcc) {
637 		/* BCC is bogus.  Will fail later. */
638 		byte_count = max_bytes;
639 	} else {
640 		/* ordinary case */
641 		byte_count = (uint32_t)sr->smb_bcc;
642 	}
643 
644 	(void) MBC_SHADOW_CHAIN(&sr->smb_data, &sr->command,
645 	    sr->command.chain_offset, byte_count);
646 
647 	sr->command.chain_offset += byte_count;
648 	if (sr->command.chain_offset > sr->command.max_bytes) {
649 		disconnect = B_TRUE;
650 		goto report_error;
651 	}
652 
653 	/* Store pointers for later */
654 	sr->cur_reply_offset = sr->reply.chain_offset;
655 
656 	if (is_andx_com(sr->smb_com)) {
657 		/* Peek ahead and don't disturb vwv */
658 		if (smb_mbc_peek(&sr->smb_vwv, sr->smb_vwv.chain_offset, "b.w",
659 		    &sr->andx_com, &sr->andx_off) < 0) {
660 			disconnect = B_TRUE;
661 			goto report_error;
662 		}
663 	} else {
664 		sr->andx_com = (unsigned char)-1;
665 	}
666 
667 	mutex_enter(&sr->sr_mutex);
668 	switch (sr->sr_state) {
669 	case SMB_REQ_STATE_SUBMITTED:
670 	case SMB_REQ_STATE_CLEANED_UP:
671 		sr->sr_state = SMB_REQ_STATE_ACTIVE;
672 		break;
673 	case SMB_REQ_STATE_CANCELED:
674 		break;
675 	default:
676 		ASSERT(0);
677 		break;
678 	}
679 	mutex_exit(&sr->sr_mutex);
680 
681 	/*
682 	 * Setup UID and TID information (if required). Both functions
683 	 * will set the sr credentials. In domain mode, the user and
684 	 * tree credentials should be the same. In share mode, the
685 	 * tree credentials (defined in the share definition) should
686 	 * override the user credentials.
687 	 */
688 	if (!(sdd->sdt_flags & SDDF_SUPPRESS_UID) && (sr->uid_user == NULL)) {
689 		sr->uid_user = smb_session_lookup_uid(session, sr->smb_uid);
690 		if (sr->uid_user == NULL) {
691 			smbsr_error(sr, 0, ERRSRV, ERRbaduid);
692 			smbsr_cleanup(sr);
693 			goto report_error;
694 		}
695 
696 		sr->user_cr = smb_user_getcred(sr->uid_user);
697 
698 		if (!(sdd->sdt_flags & SDDF_SUPPRESS_TID) &&
699 		    (sr->tid_tree == NULL)) {
700 			sr->tid_tree = smb_user_lookup_tree(
701 			    sr->uid_user, sr->smb_tid);
702 			if (sr->tid_tree == NULL) {
703 				smbsr_error(sr, 0, ERRSRV, ERRinvnid);
704 				smbsr_cleanup(sr);
705 				goto report_error;
706 			}
707 		}
708 	}
709 
710 	/*
711 	 * If the command is not a read raw request we can set the
712 	 * state of the session back to SMB_SESSION_STATE_NEGOTIATED
713 	 * (if the current state is SMB_SESSION_STATE_OPLOCK_BREAKING).
714 	 * Otherwise we let the read raw handler to deal with it.
715 	 */
716 	smb_rwx_rwenter(&session->s_lock, RW_READER);
717 	if ((session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING) &&
718 	    (sr->smb_com != SMB_COM_READ_RAW)) {
719 		(void) smb_rwx_rwupgrade(&session->s_lock);
720 		if (session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING)
721 			session->s_state = SMB_SESSION_STATE_NEGOTIATED;
722 	}
723 	smb_rwx_rwexit(&session->s_lock);
724 
725 	sr->sr_time_start = gethrtime();
726 	if ((sdrc = (*sdd->sdt_pre_op)(sr)) == SDRC_SUCCESS)
727 		sdrc = (*sdd->sdt_function)(sr);
728 
729 	if (sdrc != SDRC_SR_KEPT) {
730 		(*sdd->sdt_post_op)(sr);
731 		smbsr_cleanup(sr);
732 	}
733 	smb_latency_add_sample(&sdd->sdt_lat, gethrtime() - sr->sr_time_start);
734 
735 	atomic_add_64(&sdd->sdt_txb,
736 	    (int64_t)(sr->reply.chain_offset - sr->sr_txb));
737 
738 	if (sdrc != SDRC_SUCCESS) {
739 		/*
740 		 * Handle errors from raw write.
741 		 */
742 		smb_rwx_rwenter(&session->s_lock, RW_WRITER);
743 		if (session->s_state == SMB_SESSION_STATE_WRITE_RAW_ACTIVE) {
744 			/*
745 			 * Set state so that the netbios session
746 			 * daemon will start accepting data again.
747 			 */
748 			session->s_write_raw_status = 0;
749 			session->s_state = SMB_SESSION_STATE_NEGOTIATED;
750 		}
751 		smb_rwx_rwexit(&session->s_lock);
752 	}
753 
754 	switch (sdrc) {
755 	case SDRC_SUCCESS:
756 		break;
757 
758 	case SDRC_DROP_VC:
759 		disconnect = B_TRUE;
760 		goto drop_connection;
761 
762 	case SDRC_NO_REPLY:
763 		return (B_TRUE);
764 
765 	case SDRC_SR_KEPT:
766 		return (B_FALSE);
767 
768 	case SDRC_ERROR:
769 		goto report_error;
770 
771 	case SDRC_NOT_IMPLEMENTED:
772 	default:
773 		smbsr_error(sr, 0, ERRDOS, ERRbadfunc);
774 		goto report_error;
775 	}
776 
777 	/*
778 	 * If there's no AndX command, we're done.
779 	 */
780 	if (sr->andx_com == 0xff)
781 		goto reply_ready;
782 
783 	/*
784 	 * Otherwise, we have to back-patch the AndXCommand and AndXOffset
785 	 * and continue processing.
786 	 */
787 	sr->andx_prev_wct = sr->cur_reply_offset;
788 	(void) smb_mbc_poke(&sr->reply, sr->andx_prev_wct + 1, "b.w",
789 	    sr->andx_com, MBC_LENGTH(&sr->reply));
790 
791 	sr->command.chain_offset = sr->orig_request_hdr + sr->andx_off;
792 	sr->smb_com = sr->andx_com;
793 	goto andx_more;
794 
795 report_error:
796 	sr->reply.chain_offset = sr->cur_reply_offset;
797 	(void) smb_mbc_encodef(&sr->reply, "bw", 0, 0);
798 
799 	sr->smb_wct = 0;
800 	sr->smb_bcc = 0;
801 
802 	if (sr->smb_rcls == 0 && sr->smb_reh == 0 && sr->smb_err == 0)
803 		smbsr_error(sr, 0, ERRSRV, ERRerror);
804 
805 reply_ready:
806 	smbsr_send_reply(sr);
807 
808 drop_connection:
809 	if (disconnect) {
810 		smb_rwx_rwenter(&session->s_lock, RW_WRITER);
811 		switch (session->s_state) {
812 		case SMB_SESSION_STATE_DISCONNECTED:
813 		case SMB_SESSION_STATE_TERMINATED:
814 			break;
815 		default:
816 			smb_soshutdown(session->sock);
817 			session->s_state = SMB_SESSION_STATE_DISCONNECTED;
818 			break;
819 		}
820 		smb_rwx_rwexit(&session->s_lock);
821 	}
822 
823 	return (B_TRUE);
824 }
825 
826 int
827 smbsr_encode_empty_result(struct smb_request *sr)
828 {
829 	return (smbsr_encode_result(sr, 0, 0, "bw", 0, 0));
830 }
831 
832 int
833 smbsr_encode_result(struct smb_request *sr, int wct, int bcc, char *fmt, ...)
834 {
835 	va_list ap;
836 
837 	if (MBC_LENGTH(&sr->reply) != sr->cur_reply_offset)
838 		return (-1);
839 
840 	va_start(ap, fmt);
841 	(void) smb_mbc_vencodef(&sr->reply, fmt, ap);
842 	va_end(ap);
843 
844 	sr->smb_wct = (unsigned char)wct;
845 	sr->smb_bcc = (uint16_t)bcc;
846 
847 	if (smbsr_check_result(sr, wct, bcc) != 0)
848 		return (-1);
849 
850 	return (0);
851 }
852 
853 static int
854 smbsr_check_result(struct smb_request *sr, int wct, int bcc)
855 {
856 	int		offset = sr->cur_reply_offset;
857 	int		total_bytes;
858 	unsigned char	temp, temp1;
859 	struct mbuf	*m;
860 
861 	total_bytes = 0;
862 	m = sr->reply.chain;
863 	while (m != 0) {
864 		total_bytes += m->m_len;
865 		m = m->m_next;
866 	}
867 
868 	if ((offset + 3) > total_bytes)
869 		return (-1);
870 
871 	(void) smb_mbc_peek(&sr->reply, offset, "b", &temp);
872 	if (temp != wct)
873 		return (-1);
874 
875 	if ((offset + (wct * 2 + 1)) > total_bytes)
876 		return (-1);
877 
878 	/* reply wct & vwv seem ok, consider data now */
879 	offset += wct * 2 + 1;
880 
881 	if ((offset + 2) > total_bytes)
882 		return (-1);
883 
884 	(void) smb_mbc_peek(&sr->reply, offset, "bb", &temp, &temp1);
885 	if (bcc == VAR_BCC) {
886 		if ((temp != 0xFF) || (temp1 != 0xFF)) {
887 			return (-1);
888 		} else {
889 			bcc = (total_bytes - offset) - 2;
890 			(void) smb_mbc_poke(&sr->reply, offset, "bb",
891 			    bcc, bcc >> 8);
892 		}
893 	} else {
894 		if ((temp != (bcc&0xFF)) || (temp1 != ((bcc>>8)&0xFF)))
895 			return (-1);
896 	}
897 
898 	offset += bcc + 2;
899 
900 	if (offset != total_bytes)
901 		return (-1);
902 
903 	sr->smb_wct = (unsigned char)wct;
904 	sr->smb_bcc = (uint16_t)bcc;
905 	return (0);
906 }
907 
908 int
909 smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...)
910 {
911 	int rc;
912 	va_list ap;
913 
914 	va_start(ap, fmt);
915 	rc = smb_mbc_vdecodef(&sr->smb_vwv, fmt, ap);
916 	va_end(ap);
917 
918 	if (rc)
919 		smbsr_error(sr, 0, ERRSRV, ERRerror);
920 	return (rc);
921 }
922 
923 int
924 smbsr_decode_data(struct smb_request *sr, char *fmt, ...)
925 {
926 	int rc;
927 	va_list ap;
928 
929 	va_start(ap, fmt);
930 	rc = smb_mbc_vdecodef(&sr->smb_data, fmt, ap);
931 	va_end(ap);
932 
933 	if (rc)
934 		smbsr_error(sr, 0, ERRSRV, ERRerror);
935 	return (rc);
936 }
937 
938 boolean_t
939 smbsr_decode_data_avail(smb_request_t *sr)
940 {
941 	return (sr->smb_data.chain_offset < sr->smb_data.max_bytes);
942 }
943 
944 void
945 smbsr_send_reply(smb_request_t *sr)
946 {
947 	if (SMB_TREE_IS_CASEINSENSITIVE(sr))
948 		sr->smb_flg |= SMB_FLAGS_CASE_INSENSITIVE;
949 	else
950 		sr->smb_flg &= ~SMB_FLAGS_CASE_INSENSITIVE;
951 
952 	(void) smb_mbc_poke(&sr->reply, 0, SMB_HEADER_ED_FMT,
953 	    sr->first_smb_com,
954 	    sr->smb_rcls,
955 	    sr->smb_reh,
956 	    sr->smb_err,
957 	    sr->smb_flg | SMB_FLAGS_REPLY,
958 	    sr->smb_flg2,
959 	    sr->smb_pid_high,
960 	    sr->smb_sig,
961 	    sr->smb_tid,
962 	    sr->smb_pid,
963 	    sr->smb_uid,
964 	    sr->smb_mid);
965 
966 	if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
967 		smb_sign_reply(sr, NULL);
968 
969 	smb_server_inc_req(sr->session->s_server);
970 	if (smb_session_send(sr->session, 0, &sr->reply) == 0)
971 		sr->reply.chain = 0;
972 }
973 
974 /*
975  * Map errno values to SMB and NT status values.
976  * Note: ESRCH is a special case to handle a streams lookup failure.
977  */
978 static struct {
979 	int errnum;
980 	int errcls;
981 	int errcode;
982 	DWORD status32;
983 } smb_errno_map[] = {
984 	{ ENOSPC,	ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL },
985 	{ EDQUOT,	ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL },
986 	{ EPERM,	ERRSRV, ERRaccess, NT_STATUS_ACCESS_DENIED },
987 	{ ENOTDIR,	ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND },
988 	{ EISDIR,	ERRDOS, ERRbadpath, NT_STATUS_FILE_IS_A_DIRECTORY },
989 	{ ENOENT,	ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE },
990 	{ ENOTEMPTY,	ERRDOS, ERROR_DIR_NOT_EMPTY,
991 	    NT_STATUS_DIRECTORY_NOT_EMPTY },
992 	{ EILSEQ,	ERRDOS, ERROR_INVALID_NAME,
993 	    NT_STATUS_OBJECT_NAME_INVALID },
994 	{ EACCES,	ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
995 	{ ENOMEM,	ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY },
996 	{ EIO,		ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR },
997 	{ EXDEV, 	ERRSRV, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE },
998 	{ EREMOTE, 	ERRSRV, ERRbadpath, NT_STATUS_PATH_NOT_COVERED},
999 	{ EROFS,	ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED },
1000 	{ ESTALE,	ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE },
1001 	{ EBADF,	ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE },
1002 	{ EEXIST,	ERRDOS, ERRfilexists, NT_STATUS_OBJECT_NAME_COLLISION },
1003 	{ ENXIO,	ERRSRV, ERRinvdevice, NT_STATUS_BAD_DEVICE_TYPE },
1004 	{ ESRCH,	ERRDOS, ERROR_FILE_NOT_FOUND,
1005 	    NT_STATUS_OBJECT_NAME_NOT_FOUND },
1006 	/*
1007 	 * It's not clear why smb_read_common effectively returns
1008 	 * ERRnoaccess if a range lock prevents access and smb_write_common
1009 	 * effectively returns ERRaccess.  This table entry is used by
1010 	 * smb_read_common and preserves the behavior that was there before.
1011 	 */
1012 	{ ERANGE,	ERRDOS, ERRnoaccess, NT_STATUS_FILE_LOCK_CONFLICT }
1013 };
1014 
1015 void
1016 smbsr_map_errno(int errnum, smb_error_t *err)
1017 {
1018 	int i;
1019 
1020 	for (i = 0; i < sizeof (smb_errno_map)/sizeof (smb_errno_map[0]); ++i) {
1021 		if (smb_errno_map[i].errnum == errnum) {
1022 			err->status   = smb_errno_map[i].status32;
1023 			err->errcls   = smb_errno_map[i].errcls;
1024 			err->errcode  = smb_errno_map[i].errcode;
1025 			return;
1026 		}
1027 	}
1028 
1029 	err->status   = NT_STATUS_INTERNAL_ERROR;
1030 	err->errcls   = ERRDOS;
1031 	err->errcode  = ERROR_INTERNAL_ERROR;
1032 }
1033 
1034 void
1035 smbsr_errno(struct smb_request *sr, int errnum)
1036 {
1037 	smbsr_map_errno(errnum, &sr->smb_error);
1038 	smbsr_set_error(sr, &sr->smb_error);
1039 }
1040 
1041 /*
1042  * Report a request processing status (error or warning).
1043  */
1044 void
1045 smbsr_status(smb_request_t *sr, DWORD status, uint16_t errcls, uint16_t errcode)
1046 {
1047 	sr->smb_error.status   = status;
1048 	sr->smb_error.errcls   = errcls;
1049 	sr->smb_error.errcode  = errcode;
1050 
1051 	smbsr_set_error(sr, &sr->smb_error);
1052 }
1053 
1054 /*
1055  * Setup a request processing error.  This function can be used to
1056  * report 32-bit status codes or DOS errors.  Set the status code
1057  * to 0 (NT_STATUS_SUCCESS) to explicitly report a DOS error,
1058  * regardless of the client capabilities.
1059  *
1060  * If status is non-zero and the client supports 32-bit status
1061  * codes, report the status.  Otherwise, report the DOS error.
1062  */
1063 void
1064 smbsr_set_error(smb_request_t *sr, smb_error_t *err)
1065 {
1066 	uint32_t status;
1067 	uint32_t capabilities;
1068 
1069 	ASSERT(sr);
1070 	ASSERT(err);
1071 
1072 	status = err->status;
1073 	capabilities = sr->session->capabilities;
1074 
1075 	if ((err->errcls == 0) && (err->errcode == 0)) {
1076 		capabilities |= CAP_STATUS32;
1077 		if (status == 0)
1078 			status = NT_STATUS_INTERNAL_ERROR;
1079 	}
1080 
1081 	if ((capabilities & CAP_STATUS32) && (status != 0)) {
1082 		sr->smb_rcls = status & 0xff;
1083 		sr->smb_reh = (status >> 8) & 0xff;
1084 		sr->smb_err  = status >> 16;
1085 		sr->smb_flg2 |= SMB_FLAGS2_NT_STATUS;
1086 	} else {
1087 		if ((err->errcls == 0) || (err->errcode == 0)) {
1088 			sr->smb_rcls = ERRSRV;
1089 			sr->smb_err  = ERRerror;
1090 		} else {
1091 			sr->smb_rcls = (uint8_t)err->errcls;
1092 			sr->smb_err  = (uint16_t)err->errcode;
1093 		}
1094 	}
1095 }
1096 
1097 smb_xa_t *
1098 smbsr_lookup_xa(smb_request_t *sr)
1099 {
1100 	ASSERT(sr->r_xa == 0);
1101 
1102 	sr->r_xa = smb_xa_find(sr->session, sr->smb_pid, sr->smb_mid);
1103 	return (sr->r_xa);
1104 }
1105 
1106 void
1107 smbsr_release_file(smb_request_t *sr)
1108 {
1109 	smb_ofile_t	*of = sr->fid_ofile;
1110 
1111 	sr->fid_ofile = NULL;
1112 	(void) smb_ofile_release(of);
1113 }
1114 
1115 void
1116 smbsr_lookup_file(smb_request_t *sr)
1117 {
1118 	if (sr->fid_ofile == NULL)
1119 		sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree,
1120 		    sr->smb_fid);
1121 }
1122 
1123 static int
1124 is_andx_com(unsigned char com)
1125 {
1126 	switch (com) {
1127 	case SMB_COM_LOCKING_ANDX:
1128 	case SMB_COM_OPEN_ANDX:
1129 	case SMB_COM_READ_ANDX:
1130 	case SMB_COM_WRITE_ANDX:
1131 	case SMB_COM_SESSION_SETUP_ANDX:
1132 	case SMB_COM_LOGOFF_ANDX:
1133 	case SMB_COM_TREE_CONNECT_ANDX:
1134 	case SMB_COM_NT_CREATE_ANDX:
1135 		return (1);
1136 	}
1137 	return (0);
1138 }
1139 
1140 /*
1141  * Invalid command stubs.
1142  *
1143  * SmbWriteComplete is sent to acknowledge completion of raw write requests.
1144  * We never send raw write commands to other servers so, if we receive
1145  * SmbWriteComplete, we treat it as an error.
1146  *
1147  * The Read/Write Block Multiplexed (mpx) protocol is used to maximize
1148  * performance when reading/writing a large block of data: it can be
1149  * used in parallel with other client/server operations.  The mpx sub-
1150  * protocol is not supported because we support only connection oriented
1151  * transports and NT supports mpx only over connectionless transports.
1152  */
1153 smb_sdrc_t
1154 smb_pre_invalid(smb_request_t *sr)
1155 {
1156 	DTRACE_SMB_1(op__Invalid__start, smb_request_t *, sr);
1157 	return (SDRC_SUCCESS);
1158 }
1159 
1160 void
1161 smb_post_invalid(smb_request_t *sr)
1162 {
1163 	DTRACE_SMB_1(op__Invalid__done, smb_request_t *, sr);
1164 }
1165 
1166 smb_sdrc_t
1167 smb_com_invalid(smb_request_t *sr)
1168 {
1169 	smb_sdrc_t sdrc;
1170 
1171 	switch (sr->smb_com) {
1172 	case SMB_COM_WRITE_COMPLETE:
1173 		smbsr_error(sr, 0, ERRSRV, ERRerror);
1174 		sdrc = SDRC_ERROR;
1175 		break;
1176 
1177 	default:
1178 		smbsr_error(sr, NT_STATUS_NOT_IMPLEMENTED,
1179 		    ERRDOS, ERROR_INVALID_FUNCTION);
1180 		sdrc = SDRC_NOT_IMPLEMENTED;
1181 		break;
1182 	}
1183 
1184 	return (sdrc);
1185 }
1186 
1187 /*
1188  * smb_dispatch_stats_init
1189  *
1190  * Initializes dispatch statistics.
1191  */
1192 void
1193 smb_dispatch_stats_init(smb_kstat_req_t *ksr)
1194 {
1195 	kstat_named_t	*ksn;
1196 	int		ks_ndata;
1197 	int		i;
1198 
1199 	for (i = 0; i < SMB_COM_NUM; i++, ksr++) {
1200 		smb_latency_init(&smb_disp_table[i].sdt_lat);
1201 		(void) strlcpy(ksr->kr_name, smb_disp_table[i].sdt_name,
1202 		    sizeof (ksr->kr_name));
1203 	}
1204 	/* Legacy Statistics */
1205 	for (i = 0, ks_ndata = 0; i < SMB_COM_NUM; i++) {
1206 		if (smb_disp_table[i].sdt_function != smb_com_invalid)
1207 			ks_ndata++;
1208 	}
1209 
1210 	smb_legacy_dispatch_ksp = kstat_create(SMBSRV_KSTAT_MODULE, 0,
1211 	    SMBSRV_KSTAT_NAME_CMDS, SMBSRV_KSTAT_CLASS,
1212 	    KSTAT_TYPE_NAMED, ks_ndata, 0);
1213 
1214 	if (smb_legacy_dispatch_ksp != NULL) {
1215 		ksn = smb_legacy_dispatch_ksp->ks_data;
1216 
1217 		for (i = 0, ks_ndata = 0; i < SMB_COM_NUM; i++) {
1218 			if (smb_disp_table[i].sdt_function != smb_com_invalid) {
1219 				(void) strlcpy(ksn->name,
1220 				    smb_disp_table[i].sdt_name,
1221 				    sizeof (ksn->name));
1222 				ksn->data_type = KSTAT_DATA_UINT64;
1223 				++ksn;
1224 			}
1225 		}
1226 		mutex_init(&smb_legacy_dispatch_ksmtx, NULL,
1227 		    MUTEX_DEFAULT, NULL);
1228 		smb_legacy_dispatch_ksp->ks_update =
1229 		    smb_legacy_dispatch_stats_update;
1230 		smb_legacy_dispatch_ksp->ks_lock = &smb_legacy_dispatch_ksmtx;
1231 		kstat_install(smb_legacy_dispatch_ksp);
1232 	}
1233 }
1234 
1235 /*
1236  * smb_dispatch_stats_fini
1237  *
1238  * Frees and destroyes the resources used for statistics.
1239  */
1240 void
1241 smb_dispatch_stats_fini(void)
1242 {
1243 	int	i;
1244 
1245 	if (smb_legacy_dispatch_ksp != NULL) {
1246 		kstat_delete(smb_legacy_dispatch_ksp);
1247 		mutex_destroy(&smb_legacy_dispatch_ksmtx);
1248 		smb_legacy_dispatch_ksp = NULL;
1249 	}
1250 
1251 	for (i = 0; i < SMB_COM_NUM; i++)
1252 		smb_latency_destroy(&smb_disp_table[i].sdt_lat);
1253 }
1254 
1255 void
1256 smb_dispatch_stats_update(smb_kstat_req_t *ksr, int first, int nreq)
1257 {
1258 	int	i;
1259 	int	last;
1260 
1261 	last = first + nreq - 1;
1262 
1263 	if ((first < SMB_COM_NUM) && (last < SMB_COM_NUM))  {
1264 		for (i = first; i <= last; i++, ksr++) {
1265 			ksr->kr_rxb = smb_disp_table[i].sdt_rxb;
1266 			ksr->kr_txb = smb_disp_table[i].sdt_txb;
1267 			mutex_enter(&smb_disp_table[i].sdt_lat.ly_mutex);
1268 			ksr->kr_nreq = smb_disp_table[i].sdt_lat.ly_a_nreq;
1269 			ksr->kr_sum = smb_disp_table[i].sdt_lat.ly_a_sum;
1270 			ksr->kr_a_mean = smb_disp_table[i].sdt_lat.ly_a_mean;
1271 			ksr->kr_a_stddev =
1272 			    smb_disp_table[i].sdt_lat.ly_a_stddev;
1273 			ksr->kr_d_mean = smb_disp_table[i].sdt_lat.ly_d_mean;
1274 			ksr->kr_d_stddev =
1275 			    smb_disp_table[i].sdt_lat.ly_d_stddev;
1276 			smb_disp_table[i].sdt_lat.ly_d_mean = 0;
1277 			smb_disp_table[i].sdt_lat.ly_d_nreq = 0;
1278 			smb_disp_table[i].sdt_lat.ly_d_stddev = 0;
1279 			smb_disp_table[i].sdt_lat.ly_d_sum = 0;
1280 			mutex_exit(&smb_disp_table[i].sdt_lat.ly_mutex);
1281 		}
1282 	}
1283 }
1284 
1285 /*
1286  * smb_legacy_dispatch_stats_update
1287  *
1288  * This callback function updates the smb_legacy_dispatch_kstat_data when kstat
1289  * command is invoked.
1290  */
1291 static int
1292 smb_legacy_dispatch_stats_update(kstat_t *ksp, int rw)
1293 {
1294 	kstat_named_t   *ksn;
1295 	int		i;
1296 
1297 	ASSERT(MUTEX_HELD(ksp->ks_lock));
1298 
1299 	switch (rw) {
1300 	case KSTAT_WRITE:
1301 		return (EACCES);
1302 
1303 	case KSTAT_READ:
1304 		ksn = ksp->ks_data;
1305 		for (i = 0; i < SMB_COM_NUM; i++) {
1306 			if (smb_disp_table[i].sdt_function != smb_com_invalid) {
1307 				ksn->value.ui64 =
1308 				    smb_disp_table[i].sdt_lat.ly_a_nreq;
1309 				++ksn;
1310 			}
1311 		}
1312 		return (0);
1313 
1314 	default:
1315 		return (EIO);
1316 	}
1317 }
1318