xref: /titanic_41/usr/src/cmd/mdb/common/modules/smbsrv/smbsrv.c (revision 7206bf49b1fe641544165ee97f63856da95e0868)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
2141610d10SYuri Pankov 
22da6c28aaSamw /*
23148c5f43SAlan Wright  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24*7206bf49SGordon Ross  * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25da6c28aaSamw  */
26da6c28aaSamw 
27148c5f43SAlan Wright #include <mdb/mdb_modapi.h>
28148c5f43SAlan Wright #include <mdb/mdb_ks.h>
29fc724630SAlan Wright #include <sys/thread.h>
30*7206bf49SGordon Ross #include <sys/taskq.h>
31da6c28aaSamw #include <smbsrv/smb_vops.h>
32da6c28aaSamw #include <smbsrv/smb.h>
33faa1795aSjb150015 #include <smbsrv/smb_ktypes.h>
34da6c28aaSamw 
35*7206bf49SGordon Ross #ifdef _KERNEL
36*7206bf49SGordon Ross #define	SMBSRV_OBJNAME	"smbsrv"
37*7206bf49SGordon Ross #else
38*7206bf49SGordon Ross #define	SMBSRV_OBJNAME	"libfksmbsrv.so.1"
39*7206bf49SGordon Ross #endif
40*7206bf49SGordon Ross 
416537f381Sas200622 #define	SMB_DCMD_INDENT		2
426537f381Sas200622 #define	ACE_TYPE_TABLEN		(ACE_ALL_TYPES + 1)
436537f381Sas200622 #define	ACE_TYPE_ENTRY(_v_)	{_v_, #_v_}
446537f381Sas200622 #define	SMB_COM_ENTRY(_v_, _x_)	{#_v_, _x_}
45da6c28aaSamw 
46148c5f43SAlan Wright #define	SMB_MDB_MAX_OPTS	9
476537f381Sas200622 
486537f381Sas200622 #define	SMB_OPT_SERVER		0x00000001
49148c5f43SAlan Wright #define	SMB_OPT_SESSION		0x00000002
50148c5f43SAlan Wright #define	SMB_OPT_REQUEST		0x00000004
51148c5f43SAlan Wright #define	SMB_OPT_USER		0x00000008
52148c5f43SAlan Wright #define	SMB_OPT_TREE		0x00000010
53148c5f43SAlan Wright #define	SMB_OPT_OFILE		0x00000020
54148c5f43SAlan Wright #define	SMB_OPT_ODIR		0x00000040
556537f381Sas200622 #define	SMB_OPT_WALK		0x00000100
566537f381Sas200622 #define	SMB_OPT_VERBOSE		0x00000200
576537f381Sas200622 #define	SMB_OPT_ALL_OBJ		0x000000FF
58da6c28aaSamw 
59da6c28aaSamw /*
606537f381Sas200622  * Structure associating an ACE type to a string.
61da6c28aaSamw  */
626537f381Sas200622 typedef struct {
636537f381Sas200622 	uint8_t		ace_type_value;
646537f381Sas200622 	const char	*ace_type_sting;
656537f381Sas200622 } ace_type_entry_t;
66da6c28aaSamw 
67da6c28aaSamw /*
686537f381Sas200622  * Structure containing strings describing an SMB command.
69da6c28aaSamw  */
706537f381Sas200622 typedef struct {
716537f381Sas200622 	const char	*smb_com;
726537f381Sas200622 	const char	*smb_andx;
736537f381Sas200622 } smb_com_entry_t;
74da6c28aaSamw 
75da6c28aaSamw /*
766537f381Sas200622  * Structure describing an object to be expanded (displayed).
776537f381Sas200622  */
786537f381Sas200622 typedef struct {
796537f381Sas200622 	uint_t		ex_mask;
806537f381Sas200622 	size_t		ex_offset;
816537f381Sas200622 	const char	*ex_dcmd;
826537f381Sas200622 	const char	*ex_name;
836537f381Sas200622 } smb_exp_t;
846537f381Sas200622 
856537f381Sas200622 /*
866537f381Sas200622  * List of supported options. Ther order has the match the bits SMB_OPT_xxx.
876537f381Sas200622  */
88148c5f43SAlan Wright typedef struct smb_mdb_opts {
89148c5f43SAlan Wright 	char		*o_name;
90148c5f43SAlan Wright 	uint32_t	o_value;
91148c5f43SAlan Wright } smb_mdb_opts_t;
92148c5f43SAlan Wright 
93148c5f43SAlan Wright static smb_mdb_opts_t smb_opts[SMB_MDB_MAX_OPTS] =
946537f381Sas200622 {
95148c5f43SAlan Wright 	{ "-s", SMB_OPT_SERVER	},
96148c5f43SAlan Wright 	{ "-e", SMB_OPT_SESSION	},
97148c5f43SAlan Wright 	{ "-r", SMB_OPT_REQUEST	},
98148c5f43SAlan Wright 	{ "-u", SMB_OPT_USER	},
99148c5f43SAlan Wright 	{ "-t", SMB_OPT_TREE	},
100148c5f43SAlan Wright 	{ "-f", SMB_OPT_OFILE	},
101148c5f43SAlan Wright 	{ "-d", SMB_OPT_ODIR	},
102148c5f43SAlan Wright 	{ "-w", SMB_OPT_WALK	},
103148c5f43SAlan Wright 	{ "-v", SMB_OPT_VERBOSE	}
1046537f381Sas200622 };
1056537f381Sas200622 
1066537f381Sas200622 static smb_com_entry_t	smb_com[256] =
1076537f381Sas200622 {
1086537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CREATE_DIRECTORY, "No"),
1096537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_DELETE_DIRECTORY, "No"),
1106537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_OPEN, "No"),
1116537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CREATE, "No"),
1126537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CLOSE, "No"),
1136537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_FLUSH, "No"),
1146537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_DELETE, "No"),
1156537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_RENAME, "No"),
1166537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION, "No"),
1176537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_SET_INFORMATION, "No"),
1186537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_READ, "No"),
1196537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE, "No"),
1206537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_LOCK_BYTE_RANGE, "No"),
1216537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_UNLOCK_BYTE_RANGE, "No"),
1226537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CREATE_TEMPORARY, "No"),
1236537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CREATE_NEW, "No"),
1246537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CHECK_DIRECTORY, "No"),
1256537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_PROCESS_EXIT, "No"),
1266537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_SEEK, "No"),
1276537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_LOCK_AND_READ, "No"),
1286537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_AND_UNLOCK, "No"),
1296537f381Sas200622 	SMB_COM_ENTRY(0x15, "?"),
1306537f381Sas200622 	SMB_COM_ENTRY(0x16, "?"),
1316537f381Sas200622 	SMB_COM_ENTRY(0x17, "?"),
1326537f381Sas200622 	SMB_COM_ENTRY(0x18, "?"),
1336537f381Sas200622 	SMB_COM_ENTRY(0x19, "?"),
1346537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_READ_RAW, "No"),
1356537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_READ_MPX, "No"),
1366537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_READ_MPX_SECONDARY, "No"),
1376537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_RAW, "No"),
1386537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_MPX, "No"),
1396537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_MPX_SECONDARY, "No"),
1406537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_COMPLETE, "No"),
1416537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_QUERY_SERVER, "No"),
1426537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_SET_INFORMATION2, "No"),
1436537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION2, "No"),
1446537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_LOCKING_ANDX, "No"),
1456537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TRANSACTION, "No"),
1466537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TRANSACTION_SECONDARY, "No"),
1476537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_IOCTL, "No"),
1486537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_IOCTL_SECONDARY, "No"),
1496537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_COPY, "No"),
1506537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_MOVE, "No"),
1516537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_ECHO, "No"),
1526537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_AND_CLOSE, "No"),
1536537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_OPEN_ANDX, "No"),
1546537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_READ_ANDX, "No"),
1556537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_ANDX, "No"),
1566537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NEW_FILE_SIZE, "No"),
1576537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CLOSE_AND_TREE_DISC, "No"),
1586537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TRANSACTION2, "No"),
1596537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TRANSACTION2_SECONDARY, "No"),
1606537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_FIND_CLOSE2, "No"),
1616537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_FIND_NOTIFY_CLOSE, "No"),
1626537f381Sas200622 	SMB_COM_ENTRY(0x36, "?"),
1636537f381Sas200622 	SMB_COM_ENTRY(0x37, "?"),
1646537f381Sas200622 	SMB_COM_ENTRY(0x38, "?"),
1656537f381Sas200622 	SMB_COM_ENTRY(0x39, "?"),
1666537f381Sas200622 	SMB_COM_ENTRY(0x3A, "?"),
1676537f381Sas200622 	SMB_COM_ENTRY(0x3B, "?"),
1686537f381Sas200622 	SMB_COM_ENTRY(0x3C, "?"),
1696537f381Sas200622 	SMB_COM_ENTRY(0x3D, "?"),
1706537f381Sas200622 	SMB_COM_ENTRY(0x3E, "?"),
1716537f381Sas200622 	SMB_COM_ENTRY(0x3F, "?"),
1726537f381Sas200622 	SMB_COM_ENTRY(0x40, "?"),
1736537f381Sas200622 	SMB_COM_ENTRY(0x41, "?"),
1746537f381Sas200622 	SMB_COM_ENTRY(0x42, "?"),
1756537f381Sas200622 	SMB_COM_ENTRY(0x43, "?"),
1766537f381Sas200622 	SMB_COM_ENTRY(0x44, "?"),
1776537f381Sas200622 	SMB_COM_ENTRY(0x45, "?"),
1786537f381Sas200622 	SMB_COM_ENTRY(0x46, "?"),
1796537f381Sas200622 	SMB_COM_ENTRY(0x47, "?"),
1806537f381Sas200622 	SMB_COM_ENTRY(0x48, "?"),
1816537f381Sas200622 	SMB_COM_ENTRY(0x49, "?"),
1826537f381Sas200622 	SMB_COM_ENTRY(0x4A, "?"),
1836537f381Sas200622 	SMB_COM_ENTRY(0x4B, "?"),
1846537f381Sas200622 	SMB_COM_ENTRY(0x4C, "?"),
1856537f381Sas200622 	SMB_COM_ENTRY(0x4D, "?"),
1866537f381Sas200622 	SMB_COM_ENTRY(0x4E, "?"),
1876537f381Sas200622 	SMB_COM_ENTRY(0x4F, "?"),
1886537f381Sas200622 	SMB_COM_ENTRY(0x50, "?"),
1896537f381Sas200622 	SMB_COM_ENTRY(0x51, "?"),
1906537f381Sas200622 	SMB_COM_ENTRY(0x52, "?"),
1916537f381Sas200622 	SMB_COM_ENTRY(0x53, "?"),
1926537f381Sas200622 	SMB_COM_ENTRY(0x54, "?"),
1936537f381Sas200622 	SMB_COM_ENTRY(0x55, "?"),
1946537f381Sas200622 	SMB_COM_ENTRY(0x56, "?"),
1956537f381Sas200622 	SMB_COM_ENTRY(0x57, "?"),
1966537f381Sas200622 	SMB_COM_ENTRY(0x58, "?"),
1976537f381Sas200622 	SMB_COM_ENTRY(0x59, "?"),
1986537f381Sas200622 	SMB_COM_ENTRY(0x5A, "?"),
1996537f381Sas200622 	SMB_COM_ENTRY(0x5B, "?"),
2006537f381Sas200622 	SMB_COM_ENTRY(0x5C, "?"),
2016537f381Sas200622 	SMB_COM_ENTRY(0x5D, "?"),
2026537f381Sas200622 	SMB_COM_ENTRY(0x5E, "?"),
2036537f381Sas200622 	SMB_COM_ENTRY(0x5F, "?"),
2046537f381Sas200622 	SMB_COM_ENTRY(0x60, "?"),
2056537f381Sas200622 	SMB_COM_ENTRY(0x61, "?"),
2066537f381Sas200622 	SMB_COM_ENTRY(0x62, "?"),
2076537f381Sas200622 	SMB_COM_ENTRY(0x63, "?"),
2086537f381Sas200622 	SMB_COM_ENTRY(0x64, "?"),
2096537f381Sas200622 	SMB_COM_ENTRY(0x65, "?"),
2106537f381Sas200622 	SMB_COM_ENTRY(0x66, "?"),
2116537f381Sas200622 	SMB_COM_ENTRY(0x67, "?"),
2126537f381Sas200622 	SMB_COM_ENTRY(0x68, "?"),
2136537f381Sas200622 	SMB_COM_ENTRY(0x69, "?"),
2146537f381Sas200622 	SMB_COM_ENTRY(0x6A, "?"),
2156537f381Sas200622 	SMB_COM_ENTRY(0x6B, "?"),
2166537f381Sas200622 	SMB_COM_ENTRY(0x6C, "?"),
2176537f381Sas200622 	SMB_COM_ENTRY(0x6D, "?"),
2186537f381Sas200622 	SMB_COM_ENTRY(0x6E, "?"),
2196537f381Sas200622 	SMB_COM_ENTRY(0x6F, "?"),
2206537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TREE_CONNECT, "No"),
2216537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TREE_DISCONNECT, "No"),
2226537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NEGOTIATE, "No"),
2236537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_SESSION_SETUP_ANDX, "No"),
2246537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_LOGOFF_ANDX, "No"),
2256537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_TREE_CONNECT_ANDX, "No"),
2266537f381Sas200622 	SMB_COM_ENTRY(0x76, "?"),
2276537f381Sas200622 	SMB_COM_ENTRY(0x77, "?"),
2286537f381Sas200622 	SMB_COM_ENTRY(0x78, "?"),
2296537f381Sas200622 	SMB_COM_ENTRY(0x79, "?"),
2306537f381Sas200622 	SMB_COM_ENTRY(0x7A, "?"),
2316537f381Sas200622 	SMB_COM_ENTRY(0x7B, "?"),
2326537f381Sas200622 	SMB_COM_ENTRY(0x7C, "?"),
2336537f381Sas200622 	SMB_COM_ENTRY(0x7D, "?"),
2346537f381Sas200622 	SMB_COM_ENTRY(0x7E, "?"),
2356537f381Sas200622 	SMB_COM_ENTRY(0x7F, "?"),
2366537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION_DISK, "No"),
2376537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_SEARCH, "No"),
2386537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_FIND, "No"),
2396537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_FIND_UNIQUE, "No"),
2406537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_FIND_CLOSE, "No"),
2416537f381Sas200622 	SMB_COM_ENTRY(0x85, "?"),
2426537f381Sas200622 	SMB_COM_ENTRY(0x86, "?"),
2436537f381Sas200622 	SMB_COM_ENTRY(0x87, "?"),
2446537f381Sas200622 	SMB_COM_ENTRY(0x88, "?"),
2456537f381Sas200622 	SMB_COM_ENTRY(0x89, "?"),
2466537f381Sas200622 	SMB_COM_ENTRY(0x8A, "?"),
2476537f381Sas200622 	SMB_COM_ENTRY(0x8B, "?"),
2486537f381Sas200622 	SMB_COM_ENTRY(0x8C, "?"),
2496537f381Sas200622 	SMB_COM_ENTRY(0x8D, "?"),
2506537f381Sas200622 	SMB_COM_ENTRY(0x8E, "?"),
2516537f381Sas200622 	SMB_COM_ENTRY(0x8F, "?"),
2526537f381Sas200622 	SMB_COM_ENTRY(0x90, "?"),
2536537f381Sas200622 	SMB_COM_ENTRY(0x91, "?"),
2546537f381Sas200622 	SMB_COM_ENTRY(0x92, "?"),
2556537f381Sas200622 	SMB_COM_ENTRY(0x93, "?"),
2566537f381Sas200622 	SMB_COM_ENTRY(0x94, "?"),
2576537f381Sas200622 	SMB_COM_ENTRY(0x95, "?"),
2586537f381Sas200622 	SMB_COM_ENTRY(0x96, "?"),
2596537f381Sas200622 	SMB_COM_ENTRY(0x97, "?"),
2606537f381Sas200622 	SMB_COM_ENTRY(0x98, "?"),
2616537f381Sas200622 	SMB_COM_ENTRY(0x99, "?"),
2626537f381Sas200622 	SMB_COM_ENTRY(0x9A, "?"),
2636537f381Sas200622 	SMB_COM_ENTRY(0x9B, "?"),
2646537f381Sas200622 	SMB_COM_ENTRY(0x9C, "?"),
2656537f381Sas200622 	SMB_COM_ENTRY(0x9D, "?"),
2666537f381Sas200622 	SMB_COM_ENTRY(0x9E, "?"),
2676537f381Sas200622 	SMB_COM_ENTRY(0x9F, "?"),
2686537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NT_TRANSACT, "No"),
2696537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NT_TRANSACT_SECONDARY, "No"),
2706537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NT_CREATE_ANDX, "No"),
271fc724630SAlan Wright 	SMB_COM_ENTRY(0xA3, "?"),
2726537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NT_CANCEL, "No"),
2736537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_NT_RENAME, "No"),
2746537f381Sas200622 	SMB_COM_ENTRY(0xA6, "?"),
2756537f381Sas200622 	SMB_COM_ENTRY(0xA7, "?"),
2766537f381Sas200622 	SMB_COM_ENTRY(0xA8, "?"),
2776537f381Sas200622 	SMB_COM_ENTRY(0xA9, "?"),
2786537f381Sas200622 	SMB_COM_ENTRY(0xAA, "?"),
2796537f381Sas200622 	SMB_COM_ENTRY(0xAB, "?"),
2806537f381Sas200622 	SMB_COM_ENTRY(0xAC, "?"),
2816537f381Sas200622 	SMB_COM_ENTRY(0xAD, "?"),
2826537f381Sas200622 	SMB_COM_ENTRY(0xAE, "?"),
2836537f381Sas200622 	SMB_COM_ENTRY(0xAF, "?"),
2846537f381Sas200622 	SMB_COM_ENTRY(0xB0, "?"),
2856537f381Sas200622 	SMB_COM_ENTRY(0xB1, "?"),
2866537f381Sas200622 	SMB_COM_ENTRY(0xB2, "?"),
2876537f381Sas200622 	SMB_COM_ENTRY(0xB3, "?"),
2886537f381Sas200622 	SMB_COM_ENTRY(0xB4, "?"),
2896537f381Sas200622 	SMB_COM_ENTRY(0xB5, "?"),
2906537f381Sas200622 	SMB_COM_ENTRY(0xB6, "?"),
2916537f381Sas200622 	SMB_COM_ENTRY(0xB7, "?"),
2926537f381Sas200622 	SMB_COM_ENTRY(0xB8, "?"),
2936537f381Sas200622 	SMB_COM_ENTRY(0xB9, "?"),
2946537f381Sas200622 	SMB_COM_ENTRY(0xBA, "?"),
2956537f381Sas200622 	SMB_COM_ENTRY(0xBB, "?"),
2966537f381Sas200622 	SMB_COM_ENTRY(0xBC, "?"),
2976537f381Sas200622 	SMB_COM_ENTRY(0xBD, "?"),
2986537f381Sas200622 	SMB_COM_ENTRY(0xBE, "?"),
2996537f381Sas200622 	SMB_COM_ENTRY(0xBF, "?"),
3006537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_OPEN_PRINT_FILE, "No"),
3016537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_PRINT_FILE, "No"),
3026537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_CLOSE_PRINT_FILE, "No"),
3036537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_GET_PRINT_QUEUE, "No"),
3046537f381Sas200622 	SMB_COM_ENTRY(0xC4, "?"),
3056537f381Sas200622 	SMB_COM_ENTRY(0xC5, "?"),
3066537f381Sas200622 	SMB_COM_ENTRY(0xC6, "?"),
3076537f381Sas200622 	SMB_COM_ENTRY(0xC7, "?"),
3086537f381Sas200622 	SMB_COM_ENTRY(0xC8, "?"),
3096537f381Sas200622 	SMB_COM_ENTRY(0xC9, "?"),
3106537f381Sas200622 	SMB_COM_ENTRY(0xCA, "?"),
3116537f381Sas200622 	SMB_COM_ENTRY(0xCB, "?"),
3126537f381Sas200622 	SMB_COM_ENTRY(0xCC, "?"),
3136537f381Sas200622 	SMB_COM_ENTRY(0xCD, "?"),
3146537f381Sas200622 	SMB_COM_ENTRY(0xCE, "?"),
3156537f381Sas200622 	SMB_COM_ENTRY(0xCF, "?"),
3166537f381Sas200622 	SMB_COM_ENTRY(0xD0, "?"),
3176537f381Sas200622 	SMB_COM_ENTRY(0xD1, "?"),
3186537f381Sas200622 	SMB_COM_ENTRY(0xD2, "?"),
3196537f381Sas200622 	SMB_COM_ENTRY(0xD3, "?"),
3206537f381Sas200622 	SMB_COM_ENTRY(0xD4, "?"),
3216537f381Sas200622 	SMB_COM_ENTRY(0xD5, "?"),
3226537f381Sas200622 	SMB_COM_ENTRY(0xD6, "?"),
3236537f381Sas200622 	SMB_COM_ENTRY(0xD7, "?"),
3246537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_READ_BULK, "No"),
3256537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_BULK, "No"),
3266537f381Sas200622 	SMB_COM_ENTRY(SMB_COM_WRITE_BULK_DATA, "No"),
3276537f381Sas200622 	SMB_COM_ENTRY(0xDB, "?"),
3286537f381Sas200622 	SMB_COM_ENTRY(0xDC, "?"),
329fc724630SAlan Wright 	SMB_COM_ENTRY(0xDD, "?"),
3306537f381Sas200622 	SMB_COM_ENTRY(0xDE, "?"),
3316537f381Sas200622 	SMB_COM_ENTRY(0xDF, "?"),
3326537f381Sas200622 	SMB_COM_ENTRY(0xE0, "?"),
3336537f381Sas200622 	SMB_COM_ENTRY(0xE1, "?"),
3346537f381Sas200622 	SMB_COM_ENTRY(0xE2, "?"),
3356537f381Sas200622 	SMB_COM_ENTRY(0xE3, "?"),
3366537f381Sas200622 	SMB_COM_ENTRY(0xE4, "?"),
3376537f381Sas200622 	SMB_COM_ENTRY(0xE5, "?"),
3386537f381Sas200622 	SMB_COM_ENTRY(0xE6, "?"),
3396537f381Sas200622 	SMB_COM_ENTRY(0xE7, "?"),
3406537f381Sas200622 	SMB_COM_ENTRY(0xE8, "?"),
3416537f381Sas200622 	SMB_COM_ENTRY(0xE9, "?"),
3426537f381Sas200622 	SMB_COM_ENTRY(0xEA, "?"),
3436537f381Sas200622 	SMB_COM_ENTRY(0xEB, "?"),
3446537f381Sas200622 	SMB_COM_ENTRY(0xEC, "?"),
3456537f381Sas200622 	SMB_COM_ENTRY(0xED, "?"),
3466537f381Sas200622 	SMB_COM_ENTRY(0xEE, "?"),
3476537f381Sas200622 	SMB_COM_ENTRY(0xEF, "?"),
3486537f381Sas200622 	SMB_COM_ENTRY(0xF0, "?"),
3496537f381Sas200622 	SMB_COM_ENTRY(0xF1, "?"),
3506537f381Sas200622 	SMB_COM_ENTRY(0xF2, "?"),
3516537f381Sas200622 	SMB_COM_ENTRY(0xF3, "?"),
3526537f381Sas200622 	SMB_COM_ENTRY(0xF4, "?"),
3536537f381Sas200622 	SMB_COM_ENTRY(0xF5, "?"),
3546537f381Sas200622 	SMB_COM_ENTRY(0xF6, "?"),
3556537f381Sas200622 	SMB_COM_ENTRY(0xF7, "?"),
3566537f381Sas200622 	SMB_COM_ENTRY(0xF8, "?"),
3576537f381Sas200622 	SMB_COM_ENTRY(0xF9, "?"),
3586537f381Sas200622 	SMB_COM_ENTRY(0xFA, "?"),
3596537f381Sas200622 	SMB_COM_ENTRY(0xFB, "?"),
3606537f381Sas200622 	SMB_COM_ENTRY(0xFC, "?"),
3616537f381Sas200622 	SMB_COM_ENTRY(0xFD, "?"),
3626537f381Sas200622 	SMB_COM_ENTRY(0xFE, "?"),
3636537f381Sas200622 	SMB_COM_ENTRY(0xFF, "?")
3646537f381Sas200622 };
3656537f381Sas200622 
3666537f381Sas200622 static int smb_dcmd_list(uintptr_t, uint_t, int, const mdb_arg_t *);
3676537f381Sas200622 static void smb_dcmd_list_help(void);
3686537f381Sas200622 static int smb_dcmd_server(uintptr_t, uint_t, int, const mdb_arg_t *);
3696537f381Sas200622 static void smb_dcmd_session_help(void);
3706537f381Sas200622 static int smb_dcmd_session(uintptr_t, uint_t, int, const mdb_arg_t *);
3716537f381Sas200622 static int smb_dcmd_request(uintptr_t, uint_t, int, const mdb_arg_t *);
3726537f381Sas200622 static void smb_dcmd_user_help(void);
3736537f381Sas200622 static int smb_dcmd_user(uintptr_t, uint_t, int, const mdb_arg_t *);
3746537f381Sas200622 static void smb_dcmd_tree_help(void);
3756537f381Sas200622 static int smb_dcmd_tree(uintptr_t, uint_t, int, const mdb_arg_t *);
3766537f381Sas200622 static int smb_dcmd_odir(uintptr_t, uint_t, int, const mdb_arg_t *);
3776537f381Sas200622 static int smb_dcmd_ofile(uintptr_t, uint_t, int, const mdb_arg_t *);
3785a6c34e6SGordon Ross static int smb_dcmd_kshare(uintptr_t, uint_t, int, const mdb_arg_t *);
3795a6c34e6SGordon Ross static int smb_dcmd_vfs(uintptr_t, uint_t, int, const mdb_arg_t *);
380148c5f43SAlan Wright static int smb_vfs_walk_init(mdb_walk_state_t *);
381148c5f43SAlan Wright static int smb_vfs_walk_step(mdb_walk_state_t *);
3826537f381Sas200622 static void smb_node_help(void);
3835a6c34e6SGordon Ross static int smb_dcmd_node(uintptr_t, uint_t, int, const mdb_arg_t *);
3846537f381Sas200622 static int smb_node_walk_init(mdb_walk_state_t *);
3856537f381Sas200622 static int smb_node_walk_step(mdb_walk_state_t *);
3866537f381Sas200622 static int smb_lock(uintptr_t, uint_t, int, const mdb_arg_t *);
387cb174861Sjoyce mcintosh static int smb_oplock(uintptr_t, uint_t, int, const mdb_arg_t *);
388cb174861Sjoyce mcintosh static int smb_oplock_grant(uintptr_t, uint_t, int, const mdb_arg_t *);
3896537f381Sas200622 static int smb_ace(uintptr_t, uint_t, int, const mdb_arg_t *);
3906537f381Sas200622 static int smb_ace_walk_init(mdb_walk_state_t *);
3916537f381Sas200622 static int smb_ace_walk_step(mdb_walk_state_t *);
3926537f381Sas200622 static int smb_acl(uintptr_t, uint_t, int, const mdb_arg_t *);
3936537f381Sas200622 static int smb_sd(uintptr_t, uint_t, int, const mdb_arg_t *);
3946537f381Sas200622 static int smb_sid(uintptr_t, uint_t, int, const mdb_arg_t *);
3956537f381Sas200622 static int smb_sid_print(uintptr_t);
3966537f381Sas200622 static int smb_fssd(uintptr_t, uint_t, int, const mdb_arg_t *);
3976537f381Sas200622 static int smb_dcmd_getopt(uint_t *, int, const mdb_arg_t *);
3986537f381Sas200622 static int smb_dcmd_setopt(uint_t, int, mdb_arg_t *);
3996537f381Sas200622 static int smb_obj_expand(uintptr_t, uint_t, const smb_exp_t *, ulong_t);
4006537f381Sas200622 static int smb_obj_list(const char *, uint_t, uint_t);
401fc724630SAlan Wright static int smb_worker_findstack(uintptr_t);
402148c5f43SAlan Wright static int smb_stats(uintptr_t, uint_t, int, const mdb_arg_t *);
4036537f381Sas200622 
4046537f381Sas200622 /*
4056537f381Sas200622  * MDB module linkage information:
406da6c28aaSamw  *
4076537f381Sas200622  * We declare a list of structures describing our dcmds, a list of structures
4086537f381Sas200622  * describing our walkers and a function named _mdb_init to return a pointer
4096537f381Sas200622  * to our module information.
4106537f381Sas200622  */
4116537f381Sas200622 static const mdb_dcmd_t dcmds[] = {
4126537f381Sas200622 	{   "smblist",
4136537f381Sas200622 	    "[-seutfdwv]",
4146537f381Sas200622 	    "print tree of SMB objects",
4156537f381Sas200622 	    smb_dcmd_list,
4166537f381Sas200622 	    smb_dcmd_list_help },
4176537f381Sas200622 	{   "smbsrv",
4186537f381Sas200622 	    "[-seutfdwv]",
4196537f381Sas200622 	    "print smb_server information",
4206537f381Sas200622 	    smb_dcmd_server },
4215a6c34e6SGordon Ross 	{   "smbshares",
4225a6c34e6SGordon Ross 	    "[-v]",
4235a6c34e6SGordon Ross 	    "print smb_kshare_t information",
4245a6c34e6SGordon Ross 	    smb_dcmd_kshare },
4256537f381Sas200622 	{   "smbvfs",
4266537f381Sas200622 	    "[-v]",
4276537f381Sas200622 	    "print smb_vfs information",
4285a6c34e6SGordon Ross 	    smb_dcmd_vfs },
4296537f381Sas200622 	{   "smbnode",
4306537f381Sas200622 	    "?[-vps]",
4316537f381Sas200622 	    "print smb_node_t information",
4325a6c34e6SGordon Ross 	    smb_dcmd_node,
4336537f381Sas200622 	    smb_node_help },
4346537f381Sas200622 	{   "smbsess",
4356537f381Sas200622 	    "[-utfdwv]",
4366537f381Sas200622 	    "print smb_session_t information",
4376537f381Sas200622 	    smb_dcmd_session,
4386537f381Sas200622 	    smb_dcmd_session_help},
4396537f381Sas200622 	{   "smbreq",
4406537f381Sas200622 	    ":[-v]",
4416537f381Sas200622 	    "print smb_request_t information",
4426537f381Sas200622 	    smb_dcmd_request },
4436537f381Sas200622 	{   "smblock", ":[-v]",
4446537f381Sas200622 	    "print smb_lock_t information", smb_lock },
4456537f381Sas200622 	{   "smbuser",
4466537f381Sas200622 	    ":[-vdftq]",
4476537f381Sas200622 	    "print smb_user_t information",
4486537f381Sas200622 	    smb_dcmd_user,
4496537f381Sas200622 	    smb_dcmd_user_help },
4506537f381Sas200622 	{   "smbtree",
4516537f381Sas200622 	    ":[-vdf]",
4526537f381Sas200622 	    "print smb_tree_t information",
4536537f381Sas200622 	    smb_dcmd_tree,
4546537f381Sas200622 	    smb_dcmd_tree_help },
4556537f381Sas200622 	{   "smbodir",
4566537f381Sas200622 	    ":[-v]",
4576537f381Sas200622 	    "print smb_odir_t information",
4586537f381Sas200622 	    smb_dcmd_odir },
4596537f381Sas200622 	{   "smbofile",
4606537f381Sas200622 	    "[-v]",
461cb174861Sjoyce mcintosh 	    "print smb_file_t information",
4626537f381Sas200622 	    smb_dcmd_ofile },
463cb174861Sjoyce mcintosh 	{   "smboplock", NULL,
464cb174861Sjoyce mcintosh 	    "print smb_oplock_t information", smb_oplock },
465cb174861Sjoyce mcintosh 	{   "smboplockgrant", NULL,
466cb174861Sjoyce mcintosh 	    "print smb_oplock_grant_t information", smb_oplock_grant },
467148c5f43SAlan Wright 	{   "smbstat", NULL,
468148c5f43SAlan Wright 	    "print all smb dispatched requests statistics",
469148c5f43SAlan Wright 	    smb_stats },
4706537f381Sas200622 	{   "smbace", "[-v]",
4716537f381Sas200622 	    "print smb_ace_t information", smb_ace },
4726537f381Sas200622 	{   "smbacl", "[-v]",
4736537f381Sas200622 	    "print smb_acl_t information", smb_acl },
4746537f381Sas200622 	{   "smbsid", "[-v]",
4756537f381Sas200622 	    "print smb_sid_t information", smb_sid },
4766537f381Sas200622 	{   "smbsd", "[-v]",
4776537f381Sas200622 	    "print smb_sd_t information", smb_sd },
4786537f381Sas200622 	{   "smbfssd", "[-v]",
4796537f381Sas200622 	    "print smb_fssd_t information", smb_fssd },
4806537f381Sas200622 	{ NULL }
4816537f381Sas200622 };
4826537f381Sas200622 
4836537f381Sas200622 static const mdb_walker_t walkers[] = {
4846537f381Sas200622 	{   "smbnode_walker",
4856537f381Sas200622 	    "walk list of smb_node_t structures",
4866537f381Sas200622 	    smb_node_walk_init,
4876537f381Sas200622 	    smb_node_walk_step,
4886537f381Sas200622 	    NULL,
4896537f381Sas200622 	    NULL },
490148c5f43SAlan Wright 	{   "smbvfs_walker",
491148c5f43SAlan Wright 	    "walk list of smb_vfs_t structures",
492148c5f43SAlan Wright 	    smb_vfs_walk_init,
493148c5f43SAlan Wright 	    smb_vfs_walk_step,
494148c5f43SAlan Wright 	    NULL,
495148c5f43SAlan Wright 	    NULL },
4966537f381Sas200622 	{   "smbace_walker",
4976537f381Sas200622 	    "walk list of smb_ace_t structures",
4986537f381Sas200622 	    smb_ace_walk_init,
4996537f381Sas200622 	    smb_ace_walk_step,
5006537f381Sas200622 	    NULL,
5016537f381Sas200622 	    NULL },
5026537f381Sas200622 	{ NULL }
5036537f381Sas200622 };
5046537f381Sas200622 
5056537f381Sas200622 static const mdb_modinfo_t modinfo = {
5066537f381Sas200622 	MDB_API_VERSION, dcmds, walkers
5076537f381Sas200622 };
5086537f381Sas200622 
5096537f381Sas200622 const mdb_modinfo_t *
_mdb_init(void)5106537f381Sas200622 _mdb_init(void)
5116537f381Sas200622 {
5126537f381Sas200622 	return (&modinfo);
5136537f381Sas200622 }
5146537f381Sas200622 
5156537f381Sas200622 /*
5166537f381Sas200622  * *****************************************************************************
5176537f381Sas200622  * ****************************** Top level DCMD *******************************
5186537f381Sas200622  * *****************************************************************************
5196537f381Sas200622  */
5206537f381Sas200622 
5216537f381Sas200622 static void
smb_dcmd_list_help(void)5226537f381Sas200622 smb_dcmd_list_help(void)
5236537f381Sas200622 {
5246537f381Sas200622 	mdb_printf(
5256537f381Sas200622 	    "Displays the list of objects using an indented tree format.\n"
5266537f381Sas200622 	    "If no option is specified the entire tree is displayed\n\n");
5276537f381Sas200622 	(void) mdb_dec_indent(2);
5286537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
5296537f381Sas200622 	(void) mdb_inc_indent(2);
5306537f381Sas200622 	mdb_printf(
5316537f381Sas200622 	    "-v\tDisplay verbose information\n"
5326537f381Sas200622 	    "-s\tDisplay the list of servers\n"
5336537f381Sas200622 	    "-e\tDisplay the list of sessions\n"
5346537f381Sas200622 	    "-r\tDisplay the list of smb requests\n"
5356537f381Sas200622 	    "-u\tDisplay the list of users\n"
5366537f381Sas200622 	    "-t\tDisplay the list of trees\n"
5376537f381Sas200622 	    "-f\tDisplay the list of open files\n"
5386537f381Sas200622 	    "-d\tDisplay the list of open searches\n");
5396537f381Sas200622 }
5406537f381Sas200622 
5416537f381Sas200622 /*
5426537f381Sas200622  * ::smblist
5436537f381Sas200622  *
5446537f381Sas200622  * This function lists the objects specified on the command line. If no object
5456537f381Sas200622  * is specified the entire tree (server through ofile and odir) is displayed.
5466537f381Sas200622  *
547da6c28aaSamw  */
548da6c28aaSamw /*ARGSUSED*/
549da6c28aaSamw static int
smb_dcmd_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5506537f381Sas200622 smb_dcmd_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
551da6c28aaSamw {
5526537f381Sas200622 	GElf_Sym	sym;
5536537f381Sas200622 	uint_t		opts = 0;
5546537f381Sas200622 	int		new_argc;
5556537f381Sas200622 	mdb_arg_t	new_argv[SMB_MDB_MAX_OPTS];
5566537f381Sas200622 
5576537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
5586537f381Sas200622 		return (DCMD_USAGE);
5596537f381Sas200622 
5606537f381Sas200622 	if (!(opts & ~(SMB_OPT_WALK | SMB_OPT_VERBOSE)))
5616537f381Sas200622 		opts |= SMB_OPT_ALL_OBJ;
5626537f381Sas200622 
5636537f381Sas200622 	opts |= SMB_OPT_WALK;
5646537f381Sas200622 
5656537f381Sas200622 	new_argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, new_argv);
5666537f381Sas200622 
567*7206bf49SGordon Ross 	if (mdb_lookup_by_obj(SMBSRV_OBJNAME, "smb_servers", &sym) == -1) {
5686537f381Sas200622 		mdb_warn("failed to find symbol smb_servers");
5696537f381Sas200622 		return (DCMD_ERR);
5706537f381Sas200622 	}
5716537f381Sas200622 
572*7206bf49SGordon Ross 	addr = (uintptr_t)sym.st_value + OFFSETOF(smb_llist_t, ll_list);
5736537f381Sas200622 
574*7206bf49SGordon Ross 	if (mdb_pwalk_dcmd("list", "smbsrv", new_argc, new_argv, addr)) {
575*7206bf49SGordon Ross 		mdb_warn("cannot walk smb_server list");
5766537f381Sas200622 		return (DCMD_ERR);
577*7206bf49SGordon Ross 	}
5786537f381Sas200622 	return (DCMD_OK);
5796537f381Sas200622 }
5806537f381Sas200622 
5816537f381Sas200622 /*
5826537f381Sas200622  * *****************************************************************************
5836537f381Sas200622  * ***************************** smb_server_t **********************************
5846537f381Sas200622  * *****************************************************************************
5856537f381Sas200622  */
5866537f381Sas200622 
5876537f381Sas200622 static const char *smb_server_state[SMB_SERVER_STATE_SENTINEL] =
5886537f381Sas200622 {
5896537f381Sas200622 	"CREATED",
5906537f381Sas200622 	"CONFIGURED",
5916537f381Sas200622 	"RUNNING",
5929fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"STOPPING",
5936537f381Sas200622 	"DELETING"
5946537f381Sas200622 };
5956537f381Sas200622 
5966537f381Sas200622 /*
5976537f381Sas200622  * List of objects that can be expanded under a server structure.
5986537f381Sas200622  */
5996537f381Sas200622 static const smb_exp_t smb_server_exp[] =
6006537f381Sas200622 {
6016537f381Sas200622 	{ SMB_OPT_ALL_OBJ,
602*7206bf49SGordon Ross 	    OFFSETOF(smb_server_t, sv_nbt_daemon.ld_session_list.ll_list),
6036537f381Sas200622 	    "smbsess", "smb_session"},
6046537f381Sas200622 	{ SMB_OPT_ALL_OBJ,
605*7206bf49SGordon Ross 	    OFFSETOF(smb_server_t, sv_tcp_daemon.ld_session_list.ll_list),
6066537f381Sas200622 	    "smbsess", "smb_session"},
6076537f381Sas200622 	{ 0, 0, NULL, NULL }
6086537f381Sas200622 };
6096537f381Sas200622 
6106537f381Sas200622 /*
6116537f381Sas200622  * ::smbsrv
6126537f381Sas200622  *
6136537f381Sas200622  * smbsrv dcmd - Print out smb_server structures.
6146537f381Sas200622  */
6156537f381Sas200622 /*ARGSUSED*/
6166537f381Sas200622 static int
smb_dcmd_server(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)6176537f381Sas200622 smb_dcmd_server(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
6186537f381Sas200622 {
6196537f381Sas200622 	uint_t		opts;
6206537f381Sas200622 	ulong_t		indent = 0;
6216537f381Sas200622 
6226537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
6236537f381Sas200622 		return (DCMD_USAGE);
6246537f381Sas200622 
6256537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
6266537f381Sas200622 		return (smb_obj_list("smb_server", opts | SMB_OPT_SERVER,
6276537f381Sas200622 		    flags));
6286537f381Sas200622 
6296537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SERVER)) ||
6306537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
631faa1795aSjb150015 		smb_server_t	*sv;
6326537f381Sas200622 		const char	*state;
633da6c28aaSamw 
6346537f381Sas200622 		sv = mdb_alloc(sizeof (smb_server_t), UM_SLEEP | UM_GC);
6356537f381Sas200622 		if (mdb_vread(sv, sizeof (smb_server_t), addr) == -1) {
6366537f381Sas200622 			mdb_warn("failed to read smb_server at %p", addr);
637da6c28aaSamw 			return (DCMD_ERR);
638da6c28aaSamw 		}
639da6c28aaSamw 
6406537f381Sas200622 		indent = SMB_DCMD_INDENT;
6416537f381Sas200622 
6426537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
6436537f381Sas200622 			mdb_arg_t	argv;
6446537f381Sas200622 
6456537f381Sas200622 			argv.a_type = MDB_TYPE_STRING;
6466537f381Sas200622 			argv.a_un.a_str = "smb_server_t";
6476537f381Sas200622 			if (mdb_call_dcmd("print", addr, flags, 1, &argv))
648faa1795aSjb150015 				return (DCMD_ERR);
6496537f381Sas200622 		} else {
6506537f381Sas200622 			if (DCMD_HDRSPEC(flags))
6516537f381Sas200622 				mdb_printf(
6526537f381Sas200622 				    "%<b>%<u>%-?s% "
6536537f381Sas200622 				    "%-4s% "
6546537f381Sas200622 				    "%-32s% "
655148c5f43SAlan Wright 				    "%</u>%</b>\n",
656148c5f43SAlan Wright 				    "SERVER", "ZONE", "STATE");
6576537f381Sas200622 
6586537f381Sas200622 			if (sv->sv_state >= SMB_SERVER_STATE_SENTINEL)
6596537f381Sas200622 				state = "UNKNOWN";
6606537f381Sas200622 			else
6616537f381Sas200622 				state = smb_server_state[sv->sv_state];
6626537f381Sas200622 
663148c5f43SAlan Wright 			mdb_printf("%-?p %-4d %-32s \n",
664148c5f43SAlan Wright 			    addr, sv->sv_zid, state);
665faa1795aSjb150015 		}
6666537f381Sas200622 	}
6676537f381Sas200622 	if (smb_obj_expand(addr, opts, smb_server_exp, indent))
6686537f381Sas200622 		return (DCMD_ERR);
669faa1795aSjb150015 	return (DCMD_OK);
670faa1795aSjb150015 }
671faa1795aSjb150015 
6726537f381Sas200622 /*
6736537f381Sas200622  * *****************************************************************************
6746537f381Sas200622  * ***************************** smb_session_t *********************************
6756537f381Sas200622  * *****************************************************************************
6766537f381Sas200622  */
6776537f381Sas200622 
6786537f381Sas200622 static const char *smb_session_state[SMB_SESSION_STATE_SENTINEL] =
6796537f381Sas200622 {
6806537f381Sas200622 	"INITIALIZED",
6816537f381Sas200622 	"DISCONNECTED",
6826537f381Sas200622 	"CONNECTED",
6836537f381Sas200622 	"ESTABLISHED",
6846537f381Sas200622 	"NEGOTIATED",
6856537f381Sas200622 	"OPLOCK_BREAKING",
6866537f381Sas200622 	"TERMINATED"
6876537f381Sas200622 };
6886537f381Sas200622 
6896537f381Sas200622 /*
6906537f381Sas200622  * List of objects that can be expanded under a session structure.
6916537f381Sas200622  */
6926537f381Sas200622 static const smb_exp_t smb_session_exp[] =
6936537f381Sas200622 {
6946537f381Sas200622 	{ SMB_OPT_REQUEST,
695*7206bf49SGordon Ross 	    OFFSETOF(smb_session_t, s_req_list.sl_list),
6966537f381Sas200622 	    "smbreq", "smb_request"},
697d040dae9SThomas Keiser 	{ SMB_OPT_USER,
698*7206bf49SGordon Ross 	    OFFSETOF(smb_session_t, s_user_list.ll_list),
6996537f381Sas200622 	    "smbuser", "smb_user"},
700d040dae9SThomas Keiser 	{ SMB_OPT_TREE | SMB_OPT_OFILE | SMB_OPT_ODIR,
701*7206bf49SGordon Ross 	    OFFSETOF(smb_session_t, s_tree_list.ll_list),
702d040dae9SThomas Keiser 	    "smbtree", "smb_tree"},
7036537f381Sas200622 	{ 0, 0, NULL, NULL}
7046537f381Sas200622 };
7056537f381Sas200622 
706da6c28aaSamw static void
smb_dcmd_session_help(void)7076537f381Sas200622 smb_dcmd_session_help(void)
708da6c28aaSamw {
7096537f381Sas200622 	mdb_printf(
7106537f381Sas200622 	    "Display the contents of smb_session_t, with optional"
7116537f381Sas200622 	    " filtering.\n\n");
7126537f381Sas200622 	(void) mdb_dec_indent(2);
7136537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
7146537f381Sas200622 	(void) mdb_inc_indent(2);
7156537f381Sas200622 	mdb_printf(
7166537f381Sas200622 	    "-v\tDisplay verbose smb_session information\n"
7176537f381Sas200622 	    "-r\tDisplay the list of smb requests attached\n"
7186537f381Sas200622 	    "-u\tDisplay the list of users attached\n");
719da6c28aaSamw }
720da6c28aaSamw 
7216537f381Sas200622 /*
7226537f381Sas200622  * ::smbsess
7236537f381Sas200622  *
7246537f381Sas200622  * smbsess dcmd - Print out the smb_session structure.
7256537f381Sas200622  */
7266537f381Sas200622 static int
smb_dcmd_session(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)7276537f381Sas200622 smb_dcmd_session(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7286537f381Sas200622 {
7296537f381Sas200622 	uint_t		opts;
7306537f381Sas200622 	ulong_t		indent = 0;
7316537f381Sas200622 
7326537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
7336537f381Sas200622 		return (DCMD_USAGE);
7346537f381Sas200622 
7356537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
7366537f381Sas200622 		opts |= SMB_OPT_SESSION;
7376537f381Sas200622 		opts &= ~SMB_OPT_SERVER;
7386537f381Sas200622 		return (smb_obj_list("smb_session", opts, flags));
7396537f381Sas200622 	}
7406537f381Sas200622 
7416537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SESSION)) ||
7426537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
7436537f381Sas200622 		smb_session_t	*se;
7446537f381Sas200622 		const char	*state;
7456537f381Sas200622 
7466537f381Sas200622 		indent = SMB_DCMD_INDENT;
7476537f381Sas200622 
7486537f381Sas200622 		se = mdb_alloc(sizeof (*se), UM_SLEEP | UM_GC);
7496537f381Sas200622 		if (mdb_vread(se, sizeof (*se), addr) == -1) {
7506537f381Sas200622 			mdb_warn("failed to read smb_session at %p", addr);
7516537f381Sas200622 			return (DCMD_ERR);
7526537f381Sas200622 		}
7536537f381Sas200622 		if (se->s_state >= SMB_SESSION_STATE_SENTINEL)
7546537f381Sas200622 			state = "INVALID";
7556537f381Sas200622 		else
7566537f381Sas200622 			state = smb_session_state[se->s_state];
7576537f381Sas200622 
7586537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
7596537f381Sas200622 			mdb_printf("%<b>%<u>SMB session information "
7606537f381Sas200622 			    "(%p): %</u>%</b>\n", addr);
76141610d10SYuri Pankov 			switch (se->ipaddr.a_family) {
76241610d10SYuri Pankov 			case AF_INET:
76341610d10SYuri Pankov 				mdb_printf("Client IP address: %I\n",
76441610d10SYuri Pankov 				    se->ipaddr.a_ipv4);
76541610d10SYuri Pankov 				mdb_printf("Local IP Address: %I\n",
76641610d10SYuri Pankov 				    se->local_ipaddr.a_ipv4);
76741610d10SYuri Pankov 				break;
76841610d10SYuri Pankov 			case AF_INET6:
76941610d10SYuri Pankov 				mdb_printf("Client IP address: %N\n",
77041610d10SYuri Pankov 				    &(se->ipaddr.a_ipv6));
77141610d10SYuri Pankov 				mdb_printf("Local IP Address: %N\n",
77241610d10SYuri Pankov 				    &(se->local_ipaddr.a_ipv6));
77341610d10SYuri Pankov 				break;
77441610d10SYuri Pankov 			default:
77541610d10SYuri Pankov 				mdb_printf("Client IP address: unknown\n");
77641610d10SYuri Pankov 				mdb_printf("Local IP Address: unknown\n");
77741610d10SYuri Pankov 			}
7786537f381Sas200622 			mdb_printf("Session KID: %u\n", se->s_kid);
7796537f381Sas200622 			mdb_printf("Workstation Name: %s\n",
7806537f381Sas200622 			    se->workstation);
7816537f381Sas200622 			mdb_printf("Session state: %u (%s)\n", se->s_state,
7826537f381Sas200622 			    state);
7836537f381Sas200622 			mdb_printf("Number of Users: %u\n",
7846537f381Sas200622 			    se->s_user_list.ll_count);
7856537f381Sas200622 			mdb_printf("Number of Trees: %u\n", se->s_tree_cnt);
7866537f381Sas200622 			mdb_printf("Number of Files: %u\n", se->s_file_cnt);
7876537f381Sas200622 			mdb_printf("Number of Shares: %u\n", se->s_dir_cnt);
7886537f381Sas200622 			mdb_printf("Number of active Transact.: %u\n\n",
7896537f381Sas200622 			    se->s_xa_list.ll_count);
790da6c28aaSamw 		} else {
79141610d10SYuri Pankov 			char	cipaddr[INET6_ADDRSTRLEN];
79241610d10SYuri Pankov 			char	lipaddr[INET6_ADDRSTRLEN];
79341610d10SYuri Pankov 			int	ipaddrstrlen;
794fc724630SAlan Wright 
79541610d10SYuri Pankov 			switch (se->ipaddr.a_family) {
79641610d10SYuri Pankov 			case AF_INET:
79741610d10SYuri Pankov 				ipaddrstrlen = INET_ADDRSTRLEN;
79841610d10SYuri Pankov 				(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
79941610d10SYuri Pankov 				    "%I", se->ipaddr.a_ipv4);
80041610d10SYuri Pankov 				(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
80141610d10SYuri Pankov 				    "%I", se->local_ipaddr.a_ipv4);
80241610d10SYuri Pankov 				break;
80341610d10SYuri Pankov 			case AF_INET6:
80441610d10SYuri Pankov 				ipaddrstrlen = INET6_ADDRSTRLEN;
80541610d10SYuri Pankov 				(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
80641610d10SYuri Pankov 				    "%N", &(se->ipaddr.a_ipv6));
80741610d10SYuri Pankov 				(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
80841610d10SYuri Pankov 				    "%N", &(se->local_ipaddr.a_ipv6));
80941610d10SYuri Pankov 				break;
81041610d10SYuri Pankov 			default:
81141610d10SYuri Pankov 				ipaddrstrlen = INET_ADDRSTRLEN;
81241610d10SYuri Pankov 				(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
81341610d10SYuri Pankov 				    "unknown");
81441610d10SYuri Pankov 				(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
81541610d10SYuri Pankov 				    "unknown");
81641610d10SYuri Pankov 			}
81741610d10SYuri Pankov 
81841610d10SYuri Pankov 			if (DCMD_HDRSPEC(flags)) {
8196537f381Sas200622 				mdb_printf(
82041610d10SYuri Pankov 				    "%<b>%<u>%-?s %-*s %-*s %-16s%</u>%</b>\n",
82141610d10SYuri Pankov 				    "SESSION", ipaddrstrlen, "CLIENT_IP_ADDR",
82241610d10SYuri Pankov 				    ipaddrstrlen, "LOCAL_IP_ADDR", "STATE");
82341610d10SYuri Pankov 			}
82441610d10SYuri Pankov 			mdb_printf("%-?p %-*s %-*s %s\n", addr, ipaddrstrlen,
82541610d10SYuri Pankov 			    cipaddr, ipaddrstrlen, lipaddr, state);
826da6c28aaSamw 		}
827da6c28aaSamw 	}
8286537f381Sas200622 	if (smb_obj_expand(addr, opts, smb_session_exp, indent))
8296537f381Sas200622 		return (DCMD_ERR);
8306537f381Sas200622 	return (DCMD_OK);
831da6c28aaSamw }
832da6c28aaSamw 
8336537f381Sas200622 /*
8346537f381Sas200622  * *****************************************************************************
8356537f381Sas200622  * **************************** smb_request_t **********************************
8366537f381Sas200622  * *****************************************************************************
8376537f381Sas200622  */
8386537f381Sas200622 
8396537f381Sas200622 static const char *smb_request_state[SMB_REQ_STATE_SENTINEL] =
8406537f381Sas200622 {
8416537f381Sas200622 	"FREE",
8426537f381Sas200622 	"INITIALIZING",
8436537f381Sas200622 	"SUBMITTED",
8446537f381Sas200622 	"ACTIVE",
8456537f381Sas200622 	"WAITING_EVENT",
8466537f381Sas200622 	"EVENT_OCCURRED",
8476537f381Sas200622 	"WAITING_LOCK",
8486537f381Sas200622 	"COMPLETED",
8496537f381Sas200622 	"CANCELED",
8506537f381Sas200622 	"CLEANED_UP"
8516537f381Sas200622 };
8526537f381Sas200622 
853148c5f43SAlan Wright #define	SMB_REQUEST_BANNER	\
854148c5f43SAlan Wright 	"%<b>%<u>%-?s %-?s %-14s %-14s %-16s %-32s%</u>%</b>\n"
855148c5f43SAlan Wright #define	SMB_REQUEST_FORMAT	\
856cb174861Sjoyce mcintosh 	"%-?p %-?p %-14lld %-14lld %-16s %s\n"
857148c5f43SAlan Wright 
8586537f381Sas200622 static int
smb_dcmd_request(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)8596537f381Sas200622 smb_dcmd_request(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
8606537f381Sas200622 {
8616537f381Sas200622 	uint_t		opts;
8626537f381Sas200622 
8636537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
8646537f381Sas200622 		return (DCMD_USAGE);
8656537f381Sas200622 
8666537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
8676537f381Sas200622 		opts |= SMB_OPT_REQUEST;
8686537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_USER);
8696537f381Sas200622 		return (smb_obj_list("smb_request", opts, flags));
8706537f381Sas200622 	}
8716537f381Sas200622 
8726537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_REQUEST)) ||
8736537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
8746537f381Sas200622 		smb_request_t	*sr;
8756537f381Sas200622 		const char	*state;
876148c5f43SAlan Wright 		uint64_t	waiting;
877148c5f43SAlan Wright 		uint64_t	running;
8786537f381Sas200622 
8796537f381Sas200622 		sr = mdb_alloc(sizeof (*sr), UM_SLEEP | UM_GC);
8806537f381Sas200622 		if (mdb_vread(sr, sizeof (*sr), addr) == -1) {
8816537f381Sas200622 			mdb_warn("failed to read smb_request at %p", addr);
8826537f381Sas200622 			return (DCMD_ERR);
8836537f381Sas200622 		}
884148c5f43SAlan Wright 		if (sr->sr_magic != SMB_REQ_MAGIC) {
885148c5f43SAlan Wright 			mdb_warn("not an smb_request_t (%p)>", addr);
886148c5f43SAlan Wright 			return (DCMD_ERR);
887148c5f43SAlan Wright 		}
888148c5f43SAlan Wright 		waiting = 0;
889148c5f43SAlan Wright 		running = 0;
890*7206bf49SGordon Ross 		/*
891*7206bf49SGordon Ross 		 * Note: mdb_gethrtime() is only available in kmdb
892*7206bf49SGordon Ross 		 */
893*7206bf49SGordon Ross #ifdef	_KERNEL
894148c5f43SAlan Wright 		if (sr->sr_time_submitted != 0) {
895148c5f43SAlan Wright 			if (sr->sr_time_active != 0) {
896148c5f43SAlan Wright 				waiting = sr->sr_time_active -
897148c5f43SAlan Wright 				    sr->sr_time_submitted;
898148c5f43SAlan Wright 				running = mdb_gethrtime() -
899148c5f43SAlan Wright 				    sr->sr_time_active;
900148c5f43SAlan Wright 			} else {
901148c5f43SAlan Wright 				waiting = mdb_gethrtime() -
902148c5f43SAlan Wright 				    sr->sr_time_submitted;
903148c5f43SAlan Wright 			}
904148c5f43SAlan Wright 		}
905148c5f43SAlan Wright 		waiting /= NANOSEC;
906148c5f43SAlan Wright 		running /= NANOSEC;
907*7206bf49SGordon Ross #endif	/* _KERNEL */
9086537f381Sas200622 
9096537f381Sas200622 		if (sr->sr_state >= SMB_REQ_STATE_SENTINEL)
9106537f381Sas200622 			state = "INVALID";
9116537f381Sas200622 		else
9126537f381Sas200622 			state = smb_request_state[sr->sr_state];
9136537f381Sas200622 
9146537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
9156537f381Sas200622 			mdb_printf(
916fc724630SAlan Wright 			    "%</b>%</u>SMB request information (%p):"
9176537f381Sas200622 			    "%</u>%</b>\n\n", addr);
918148c5f43SAlan Wright 
919148c5f43SAlan Wright 			mdb_printf(
920148c5f43SAlan Wright 			    "first SMB COM: %u (%s)\n"
921148c5f43SAlan Wright 			    "current SMB COM: %u (%s)\n"
922148c5f43SAlan Wright 			    "state: %u (%s)\n"
923148c5f43SAlan Wright 			    "TID(tree): %u (%p)\n"
924148c5f43SAlan Wright 			    "UID(user): %u (%p)\n"
925148c5f43SAlan Wright 			    "FID(file): %u (%p)\n"
926148c5f43SAlan Wright 			    "PID: %u\n"
927148c5f43SAlan Wright 			    "MID: %u\n\n"
928cb174861Sjoyce mcintosh 			    "waiting time: %lld\n"
929cb174861Sjoyce mcintosh 			    "running time: %lld\n",
930cb174861Sjoyce mcintosh 			    sr->first_smb_com,
931cb174861Sjoyce mcintosh 			    smb_com[sr->first_smb_com].smb_com,
932cb174861Sjoyce mcintosh 			    sr->smb_com,
933cb174861Sjoyce mcintosh 			    smb_com[sr->smb_com].smb_com,
934148c5f43SAlan Wright 			    sr->sr_state, state,
935148c5f43SAlan Wright 			    sr->smb_tid, sr->tid_tree,
936148c5f43SAlan Wright 			    sr->smb_uid, sr->uid_user,
937148c5f43SAlan Wright 			    sr->smb_fid, sr->fid_ofile,
938148c5f43SAlan Wright 			    sr->smb_pid,
939148c5f43SAlan Wright 			    sr->smb_mid,
940148c5f43SAlan Wright 			    waiting,
941148c5f43SAlan Wright 			    running);
942148c5f43SAlan Wright 
943fc724630SAlan Wright 			smb_worker_findstack((uintptr_t)sr->sr_worker);
9446537f381Sas200622 		} else {
9456537f381Sas200622 			if (DCMD_HDRSPEC(flags))
9466537f381Sas200622 				mdb_printf(
947148c5f43SAlan Wright 				    SMB_REQUEST_BANNER,
948148c5f43SAlan Wright 				    "ADDR",
949148c5f43SAlan Wright 				    "WORKER",
950148c5f43SAlan Wright 				    "WAITING(s)",
951148c5f43SAlan Wright 				    "RUNNING(s)",
952148c5f43SAlan Wright 				    "STATE",
953148c5f43SAlan Wright 				    "COMMAND");
9546537f381Sas200622 
955148c5f43SAlan Wright 			mdb_printf(SMB_REQUEST_FORMAT,
956148c5f43SAlan Wright 			    addr,
957148c5f43SAlan Wright 			    sr->sr_worker,
958148c5f43SAlan Wright 			    waiting,
959148c5f43SAlan Wright 			    running,
960148c5f43SAlan Wright 			    state,
961cb174861Sjoyce mcintosh 			    smb_com[sr->smb_com].smb_com);
9626537f381Sas200622 		}
9636537f381Sas200622 	}
9646537f381Sas200622 	return (DCMD_OK);
9656537f381Sas200622 }
9666537f381Sas200622 
9676537f381Sas200622 /*
9686537f381Sas200622  * *****************************************************************************
9696537f381Sas200622  * ****************************** smb_user_t ***********************************
9706537f381Sas200622  * *****************************************************************************
9716537f381Sas200622  */
9726537f381Sas200622 
9736537f381Sas200622 static const char *smb_user_state[SMB_USER_STATE_SENTINEL] =
9746537f381Sas200622 {
9756537f381Sas200622 	"LOGGED_IN",
9766537f381Sas200622 	"LOGGING_OFF",
9776537f381Sas200622 	"LOGGED_OFF"
9786537f381Sas200622 };
9796537f381Sas200622 
9806537f381Sas200622 static void
smb_dcmd_user_help(void)9816537f381Sas200622 smb_dcmd_user_help(void)
9826537f381Sas200622 {
9836537f381Sas200622 	mdb_printf(
9846537f381Sas200622 	    "Display the contents of smb_user_t, with optional filtering.\n\n");
9856537f381Sas200622 	(void) mdb_dec_indent(2);
9866537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
9876537f381Sas200622 	(void) mdb_inc_indent(2);
9886537f381Sas200622 	mdb_printf(
989d040dae9SThomas Keiser 	    "-v\tDisplay verbose smb_user information\n");
9906537f381Sas200622 }
9916537f381Sas200622 
9926537f381Sas200622 static int
smb_dcmd_user(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)9936537f381Sas200622 smb_dcmd_user(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
9946537f381Sas200622 {
9956537f381Sas200622 	uint_t		opts;
9966537f381Sas200622 
9976537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
9986537f381Sas200622 		return (DCMD_USAGE);
9996537f381Sas200622 
10006537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
10016537f381Sas200622 		opts |= SMB_OPT_USER;
10026537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST);
10036537f381Sas200622 		return (smb_obj_list("smb_user", opts, flags));
10046537f381Sas200622 	}
10056537f381Sas200622 
10066537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_USER)) ||
10076537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
10086537f381Sas200622 		smb_user_t	*user;
10096537f381Sas200622 		char		*account;
10106537f381Sas200622 
10116537f381Sas200622 		user = mdb_alloc(sizeof (*user), UM_SLEEP | UM_GC);
10126537f381Sas200622 		if (mdb_vread(user, sizeof (*user), addr) == -1) {
10136537f381Sas200622 			mdb_warn("failed to read smb_user at %p", addr);
10146537f381Sas200622 			return (DCMD_ERR);
10156537f381Sas200622 		}
10166537f381Sas200622 		account = mdb_zalloc(user->u_domain_len + user->u_name_len + 2,
10176537f381Sas200622 		    UM_SLEEP | UM_GC);
10186537f381Sas200622 
10196537f381Sas200622 		if (user->u_domain_len)
10206537f381Sas200622 			(void) mdb_vread(account, user->u_domain_len,
10216537f381Sas200622 			    (uintptr_t)user->u_domain);
10226537f381Sas200622 
10236537f381Sas200622 		strcat(account, "\\");
10246537f381Sas200622 
10256537f381Sas200622 		if (user->u_name_len)
10266537f381Sas200622 			(void) mdb_vread(account + strlen(account),
10276537f381Sas200622 			    user->u_name_len, (uintptr_t)user->u_name);
10286537f381Sas200622 
10296537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
10306537f381Sas200622 			const char	*state;
10316537f381Sas200622 
10326537f381Sas200622 			if (user->u_state >= SMB_USER_STATE_SENTINEL)
10336537f381Sas200622 				state = "INVALID";
10346537f381Sas200622 			else
10356537f381Sas200622 				state = smb_user_state[user->u_state];
10366537f381Sas200622 
10376537f381Sas200622 			mdb_printf("%<b>%<u>SMB user information (%p):"
10386537f381Sas200622 			    "%</u>%</b>\n", addr);
10396537f381Sas200622 			mdb_printf("UID: %u\n", user->u_uid);
10406537f381Sas200622 			mdb_printf("State: %d (%s)\n", user->u_state, state);
10416537f381Sas200622 			mdb_printf("Flags: 0x%08x\n", user->u_flags);
10426537f381Sas200622 			mdb_printf("Privileges: 0x%08x\n", user->u_privileges);
10436537f381Sas200622 			mdb_printf("Credential: %p\n", user->u_cred);
10446537f381Sas200622 			mdb_printf("Reference Count: %d\n", user->u_refcnt);
10456537f381Sas200622 			mdb_printf("User Account: %s\n\n", account);
10466537f381Sas200622 		} else {
10476537f381Sas200622 			if (DCMD_HDRSPEC(flags))
10486537f381Sas200622 				mdb_printf(
10496537f381Sas200622 				    "%<b>%<u>%?-s "
10506537f381Sas200622 				    "%-5s "
10516537f381Sas200622 				    "%-32s%</u>%</b>\n",
10526537f381Sas200622 				    "USER", "UID", "ACCOUNT");
10536537f381Sas200622 
10546537f381Sas200622 			mdb_printf("%-?p %-5u %-32s\n", addr, user->u_uid,
10556537f381Sas200622 			    account);
10566537f381Sas200622 		}
10576537f381Sas200622 	}
10586537f381Sas200622 	return (DCMD_OK);
10596537f381Sas200622 }
10606537f381Sas200622 
10616537f381Sas200622 /*
10626537f381Sas200622  * *****************************************************************************
10636537f381Sas200622  * ****************************** smb_tree_t ***********************************
10646537f381Sas200622  * *****************************************************************************
10656537f381Sas200622  */
10666537f381Sas200622 
10676537f381Sas200622 static const char *smb_tree_state[SMB_TREE_STATE_SENTINEL] =
10686537f381Sas200622 {
10696537f381Sas200622 	"CONNECTED",
10706537f381Sas200622 	"DISCONNECTING",
10716537f381Sas200622 	"DISCONNECTED"
10726537f381Sas200622 };
10736537f381Sas200622 
10746537f381Sas200622 /*
10756537f381Sas200622  * List of objects that can be expanded under a tree structure.
10766537f381Sas200622  */
10776537f381Sas200622 static const smb_exp_t smb_tree_exp[] =
10786537f381Sas200622 {
10796537f381Sas200622 	{ SMB_OPT_OFILE,
1080*7206bf49SGordon Ross 	    OFFSETOF(smb_tree_t, t_ofile_list.ll_list),
10816537f381Sas200622 	    "smbofile", "smb_ofile"},
10826537f381Sas200622 	{ SMB_OPT_ODIR,
1083*7206bf49SGordon Ross 	    OFFSETOF(smb_tree_t, t_odir_list.ll_list),
10846537f381Sas200622 	    "smbodir", "smb_odir"},
10856537f381Sas200622 	{ 0, 0, NULL, NULL}
10866537f381Sas200622 };
10876537f381Sas200622 
10886537f381Sas200622 static void
smb_dcmd_tree_help(void)10896537f381Sas200622 smb_dcmd_tree_help(void)
10906537f381Sas200622 {
10916537f381Sas200622 	mdb_printf(
10926537f381Sas200622 	    "Display the contents of smb_tree_t, with optional filtering.\n\n");
10936537f381Sas200622 	(void) mdb_dec_indent(2);
10946537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
10956537f381Sas200622 	(void) mdb_inc_indent(2);
10966537f381Sas200622 	mdb_printf(
10976537f381Sas200622 	    "-v\tDisplay verbose smb_tree information\n"
10986537f381Sas200622 	    "-d\tDisplay the list of smb_odirs attached\n"
10996537f381Sas200622 	    "-f\tDisplay the list of smb_ofiles attached\n");
11006537f381Sas200622 }
11016537f381Sas200622 
11026537f381Sas200622 static int
smb_dcmd_tree(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)11036537f381Sas200622 smb_dcmd_tree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
11046537f381Sas200622 {
11056537f381Sas200622 	uint_t		opts;
11066537f381Sas200622 	ulong_t		indent = 0;
11076537f381Sas200622 
11086537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
11096537f381Sas200622 		return (DCMD_USAGE);
11106537f381Sas200622 
11116537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
11126537f381Sas200622 		opts |= SMB_OPT_TREE;
11136537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
11146537f381Sas200622 		    SMB_OPT_USER);
11156537f381Sas200622 		return (smb_obj_list("smb_tree", opts, flags));
11166537f381Sas200622 	}
11176537f381Sas200622 
11186537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_TREE)) ||
11196537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
11206537f381Sas200622 		smb_tree_t	*tree;
11216537f381Sas200622 
11226537f381Sas200622 		indent = SMB_DCMD_INDENT;
11236537f381Sas200622 
11246537f381Sas200622 		tree = mdb_alloc(sizeof (*tree), UM_SLEEP | UM_GC);
11256537f381Sas200622 		if (mdb_vread(tree, sizeof (*tree), addr) == -1) {
11266537f381Sas200622 			mdb_warn("failed to read smb_tree at %p", addr);
11276537f381Sas200622 			return (DCMD_ERR);
11286537f381Sas200622 		}
11296537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
11306537f381Sas200622 			const char	*state;
11316537f381Sas200622 
11326537f381Sas200622 			if (tree->t_state >= SMB_TREE_STATE_SENTINEL)
11336537f381Sas200622 				state = "INVALID";
11346537f381Sas200622 			else
11356537f381Sas200622 				state = smb_tree_state[tree->t_state];
11366537f381Sas200622 
11376537f381Sas200622 			mdb_printf("%<b>%<u>SMB tree information (%p):"
11386537f381Sas200622 			    "%</u>%</b>\n\n", addr);
11396537f381Sas200622 			mdb_printf("TID: %04x\n", tree->t_tid);
11406537f381Sas200622 			mdb_printf("State: %d (%s)\n", tree->t_state, state);
1141c8ec8eeaSjose borrego 			mdb_printf("Share: %s\n", tree->t_sharename);
11426537f381Sas200622 			mdb_printf("Resource: %s\n", tree->t_resource);
1143c8ec8eeaSjose borrego 			mdb_printf("Type: %s\n", tree->t_typename);
1144c8ec8eeaSjose borrego 			mdb_printf("Volume: %s\n", tree->t_volume);
11456537f381Sas200622 			mdb_printf("Umask: %04x\n", tree->t_umask);
11466537f381Sas200622 			mdb_printf("Flags: %08x\n", tree->t_flags);
11476537f381Sas200622 			mdb_printf("SMB Node: %llx\n", tree->t_snode);
11486537f381Sas200622 			mdb_printf("Reference Count: %d\n\n", tree->t_refcnt);
11496537f381Sas200622 		} else {
11506537f381Sas200622 			if (DCMD_HDRSPEC(flags))
11516537f381Sas200622 				mdb_printf(
11526537f381Sas200622 				    "%<b>%<u>%-?s %-5s %-16s %-32s%</u>%</b>\n",
11536537f381Sas200622 				    "TREE", "TID", "SHARE NAME", "RESOURCE");
11546537f381Sas200622 
11556537f381Sas200622 			mdb_printf("%-?p %-5u %-16s %-32s\n", addr,
11566537f381Sas200622 			    tree->t_tid, tree->t_sharename, tree->t_resource);
11576537f381Sas200622 		}
11586537f381Sas200622 	}
11596537f381Sas200622 	if (smb_obj_expand(addr, opts, smb_tree_exp, indent))
11606537f381Sas200622 		return (DCMD_ERR);
11616537f381Sas200622 	return (DCMD_OK);
11626537f381Sas200622 }
11636537f381Sas200622 
11646537f381Sas200622 /*
11656537f381Sas200622  * *****************************************************************************
11666537f381Sas200622  * ****************************** smb_odir_t ***********************************
11676537f381Sas200622  * *****************************************************************************
11686537f381Sas200622  */
11696537f381Sas200622 
11706537f381Sas200622 static const char *smb_odir_state[SMB_ODIR_STATE_SENTINEL] =
11716537f381Sas200622 {
11726537f381Sas200622 	"OPEN",
11739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"IN_USE",
11746537f381Sas200622 	"CLOSING",
11756537f381Sas200622 	"CLOSED"
11766537f381Sas200622 };
11776537f381Sas200622 
11786537f381Sas200622 static int
smb_dcmd_odir(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)11796537f381Sas200622 smb_dcmd_odir(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
11806537f381Sas200622 {
11816537f381Sas200622 	uint_t		opts;
11826537f381Sas200622 
11836537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
11846537f381Sas200622 		return (DCMD_USAGE);
11856537f381Sas200622 
11866537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
11876537f381Sas200622 		opts |= SMB_OPT_ODIR;
11886537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
11896537f381Sas200622 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_OFILE);
11906537f381Sas200622 		return (smb_obj_list("smb_odir", opts, flags));
11916537f381Sas200622 	}
11926537f381Sas200622 
11936537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_ODIR)) ||
11946537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
11956537f381Sas200622 		smb_odir_t	*od;
11966537f381Sas200622 
11976537f381Sas200622 		od = mdb_alloc(sizeof (*od), UM_SLEEP | UM_GC);
11986537f381Sas200622 		if (mdb_vread(od, sizeof (*od), addr) == -1) {
11996537f381Sas200622 			mdb_warn("failed to read smb_odir at %p", addr);
12006537f381Sas200622 			return (DCMD_ERR);
12016537f381Sas200622 		}
12026537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
12036537f381Sas200622 			const char	*state;
12046537f381Sas200622 
12056537f381Sas200622 			if (od->d_state >= SMB_ODIR_STATE_SENTINEL)
12066537f381Sas200622 				state = "INVALID";
12076537f381Sas200622 			else
12086537f381Sas200622 				state = smb_odir_state[od->d_state];
12096537f381Sas200622 
12106537f381Sas200622 			mdb_printf(
12116537f381Sas200622 			    "%<b>%<u>SMB odir information (%p):%</u>%</b>\n\n",
12126537f381Sas200622 			    addr);
12136537f381Sas200622 			mdb_printf("State: %d (%s)\n", od->d_state, state);
12147f667e74Sjose borrego 			mdb_printf("SID: %u\n", od->d_odid);
1215d040dae9SThomas Keiser 			mdb_printf("User: %p\n", od->d_user);
1216d040dae9SThomas Keiser 			mdb_printf("Tree: %p\n", od->d_tree);
12176537f381Sas200622 			mdb_printf("Reference Count: %d\n", od->d_refcnt);
12186537f381Sas200622 			mdb_printf("Pattern: %s\n", od->d_pattern);
12197f667e74Sjose borrego 			mdb_printf("SMB Node: %p\n\n", od->d_dnode);
12206537f381Sas200622 		} else {
12216537f381Sas200622 			if (DCMD_HDRSPEC(flags))
12226537f381Sas200622 				mdb_printf(
1223e3f2c991SKeyur Desai 				    "%<b>%<u>%-?s "
12246537f381Sas200622 				    "%-5s "
12256537f381Sas200622 				    "%-?s "
1226e3f2c991SKeyur Desai 				    "%-16s%</u>%</b>\n",
12276537f381Sas200622 				    "ODIR", "SID", "VNODE", "PATTERN");
12286537f381Sas200622 
1229e3f2c991SKeyur Desai 			mdb_printf("%?p %-5u %-16p %s\n",
12307f667e74Sjose borrego 			    addr, od->d_odid, od->d_dnode, od->d_pattern);
12316537f381Sas200622 		}
12326537f381Sas200622 	}
12336537f381Sas200622 	return (DCMD_OK);
12346537f381Sas200622 }
12356537f381Sas200622 
12366537f381Sas200622 /*
12376537f381Sas200622  * *****************************************************************************
12386537f381Sas200622  * ****************************** smb_ofile_t **********************************
12396537f381Sas200622  * *****************************************************************************
12406537f381Sas200622  */
12416537f381Sas200622 
12426537f381Sas200622 static const char *smb_ofile_state[SMB_OFILE_STATE_SENTINEL] =
12436537f381Sas200622 {
12446537f381Sas200622 	"OPEN",
12456537f381Sas200622 	"CLOSING",
12466537f381Sas200622 	"CLOSED"
12476537f381Sas200622 };
12486537f381Sas200622 
12496537f381Sas200622 static int
smb_dcmd_ofile(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)12506537f381Sas200622 smb_dcmd_ofile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
12516537f381Sas200622 {
12526537f381Sas200622 	uint_t		opts;
12536537f381Sas200622 
12546537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
12556537f381Sas200622 		return (DCMD_USAGE);
12566537f381Sas200622 
12576537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
12586537f381Sas200622 		opts |= SMB_OPT_OFILE;
12596537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
12606537f381Sas200622 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_ODIR);
12616537f381Sas200622 		return (smb_obj_list("smb_ofile", opts, flags));
12626537f381Sas200622 	}
12636537f381Sas200622 
12646537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_OFILE)) ||
12656537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
12666537f381Sas200622 		smb_ofile_t	*of;
12676537f381Sas200622 
12686537f381Sas200622 		of = mdb_alloc(sizeof (*of), UM_SLEEP | UM_GC);
12696537f381Sas200622 		if (mdb_vread(of, sizeof (*of), addr) == -1) {
12706537f381Sas200622 			mdb_warn("failed to read smb_ofile at %p", addr);
12716537f381Sas200622 			return (DCMD_ERR);
12726537f381Sas200622 		}
12736537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
12746537f381Sas200622 			const char	*state;
12756537f381Sas200622 
12762c2d21e9SRichard Lowe 			if (of->f_state >= SMB_OFILE_STATE_SENTINEL)
12776537f381Sas200622 				state = "INVALID";
12786537f381Sas200622 			else
12796537f381Sas200622 				state = smb_ofile_state[of->f_state];
12806537f381Sas200622 
12816537f381Sas200622 			mdb_printf(
12826537f381Sas200622 			    "%<b>%<u>SMB ofile information (%p):%</u>%</b>\n\n",
12836537f381Sas200622 			    addr);
12846537f381Sas200622 			mdb_printf("FID: %u\n", of->f_fid);
12856537f381Sas200622 			mdb_printf("State: %d (%s)\n", of->f_state, state);
12866537f381Sas200622 			mdb_printf("SMB Node: %p\n", of->f_node);
12876537f381Sas200622 			mdb_printf("LLF Offset: 0x%llx (%s)\n",
12886537f381Sas200622 			    of->f_llf_pos,
12896537f381Sas200622 			    ((of->f_flags & SMB_OFLAGS_LLF_POS_VALID) ?
12906537f381Sas200622 			    "Valid" : "Invalid"));
12916537f381Sas200622 			mdb_printf("Flags: 0x%08x\n", of->f_flags);
1292d040dae9SThomas Keiser 			mdb_printf("User: %p\n", of->f_user);
1293d040dae9SThomas Keiser 			mdb_printf("Tree: %p\n", of->f_tree);
12946537f381Sas200622 			mdb_printf("Credential: %p\n\n", of->f_cr);
12956537f381Sas200622 		} else {
12966537f381Sas200622 			if (DCMD_HDRSPEC(flags))
12976537f381Sas200622 				mdb_printf(
12986537f381Sas200622 				    "%<b>%<u>%-?s "
12996537f381Sas200622 				    "%-5s "
13006537f381Sas200622 				    "%-?s "
13016537f381Sas200622 				    "%-?s%</u>%</b>\n",
13026537f381Sas200622 				    "OFILE", "FID", "SMB NODE", "CRED");
13036537f381Sas200622 
13046537f381Sas200622 			mdb_printf("%?p %-5u %-p %p\n", addr,
13056537f381Sas200622 			    of->f_fid, of->f_node, of->f_cr);
13066537f381Sas200622 		}
13076537f381Sas200622 	}
13086537f381Sas200622 	return (DCMD_OK);
13096537f381Sas200622 }
13106537f381Sas200622 
13116537f381Sas200622 /*
13126537f381Sas200622  * *****************************************************************************
13135a6c34e6SGordon Ross  * ******************************** smb_kshare_t *******************************
13145a6c34e6SGordon Ross  * *****************************************************************************
13155a6c34e6SGordon Ross  */
13165a6c34e6SGordon Ross 
13175a6c34e6SGordon Ross static int
smb_kshare_cb(uintptr_t addr,const void * data,void * arg)13185a6c34e6SGordon Ross smb_kshare_cb(uintptr_t addr, const void *data, void *arg)
13195a6c34e6SGordon Ross {
13205a6c34e6SGordon Ross 	uint_t *opts = arg;
13215a6c34e6SGordon Ross 	uintptr_t ta, sa;
13225a6c34e6SGordon Ross 	char name[32];
13235a6c34e6SGordon Ross 	char path[64];
13245a6c34e6SGordon Ross 	_NOTE(ARGUNUSED(data));
13255a6c34e6SGordon Ross 
13265a6c34e6SGordon Ross 	if (*opts & SMB_OPT_VERBOSE) {
13275a6c34e6SGordon Ross 		mdb_arg_t	argv;
13285a6c34e6SGordon Ross 
13295a6c34e6SGordon Ross 		argv.a_type = MDB_TYPE_STRING;
13305a6c34e6SGordon Ross 		argv.a_un.a_str = "smb_kshare_t";
13315a6c34e6SGordon Ross 		/* Don't fail the walk if this fails. */
13325a6c34e6SGordon Ross 		mdb_call_dcmd("print", addr, 0, 1, &argv);
13335a6c34e6SGordon Ross 	} else {
13345a6c34e6SGordon Ross 		/*
13355a6c34e6SGordon Ross 		 * Summary line for a kshare
13365a6c34e6SGordon Ross 		 * Don't fail the walk if any of these fail.
13375a6c34e6SGordon Ross 		 */
13385a6c34e6SGordon Ross 		ta = addr + OFFSETOF(smb_kshare_t, shr_name);
13395a6c34e6SGordon Ross 		if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
13405a6c34e6SGordon Ross 		    mdb_readstr(name, sizeof (name), sa) <= 0)
13415a6c34e6SGordon Ross 			strcpy(name, "?");
13425a6c34e6SGordon Ross 
13435a6c34e6SGordon Ross 		ta = addr + OFFSETOF(smb_kshare_t, shr_path);
13445a6c34e6SGordon Ross 		if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
13455a6c34e6SGordon Ross 		    mdb_readstr(path, sizeof (path), sa) <= 0)
13465a6c34e6SGordon Ross 			strcpy(path, "?");
13475a6c34e6SGordon Ross 
13485a6c34e6SGordon Ross 		mdb_printf("%-?p ", addr);	/* smb_kshare_t */
13495a6c34e6SGordon Ross 		mdb_printf("%-16s ", name);
13505a6c34e6SGordon Ross 		mdb_printf("%-s", path);
13515a6c34e6SGordon Ross 		mdb_printf("\n");
13525a6c34e6SGordon Ross 	}
13535a6c34e6SGordon Ross 
13545a6c34e6SGordon Ross 	return (WALK_NEXT);
13555a6c34e6SGordon Ross }
13565a6c34e6SGordon Ross 
13575a6c34e6SGordon Ross /*
13585a6c34e6SGordon Ross  * ::smbshares
13595a6c34e6SGordon Ross  *
13605a6c34e6SGordon Ross  * dcmd - Print out smb_kshare structures.
1361ae240eb8SGordon Ross  *	requires addr of an smb_server_t
13625a6c34e6SGordon Ross  */
13635a6c34e6SGordon Ross /*ARGSUSED*/
13645a6c34e6SGordon Ross static int
smb_dcmd_kshare(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)13655a6c34e6SGordon Ross smb_dcmd_kshare(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13665a6c34e6SGordon Ross {
13675a6c34e6SGordon Ross 	uint_t		opts = 0;
13685a6c34e6SGordon Ross 
13695a6c34e6SGordon Ross 	if (mdb_getopts(argc, argv,
13705a6c34e6SGordon Ross 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, &opts,
13715a6c34e6SGordon Ross 	    NULL) != argc)
13725a6c34e6SGordon Ross 		return (DCMD_USAGE);
13735a6c34e6SGordon Ross 
1374ae240eb8SGordon Ross 	if (!(flags & DCMD_ADDRSPEC))
1375ae240eb8SGordon Ross 		return (DCMD_USAGE);
1376ae240eb8SGordon Ross 	addr += OFFSETOF(smb_server_t, sv_export.e_share_avl.avl_tree);
13775a6c34e6SGordon Ross 
13785a6c34e6SGordon Ross 	if (DCMD_HDRSPEC(flags)) {
13795a6c34e6SGordon Ross 		mdb_printf(
13805a6c34e6SGordon Ross 		    "%<b>%<u>"
13815a6c34e6SGordon Ross 		    "%-?s "
13825a6c34e6SGordon Ross 		    "%-16s "
13835a6c34e6SGordon Ross 		    "%-s"
13845a6c34e6SGordon Ross 		    "%</u>%</b>\n",
13855a6c34e6SGordon Ross 		    "smb_kshare_t", "name", "path");
13865a6c34e6SGordon Ross 	}
13875a6c34e6SGordon Ross 
1388*7206bf49SGordon Ross 	if (mdb_pwalk("avl", smb_kshare_cb, &opts, addr) == -1) {
13895a6c34e6SGordon Ross 		mdb_warn("cannot walk smb_kshare avl");
13905a6c34e6SGordon Ross 		return (DCMD_ERR);
13915a6c34e6SGordon Ross 	}
13925a6c34e6SGordon Ross 
13935a6c34e6SGordon Ross 	return (DCMD_OK);
13945a6c34e6SGordon Ross }
13955a6c34e6SGordon Ross 
13965a6c34e6SGordon Ross /*
13975a6c34e6SGordon Ross  * *****************************************************************************
1398148c5f43SAlan Wright  * ******************************** smb_vfs_t **********************************
1399148c5f43SAlan Wright  * *****************************************************************************
1400148c5f43SAlan Wright  */
1401148c5f43SAlan Wright 
1402148c5f43SAlan Wright /*
1403148c5f43SAlan Wright  * ::smbvfs
1404148c5f43SAlan Wright  *
1405148c5f43SAlan Wright  * smbvfs dcmd - Prints out smb_vfs structures.
1406148c5f43SAlan Wright  */
1407148c5f43SAlan Wright /*ARGSUSED*/
1408148c5f43SAlan Wright static int
smb_dcmd_vfs(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)14095a6c34e6SGordon Ross smb_dcmd_vfs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1410148c5f43SAlan Wright {
1411148c5f43SAlan Wright 	int		verbose = FALSE;
1412148c5f43SAlan Wright 	smb_vfs_t	*sf;
1413148c5f43SAlan Wright 	vnode_t		*vn;
1414148c5f43SAlan Wright 	char		*path;
1415148c5f43SAlan Wright 
1416148c5f43SAlan Wright 	if (mdb_getopts(argc, argv,
1417148c5f43SAlan Wright 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1418148c5f43SAlan Wright 	    NULL) != argc)
1419148c5f43SAlan Wright 		return (DCMD_USAGE);
1420148c5f43SAlan Wright 
1421148c5f43SAlan Wright 	/*
1422148c5f43SAlan Wright 	 * If no smb_vfs address was specified on the command line, we can
1423148c5f43SAlan Wright 	 * print out all smb_vfs by invoking the smb_vfs walker, using
1424148c5f43SAlan Wright 	 * this dcmd itself as the callback.
1425148c5f43SAlan Wright 	 */
1426148c5f43SAlan Wright 	if (!(flags & DCMD_ADDRSPEC)) {
1427148c5f43SAlan Wright 		if (mdb_walk_dcmd("smbvfs_walker", "smbvfs",
1428148c5f43SAlan Wright 		    argc, argv) == -1) {
1429148c5f43SAlan Wright 			mdb_warn("failed to walk 'smb_vfs'");
1430148c5f43SAlan Wright 			return (DCMD_ERR);
1431148c5f43SAlan Wright 		}
1432148c5f43SAlan Wright 		return (DCMD_OK);
1433148c5f43SAlan Wright 	}
1434148c5f43SAlan Wright 
1435148c5f43SAlan Wright 	if (DCMD_HDRSPEC(flags)) {
1436148c5f43SAlan Wright 		mdb_printf(
1437148c5f43SAlan Wright 		    "%<b>%<u>"
1438148c5f43SAlan Wright 		    "%-?s "
1439148c5f43SAlan Wright 		    "%-10s "
1440148c5f43SAlan Wright 		    "%-16s "
1441148c5f43SAlan Wright 		    "%-16s"
1442148c5f43SAlan Wright 		    "%-s"
1443148c5f43SAlan Wright 		    "%</u>%</b>\n",
1444148c5f43SAlan Wright 		    "SMB_VFS", "REFCNT", "VFS", "VNODE", "ROOT");
1445148c5f43SAlan Wright 	}
1446148c5f43SAlan Wright 
1447148c5f43SAlan Wright 	sf = mdb_alloc(sizeof (*sf), UM_SLEEP | UM_GC);
1448148c5f43SAlan Wright 	if (mdb_vread(sf, sizeof (*sf), addr) == -1) {
1449148c5f43SAlan Wright 		mdb_warn("failed to read smb_vfs at %p", addr);
1450148c5f43SAlan Wright 		return (DCMD_ERR);
1451148c5f43SAlan Wright 	}
1452148c5f43SAlan Wright 
1453148c5f43SAlan Wright 	vn = mdb_alloc(sizeof (*vn), UM_SLEEP | UM_GC);
1454148c5f43SAlan Wright 	if (mdb_vread(vn, sizeof (*vn),
1455148c5f43SAlan Wright 	    (uintptr_t)sf->sv_rootvp) == -1) {
1456148c5f43SAlan Wright 		mdb_warn("failed to read vnode at %p", sf->sv_rootvp);
1457148c5f43SAlan Wright 		return (DCMD_ERR);
1458148c5f43SAlan Wright 	}
1459148c5f43SAlan Wright 
1460148c5f43SAlan Wright 	path = mdb_zalloc(MAXPATHLEN, UM_SLEEP | UM_GC);
1461148c5f43SAlan Wright 	(void) mdb_vread(path, MAXPATHLEN, (uintptr_t)vn->v_path);
1462148c5f43SAlan Wright 
1463148c5f43SAlan Wright 	mdb_printf(
1464148c5f43SAlan Wright 	    "%-?p %-10d %-?p %-?p %-s\n", addr, sf->sv_refcnt,
1465148c5f43SAlan Wright 	    sf->sv_vfsp, sf->sv_rootvp, path);
1466148c5f43SAlan Wright 
1467148c5f43SAlan Wright 	return (DCMD_OK);
1468148c5f43SAlan Wright }
1469148c5f43SAlan Wright 
1470148c5f43SAlan Wright /*
1471ae240eb8SGordon Ross  * Initialize the smb_vfs_t walker to point to the smb_export
1472ae240eb8SGordon Ross  * in the specified smb_server_t instance.  (no global walks)
1473148c5f43SAlan Wright  */
1474148c5f43SAlan Wright static int
smb_vfs_walk_init(mdb_walk_state_t * wsp)1475148c5f43SAlan Wright smb_vfs_walk_init(mdb_walk_state_t *wsp)
1476148c5f43SAlan Wright {
1477148c5f43SAlan Wright 
1478ae240eb8SGordon Ross 	if (wsp->walk_addr == NULL) {
1479ae240eb8SGordon Ross 		mdb_printf("require address of an smb_server_t\n");
1480148c5f43SAlan Wright 		return (WALK_ERR);
1481148c5f43SAlan Wright 	}
1482148c5f43SAlan Wright 
1483ae240eb8SGordon Ross 	wsp->walk_addr +=
1484ae240eb8SGordon Ross 	    OFFSETOF(smb_server_t, sv_export.e_vfs_list.ll_list);
1485148c5f43SAlan Wright 
1486148c5f43SAlan Wright 	if (mdb_layered_walk("list", wsp) == -1) {
1487148c5f43SAlan Wright 		mdb_warn("failed to walk list of VFS");
1488148c5f43SAlan Wright 		return (WALK_ERR);
1489148c5f43SAlan Wright 	}
1490148c5f43SAlan Wright 
1491148c5f43SAlan Wright 	return (WALK_NEXT);
1492148c5f43SAlan Wright }
1493148c5f43SAlan Wright 
1494148c5f43SAlan Wright static int
smb_vfs_walk_step(mdb_walk_state_t * wsp)1495148c5f43SAlan Wright smb_vfs_walk_step(mdb_walk_state_t *wsp)
1496148c5f43SAlan Wright {
1497148c5f43SAlan Wright 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1498148c5f43SAlan Wright 	    wsp->walk_cbdata));
1499148c5f43SAlan Wright }
1500148c5f43SAlan Wright 
1501148c5f43SAlan Wright /*
1502148c5f43SAlan Wright  * *****************************************************************************
15036537f381Sas200622  * ******************************* smb_node_t **********************************
15046537f381Sas200622  * *****************************************************************************
15056537f381Sas200622  */
15066537f381Sas200622 
1507da6c28aaSamw static void
smb_node_help(void)1508da6c28aaSamw smb_node_help(void)
1509da6c28aaSamw {
1510da6c28aaSamw 	mdb_printf(
1511da6c28aaSamw 	    "Display the contents of smb_node_t, with optional filtering.\n\n");
15126537f381Sas200622 	(void) mdb_dec_indent(2);
1513da6c28aaSamw 	mdb_printf("%<b>OPTIONS%</b>\n");
15146537f381Sas200622 	(void) mdb_inc_indent(2);
1515da6c28aaSamw 	mdb_printf(
1516da6c28aaSamw 	    "-v\tDisplay verbose smb_node information\n"
1517da6c28aaSamw 	    "-p\tDisplay the full path of the vnode associated\n"
1518da6c28aaSamw 	    "-s\tDisplay the stack of the last 16 calls that modified the "
1519da6c28aaSamw 	    "reference\n\tcount\n");
1520da6c28aaSamw }
1521da6c28aaSamw 
1522da6c28aaSamw /*
15236537f381Sas200622  * ::smbnode
1524da6c28aaSamw  *
1525da6c28aaSamw  * smb_node dcmd - Print out smb_node structure.
1526da6c28aaSamw  */
1527da6c28aaSamw static int
smb_dcmd_node(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)15285a6c34e6SGordon Ross smb_dcmd_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1529da6c28aaSamw {
1530da6c28aaSamw 	smb_node_t	node;
1531cb174861Sjoyce mcintosh 	int		rc;
1532da6c28aaSamw 	int		verbose = FALSE;
1533da6c28aaSamw 	int		print_full_path = FALSE;
1534da6c28aaSamw 	int		stack_trace = FALSE;
1535da6c28aaSamw 	vnode_t		vnode;
1536da6c28aaSamw 	char		od_name[MAXNAMELEN];
1537da6c28aaSamw 	char		path_name[1024];
1538cb174861Sjoyce mcintosh 	uintptr_t	list_addr, oplock_addr;
1539da6c28aaSamw 
1540da6c28aaSamw 	if (mdb_getopts(argc, argv,
1541da6c28aaSamw 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1542da6c28aaSamw 	    'p', MDB_OPT_SETBITS, TRUE, &print_full_path,
1543da6c28aaSamw 	    's', MDB_OPT_SETBITS, TRUE, &stack_trace,
1544da6c28aaSamw 	    NULL) != argc)
1545da6c28aaSamw 		return (DCMD_USAGE);
1546da6c28aaSamw 
1547da6c28aaSamw 	/*
1548da6c28aaSamw 	 * If no smb_node address was specified on the command line, we can
1549da6c28aaSamw 	 * print out all smb nodes by invoking the smb_node walker, using
1550da6c28aaSamw 	 * this dcmd itself as the callback.
1551da6c28aaSamw 	 */
1552da6c28aaSamw 	if (!(flags & DCMD_ADDRSPEC)) {
15536537f381Sas200622 		if (mdb_walk_dcmd("smbnode_walker", "smbnode",
1554da6c28aaSamw 		    argc, argv) == -1) {
1555da6c28aaSamw 			mdb_warn("failed to walk 'smb_node'");
1556da6c28aaSamw 			return (DCMD_ERR);
1557da6c28aaSamw 		}
1558da6c28aaSamw 		return (DCMD_OK);
1559da6c28aaSamw 	}
1560da6c28aaSamw 
1561da6c28aaSamw 	/*
1562da6c28aaSamw 	 * If this is the first invocation of the command, print a nice
1563da6c28aaSamw 	 * header line for the output that will follow.
1564da6c28aaSamw 	 */
1565da6c28aaSamw 	if (DCMD_HDRSPEC(flags)) {
15666537f381Sas200622 		if (verbose) {
15676537f381Sas200622 			mdb_printf("%<b>%<u>SMB node information:%</u>%</b>\n");
15686537f381Sas200622 		} else {
15696537f381Sas200622 			mdb_printf(
15706537f381Sas200622 			    "%<b>%<u>%-?s "
15716537f381Sas200622 			    "%-?s "
15726537f381Sas200622 			    "%-18s "
15736537f381Sas200622 			    "%-6s "
15746537f381Sas200622 			    "%-6s "
1575cb174861Sjoyce mcintosh 			    "%-8s "
15766537f381Sas200622 			    "%-6s%</u>%</b>\n",
15776537f381Sas200622 			    "ADDR", "VP", "NODE-NAME", "OFILES", "LOCKS",
1578cb174861Sjoyce mcintosh 			    "OPLOCK", "REF");
15796537f381Sas200622 		}
1580da6c28aaSamw 	}
1581da6c28aaSamw 
1582da6c28aaSamw 	/*
15836537f381Sas200622 	 * For each smb_node, we just need to read the smb_node_t struct, read
15846537f381Sas200622 	 * and then print out the following fields.
1585da6c28aaSamw 	 */
1586da6c28aaSamw 	if (mdb_vread(&node, sizeof (node), addr) == sizeof (node)) {
15876537f381Sas200622 		(void) mdb_snprintf(od_name, sizeof (od_name), "%s",
15886537f381Sas200622 		    node.od_name);
1589da6c28aaSamw 		if (print_full_path) {
1590da6c28aaSamw 			if (mdb_vread(&vnode, sizeof (vnode_t),
15916537f381Sas200622 			    (uintptr_t)node.vp) == sizeof (vnode_t)) {
15926537f381Sas200622 				if (mdb_readstr(path_name, sizeof (path_name),
1593da6c28aaSamw 				    (uintptr_t)vnode.v_path) != 0) {
1594da6c28aaSamw 					(void) mdb_snprintf(od_name,
15956537f381Sas200622 					    sizeof (od_name), "N/A");
1596da6c28aaSamw 				}
1597da6c28aaSamw 			}
1598da6c28aaSamw 		}
1599da6c28aaSamw 		if (verbose) {
16006537f381Sas200622 			mdb_printf("VP: %p\n", node.vp);
16016537f381Sas200622 			mdb_printf("Name: %s\n", od_name);
16026537f381Sas200622 			if (print_full_path)
16036537f381Sas200622 				mdb_printf("V-node Path: %s\n", path_name);
16046537f381Sas200622 			mdb_printf("Ofiles: %u\n", node.n_ofile_list.ll_count);
16056537f381Sas200622 			mdb_printf("Range Locks: %u\n",
1606da6c28aaSamw 			    node.n_lock_list.ll_count);
1607da6c28aaSamw 			if (node.n_lock_list.ll_count != 0) {
1608da6c28aaSamw 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1609da6c28aaSamw 				list_addr = addr +
1610*7206bf49SGordon Ross 				    OFFSETOF(smb_node_t, n_lock_list) +
1611*7206bf49SGordon Ross 				    OFFSETOF(smb_llist_t, ll_list);
16126537f381Sas200622 				if (mdb_pwalk_dcmd("list", "smblock", 0,
16136537f381Sas200622 				    NULL, list_addr)) {
1614da6c28aaSamw 					mdb_warn("failed to walk node's active"
1615da6c28aaSamw 					    " locks");
1616da6c28aaSamw 				}
1617da6c28aaSamw 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1618da6c28aaSamw 			}
1619cb174861Sjoyce mcintosh 			if (node.n_oplock.ol_count == 0) {
1620cb174861Sjoyce mcintosh 				mdb_printf("Opportunistic Locks: 0\n");
1621cb174861Sjoyce mcintosh 			} else {
1622cb174861Sjoyce mcintosh 				oplock_addr =
1623*7206bf49SGordon Ross 				    addr + OFFSETOF(smb_node_t, n_oplock);
1624cb174861Sjoyce mcintosh 				mdb_printf("Opportunistic Lock: %p\n",
1625cb174861Sjoyce mcintosh 				    oplock_addr);
1626cb174861Sjoyce mcintosh 				rc = mdb_call_dcmd("smboplock", oplock_addr,
1627cb174861Sjoyce mcintosh 				    flags, argc, argv);
1628cb174861Sjoyce mcintosh 				if (rc != DCMD_OK)
1629cb174861Sjoyce mcintosh 					return (rc);
1630cb174861Sjoyce mcintosh 			}
16316537f381Sas200622 			mdb_printf("Reference Count: %u\n\n", node.n_refcnt);
1632da6c28aaSamw 		} else {
1633cb174861Sjoyce mcintosh 			mdb_printf("%-?p %-?p %-18s %-6d %-6d %-8d %-6d ",
1634da6c28aaSamw 			    addr, node.vp, od_name, node.n_ofile_list.ll_count,
1635cb174861Sjoyce mcintosh 			    node.n_lock_list.ll_count,
1636cb174861Sjoyce mcintosh 			    node.n_oplock.ol_count, node.n_refcnt);
1637cb174861Sjoyce mcintosh 
16386537f381Sas200622 			if (print_full_path)
16396537f381Sas200622 				mdb_printf("\t%s\n", path_name);
1640da6c28aaSamw 		}
1641da6c28aaSamw 		if (stack_trace && node.n_audit_buf) {
1642da6c28aaSamw 			int ctr;
1643da6c28aaSamw 			smb_audit_buf_node_t *anb;
1644da6c28aaSamw 
1645da6c28aaSamw 			anb = mdb_alloc(sizeof (smb_audit_buf_node_t),
16466537f381Sas200622 			    UM_SLEEP | UM_GC);
1647da6c28aaSamw 
1648da6c28aaSamw 			if (mdb_vread(anb, sizeof (*anb),
1649da6c28aaSamw 			    (uintptr_t)node.n_audit_buf) != sizeof (*anb)) {
1650da6c28aaSamw 				mdb_warn("failed to read audit buffer");
1651da6c28aaSamw 				return (DCMD_ERR);
1652da6c28aaSamw 			}
1653da6c28aaSamw 			ctr = anb->anb_max_index + 1;
1654da6c28aaSamw 			anb->anb_index--;
1655da6c28aaSamw 			anb->anb_index &= anb->anb_max_index;
1656da6c28aaSamw 
1657da6c28aaSamw 			while (ctr) {
1658da6c28aaSamw 				smb_audit_record_node_t	*anr;
1659da6c28aaSamw 
1660da6c28aaSamw 				anr = anb->anb_records + anb->anb_index;
1661da6c28aaSamw 
1662da6c28aaSamw 				if (anr->anr_depth) {
1663da6c28aaSamw 					char c[MDB_SYM_NAMLEN];
1664da6c28aaSamw 					GElf_Sym sym;
1665da6c28aaSamw 					int i;
1666da6c28aaSamw 
1667da6c28aaSamw 					mdb_printf("\nRefCnt: %u\t",
1668da6c28aaSamw 					    anr->anr_refcnt);
1669da6c28aaSamw 
1670da6c28aaSamw 					for (i = 0;
1671da6c28aaSamw 					    i < anr->anr_depth;
1672da6c28aaSamw 					    i++) {
1673da6c28aaSamw 						if (mdb_lookup_by_addr(
1674da6c28aaSamw 						    anr->anr_stack[i],
1675da6c28aaSamw 						    MDB_SYM_FUZZY,
1676da6c28aaSamw 						    c, sizeof (c),
1677da6c28aaSamw 						    &sym) == -1) {
1678da6c28aaSamw 							continue;
1679da6c28aaSamw 						}
1680da6c28aaSamw 						mdb_printf("%s+0x%1x",
1681da6c28aaSamw 						    c,
1682da6c28aaSamw 						    anr->anr_stack[i] -
1683da6c28aaSamw 						    (uintptr_t)sym.st_value);
1684da6c28aaSamw 						++i;
1685da6c28aaSamw 						break;
1686da6c28aaSamw 					}
1687da6c28aaSamw 
1688da6c28aaSamw 					while (i < anr->anr_depth) {
1689da6c28aaSamw 						if (mdb_lookup_by_addr(
1690da6c28aaSamw 						    anr->anr_stack[i],
1691da6c28aaSamw 						    MDB_SYM_FUZZY,
1692da6c28aaSamw 						    c, sizeof (c),
1693da6c28aaSamw 						    &sym) == -1) {
1694da6c28aaSamw 							++i;
1695da6c28aaSamw 							continue;
1696da6c28aaSamw 						}
1697da6c28aaSamw 						mdb_printf("\n\t\t%s+0x%1x",
1698da6c28aaSamw 						    c,
1699da6c28aaSamw 						    anr->anr_stack[i] -
1700da6c28aaSamw 						    (uintptr_t)sym.st_value);
1701da6c28aaSamw 						++i;
1702da6c28aaSamw 					}
1703da6c28aaSamw 					mdb_printf("\n");
1704da6c28aaSamw 				}
1705da6c28aaSamw 				anb->anb_index--;
1706da6c28aaSamw 				anb->anb_index &= anb->anb_max_index;
1707da6c28aaSamw 				ctr--;
1708da6c28aaSamw 			}
1709da6c28aaSamw 		}
1710da6c28aaSamw 	} else {
1711da6c28aaSamw 		mdb_warn("failed to read struct smb_node at %p", addr);
1712da6c28aaSamw 		return (DCMD_ERR);
1713da6c28aaSamw 	}
1714da6c28aaSamw 
1715da6c28aaSamw 	return (DCMD_OK);
1716da6c28aaSamw }
1717da6c28aaSamw 
1718da6c28aaSamw /*
17196537f381Sas200622  * Initialize the smb_node_t walker by reading the value of smb_node_hash_table
17206537f381Sas200622  * in the kernel's symbol table. Only global walk supported.
1721da6c28aaSamw  */
1722da6c28aaSamw static int
smb_node_walk_init(mdb_walk_state_t * wsp)17236537f381Sas200622 smb_node_walk_init(mdb_walk_state_t *wsp)
1724da6c28aaSamw {
17256537f381Sas200622 	GElf_Sym	sym;
17266537f381Sas200622 	int		i;
17276537f381Sas200622 	uintptr_t	node_hash_table_addr;
1728da6c28aaSamw 
17296537f381Sas200622 	if (wsp->walk_addr == NULL) {
1730*7206bf49SGordon Ross 		if (mdb_lookup_by_obj(SMBSRV_OBJNAME, "smb_node_hash_table",
1731*7206bf49SGordon Ross 		    &sym) == -1) {
17326537f381Sas200622 			mdb_warn("failed to find 'smb_node_hash_table'");
17336537f381Sas200622 			return (WALK_ERR);
1734faa1795aSjb150015 		}
17356537f381Sas200622 		node_hash_table_addr = (uintptr_t)sym.st_value;
1736da6c28aaSamw 	} else {
17376537f381Sas200622 		mdb_printf("smb_node walk only supports global walks\n");
17386537f381Sas200622 		return (WALK_ERR);
1739da6c28aaSamw 	}
1740da6c28aaSamw 
17416537f381Sas200622 	for (i = 0; i < SMBND_HASH_MASK + 1; i++) {
17426537f381Sas200622 		wsp->walk_addr = node_hash_table_addr +
1743*7206bf49SGordon Ross 		    (i * sizeof (smb_llist_t)) + OFFSETOF(smb_llist_t, ll_list);
17446537f381Sas200622 		if (mdb_layered_walk("list", wsp) == -1) {
17456537f381Sas200622 			mdb_warn("failed to walk 'list'");
17466537f381Sas200622 			return (WALK_ERR);
1747da6c28aaSamw 		}
1748da6c28aaSamw 	}
1749da6c28aaSamw 
17506537f381Sas200622 	return (WALK_NEXT);
1751da6c28aaSamw }
1752da6c28aaSamw 
1753da6c28aaSamw static int
smb_node_walk_step(mdb_walk_state_t * wsp)17546537f381Sas200622 smb_node_walk_step(mdb_walk_state_t *wsp)
1755da6c28aaSamw {
17566537f381Sas200622 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
17576537f381Sas200622 	    wsp->walk_cbdata));
17586537f381Sas200622 }
1759da6c28aaSamw 
1760da6c28aaSamw /*
17616537f381Sas200622  * *****************************************************************************
17626537f381Sas200622  * ****************************** smb_lock_t ***********************************
17636537f381Sas200622  * *****************************************************************************
1764da6c28aaSamw  */
1765da6c28aaSamw 
1766da6c28aaSamw static int
smb_lock(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1767da6c28aaSamw smb_lock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1768da6c28aaSamw {
1769da6c28aaSamw 	smb_lock_t	lock;
1770da6c28aaSamw 	int		verbose = FALSE;
1771da6c28aaSamw 	uintptr_t	list_addr;
1772da6c28aaSamw 	char		*lock_type;
1773da6c28aaSamw 
1774da6c28aaSamw 	if (mdb_getopts(argc, argv,
1775da6c28aaSamw 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1776da6c28aaSamw 	    NULL) != argc)
1777da6c28aaSamw 		return (DCMD_USAGE);
1778da6c28aaSamw 
1779da6c28aaSamw 	/*
1780da6c28aaSamw 	 * An smb_lock_t address must be specified.
1781da6c28aaSamw 	 */
1782da6c28aaSamw 	if (!(flags & DCMD_ADDRSPEC))
1783da6c28aaSamw 		return (DCMD_USAGE);
1784da6c28aaSamw 
1785da6c28aaSamw 	/*
1786da6c28aaSamw 	 * If this is the first invocation of the command, print a nice
1787da6c28aaSamw 	 * header line for the output that will follow.
1788da6c28aaSamw 	 */
1789da6c28aaSamw 	if (DCMD_HDRSPEC(flags)) {
1790da6c28aaSamw 		if (verbose)
1791da6c28aaSamw 			mdb_printf("SMB lock information:\n\n");
1792da6c28aaSamw 		else
1793da6c28aaSamw 			mdb_printf("%<u>%-?s %4s %16s %8s %9s%</u>\n",
1794da6c28aaSamw 			    "Locks: ", "TYPE", "START", "LENGTH",
1795da6c28aaSamw 			    "CONFLICTS");
1796da6c28aaSamw 	}
1797da6c28aaSamw 
1798da6c28aaSamw 	if (mdb_vread(&lock, sizeof (lock), addr) == sizeof (lock)) {
1799da6c28aaSamw 		switch (lock.l_type) {
1800da6c28aaSamw 		case SMB_LOCK_TYPE_READWRITE:
1801da6c28aaSamw 			lock_type = "RW";
1802da6c28aaSamw 			break;
1803da6c28aaSamw 		case SMB_LOCK_TYPE_READONLY:
1804da6c28aaSamw 			lock_type = "RO";
1805da6c28aaSamw 			break;
1806da6c28aaSamw 		default:
1807da6c28aaSamw 			lock_type = "N/A";
1808da6c28aaSamw 			break;
1809da6c28aaSamw 		}
1810da6c28aaSamw 		if (verbose) {
1811da6c28aaSamw 			mdb_printf("Type             :\t%s (%u)\n",
1812da6c28aaSamw 			    lock_type, lock.l_type);
1813da6c28aaSamw 			mdb_printf("Start            :\t%llx\n",
1814da6c28aaSamw 			    lock.l_start);
1815da6c28aaSamw 			mdb_printf("Length           :\t%lx\n",
1816da6c28aaSamw 			    lock.l_length);
1817da6c28aaSamw 			mdb_printf("Session          :\t%p\n",
1818da6c28aaSamw 			    lock.l_session);
1819da6c28aaSamw 			mdb_printf("File             :\t%p\n",
1820da6c28aaSamw 			    lock.l_file);
1821da6c28aaSamw 			mdb_printf("User ID          :\t%u\n",
1822da6c28aaSamw 			    lock.l_uid);
1823da6c28aaSamw 			mdb_printf("Process ID       :\t%u\n",
1824da6c28aaSamw 			    lock.l_pid);
1825da6c28aaSamw 			mdb_printf("Conflicts        :\t%u\n",
1826da6c28aaSamw 			    lock.l_conflict_list.sl_count);
1827da6c28aaSamw 			if (lock.l_conflict_list.sl_count != 0) {
1828da6c28aaSamw 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1829da6c28aaSamw 				list_addr = addr +
1830*7206bf49SGordon Ross 				    OFFSETOF(smb_lock_t, l_conflict_list) +
1831*7206bf49SGordon Ross 				    OFFSETOF(smb_slist_t, sl_list);
1832da6c28aaSamw 				if (mdb_pwalk_dcmd("list", "smb_lock",
1833da6c28aaSamw 				    0, NULL, list_addr)) {
1834da6c28aaSamw 					mdb_warn("failed to walk conflict "
1835da6c28aaSamw 					    "locks ");
1836da6c28aaSamw 				}
1837da6c28aaSamw 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1838da6c28aaSamw 			}
1839da6c28aaSamw 			mdb_printf("Blocked by       :\t%p\n",
1840da6c28aaSamw 			    lock.l_blocked_by);
1841da6c28aaSamw 			mdb_printf("Flags            :\t0x%x\n",
1842da6c28aaSamw 			    lock.l_flags);
1843da6c28aaSamw 			mdb_printf("\n");
1844da6c28aaSamw 		} else {
1845da6c28aaSamw 			mdb_printf("%?p %4s %16llx %08lx %9x", addr,
1846da6c28aaSamw 			    lock_type, lock.l_start, lock.l_length,
1847da6c28aaSamw 			    lock.l_conflict_list.sl_count);
1848da6c28aaSamw 		}
1849da6c28aaSamw 	} else {
1850da6c28aaSamw 		mdb_warn("failed to read struct smb_request at %p", addr);
1851da6c28aaSamw 		return (DCMD_ERR);
1852da6c28aaSamw 	}
1853da6c28aaSamw 
1854da6c28aaSamw 	return (DCMD_OK);
1855da6c28aaSamw }
1856da6c28aaSamw 
1857da6c28aaSamw /*
1858cb174861Sjoyce mcintosh  * *****************************************************************************
1859cb174861Sjoyce mcintosh  * ************************** smb_oplock_grant_t *******************************
1860cb174861Sjoyce mcintosh  * *****************************************************************************
1861cb174861Sjoyce mcintosh  */
1862cb174861Sjoyce mcintosh /*ARGSUSED*/
1863cb174861Sjoyce mcintosh static int
smb_oplock_grant(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1864cb174861Sjoyce mcintosh smb_oplock_grant(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1865cb174861Sjoyce mcintosh {
1866cb174861Sjoyce mcintosh 	smb_oplock_grant_t	grant;
1867cb174861Sjoyce mcintosh 	char			 *level;
1868cb174861Sjoyce mcintosh 
1869cb174861Sjoyce mcintosh 	if (!(flags & DCMD_ADDRSPEC))
1870cb174861Sjoyce mcintosh 		return (DCMD_USAGE);
1871cb174861Sjoyce mcintosh 
1872cb174861Sjoyce mcintosh 	/*
1873cb174861Sjoyce mcintosh 	 * If this is the first invocation of the command, print a nice
1874cb174861Sjoyce mcintosh 	 * header line for the output that will follow.
1875cb174861Sjoyce mcintosh 	 */
1876cb174861Sjoyce mcintosh 	if (DCMD_HDRSPEC(flags)) {
1877cb174861Sjoyce mcintosh 		mdb_printf("%<u>%-16s %-10s %-16s%</u>\n",
1878cb174861Sjoyce mcintosh 		    "Grants:", "LEVEL", "OFILE");
1879cb174861Sjoyce mcintosh 	}
1880cb174861Sjoyce mcintosh 
1881cb174861Sjoyce mcintosh 	if (mdb_vread(&grant, sizeof (grant), addr) == sizeof (grant)) {
1882cb174861Sjoyce mcintosh 		switch (grant.og_level) {
1883cb174861Sjoyce mcintosh 		case SMB_OPLOCK_EXCLUSIVE:
1884cb174861Sjoyce mcintosh 			level = "EXCLUSIVE";
1885cb174861Sjoyce mcintosh 			break;
1886cb174861Sjoyce mcintosh 		case SMB_OPLOCK_BATCH:
1887cb174861Sjoyce mcintosh 			level = "BATCH";
1888cb174861Sjoyce mcintosh 			break;
1889cb174861Sjoyce mcintosh 		case SMB_OPLOCK_LEVEL_II:
1890cb174861Sjoyce mcintosh 			level = "LEVEL_II";
1891cb174861Sjoyce mcintosh 			break;
1892cb174861Sjoyce mcintosh 		default:
1893cb174861Sjoyce mcintosh 			level = "UNKNOWN";
1894cb174861Sjoyce mcintosh 			break;
1895cb174861Sjoyce mcintosh 		}
1896cb174861Sjoyce mcintosh 
1897cb174861Sjoyce mcintosh 		mdb_printf("%-16p %-10s %-16p", addr, level, grant.og_ofile);
1898cb174861Sjoyce mcintosh 	}
1899cb174861Sjoyce mcintosh 	return (DCMD_OK);
1900cb174861Sjoyce mcintosh }
1901cb174861Sjoyce mcintosh 
1902cb174861Sjoyce mcintosh /*
1903cb174861Sjoyce mcintosh  * *****************************************************************************
1904cb174861Sjoyce mcintosh  * ***************************** smb_oplock_t **********************************
1905cb174861Sjoyce mcintosh  * *****************************************************************************
1906cb174861Sjoyce mcintosh  */
1907cb174861Sjoyce mcintosh /*ARGSUSED*/
1908cb174861Sjoyce mcintosh static int
smb_oplock(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1909cb174861Sjoyce mcintosh smb_oplock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1910cb174861Sjoyce mcintosh {
1911cb174861Sjoyce mcintosh 	smb_oplock_t	oplock;
1912cb174861Sjoyce mcintosh 	uintptr_t	list_addr;
1913cb174861Sjoyce mcintosh 
1914cb174861Sjoyce mcintosh 	if (!(flags & DCMD_ADDRSPEC))
1915cb174861Sjoyce mcintosh 		return (DCMD_USAGE);
1916cb174861Sjoyce mcintosh 
1917cb174861Sjoyce mcintosh 	if (mdb_vread(&oplock, sizeof (oplock), addr) != sizeof (oplock)) {
1918cb174861Sjoyce mcintosh 		mdb_warn("failed to read struct smb_oplock at %p", addr);
1919cb174861Sjoyce mcintosh 		return (DCMD_ERR);
1920cb174861Sjoyce mcintosh 	}
1921cb174861Sjoyce mcintosh 
1922cb174861Sjoyce mcintosh 	if (oplock.ol_count == 0)
1923cb174861Sjoyce mcintosh 		return (DCMD_OK);
1924cb174861Sjoyce mcintosh 
1925cb174861Sjoyce mcintosh 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
1926cb174861Sjoyce mcintosh 	switch (oplock.ol_break) {
1927cb174861Sjoyce mcintosh 	case SMB_OPLOCK_BREAK_TO_NONE:
1928cb174861Sjoyce mcintosh 		mdb_printf("Break Pending: BREAK_TO_NONE\n");
1929cb174861Sjoyce mcintosh 		break;
1930cb174861Sjoyce mcintosh 	case SMB_OPLOCK_BREAK_TO_LEVEL_II:
1931cb174861Sjoyce mcintosh 		mdb_printf(
1932cb174861Sjoyce mcintosh 		    "Break Pending: BREAK_TO_LEVEL_II\n");
1933cb174861Sjoyce mcintosh 		break;
1934cb174861Sjoyce mcintosh 	default:
1935cb174861Sjoyce mcintosh 		break;
1936cb174861Sjoyce mcintosh 	}
1937cb174861Sjoyce mcintosh 
1938*7206bf49SGordon Ross 	list_addr = addr + OFFSETOF(smb_oplock_t, ol_grants);
1939cb174861Sjoyce mcintosh 
1940cb174861Sjoyce mcintosh 	if (mdb_pwalk_dcmd("list", "smboplockgrant",
1941cb174861Sjoyce mcintosh 	    argc, argv, list_addr)) {
1942cb174861Sjoyce mcintosh 		mdb_warn("failed to walk oplock grants");
1943cb174861Sjoyce mcintosh 	}
1944cb174861Sjoyce mcintosh 
1945cb174861Sjoyce mcintosh 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
1946cb174861Sjoyce mcintosh 
1947cb174861Sjoyce mcintosh 	return (DCMD_OK);
1948cb174861Sjoyce mcintosh }
1949cb174861Sjoyce mcintosh 
1950cb174861Sjoyce mcintosh /*
1951148c5f43SAlan Wright  * ::smbstat
1952da6c28aaSamw  *
1953148c5f43SAlan Wright  * Prints SMB requests statistics.
1954da6c28aaSamw  */
1955da6c28aaSamw /*ARGSUSED*/
1956da6c28aaSamw static int
smb_stats(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)19576537f381Sas200622 smb_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1958da6c28aaSamw {
1959148c5f43SAlan Wright 	smb_server_t	*sv;
1960da6c28aaSamw 
1961148c5f43SAlan Wright 	if (!(flags & DCMD_ADDRSPEC))
1962da6c28aaSamw 		return (DCMD_USAGE);
1963da6c28aaSamw 
1964148c5f43SAlan Wright 	sv = mdb_alloc(sizeof (*sv), UM_SLEEP | UM_GC);
1965148c5f43SAlan Wright 	if (mdb_vread(sv, sizeof (*sv), addr) == -1) {
1966148c5f43SAlan Wright 		mdb_warn("failed to read server object at %p", addr);
1967da6c28aaSamw 		return (DCMD_ERR);
1968da6c28aaSamw 	}
1969148c5f43SAlan Wright 	if (sv->sv_magic != SMB_SERVER_MAGIC) {
1970148c5f43SAlan Wright 		mdb_warn("not an smb_server_t (%p)>", addr);
1971da6c28aaSamw 		return (DCMD_ERR);
1972da6c28aaSamw 	}
1973148c5f43SAlan Wright 	mdb_printf(
1974148c5f43SAlan Wright 	    "\n%<b>  nbt   tcp users trees files pipes%</b>\n"
1975148c5f43SAlan Wright 	    "%5d %5d %5d %5d %5d %5d\n",
1976148c5f43SAlan Wright 	    sv->sv_nbt_sess,
1977148c5f43SAlan Wright 	    sv->sv_tcp_sess,
1978148c5f43SAlan Wright 	    sv->sv_users,
1979148c5f43SAlan Wright 	    sv->sv_trees,
1980148c5f43SAlan Wright 	    sv->sv_files,
1981148c5f43SAlan Wright 	    sv->sv_pipes);
1982da6c28aaSamw 
1983da6c28aaSamw 	return (DCMD_OK);
1984da6c28aaSamw }
1985da6c28aaSamw 
1986da6c28aaSamw /*
19876537f381Sas200622  * *****************************************************************************
19886537f381Sas200622  * ******************************** smb_ace_t **********************************
19896537f381Sas200622  * *****************************************************************************
1990da6c28aaSamw  */
19916537f381Sas200622 static const ace_type_entry_t	ace_types[ACE_TYPE_TABLEN] =
1992da6c28aaSamw {
19936537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_ACE_TYPE),
19946537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_ACE_TYPE),
19956537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_ACE_TYPE),
19966537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_ACE_TYPE),
19976537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE),
19986537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE),
19996537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_OBJECT_ACE_TYPE),
20006537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE),
20016537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE),
20026537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE),
20036537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE),
20046537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE),
20056537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE),
20066537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE),
20076537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE),
20086537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE),
20096537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE),
20106537f381Sas200622 	ACE_TYPE_ENTRY(0x11),
20116537f381Sas200622 	ACE_TYPE_ENTRY(0x12),
20126537f381Sas200622 	ACE_TYPE_ENTRY(0x13),
20136537f381Sas200622 	ACE_TYPE_ENTRY(0x14),
20146537f381Sas200622 	ACE_TYPE_ENTRY(0x15),
20156537f381Sas200622 	ACE_TYPE_ENTRY(0x16),
20166537f381Sas200622 	ACE_TYPE_ENTRY(0x17),
20176537f381Sas200622 	ACE_TYPE_ENTRY(0x18),
20186537f381Sas200622 	ACE_TYPE_ENTRY(0x19),
20196537f381Sas200622 	ACE_TYPE_ENTRY(0x1A),
20206537f381Sas200622 	ACE_TYPE_ENTRY(0x1B),
20216537f381Sas200622 	ACE_TYPE_ENTRY(0x1C),
20226537f381Sas200622 	ACE_TYPE_ENTRY(0x1D),
20236537f381Sas200622 	ACE_TYPE_ENTRY(0x1E),
20246537f381Sas200622 	ACE_TYPE_ENTRY(0x1F)
20256537f381Sas200622 };
20266537f381Sas200622 
20276537f381Sas200622 static const mdb_bitmask_t ace_flag_bits[] = {
20286537f381Sas200622 	{ "OBJECT_INHERIT_ACE", OBJECT_INHERIT_ACE, OBJECT_INHERIT_ACE },
20296537f381Sas200622 	{ "CONTAINER_INHERIT_ACE", CONTAINER_INHERIT_ACE,
20306537f381Sas200622 	    CONTAINER_INHERIT_ACE },
20316537f381Sas200622 	{ "NO_PROPOGATE_INHERIT_ACE", NO_PROPOGATE_INHERIT_ACE,
20326537f381Sas200622 	    NO_PROPOGATE_INHERIT_ACE },
20336537f381Sas200622 	{ "INHERIT_ONLY_ACE", INHERIT_ONLY_ACE, INHERIT_ONLY_ACE },
20346537f381Sas200622 	{ "INHERITED_ACE", INHERITED_ACE, INHERITED_ACE },
20356537f381Sas200622 	{ "SUCCESSFUL_ACCESS_ACE_FLAG", SUCCESSFUL_ACCESS_ACE_FLAG,
20366537f381Sas200622 	    SUCCESSFUL_ACCESS_ACE_FLAG },
20376537f381Sas200622 	{ "FAILED_ACCESS_ACE_FLAG", FAILED_ACCESS_ACE_FLAG,
20386537f381Sas200622 	    FAILED_ACCESS_ACE_FLAG },
20396537f381Sas200622 	{ NULL, 0, 0 }
20406537f381Sas200622 };
20416537f381Sas200622 
20426537f381Sas200622 /*
20436537f381Sas200622  * ::smbace
20446537f381Sas200622  */
20456537f381Sas200622 static int
smb_ace(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)20466537f381Sas200622 smb_ace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
20476537f381Sas200622 {
20486537f381Sas200622 	smb_ace_t	ace;
20496537f381Sas200622 	int		verbose = FALSE;
20506537f381Sas200622 	const char	*ptr;
20516537f381Sas200622 	int		rc;
20526537f381Sas200622 
20536537f381Sas200622 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose,
20546537f381Sas200622 	    NULL) != argc)
20556537f381Sas200622 		return (DCMD_USAGE);
20566537f381Sas200622 
20576537f381Sas200622 	/*
20586537f381Sas200622 	 * An smb_ace address is required.
20596537f381Sas200622 	 */
20606537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
20616537f381Sas200622 		return (DCMD_USAGE);
20626537f381Sas200622 
20636537f381Sas200622 	if (mdb_vread(&ace, sizeof (ace), addr) != sizeof (ace)) {
20646537f381Sas200622 		mdb_warn("failed to read struct smb_ace at %p", addr);
20656537f381Sas200622 		return (DCMD_ERR);
20666537f381Sas200622 	}
20676537f381Sas200622 
20686537f381Sas200622 	if (verbose) {
20696537f381Sas200622 		if (ace.se_hdr.se_type < ACE_TYPE_TABLEN)
20706537f381Sas200622 			ptr = ace_types[ace.se_hdr.se_type].ace_type_sting;
20716537f381Sas200622 		else
20726537f381Sas200622 			ptr = "Unknown";
20736537f381Sas200622 
20746537f381Sas200622 		mdb_printf("ACE Type: 0x%02x (%s)\n", ace.se_hdr.se_type, ptr);
20756537f381Sas200622 		mdb_printf("ACE Flags: %b\n", (int)ace.se_hdr.se_flags,
20766537f381Sas200622 		    ace_flag_bits);
20776537f381Sas200622 		mdb_printf("ACE Wire Size: 0x%04x\n", ace.se_hdr.se_bsize);
20786537f381Sas200622 		mdb_printf("ACE Mask: 0x%08x\n", ace.se_mask);
20796537f381Sas200622 		mdb_printf("ACE SID: ");
20806537f381Sas200622 	} else {
20816537f381Sas200622 		if (DCMD_HDRSPEC(flags))
20826537f381Sas200622 			mdb_printf(
20836537f381Sas200622 			    "%<b>%<u>%?-s %-4s %-4s %-8s %s%</u>%</b>\n",
20846537f381Sas200622 			    "ACE", "TYPE", "FLAGS", "MASK", "SID");
20856537f381Sas200622 		mdb_printf("%?p 0x%02x 0x%02x 0x%08x ", addr,
20866537f381Sas200622 		    ace.se_hdr.se_type, ace.se_hdr.se_flags, ace.se_mask);
20876537f381Sas200622 	}
20886537f381Sas200622 	rc = smb_sid_print((uintptr_t)ace.se_sid);
20896537f381Sas200622 	mdb_printf("\n");
20906537f381Sas200622 	return (rc);
20916537f381Sas200622 }
20926537f381Sas200622 
20936537f381Sas200622 static int
smb_ace_walk_init(mdb_walk_state_t * wsp)20946537f381Sas200622 smb_ace_walk_init(mdb_walk_state_t *wsp)
20956537f381Sas200622 {
20966537f381Sas200622 	if (wsp->walk_addr == 0) {
20976537f381Sas200622 		mdb_printf("smb_ace walk only supports local walks\n");
20986537f381Sas200622 		return (WALK_ERR);
20996537f381Sas200622 	}
21006537f381Sas200622 
2101*7206bf49SGordon Ross 	wsp->walk_addr += OFFSETOF(smb_acl_t, sl_sorted);
21026537f381Sas200622 
21036537f381Sas200622 	if (mdb_layered_walk("list", wsp) == -1) {
21046537f381Sas200622 		mdb_warn("failed to walk list of ACEs");
21056537f381Sas200622 		return (WALK_ERR);
21066537f381Sas200622 	}
21076537f381Sas200622 
21086537f381Sas200622 	return (WALK_NEXT);
21096537f381Sas200622 }
21106537f381Sas200622 
21116537f381Sas200622 static int
smb_ace_walk_step(mdb_walk_state_t * wsp)21126537f381Sas200622 smb_ace_walk_step(mdb_walk_state_t *wsp)
21136537f381Sas200622 {
21146537f381Sas200622 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
21156537f381Sas200622 	    wsp->walk_cbdata));
21166537f381Sas200622 }
21176537f381Sas200622 
21186537f381Sas200622 /*
21196537f381Sas200622  * *****************************************************************************
21206537f381Sas200622  * ******************************** smb_acl_t **********************************
21216537f381Sas200622  * *****************************************************************************
21226537f381Sas200622  */
21236537f381Sas200622 
21246537f381Sas200622 /*
21256537f381Sas200622  * ::smbacl
21266537f381Sas200622  */
21276537f381Sas200622 static int
smb_acl(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)21286537f381Sas200622 smb_acl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
21296537f381Sas200622 {
21306537f381Sas200622 	smb_acl_t	acl;
21316537f381Sas200622 
21326537f381Sas200622 	/* An smb_acl address is required. */
21336537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
21346537f381Sas200622 		return (DCMD_USAGE);
21356537f381Sas200622 
21366537f381Sas200622 	if (mdb_vread(&acl, sizeof (acl), addr) != sizeof (acl)) {
21376537f381Sas200622 		mdb_warn("failed to read struct smb_acl at %p", addr);
21386537f381Sas200622 		return (DCMD_ERR);
21396537f381Sas200622 	}
21406537f381Sas200622 
21416537f381Sas200622 	mdb_printf("ACL Revision: %d\n", acl.sl_revision);
21426537f381Sas200622 	mdb_printf("ACL Size on Wire: %d\n", acl.sl_bsize);
21436537f381Sas200622 	mdb_printf("ACL Number of ACEs: %d\n", acl.sl_acecnt);
21446537f381Sas200622 
21456537f381Sas200622 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
21466537f381Sas200622 	if (mdb_pwalk_dcmd("smbace_walker", "smbace", argc, argv, addr)) {
21476537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
21486537f381Sas200622 		mdb_warn("failed to walk list of ACEs for ACL %p", addr);
21496537f381Sas200622 		return (DCMD_ERR);
21506537f381Sas200622 	}
21516537f381Sas200622 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
21526537f381Sas200622 	return (DCMD_OK);
21536537f381Sas200622 }
21546537f381Sas200622 
21556537f381Sas200622 /*
21566537f381Sas200622  * *****************************************************************************
21576537f381Sas200622  * ********************************* smb_sd_t **********************************
21586537f381Sas200622  * *****************************************************************************
21596537f381Sas200622  */
21606537f381Sas200622 
21616537f381Sas200622 /*
21626537f381Sas200622  * ::smbsd
21636537f381Sas200622  */
21646537f381Sas200622 static int
smb_sd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)21656537f381Sas200622 smb_sd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
21666537f381Sas200622 {
21676537f381Sas200622 	smb_sd_t	sd;
21686537f381Sas200622 	int		rc;
21696537f381Sas200622 
21706537f381Sas200622 	/*
21716537f381Sas200622 	 * An smb_sid address is required.
21726537f381Sas200622 	 */
21736537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
21746537f381Sas200622 		return (DCMD_USAGE);
21756537f381Sas200622 
21766537f381Sas200622 	if (mdb_vread(&sd, sizeof (sd), addr) != sizeof (sd)) {
21776537f381Sas200622 		mdb_warn("failed to read struct smb_sd at %p", addr);
21786537f381Sas200622 		return (DCMD_ERR);
21796537f381Sas200622 	}
21806537f381Sas200622 
21816537f381Sas200622 	mdb_printf("SD Revision: %d\n", sd.sd_revision);
21826537f381Sas200622 	mdb_printf("SD Control: %04x\n", sd.sd_control);
21836537f381Sas200622 	if (sd.sd_control & SE_OWNER_DEFAULTED)
21846537f381Sas200622 		mdb_printf("\t    SE_OWNER_DEFAULTED\n");
21856537f381Sas200622 	if (sd.sd_control & SE_GROUP_DEFAULTED)
21866537f381Sas200622 		mdb_printf("\t    SE_GROUP_DEFAULTED\n");
21876537f381Sas200622 	if (sd.sd_control & SE_DACL_PRESENT)
21886537f381Sas200622 		mdb_printf("\t    SE_DACL_PRESENT\n");
21896537f381Sas200622 	if (sd.sd_control & SE_DACL_DEFAULTED)
21906537f381Sas200622 		mdb_printf("\t    SE_DACL_DEFAULTED\n");
21916537f381Sas200622 	if (sd.sd_control & SE_SACL_PRESENT)
21926537f381Sas200622 		mdb_printf("\t    SE_SACL_PRESENT\n");
21936537f381Sas200622 	if (sd.sd_control & SE_SACL_DEFAULTED)
21946537f381Sas200622 		mdb_printf("\t    SE_SACL_DEFAULTED\n");
21956537f381Sas200622 	if (sd.sd_control & SE_DACL_AUTO_INHERIT_REQ)
21966537f381Sas200622 		mdb_printf("\t    SE_DACL_AUTO_INHERIT_REQ\n");
21976537f381Sas200622 	if (sd.sd_control & SE_SACL_AUTO_INHERIT_REQ)
21986537f381Sas200622 		mdb_printf("\t    SE_SACL_AUTO_INHERIT_REQ\n");
21996537f381Sas200622 	if (sd.sd_control & SE_DACL_AUTO_INHERITED)
22006537f381Sas200622 		mdb_printf("\t    SE_DACL_AUTO_INHERITED\n");
22016537f381Sas200622 	if (sd.sd_control & SE_SACL_AUTO_INHERITED)
22026537f381Sas200622 		mdb_printf("\t    SE_SACL_AUTO_INHERITED\n");
22036537f381Sas200622 	if (sd.sd_control & SE_DACL_PROTECTED)
22046537f381Sas200622 		mdb_printf("\t    SE_DACL_PROTECTED\n");
22056537f381Sas200622 	if (sd.sd_control & SE_SACL_PROTECTED)
22066537f381Sas200622 		mdb_printf("\t    SE_SACL_PROTECTED\n");
22076537f381Sas200622 	if (sd.sd_control & SE_SELF_RELATIVE)
22086537f381Sas200622 		mdb_printf("\t    SE_SELF_RELATIVE\n");
22096537f381Sas200622 
22106537f381Sas200622 	mdb_printf("SID of Owner: ");
22116537f381Sas200622 	rc = smb_sid_print((uintptr_t)sd.sd_owner);
22126537f381Sas200622 	if (rc != DCMD_OK)
22136537f381Sas200622 		return (rc);
22146537f381Sas200622 	mdb_printf("\nSID of Group: ");
22156537f381Sas200622 	rc = smb_sid_print((uintptr_t)sd.sd_group);
22166537f381Sas200622 	if (rc != DCMD_OK)
22176537f381Sas200622 		return (rc);
22186537f381Sas200622 	mdb_printf("\n");
22196537f381Sas200622 
22206537f381Sas200622 	if (sd.sd_control & SE_SACL_PRESENT && sd.sd_sacl) {
22216537f381Sas200622 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
22226537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
22236537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_sacl, flags,
22246537f381Sas200622 		    argc, argv);
22256537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
22266537f381Sas200622 		if (rc != DCMD_OK)
22276537f381Sas200622 			return (rc);
22286537f381Sas200622 	}
22296537f381Sas200622 	if (sd.sd_control & SE_DACL_PRESENT && sd.sd_dacl) {
22306537f381Sas200622 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
22316537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
22326537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_dacl, flags,
22336537f381Sas200622 		    argc, argv);
22346537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
22356537f381Sas200622 		if (rc != DCMD_OK)
22366537f381Sas200622 			return (rc);
22376537f381Sas200622 	}
22386537f381Sas200622 
22396537f381Sas200622 	return (DCMD_OK);
22406537f381Sas200622 }
22416537f381Sas200622 
22426537f381Sas200622 /*
22436537f381Sas200622  * *****************************************************************************
22446537f381Sas200622  * ********************************* smb_sid_t *********************************
22456537f381Sas200622  * *****************************************************************************
22466537f381Sas200622  */
22476537f381Sas200622 
22486537f381Sas200622 /*
22496537f381Sas200622  * ::smbsid
22506537f381Sas200622  */
22516537f381Sas200622 /*ARGSUSED*/
22526537f381Sas200622 static int
smb_sid(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)22536537f381Sas200622 smb_sid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
22546537f381Sas200622 {
22556537f381Sas200622 	/*
22566537f381Sas200622 	 * An smb_sid address is required.
22576537f381Sas200622 	 */
22586537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
22596537f381Sas200622 		return (DCMD_USAGE);
22606537f381Sas200622 
22616537f381Sas200622 	return (smb_sid_print(addr));
22626537f381Sas200622 }
22636537f381Sas200622 
22646537f381Sas200622 /*
22656537f381Sas200622  * smb_sid_print
22666537f381Sas200622  */
22676537f381Sas200622 static int
smb_sid_print(uintptr_t addr)22686537f381Sas200622 smb_sid_print(uintptr_t addr)
22696537f381Sas200622 {
22706537f381Sas200622 	smb_sid_t	sid;
22716537f381Sas200622 	smb_sid_t	*psid;
22726537f381Sas200622 	size_t		sid_size;
22736537f381Sas200622 	int		i;
22746537f381Sas200622 	uint64_t	authority;
22756537f381Sas200622 
2276*7206bf49SGordon Ross 	sid_size = OFFSETOF(smb_sid_t, sid_subauth);
22776537f381Sas200622 
22786537f381Sas200622 	if (mdb_vread(&sid, sid_size, addr) != sid_size) {
22796537f381Sas200622 		mdb_warn("failed to read struct smb_sid at %p", addr);
22806537f381Sas200622 		return (DCMD_ERR);
22816537f381Sas200622 	}
22826537f381Sas200622 
22836537f381Sas200622 	sid_size += sid.sid_subauthcnt * sizeof (sid.sid_subauth[0]);
22846537f381Sas200622 
22856537f381Sas200622 	psid = mdb_zalloc(sid_size, UM_SLEEP | UM_GC);
22866537f381Sas200622 	if (mdb_vread(psid, sid_size, addr) != sid_size) {
22876537f381Sas200622 		mdb_warn("failed to read struct smb_sid at %p", addr);
22886537f381Sas200622 		return (DCMD_ERR);
22896537f381Sas200622 	}
22906537f381Sas200622 
22916537f381Sas200622 	mdb_printf("S-%d", psid->sid_revision);
22926537f381Sas200622 	authority = 0;
22936537f381Sas200622 	for (i = 0; i < NT_SID_AUTH_MAX; i++) {
22946537f381Sas200622 		authority += ((uint64_t)psid->sid_authority[i]) <<
22956537f381Sas200622 		    (8 * (NT_SID_AUTH_MAX - 1) - i);
22966537f381Sas200622 	}
22976537f381Sas200622 	mdb_printf("-%ll", authority);
22986537f381Sas200622 
22996537f381Sas200622 	for (i = 0; i < psid->sid_subauthcnt; i++)
23006537f381Sas200622 		mdb_printf("-%d", psid->sid_subauth[i]);
23016537f381Sas200622 
23026537f381Sas200622 	return (DCMD_OK);
23036537f381Sas200622 }
23046537f381Sas200622 
23056537f381Sas200622 /*
23066537f381Sas200622  * *****************************************************************************
23076537f381Sas200622  * ********************************* smb_fssd_t ********************************
23086537f381Sas200622  * *****************************************************************************
23096537f381Sas200622  */
23106537f381Sas200622 
23116537f381Sas200622 /*
23126537f381Sas200622  * ::smbfssd
23136537f381Sas200622  */
23146537f381Sas200622 static int
smb_fssd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)23156537f381Sas200622 smb_fssd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23166537f381Sas200622 {
23176537f381Sas200622 	smb_fssd_t	fssd;
23186537f381Sas200622 	int		rc;
23196537f381Sas200622 
23206537f381Sas200622 	/*
23216537f381Sas200622 	 * An smb_fssd address is required.
23226537f381Sas200622 	 */
23236537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
23246537f381Sas200622 		return (DCMD_USAGE);
23256537f381Sas200622 
23266537f381Sas200622 	if (mdb_vread(&fssd, sizeof (fssd), addr) != sizeof (fssd)) {
23276537f381Sas200622 		mdb_warn("failed to read struct smb_fssd at %p", addr);
23286537f381Sas200622 		return (DCMD_ERR);
23296537f381Sas200622 	}
23306537f381Sas200622 
23316537f381Sas200622 	mdb_printf("FSSD secinfo: 0x%x\n", fssd.sd_secinfo);
23326537f381Sas200622 	if (fssd.sd_secinfo & SMB_OWNER_SECINFO)
23336537f381Sas200622 		mdb_printf("FSSD uid: %d\n", fssd.sd_uid);
23346537f381Sas200622 	if (fssd.sd_secinfo & SMB_GROUP_SECINFO)
23356537f381Sas200622 		mdb_printf("FSSD gid: %d\n", fssd.sd_gid);
23366537f381Sas200622 	if (fssd.sd_secinfo & SMB_SACL_SECINFO && fssd.sd_zsacl) {
23376537f381Sas200622 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
23386537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
23396537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zsacl, flags,
23406537f381Sas200622 		    argc, argv);
23416537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
23426537f381Sas200622 		if (rc != DCMD_OK)
23436537f381Sas200622 			return (rc);
23446537f381Sas200622 	}
23456537f381Sas200622 	if (fssd.sd_secinfo & SMB_DACL_SECINFO && fssd.sd_zdacl) {
23466537f381Sas200622 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
23476537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
23486537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zdacl, flags,
23496537f381Sas200622 		    argc, argv);
23506537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
23516537f381Sas200622 		if (rc != DCMD_OK)
23526537f381Sas200622 			return (rc);
23536537f381Sas200622 	}
23546537f381Sas200622 
23556537f381Sas200622 	return (DCMD_OK);
23566537f381Sas200622 }
23576537f381Sas200622 
23586537f381Sas200622 /*
23596537f381Sas200622  * *****************************************************************************
23606537f381Sas200622  * **************************** Utility Funcions *******************************
23616537f381Sas200622  * *****************************************************************************
23626537f381Sas200622  */
23636537f381Sas200622 
23646537f381Sas200622 /*
23656537f381Sas200622  * smb_dcmd_getopt
23666537f381Sas200622  *
23676537f381Sas200622  * This function analyzes the arguments passed in and sets the bit corresponding
23686537f381Sas200622  * to the options found in the opts variable.
23696537f381Sas200622  *
23706537f381Sas200622  * Return Value
23716537f381Sas200622  *
23726537f381Sas200622  *	-1	An error occured during the decoding
23736537f381Sas200622  *	0	The decoding was successful
23746537f381Sas200622  */
23756537f381Sas200622 static int
smb_dcmd_getopt(uint_t * opts,int argc,const mdb_arg_t * argv)23766537f381Sas200622 smb_dcmd_getopt(uint_t *opts, int argc, const mdb_arg_t *argv)
23776537f381Sas200622 {
23786537f381Sas200622 	*opts = 0;
23796537f381Sas200622 
23806537f381Sas200622 	if (mdb_getopts(argc, argv,
23816537f381Sas200622 	    's', MDB_OPT_SETBITS, SMB_OPT_SERVER, opts,
23826537f381Sas200622 	    'e', MDB_OPT_SETBITS, SMB_OPT_SESSION, opts,
23836537f381Sas200622 	    'r', MDB_OPT_SETBITS, SMB_OPT_REQUEST, opts,
23846537f381Sas200622 	    'u', MDB_OPT_SETBITS, SMB_OPT_USER, opts,
23856537f381Sas200622 	    't', MDB_OPT_SETBITS, SMB_OPT_TREE, opts,
23866537f381Sas200622 	    'f', MDB_OPT_SETBITS, SMB_OPT_OFILE, opts,
23876537f381Sas200622 	    'd', MDB_OPT_SETBITS, SMB_OPT_ODIR, opts,
23886537f381Sas200622 	    'w', MDB_OPT_SETBITS, SMB_OPT_WALK, opts,
23896537f381Sas200622 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, opts,
23906537f381Sas200622 	    NULL) != argc)
23916537f381Sas200622 		return (-1);
23926537f381Sas200622 
23936537f381Sas200622 	return (0);
23946537f381Sas200622 }
23956537f381Sas200622 
23966537f381Sas200622 /*
23976537f381Sas200622  * smb_dcmd_setopt
23986537f381Sas200622  *
23996537f381Sas200622  * This function set the arguments corresponding to the bits set in opts.
24006537f381Sas200622  *
24016537f381Sas200622  * Return Value
24026537f381Sas200622  *
24036537f381Sas200622  *	Number of arguments set.
24046537f381Sas200622  */
24056537f381Sas200622 static int
smb_dcmd_setopt(uint_t opts,int max_argc,mdb_arg_t * argv)24066537f381Sas200622 smb_dcmd_setopt(uint_t opts, int max_argc, mdb_arg_t *argv)
24076537f381Sas200622 {
24086537f381Sas200622 	int	i;
24096537f381Sas200622 	int	argc = 0;
24106537f381Sas200622 
24116537f381Sas200622 	for (i = 0; i < SMB_MDB_MAX_OPTS; i++) {
2412148c5f43SAlan Wright 		if ((opts & smb_opts[i].o_value) && (argc < max_argc)) {
24136537f381Sas200622 			argv->a_type = MDB_TYPE_STRING;
2414148c5f43SAlan Wright 			argv->a_un.a_str = smb_opts[i].o_name;
24156537f381Sas200622 			argc++;
24166537f381Sas200622 			argv++;
24176537f381Sas200622 		}
24186537f381Sas200622 	}
24196537f381Sas200622 	return (argc);
24206537f381Sas200622 }
24216537f381Sas200622 
24226537f381Sas200622 /*
24236537f381Sas200622  * smb_obj_expand
24246537f381Sas200622  */
24256537f381Sas200622 static int
smb_obj_expand(uintptr_t addr,uint_t opts,const smb_exp_t * x,ulong_t indent)24266537f381Sas200622 smb_obj_expand(uintptr_t addr, uint_t opts, const smb_exp_t *x, ulong_t indent)
24276537f381Sas200622 {
24286537f381Sas200622 	int		rc = 0;
24296537f381Sas200622 	int		argc;
24306537f381Sas200622 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
24316537f381Sas200622 
24326537f381Sas200622 	argc = smb_dcmd_setopt(opts | SMB_OPT_WALK, SMB_MDB_MAX_OPTS, argv);
24336537f381Sas200622 
24346537f381Sas200622 	(void) mdb_inc_indent(indent);
24356537f381Sas200622 	while (x->ex_dcmd) {
24366537f381Sas200622 		if (x->ex_mask & opts) {
24376537f381Sas200622 			rc = mdb_pwalk_dcmd("list", x->ex_dcmd, argc, argv,
24386537f381Sas200622 			    addr + x->ex_offset);
24396537f381Sas200622 
24406537f381Sas200622 			if (rc) {
24416537f381Sas200622 				mdb_warn("failed to walk the list of %s in %p",
24426537f381Sas200622 				    x->ex_name, addr + x->ex_offset);
24436537f381Sas200622 				break;
24446537f381Sas200622 			}
24456537f381Sas200622 		}
24466537f381Sas200622 		x++;
24476537f381Sas200622 	}
24486537f381Sas200622 	(void) mdb_dec_indent(indent);
24496537f381Sas200622 	return (rc);
24506537f381Sas200622 }
24516537f381Sas200622 
24526537f381Sas200622 /*
24536537f381Sas200622  * smb_obj_list
24546537f381Sas200622  *
24556537f381Sas200622  * Function called by the DCMDs when no address is provided. It expands the
24566537f381Sas200622  * tree under the object type associated with the calling DCMD (based on the
24576537f381Sas200622  * flags passed in).
24586537f381Sas200622  *
24596537f381Sas200622  * Return Value
24606537f381Sas200622  *
24616537f381Sas200622  *	DCMD_OK
24626537f381Sas200622  *	DCMD_ERR
24636537f381Sas200622  */
24646537f381Sas200622 static int
smb_obj_list(const char * name,uint_t opts,uint_t flags)24656537f381Sas200622 smb_obj_list(const char *name, uint_t opts, uint_t flags)
24666537f381Sas200622 {
24676537f381Sas200622 	int		argc;
24686537f381Sas200622 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
24696537f381Sas200622 
24706537f381Sas200622 	argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, argv);
24716537f381Sas200622 
24726537f381Sas200622 	if (mdb_call_dcmd("smblist", 0, flags, argc, argv)) {
24736537f381Sas200622 		mdb_warn("failed to list %s", name);
24746537f381Sas200622 		return (DCMD_ERR);
24756537f381Sas200622 	}
24766537f381Sas200622 	return (DCMD_OK);
2477da6c28aaSamw }
2478fc724630SAlan Wright 
2479fc724630SAlan Wright static int
smb_worker_findstack(uintptr_t addr)2480fc724630SAlan Wright smb_worker_findstack(uintptr_t addr)
2481fc724630SAlan Wright {
2482fc724630SAlan Wright 	char		cmd[80];
2483fc724630SAlan Wright 	mdb_arg_t	cmdarg;
2484fc724630SAlan Wright 
2485fc724630SAlan Wright 	mdb_inc_indent(2);
2486fc724630SAlan Wright 	mdb_snprintf(cmd, sizeof (cmd), "<.$c%d", 16);
2487fc724630SAlan Wright 	cmdarg.a_type = MDB_TYPE_STRING;
2488fc724630SAlan Wright 	cmdarg.a_un.a_str = cmd;
2489fc724630SAlan Wright 	(void) mdb_call_dcmd("findstack", addr, DCMD_ADDRSPEC, 1, &cmdarg);
2490fc724630SAlan Wright 	mdb_dec_indent(2);
2491fc724630SAlan Wright 	mdb_printf("\n");
2492fc724630SAlan Wright 	return (DCMD_OK);
2493fc724630SAlan Wright }
2494