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