xref: /onnv-gate/usr/src/uts/common/fs/smbsrv/smb_dispatch.c (revision 12890:16985853e3aa)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
2112508Samw@Sun.COM 
225331Samw /*
2312508Samw@Sun.COM  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
245331Samw  */
255331Samw 
265331Samw /*
278934SJose.Borrego@Sun.COM  * SMB requests.
285331Samw  *
295331Samw  * Request
305331Samw  *   Header
315331Samw  *	Magic		0xFF 'S' 'M' 'B'
325331Samw  *	smb_com 	a byte, the "first" command
335331Samw  *	Error		a 4-byte union, ignored in a request
345331Samw  *	smb_flg		a one byte set of eight flags
355331Samw  *	smb_flg2	a two byte set of 16 flags
365331Samw  *	.		twelve reserved bytes, have a role
375331Samw  *			in connectionless transports (IPX, UDP?)
385331Samw  *	smb_tid		a 16-bit tree ID, a mount point sorta,
395331Samw  *			0xFFFF is this command does not have
405331Samw  *			or require a tree context
415331Samw  *	smb_pid		a 16-bit process ID
425331Samw  *	smb_uid		a 16-bit user ID, specific to this "session"
435331Samw  *			and mapped to a system (bona-fide) UID
445331Samw  *	smb_mid		a 16-bit multiplex ID, used to differentiate
455331Samw  *			multiple simultaneous requests from the same
465331Samw  *			process (pid) (ref RPC "xid")
475331Samw  *
485331Samw  *   Chained (AndX) commands (0 or more)
495331Samw  *	smb_wct		a byte, number of 16-bit words containing
505331Samw  *			command parameters, min 2 for chained command
515331Samw  *	andx_com	a byte, the "next" command, 0xFF for none
525331Samw  *	.		an unused byte
535331Samw  *	andx_off	a 16-bit offset, byte displacement from &Magic
545331Samw  *			to the smb_wct field of the "next" command,
555331Samw  *			ignore if andx_com is 0xFF, s/b 0 if no next
565331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
575331Samw  *			"this" command (i.e. smb_com if this is the
585331Samw  *			first parameters, or the andx_com of the just
595331Samw  *			previous block.
605331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
615331Samw  *	smb_data[]	0 or more bytes, format specific to commands
625331Samw  *	padding[]	Optional padding
635331Samw  *
645331Samw  *   Last command
655331Samw  *	smb_wct		a byte, number of 16-bit words containing
665331Samw  *			command parameters, min 0 for chained command
675331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
685331Samw  *			"this" command (i.e. smb_com if this is the
695331Samw  *			first parameters, or the andx_com of the just
705331Samw  *			previous block.
715331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
725331Samw  *	smb_data[]	0 or more bytes, format specific to commands
735331Samw  *
745331Samw  * Reply
755331Samw  *   Header
765331Samw  *	Magic		0xFF 'S' 'M' 'B'
775331Samw  *	smb_com 	a byte, the "first" command, corresponds
785331Samw  *			to request
795331Samw  *	Error		a 4-byte union, coding depends on dialect in use
805331Samw  *			for "DOS" errors
815331Samw  *				a byte for error class
825331Samw  *				an unused byte
835331Samw  *				a 16-bit word for error code
845331Samw  *			for "NT" errors
855331Samw  *				a 32-bit error code which
865331Samw  *				is a packed class and specifier
875331Samw  *			for "OS/2" errors
885331Samw  *				I don't know
895331Samw  *			The error information is specific to the
905331Samw  *			last command in the reply chain.
915331Samw  *	smb_flg		a one byte set of eight flags, 0x80 bit set
925331Samw  *			indicating this message is a reply
935331Samw  *	smb_flg2	a two byte set of 16 flags
945331Samw  *	.		twelve reserved bytes, have a role
955331Samw  *			in connectionless transports (IPX, UDP?)
965331Samw  *	smb_tid		a 16-bit tree ID, a mount point sorta,
975331Samw  *			should be the same as the request
985331Samw  *	smb_pid		a 16-bit process ID, MUST BE the same as request
995331Samw  *	smb_uid		a 16-bit user ID, specific to this "session"
1005331Samw  *			and mapped to a system (bona-fide) UID,
1015331Samw  *			should be the same as request
1025331Samw  *	smb_mid		a 16-bit multiplex ID, used to differentiate
1035331Samw  *			multiple simultaneous requests from the same
1045331Samw  *			process (pid) (ref RPC "xid"), MUST BE the
1055331Samw  *			same as request
1065331Samw  *	padding[]	Optional padding
1075331Samw  *
1085331Samw  *   Chained (AndX) commands (0 or more)
1095331Samw  *	smb_wct		a byte, number of 16-bit words containing
1105331Samw  *			command parameters, min 2 for chained command,
1115331Samw  *	andx_com	a byte, the "next" command, 0xFF for none,
1125331Samw  *			corresponds to request, if this is the chained
1135331Samw  *			command that had an error set to 0xFF
1145331Samw  *	.		an unused byte
1155331Samw  *	andx_off	a 16-bit offset, byte displacement from &Magic
1165331Samw  *			to the smb_wct field of the "next" command,
1175331Samw  *			ignore if andx_com is 0xFF, s/b 0 if no next
1185331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
1195331Samw  *			"this" command (i.e. smb_com if this is the
1205331Samw  *			first parameters, or the andx_com of the just
1215331Samw  *			previous block. Empty if an error.
1225331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
1235331Samw  *	smb_data[]	0 or more bytes, format specific to commands
1245331Samw  *			empty if an error.
1255331Samw  *
1265331Samw  *   Last command
1275331Samw  *	smb_wct		a byte, number of 16-bit words containing
1285331Samw  *			command parameters, min 0 for chained command
1295331Samw  *	smb_vwv[]	0 or more 16-bit (sorta) parameters for
1305331Samw  *			"this" command (i.e. smb_com if this is the
1315331Samw  *			first parameters, or the andx_com of the just
1325331Samw  *			previous block, empty if an error.
1335331Samw  *	smb_bcc		a 16-bit count of smb_data[] bytes
1345331Samw  *	smb_data[]	0 or more bytes, format specific to commands,
1355331Samw  *			empty if an error.
1365331Samw  */
1375331Samw 
13810966SJordan.Brown@Sun.COM #include <smbsrv/smb_kproto.h>
1396432Sas200622 #include <smbsrv/smb_kstat.h>
1405331Samw #include <sys/sdt.h>
14112508Samw@Sun.COM #include <sys/spl.h>
1425331Samw 
143*12890SJoyce.McIntosh@Sun.COM static int smb_legacy_dispatch_stats_update(kstat_t *, int);
1446030Sjb150015 static int is_andx_com(unsigned char);
1456030Sjb150015 static int smbsr_check_result(struct smb_request *, int, int);
1465331Samw 
147*12890SJoyce.McIntosh@Sun.COM static kstat_t *smb_legacy_dispatch_ksp = NULL;
148*12890SJoyce.McIntosh@Sun.COM static kmutex_t smb_legacy_dispatch_ksmtx;
149*12890SJoyce.McIntosh@Sun.COM 
15012508Samw@Sun.COM static smb_disp_entry_t	smb_disp_table[SMB_COM_NUM] = {
15112508Samw@Sun.COM 	{ "SmbCreateDirectory", SMB_SDT_OPS(create_directory),  /* 0x00 000 */
15212508Samw@Sun.COM 	    0x00, PC_NETWORK_PROGRAM_1_0 },
15312508Samw@Sun.COM 	{ "SmbDeleteDirectory", SMB_SDT_OPS(delete_directory),	/* 0x01 001 */
15412508Samw@Sun.COM 	    0x01, PC_NETWORK_PROGRAM_1_0 },
15512508Samw@Sun.COM 	{ "SmbOpen", SMB_SDT_OPS(open),				/* 0x02 002 */
15612508Samw@Sun.COM 	    0x02, PC_NETWORK_PROGRAM_1_0 },
15712508Samw@Sun.COM 	{ "SmbCreate", SMB_SDT_OPS(create),			/* 0x03 003 */
15812508Samw@Sun.COM 	    0x03, PC_NETWORK_PROGRAM_1_0 },
15912508Samw@Sun.COM 	{ "SmbClose", SMB_SDT_OPS(close),			/* 0x04 004 */
16012508Samw@Sun.COM 	    0x04, PC_NETWORK_PROGRAM_1_0 },
16112508Samw@Sun.COM 	{ "SmbFlush", SMB_SDT_OPS(flush),			/* 0x05 005 */
16212508Samw@Sun.COM 	    0x05, PC_NETWORK_PROGRAM_1_0 },
16312508Samw@Sun.COM 	{ "SmbDelete", SMB_SDT_OPS(delete),			/* 0x06 006 */
16412508Samw@Sun.COM 	    0x06, PC_NETWORK_PROGRAM_1_0 },
16512508Samw@Sun.COM 	{ "SmbRename", SMB_SDT_OPS(rename),			/* 0x07 007 */
16612508Samw@Sun.COM 	    0x07, PC_NETWORK_PROGRAM_1_0 },
16712508Samw@Sun.COM 	{ "SmbQueryInformation", SMB_SDT_OPS(query_information), /* 0x08 008 */
16812508Samw@Sun.COM 	    0x08, PC_NETWORK_PROGRAM_1_0 },
16912508Samw@Sun.COM 	{ "SmbSetInformation", SMB_SDT_OPS(set_information),	/* 0x09 009 */
17012508Samw@Sun.COM 	    0x09, PC_NETWORK_PROGRAM_1_0 },
17112508Samw@Sun.COM 	{ "SmbRead", SMB_SDT_OPS(read),				/* 0x0A 010 */
17212508Samw@Sun.COM 	    0x0A, PC_NETWORK_PROGRAM_1_0 },
17312508Samw@Sun.COM 	{ "SmbWrite", SMB_SDT_OPS(write),			/* 0x0B 011 */
17412508Samw@Sun.COM 	    0x0B, PC_NETWORK_PROGRAM_1_0 },
17512508Samw@Sun.COM 	{ "SmbLockByteRange", SMB_SDT_OPS(lock_byte_range),	/* 0x0C 012 */
17612508Samw@Sun.COM 	    0x0C, PC_NETWORK_PROGRAM_1_0 },
17712508Samw@Sun.COM 	{ "SmbUnlockByteRange", SMB_SDT_OPS(unlock_byte_range),	/* 0x0D 013 */
17812508Samw@Sun.COM 	    0x0D, PC_NETWORK_PROGRAM_1_0 },
17912508Samw@Sun.COM 	{ "SmbCreateTemporary", SMB_SDT_OPS(create_temporary),	/* 0x0E 014 */
18012508Samw@Sun.COM 	    0x0E, PC_NETWORK_PROGRAM_1_0 },
18112508Samw@Sun.COM 	{ "SmbCreateNew", SMB_SDT_OPS(create_new),		/* 0x0F 015 */
18212508Samw@Sun.COM 	    0x0F, PC_NETWORK_PROGRAM_1_0 },
18312508Samw@Sun.COM 	{ "SmbCheckDirectory", SMB_SDT_OPS(check_directory),	/* 0x10 016 */
18412508Samw@Sun.COM 	    0x10, PC_NETWORK_PROGRAM_1_0 },
18512508Samw@Sun.COM 	{ "SmbProcessExit", SMB_SDT_OPS(process_exit),		/* 0x11 017 */
18612508Samw@Sun.COM 	    0x11, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
18712508Samw@Sun.COM 	    0, 0, { 0 } },
18812508Samw@Sun.COM 	{ "SmbSeek", SMB_SDT_OPS(seek),				/* 0x12 018 */
18912508Samw@Sun.COM 	    0x12, PC_NETWORK_PROGRAM_1_0 },
19012508Samw@Sun.COM 	{ "SmbLockAndRead", SMB_SDT_OPS(lock_and_read),		/* 0x13 019 */
19112508Samw@Sun.COM 	    0x13, LANMAN1_0 },
19212508Samw@Sun.COM 	{ "SmbWriteAndUnlock", SMB_SDT_OPS(write_and_unlock),	/* 0x14 020 */
19312508Samw@Sun.COM 	    0x14, LANMAN1_0 },
19412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x15, 0 },		/* 0x15	021 */
19512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x16, 0 },		/* 0x16 022 */
19612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x17, 0 },		/* 0x17 023 */
19712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x18, 0 },		/* 0x18 024 */
19812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x19, 0 },		/* 0x19 025 */
19912508Samw@Sun.COM 	{ "SmbReadRaw", SMB_SDT_OPS(read_raw),			/* 0x1A 026 */
20012508Samw@Sun.COM 	    0x1A, LANMAN1_0 },
20112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1B, 0 },		/* 0x1B 027 */
20212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1C, 0 },		/* 0x1C 028 */
20312508Samw@Sun.COM 	{ "SmbWriteRaw", SMB_SDT_OPS(write_raw),		/* 0x1D 029 */
20412508Samw@Sun.COM 	    0x1D, LANMAN1_0 },
20512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1E, 0 },		/* 0x1E 030 */
20612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x1F, 0 },		/* 0x1F 031 */
20712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x20, 0 },		/* 0x20 032 */
20812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x21, 0 },		/* 0x21 033 */
20912508Samw@Sun.COM 	{ "SmbSetInformation2", SMB_SDT_OPS(set_information2),	/* 0x22 034 */
21012508Samw@Sun.COM 	    0x22, LANMAN1_0 },
21112508Samw@Sun.COM 	{ "SmbQueryInformation2",
21212508Samw@Sun.COM 	    SMB_SDT_OPS(query_information2),			/* 0x23 035 */
21312508Samw@Sun.COM 	    0x23, LANMAN1_0 },
21412508Samw@Sun.COM 	{ "SmbLockingX", SMB_SDT_OPS(locking_andx),		/* 0x24 036 */
21512508Samw@Sun.COM 	    0x24, LANMAN1_0 },
21612508Samw@Sun.COM 	{ "SmbTransaction", SMB_SDT_OPS(transaction),		/* 0x25 037 */
21712508Samw@Sun.COM 	    0x25, LANMAN1_0 },
21812508Samw@Sun.COM 	{ "SmbTransactionSecondary",
21912508Samw@Sun.COM 	    SMB_SDT_OPS(transaction_secondary),			/* 0x26 038 */
22012508Samw@Sun.COM 	    0x26, LANMAN1_0 },
22112508Samw@Sun.COM 	{ "SmbIoctl", SMB_SDT_OPS(ioctl),			/* 0x27 039 */
22212508Samw@Sun.COM 	    0x27, LANMAN1_0 },
22312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x28, 0 },	/* 0x28 040 */
22412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x29, 0 },	/* 0x29 041 */
22512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x2A, 0 },	/* 0x2A 042 */
22612508Samw@Sun.COM 	{ "SmbEcho", SMB_SDT_OPS(echo),				/* 0x2B 043 */
22712508Samw@Sun.COM 	    0x2B, LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID },
22812508Samw@Sun.COM 	{ "SmbWriteAndClose", SMB_SDT_OPS(write_and_close),	/* 0x2C 044 */
22912508Samw@Sun.COM 	    0x2C, LANMAN1_0 },
23012508Samw@Sun.COM 	{ "SmbOpenX", SMB_SDT_OPS(open_andx),			/* 0x2D 045 */
23112508Samw@Sun.COM 	    0x2D, LANMAN1_0 },
23212508Samw@Sun.COM 	{ "SmbReadX", SMB_SDT_OPS(read_andx),			/* 0x2E 046 */
23312508Samw@Sun.COM 	    0x2E, LANMAN1_0 },
23412508Samw@Sun.COM 	{ "SmbWriteX", SMB_SDT_OPS(write_andx),			/* 0x2F 047 */
23512508Samw@Sun.COM 	    0x2F, LANMAN1_0 },
23612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x30, 0 },	/* 0x30 048 */
23712508Samw@Sun.COM 	{ "SmbCloseAndTreeDisconnect",
23812508Samw@Sun.COM 	    SMB_SDT_OPS(close_and_tree_disconnect),		/* 0x31 049 */
23912508Samw@Sun.COM 	    0x31, LANMAN1_0 },
24012508Samw@Sun.COM 	{ "SmbTransaction2", SMB_SDT_OPS(transaction2),		/* 0x32 050 */
24112508Samw@Sun.COM 	    0x32, LM1_2X002 },
24212508Samw@Sun.COM 	{ "SmbTransaction2Secondary",
24312508Samw@Sun.COM 	    SMB_SDT_OPS(transaction2_secondary),		/* 0x33 051 */
24412508Samw@Sun.COM 	    0x33, LM1_2X002 },
24512508Samw@Sun.COM 	{ "SmbFindClose2", SMB_SDT_OPS(find_close2),		/* 0x34 052 */
24612508Samw@Sun.COM 	    0x34, LM1_2X002 },
24712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x35, 0 },	/* 0x35 053 */
24812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x36, 0 },	/* 0x36 054 */
24912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x37, 0 },	/* 0x37 055 */
25012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x38, 0 },	/* 0x38 056 */
25112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x39, 0 },	/* 0x39 057 */
25212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3A, 0 },	/* 0x3A 058 */
25312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3B, 0 },	/* 0x3B 059 */
25412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3C, 0 },	/* 0x3C 060 */
25512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3D, 0 },	/* 0x3D 061 */
25612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3E, 0 },	/* 0x3E 062 */
25712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x3F, 0 },	/* 0x3F 063 */
25812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x40, 0 },	/* 0x40 064 */
25912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x47, 0 },	/* 0x47 065 */
26012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x48, 0 },	/* 0x48 066 */
26112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x49, 0 },	/* 0x49 067 */
26212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x44, 0 },	/* 0x44 068 */
26312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x45, 0 },	/* 0x45 069 */
26412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x46, 0 },	/* 0x46 070 */
26512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x47, 0 },	/* 0x47 071 */
26612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x48, 0 },	/* 0x48 072 */
26712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x49, 0 },	/* 0x49 073 */
26812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4A, 0 },	/* 0x4A 074 */
26912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4B, 0 },	/* 0x4B 075 */
27012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4C, 0 },	/* 0x4C 076 */
27112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4D, 0 },	/* 0x4D 077 */
27212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4E, 0 },	/* 0x4E 078 */
27312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x4F, 0 },	/* 0x4F 079 */
27412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x50, 0 },	/* 0x50 080 */
27512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x51, 0 },	/* 0x51 081 */
27612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x52, 0 },	/* 0x52 082 */
27712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x53, 0 },	/* 0x53 083 */
27812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x54, 0 },	/* 0x54 084 */
27912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x55, 0 },	/* 0x55 085 */
28012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x56, 0 },	/* 0x56 086 */
28112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x57, 0 },	/* 0x57 087 */
28212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x58, 0 },	/* 0x58 088 */
28312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x59, 0 },	/* 0x59 089 */
28412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5A, 0 },	/* 0x5A 090 */
28512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5B, 0 },	/* 0x5B 091 */
28612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5C, 0 },	/* 0x5C 092 */
28712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5D, 0 },	/* 0x5D 093 */
28812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5E, 0 },	/* 0x5E 094 */
28912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x5F, 0 },	/* 0x5F 095 */
29012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x60, 0 },	/* 0x60 096 */
29112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x61, 0 },	/* 0x61 097 */
29212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x62, 0 },	/* 0x62 098 */
29312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x63, 0 },	/* 0x63 099 */
29412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x64, 0 },	/* 0x64 100 */
29512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x65, 0 },	/* 0x65 101 */
29612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x66, 0 },	/* 0x66 102 */
29712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x67, 0 },	/* 0x67 103 */
29812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x68, 0 },	/* 0x68 104 */
29912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x69, 0 },	/* 0x69 105 */
30012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6A, 0 },	/* 0x6A 106 */
30112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6B, 0 },	/* 0x6B 107 */
30212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6C, 0 },	/* 0x6C 108 */
30312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6D, 0 },	/* 0x6D 109 */
30412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6E, 0 },	/* 0x6E 110 */
30512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x6F, 0 },	/* 0x6F 111 */
30612508Samw@Sun.COM 	{ "SmbTreeConnect", SMB_SDT_OPS(tree_connect),		/* 0x70 112 */
30712508Samw@Sun.COM 	    0x70, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID },
30812508Samw@Sun.COM 	{ "SmbTreeDisconnect", SMB_SDT_OPS(tree_disconnect),	/* 0x71 113 */
30912508Samw@Sun.COM 	    0x71, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
31012508Samw@Sun.COM 	    NULL },
31112508Samw@Sun.COM 	{ "SmbNegotiate", SMB_SDT_OPS(negotiate),		/* 0x72 114 */
31212508Samw@Sun.COM 	    0x72, PC_NETWORK_PROGRAM_1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID,
31312508Samw@Sun.COM 	    NULL },
31412508Samw@Sun.COM 	{ "SmbSessionSetupX", SMB_SDT_OPS(session_setup_andx),	/* 0x73 115 */
31512508Samw@Sun.COM 	    0x73, LANMAN1_0, SDDF_SUPPRESS_TID | SDDF_SUPPRESS_UID },
31612508Samw@Sun.COM 	{ "SmbLogoffX", SMB_SDT_OPS(logoff_andx),		/* 0x74 116 */
31712508Samw@Sun.COM 	    0x74, LM1_2X002, SDDF_SUPPRESS_TID },
31812508Samw@Sun.COM 	{ "SmbTreeConnectX", SMB_SDT_OPS(tree_connect_andx),	/* 0x75 117 */
31912508Samw@Sun.COM 	    0x75, LANMAN1_0, SDDF_SUPPRESS_TID },
32012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x76, 0, 0 },	/* 0x76 118 */
32112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x77, 0, 0 },	/* 0x77 119 */
32212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x78, 0, 0 },	/* 0x78 120 */
32312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x79, 0, 0 },	/* 0x79 121 */
32412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7A, 0, 0 },	/* 0x7A 122 */
32512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7B, 0, 0 },	/* 0x7B 123 */
32612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7C, 0, 0 },	/* 0x7C 124 */
32712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7D, 0, 0 },	/* 0x7D 125 */
32812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7E, 0, 0 },	/* 0x7E 126 */
32912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x7F, 0, 0 },	/* 0x7F 127 */
33012508Samw@Sun.COM 	{ "SmbQueryInformationDisk",
33112508Samw@Sun.COM 	    SMB_SDT_OPS(query_information_disk),		/* 0x80 128 */
33212508Samw@Sun.COM 	    0x80, PC_NETWORK_PROGRAM_1_0, 0 },
33312508Samw@Sun.COM 	{ "SmbSearch", SMB_SDT_OPS(search),			/* 0x81 129 */
33412508Samw@Sun.COM 	    0x81, PC_NETWORK_PROGRAM_1_0, 0 },
33512508Samw@Sun.COM 	{ "SmbFind", SMB_SDT_OPS(find),				/* 0x82 130 */
33612508Samw@Sun.COM 	    0x82, LANMAN1_0, 0 },
33712508Samw@Sun.COM 	{ "SmbFindUnique", SMB_SDT_OPS(find_unique),		/* 0x83 131 */
33812508Samw@Sun.COM 	    0x83, LANMAN1_0, 0 },
33912508Samw@Sun.COM 	{ "SmbFindClose", SMB_SDT_OPS(find_close),		/* 0x84 132 */
34012508Samw@Sun.COM 	    0x84, LANMAN1_0, 0 },
34112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x85, 0, 0 },	/* 0x85 133 */
34212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x86, 0, 0 },	/* 0x86 134 */
34312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x87, 0, 0 },	/* 0x87 135 */
34412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x88, 0, 0 },	/* 0x88 136 */
34512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x89, 0, 0 },	/* 0x89 137 */
34612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8A, 0, 0 },	/* 0x8A 138 */
34712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8B, 0, 0 },	/* 0x8B 139 */
34812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8C, 0, 0 },	/* 0x8C 140 */
34912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8D, 0, 0 },	/* 0x8D 141 */
35012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8E, 0, 0 },	/* 0x8E 142 */
35112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x8F, 0, 0 },	/* 0x8F 143 */
35212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x90, 0, 0 },	/* 0x90 144 */
35312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x91, 0, 0 },	/* 0x91 145 */
35412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x92, 0, 0 },	/* 0x92 146 */
35512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x93, 0, 0 },	/* 0x93 147 */
35612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x94, 0, 0 },	/* 0x94 148 */
35712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x95, 0, 0 },	/* 0x95 149 */
35812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x96, 0, 0 },	/* 0x96 150 */
35912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x97, 0, 0 },	/* 0x97 151 */
36012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x98, 0, 0 },	/* 0x98 152 */
36112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x99, 0, 0 },	/* 0x99 153 */
36212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9A, 0, 0 },	/* 0x9A 154 */
36312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9B, 0, 0 },	/* 0x9B 155 */
36412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9C, 0, 0 },	/* 0x9C 156 */
36512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9D, 0, 0 },	/* 0x9D 157 */
36612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9E, 0, 0 },	/* 0x9E 158 */
36712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0x9F, 0, 0 },	/* 0x9F 159 */
36812508Samw@Sun.COM 	{ "SmbNtTransact", SMB_SDT_OPS(nt_transact),	/* 0xA0 160 */
36912508Samw@Sun.COM 	    0xA0, NT_LM_0_12, 0 },
37012508Samw@Sun.COM 	{ "SmbNtTransactSecondary",
37112508Samw@Sun.COM 	    SMB_SDT_OPS(nt_transact_secondary),			/* 0xA1 161 */
37212508Samw@Sun.COM 	    0xA1, NT_LM_0_12, 0 },
37312508Samw@Sun.COM 	{ "SmbNtCreateX", SMB_SDT_OPS(nt_create_andx),		/* 0xA2 162 */
37412508Samw@Sun.COM 	    0xA2, NT_LM_0_12, 0 },
37512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA3, 0, 0 },	/* 0xA3 163 */
37612508Samw@Sun.COM 	{ "SmbNtCancel", SMB_SDT_OPS(nt_cancel),		/* 0xA4 164 */
37712508Samw@Sun.COM 	    0xA4, NT_LM_0_12, 0 },
37812508Samw@Sun.COM 	{ "SmbNtRename", SMB_SDT_OPS(nt_rename),		/* 0xA5 165 */
37912508Samw@Sun.COM 	    0xA5, NT_LM_0_12, 0 },
38012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA6, 0, 0 },	/* 0xA6 166 */
38112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA7, 0, 0 },	/* 0xA7 167 */
38212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA8, 0, 0 },	/* 0xA8 168 */
38312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xA9, 0, 0 },	/* 0xA9 169 */
38412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAA, 0, 0 },	/* 0xAA 170 */
38512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAB, 0, 0 },	/* 0xAB 171 */
38612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAC, 0, 0 },	/* 0xAC 172 */
38712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAD, 0, 0 },	/* 0xAD 173 */
38812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAE, 0, 0 },	/* 0xAE 174 */
38912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xAF, 0, 0 },	/* 0xAF 175 */
39012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB0, 0, 0 },	/* 0xB0 176 */
39112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB1, 0, 0 },	/* 0xB1 177 */
39212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB2, 0, 0 },	/* 0xB2 178 */
39312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB3, 0, 0 },	/* 0xB3 179 */
39412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB4, 0, 0 },	/* 0xB4 180 */
39512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB5, 0, 0 },	/* 0xB5 181 */
39612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB6, 0, 0 },	/* 0xB6 182 */
39712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB7, 0, 0 },	/* 0xB7 183 */
39812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB8, 0, 0 },	/* 0xB8 184 */
39912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xB9, 0, 0 },	/* 0xB9 185 */
40012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBA, 0, 0 },	/* 0xBA 186 */
40112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBB, 0, 0 },	/* 0xBB 187 */
40212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBC, 0, 0 },	/* 0xBC 188 */
40312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBD, 0, 0 },	/* 0xBD 189 */
40412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBE, 0, 0 },	/* 0xBE 190 */
40512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xBF, 0, 0 },	/* 0xBF 191 */
40612508Samw@Sun.COM 	{ "SmbOpenPrintFile", SMB_SDT_OPS(open_print_file),	/* 0xC0 192 */
40712508Samw@Sun.COM 	    0xC0, PC_NETWORK_PROGRAM_1_0, 0 },
40812508Samw@Sun.COM 	{ "SmbWritePrintFile", SMB_SDT_OPS(write_print_file),	/* 0xC1 193 */
40912508Samw@Sun.COM 	    0xC1, PC_NETWORK_PROGRAM_1_0, 0 },
41012508Samw@Sun.COM 	{ "SmbClosePrintFile", SMB_SDT_OPS(close_print_file),	/* 0xC2 194 */
41112508Samw@Sun.COM 	    0xC2, PC_NETWORK_PROGRAM_1_0, 0 },
41212508Samw@Sun.COM 	{ "SmbGetPrintQueue", SMB_SDT_OPS(get_print_queue),	/* 0xC3 195 */
41312508Samw@Sun.COM 	    0xC3, PC_NETWORK_PROGRAM_1_0, 0 },
41412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC4, 0, 0 },	/* 0xC4 196 */
41512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC5, 0, 0 },	/* 0xC5 197 */
41612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC6, 0, 0 },	/* 0xC6 198 */
41712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC7, 0, 0 },	/* 0xC7 199 */
41812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC8, 0, 0 },	/* 0xC8 200 */
41912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xC9, 0, 0 },	/* 0xC9 201 */
42012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCA, 0, 0 },	/* 0xCA 202 */
42112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCB, 0, 0 },	/* 0xCB 203 */
42212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCC, 0, 0 },	/* 0xCC 204 */
42312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCD, 0, 0 },	/* 0xCD 205 */
42412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCE, 0, 0 },	/* 0xCE 206 */
42512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xCF, 0, 0 },	/* 0xCF 207 */
42612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD0, 0, 0 },	/* 0xD0 208 */
42712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD1, 0, 0 },	/* 0xD1 209 */
42812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD2, 0, 0 },	/* 0xD2 210 */
42912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD3, 0, 0 },	/* 0xD3 211 */
43012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD4, 0, 0 },	/* 0xD4 212 */
43112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD5, 0, 0 },	/* 0xD5 213 */
43212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD6, 0, 0 },	/* 0xD6 214 */
43312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD7, 0, 0 },	/* 0xD7 215 */
43412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD8, 0, 0 },	/* 0xD8 216 */
43512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xD9, 0, 0 },	/* 0xD9 217 */
43612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDA, 0, 0 },	/* 0xDA 218 */
43712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDB, 0, 0 },	/* 0xDB 219 */
43812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDC, 0, 0 },	/* 0xDC 220 */
43912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDD, 0, 0 },	/* 0xDD 221 */
44012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDE, 0, 0 },	/* 0xDE 222 */
44112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xDF, 0, 0 },	/* 0xDF 223 */
44212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE0, 0, 0 },	/* 0xE0 224 */
44312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE1, 0, 0 },	/* 0xE1 225 */
44412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE2, 0, 0 },	/* 0xE2 226 */
44512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE3, 0, 0 },	/* 0xE3 227 */
44612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE4, 0, 0 },	/* 0xE4 228 */
44712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE5, 0, 0 },	/* 0xE5 229 */
44812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE6, 0, 0 },	/* 0xE6 230 */
44912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE7, 0, 0 },	/* 0xE7 231 */
45012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE8, 0, 0 },	/* 0xE8 232 */
45112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xE9, 0, 0 },	/* 0xE9 233 */
45212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEA, 0, 0 },	/* 0xEA 234 */
45312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEB, 0, 0 },	/* 0xEB 235 */
45412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEC, 0, 0 },	/* 0xEC 236 */
45512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xED, 0, 0 },	/* 0xED 237 */
45612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEE, 0, 0 },	/* 0xEE 238 */
45712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xEF, 0, 0 },	/* 0xEF 239 */
45812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF0, 0, 0 },	/* 0xF0 240 */
45912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF1, 0, 0 },	/* 0xF1 241 */
46012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF2, 0, 0 },	/* 0xF2 242 */
46112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF3, 0, 0 },	/* 0xF3 243 */
46212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF4, 0, 0 },	/* 0xF4 244 */
46312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF5, 0, 0 },	/* 0xF5 245 */
46412508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF6, 0, 0 },	/* 0xF6 246 */
46512508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF7, 0, 0 },	/* 0xF7 247 */
46612508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF8, 0, 0 },	/* 0xF8 248 */
46712508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xF9, 0, 0 },	/* 0xF9 249 */
46812508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFA, 0, 0 },	/* 0xFA 250 */
46912508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFB, 0, 0 },	/* 0xFB 251 */
47012508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFC, 0, 0 },	/* 0xFC 252 */
47112508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFD, 0, 0 },	/* 0xFD 253 */
47212508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFE, 0, 0 },	/* 0xFE 254 */
47312508Samw@Sun.COM 	{ "Invalid", SMB_SDT_OPS(invalid), 0xFF, 0, 0 }	/* 0xFF	255 */
4745331Samw };
4755331Samw 
4765331Samw /*
4775331Samw  * smbsr_cleanup
4785331Samw  *
4795331Samw  * If any user/tree/file is used by given request then
4805331Samw  * the reference count for that resource has been incremented.
4815331Samw  * This function decrements the reference count and close
4825331Samw  * the resource if it's needed.
4835331Samw  */
4845331Samw 
4855331Samw void
smbsr_cleanup(smb_request_t * sr)4866139Sjb150015 smbsr_cleanup(smb_request_t *sr)
4875331Samw {
4885331Samw 	ASSERT((sr->sr_state != SMB_REQ_STATE_CLEANED_UP) &&
4895331Samw 	    (sr->sr_state != SMB_REQ_STATE_COMPLETED));
4905331Samw 
4915331Samw 	if (sr->r_xa) {
4925331Samw 		if (sr->r_xa->xa_flags & SMB_XA_FLAG_COMPLETE)
4935331Samw 			smb_xa_close(sr->r_xa);
4945331Samw 		smb_xa_rele(sr->session, sr->r_xa);
4955331Samw 		sr->r_xa = NULL;
4965331Samw 	}
4975331Samw 
4985331Samw 	/*
4995331Samw 	 * Mark this request so we know that we've already cleaned it up.
5005331Samw 	 * A request should only get cleaned up once so multiple calls to
5015331Samw 	 * smbsr_cleanup for the same request indicate a bug.
5025331Samw 	 */
5035331Samw 	mutex_enter(&sr->sr_mutex);
5045331Samw 	if (sr->sr_state != SMB_REQ_STATE_CANCELED)
5055331Samw 		sr->sr_state = SMB_REQ_STATE_CLEANED_UP;
5065331Samw 	mutex_exit(&sr->sr_mutex);
5075331Samw }
5088262SJose.Borrego@Sun.COM /*
5098262SJose.Borrego@Sun.COM  * smb_dispatch_request
5108262SJose.Borrego@Sun.COM  *
5118262SJose.Borrego@Sun.COM  * Returns:
5128262SJose.Borrego@Sun.COM  *
5138262SJose.Borrego@Sun.COM  *    B_TRUE	The caller must free the smb request passed in.
5148262SJose.Borrego@Sun.COM  *    B_FALSE	The caller must not access the smb request passed in. It has
5158262SJose.Borrego@Sun.COM  *		been kept in an internal queue and may have already been freed.
5168262SJose.Borrego@Sun.COM  */
5178262SJose.Borrego@Sun.COM boolean_t
smb_dispatch_request(struct smb_request * sr)5185331Samw smb_dispatch_request(struct smb_request *sr)
5195331Samw {
5206030Sjb150015 	smb_sdrc_t		sdrc;
5218934SJose.Borrego@Sun.COM 	smb_disp_entry_t	*sdd;
5226030Sjb150015 	boolean_t		disconnect = B_FALSE;
5238262SJose.Borrego@Sun.COM 	smb_session_t		*session;
5248934SJose.Borrego@Sun.COM 	uint32_t		capabilities;
5258934SJose.Borrego@Sun.COM 	uint32_t		byte_count;
5268262SJose.Borrego@Sun.COM 
5278262SJose.Borrego@Sun.COM 	session = sr->session;
5288934SJose.Borrego@Sun.COM 	capabilities = session->capabilities;
5295331Samw 
5305331Samw 	ASSERT(sr->tid_tree == 0);
5315331Samw 	ASSERT(sr->uid_user == 0);
5325331Samw 	ASSERT(sr->fid_ofile == 0);
5335331Samw 	sr->smb_fid = (uint16_t)-1;
5345331Samw 
5355331Samw 	/* temporary until we identify a user */
5365331Samw 	sr->user_cr = kcred;
5375331Samw 	sr->orig_request_hdr = sr->command.chain_offset;
5385331Samw 
5395331Samw 	/* If this connection is shutting down just kill request */
5407052Samw 	if (smb_mbc_decodef(&sr->command, SMB_HEADER_ED_FMT,
5415331Samw 	    &sr->smb_com,
5425331Samw 	    &sr->smb_rcls,
5435331Samw 	    &sr->smb_reh,
5445331Samw 	    &sr->smb_err,
5455331Samw 	    &sr->smb_flg,
5465331Samw 	    &sr->smb_flg2,
5475331Samw 	    &sr->smb_pid_high,
5485331Samw 	    sr->smb_sig,
5495331Samw 	    &sr->smb_tid,
5505331Samw 	    &sr->smb_pid,
5515331Samw 	    &sr->smb_uid,
5525331Samw 	    &sr->smb_mid) != 0) {
5536030Sjb150015 		disconnect = B_TRUE;
5546030Sjb150015 		goto drop_connection;
5555331Samw 	}
5565331Samw 
5575331Samw 	/*
5586030Sjb150015 	 * The reply "header" is filled in now even though it will,
5596030Sjb150015 	 * most likely, be rewritten under reply_ready below.  We
5606030Sjb150015 	 * could reserve the space but this is convenient in case
5616030Sjb150015 	 * the dialect dispatcher has to send a special reply (like
5626030Sjb150015 	 * TRANSACT).
5635331Samw 	 *
5645331Samw 	 * Ensure that the 32-bit error code flag is turned off.
5655331Samw 	 * Clients seem to set it in transact requests and they may
5665331Samw 	 * get confused if we return success or a 16-bit SMB code.
5675331Samw 	 */
5685331Samw 	sr->smb_rcls = 0;
5695331Samw 	sr->smb_reh = 0;
5705331Samw 	sr->smb_err = 0;
5715331Samw 	sr->smb_flg2 &= ~SMB_FLAGS2_NT_STATUS;
5725331Samw 
5737052Samw 	(void) smb_mbc_encodef(&sr->reply, SMB_HEADER_ED_FMT,
5745331Samw 	    sr->smb_com,
5755331Samw 	    sr->smb_rcls,
5765331Samw 	    sr->smb_reh,
5775331Samw 	    sr->smb_err,
5785331Samw 	    sr->smb_flg,
5795331Samw 	    sr->smb_flg2,
5805331Samw 	    sr->smb_pid_high,
5815331Samw 	    sr->smb_sig,
5825331Samw 	    sr->smb_tid,
5835331Samw 	    sr->smb_pid,
5845331Samw 	    sr->smb_uid,
5855331Samw 	    sr->smb_mid);
5865331Samw 	sr->first_smb_com = sr->smb_com;
5875331Samw 
5885331Samw 	/*
5895772Sas200622 	 * Verify SMB signature if signing is enabled, dialect is NT LM 0.12,
5905331Samw 	 * signing was negotiated and authentication has occurred.
5915331Samw 	 */
5928262SJose.Borrego@Sun.COM 	if (session->signing.flags & SMB_SIGNING_ENABLED) {
5935331Samw 		if (smb_sign_check_request(sr) != 0) {
5946030Sjb150015 			smbsr_error(sr, NT_STATUS_ACCESS_DENIED,
5956030Sjb150015 			    ERRDOS, ERROR_ACCESS_DENIED);
5966030Sjb150015 			disconnect = B_TRUE;
5976030Sjb150015 			goto report_error;
5985331Samw 		}
5995331Samw 	}
6005331Samw 
6015331Samw andx_more:
60212508Samw@Sun.COM 	sdd = &smb_disp_table[sr->smb_com];
6036139Sjb150015 	ASSERT(sdd->sdt_function);
6045331Samw 
6057052Samw 	if (smb_mbc_decodef(&sr->command, "b", &sr->smb_wct) != 0) {
6066030Sjb150015 		disconnect = B_TRUE;
6076030Sjb150015 		goto report_error;
6085331Samw 	}
6095331Samw 
6105331Samw 	(void) MBC_SHADOW_CHAIN(&sr->smb_vwv, &sr->command,
6115331Samw 	    sr->command.chain_offset, sr->smb_wct * 2);
6125331Samw 
6137052Samw 	if (smb_mbc_decodef(&sr->command, "#.w", sr->smb_wct*2, &sr->smb_bcc)) {
6146030Sjb150015 		disconnect = B_TRUE;
6156030Sjb150015 		goto report_error;
6165331Samw 	}
6175331Samw 
61812508Samw@Sun.COM 	atomic_add_64(&sdd->sdt_rxb,
61912508Samw@Sun.COM 	    (int64_t)(sr->smb_wct * 2 + sr->smb_bcc + 1));
62012508Samw@Sun.COM 	sr->sr_txb = sr->reply.chain_offset;
62112508Samw@Sun.COM 
6228934SJose.Borrego@Sun.COM 	/*
6238934SJose.Borrego@Sun.COM 	 * Ignore smb_bcc if CAP_LARGE_READX/CAP_LARGE_WRITEX
6248934SJose.Borrego@Sun.COM 	 * and this is SmbReadX/SmbWriteX since this enables
6258934SJose.Borrego@Sun.COM 	 * large reads/write and bcc is only 16-bits.
6268934SJose.Borrego@Sun.COM 	 */
6278934SJose.Borrego@Sun.COM 	if (((sr->smb_com == SMB_COM_READ_ANDX) &&
6288934SJose.Borrego@Sun.COM 	    (capabilities & CAP_LARGE_READX)) ||
6298934SJose.Borrego@Sun.COM 	    ((sr->smb_com == SMB_COM_WRITE_ANDX) &&
6308934SJose.Borrego@Sun.COM 	    (capabilities & CAP_LARGE_WRITEX))) {
6318934SJose.Borrego@Sun.COM 		byte_count = sr->command.max_bytes - sr->command.chain_offset;
6328934SJose.Borrego@Sun.COM 	} else {
6338934SJose.Borrego@Sun.COM 		byte_count = (uint32_t)sr->smb_bcc;
6348934SJose.Borrego@Sun.COM 	}
6358934SJose.Borrego@Sun.COM 
6365331Samw 	(void) MBC_SHADOW_CHAIN(&sr->smb_data, &sr->command,
6378934SJose.Borrego@Sun.COM 	    sr->command.chain_offset, byte_count);
6385331Samw 
6398934SJose.Borrego@Sun.COM 	sr->command.chain_offset += byte_count;
6405331Samw 	if (sr->command.chain_offset > sr->command.max_bytes) {
6416030Sjb150015 		disconnect = B_TRUE;
6426030Sjb150015 		goto report_error;
6435331Samw 	}
6445331Samw 
6455331Samw 	/* Store pointers for later */
6465331Samw 	sr->cur_reply_offset = sr->reply.chain_offset;
6475331Samw 
6485331Samw 	if (is_andx_com(sr->smb_com)) {
6495331Samw 		/* Peek ahead and don't disturb vwv */
6507052Samw 		if (smb_mbc_peek(&sr->smb_vwv, sr->smb_vwv.chain_offset, "b.w",
6515331Samw 		    &sr->andx_com, &sr->andx_off) < 0) {
6526030Sjb150015 			disconnect = B_TRUE;
6536030Sjb150015 			goto report_error;
6545331Samw 		}
6555331Samw 	} else {
6565331Samw 		sr->andx_com = (unsigned char)-1;
6575331Samw 	}
6585331Samw 
6595331Samw 	mutex_enter(&sr->sr_mutex);
6605331Samw 	switch (sr->sr_state) {
6615331Samw 	case SMB_REQ_STATE_SUBMITTED:
6625331Samw 	case SMB_REQ_STATE_CLEANED_UP:
6635331Samw 		sr->sr_state = SMB_REQ_STATE_ACTIVE;
6645331Samw 		break;
6655331Samw 	case SMB_REQ_STATE_CANCELED:
6665331Samw 		break;
6675331Samw 	default:
6685331Samw 		ASSERT(0);
6695331Samw 		break;
6705331Samw 	}
6715331Samw 	mutex_exit(&sr->sr_mutex);
6725331Samw 
6736030Sjb150015 	/*
6746030Sjb150015 	 * Setup UID and TID information (if required). Both functions
6756030Sjb150015 	 * will set the sr credentials. In domain mode, the user and
6766030Sjb150015 	 * tree credentials should be the same. In share mode, the
6776030Sjb150015 	 * tree credentials (defined in the share definition) should
6786030Sjb150015 	 * override the user credentials.
6796030Sjb150015 	 */
6806139Sjb150015 	if (!(sdd->sdt_flags & SDDF_SUPPRESS_UID) && (sr->uid_user == NULL)) {
68111963SAfshin.Ardakani@Sun.COM 		sr->uid_user = smb_session_lookup_uid(session, sr->smb_uid);
6826030Sjb150015 		if (sr->uid_user == NULL) {
6836030Sjb150015 			smbsr_error(sr, 0, ERRSRV, ERRbaduid);
6846139Sjb150015 			smbsr_cleanup(sr);
6856030Sjb150015 			goto report_error;
6865331Samw 		}
6875331Samw 
6887961SNatalie.Li@Sun.COM 		sr->user_cr = smb_user_getcred(sr->uid_user);
6897961SNatalie.Li@Sun.COM 
6906139Sjb150015 		if (!(sdd->sdt_flags & SDDF_SUPPRESS_TID) &&
6916139Sjb150015 		    (sr->tid_tree == NULL)) {
6927348SJose.Borrego@Sun.COM 			sr->tid_tree = smb_user_lookup_tree(
6936030Sjb150015 			    sr->uid_user, sr->smb_tid);
6946030Sjb150015 			if (sr->tid_tree == NULL) {
6956030Sjb150015 				smbsr_error(sr, 0, ERRSRV, ERRinvnid);
6966139Sjb150015 				smbsr_cleanup(sr);
6976030Sjb150015 				goto report_error;
6985331Samw 			}
6995331Samw 		}
7005331Samw 	}
7015331Samw 
7026030Sjb150015 	/*
7036030Sjb150015 	 * If the command is not a read raw request we can set the
7046030Sjb150015 	 * state of the session back to SMB_SESSION_STATE_NEGOTIATED
7056030Sjb150015 	 * (if the current state is SMB_SESSION_STATE_OPLOCK_BREAKING).
7066030Sjb150015 	 * Otherwise we let the read raw handler to deal with it.
7076030Sjb150015 	 */
7089343SAfshin.Ardakani@Sun.COM 	smb_rwx_rwenter(&session->s_lock, RW_READER);
7098262SJose.Borrego@Sun.COM 	if ((session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING) &&
7106030Sjb150015 	    (sr->smb_com != SMB_COM_READ_RAW)) {
7119343SAfshin.Ardakani@Sun.COM 		(void) smb_rwx_rwupgrade(&session->s_lock);
7128262SJose.Borrego@Sun.COM 		if (session->s_state == SMB_SESSION_STATE_OPLOCK_BREAKING)
7138262SJose.Borrego@Sun.COM 			session->s_state = SMB_SESSION_STATE_NEGOTIATED;
7146030Sjb150015 	}
7159343SAfshin.Ardakani@Sun.COM 	smb_rwx_rwexit(&session->s_lock);
7166030Sjb150015 
71712508Samw@Sun.COM 	sr->sr_time_start = gethrtime();
7186139Sjb150015 	if ((sdrc = (*sdd->sdt_pre_op)(sr)) == SDRC_SUCCESS)
7196139Sjb150015 		sdrc = (*sdd->sdt_function)(sr);
7206139Sjb150015 
7219343SAfshin.Ardakani@Sun.COM 	if (sdrc != SDRC_SR_KEPT) {
7229343SAfshin.Ardakani@Sun.COM 		(*sdd->sdt_post_op)(sr);
7239343SAfshin.Ardakani@Sun.COM 		smbsr_cleanup(sr);
7249343SAfshin.Ardakani@Sun.COM 	}
72512508Samw@Sun.COM 	smb_latency_add_sample(&sdd->sdt_lat, gethrtime() - sr->sr_time_start);
72612508Samw@Sun.COM 
72712508Samw@Sun.COM 	atomic_add_64(&sdd->sdt_txb,
72812508Samw@Sun.COM 	    (int64_t)(sr->reply.chain_offset - sr->sr_txb));
7299343SAfshin.Ardakani@Sun.COM 
7306139Sjb150015 	if (sdrc != SDRC_SUCCESS) {
7316030Sjb150015 		/*
7326030Sjb150015 		 * Handle errors from raw write.
7336030Sjb150015 		 */
7349343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwenter(&session->s_lock, RW_WRITER);
7358262SJose.Borrego@Sun.COM 		if (session->s_state == SMB_SESSION_STATE_WRITE_RAW_ACTIVE) {
7366030Sjb150015 			/*
7376030Sjb150015 			 * Set state so that the netbios session
7386030Sjb150015 			 * daemon will start accepting data again.
7396030Sjb150015 			 */
7408262SJose.Borrego@Sun.COM 			session->s_write_raw_status = 0;
7418262SJose.Borrego@Sun.COM 			session->s_state = SMB_SESSION_STATE_NEGOTIATED;
7426030Sjb150015 		}
7439343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwexit(&session->s_lock);
7448262SJose.Borrego@Sun.COM 	}
7456030Sjb150015 
7466030Sjb150015 	switch (sdrc) {
7476139Sjb150015 	case SDRC_SUCCESS:
7486030Sjb150015 		break;
7496030Sjb150015 
7506030Sjb150015 	case SDRC_DROP_VC:
7516030Sjb150015 		disconnect = B_TRUE;
7526030Sjb150015 		goto drop_connection;
7536030Sjb150015 
7546030Sjb150015 	case SDRC_NO_REPLY:
7558262SJose.Borrego@Sun.COM 		return (B_TRUE);
7568262SJose.Borrego@Sun.COM 
7578262SJose.Borrego@Sun.COM 	case SDRC_SR_KEPT:
7588262SJose.Borrego@Sun.COM 		return (B_FALSE);
7596030Sjb150015 
7606139Sjb150015 	case SDRC_ERROR:
7616030Sjb150015 		goto report_error;
7626030Sjb150015 
7636139Sjb150015 	case SDRC_NOT_IMPLEMENTED:
7646030Sjb150015 	default:
7656030Sjb150015 		smbsr_error(sr, 0, ERRDOS, ERRbadfunc);
7666030Sjb150015 		goto report_error;
7676030Sjb150015 	}
7686030Sjb150015 
7696030Sjb150015 	/*
7706030Sjb150015 	 * If there's no AndX command, we're done.
7716030Sjb150015 	 */
7725331Samw 	if (sr->andx_com == 0xff)
7735331Samw 		goto reply_ready;
7745331Samw 
7756030Sjb150015 	/*
7766030Sjb150015 	 * Otherwise, we have to back-patch the AndXCommand and AndXOffset
7776030Sjb150015 	 * and continue processing.
7786030Sjb150015 	 */
7795331Samw 	sr->andx_prev_wct = sr->cur_reply_offset;
7807052Samw 	(void) smb_mbc_poke(&sr->reply, sr->andx_prev_wct + 1, "b.w",
7815331Samw 	    sr->andx_com, MBC_LENGTH(&sr->reply));
7825331Samw 
7835331Samw 	sr->command.chain_offset = sr->orig_request_hdr + sr->andx_off;
7845331Samw 	sr->smb_com = sr->andx_com;
7855331Samw 	goto andx_more;
7865331Samw 
7876030Sjb150015 report_error:
7885331Samw 	sr->reply.chain_offset = sr->cur_reply_offset;
7897052Samw 	(void) smb_mbc_encodef(&sr->reply, "bw", 0, 0);
7905331Samw 
7915331Samw 	sr->smb_wct = 0;
7925331Samw 	sr->smb_bcc = 0;
7935331Samw 
7946139Sjb150015 	if (sr->smb_rcls == 0 && sr->smb_reh == 0 && sr->smb_err == 0)
7956030Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
7966030Sjb150015 
7976030Sjb150015 reply_ready:
7986030Sjb150015 	smbsr_send_reply(sr);
7996030Sjb150015 
8006030Sjb150015 drop_connection:
8016030Sjb150015 	if (disconnect) {
8029343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwenter(&session->s_lock, RW_WRITER);
8038262SJose.Borrego@Sun.COM 		switch (session->s_state) {
8046030Sjb150015 		case SMB_SESSION_STATE_DISCONNECTED:
8056030Sjb150015 		case SMB_SESSION_STATE_TERMINATED:
8066030Sjb150015 			break;
8076030Sjb150015 		default:
8088262SJose.Borrego@Sun.COM 			smb_soshutdown(session->sock);
8098262SJose.Borrego@Sun.COM 			session->s_state = SMB_SESSION_STATE_DISCONNECTED;
8106030Sjb150015 			break;
8116030Sjb150015 		}
8129343SAfshin.Ardakani@Sun.COM 		smb_rwx_rwexit(&session->s_lock);
8135331Samw 	}
8146030Sjb150015 
8158262SJose.Borrego@Sun.COM 	return (B_TRUE);
8165331Samw }
8175331Samw 
8186030Sjb150015 int
smbsr_encode_empty_result(struct smb_request * sr)8196030Sjb150015 smbsr_encode_empty_result(struct smb_request *sr)
8206030Sjb150015 {
8216030Sjb150015 	return (smbsr_encode_result(sr, 0, 0, "bw", 0, 0));
8226030Sjb150015 }
8235331Samw 
8246030Sjb150015 int
smbsr_encode_result(struct smb_request * sr,int wct,int bcc,char * fmt,...)8256030Sjb150015 smbsr_encode_result(struct smb_request *sr, int wct, int bcc, char *fmt, ...)
8265331Samw {
8275331Samw 	va_list ap;
8285331Samw 
8296030Sjb150015 	if (MBC_LENGTH(&sr->reply) != sr->cur_reply_offset)
8306030Sjb150015 		return (-1);
8315331Samw 
8325331Samw 	va_start(ap, fmt);
8337052Samw 	(void) smb_mbc_vencodef(&sr->reply, fmt, ap);
8345331Samw 	va_end(ap);
8355331Samw 
8365331Samw 	sr->smb_wct = (unsigned char)wct;
8375331Samw 	sr->smb_bcc = (uint16_t)bcc;
8385331Samw 
8396030Sjb150015 	if (smbsr_check_result(sr, wct, bcc) != 0)
8406030Sjb150015 		return (-1);
8416030Sjb150015 
8426030Sjb150015 	return (0);
8435331Samw }
8445331Samw 
8456030Sjb150015 static int
smbsr_check_result(struct smb_request * sr,int wct,int bcc)8465331Samw smbsr_check_result(struct smb_request *sr, int wct, int bcc)
8475331Samw {
8485331Samw 	int		offset = sr->cur_reply_offset;
8495331Samw 	int		total_bytes;
8505331Samw 	unsigned char	temp, temp1;
8515331Samw 	struct mbuf	*m;
8525331Samw 
8535331Samw 	total_bytes = 0;
8545331Samw 	m = sr->reply.chain;
8555331Samw 	while (m != 0) {
8565331Samw 		total_bytes += m->m_len;
8575331Samw 		m = m->m_next;
8585331Samw 	}
8595331Samw 
8606030Sjb150015 	if ((offset + 3) > total_bytes)
8616030Sjb150015 		return (-1);
8625331Samw 
8637052Samw 	(void) smb_mbc_peek(&sr->reply, offset, "b", &temp);
8646030Sjb150015 	if (temp != wct)
8656030Sjb150015 		return (-1);
8665331Samw 
8676030Sjb150015 	if ((offset + (wct * 2 + 1)) > total_bytes)
8686030Sjb150015 		return (-1);
8695331Samw 
8705331Samw 	/* reply wct & vwv seem ok, consider data now */
8715331Samw 	offset += wct * 2 + 1;
8725331Samw 
8736030Sjb150015 	if ((offset + 2) > total_bytes)
8746030Sjb150015 		return (-1);
8755331Samw 
8767052Samw 	(void) smb_mbc_peek(&sr->reply, offset, "bb", &temp, &temp1);
8775331Samw 	if (bcc == VAR_BCC) {
8785331Samw 		if ((temp != 0xFF) || (temp1 != 0xFF)) {
8796030Sjb150015 			return (-1);
8805331Samw 		} else {
8815331Samw 			bcc = (total_bytes - offset) - 2;
8827052Samw 			(void) smb_mbc_poke(&sr->reply, offset, "bb",
8835331Samw 			    bcc, bcc >> 8);
8845331Samw 		}
8855331Samw 	} else {
8866030Sjb150015 		if ((temp != (bcc&0xFF)) || (temp1 != ((bcc>>8)&0xFF)))
8876030Sjb150015 			return (-1);
8885331Samw 	}
8895331Samw 
8905331Samw 	offset += bcc + 2;
8915331Samw 
8926030Sjb150015 	if (offset != total_bytes)
8936030Sjb150015 		return (-1);
8945331Samw 
8955331Samw 	sr->smb_wct = (unsigned char)wct;
8965331Samw 	sr->smb_bcc = (uint16_t)bcc;
8976030Sjb150015 	return (0);
8985331Samw }
8995331Samw 
9005331Samw int
smbsr_decode_vwv(struct smb_request * sr,char * fmt,...)9015331Samw smbsr_decode_vwv(struct smb_request *sr, char *fmt, ...)
9025331Samw {
9035331Samw 	int rc;
9045331Samw 	va_list ap;
9055331Samw 
9065331Samw 	va_start(ap, fmt);
9077052Samw 	rc = smb_mbc_vdecodef(&sr->smb_vwv, fmt, ap);
9085331Samw 	va_end(ap);
9095331Samw 
9106139Sjb150015 	if (rc)
9116139Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
9125331Samw 	return (rc);
9135331Samw }
9145331Samw 
9155331Samw int
smbsr_decode_data(struct smb_request * sr,char * fmt,...)9165331Samw smbsr_decode_data(struct smb_request *sr, char *fmt, ...)
9175331Samw {
9186139Sjb150015 	int rc;
9195331Samw 	va_list ap;
9206139Sjb150015 
9215331Samw 	va_start(ap, fmt);
9227052Samw 	rc = smb_mbc_vdecodef(&sr->smb_data, fmt, ap);
9235331Samw 	va_end(ap);
9246139Sjb150015 
9256139Sjb150015 	if (rc)
9266139Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
9276139Sjb150015 	return (rc);
9285331Samw }
9295331Samw 
93012508Samw@Sun.COM boolean_t
smbsr_decode_data_avail(smb_request_t * sr)93112508Samw@Sun.COM smbsr_decode_data_avail(smb_request_t *sr)
93212508Samw@Sun.COM {
93312508Samw@Sun.COM 	return (sr->smb_data.chain_offset < sr->smb_data.max_bytes);
93412508Samw@Sun.COM }
93512508Samw@Sun.COM 
9365331Samw void
smbsr_send_reply(smb_request_t * sr)93712508Samw@Sun.COM smbsr_send_reply(smb_request_t *sr)
9385331Samw {
9397348SJose.Borrego@Sun.COM 	if (SMB_TREE_IS_CASEINSENSITIVE(sr))
9406030Sjb150015 		sr->smb_flg |= SMB_FLAGS_CASE_INSENSITIVE;
9416030Sjb150015 	else
9426030Sjb150015 		sr->smb_flg &= ~SMB_FLAGS_CASE_INSENSITIVE;
9436030Sjb150015 
9447052Samw 	(void) smb_mbc_poke(&sr->reply, 0, SMB_HEADER_ED_FMT,
9455331Samw 	    sr->first_smb_com,
9465331Samw 	    sr->smb_rcls,
9475331Samw 	    sr->smb_reh,
9485331Samw 	    sr->smb_err,
9495331Samw 	    sr->smb_flg | SMB_FLAGS_REPLY,
9505331Samw 	    sr->smb_flg2,
9515331Samw 	    sr->smb_pid_high,
9525331Samw 	    sr->smb_sig,
9535331Samw 	    sr->smb_tid,
9545331Samw 	    sr->smb_pid,
9555331Samw 	    sr->smb_uid,
9565331Samw 	    sr->smb_mid);
9575331Samw 
9585331Samw 	if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
9595331Samw 		smb_sign_reply(sr, NULL);
9605331Samw 
96112508Samw@Sun.COM 	smb_server_inc_req(sr->session->s_server);
9626030Sjb150015 	if (smb_session_send(sr->session, 0, &sr->reply) == 0)
9636030Sjb150015 		sr->reply.chain = 0;
9645331Samw }
9655331Samw 
9665331Samw /*
9675772Sas200622  * Map errno values to SMB and NT status values.
9685772Sas200622  * Note: ESRCH is a special case to handle a streams lookup failure.
9695331Samw  */
9705331Samw static struct {
9715772Sas200622 	int errnum;
9725772Sas200622 	int errcls;
9735772Sas200622 	int errcode;
9745772Sas200622 	DWORD status32;
9755772Sas200622 } smb_errno_map[] = {
9765331Samw 	{ ENOSPC,	ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL },
9775331Samw 	{ EDQUOT,	ERRDOS, ERROR_DISK_FULL, NT_STATUS_DISK_FULL },
9785331Samw 	{ EPERM,	ERRSRV, ERRaccess, NT_STATUS_ACCESS_DENIED },
9795331Samw 	{ ENOTDIR,	ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND },
9805331Samw 	{ EISDIR,	ERRDOS, ERRbadpath, NT_STATUS_FILE_IS_A_DIRECTORY },
9815331Samw 	{ ENOENT,	ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE },
9825331Samw 	{ ENOTEMPTY,	ERRDOS, ERROR_DIR_NOT_EMPTY,
9835331Samw 	    NT_STATUS_DIRECTORY_NOT_EMPTY },
9849231SAfshin.Ardakani@Sun.COM 	{ EILSEQ,	ERRDOS, ERROR_INVALID_NAME,
9859231SAfshin.Ardakani@Sun.COM 	    NT_STATUS_OBJECT_NAME_INVALID },
9865331Samw 	{ EACCES,	ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED },
9875331Samw 	{ ENOMEM,	ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY },
9885331Samw 	{ EIO,		ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR },
9895331Samw 	{ EXDEV, 	ERRSRV, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE },
99011963SAfshin.Ardakani@Sun.COM 	{ EREMOTE, 	ERRSRV, ERRbadpath, NT_STATUS_PATH_NOT_COVERED},
9915331Samw 	{ EROFS,	ERRHRD, ERRnowrite, NT_STATUS_ACCESS_DENIED },
9929231SAfshin.Ardakani@Sun.COM 	{ ESTALE,	ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE },
9939231SAfshin.Ardakani@Sun.COM 	{ EBADF,	ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE },
9949231SAfshin.Ardakani@Sun.COM 	{ EEXIST,	ERRDOS, ERRfilexists, NT_STATUS_OBJECT_NAME_COLLISION },
9959231SAfshin.Ardakani@Sun.COM 	{ ENXIO,	ERRSRV, ERRinvdevice, NT_STATUS_BAD_DEVICE_TYPE },
9965331Samw 	{ ESRCH,	ERRDOS, ERROR_FILE_NOT_FOUND,
9975331Samw 	    NT_STATUS_OBJECT_NAME_NOT_FOUND },
9985331Samw 	/*
9995331Samw 	 * It's not clear why smb_read_common effectively returns
10005331Samw 	 * ERRnoaccess if a range lock prevents access and smb_write_common
10015331Samw 	 * effectively returns ERRaccess.  This table entry is used by
10025331Samw 	 * smb_read_common and preserves the behavior that was there before.
10035331Samw 	 */
10045331Samw 	{ ERANGE,	ERRDOS, ERRnoaccess, NT_STATUS_FILE_LOCK_CONFLICT }
10055331Samw };
10065331Samw 
10075331Samw void
smbsr_map_errno(int errnum,smb_error_t * err)10085772Sas200622 smbsr_map_errno(int errnum, smb_error_t *err)
10095331Samw {
10105331Samw 	int i;
10115331Samw 
10125772Sas200622 	for (i = 0; i < sizeof (smb_errno_map)/sizeof (smb_errno_map[0]); ++i) {
10135772Sas200622 		if (smb_errno_map[i].errnum == errnum) {
10145772Sas200622 			err->status   = smb_errno_map[i].status32;
10155772Sas200622 			err->errcls   = smb_errno_map[i].errcls;
10165772Sas200622 			err->errcode  = smb_errno_map[i].errcode;
10175772Sas200622 			return;
10185331Samw 		}
10195331Samw 	}
10205331Samw 
10215772Sas200622 	err->status   = NT_STATUS_INTERNAL_ERROR;
10225772Sas200622 	err->errcls   = ERRDOS;
10235772Sas200622 	err->errcode  = ERROR_INTERNAL_ERROR;
10245331Samw }
10255331Samw 
10265331Samw void
smbsr_errno(struct smb_request * sr,int errnum)10275772Sas200622 smbsr_errno(struct smb_request *sr, int errnum)
10285772Sas200622 {
10296030Sjb150015 	smbsr_map_errno(errnum, &sr->smb_error);
10306030Sjb150015 	smbsr_set_error(sr, &sr->smb_error);
10315772Sas200622 }
10325772Sas200622 
10335772Sas200622 /*
103412508Samw@Sun.COM  * Report a request processing status (error or warning).
10355772Sas200622  */
10365772Sas200622 void
smbsr_status(smb_request_t * sr,DWORD status,uint16_t errcls,uint16_t errcode)103712508Samw@Sun.COM smbsr_status(smb_request_t *sr, DWORD status, uint16_t errcls, uint16_t errcode)
10385772Sas200622 {
10396030Sjb150015 	sr->smb_error.status   = status;
10406030Sjb150015 	sr->smb_error.errcls   = errcls;
10416030Sjb150015 	sr->smb_error.errcode  = errcode;
10425772Sas200622 
10436030Sjb150015 	smbsr_set_error(sr, &sr->smb_error);
10445772Sas200622 }
10455772Sas200622 
10465772Sas200622 /*
10475772Sas200622  * Setup a request processing error.  This function can be used to
10485772Sas200622  * report 32-bit status codes or DOS errors.  Set the status code
10495772Sas200622  * to 0 (NT_STATUS_SUCCESS) to explicitly report a DOS error,
10505772Sas200622  * regardless of the client capabilities.
10515772Sas200622  *
10525772Sas200622  * If status is non-zero and the client supports 32-bit status
10535772Sas200622  * codes, report the status.  Otherwise, report the DOS error.
10545772Sas200622  */
10555772Sas200622 void
smbsr_set_error(smb_request_t * sr,smb_error_t * err)10565772Sas200622 smbsr_set_error(smb_request_t *sr, smb_error_t *err)
10575772Sas200622 {
10585772Sas200622 	uint32_t status;
10595772Sas200622 	uint32_t capabilities;
10605772Sas200622 
10615772Sas200622 	ASSERT(sr);
10625772Sas200622 	ASSERT(err);
10635772Sas200622 
10645772Sas200622 	status = err->status;
10655772Sas200622 	capabilities = sr->session->capabilities;
10665772Sas200622 
10675772Sas200622 	if ((err->errcls == 0) && (err->errcode == 0)) {
10685772Sas200622 		capabilities |= CAP_STATUS32;
10695772Sas200622 		if (status == 0)
10705772Sas200622 			status = NT_STATUS_INTERNAL_ERROR;
10715772Sas200622 	}
10725772Sas200622 
10735772Sas200622 	if ((capabilities & CAP_STATUS32) && (status != 0)) {
10745772Sas200622 		sr->smb_rcls = status & 0xff;
10755772Sas200622 		sr->smb_reh = (status >> 8) & 0xff;
10765772Sas200622 		sr->smb_err  = status >> 16;
10775772Sas200622 		sr->smb_flg2 |= SMB_FLAGS2_NT_STATUS;
10785772Sas200622 	} else {
10795772Sas200622 		if ((err->errcls == 0) || (err->errcode == 0)) {
10805772Sas200622 			sr->smb_rcls = ERRSRV;
10815772Sas200622 			sr->smb_err  = ERRerror;
10825772Sas200622 		} else {
10835772Sas200622 			sr->smb_rcls = (uint8_t)err->errcls;
10845772Sas200622 			sr->smb_err  = (uint16_t)err->errcode;
10855331Samw 		}
10865331Samw 	}
10875331Samw }
10885331Samw 
10895331Samw smb_xa_t *
smbsr_lookup_xa(smb_request_t * sr)10905331Samw smbsr_lookup_xa(smb_request_t *sr)
10915331Samw {
10925331Samw 	ASSERT(sr->r_xa == 0);
10935331Samw 
10945331Samw 	sr->r_xa = smb_xa_find(sr->session, sr->smb_pid, sr->smb_mid);
10955331Samw 	return (sr->r_xa);
10965331Samw }
10975331Samw 
10985331Samw void
smbsr_release_file(smb_request_t * sr)109910504SKeyur.Desai@Sun.COM smbsr_release_file(smb_request_t *sr)
11005331Samw {
11015331Samw 	smb_ofile_t	*of = sr->fid_ofile;
11025331Samw 
11035331Samw 	sr->fid_ofile = NULL;
11045331Samw 	(void) smb_ofile_release(of);
11055331Samw }
11065331Samw 
11078934SJose.Borrego@Sun.COM void
smbsr_lookup_file(smb_request_t * sr)11088934SJose.Borrego@Sun.COM smbsr_lookup_file(smb_request_t *sr)
11098934SJose.Borrego@Sun.COM {
11108934SJose.Borrego@Sun.COM 	if (sr->fid_ofile == NULL)
11118934SJose.Borrego@Sun.COM 		sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree,
11128934SJose.Borrego@Sun.COM 		    sr->smb_fid);
11138934SJose.Borrego@Sun.COM }
11148934SJose.Borrego@Sun.COM 
11155331Samw static int
is_andx_com(unsigned char com)11165331Samw is_andx_com(unsigned char com)
11175331Samw {
11185331Samw 	switch (com) {
11195331Samw 	case SMB_COM_LOCKING_ANDX:
11205331Samw 	case SMB_COM_OPEN_ANDX:
11215331Samw 	case SMB_COM_READ_ANDX:
11225331Samw 	case SMB_COM_WRITE_ANDX:
11235331Samw 	case SMB_COM_SESSION_SETUP_ANDX:
11245331Samw 	case SMB_COM_LOGOFF_ANDX:
11255331Samw 	case SMB_COM_TREE_CONNECT_ANDX:
11265331Samw 	case SMB_COM_NT_CREATE_ANDX:
11275331Samw 		return (1);
11285331Samw 	}
11295331Samw 	return (0);
11305331Samw }
11315331Samw 
11325331Samw /*
11336139Sjb150015  * Invalid command stubs.
11346139Sjb150015  *
11356139Sjb150015  * SmbWriteComplete is sent to acknowledge completion of raw write requests.
11366139Sjb150015  * We never send raw write commands to other servers so, if we receive
11376139Sjb150015  * SmbWriteComplete, we treat it as an error.
11386139Sjb150015  *
11396139Sjb150015  * The Read/Write Block Multiplexed (mpx) protocol is used to maximize
11406139Sjb150015  * performance when reading/writing a large block of data: it can be
11416139Sjb150015  * used in parallel with other client/server operations.  The mpx sub-
11426139Sjb150015  * protocol is not supported because we support only connection oriented
11436139Sjb150015  * transports and NT supports mpx only over connectionless transports.
11445331Samw  */
11456030Sjb150015 smb_sdrc_t
smb_pre_invalid(smb_request_t * sr)11466139Sjb150015 smb_pre_invalid(smb_request_t *sr)
11476139Sjb150015 {
11486139Sjb150015 	DTRACE_SMB_1(op__Invalid__start, smb_request_t *, sr);
11496139Sjb150015 	return (SDRC_SUCCESS);
11506139Sjb150015 }
11516139Sjb150015 
11526139Sjb150015 void
smb_post_invalid(smb_request_t * sr)11536139Sjb150015 smb_post_invalid(smb_request_t *sr)
11546139Sjb150015 {
11556139Sjb150015 	DTRACE_SMB_1(op__Invalid__done, smb_request_t *, sr);
11566139Sjb150015 }
11576139Sjb150015 
11586139Sjb150015 smb_sdrc_t
smb_com_invalid(smb_request_t * sr)11596139Sjb150015 smb_com_invalid(smb_request_t *sr)
11605331Samw {
11616139Sjb150015 	smb_sdrc_t sdrc;
11626139Sjb150015 
11636139Sjb150015 	switch (sr->smb_com) {
11646139Sjb150015 	case SMB_COM_WRITE_COMPLETE:
11656139Sjb150015 		smbsr_error(sr, 0, ERRSRV, ERRerror);
11666139Sjb150015 		sdrc = SDRC_ERROR;
11676139Sjb150015 		break;
11686139Sjb150015 
11696139Sjb150015 	default:
11706139Sjb150015 		smbsr_error(sr, NT_STATUS_NOT_IMPLEMENTED,
11716139Sjb150015 		    ERRDOS, ERROR_INVALID_FUNCTION);
11726139Sjb150015 		sdrc = SDRC_NOT_IMPLEMENTED;
11736139Sjb150015 		break;
11746139Sjb150015 	}
11756139Sjb150015 
11766139Sjb150015 	return (sdrc);
11775331Samw }
11785331Samw 
11795331Samw /*
118012508Samw@Sun.COM  * smb_dispatch_stats_init
11815331Samw  *
118212508Samw@Sun.COM  * Initializes dispatch statistics.
11835331Samw  */
11845331Samw void
smb_dispatch_stats_init(smb_kstat_req_t * ksr)118512508Samw@Sun.COM smb_dispatch_stats_init(smb_kstat_req_t *ksr)
11865331Samw {
1187*12890SJoyce.McIntosh@Sun.COM 	kstat_named_t	*ksn;
1188*12890SJoyce.McIntosh@Sun.COM 	int		ks_ndata;
1189*12890SJoyce.McIntosh@Sun.COM 	int		i;
11905331Samw 
119112508Samw@Sun.COM 	for (i = 0; i < SMB_COM_NUM; i++, ksr++) {
119212508Samw@Sun.COM 		smb_latency_init(&smb_disp_table[i].sdt_lat);
119312508Samw@Sun.COM 		(void) strlcpy(ksr->kr_name, smb_disp_table[i].sdt_name,
119412508Samw@Sun.COM 		    sizeof (ksr->kr_name));
11955331Samw 	}
1196*12890SJoyce.McIntosh@Sun.COM 	/* Legacy Statistics */
1197*12890SJoyce.McIntosh@Sun.COM 	for (i = 0, ks_ndata = 0; i < SMB_COM_NUM; i++) {
1198*12890SJoyce.McIntosh@Sun.COM 		if (smb_disp_table[i].sdt_function != smb_com_invalid)
1199*12890SJoyce.McIntosh@Sun.COM 			ks_ndata++;
1200*12890SJoyce.McIntosh@Sun.COM 	}
1201*12890SJoyce.McIntosh@Sun.COM 
1202*12890SJoyce.McIntosh@Sun.COM 	smb_legacy_dispatch_ksp = kstat_create(SMBSRV_KSTAT_MODULE, 0,
1203*12890SJoyce.McIntosh@Sun.COM 	    SMBSRV_KSTAT_NAME_CMDS, SMBSRV_KSTAT_CLASS,
1204*12890SJoyce.McIntosh@Sun.COM 	    KSTAT_TYPE_NAMED, ks_ndata, 0);
1205*12890SJoyce.McIntosh@Sun.COM 
1206*12890SJoyce.McIntosh@Sun.COM 	if (smb_legacy_dispatch_ksp != NULL) {
1207*12890SJoyce.McIntosh@Sun.COM 		ksn = smb_legacy_dispatch_ksp->ks_data;
1208*12890SJoyce.McIntosh@Sun.COM 
1209*12890SJoyce.McIntosh@Sun.COM 		for (i = 0, ks_ndata = 0; i < SMB_COM_NUM; i++) {
1210*12890SJoyce.McIntosh@Sun.COM 			if (smb_disp_table[i].sdt_function != smb_com_invalid) {
1211*12890SJoyce.McIntosh@Sun.COM 				(void) strlcpy(ksn->name,
1212*12890SJoyce.McIntosh@Sun.COM 				    smb_disp_table[i].sdt_name,
1213*12890SJoyce.McIntosh@Sun.COM 				    sizeof (ksn->name));
1214*12890SJoyce.McIntosh@Sun.COM 				ksn->data_type = KSTAT_DATA_UINT64;
1215*12890SJoyce.McIntosh@Sun.COM 				++ksn;
1216*12890SJoyce.McIntosh@Sun.COM 			}
1217*12890SJoyce.McIntosh@Sun.COM 		}
1218*12890SJoyce.McIntosh@Sun.COM 		mutex_init(&smb_legacy_dispatch_ksmtx, NULL,
1219*12890SJoyce.McIntosh@Sun.COM 		    MUTEX_DEFAULT, NULL);
1220*12890SJoyce.McIntosh@Sun.COM 		smb_legacy_dispatch_ksp->ks_update =
1221*12890SJoyce.McIntosh@Sun.COM 		    smb_legacy_dispatch_stats_update;
1222*12890SJoyce.McIntosh@Sun.COM 		smb_legacy_dispatch_ksp->ks_lock = &smb_legacy_dispatch_ksmtx;
1223*12890SJoyce.McIntosh@Sun.COM 		kstat_install(smb_legacy_dispatch_ksp);
1224*12890SJoyce.McIntosh@Sun.COM 	}
12255331Samw }
12265331Samw 
12275331Samw /*
122812508Samw@Sun.COM  * smb_dispatch_stats_fini
12295331Samw  *
123012508Samw@Sun.COM  * Frees and destroyes the resources used for statistics.
12315331Samw  */
12325331Samw void
smb_dispatch_stats_fini(void)123312508Samw@Sun.COM smb_dispatch_stats_fini(void)
123412508Samw@Sun.COM {
123512508Samw@Sun.COM 	int	i;
123612508Samw@Sun.COM 
1237*12890SJoyce.McIntosh@Sun.COM 	if (smb_legacy_dispatch_ksp != NULL) {
1238*12890SJoyce.McIntosh@Sun.COM 		kstat_delete(smb_legacy_dispatch_ksp);
1239*12890SJoyce.McIntosh@Sun.COM 		mutex_destroy(&smb_legacy_dispatch_ksmtx);
1240*12890SJoyce.McIntosh@Sun.COM 		smb_legacy_dispatch_ksp = NULL;
1241*12890SJoyce.McIntosh@Sun.COM 	}
1242*12890SJoyce.McIntosh@Sun.COM 
124312508Samw@Sun.COM 	for (i = 0; i < SMB_COM_NUM; i++)
124412508Samw@Sun.COM 		smb_latency_destroy(&smb_disp_table[i].sdt_lat);
124512508Samw@Sun.COM }
124612508Samw@Sun.COM 
124712508Samw@Sun.COM void
smb_dispatch_stats_update(smb_kstat_req_t * ksr,int first,int nreq)124812508Samw@Sun.COM smb_dispatch_stats_update(smb_kstat_req_t *ksr, int first, int nreq)
12495331Samw {
125012508Samw@Sun.COM 	int	i;
125112508Samw@Sun.COM 	int	last;
125212508Samw@Sun.COM 
125312508Samw@Sun.COM 	last = first + nreq - 1;
125412508Samw@Sun.COM 
125512508Samw@Sun.COM 	if ((first < SMB_COM_NUM) && (last < SMB_COM_NUM))  {
125612508Samw@Sun.COM 		for (i = first; i <= last; i++, ksr++) {
125712508Samw@Sun.COM 			ksr->kr_rxb = smb_disp_table[i].sdt_rxb;
125812508Samw@Sun.COM 			ksr->kr_txb = smb_disp_table[i].sdt_txb;
125912508Samw@Sun.COM 			mutex_enter(&smb_disp_table[i].sdt_lat.ly_mutex);
126012508Samw@Sun.COM 			ksr->kr_nreq = smb_disp_table[i].sdt_lat.ly_a_nreq;
126112508Samw@Sun.COM 			ksr->kr_sum = smb_disp_table[i].sdt_lat.ly_a_sum;
126212508Samw@Sun.COM 			ksr->kr_a_mean = smb_disp_table[i].sdt_lat.ly_a_mean;
126312508Samw@Sun.COM 			ksr->kr_a_stddev =
126412508Samw@Sun.COM 			    smb_disp_table[i].sdt_lat.ly_a_stddev;
126512508Samw@Sun.COM 			ksr->kr_d_mean = smb_disp_table[i].sdt_lat.ly_d_mean;
126612508Samw@Sun.COM 			ksr->kr_d_stddev =
126712508Samw@Sun.COM 			    smb_disp_table[i].sdt_lat.ly_d_stddev;
126812508Samw@Sun.COM 			smb_disp_table[i].sdt_lat.ly_d_mean = 0;
126912508Samw@Sun.COM 			smb_disp_table[i].sdt_lat.ly_d_nreq = 0;
127012508Samw@Sun.COM 			smb_disp_table[i].sdt_lat.ly_d_stddev = 0;
127112508Samw@Sun.COM 			smb_disp_table[i].sdt_lat.ly_d_sum = 0;
127212508Samw@Sun.COM 			mutex_exit(&smb_disp_table[i].sdt_lat.ly_mutex);
127312508Samw@Sun.COM 		}
12745331Samw 	}
12755331Samw }
1276*12890SJoyce.McIntosh@Sun.COM 
1277*12890SJoyce.McIntosh@Sun.COM /*
1278*12890SJoyce.McIntosh@Sun.COM  * smb_legacy_dispatch_stats_update
1279*12890SJoyce.McIntosh@Sun.COM  *
1280*12890SJoyce.McIntosh@Sun.COM  * This callback function updates the smb_legacy_dispatch_kstat_data when kstat
1281*12890SJoyce.McIntosh@Sun.COM  * command is invoked.
1282*12890SJoyce.McIntosh@Sun.COM  */
1283*12890SJoyce.McIntosh@Sun.COM static int
smb_legacy_dispatch_stats_update(kstat_t * ksp,int rw)1284*12890SJoyce.McIntosh@Sun.COM smb_legacy_dispatch_stats_update(kstat_t *ksp, int rw)
1285*12890SJoyce.McIntosh@Sun.COM {
1286*12890SJoyce.McIntosh@Sun.COM 	kstat_named_t   *ksn;
1287*12890SJoyce.McIntosh@Sun.COM 	int		i;
1288*12890SJoyce.McIntosh@Sun.COM 
1289*12890SJoyce.McIntosh@Sun.COM 	ASSERT(MUTEX_HELD(ksp->ks_lock));
1290*12890SJoyce.McIntosh@Sun.COM 
1291*12890SJoyce.McIntosh@Sun.COM 	switch (rw) {
1292*12890SJoyce.McIntosh@Sun.COM 	case KSTAT_WRITE:
1293*12890SJoyce.McIntosh@Sun.COM 		return (EACCES);
1294*12890SJoyce.McIntosh@Sun.COM 
1295*12890SJoyce.McIntosh@Sun.COM 	case KSTAT_READ:
1296*12890SJoyce.McIntosh@Sun.COM 		ksn = ksp->ks_data;
1297*12890SJoyce.McIntosh@Sun.COM 		for (i = 0; i < SMB_COM_NUM; i++) {
1298*12890SJoyce.McIntosh@Sun.COM 			if (smb_disp_table[i].sdt_function != smb_com_invalid) {
1299*12890SJoyce.McIntosh@Sun.COM 				ksn->value.ui64 =
1300*12890SJoyce.McIntosh@Sun.COM 				    smb_disp_table[i].sdt_lat.ly_a_nreq;
1301*12890SJoyce.McIntosh@Sun.COM 				++ksn;
1302*12890SJoyce.McIntosh@Sun.COM 			}
1303*12890SJoyce.McIntosh@Sun.COM 		}
1304*12890SJoyce.McIntosh@Sun.COM 		return (0);
1305*12890SJoyce.McIntosh@Sun.COM 
1306*12890SJoyce.McIntosh@Sun.COM 	default:
1307*12890SJoyce.McIntosh@Sun.COM 		return (EIO);
1308*12890SJoyce.McIntosh@Sun.COM 	}
1309*12890SJoyce.McIntosh@Sun.COM }
1310