xref: /titanic_52/usr/src/cmd/mdb/common/modules/smbsrv/smbsrv.c (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
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*a90cf9f2SGordon Ross  * Copyright 2015 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>
30b819cea2SGordon Ross #include <sys/taskq.h>
31da6c28aaSamw #include <smbsrv/smb_vops.h>
32da6c28aaSamw #include <smbsrv/smb.h>
33faa1795aSjb150015 #include <smbsrv/smb_ktypes.h>
34da6c28aaSamw 
35b819cea2SGordon Ross #ifdef _KERNEL
36b819cea2SGordon Ross #define	SMBSRV_OBJNAME	"smbsrv"
37b819cea2SGordon Ross #else
38b819cea2SGordon Ross #define	SMBSRV_OBJNAME	"libfksmbsrv.so.1"
39b819cea2SGordon Ross #endif
40b819cea2SGordon 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 
366*a90cf9f2SGordon Ross static const char *smb2_cmd_names[SMB2__NCMDS] = {
367*a90cf9f2SGordon Ross 	"smb2_negotiate",
368*a90cf9f2SGordon Ross 	"smb2_session_setup",
369*a90cf9f2SGordon Ross 	"smb2_logoff",
370*a90cf9f2SGordon Ross 	"smb2_tree_connect",
371*a90cf9f2SGordon Ross 	"smb2_tree_disconn",
372*a90cf9f2SGordon Ross 	"smb2_create",
373*a90cf9f2SGordon Ross 	"smb2_close",
374*a90cf9f2SGordon Ross 	"smb2_flush",
375*a90cf9f2SGordon Ross 	"smb2_read",
376*a90cf9f2SGordon Ross 	"smb2_write",
377*a90cf9f2SGordon Ross 	"smb2_lock",
378*a90cf9f2SGordon Ross 	"smb2_ioctl",
379*a90cf9f2SGordon Ross 	"smb2_cancel",
380*a90cf9f2SGordon Ross 	"smb2_echo",
381*a90cf9f2SGordon Ross 	"smb2_query_dir",
382*a90cf9f2SGordon Ross 	"smb2_change_notify",
383*a90cf9f2SGordon Ross 	"smb2_query_info",
384*a90cf9f2SGordon Ross 	"smb2_set_info",
385*a90cf9f2SGordon Ross 	"smb2_oplock_break",
386*a90cf9f2SGordon Ross 	"smb2_invalid_cmd"
387*a90cf9f2SGordon Ross };
388*a90cf9f2SGordon Ross 
3896537f381Sas200622 static int smb_dcmd_list(uintptr_t, uint_t, int, const mdb_arg_t *);
3906537f381Sas200622 static void smb_dcmd_list_help(void);
3916537f381Sas200622 static int smb_dcmd_server(uintptr_t, uint_t, int, const mdb_arg_t *);
3926537f381Sas200622 static void smb_dcmd_session_help(void);
3936537f381Sas200622 static int smb_dcmd_session(uintptr_t, uint_t, int, const mdb_arg_t *);
3946537f381Sas200622 static int smb_dcmd_request(uintptr_t, uint_t, int, const mdb_arg_t *);
3956537f381Sas200622 static void smb_dcmd_user_help(void);
3966537f381Sas200622 static int smb_dcmd_user(uintptr_t, uint_t, int, const mdb_arg_t *);
3976537f381Sas200622 static void smb_dcmd_tree_help(void);
3986537f381Sas200622 static int smb_dcmd_tree(uintptr_t, uint_t, int, const mdb_arg_t *);
3996537f381Sas200622 static int smb_dcmd_odir(uintptr_t, uint_t, int, const mdb_arg_t *);
4006537f381Sas200622 static int smb_dcmd_ofile(uintptr_t, uint_t, int, const mdb_arg_t *);
4015a6c34e6SGordon Ross static int smb_dcmd_kshare(uintptr_t, uint_t, int, const mdb_arg_t *);
4025a6c34e6SGordon Ross static int smb_dcmd_vfs(uintptr_t, uint_t, int, const mdb_arg_t *);
403148c5f43SAlan Wright static int smb_vfs_walk_init(mdb_walk_state_t *);
404148c5f43SAlan Wright static int smb_vfs_walk_step(mdb_walk_state_t *);
4056537f381Sas200622 static void smb_node_help(void);
4065a6c34e6SGordon Ross static int smb_dcmd_node(uintptr_t, uint_t, int, const mdb_arg_t *);
4076537f381Sas200622 static int smb_node_walk_init(mdb_walk_state_t *);
4086537f381Sas200622 static int smb_node_walk_step(mdb_walk_state_t *);
4096537f381Sas200622 static int smb_lock(uintptr_t, uint_t, int, const mdb_arg_t *);
410cb174861Sjoyce mcintosh static int smb_oplock(uintptr_t, uint_t, int, const mdb_arg_t *);
411cb174861Sjoyce mcintosh static int smb_oplock_grant(uintptr_t, uint_t, int, const mdb_arg_t *);
4126537f381Sas200622 static int smb_ace(uintptr_t, uint_t, int, const mdb_arg_t *);
4136537f381Sas200622 static int smb_ace_walk_init(mdb_walk_state_t *);
4146537f381Sas200622 static int smb_ace_walk_step(mdb_walk_state_t *);
4156537f381Sas200622 static int smb_acl(uintptr_t, uint_t, int, const mdb_arg_t *);
4166537f381Sas200622 static int smb_sd(uintptr_t, uint_t, int, const mdb_arg_t *);
4176537f381Sas200622 static int smb_sid(uintptr_t, uint_t, int, const mdb_arg_t *);
4186537f381Sas200622 static int smb_sid_print(uintptr_t);
4196537f381Sas200622 static int smb_fssd(uintptr_t, uint_t, int, const mdb_arg_t *);
4206537f381Sas200622 static int smb_dcmd_getopt(uint_t *, int, const mdb_arg_t *);
4216537f381Sas200622 static int smb_dcmd_setopt(uint_t, int, mdb_arg_t *);
4226537f381Sas200622 static int smb_obj_expand(uintptr_t, uint_t, const smb_exp_t *, ulong_t);
4236537f381Sas200622 static int smb_obj_list(const char *, uint_t, uint_t);
424fc724630SAlan Wright static int smb_worker_findstack(uintptr_t);
425148c5f43SAlan Wright static int smb_stats(uintptr_t, uint_t, int, const mdb_arg_t *);
4266537f381Sas200622 
4276537f381Sas200622 /*
4286537f381Sas200622  * MDB module linkage information:
429da6c28aaSamw  *
4306537f381Sas200622  * We declare a list of structures describing our dcmds, a list of structures
4316537f381Sas200622  * describing our walkers and a function named _mdb_init to return a pointer
4326537f381Sas200622  * to our module information.
4336537f381Sas200622  */
4346537f381Sas200622 static const mdb_dcmd_t dcmds[] = {
4356537f381Sas200622 	{   "smblist",
4366537f381Sas200622 	    "[-seutfdwv]",
4376537f381Sas200622 	    "print tree of SMB objects",
4386537f381Sas200622 	    smb_dcmd_list,
4396537f381Sas200622 	    smb_dcmd_list_help },
4406537f381Sas200622 	{   "smbsrv",
4416537f381Sas200622 	    "[-seutfdwv]",
4426537f381Sas200622 	    "print smb_server information",
4436537f381Sas200622 	    smb_dcmd_server },
4445a6c34e6SGordon Ross 	{   "smbshares",
4455a6c34e6SGordon Ross 	    "[-v]",
4465a6c34e6SGordon Ross 	    "print smb_kshare_t information",
4475a6c34e6SGordon Ross 	    smb_dcmd_kshare },
4486537f381Sas200622 	{   "smbvfs",
4496537f381Sas200622 	    "[-v]",
4506537f381Sas200622 	    "print smb_vfs information",
4515a6c34e6SGordon Ross 	    smb_dcmd_vfs },
4526537f381Sas200622 	{   "smbnode",
4536537f381Sas200622 	    "?[-vps]",
4546537f381Sas200622 	    "print smb_node_t information",
4555a6c34e6SGordon Ross 	    smb_dcmd_node,
4566537f381Sas200622 	    smb_node_help },
4576537f381Sas200622 	{   "smbsess",
4586537f381Sas200622 	    "[-utfdwv]",
4596537f381Sas200622 	    "print smb_session_t information",
4606537f381Sas200622 	    smb_dcmd_session,
4616537f381Sas200622 	    smb_dcmd_session_help},
4626537f381Sas200622 	{   "smbreq",
4636537f381Sas200622 	    ":[-v]",
4646537f381Sas200622 	    "print smb_request_t information",
4656537f381Sas200622 	    smb_dcmd_request },
4666537f381Sas200622 	{   "smblock", ":[-v]",
4676537f381Sas200622 	    "print smb_lock_t information", smb_lock },
4686537f381Sas200622 	{   "smbuser",
4696537f381Sas200622 	    ":[-vdftq]",
4706537f381Sas200622 	    "print smb_user_t information",
4716537f381Sas200622 	    smb_dcmd_user,
4726537f381Sas200622 	    smb_dcmd_user_help },
4736537f381Sas200622 	{   "smbtree",
4746537f381Sas200622 	    ":[-vdf]",
4756537f381Sas200622 	    "print smb_tree_t information",
4766537f381Sas200622 	    smb_dcmd_tree,
4776537f381Sas200622 	    smb_dcmd_tree_help },
4786537f381Sas200622 	{   "smbodir",
4796537f381Sas200622 	    ":[-v]",
4806537f381Sas200622 	    "print smb_odir_t information",
4816537f381Sas200622 	    smb_dcmd_odir },
4826537f381Sas200622 	{   "smbofile",
4836537f381Sas200622 	    "[-v]",
484cb174861Sjoyce mcintosh 	    "print smb_file_t information",
4856537f381Sas200622 	    smb_dcmd_ofile },
486cb174861Sjoyce mcintosh 	{   "smboplock", NULL,
487cb174861Sjoyce mcintosh 	    "print smb_oplock_t information", smb_oplock },
488cb174861Sjoyce mcintosh 	{   "smboplockgrant", NULL,
489cb174861Sjoyce mcintosh 	    "print smb_oplock_grant_t information", smb_oplock_grant },
490148c5f43SAlan Wright 	{   "smbstat", NULL,
491148c5f43SAlan Wright 	    "print all smb dispatched requests statistics",
492148c5f43SAlan Wright 	    smb_stats },
4936537f381Sas200622 	{   "smbace", "[-v]",
4946537f381Sas200622 	    "print smb_ace_t information", smb_ace },
4956537f381Sas200622 	{   "smbacl", "[-v]",
4966537f381Sas200622 	    "print smb_acl_t information", smb_acl },
4976537f381Sas200622 	{   "smbsid", "[-v]",
4986537f381Sas200622 	    "print smb_sid_t information", smb_sid },
4996537f381Sas200622 	{   "smbsd", "[-v]",
5006537f381Sas200622 	    "print smb_sd_t information", smb_sd },
5016537f381Sas200622 	{   "smbfssd", "[-v]",
5026537f381Sas200622 	    "print smb_fssd_t information", smb_fssd },
5036537f381Sas200622 	{ NULL }
5046537f381Sas200622 };
5056537f381Sas200622 
5066537f381Sas200622 static const mdb_walker_t walkers[] = {
5076537f381Sas200622 	{   "smbnode_walker",
5086537f381Sas200622 	    "walk list of smb_node_t structures",
5096537f381Sas200622 	    smb_node_walk_init,
5106537f381Sas200622 	    smb_node_walk_step,
5116537f381Sas200622 	    NULL,
5126537f381Sas200622 	    NULL },
513148c5f43SAlan Wright 	{   "smbvfs_walker",
514148c5f43SAlan Wright 	    "walk list of smb_vfs_t structures",
515148c5f43SAlan Wright 	    smb_vfs_walk_init,
516148c5f43SAlan Wright 	    smb_vfs_walk_step,
517148c5f43SAlan Wright 	    NULL,
518148c5f43SAlan Wright 	    NULL },
5196537f381Sas200622 	{   "smbace_walker",
5206537f381Sas200622 	    "walk list of smb_ace_t structures",
5216537f381Sas200622 	    smb_ace_walk_init,
5226537f381Sas200622 	    smb_ace_walk_step,
5236537f381Sas200622 	    NULL,
5246537f381Sas200622 	    NULL },
5256537f381Sas200622 	{ NULL }
5266537f381Sas200622 };
5276537f381Sas200622 
5286537f381Sas200622 static const mdb_modinfo_t modinfo = {
5296537f381Sas200622 	MDB_API_VERSION, dcmds, walkers
5306537f381Sas200622 };
5316537f381Sas200622 
5326537f381Sas200622 const mdb_modinfo_t *
5336537f381Sas200622 _mdb_init(void)
5346537f381Sas200622 {
5356537f381Sas200622 	return (&modinfo);
5366537f381Sas200622 }
5376537f381Sas200622 
5386537f381Sas200622 /*
5396537f381Sas200622  * *****************************************************************************
5406537f381Sas200622  * ****************************** Top level DCMD *******************************
5416537f381Sas200622  * *****************************************************************************
5426537f381Sas200622  */
5436537f381Sas200622 
5446537f381Sas200622 static void
5456537f381Sas200622 smb_dcmd_list_help(void)
5466537f381Sas200622 {
5476537f381Sas200622 	mdb_printf(
5486537f381Sas200622 	    "Displays the list of objects using an indented tree format.\n"
5496537f381Sas200622 	    "If no option is specified the entire tree is displayed\n\n");
5506537f381Sas200622 	(void) mdb_dec_indent(2);
5516537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
5526537f381Sas200622 	(void) mdb_inc_indent(2);
5536537f381Sas200622 	mdb_printf(
5546537f381Sas200622 	    "-v\tDisplay verbose information\n"
5556537f381Sas200622 	    "-s\tDisplay the list of servers\n"
5566537f381Sas200622 	    "-e\tDisplay the list of sessions\n"
5576537f381Sas200622 	    "-r\tDisplay the list of smb requests\n"
5586537f381Sas200622 	    "-u\tDisplay the list of users\n"
5596537f381Sas200622 	    "-t\tDisplay the list of trees\n"
5606537f381Sas200622 	    "-f\tDisplay the list of open files\n"
5616537f381Sas200622 	    "-d\tDisplay the list of open searches\n");
5626537f381Sas200622 }
5636537f381Sas200622 
5646537f381Sas200622 /*
5656537f381Sas200622  * ::smblist
5666537f381Sas200622  *
5676537f381Sas200622  * This function lists the objects specified on the command line. If no object
5686537f381Sas200622  * is specified the entire tree (server through ofile and odir) is displayed.
5696537f381Sas200622  *
570da6c28aaSamw  */
571da6c28aaSamw /*ARGSUSED*/
572da6c28aaSamw static int
5736537f381Sas200622 smb_dcmd_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
574da6c28aaSamw {
5756537f381Sas200622 	GElf_Sym	sym;
5766537f381Sas200622 	uint_t		opts = 0;
5776537f381Sas200622 	int		new_argc;
5786537f381Sas200622 	mdb_arg_t	new_argv[SMB_MDB_MAX_OPTS];
5796537f381Sas200622 
5806537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
5816537f381Sas200622 		return (DCMD_USAGE);
5826537f381Sas200622 
5836537f381Sas200622 	if (!(opts & ~(SMB_OPT_WALK | SMB_OPT_VERBOSE)))
5846537f381Sas200622 		opts |= SMB_OPT_ALL_OBJ;
5856537f381Sas200622 
5866537f381Sas200622 	opts |= SMB_OPT_WALK;
5876537f381Sas200622 
5886537f381Sas200622 	new_argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, new_argv);
5896537f381Sas200622 
590b819cea2SGordon Ross 	if (mdb_lookup_by_obj(SMBSRV_OBJNAME, "smb_servers", &sym) == -1) {
5916537f381Sas200622 		mdb_warn("failed to find symbol smb_servers");
5926537f381Sas200622 		return (DCMD_ERR);
5936537f381Sas200622 	}
5946537f381Sas200622 
595b819cea2SGordon Ross 	addr = (uintptr_t)sym.st_value + OFFSETOF(smb_llist_t, ll_list);
5966537f381Sas200622 
597b819cea2SGordon Ross 	if (mdb_pwalk_dcmd("list", "smbsrv", new_argc, new_argv, addr)) {
598b819cea2SGordon Ross 		mdb_warn("cannot walk smb_server list");
5996537f381Sas200622 		return (DCMD_ERR);
600b819cea2SGordon Ross 	}
6016537f381Sas200622 	return (DCMD_OK);
6026537f381Sas200622 }
6036537f381Sas200622 
6046537f381Sas200622 /*
6056537f381Sas200622  * *****************************************************************************
6066537f381Sas200622  * ***************************** smb_server_t **********************************
6076537f381Sas200622  * *****************************************************************************
6086537f381Sas200622  */
6096537f381Sas200622 
6106537f381Sas200622 static const char *smb_server_state[SMB_SERVER_STATE_SENTINEL] =
6116537f381Sas200622 {
6126537f381Sas200622 	"CREATED",
6136537f381Sas200622 	"CONFIGURED",
6146537f381Sas200622 	"RUNNING",
6159fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"STOPPING",
6166537f381Sas200622 	"DELETING"
6176537f381Sas200622 };
6186537f381Sas200622 
6196537f381Sas200622 /*
6206537f381Sas200622  * List of objects that can be expanded under a server structure.
6216537f381Sas200622  */
6226537f381Sas200622 static const smb_exp_t smb_server_exp[] =
6236537f381Sas200622 {
6246537f381Sas200622 	{ SMB_OPT_ALL_OBJ,
625b819cea2SGordon Ross 	    OFFSETOF(smb_server_t, sv_nbt_daemon.ld_session_list.ll_list),
6266537f381Sas200622 	    "smbsess", "smb_session"},
6276537f381Sas200622 	{ SMB_OPT_ALL_OBJ,
628b819cea2SGordon Ross 	    OFFSETOF(smb_server_t, sv_tcp_daemon.ld_session_list.ll_list),
6296537f381Sas200622 	    "smbsess", "smb_session"},
6306537f381Sas200622 	{ 0, 0, NULL, NULL }
6316537f381Sas200622 };
6326537f381Sas200622 
6336537f381Sas200622 /*
6346537f381Sas200622  * ::smbsrv
6356537f381Sas200622  *
6366537f381Sas200622  * smbsrv dcmd - Print out smb_server structures.
6376537f381Sas200622  */
6386537f381Sas200622 /*ARGSUSED*/
6396537f381Sas200622 static int
6406537f381Sas200622 smb_dcmd_server(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
6416537f381Sas200622 {
6426537f381Sas200622 	uint_t		opts;
6436537f381Sas200622 	ulong_t		indent = 0;
6446537f381Sas200622 
6456537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
6466537f381Sas200622 		return (DCMD_USAGE);
6476537f381Sas200622 
6486537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
6496537f381Sas200622 		return (smb_obj_list("smb_server", opts | SMB_OPT_SERVER,
6506537f381Sas200622 		    flags));
6516537f381Sas200622 
6526537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SERVER)) ||
6536537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
654faa1795aSjb150015 		smb_server_t	*sv;
6556537f381Sas200622 		const char	*state;
656da6c28aaSamw 
6576537f381Sas200622 		sv = mdb_alloc(sizeof (smb_server_t), UM_SLEEP | UM_GC);
6586537f381Sas200622 		if (mdb_vread(sv, sizeof (smb_server_t), addr) == -1) {
6596537f381Sas200622 			mdb_warn("failed to read smb_server at %p", addr);
660da6c28aaSamw 			return (DCMD_ERR);
661da6c28aaSamw 		}
662da6c28aaSamw 
6636537f381Sas200622 		indent = SMB_DCMD_INDENT;
6646537f381Sas200622 
6656537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
6666537f381Sas200622 			mdb_arg_t	argv;
6676537f381Sas200622 
6686537f381Sas200622 			argv.a_type = MDB_TYPE_STRING;
6696537f381Sas200622 			argv.a_un.a_str = "smb_server_t";
6706537f381Sas200622 			if (mdb_call_dcmd("print", addr, flags, 1, &argv))
671faa1795aSjb150015 				return (DCMD_ERR);
6726537f381Sas200622 		} else {
6736537f381Sas200622 			if (DCMD_HDRSPEC(flags))
6746537f381Sas200622 				mdb_printf(
6756537f381Sas200622 				    "%<b>%<u>%-?s% "
6766537f381Sas200622 				    "%-4s% "
6776537f381Sas200622 				    "%-32s% "
678148c5f43SAlan Wright 				    "%</u>%</b>\n",
679148c5f43SAlan Wright 				    "SERVER", "ZONE", "STATE");
6806537f381Sas200622 
6816537f381Sas200622 			if (sv->sv_state >= SMB_SERVER_STATE_SENTINEL)
6826537f381Sas200622 				state = "UNKNOWN";
6836537f381Sas200622 			else
6846537f381Sas200622 				state = smb_server_state[sv->sv_state];
6856537f381Sas200622 
686148c5f43SAlan Wright 			mdb_printf("%-?p %-4d %-32s \n",
687148c5f43SAlan Wright 			    addr, sv->sv_zid, state);
688faa1795aSjb150015 		}
6896537f381Sas200622 	}
6906537f381Sas200622 	if (smb_obj_expand(addr, opts, smb_server_exp, indent))
6916537f381Sas200622 		return (DCMD_ERR);
692faa1795aSjb150015 	return (DCMD_OK);
693faa1795aSjb150015 }
694faa1795aSjb150015 
6956537f381Sas200622 /*
6966537f381Sas200622  * *****************************************************************************
6976537f381Sas200622  * ***************************** smb_session_t *********************************
6986537f381Sas200622  * *****************************************************************************
6996537f381Sas200622  */
7006537f381Sas200622 
7016537f381Sas200622 static const char *smb_session_state[SMB_SESSION_STATE_SENTINEL] =
7026537f381Sas200622 {
7036537f381Sas200622 	"INITIALIZED",
7046537f381Sas200622 	"DISCONNECTED",
7056537f381Sas200622 	"CONNECTED",
7066537f381Sas200622 	"ESTABLISHED",
7076537f381Sas200622 	"NEGOTIATED",
7086537f381Sas200622 	"TERMINATED"
7096537f381Sas200622 };
7106537f381Sas200622 
7116537f381Sas200622 /*
7126537f381Sas200622  * List of objects that can be expanded under a session structure.
7136537f381Sas200622  */
7146537f381Sas200622 static const smb_exp_t smb_session_exp[] =
7156537f381Sas200622 {
7166537f381Sas200622 	{ SMB_OPT_REQUEST,
717b819cea2SGordon Ross 	    OFFSETOF(smb_session_t, s_req_list.sl_list),
7186537f381Sas200622 	    "smbreq", "smb_request"},
7193b13a1efSThomas Keiser 	{ SMB_OPT_USER,
720b819cea2SGordon Ross 	    OFFSETOF(smb_session_t, s_user_list.ll_list),
7216537f381Sas200622 	    "smbuser", "smb_user"},
7223b13a1efSThomas Keiser 	{ SMB_OPT_TREE | SMB_OPT_OFILE | SMB_OPT_ODIR,
723b819cea2SGordon Ross 	    OFFSETOF(smb_session_t, s_tree_list.ll_list),
7243b13a1efSThomas Keiser 	    "smbtree", "smb_tree"},
7256537f381Sas200622 	{ 0, 0, NULL, NULL}
7266537f381Sas200622 };
7276537f381Sas200622 
728da6c28aaSamw static void
7296537f381Sas200622 smb_dcmd_session_help(void)
730da6c28aaSamw {
7316537f381Sas200622 	mdb_printf(
7326537f381Sas200622 	    "Display the contents of smb_session_t, with optional"
7336537f381Sas200622 	    " filtering.\n\n");
7346537f381Sas200622 	(void) mdb_dec_indent(2);
7356537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
7366537f381Sas200622 	(void) mdb_inc_indent(2);
7376537f381Sas200622 	mdb_printf(
7386537f381Sas200622 	    "-v\tDisplay verbose smb_session information\n"
7396537f381Sas200622 	    "-r\tDisplay the list of smb requests attached\n"
7406537f381Sas200622 	    "-u\tDisplay the list of users attached\n");
741da6c28aaSamw }
742da6c28aaSamw 
7436537f381Sas200622 /*
7446537f381Sas200622  * ::smbsess
7456537f381Sas200622  *
7466537f381Sas200622  * smbsess dcmd - Print out the smb_session structure.
7476537f381Sas200622  */
7486537f381Sas200622 static int
7496537f381Sas200622 smb_dcmd_session(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7506537f381Sas200622 {
7516537f381Sas200622 	uint_t		opts;
7526537f381Sas200622 	ulong_t		indent = 0;
7536537f381Sas200622 
7546537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
7556537f381Sas200622 		return (DCMD_USAGE);
7566537f381Sas200622 
7576537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
7586537f381Sas200622 		opts |= SMB_OPT_SESSION;
7596537f381Sas200622 		opts &= ~SMB_OPT_SERVER;
7606537f381Sas200622 		return (smb_obj_list("smb_session", opts, flags));
7616537f381Sas200622 	}
7626537f381Sas200622 
7636537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SESSION)) ||
7646537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
765*a90cf9f2SGordon Ross 		char	cipaddr[INET6_ADDRSTRLEN];
766*a90cf9f2SGordon Ross 		char	lipaddr[INET6_ADDRSTRLEN];
767*a90cf9f2SGordon Ross 		int	ipaddrstrlen;
7686537f381Sas200622 		smb_session_t	*se;
7696537f381Sas200622 		const char	*state;
7706537f381Sas200622 
7716537f381Sas200622 		indent = SMB_DCMD_INDENT;
7726537f381Sas200622 
7736537f381Sas200622 		se = mdb_alloc(sizeof (*se), UM_SLEEP | UM_GC);
7746537f381Sas200622 		if (mdb_vread(se, sizeof (*se), addr) == -1) {
7756537f381Sas200622 			mdb_warn("failed to read smb_session at %p", addr);
7766537f381Sas200622 			return (DCMD_ERR);
7776537f381Sas200622 		}
7786537f381Sas200622 		if (se->s_state >= SMB_SESSION_STATE_SENTINEL)
7796537f381Sas200622 			state = "INVALID";
7806537f381Sas200622 		else
7816537f381Sas200622 			state = smb_session_state[se->s_state];
7826537f381Sas200622 
78341610d10SYuri Pankov 		switch (se->ipaddr.a_family) {
78441610d10SYuri Pankov 		case AF_INET:
78541610d10SYuri Pankov 			ipaddrstrlen = INET_ADDRSTRLEN;
78641610d10SYuri Pankov 			(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
78741610d10SYuri Pankov 			    "%I", se->ipaddr.a_ipv4);
78841610d10SYuri Pankov 			(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
78941610d10SYuri Pankov 			    "%I", se->local_ipaddr.a_ipv4);
79041610d10SYuri Pankov 			break;
79141610d10SYuri Pankov 		case AF_INET6:
79241610d10SYuri Pankov 			ipaddrstrlen = INET6_ADDRSTRLEN;
79341610d10SYuri Pankov 			(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
79441610d10SYuri Pankov 			    "%N", &(se->ipaddr.a_ipv6));
79541610d10SYuri Pankov 			(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
79641610d10SYuri Pankov 			    "%N", &(se->local_ipaddr.a_ipv6));
79741610d10SYuri Pankov 			break;
79841610d10SYuri Pankov 		default:
79941610d10SYuri Pankov 			ipaddrstrlen = INET_ADDRSTRLEN;
80041610d10SYuri Pankov 			(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
80141610d10SYuri Pankov 			    "unknown");
80241610d10SYuri Pankov 			(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
80341610d10SYuri Pankov 			    "unknown");
80441610d10SYuri Pankov 		}
80541610d10SYuri Pankov 
806*a90cf9f2SGordon Ross 		if (opts & SMB_OPT_VERBOSE) {
807*a90cf9f2SGordon Ross 			mdb_printf("%<b>%<u>SMB session information "
808*a90cf9f2SGordon Ross 			    "(%p): %</u>%</b>\n", addr);
809*a90cf9f2SGordon Ross 			mdb_printf("Client IP address: %s %d\n",
810*a90cf9f2SGordon Ross 			    cipaddr, se->s_remote_port);
811*a90cf9f2SGordon Ross 			mdb_printf("Local IP Address: %s %d\n",
812*a90cf9f2SGordon Ross 			    lipaddr, se->s_local_port);
813*a90cf9f2SGordon Ross 			mdb_printf("Session KID: %u\n", se->s_kid);
814*a90cf9f2SGordon Ross 			mdb_printf("Workstation Name: %s\n",
815*a90cf9f2SGordon Ross 			    se->workstation);
816*a90cf9f2SGordon Ross 			mdb_printf("Session state: %u (%s)\n", se->s_state,
817*a90cf9f2SGordon Ross 			    state);
818*a90cf9f2SGordon Ross 			mdb_printf("Session dialect: %#x\n", se->dialect);
819*a90cf9f2SGordon Ross 			mdb_printf("Number of Users: %u\n",
820*a90cf9f2SGordon Ross 			    se->s_user_list.ll_count);
821*a90cf9f2SGordon Ross 			mdb_printf("Number of Trees: %u\n", se->s_tree_cnt);
822*a90cf9f2SGordon Ross 			mdb_printf("Number of Files: %u\n", se->s_file_cnt);
823*a90cf9f2SGordon Ross 			mdb_printf("Number of Shares: %u\n", se->s_dir_cnt);
824*a90cf9f2SGordon Ross 			mdb_printf("Number of active Transact.: %u\n\n",
825*a90cf9f2SGordon Ross 			    se->s_xa_list.ll_count);
826*a90cf9f2SGordon Ross 		} else {
82741610d10SYuri Pankov 			if (DCMD_HDRSPEC(flags)) {
8286537f381Sas200622 				mdb_printf(
829*a90cf9f2SGordon Ross 			"%<b>%<u>%-?s %-*s %-8s %-8s %-12s%</u>%</b>\n",
830*a90cf9f2SGordon Ross 				    "SESSION", ipaddrstrlen, "IP_ADDR",
831*a90cf9f2SGordon Ross 				    "PORT", "DIALECT", "STATE");
83241610d10SYuri Pankov 			}
833*a90cf9f2SGordon Ross 			mdb_printf("%-?p %-*s %-8d %-8#x %s\n",
834*a90cf9f2SGordon Ross 			    addr, ipaddrstrlen, cipaddr,
835*a90cf9f2SGordon Ross 			    se->s_remote_port, se->dialect, state);
836da6c28aaSamw 		}
837da6c28aaSamw 	}
8386537f381Sas200622 	if (smb_obj_expand(addr, opts, smb_session_exp, indent))
8396537f381Sas200622 		return (DCMD_ERR);
8406537f381Sas200622 	return (DCMD_OK);
841da6c28aaSamw }
842da6c28aaSamw 
8436537f381Sas200622 /*
8446537f381Sas200622  * *****************************************************************************
8456537f381Sas200622  * **************************** smb_request_t **********************************
8466537f381Sas200622  * *****************************************************************************
8476537f381Sas200622  */
8486537f381Sas200622 
8496537f381Sas200622 static const char *smb_request_state[SMB_REQ_STATE_SENTINEL] =
8506537f381Sas200622 {
8516537f381Sas200622 	"FREE",
8526537f381Sas200622 	"INITIALIZING",
8536537f381Sas200622 	"SUBMITTED",
8546537f381Sas200622 	"ACTIVE",
8556537f381Sas200622 	"WAITING_EVENT",
8566537f381Sas200622 	"EVENT_OCCURRED",
8576537f381Sas200622 	"WAITING_LOCK",
8586537f381Sas200622 	"COMPLETED",
8596537f381Sas200622 	"CANCELED",
8606537f381Sas200622 	"CLEANED_UP"
8616537f381Sas200622 };
8626537f381Sas200622 
863148c5f43SAlan Wright #define	SMB_REQUEST_BANNER	\
864148c5f43SAlan Wright 	"%<b>%<u>%-?s %-?s %-14s %-14s %-16s %-32s%</u>%</b>\n"
865148c5f43SAlan Wright #define	SMB_REQUEST_FORMAT	\
866cb174861Sjoyce mcintosh 	"%-?p %-?p %-14lld %-14lld %-16s %s\n"
867148c5f43SAlan Wright 
8686537f381Sas200622 static int
8696537f381Sas200622 smb_dcmd_request(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
8706537f381Sas200622 {
8716537f381Sas200622 	uint_t		opts;
8726537f381Sas200622 
8736537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
8746537f381Sas200622 		return (DCMD_USAGE);
8756537f381Sas200622 
8766537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
8776537f381Sas200622 		opts |= SMB_OPT_REQUEST;
8786537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_USER);
8796537f381Sas200622 		return (smb_obj_list("smb_request", opts, flags));
8806537f381Sas200622 	}
8816537f381Sas200622 
8826537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_REQUEST)) ||
8836537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
8846537f381Sas200622 		smb_request_t	*sr;
8856537f381Sas200622 		const char	*state;
886*a90cf9f2SGordon Ross 		const char	*cur_cmd_name;
887*a90cf9f2SGordon Ross 		uint_t		cur_cmd_code;
888148c5f43SAlan Wright 		uint64_t	waiting;
889148c5f43SAlan Wright 		uint64_t	running;
8906537f381Sas200622 
8916537f381Sas200622 		sr = mdb_alloc(sizeof (*sr), UM_SLEEP | UM_GC);
8926537f381Sas200622 		if (mdb_vread(sr, sizeof (*sr), addr) == -1) {
8936537f381Sas200622 			mdb_warn("failed to read smb_request at %p", addr);
8946537f381Sas200622 			return (DCMD_ERR);
8956537f381Sas200622 		}
896148c5f43SAlan Wright 		if (sr->sr_magic != SMB_REQ_MAGIC) {
897148c5f43SAlan Wright 			mdb_warn("not an smb_request_t (%p)>", addr);
898148c5f43SAlan Wright 			return (DCMD_ERR);
899148c5f43SAlan Wright 		}
900148c5f43SAlan Wright 		waiting = 0;
901148c5f43SAlan Wright 		running = 0;
902b819cea2SGordon Ross 		/*
903b819cea2SGordon Ross 		 * Note: mdb_gethrtime() is only available in kmdb
904b819cea2SGordon Ross 		 */
905b819cea2SGordon Ross #ifdef	_KERNEL
906148c5f43SAlan Wright 		if (sr->sr_time_submitted != 0) {
907148c5f43SAlan Wright 			if (sr->sr_time_active != 0) {
908148c5f43SAlan Wright 				waiting = sr->sr_time_active -
909148c5f43SAlan Wright 				    sr->sr_time_submitted;
910148c5f43SAlan Wright 				running = mdb_gethrtime() -
911148c5f43SAlan Wright 				    sr->sr_time_active;
912148c5f43SAlan Wright 			} else {
913148c5f43SAlan Wright 				waiting = mdb_gethrtime() -
914148c5f43SAlan Wright 				    sr->sr_time_submitted;
915148c5f43SAlan Wright 			}
916148c5f43SAlan Wright 		}
917148c5f43SAlan Wright 		waiting /= NANOSEC;
918148c5f43SAlan Wright 		running /= NANOSEC;
919b819cea2SGordon Ross #endif	/* _KERNEL */
9206537f381Sas200622 
9216537f381Sas200622 		if (sr->sr_state >= SMB_REQ_STATE_SENTINEL)
9226537f381Sas200622 			state = "INVALID";
9236537f381Sas200622 		else
9246537f381Sas200622 			state = smb_request_state[sr->sr_state];
9256537f381Sas200622 
926*a90cf9f2SGordon Ross 		if (sr->smb2_cmd_code != 0) {
927*a90cf9f2SGordon Ross 			/* SMB2 request */
928*a90cf9f2SGordon Ross 			cur_cmd_code = sr->smb2_cmd_code;
929*a90cf9f2SGordon Ross 			if (cur_cmd_code > SMB2_INVALID_CMD)
930*a90cf9f2SGordon Ross 				cur_cmd_code = SMB2_INVALID_CMD;
931*a90cf9f2SGordon Ross 			cur_cmd_name = smb2_cmd_names[cur_cmd_code];
932*a90cf9f2SGordon Ross 		} else {
933*a90cf9f2SGordon Ross 			/* SMB1 request */
934*a90cf9f2SGordon Ross 			cur_cmd_code = sr->smb_com & 0xFF;
935*a90cf9f2SGordon Ross 			cur_cmd_name = smb_com[cur_cmd_code].smb_com;
936*a90cf9f2SGordon Ross 		}
937*a90cf9f2SGordon Ross 
9386537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
9396537f381Sas200622 			mdb_printf(
940fc724630SAlan Wright 			    "%</b>%</u>SMB request information (%p):"
9416537f381Sas200622 			    "%</u>%</b>\n\n", addr);
942148c5f43SAlan Wright 
943*a90cf9f2SGordon Ross 			if (sr->smb2_cmd_code == 0) {
944*a90cf9f2SGordon Ross 				/* SMB1 request */
945148c5f43SAlan Wright 				mdb_printf(
946*a90cf9f2SGordon Ross 				    "first SMB COM: %u (%s)\n",
947cb174861Sjoyce mcintosh 				    sr->first_smb_com,
948*a90cf9f2SGordon Ross 				    smb_com[sr->first_smb_com].smb_com);
949*a90cf9f2SGordon Ross 			}
950*a90cf9f2SGordon Ross 
951*a90cf9f2SGordon Ross 			mdb_printf(
952*a90cf9f2SGordon Ross 			    "current SMB COM: %u (%s)\n",
953*a90cf9f2SGordon Ross 			    cur_cmd_code, cur_cmd_name);
954*a90cf9f2SGordon Ross 
955*a90cf9f2SGordon Ross 			mdb_printf(
956*a90cf9f2SGordon Ross 			    "state: %u (%s)\n",
957*a90cf9f2SGordon Ross 			    sr->sr_state, state);
958*a90cf9f2SGordon Ross 
959*a90cf9f2SGordon Ross 			mdb_printf(
960*a90cf9f2SGordon Ross 			    "TID(tree): %u (%p)\n",
961*a90cf9f2SGordon Ross 			    sr->smb_tid, sr->tid_tree);
962*a90cf9f2SGordon Ross 
963*a90cf9f2SGordon Ross 			mdb_printf(
964*a90cf9f2SGordon Ross 			    "UID(user): %u (%p)\n",
965*a90cf9f2SGordon Ross 			    sr->smb_uid, sr->uid_user);
966*a90cf9f2SGordon Ross 
967*a90cf9f2SGordon Ross 			mdb_printf(
968*a90cf9f2SGordon Ross 			    "FID(file): %u (%p)\n",
969*a90cf9f2SGordon Ross 			    sr->smb_fid, sr->fid_ofile);
970*a90cf9f2SGordon Ross 
971*a90cf9f2SGordon Ross 			mdb_printf(
972*a90cf9f2SGordon Ross 			    "PID: %u\n",
973*a90cf9f2SGordon Ross 			    sr->smb_pid);
974*a90cf9f2SGordon Ross 
975*a90cf9f2SGordon Ross 			if (sr->smb2_messageid != 0) {
976*a90cf9f2SGordon Ross 				mdb_printf(
977*a90cf9f2SGordon Ross 				    "MID: 0x%llx\n\n",
978*a90cf9f2SGordon Ross 				    sr->smb2_messageid);
979*a90cf9f2SGordon Ross 			} else {
980*a90cf9f2SGordon Ross 				mdb_printf(
981*a90cf9f2SGordon Ross 				    "MID: %u\n\n",
982*a90cf9f2SGordon Ross 				    sr->smb_mid);
983*a90cf9f2SGordon Ross 			}
984*a90cf9f2SGordon Ross 
985*a90cf9f2SGordon Ross 			mdb_printf(
986*a90cf9f2SGordon Ross 			    "waiting time: %lld\n",
987*a90cf9f2SGordon Ross 			    waiting);
988*a90cf9f2SGordon Ross 
989*a90cf9f2SGordon Ross 			mdb_printf(
990*a90cf9f2SGordon Ross 			    "running time: %lld\n",
991148c5f43SAlan Wright 			    running);
992148c5f43SAlan Wright 
993*a90cf9f2SGordon Ross 			mdb_printf(
994*a90cf9f2SGordon Ross 			    "worker thread: %p\n",
995*a90cf9f2SGordon Ross 			    sr->sr_worker);
996fc724630SAlan Wright 			smb_worker_findstack((uintptr_t)sr->sr_worker);
9976537f381Sas200622 		} else {
9986537f381Sas200622 			if (DCMD_HDRSPEC(flags))
9996537f381Sas200622 				mdb_printf(
1000148c5f43SAlan Wright 				    SMB_REQUEST_BANNER,
1001148c5f43SAlan Wright 				    "ADDR",
1002148c5f43SAlan Wright 				    "WORKER",
1003148c5f43SAlan Wright 				    "WAITING(s)",
1004148c5f43SAlan Wright 				    "RUNNING(s)",
1005148c5f43SAlan Wright 				    "STATE",
1006148c5f43SAlan Wright 				    "COMMAND");
10076537f381Sas200622 
1008*a90cf9f2SGordon Ross 			mdb_printf(
1009*a90cf9f2SGordon Ross 			    SMB_REQUEST_FORMAT,
1010148c5f43SAlan Wright 			    addr,
1011148c5f43SAlan Wright 			    sr->sr_worker,
1012148c5f43SAlan Wright 			    waiting,
1013148c5f43SAlan Wright 			    running,
1014148c5f43SAlan Wright 			    state,
1015*a90cf9f2SGordon Ross 			    cur_cmd_name);
10166537f381Sas200622 		}
10176537f381Sas200622 	}
10186537f381Sas200622 	return (DCMD_OK);
10196537f381Sas200622 }
10206537f381Sas200622 
10216537f381Sas200622 /*
10226537f381Sas200622  * *****************************************************************************
10236537f381Sas200622  * ****************************** smb_user_t ***********************************
10246537f381Sas200622  * *****************************************************************************
10256537f381Sas200622  */
10266537f381Sas200622 
10276537f381Sas200622 static const char *smb_user_state[SMB_USER_STATE_SENTINEL] =
10286537f381Sas200622 {
102912b65585SGordon Ross 	"LOGGING_ON",
103012b65585SGordon Ross 	"LOGGED_ON",
10316537f381Sas200622 	"LOGGING_OFF",
10326537f381Sas200622 	"LOGGED_OFF"
10336537f381Sas200622 };
10346537f381Sas200622 
10356537f381Sas200622 static void
10366537f381Sas200622 smb_dcmd_user_help(void)
10376537f381Sas200622 {
10386537f381Sas200622 	mdb_printf(
10396537f381Sas200622 	    "Display the contents of smb_user_t, with optional filtering.\n\n");
10406537f381Sas200622 	(void) mdb_dec_indent(2);
10416537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
10426537f381Sas200622 	(void) mdb_inc_indent(2);
10436537f381Sas200622 	mdb_printf(
10443b13a1efSThomas Keiser 	    "-v\tDisplay verbose smb_user information\n");
10456537f381Sas200622 }
10466537f381Sas200622 
10476537f381Sas200622 static int
10486537f381Sas200622 smb_dcmd_user(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
10496537f381Sas200622 {
10506537f381Sas200622 	uint_t		opts;
10516537f381Sas200622 
10526537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
10536537f381Sas200622 		return (DCMD_USAGE);
10546537f381Sas200622 
10556537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
10566537f381Sas200622 		opts |= SMB_OPT_USER;
10576537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST);
10586537f381Sas200622 		return (smb_obj_list("smb_user", opts, flags));
10596537f381Sas200622 	}
10606537f381Sas200622 
10616537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_USER)) ||
10626537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
10636537f381Sas200622 		smb_user_t	*user;
10646537f381Sas200622 		char		*account;
10656537f381Sas200622 
10666537f381Sas200622 		user = mdb_alloc(sizeof (*user), UM_SLEEP | UM_GC);
10676537f381Sas200622 		if (mdb_vread(user, sizeof (*user), addr) == -1) {
10686537f381Sas200622 			mdb_warn("failed to read smb_user at %p", addr);
10696537f381Sas200622 			return (DCMD_ERR);
10706537f381Sas200622 		}
10716537f381Sas200622 		account = mdb_zalloc(user->u_domain_len + user->u_name_len + 2,
10726537f381Sas200622 		    UM_SLEEP | UM_GC);
10736537f381Sas200622 
10746537f381Sas200622 		if (user->u_domain_len)
10756537f381Sas200622 			(void) mdb_vread(account, user->u_domain_len,
10766537f381Sas200622 			    (uintptr_t)user->u_domain);
10776537f381Sas200622 
10786537f381Sas200622 		strcat(account, "\\");
10796537f381Sas200622 
10806537f381Sas200622 		if (user->u_name_len)
10816537f381Sas200622 			(void) mdb_vread(account + strlen(account),
10826537f381Sas200622 			    user->u_name_len, (uintptr_t)user->u_name);
10836537f381Sas200622 
10846537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
10856537f381Sas200622 			const char	*state;
10866537f381Sas200622 
10876537f381Sas200622 			if (user->u_state >= SMB_USER_STATE_SENTINEL)
10886537f381Sas200622 				state = "INVALID";
10896537f381Sas200622 			else
10906537f381Sas200622 				state = smb_user_state[user->u_state];
10916537f381Sas200622 
10926537f381Sas200622 			mdb_printf("%<b>%<u>SMB user information (%p):"
10936537f381Sas200622 			    "%</u>%</b>\n", addr);
10946537f381Sas200622 			mdb_printf("UID: %u\n", user->u_uid);
10956537f381Sas200622 			mdb_printf("State: %d (%s)\n", user->u_state, state);
10966537f381Sas200622 			mdb_printf("Flags: 0x%08x\n", user->u_flags);
10976537f381Sas200622 			mdb_printf("Privileges: 0x%08x\n", user->u_privileges);
10986537f381Sas200622 			mdb_printf("Credential: %p\n", user->u_cred);
10996537f381Sas200622 			mdb_printf("Reference Count: %d\n", user->u_refcnt);
11006537f381Sas200622 			mdb_printf("User Account: %s\n\n", account);
11016537f381Sas200622 		} else {
11026537f381Sas200622 			if (DCMD_HDRSPEC(flags))
11036537f381Sas200622 				mdb_printf(
11046537f381Sas200622 				    "%<b>%<u>%?-s "
11056537f381Sas200622 				    "%-5s "
11066537f381Sas200622 				    "%-32s%</u>%</b>\n",
11076537f381Sas200622 				    "USER", "UID", "ACCOUNT");
11086537f381Sas200622 
11096537f381Sas200622 			mdb_printf("%-?p %-5u %-32s\n", addr, user->u_uid,
11106537f381Sas200622 			    account);
11116537f381Sas200622 		}
11126537f381Sas200622 	}
11136537f381Sas200622 	return (DCMD_OK);
11146537f381Sas200622 }
11156537f381Sas200622 
11166537f381Sas200622 /*
11176537f381Sas200622  * *****************************************************************************
11186537f381Sas200622  * ****************************** smb_tree_t ***********************************
11196537f381Sas200622  * *****************************************************************************
11206537f381Sas200622  */
11216537f381Sas200622 
11226537f381Sas200622 static const char *smb_tree_state[SMB_TREE_STATE_SENTINEL] =
11236537f381Sas200622 {
11246537f381Sas200622 	"CONNECTED",
11256537f381Sas200622 	"DISCONNECTING",
11266537f381Sas200622 	"DISCONNECTED"
11276537f381Sas200622 };
11286537f381Sas200622 
11296537f381Sas200622 /*
11306537f381Sas200622  * List of objects that can be expanded under a tree structure.
11316537f381Sas200622  */
11326537f381Sas200622 static const smb_exp_t smb_tree_exp[] =
11336537f381Sas200622 {
11346537f381Sas200622 	{ SMB_OPT_OFILE,
1135b819cea2SGordon Ross 	    OFFSETOF(smb_tree_t, t_ofile_list.ll_list),
11366537f381Sas200622 	    "smbofile", "smb_ofile"},
11376537f381Sas200622 	{ SMB_OPT_ODIR,
1138b819cea2SGordon Ross 	    OFFSETOF(smb_tree_t, t_odir_list.ll_list),
11396537f381Sas200622 	    "smbodir", "smb_odir"},
11406537f381Sas200622 	{ 0, 0, NULL, NULL}
11416537f381Sas200622 };
11426537f381Sas200622 
11436537f381Sas200622 static void
11446537f381Sas200622 smb_dcmd_tree_help(void)
11456537f381Sas200622 {
11466537f381Sas200622 	mdb_printf(
11476537f381Sas200622 	    "Display the contents of smb_tree_t, with optional filtering.\n\n");
11486537f381Sas200622 	(void) mdb_dec_indent(2);
11496537f381Sas200622 	mdb_printf("%<b>OPTIONS%</b>\n");
11506537f381Sas200622 	(void) mdb_inc_indent(2);
11516537f381Sas200622 	mdb_printf(
11526537f381Sas200622 	    "-v\tDisplay verbose smb_tree information\n"
11536537f381Sas200622 	    "-d\tDisplay the list of smb_odirs attached\n"
11546537f381Sas200622 	    "-f\tDisplay the list of smb_ofiles attached\n");
11556537f381Sas200622 }
11566537f381Sas200622 
11576537f381Sas200622 static int
11586537f381Sas200622 smb_dcmd_tree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
11596537f381Sas200622 {
11606537f381Sas200622 	uint_t		opts;
11616537f381Sas200622 	ulong_t		indent = 0;
11626537f381Sas200622 
11636537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
11646537f381Sas200622 		return (DCMD_USAGE);
11656537f381Sas200622 
11666537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
11676537f381Sas200622 		opts |= SMB_OPT_TREE;
11686537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
11696537f381Sas200622 		    SMB_OPT_USER);
11706537f381Sas200622 		return (smb_obj_list("smb_tree", opts, flags));
11716537f381Sas200622 	}
11726537f381Sas200622 
11736537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_TREE)) ||
11746537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
11756537f381Sas200622 		smb_tree_t	*tree;
11766537f381Sas200622 
11776537f381Sas200622 		indent = SMB_DCMD_INDENT;
11786537f381Sas200622 
11796537f381Sas200622 		tree = mdb_alloc(sizeof (*tree), UM_SLEEP | UM_GC);
11806537f381Sas200622 		if (mdb_vread(tree, sizeof (*tree), addr) == -1) {
11816537f381Sas200622 			mdb_warn("failed to read smb_tree at %p", addr);
11826537f381Sas200622 			return (DCMD_ERR);
11836537f381Sas200622 		}
11846537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
11856537f381Sas200622 			const char	*state;
11866537f381Sas200622 
11876537f381Sas200622 			if (tree->t_state >= SMB_TREE_STATE_SENTINEL)
11886537f381Sas200622 				state = "INVALID";
11896537f381Sas200622 			else
11906537f381Sas200622 				state = smb_tree_state[tree->t_state];
11916537f381Sas200622 
11926537f381Sas200622 			mdb_printf("%<b>%<u>SMB tree information (%p):"
11936537f381Sas200622 			    "%</u>%</b>\n\n", addr);
11946537f381Sas200622 			mdb_printf("TID: %04x\n", tree->t_tid);
11956537f381Sas200622 			mdb_printf("State: %d (%s)\n", tree->t_state, state);
1196c8ec8eeaSjose borrego 			mdb_printf("Share: %s\n", tree->t_sharename);
11976537f381Sas200622 			mdb_printf("Resource: %s\n", tree->t_resource);
1198c8ec8eeaSjose borrego 			mdb_printf("Type: %s\n", tree->t_typename);
1199c8ec8eeaSjose borrego 			mdb_printf("Volume: %s\n", tree->t_volume);
12006537f381Sas200622 			mdb_printf("Umask: %04x\n", tree->t_umask);
12016537f381Sas200622 			mdb_printf("Flags: %08x\n", tree->t_flags);
12026537f381Sas200622 			mdb_printf("SMB Node: %llx\n", tree->t_snode);
12036537f381Sas200622 			mdb_printf("Reference Count: %d\n\n", tree->t_refcnt);
12046537f381Sas200622 		} else {
12056537f381Sas200622 			if (DCMD_HDRSPEC(flags))
12066537f381Sas200622 				mdb_printf(
12076537f381Sas200622 				    "%<b>%<u>%-?s %-5s %-16s %-32s%</u>%</b>\n",
12086537f381Sas200622 				    "TREE", "TID", "SHARE NAME", "RESOURCE");
12096537f381Sas200622 
12106537f381Sas200622 			mdb_printf("%-?p %-5u %-16s %-32s\n", addr,
12116537f381Sas200622 			    tree->t_tid, tree->t_sharename, tree->t_resource);
12126537f381Sas200622 		}
12136537f381Sas200622 	}
12146537f381Sas200622 	if (smb_obj_expand(addr, opts, smb_tree_exp, indent))
12156537f381Sas200622 		return (DCMD_ERR);
12166537f381Sas200622 	return (DCMD_OK);
12176537f381Sas200622 }
12186537f381Sas200622 
12196537f381Sas200622 /*
12206537f381Sas200622  * *****************************************************************************
12216537f381Sas200622  * ****************************** smb_odir_t ***********************************
12226537f381Sas200622  * *****************************************************************************
12236537f381Sas200622  */
12246537f381Sas200622 
12256537f381Sas200622 static const char *smb_odir_state[SMB_ODIR_STATE_SENTINEL] =
12266537f381Sas200622 {
12276537f381Sas200622 	"OPEN",
12289fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	"IN_USE",
12296537f381Sas200622 	"CLOSING",
12306537f381Sas200622 	"CLOSED"
12316537f381Sas200622 };
12326537f381Sas200622 
12336537f381Sas200622 static int
12346537f381Sas200622 smb_dcmd_odir(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
12356537f381Sas200622 {
12366537f381Sas200622 	uint_t		opts;
12376537f381Sas200622 
12386537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
12396537f381Sas200622 		return (DCMD_USAGE);
12406537f381Sas200622 
12416537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
12426537f381Sas200622 		opts |= SMB_OPT_ODIR;
12436537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
12446537f381Sas200622 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_OFILE);
12456537f381Sas200622 		return (smb_obj_list("smb_odir", opts, flags));
12466537f381Sas200622 	}
12476537f381Sas200622 
12486537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_ODIR)) ||
12496537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
12506537f381Sas200622 		smb_odir_t	*od;
12516537f381Sas200622 
12526537f381Sas200622 		od = mdb_alloc(sizeof (*od), UM_SLEEP | UM_GC);
12536537f381Sas200622 		if (mdb_vread(od, sizeof (*od), addr) == -1) {
12546537f381Sas200622 			mdb_warn("failed to read smb_odir at %p", addr);
12556537f381Sas200622 			return (DCMD_ERR);
12566537f381Sas200622 		}
12576537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
12586537f381Sas200622 			const char	*state;
12596537f381Sas200622 
12606537f381Sas200622 			if (od->d_state >= SMB_ODIR_STATE_SENTINEL)
12616537f381Sas200622 				state = "INVALID";
12626537f381Sas200622 			else
12636537f381Sas200622 				state = smb_odir_state[od->d_state];
12646537f381Sas200622 
12656537f381Sas200622 			mdb_printf(
12666537f381Sas200622 			    "%<b>%<u>SMB odir information (%p):%</u>%</b>\n\n",
12676537f381Sas200622 			    addr);
12686537f381Sas200622 			mdb_printf("State: %d (%s)\n", od->d_state, state);
12697f667e74Sjose borrego 			mdb_printf("SID: %u\n", od->d_odid);
12703b13a1efSThomas Keiser 			mdb_printf("User: %p\n", od->d_user);
12713b13a1efSThomas Keiser 			mdb_printf("Tree: %p\n", od->d_tree);
12726537f381Sas200622 			mdb_printf("Reference Count: %d\n", od->d_refcnt);
12736537f381Sas200622 			mdb_printf("Pattern: %s\n", od->d_pattern);
12747f667e74Sjose borrego 			mdb_printf("SMB Node: %p\n\n", od->d_dnode);
12756537f381Sas200622 		} else {
12766537f381Sas200622 			if (DCMD_HDRSPEC(flags))
12776537f381Sas200622 				mdb_printf(
1278e3f2c991SKeyur Desai 				    "%<b>%<u>%-?s "
12796537f381Sas200622 				    "%-5s "
12806537f381Sas200622 				    "%-?s "
1281e3f2c991SKeyur Desai 				    "%-16s%</u>%</b>\n",
12826537f381Sas200622 				    "ODIR", "SID", "VNODE", "PATTERN");
12836537f381Sas200622 
1284e3f2c991SKeyur Desai 			mdb_printf("%?p %-5u %-16p %s\n",
12857f667e74Sjose borrego 			    addr, od->d_odid, od->d_dnode, od->d_pattern);
12866537f381Sas200622 		}
12876537f381Sas200622 	}
12886537f381Sas200622 	return (DCMD_OK);
12896537f381Sas200622 }
12906537f381Sas200622 
12916537f381Sas200622 /*
12926537f381Sas200622  * *****************************************************************************
12936537f381Sas200622  * ****************************** smb_ofile_t **********************************
12946537f381Sas200622  * *****************************************************************************
12956537f381Sas200622  */
12966537f381Sas200622 
12976537f381Sas200622 static const char *smb_ofile_state[SMB_OFILE_STATE_SENTINEL] =
12986537f381Sas200622 {
12996537f381Sas200622 	"OPEN",
13006537f381Sas200622 	"CLOSING",
13016537f381Sas200622 	"CLOSED"
13026537f381Sas200622 };
13036537f381Sas200622 
13046537f381Sas200622 static int
13056537f381Sas200622 smb_dcmd_ofile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13066537f381Sas200622 {
13076537f381Sas200622 	uint_t		opts;
13086537f381Sas200622 
13096537f381Sas200622 	if (smb_dcmd_getopt(&opts, argc, argv))
13106537f381Sas200622 		return (DCMD_USAGE);
13116537f381Sas200622 
13126537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC)) {
13136537f381Sas200622 		opts |= SMB_OPT_OFILE;
13146537f381Sas200622 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
13156537f381Sas200622 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_ODIR);
13166537f381Sas200622 		return (smb_obj_list("smb_ofile", opts, flags));
13176537f381Sas200622 	}
13186537f381Sas200622 
13196537f381Sas200622 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_OFILE)) ||
13206537f381Sas200622 	    !(opts & SMB_OPT_WALK)) {
13216537f381Sas200622 		smb_ofile_t	*of;
13226537f381Sas200622 
13236537f381Sas200622 		of = mdb_alloc(sizeof (*of), UM_SLEEP | UM_GC);
13246537f381Sas200622 		if (mdb_vread(of, sizeof (*of), addr) == -1) {
13256537f381Sas200622 			mdb_warn("failed to read smb_ofile at %p", addr);
13266537f381Sas200622 			return (DCMD_ERR);
13276537f381Sas200622 		}
13286537f381Sas200622 		if (opts & SMB_OPT_VERBOSE) {
13296537f381Sas200622 			const char	*state;
13306537f381Sas200622 
13312c2d21e9SRichard Lowe 			if (of->f_state >= SMB_OFILE_STATE_SENTINEL)
13326537f381Sas200622 				state = "INVALID";
13336537f381Sas200622 			else
13346537f381Sas200622 				state = smb_ofile_state[of->f_state];
13356537f381Sas200622 
13366537f381Sas200622 			mdb_printf(
13376537f381Sas200622 			    "%<b>%<u>SMB ofile information (%p):%</u>%</b>\n\n",
13386537f381Sas200622 			    addr);
13396537f381Sas200622 			mdb_printf("FID: %u\n", of->f_fid);
13406537f381Sas200622 			mdb_printf("State: %d (%s)\n", of->f_state, state);
13416537f381Sas200622 			mdb_printf("SMB Node: %p\n", of->f_node);
13426537f381Sas200622 			mdb_printf("LLF Offset: 0x%llx (%s)\n",
13436537f381Sas200622 			    of->f_llf_pos,
13446537f381Sas200622 			    ((of->f_flags & SMB_OFLAGS_LLF_POS_VALID) ?
13456537f381Sas200622 			    "Valid" : "Invalid"));
13466537f381Sas200622 			mdb_printf("Flags: 0x%08x\n", of->f_flags);
13473b13a1efSThomas Keiser 			mdb_printf("User: %p\n", of->f_user);
13483b13a1efSThomas Keiser 			mdb_printf("Tree: %p\n", of->f_tree);
13496537f381Sas200622 			mdb_printf("Credential: %p\n\n", of->f_cr);
13506537f381Sas200622 		} else {
13516537f381Sas200622 			if (DCMD_HDRSPEC(flags))
13526537f381Sas200622 				mdb_printf(
13536537f381Sas200622 				    "%<b>%<u>%-?s "
13546537f381Sas200622 				    "%-5s "
13556537f381Sas200622 				    "%-?s "
13566537f381Sas200622 				    "%-?s%</u>%</b>\n",
13576537f381Sas200622 				    "OFILE", "FID", "SMB NODE", "CRED");
13586537f381Sas200622 
13596537f381Sas200622 			mdb_printf("%?p %-5u %-p %p\n", addr,
13606537f381Sas200622 			    of->f_fid, of->f_node, of->f_cr);
13616537f381Sas200622 		}
13626537f381Sas200622 	}
13636537f381Sas200622 	return (DCMD_OK);
13646537f381Sas200622 }
13656537f381Sas200622 
13666537f381Sas200622 /*
13676537f381Sas200622  * *****************************************************************************
13685a6c34e6SGordon Ross  * ******************************** smb_kshare_t *******************************
13695a6c34e6SGordon Ross  * *****************************************************************************
13705a6c34e6SGordon Ross  */
13715a6c34e6SGordon Ross 
13725a6c34e6SGordon Ross static int
13735a6c34e6SGordon Ross smb_kshare_cb(uintptr_t addr, const void *data, void *arg)
13745a6c34e6SGordon Ross {
13755a6c34e6SGordon Ross 	uint_t *opts = arg;
13765a6c34e6SGordon Ross 	uintptr_t ta, sa;
13775a6c34e6SGordon Ross 	char name[32];
13785a6c34e6SGordon Ross 	char path[64];
13795a6c34e6SGordon Ross 	_NOTE(ARGUNUSED(data));
13805a6c34e6SGordon Ross 
13815a6c34e6SGordon Ross 	if (*opts & SMB_OPT_VERBOSE) {
13825a6c34e6SGordon Ross 		mdb_arg_t	argv;
13835a6c34e6SGordon Ross 
13845a6c34e6SGordon Ross 		argv.a_type = MDB_TYPE_STRING;
13855a6c34e6SGordon Ross 		argv.a_un.a_str = "smb_kshare_t";
13865a6c34e6SGordon Ross 		/* Don't fail the walk if this fails. */
13875a6c34e6SGordon Ross 		mdb_call_dcmd("print", addr, 0, 1, &argv);
13885a6c34e6SGordon Ross 	} else {
13895a6c34e6SGordon Ross 		/*
13905a6c34e6SGordon Ross 		 * Summary line for a kshare
13915a6c34e6SGordon Ross 		 * Don't fail the walk if any of these fail.
13925a6c34e6SGordon Ross 		 */
13935a6c34e6SGordon Ross 		ta = addr + OFFSETOF(smb_kshare_t, shr_name);
13945a6c34e6SGordon Ross 		if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
13955a6c34e6SGordon Ross 		    mdb_readstr(name, sizeof (name), sa) <= 0)
13965a6c34e6SGordon Ross 			strcpy(name, "?");
13975a6c34e6SGordon Ross 
13985a6c34e6SGordon Ross 		ta = addr + OFFSETOF(smb_kshare_t, shr_path);
13995a6c34e6SGordon Ross 		if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
14005a6c34e6SGordon Ross 		    mdb_readstr(path, sizeof (path), sa) <= 0)
14015a6c34e6SGordon Ross 			strcpy(path, "?");
14025a6c34e6SGordon Ross 
14035a6c34e6SGordon Ross 		mdb_printf("%-?p ", addr);	/* smb_kshare_t */
14045a6c34e6SGordon Ross 		mdb_printf("%-16s ", name);
14055a6c34e6SGordon Ross 		mdb_printf("%-s", path);
14065a6c34e6SGordon Ross 		mdb_printf("\n");
14075a6c34e6SGordon Ross 	}
14085a6c34e6SGordon Ross 
14095a6c34e6SGordon Ross 	return (WALK_NEXT);
14105a6c34e6SGordon Ross }
14115a6c34e6SGordon Ross 
14125a6c34e6SGordon Ross /*
14135a6c34e6SGordon Ross  * ::smbshares
14145a6c34e6SGordon Ross  *
14155a6c34e6SGordon Ross  * dcmd - Print out smb_kshare structures.
14168622ec45SGordon Ross  *	requires addr of an smb_server_t
14175a6c34e6SGordon Ross  */
14185a6c34e6SGordon Ross /*ARGSUSED*/
14195a6c34e6SGordon Ross static int
14205a6c34e6SGordon Ross smb_dcmd_kshare(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
14215a6c34e6SGordon Ross {
14225a6c34e6SGordon Ross 	uint_t		opts = 0;
14235a6c34e6SGordon Ross 
14245a6c34e6SGordon Ross 	if (mdb_getopts(argc, argv,
14255a6c34e6SGordon Ross 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, &opts,
14265a6c34e6SGordon Ross 	    NULL) != argc)
14275a6c34e6SGordon Ross 		return (DCMD_USAGE);
14285a6c34e6SGordon Ross 
14298622ec45SGordon Ross 	if (!(flags & DCMD_ADDRSPEC))
14308622ec45SGordon Ross 		return (DCMD_USAGE);
14318622ec45SGordon Ross 	addr += OFFSETOF(smb_server_t, sv_export.e_share_avl.avl_tree);
14325a6c34e6SGordon Ross 
14335a6c34e6SGordon Ross 	if (DCMD_HDRSPEC(flags)) {
14345a6c34e6SGordon Ross 		mdb_printf(
14355a6c34e6SGordon Ross 		    "%<b>%<u>"
14365a6c34e6SGordon Ross 		    "%-?s "
14375a6c34e6SGordon Ross 		    "%-16s "
14385a6c34e6SGordon Ross 		    "%-s"
14395a6c34e6SGordon Ross 		    "%</u>%</b>\n",
14405a6c34e6SGordon Ross 		    "smb_kshare_t", "name", "path");
14415a6c34e6SGordon Ross 	}
14425a6c34e6SGordon Ross 
1443b819cea2SGordon Ross 	if (mdb_pwalk("avl", smb_kshare_cb, &opts, addr) == -1) {
14445a6c34e6SGordon Ross 		mdb_warn("cannot walk smb_kshare avl");
14455a6c34e6SGordon Ross 		return (DCMD_ERR);
14465a6c34e6SGordon Ross 	}
14475a6c34e6SGordon Ross 
14485a6c34e6SGordon Ross 	return (DCMD_OK);
14495a6c34e6SGordon Ross }
14505a6c34e6SGordon Ross 
14515a6c34e6SGordon Ross /*
14525a6c34e6SGordon Ross  * *****************************************************************************
1453148c5f43SAlan Wright  * ******************************** smb_vfs_t **********************************
1454148c5f43SAlan Wright  * *****************************************************************************
1455148c5f43SAlan Wright  */
1456148c5f43SAlan Wright 
1457148c5f43SAlan Wright /*
1458148c5f43SAlan Wright  * ::smbvfs
1459148c5f43SAlan Wright  *
1460148c5f43SAlan Wright  * smbvfs dcmd - Prints out smb_vfs structures.
1461148c5f43SAlan Wright  */
1462148c5f43SAlan Wright /*ARGSUSED*/
1463148c5f43SAlan Wright static int
14645a6c34e6SGordon Ross smb_dcmd_vfs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1465148c5f43SAlan Wright {
1466148c5f43SAlan Wright 	int		verbose = FALSE;
1467148c5f43SAlan Wright 	smb_vfs_t	*sf;
1468148c5f43SAlan Wright 	vnode_t		*vn;
1469148c5f43SAlan Wright 	char		*path;
1470148c5f43SAlan Wright 
1471148c5f43SAlan Wright 	if (mdb_getopts(argc, argv,
1472148c5f43SAlan Wright 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1473148c5f43SAlan Wright 	    NULL) != argc)
1474148c5f43SAlan Wright 		return (DCMD_USAGE);
1475148c5f43SAlan Wright 
1476148c5f43SAlan Wright 	/*
1477148c5f43SAlan Wright 	 * If no smb_vfs address was specified on the command line, we can
1478148c5f43SAlan Wright 	 * print out all smb_vfs by invoking the smb_vfs walker, using
1479148c5f43SAlan Wright 	 * this dcmd itself as the callback.
1480148c5f43SAlan Wright 	 */
1481148c5f43SAlan Wright 	if (!(flags & DCMD_ADDRSPEC)) {
1482148c5f43SAlan Wright 		if (mdb_walk_dcmd("smbvfs_walker", "smbvfs",
1483148c5f43SAlan Wright 		    argc, argv) == -1) {
1484148c5f43SAlan Wright 			mdb_warn("failed to walk 'smb_vfs'");
1485148c5f43SAlan Wright 			return (DCMD_ERR);
1486148c5f43SAlan Wright 		}
1487148c5f43SAlan Wright 		return (DCMD_OK);
1488148c5f43SAlan Wright 	}
1489148c5f43SAlan Wright 
1490148c5f43SAlan Wright 	if (DCMD_HDRSPEC(flags)) {
1491148c5f43SAlan Wright 		mdb_printf(
1492148c5f43SAlan Wright 		    "%<b>%<u>"
1493148c5f43SAlan Wright 		    "%-?s "
1494148c5f43SAlan Wright 		    "%-10s "
1495148c5f43SAlan Wright 		    "%-16s "
1496148c5f43SAlan Wright 		    "%-16s"
1497148c5f43SAlan Wright 		    "%-s"
1498148c5f43SAlan Wright 		    "%</u>%</b>\n",
1499148c5f43SAlan Wright 		    "SMB_VFS", "REFCNT", "VFS", "VNODE", "ROOT");
1500148c5f43SAlan Wright 	}
1501148c5f43SAlan Wright 
1502148c5f43SAlan Wright 	sf = mdb_alloc(sizeof (*sf), UM_SLEEP | UM_GC);
1503148c5f43SAlan Wright 	if (mdb_vread(sf, sizeof (*sf), addr) == -1) {
1504148c5f43SAlan Wright 		mdb_warn("failed to read smb_vfs at %p", addr);
1505148c5f43SAlan Wright 		return (DCMD_ERR);
1506148c5f43SAlan Wright 	}
1507148c5f43SAlan Wright 
1508148c5f43SAlan Wright 	vn = mdb_alloc(sizeof (*vn), UM_SLEEP | UM_GC);
1509148c5f43SAlan Wright 	if (mdb_vread(vn, sizeof (*vn),
1510148c5f43SAlan Wright 	    (uintptr_t)sf->sv_rootvp) == -1) {
1511148c5f43SAlan Wright 		mdb_warn("failed to read vnode at %p", sf->sv_rootvp);
1512148c5f43SAlan Wright 		return (DCMD_ERR);
1513148c5f43SAlan Wright 	}
1514148c5f43SAlan Wright 
1515148c5f43SAlan Wright 	path = mdb_zalloc(MAXPATHLEN, UM_SLEEP | UM_GC);
1516148c5f43SAlan Wright 	(void) mdb_vread(path, MAXPATHLEN, (uintptr_t)vn->v_path);
1517148c5f43SAlan Wright 
1518148c5f43SAlan Wright 	mdb_printf(
1519148c5f43SAlan Wright 	    "%-?p %-10d %-?p %-?p %-s\n", addr, sf->sv_refcnt,
1520148c5f43SAlan Wright 	    sf->sv_vfsp, sf->sv_rootvp, path);
1521148c5f43SAlan Wright 
1522148c5f43SAlan Wright 	return (DCMD_OK);
1523148c5f43SAlan Wright }
1524148c5f43SAlan Wright 
1525148c5f43SAlan Wright /*
15268622ec45SGordon Ross  * Initialize the smb_vfs_t walker to point to the smb_export
15278622ec45SGordon Ross  * in the specified smb_server_t instance.  (no global walks)
1528148c5f43SAlan Wright  */
1529148c5f43SAlan Wright static int
1530148c5f43SAlan Wright smb_vfs_walk_init(mdb_walk_state_t *wsp)
1531148c5f43SAlan Wright {
1532148c5f43SAlan Wright 
15338622ec45SGordon Ross 	if (wsp->walk_addr == NULL) {
15348622ec45SGordon Ross 		mdb_printf("require address of an smb_server_t\n");
1535148c5f43SAlan Wright 		return (WALK_ERR);
1536148c5f43SAlan Wright 	}
1537148c5f43SAlan Wright 
15388622ec45SGordon Ross 	wsp->walk_addr +=
15398622ec45SGordon Ross 	    OFFSETOF(smb_server_t, sv_export.e_vfs_list.ll_list);
1540148c5f43SAlan Wright 
1541148c5f43SAlan Wright 	if (mdb_layered_walk("list", wsp) == -1) {
1542148c5f43SAlan Wright 		mdb_warn("failed to walk list of VFS");
1543148c5f43SAlan Wright 		return (WALK_ERR);
1544148c5f43SAlan Wright 	}
1545148c5f43SAlan Wright 
1546148c5f43SAlan Wright 	return (WALK_NEXT);
1547148c5f43SAlan Wright }
1548148c5f43SAlan Wright 
1549148c5f43SAlan Wright static int
1550148c5f43SAlan Wright smb_vfs_walk_step(mdb_walk_state_t *wsp)
1551148c5f43SAlan Wright {
1552148c5f43SAlan Wright 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1553148c5f43SAlan Wright 	    wsp->walk_cbdata));
1554148c5f43SAlan Wright }
1555148c5f43SAlan Wright 
1556148c5f43SAlan Wright /*
1557148c5f43SAlan Wright  * *****************************************************************************
15586537f381Sas200622  * ******************************* smb_node_t **********************************
15596537f381Sas200622  * *****************************************************************************
15606537f381Sas200622  */
15616537f381Sas200622 
1562da6c28aaSamw static void
1563da6c28aaSamw smb_node_help(void)
1564da6c28aaSamw {
1565da6c28aaSamw 	mdb_printf(
1566da6c28aaSamw 	    "Display the contents of smb_node_t, with optional filtering.\n\n");
15676537f381Sas200622 	(void) mdb_dec_indent(2);
1568da6c28aaSamw 	mdb_printf("%<b>OPTIONS%</b>\n");
15696537f381Sas200622 	(void) mdb_inc_indent(2);
1570da6c28aaSamw 	mdb_printf(
1571da6c28aaSamw 	    "-v\tDisplay verbose smb_node information\n"
1572da6c28aaSamw 	    "-p\tDisplay the full path of the vnode associated\n"
1573da6c28aaSamw 	    "-s\tDisplay the stack of the last 16 calls that modified the "
1574da6c28aaSamw 	    "reference\n\tcount\n");
1575da6c28aaSamw }
1576da6c28aaSamw 
1577da6c28aaSamw /*
15786537f381Sas200622  * ::smbnode
1579da6c28aaSamw  *
1580da6c28aaSamw  * smb_node dcmd - Print out smb_node structure.
1581da6c28aaSamw  */
1582da6c28aaSamw static int
15835a6c34e6SGordon Ross smb_dcmd_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1584da6c28aaSamw {
1585da6c28aaSamw 	smb_node_t	node;
1586cb174861Sjoyce mcintosh 	int		rc;
1587da6c28aaSamw 	int		verbose = FALSE;
1588da6c28aaSamw 	int		print_full_path = FALSE;
1589da6c28aaSamw 	int		stack_trace = FALSE;
1590da6c28aaSamw 	vnode_t		vnode;
1591da6c28aaSamw 	char		od_name[MAXNAMELEN];
1592da6c28aaSamw 	char		path_name[1024];
1593cb174861Sjoyce mcintosh 	uintptr_t	list_addr, oplock_addr;
1594da6c28aaSamw 
1595da6c28aaSamw 	if (mdb_getopts(argc, argv,
1596da6c28aaSamw 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1597da6c28aaSamw 	    'p', MDB_OPT_SETBITS, TRUE, &print_full_path,
1598da6c28aaSamw 	    's', MDB_OPT_SETBITS, TRUE, &stack_trace,
1599da6c28aaSamw 	    NULL) != argc)
1600da6c28aaSamw 		return (DCMD_USAGE);
1601da6c28aaSamw 
1602da6c28aaSamw 	/*
1603da6c28aaSamw 	 * If no smb_node address was specified on the command line, we can
1604da6c28aaSamw 	 * print out all smb nodes by invoking the smb_node walker, using
1605da6c28aaSamw 	 * this dcmd itself as the callback.
1606da6c28aaSamw 	 */
1607da6c28aaSamw 	if (!(flags & DCMD_ADDRSPEC)) {
16086537f381Sas200622 		if (mdb_walk_dcmd("smbnode_walker", "smbnode",
1609da6c28aaSamw 		    argc, argv) == -1) {
1610da6c28aaSamw 			mdb_warn("failed to walk 'smb_node'");
1611da6c28aaSamw 			return (DCMD_ERR);
1612da6c28aaSamw 		}
1613da6c28aaSamw 		return (DCMD_OK);
1614da6c28aaSamw 	}
1615da6c28aaSamw 
1616da6c28aaSamw 	/*
1617da6c28aaSamw 	 * If this is the first invocation of the command, print a nice
1618da6c28aaSamw 	 * header line for the output that will follow.
1619da6c28aaSamw 	 */
1620da6c28aaSamw 	if (DCMD_HDRSPEC(flags)) {
16216537f381Sas200622 		if (verbose) {
16226537f381Sas200622 			mdb_printf("%<b>%<u>SMB node information:%</u>%</b>\n");
16236537f381Sas200622 		} else {
16246537f381Sas200622 			mdb_printf(
16256537f381Sas200622 			    "%<b>%<u>%-?s "
16266537f381Sas200622 			    "%-?s "
16276537f381Sas200622 			    "%-18s "
16286537f381Sas200622 			    "%-6s "
16296537f381Sas200622 			    "%-6s "
1630cb174861Sjoyce mcintosh 			    "%-8s "
16316537f381Sas200622 			    "%-6s%</u>%</b>\n",
16326537f381Sas200622 			    "ADDR", "VP", "NODE-NAME", "OFILES", "LOCKS",
1633cb174861Sjoyce mcintosh 			    "OPLOCK", "REF");
16346537f381Sas200622 		}
1635da6c28aaSamw 	}
1636da6c28aaSamw 
1637da6c28aaSamw 	/*
16386537f381Sas200622 	 * For each smb_node, we just need to read the smb_node_t struct, read
16396537f381Sas200622 	 * and then print out the following fields.
1640da6c28aaSamw 	 */
1641da6c28aaSamw 	if (mdb_vread(&node, sizeof (node), addr) == sizeof (node)) {
16426537f381Sas200622 		(void) mdb_snprintf(od_name, sizeof (od_name), "%s",
16436537f381Sas200622 		    node.od_name);
1644da6c28aaSamw 		if (print_full_path) {
1645da6c28aaSamw 			if (mdb_vread(&vnode, sizeof (vnode_t),
16466537f381Sas200622 			    (uintptr_t)node.vp) == sizeof (vnode_t)) {
16476537f381Sas200622 				if (mdb_readstr(path_name, sizeof (path_name),
1648da6c28aaSamw 				    (uintptr_t)vnode.v_path) != 0) {
1649da6c28aaSamw 					(void) mdb_snprintf(od_name,
16506537f381Sas200622 					    sizeof (od_name), "N/A");
1651da6c28aaSamw 				}
1652da6c28aaSamw 			}
1653da6c28aaSamw 		}
1654da6c28aaSamw 		if (verbose) {
16556537f381Sas200622 			mdb_printf("VP: %p\n", node.vp);
16566537f381Sas200622 			mdb_printf("Name: %s\n", od_name);
16576537f381Sas200622 			if (print_full_path)
16586537f381Sas200622 				mdb_printf("V-node Path: %s\n", path_name);
16596537f381Sas200622 			mdb_printf("Ofiles: %u\n", node.n_ofile_list.ll_count);
16606537f381Sas200622 			mdb_printf("Range Locks: %u\n",
1661da6c28aaSamw 			    node.n_lock_list.ll_count);
1662da6c28aaSamw 			if (node.n_lock_list.ll_count != 0) {
1663da6c28aaSamw 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1664da6c28aaSamw 				list_addr = addr +
1665b819cea2SGordon Ross 				    OFFSETOF(smb_node_t, n_lock_list) +
1666b819cea2SGordon Ross 				    OFFSETOF(smb_llist_t, ll_list);
16676537f381Sas200622 				if (mdb_pwalk_dcmd("list", "smblock", 0,
16686537f381Sas200622 				    NULL, list_addr)) {
1669da6c28aaSamw 					mdb_warn("failed to walk node's active"
1670da6c28aaSamw 					    " locks");
1671da6c28aaSamw 				}
1672da6c28aaSamw 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1673da6c28aaSamw 			}
1674cb174861Sjoyce mcintosh 			if (node.n_oplock.ol_count == 0) {
1675cb174861Sjoyce mcintosh 				mdb_printf("Opportunistic Locks: 0\n");
1676cb174861Sjoyce mcintosh 			} else {
1677cb174861Sjoyce mcintosh 				oplock_addr =
1678b819cea2SGordon Ross 				    addr + OFFSETOF(smb_node_t, n_oplock);
1679cb174861Sjoyce mcintosh 				mdb_printf("Opportunistic Lock: %p\n",
1680cb174861Sjoyce mcintosh 				    oplock_addr);
1681cb174861Sjoyce mcintosh 				rc = mdb_call_dcmd("smboplock", oplock_addr,
1682cb174861Sjoyce mcintosh 				    flags, argc, argv);
1683cb174861Sjoyce mcintosh 				if (rc != DCMD_OK)
1684cb174861Sjoyce mcintosh 					return (rc);
1685cb174861Sjoyce mcintosh 			}
16866537f381Sas200622 			mdb_printf("Reference Count: %u\n\n", node.n_refcnt);
1687da6c28aaSamw 		} else {
1688cb174861Sjoyce mcintosh 			mdb_printf("%-?p %-?p %-18s %-6d %-6d %-8d %-6d ",
1689da6c28aaSamw 			    addr, node.vp, od_name, node.n_ofile_list.ll_count,
1690cb174861Sjoyce mcintosh 			    node.n_lock_list.ll_count,
1691cb174861Sjoyce mcintosh 			    node.n_oplock.ol_count, node.n_refcnt);
1692cb174861Sjoyce mcintosh 
16936537f381Sas200622 			if (print_full_path)
16946537f381Sas200622 				mdb_printf("\t%s\n", path_name);
1695da6c28aaSamw 		}
1696da6c28aaSamw 		if (stack_trace && node.n_audit_buf) {
1697da6c28aaSamw 			int ctr;
1698da6c28aaSamw 			smb_audit_buf_node_t *anb;
1699da6c28aaSamw 
1700da6c28aaSamw 			anb = mdb_alloc(sizeof (smb_audit_buf_node_t),
17016537f381Sas200622 			    UM_SLEEP | UM_GC);
1702da6c28aaSamw 
1703da6c28aaSamw 			if (mdb_vread(anb, sizeof (*anb),
1704da6c28aaSamw 			    (uintptr_t)node.n_audit_buf) != sizeof (*anb)) {
1705da6c28aaSamw 				mdb_warn("failed to read audit buffer");
1706da6c28aaSamw 				return (DCMD_ERR);
1707da6c28aaSamw 			}
1708da6c28aaSamw 			ctr = anb->anb_max_index + 1;
1709da6c28aaSamw 			anb->anb_index--;
1710da6c28aaSamw 			anb->anb_index &= anb->anb_max_index;
1711da6c28aaSamw 
1712da6c28aaSamw 			while (ctr) {
1713da6c28aaSamw 				smb_audit_record_node_t	*anr;
1714da6c28aaSamw 
1715da6c28aaSamw 				anr = anb->anb_records + anb->anb_index;
1716da6c28aaSamw 
1717da6c28aaSamw 				if (anr->anr_depth) {
1718da6c28aaSamw 					char c[MDB_SYM_NAMLEN];
1719da6c28aaSamw 					GElf_Sym sym;
1720da6c28aaSamw 					int i;
1721da6c28aaSamw 
1722da6c28aaSamw 					mdb_printf("\nRefCnt: %u\t",
1723da6c28aaSamw 					    anr->anr_refcnt);
1724da6c28aaSamw 
1725da6c28aaSamw 					for (i = 0;
1726da6c28aaSamw 					    i < anr->anr_depth;
1727da6c28aaSamw 					    i++) {
1728da6c28aaSamw 						if (mdb_lookup_by_addr(
1729da6c28aaSamw 						    anr->anr_stack[i],
1730da6c28aaSamw 						    MDB_SYM_FUZZY,
1731da6c28aaSamw 						    c, sizeof (c),
1732da6c28aaSamw 						    &sym) == -1) {
1733da6c28aaSamw 							continue;
1734da6c28aaSamw 						}
1735da6c28aaSamw 						mdb_printf("%s+0x%1x",
1736da6c28aaSamw 						    c,
1737da6c28aaSamw 						    anr->anr_stack[i] -
1738da6c28aaSamw 						    (uintptr_t)sym.st_value);
1739da6c28aaSamw 						++i;
1740da6c28aaSamw 						break;
1741da6c28aaSamw 					}
1742da6c28aaSamw 
1743da6c28aaSamw 					while (i < anr->anr_depth) {
1744da6c28aaSamw 						if (mdb_lookup_by_addr(
1745da6c28aaSamw 						    anr->anr_stack[i],
1746da6c28aaSamw 						    MDB_SYM_FUZZY,
1747da6c28aaSamw 						    c, sizeof (c),
1748da6c28aaSamw 						    &sym) == -1) {
1749da6c28aaSamw 							++i;
1750da6c28aaSamw 							continue;
1751da6c28aaSamw 						}
1752da6c28aaSamw 						mdb_printf("\n\t\t%s+0x%1x",
1753da6c28aaSamw 						    c,
1754da6c28aaSamw 						    anr->anr_stack[i] -
1755da6c28aaSamw 						    (uintptr_t)sym.st_value);
1756da6c28aaSamw 						++i;
1757da6c28aaSamw 					}
1758da6c28aaSamw 					mdb_printf("\n");
1759da6c28aaSamw 				}
1760da6c28aaSamw 				anb->anb_index--;
1761da6c28aaSamw 				anb->anb_index &= anb->anb_max_index;
1762da6c28aaSamw 				ctr--;
1763da6c28aaSamw 			}
1764da6c28aaSamw 		}
1765da6c28aaSamw 	} else {
1766da6c28aaSamw 		mdb_warn("failed to read struct smb_node at %p", addr);
1767da6c28aaSamw 		return (DCMD_ERR);
1768da6c28aaSamw 	}
1769da6c28aaSamw 
1770da6c28aaSamw 	return (DCMD_OK);
1771da6c28aaSamw }
1772da6c28aaSamw 
1773da6c28aaSamw /*
17746537f381Sas200622  * Initialize the smb_node_t walker by reading the value of smb_node_hash_table
17756537f381Sas200622  * in the kernel's symbol table. Only global walk supported.
1776da6c28aaSamw  */
1777da6c28aaSamw static int
17786537f381Sas200622 smb_node_walk_init(mdb_walk_state_t *wsp)
1779da6c28aaSamw {
17806537f381Sas200622 	GElf_Sym	sym;
17816537f381Sas200622 	int		i;
17826537f381Sas200622 	uintptr_t	node_hash_table_addr;
1783da6c28aaSamw 
17846537f381Sas200622 	if (wsp->walk_addr == NULL) {
1785b819cea2SGordon Ross 		if (mdb_lookup_by_obj(SMBSRV_OBJNAME, "smb_node_hash_table",
1786b819cea2SGordon Ross 		    &sym) == -1) {
17876537f381Sas200622 			mdb_warn("failed to find 'smb_node_hash_table'");
17886537f381Sas200622 			return (WALK_ERR);
1789faa1795aSjb150015 		}
17906537f381Sas200622 		node_hash_table_addr = (uintptr_t)sym.st_value;
1791da6c28aaSamw 	} else {
17926537f381Sas200622 		mdb_printf("smb_node walk only supports global walks\n");
17936537f381Sas200622 		return (WALK_ERR);
1794da6c28aaSamw 	}
1795da6c28aaSamw 
17966537f381Sas200622 	for (i = 0; i < SMBND_HASH_MASK + 1; i++) {
17976537f381Sas200622 		wsp->walk_addr = node_hash_table_addr +
1798b819cea2SGordon Ross 		    (i * sizeof (smb_llist_t)) + OFFSETOF(smb_llist_t, ll_list);
17996537f381Sas200622 		if (mdb_layered_walk("list", wsp) == -1) {
18006537f381Sas200622 			mdb_warn("failed to walk 'list'");
18016537f381Sas200622 			return (WALK_ERR);
1802da6c28aaSamw 		}
1803da6c28aaSamw 	}
1804da6c28aaSamw 
18056537f381Sas200622 	return (WALK_NEXT);
1806da6c28aaSamw }
1807da6c28aaSamw 
1808da6c28aaSamw static int
18096537f381Sas200622 smb_node_walk_step(mdb_walk_state_t *wsp)
1810da6c28aaSamw {
18116537f381Sas200622 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
18126537f381Sas200622 	    wsp->walk_cbdata));
18136537f381Sas200622 }
1814da6c28aaSamw 
1815da6c28aaSamw /*
18166537f381Sas200622  * *****************************************************************************
18176537f381Sas200622  * ****************************** smb_lock_t ***********************************
18186537f381Sas200622  * *****************************************************************************
1819da6c28aaSamw  */
1820da6c28aaSamw 
1821da6c28aaSamw static int
1822da6c28aaSamw smb_lock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1823da6c28aaSamw {
1824da6c28aaSamw 	smb_lock_t	lock;
1825da6c28aaSamw 	int		verbose = FALSE;
1826da6c28aaSamw 	uintptr_t	list_addr;
1827da6c28aaSamw 	char		*lock_type;
1828da6c28aaSamw 
1829da6c28aaSamw 	if (mdb_getopts(argc, argv,
1830da6c28aaSamw 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1831da6c28aaSamw 	    NULL) != argc)
1832da6c28aaSamw 		return (DCMD_USAGE);
1833da6c28aaSamw 
1834da6c28aaSamw 	/*
1835da6c28aaSamw 	 * An smb_lock_t address must be specified.
1836da6c28aaSamw 	 */
1837da6c28aaSamw 	if (!(flags & DCMD_ADDRSPEC))
1838da6c28aaSamw 		return (DCMD_USAGE);
1839da6c28aaSamw 
1840da6c28aaSamw 	/*
1841da6c28aaSamw 	 * If this is the first invocation of the command, print a nice
1842da6c28aaSamw 	 * header line for the output that will follow.
1843da6c28aaSamw 	 */
1844da6c28aaSamw 	if (DCMD_HDRSPEC(flags)) {
1845da6c28aaSamw 		if (verbose)
1846da6c28aaSamw 			mdb_printf("SMB lock information:\n\n");
1847da6c28aaSamw 		else
1848da6c28aaSamw 			mdb_printf("%<u>%-?s %4s %16s %8s %9s%</u>\n",
1849da6c28aaSamw 			    "Locks: ", "TYPE", "START", "LENGTH",
1850da6c28aaSamw 			    "CONFLICTS");
1851da6c28aaSamw 	}
1852da6c28aaSamw 
1853da6c28aaSamw 	if (mdb_vread(&lock, sizeof (lock), addr) == sizeof (lock)) {
1854da6c28aaSamw 		switch (lock.l_type) {
1855da6c28aaSamw 		case SMB_LOCK_TYPE_READWRITE:
1856da6c28aaSamw 			lock_type = "RW";
1857da6c28aaSamw 			break;
1858da6c28aaSamw 		case SMB_LOCK_TYPE_READONLY:
1859da6c28aaSamw 			lock_type = "RO";
1860da6c28aaSamw 			break;
1861da6c28aaSamw 		default:
1862da6c28aaSamw 			lock_type = "N/A";
1863da6c28aaSamw 			break;
1864da6c28aaSamw 		}
1865da6c28aaSamw 		if (verbose) {
1866da6c28aaSamw 			mdb_printf("Type             :\t%s (%u)\n",
1867da6c28aaSamw 			    lock_type, lock.l_type);
1868da6c28aaSamw 			mdb_printf("Start            :\t%llx\n",
1869da6c28aaSamw 			    lock.l_start);
1870da6c28aaSamw 			mdb_printf("Length           :\t%lx\n",
1871da6c28aaSamw 			    lock.l_length);
1872da6c28aaSamw 			mdb_printf("Session          :\t%p\n",
1873da6c28aaSamw 			    lock.l_session);
1874da6c28aaSamw 			mdb_printf("File             :\t%p\n",
1875da6c28aaSamw 			    lock.l_file);
1876da6c28aaSamw 			mdb_printf("User ID          :\t%u\n",
1877da6c28aaSamw 			    lock.l_uid);
1878da6c28aaSamw 			mdb_printf("Process ID       :\t%u\n",
1879da6c28aaSamw 			    lock.l_pid);
1880da6c28aaSamw 			mdb_printf("Conflicts        :\t%u\n",
1881da6c28aaSamw 			    lock.l_conflict_list.sl_count);
1882da6c28aaSamw 			if (lock.l_conflict_list.sl_count != 0) {
1883da6c28aaSamw 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1884da6c28aaSamw 				list_addr = addr +
1885b819cea2SGordon Ross 				    OFFSETOF(smb_lock_t, l_conflict_list) +
1886b819cea2SGordon Ross 				    OFFSETOF(smb_slist_t, sl_list);
1887da6c28aaSamw 				if (mdb_pwalk_dcmd("list", "smb_lock",
1888da6c28aaSamw 				    0, NULL, list_addr)) {
1889da6c28aaSamw 					mdb_warn("failed to walk conflict "
1890da6c28aaSamw 					    "locks ");
1891da6c28aaSamw 				}
1892da6c28aaSamw 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1893da6c28aaSamw 			}
1894da6c28aaSamw 			mdb_printf("Blocked by       :\t%p\n",
1895da6c28aaSamw 			    lock.l_blocked_by);
1896da6c28aaSamw 			mdb_printf("Flags            :\t0x%x\n",
1897da6c28aaSamw 			    lock.l_flags);
1898da6c28aaSamw 			mdb_printf("\n");
1899da6c28aaSamw 		} else {
1900da6c28aaSamw 			mdb_printf("%?p %4s %16llx %08lx %9x", addr,
1901da6c28aaSamw 			    lock_type, lock.l_start, lock.l_length,
1902da6c28aaSamw 			    lock.l_conflict_list.sl_count);
1903da6c28aaSamw 		}
1904da6c28aaSamw 	} else {
1905da6c28aaSamw 		mdb_warn("failed to read struct smb_request at %p", addr);
1906da6c28aaSamw 		return (DCMD_ERR);
1907da6c28aaSamw 	}
1908da6c28aaSamw 
1909da6c28aaSamw 	return (DCMD_OK);
1910da6c28aaSamw }
1911da6c28aaSamw 
1912da6c28aaSamw /*
1913cb174861Sjoyce mcintosh  * *****************************************************************************
1914cb174861Sjoyce mcintosh  * ************************** smb_oplock_grant_t *******************************
1915cb174861Sjoyce mcintosh  * *****************************************************************************
1916cb174861Sjoyce mcintosh  */
1917cb174861Sjoyce mcintosh /*ARGSUSED*/
1918cb174861Sjoyce mcintosh static int
1919cb174861Sjoyce mcintosh smb_oplock_grant(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1920cb174861Sjoyce mcintosh {
1921cb174861Sjoyce mcintosh 	smb_oplock_grant_t	grant;
1922cb174861Sjoyce mcintosh 	char			 *level;
1923cb174861Sjoyce mcintosh 
1924cb174861Sjoyce mcintosh 	if (!(flags & DCMD_ADDRSPEC))
1925cb174861Sjoyce mcintosh 		return (DCMD_USAGE);
1926cb174861Sjoyce mcintosh 
1927cb174861Sjoyce mcintosh 	/*
1928cb174861Sjoyce mcintosh 	 * If this is the first invocation of the command, print a nice
1929cb174861Sjoyce mcintosh 	 * header line for the output that will follow.
1930cb174861Sjoyce mcintosh 	 */
1931cb174861Sjoyce mcintosh 	if (DCMD_HDRSPEC(flags)) {
1932cb174861Sjoyce mcintosh 		mdb_printf("%<u>%-16s %-10s %-16s%</u>\n",
1933cb174861Sjoyce mcintosh 		    "Grants:", "LEVEL", "OFILE");
1934cb174861Sjoyce mcintosh 	}
1935cb174861Sjoyce mcintosh 
1936cb174861Sjoyce mcintosh 	if (mdb_vread(&grant, sizeof (grant), addr) == sizeof (grant)) {
1937cb174861Sjoyce mcintosh 		switch (grant.og_level) {
1938cb174861Sjoyce mcintosh 		case SMB_OPLOCK_EXCLUSIVE:
1939cb174861Sjoyce mcintosh 			level = "EXCLUSIVE";
1940cb174861Sjoyce mcintosh 			break;
1941cb174861Sjoyce mcintosh 		case SMB_OPLOCK_BATCH:
1942cb174861Sjoyce mcintosh 			level = "BATCH";
1943cb174861Sjoyce mcintosh 			break;
1944cb174861Sjoyce mcintosh 		case SMB_OPLOCK_LEVEL_II:
1945cb174861Sjoyce mcintosh 			level = "LEVEL_II";
1946cb174861Sjoyce mcintosh 			break;
1947cb174861Sjoyce mcintosh 		default:
1948cb174861Sjoyce mcintosh 			level = "UNKNOWN";
1949cb174861Sjoyce mcintosh 			break;
1950cb174861Sjoyce mcintosh 		}
1951cb174861Sjoyce mcintosh 
1952cb174861Sjoyce mcintosh 		mdb_printf("%-16p %-10s %-16p", addr, level, grant.og_ofile);
1953cb174861Sjoyce mcintosh 	}
1954cb174861Sjoyce mcintosh 	return (DCMD_OK);
1955cb174861Sjoyce mcintosh }
1956cb174861Sjoyce mcintosh 
1957cb174861Sjoyce mcintosh /*
1958cb174861Sjoyce mcintosh  * *****************************************************************************
1959cb174861Sjoyce mcintosh  * ***************************** smb_oplock_t **********************************
1960cb174861Sjoyce mcintosh  * *****************************************************************************
1961cb174861Sjoyce mcintosh  */
1962cb174861Sjoyce mcintosh /*ARGSUSED*/
1963cb174861Sjoyce mcintosh static int
1964cb174861Sjoyce mcintosh smb_oplock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1965cb174861Sjoyce mcintosh {
1966cb174861Sjoyce mcintosh 	smb_oplock_t	oplock;
1967cb174861Sjoyce mcintosh 	uintptr_t	list_addr;
1968cb174861Sjoyce mcintosh 
1969cb174861Sjoyce mcintosh 	if (!(flags & DCMD_ADDRSPEC))
1970cb174861Sjoyce mcintosh 		return (DCMD_USAGE);
1971cb174861Sjoyce mcintosh 
1972cb174861Sjoyce mcintosh 	if (mdb_vread(&oplock, sizeof (oplock), addr) != sizeof (oplock)) {
1973cb174861Sjoyce mcintosh 		mdb_warn("failed to read struct smb_oplock at %p", addr);
1974cb174861Sjoyce mcintosh 		return (DCMD_ERR);
1975cb174861Sjoyce mcintosh 	}
1976cb174861Sjoyce mcintosh 
1977cb174861Sjoyce mcintosh 	if (oplock.ol_count == 0)
1978cb174861Sjoyce mcintosh 		return (DCMD_OK);
1979cb174861Sjoyce mcintosh 
1980cb174861Sjoyce mcintosh 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
1981cb174861Sjoyce mcintosh 	switch (oplock.ol_break) {
1982cb174861Sjoyce mcintosh 	case SMB_OPLOCK_BREAK_TO_NONE:
1983cb174861Sjoyce mcintosh 		mdb_printf("Break Pending: BREAK_TO_NONE\n");
1984cb174861Sjoyce mcintosh 		break;
1985cb174861Sjoyce mcintosh 	case SMB_OPLOCK_BREAK_TO_LEVEL_II:
1986cb174861Sjoyce mcintosh 		mdb_printf(
1987cb174861Sjoyce mcintosh 		    "Break Pending: BREAK_TO_LEVEL_II\n");
1988cb174861Sjoyce mcintosh 		break;
1989cb174861Sjoyce mcintosh 	default:
1990cb174861Sjoyce mcintosh 		break;
1991cb174861Sjoyce mcintosh 	}
1992cb174861Sjoyce mcintosh 
1993b819cea2SGordon Ross 	list_addr = addr + OFFSETOF(smb_oplock_t, ol_grants);
1994cb174861Sjoyce mcintosh 
1995cb174861Sjoyce mcintosh 	if (mdb_pwalk_dcmd("list", "smboplockgrant",
1996cb174861Sjoyce mcintosh 	    argc, argv, list_addr)) {
1997cb174861Sjoyce mcintosh 		mdb_warn("failed to walk oplock grants");
1998cb174861Sjoyce mcintosh 	}
1999cb174861Sjoyce mcintosh 
2000cb174861Sjoyce mcintosh 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
2001cb174861Sjoyce mcintosh 
2002cb174861Sjoyce mcintosh 	return (DCMD_OK);
2003cb174861Sjoyce mcintosh }
2004cb174861Sjoyce mcintosh 
2005cb174861Sjoyce mcintosh /*
2006148c5f43SAlan Wright  * ::smbstat
2007da6c28aaSamw  *
2008148c5f43SAlan Wright  * Prints SMB requests statistics.
2009da6c28aaSamw  */
2010da6c28aaSamw /*ARGSUSED*/
2011da6c28aaSamw static int
20126537f381Sas200622 smb_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2013da6c28aaSamw {
2014148c5f43SAlan Wright 	smb_server_t	*sv;
2015da6c28aaSamw 
2016148c5f43SAlan Wright 	if (!(flags & DCMD_ADDRSPEC))
2017da6c28aaSamw 		return (DCMD_USAGE);
2018da6c28aaSamw 
2019148c5f43SAlan Wright 	sv = mdb_alloc(sizeof (*sv), UM_SLEEP | UM_GC);
2020148c5f43SAlan Wright 	if (mdb_vread(sv, sizeof (*sv), addr) == -1) {
2021148c5f43SAlan Wright 		mdb_warn("failed to read server object at %p", addr);
2022da6c28aaSamw 		return (DCMD_ERR);
2023da6c28aaSamw 	}
2024148c5f43SAlan Wright 	if (sv->sv_magic != SMB_SERVER_MAGIC) {
2025148c5f43SAlan Wright 		mdb_warn("not an smb_server_t (%p)>", addr);
2026da6c28aaSamw 		return (DCMD_ERR);
2027da6c28aaSamw 	}
2028148c5f43SAlan Wright 	mdb_printf(
2029148c5f43SAlan Wright 	    "\n%<b>  nbt   tcp users trees files pipes%</b>\n"
2030148c5f43SAlan Wright 	    "%5d %5d %5d %5d %5d %5d\n",
2031148c5f43SAlan Wright 	    sv->sv_nbt_sess,
2032148c5f43SAlan Wright 	    sv->sv_tcp_sess,
2033148c5f43SAlan Wright 	    sv->sv_users,
2034148c5f43SAlan Wright 	    sv->sv_trees,
2035148c5f43SAlan Wright 	    sv->sv_files,
2036148c5f43SAlan Wright 	    sv->sv_pipes);
2037da6c28aaSamw 
2038da6c28aaSamw 	return (DCMD_OK);
2039da6c28aaSamw }
2040da6c28aaSamw 
2041da6c28aaSamw /*
20426537f381Sas200622  * *****************************************************************************
20436537f381Sas200622  * ******************************** smb_ace_t **********************************
20446537f381Sas200622  * *****************************************************************************
2045da6c28aaSamw  */
20466537f381Sas200622 static const ace_type_entry_t	ace_types[ACE_TYPE_TABLEN] =
2047da6c28aaSamw {
20486537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_ACE_TYPE),
20496537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_ACE_TYPE),
20506537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_ACE_TYPE),
20516537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_ACE_TYPE),
20526537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE),
20536537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE),
20546537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_OBJECT_ACE_TYPE),
20556537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE),
20566537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE),
20576537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE),
20586537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE),
20596537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE),
20606537f381Sas200622 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE),
20616537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE),
20626537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE),
20636537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE),
20646537f381Sas200622 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE),
20656537f381Sas200622 	ACE_TYPE_ENTRY(0x11),
20666537f381Sas200622 	ACE_TYPE_ENTRY(0x12),
20676537f381Sas200622 	ACE_TYPE_ENTRY(0x13),
20686537f381Sas200622 	ACE_TYPE_ENTRY(0x14),
20696537f381Sas200622 	ACE_TYPE_ENTRY(0x15),
20706537f381Sas200622 	ACE_TYPE_ENTRY(0x16),
20716537f381Sas200622 	ACE_TYPE_ENTRY(0x17),
20726537f381Sas200622 	ACE_TYPE_ENTRY(0x18),
20736537f381Sas200622 	ACE_TYPE_ENTRY(0x19),
20746537f381Sas200622 	ACE_TYPE_ENTRY(0x1A),
20756537f381Sas200622 	ACE_TYPE_ENTRY(0x1B),
20766537f381Sas200622 	ACE_TYPE_ENTRY(0x1C),
20776537f381Sas200622 	ACE_TYPE_ENTRY(0x1D),
20786537f381Sas200622 	ACE_TYPE_ENTRY(0x1E),
20796537f381Sas200622 	ACE_TYPE_ENTRY(0x1F)
20806537f381Sas200622 };
20816537f381Sas200622 
20826537f381Sas200622 static const mdb_bitmask_t ace_flag_bits[] = {
20836537f381Sas200622 	{ "OBJECT_INHERIT_ACE", OBJECT_INHERIT_ACE, OBJECT_INHERIT_ACE },
20846537f381Sas200622 	{ "CONTAINER_INHERIT_ACE", CONTAINER_INHERIT_ACE,
20856537f381Sas200622 	    CONTAINER_INHERIT_ACE },
20866537f381Sas200622 	{ "NO_PROPOGATE_INHERIT_ACE", NO_PROPOGATE_INHERIT_ACE,
20876537f381Sas200622 	    NO_PROPOGATE_INHERIT_ACE },
20886537f381Sas200622 	{ "INHERIT_ONLY_ACE", INHERIT_ONLY_ACE, INHERIT_ONLY_ACE },
20896537f381Sas200622 	{ "INHERITED_ACE", INHERITED_ACE, INHERITED_ACE },
20906537f381Sas200622 	{ "SUCCESSFUL_ACCESS_ACE_FLAG", SUCCESSFUL_ACCESS_ACE_FLAG,
20916537f381Sas200622 	    SUCCESSFUL_ACCESS_ACE_FLAG },
20926537f381Sas200622 	{ "FAILED_ACCESS_ACE_FLAG", FAILED_ACCESS_ACE_FLAG,
20936537f381Sas200622 	    FAILED_ACCESS_ACE_FLAG },
20946537f381Sas200622 	{ NULL, 0, 0 }
20956537f381Sas200622 };
20966537f381Sas200622 
20976537f381Sas200622 /*
20986537f381Sas200622  * ::smbace
20996537f381Sas200622  */
21006537f381Sas200622 static int
21016537f381Sas200622 smb_ace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
21026537f381Sas200622 {
21036537f381Sas200622 	smb_ace_t	ace;
21046537f381Sas200622 	int		verbose = FALSE;
21056537f381Sas200622 	const char	*ptr;
21066537f381Sas200622 	int		rc;
21076537f381Sas200622 
21086537f381Sas200622 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose,
21096537f381Sas200622 	    NULL) != argc)
21106537f381Sas200622 		return (DCMD_USAGE);
21116537f381Sas200622 
21126537f381Sas200622 	/*
21136537f381Sas200622 	 * An smb_ace address is required.
21146537f381Sas200622 	 */
21156537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
21166537f381Sas200622 		return (DCMD_USAGE);
21176537f381Sas200622 
21186537f381Sas200622 	if (mdb_vread(&ace, sizeof (ace), addr) != sizeof (ace)) {
21196537f381Sas200622 		mdb_warn("failed to read struct smb_ace at %p", addr);
21206537f381Sas200622 		return (DCMD_ERR);
21216537f381Sas200622 	}
21226537f381Sas200622 
21236537f381Sas200622 	if (verbose) {
21246537f381Sas200622 		if (ace.se_hdr.se_type < ACE_TYPE_TABLEN)
21256537f381Sas200622 			ptr = ace_types[ace.se_hdr.se_type].ace_type_sting;
21266537f381Sas200622 		else
21276537f381Sas200622 			ptr = "Unknown";
21286537f381Sas200622 
21296537f381Sas200622 		mdb_printf("ACE Type: 0x%02x (%s)\n", ace.se_hdr.se_type, ptr);
21306537f381Sas200622 		mdb_printf("ACE Flags: %b\n", (int)ace.se_hdr.se_flags,
21316537f381Sas200622 		    ace_flag_bits);
21326537f381Sas200622 		mdb_printf("ACE Wire Size: 0x%04x\n", ace.se_hdr.se_bsize);
21336537f381Sas200622 		mdb_printf("ACE Mask: 0x%08x\n", ace.se_mask);
21346537f381Sas200622 		mdb_printf("ACE SID: ");
21356537f381Sas200622 	} else {
21366537f381Sas200622 		if (DCMD_HDRSPEC(flags))
21376537f381Sas200622 			mdb_printf(
21386537f381Sas200622 			    "%<b>%<u>%?-s %-4s %-4s %-8s %s%</u>%</b>\n",
21396537f381Sas200622 			    "ACE", "TYPE", "FLAGS", "MASK", "SID");
21406537f381Sas200622 		mdb_printf("%?p 0x%02x 0x%02x 0x%08x ", addr,
21416537f381Sas200622 		    ace.se_hdr.se_type, ace.se_hdr.se_flags, ace.se_mask);
21426537f381Sas200622 	}
21436537f381Sas200622 	rc = smb_sid_print((uintptr_t)ace.se_sid);
21446537f381Sas200622 	mdb_printf("\n");
21456537f381Sas200622 	return (rc);
21466537f381Sas200622 }
21476537f381Sas200622 
21486537f381Sas200622 static int
21496537f381Sas200622 smb_ace_walk_init(mdb_walk_state_t *wsp)
21506537f381Sas200622 {
21516537f381Sas200622 	if (wsp->walk_addr == 0) {
21526537f381Sas200622 		mdb_printf("smb_ace walk only supports local walks\n");
21536537f381Sas200622 		return (WALK_ERR);
21546537f381Sas200622 	}
21556537f381Sas200622 
2156b819cea2SGordon Ross 	wsp->walk_addr += OFFSETOF(smb_acl_t, sl_sorted);
21576537f381Sas200622 
21586537f381Sas200622 	if (mdb_layered_walk("list", wsp) == -1) {
21596537f381Sas200622 		mdb_warn("failed to walk list of ACEs");
21606537f381Sas200622 		return (WALK_ERR);
21616537f381Sas200622 	}
21626537f381Sas200622 
21636537f381Sas200622 	return (WALK_NEXT);
21646537f381Sas200622 }
21656537f381Sas200622 
21666537f381Sas200622 static int
21676537f381Sas200622 smb_ace_walk_step(mdb_walk_state_t *wsp)
21686537f381Sas200622 {
21696537f381Sas200622 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
21706537f381Sas200622 	    wsp->walk_cbdata));
21716537f381Sas200622 }
21726537f381Sas200622 
21736537f381Sas200622 /*
21746537f381Sas200622  * *****************************************************************************
21756537f381Sas200622  * ******************************** smb_acl_t **********************************
21766537f381Sas200622  * *****************************************************************************
21776537f381Sas200622  */
21786537f381Sas200622 
21796537f381Sas200622 /*
21806537f381Sas200622  * ::smbacl
21816537f381Sas200622  */
21826537f381Sas200622 static int
21836537f381Sas200622 smb_acl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
21846537f381Sas200622 {
21856537f381Sas200622 	smb_acl_t	acl;
21866537f381Sas200622 
21876537f381Sas200622 	/* An smb_acl address is required. */
21886537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
21896537f381Sas200622 		return (DCMD_USAGE);
21906537f381Sas200622 
21916537f381Sas200622 	if (mdb_vread(&acl, sizeof (acl), addr) != sizeof (acl)) {
21926537f381Sas200622 		mdb_warn("failed to read struct smb_acl at %p", addr);
21936537f381Sas200622 		return (DCMD_ERR);
21946537f381Sas200622 	}
21956537f381Sas200622 
21966537f381Sas200622 	mdb_printf("ACL Revision: %d\n", acl.sl_revision);
21976537f381Sas200622 	mdb_printf("ACL Size on Wire: %d\n", acl.sl_bsize);
21986537f381Sas200622 	mdb_printf("ACL Number of ACEs: %d\n", acl.sl_acecnt);
21996537f381Sas200622 
22006537f381Sas200622 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
22016537f381Sas200622 	if (mdb_pwalk_dcmd("smbace_walker", "smbace", argc, argv, addr)) {
22026537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
22036537f381Sas200622 		mdb_warn("failed to walk list of ACEs for ACL %p", addr);
22046537f381Sas200622 		return (DCMD_ERR);
22056537f381Sas200622 	}
22066537f381Sas200622 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
22076537f381Sas200622 	return (DCMD_OK);
22086537f381Sas200622 }
22096537f381Sas200622 
22106537f381Sas200622 /*
22116537f381Sas200622  * *****************************************************************************
22126537f381Sas200622  * ********************************* smb_sd_t **********************************
22136537f381Sas200622  * *****************************************************************************
22146537f381Sas200622  */
22156537f381Sas200622 
22166537f381Sas200622 /*
22176537f381Sas200622  * ::smbsd
22186537f381Sas200622  */
22196537f381Sas200622 static int
22206537f381Sas200622 smb_sd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
22216537f381Sas200622 {
22226537f381Sas200622 	smb_sd_t	sd;
22236537f381Sas200622 	int		rc;
22246537f381Sas200622 
22256537f381Sas200622 	/*
22266537f381Sas200622 	 * An smb_sid address is required.
22276537f381Sas200622 	 */
22286537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
22296537f381Sas200622 		return (DCMD_USAGE);
22306537f381Sas200622 
22316537f381Sas200622 	if (mdb_vread(&sd, sizeof (sd), addr) != sizeof (sd)) {
22326537f381Sas200622 		mdb_warn("failed to read struct smb_sd at %p", addr);
22336537f381Sas200622 		return (DCMD_ERR);
22346537f381Sas200622 	}
22356537f381Sas200622 
22366537f381Sas200622 	mdb_printf("SD Revision: %d\n", sd.sd_revision);
22376537f381Sas200622 	mdb_printf("SD Control: %04x\n", sd.sd_control);
22386537f381Sas200622 	if (sd.sd_control & SE_OWNER_DEFAULTED)
22396537f381Sas200622 		mdb_printf("\t    SE_OWNER_DEFAULTED\n");
22406537f381Sas200622 	if (sd.sd_control & SE_GROUP_DEFAULTED)
22416537f381Sas200622 		mdb_printf("\t    SE_GROUP_DEFAULTED\n");
22426537f381Sas200622 	if (sd.sd_control & SE_DACL_PRESENT)
22436537f381Sas200622 		mdb_printf("\t    SE_DACL_PRESENT\n");
22446537f381Sas200622 	if (sd.sd_control & SE_DACL_DEFAULTED)
22456537f381Sas200622 		mdb_printf("\t    SE_DACL_DEFAULTED\n");
22466537f381Sas200622 	if (sd.sd_control & SE_SACL_PRESENT)
22476537f381Sas200622 		mdb_printf("\t    SE_SACL_PRESENT\n");
22486537f381Sas200622 	if (sd.sd_control & SE_SACL_DEFAULTED)
22496537f381Sas200622 		mdb_printf("\t    SE_SACL_DEFAULTED\n");
22506537f381Sas200622 	if (sd.sd_control & SE_DACL_AUTO_INHERIT_REQ)
22516537f381Sas200622 		mdb_printf("\t    SE_DACL_AUTO_INHERIT_REQ\n");
22526537f381Sas200622 	if (sd.sd_control & SE_SACL_AUTO_INHERIT_REQ)
22536537f381Sas200622 		mdb_printf("\t    SE_SACL_AUTO_INHERIT_REQ\n");
22546537f381Sas200622 	if (sd.sd_control & SE_DACL_AUTO_INHERITED)
22556537f381Sas200622 		mdb_printf("\t    SE_DACL_AUTO_INHERITED\n");
22566537f381Sas200622 	if (sd.sd_control & SE_SACL_AUTO_INHERITED)
22576537f381Sas200622 		mdb_printf("\t    SE_SACL_AUTO_INHERITED\n");
22586537f381Sas200622 	if (sd.sd_control & SE_DACL_PROTECTED)
22596537f381Sas200622 		mdb_printf("\t    SE_DACL_PROTECTED\n");
22606537f381Sas200622 	if (sd.sd_control & SE_SACL_PROTECTED)
22616537f381Sas200622 		mdb_printf("\t    SE_SACL_PROTECTED\n");
22626537f381Sas200622 	if (sd.sd_control & SE_SELF_RELATIVE)
22636537f381Sas200622 		mdb_printf("\t    SE_SELF_RELATIVE\n");
22646537f381Sas200622 
22656537f381Sas200622 	mdb_printf("SID of Owner: ");
22666537f381Sas200622 	rc = smb_sid_print((uintptr_t)sd.sd_owner);
22676537f381Sas200622 	if (rc != DCMD_OK)
22686537f381Sas200622 		return (rc);
22696537f381Sas200622 	mdb_printf("\nSID of Group: ");
22706537f381Sas200622 	rc = smb_sid_print((uintptr_t)sd.sd_group);
22716537f381Sas200622 	if (rc != DCMD_OK)
22726537f381Sas200622 		return (rc);
22736537f381Sas200622 	mdb_printf("\n");
22746537f381Sas200622 
22756537f381Sas200622 	if (sd.sd_control & SE_SACL_PRESENT && sd.sd_sacl) {
22766537f381Sas200622 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
22776537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
22786537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_sacl, flags,
22796537f381Sas200622 		    argc, argv);
22806537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
22816537f381Sas200622 		if (rc != DCMD_OK)
22826537f381Sas200622 			return (rc);
22836537f381Sas200622 	}
22846537f381Sas200622 	if (sd.sd_control & SE_DACL_PRESENT && sd.sd_dacl) {
22856537f381Sas200622 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
22866537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
22876537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_dacl, flags,
22886537f381Sas200622 		    argc, argv);
22896537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
22906537f381Sas200622 		if (rc != DCMD_OK)
22916537f381Sas200622 			return (rc);
22926537f381Sas200622 	}
22936537f381Sas200622 
22946537f381Sas200622 	return (DCMD_OK);
22956537f381Sas200622 }
22966537f381Sas200622 
22976537f381Sas200622 /*
22986537f381Sas200622  * *****************************************************************************
22996537f381Sas200622  * ********************************* smb_sid_t *********************************
23006537f381Sas200622  * *****************************************************************************
23016537f381Sas200622  */
23026537f381Sas200622 
23036537f381Sas200622 /*
23046537f381Sas200622  * ::smbsid
23056537f381Sas200622  */
23066537f381Sas200622 /*ARGSUSED*/
23076537f381Sas200622 static int
23086537f381Sas200622 smb_sid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23096537f381Sas200622 {
23106537f381Sas200622 	/*
23116537f381Sas200622 	 * An smb_sid address is required.
23126537f381Sas200622 	 */
23136537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
23146537f381Sas200622 		return (DCMD_USAGE);
23156537f381Sas200622 
23166537f381Sas200622 	return (smb_sid_print(addr));
23176537f381Sas200622 }
23186537f381Sas200622 
23196537f381Sas200622 /*
23206537f381Sas200622  * smb_sid_print
23216537f381Sas200622  */
23226537f381Sas200622 static int
23236537f381Sas200622 smb_sid_print(uintptr_t addr)
23246537f381Sas200622 {
23256537f381Sas200622 	smb_sid_t	sid;
23266537f381Sas200622 	smb_sid_t	*psid;
23276537f381Sas200622 	size_t		sid_size;
23286537f381Sas200622 	int		i;
23296537f381Sas200622 	uint64_t	authority;
23306537f381Sas200622 
2331b819cea2SGordon Ross 	sid_size = OFFSETOF(smb_sid_t, sid_subauth);
23326537f381Sas200622 
23336537f381Sas200622 	if (mdb_vread(&sid, sid_size, addr) != sid_size) {
23346537f381Sas200622 		mdb_warn("failed to read struct smb_sid at %p", addr);
23356537f381Sas200622 		return (DCMD_ERR);
23366537f381Sas200622 	}
23376537f381Sas200622 
23386537f381Sas200622 	sid_size += sid.sid_subauthcnt * sizeof (sid.sid_subauth[0]);
23396537f381Sas200622 
23406537f381Sas200622 	psid = mdb_zalloc(sid_size, UM_SLEEP | UM_GC);
23416537f381Sas200622 	if (mdb_vread(psid, sid_size, addr) != sid_size) {
23426537f381Sas200622 		mdb_warn("failed to read struct smb_sid at %p", addr);
23436537f381Sas200622 		return (DCMD_ERR);
23446537f381Sas200622 	}
23456537f381Sas200622 
23466537f381Sas200622 	mdb_printf("S-%d", psid->sid_revision);
23476537f381Sas200622 	authority = 0;
23486537f381Sas200622 	for (i = 0; i < NT_SID_AUTH_MAX; i++) {
23496537f381Sas200622 		authority += ((uint64_t)psid->sid_authority[i]) <<
23506537f381Sas200622 		    (8 * (NT_SID_AUTH_MAX - 1) - i);
23516537f381Sas200622 	}
23526537f381Sas200622 	mdb_printf("-%ll", authority);
23536537f381Sas200622 
23546537f381Sas200622 	for (i = 0; i < psid->sid_subauthcnt; i++)
23556537f381Sas200622 		mdb_printf("-%d", psid->sid_subauth[i]);
23566537f381Sas200622 
23576537f381Sas200622 	return (DCMD_OK);
23586537f381Sas200622 }
23596537f381Sas200622 
23606537f381Sas200622 /*
23616537f381Sas200622  * *****************************************************************************
23626537f381Sas200622  * ********************************* smb_fssd_t ********************************
23636537f381Sas200622  * *****************************************************************************
23646537f381Sas200622  */
23656537f381Sas200622 
23666537f381Sas200622 /*
23676537f381Sas200622  * ::smbfssd
23686537f381Sas200622  */
23696537f381Sas200622 static int
23706537f381Sas200622 smb_fssd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23716537f381Sas200622 {
23726537f381Sas200622 	smb_fssd_t	fssd;
23736537f381Sas200622 	int		rc;
23746537f381Sas200622 
23756537f381Sas200622 	/*
23766537f381Sas200622 	 * An smb_fssd address is required.
23776537f381Sas200622 	 */
23786537f381Sas200622 	if (!(flags & DCMD_ADDRSPEC))
23796537f381Sas200622 		return (DCMD_USAGE);
23806537f381Sas200622 
23816537f381Sas200622 	if (mdb_vread(&fssd, sizeof (fssd), addr) != sizeof (fssd)) {
23826537f381Sas200622 		mdb_warn("failed to read struct smb_fssd at %p", addr);
23836537f381Sas200622 		return (DCMD_ERR);
23846537f381Sas200622 	}
23856537f381Sas200622 
23866537f381Sas200622 	mdb_printf("FSSD secinfo: 0x%x\n", fssd.sd_secinfo);
23876537f381Sas200622 	if (fssd.sd_secinfo & SMB_OWNER_SECINFO)
23886537f381Sas200622 		mdb_printf("FSSD uid: %d\n", fssd.sd_uid);
23896537f381Sas200622 	if (fssd.sd_secinfo & SMB_GROUP_SECINFO)
23906537f381Sas200622 		mdb_printf("FSSD gid: %d\n", fssd.sd_gid);
23916537f381Sas200622 	if (fssd.sd_secinfo & SMB_SACL_SECINFO && fssd.sd_zsacl) {
23926537f381Sas200622 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
23936537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
23946537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zsacl, flags,
23956537f381Sas200622 		    argc, argv);
23966537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
23976537f381Sas200622 		if (rc != DCMD_OK)
23986537f381Sas200622 			return (rc);
23996537f381Sas200622 	}
24006537f381Sas200622 	if (fssd.sd_secinfo & SMB_DACL_SECINFO && fssd.sd_zdacl) {
24016537f381Sas200622 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
24026537f381Sas200622 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
24036537f381Sas200622 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zdacl, flags,
24046537f381Sas200622 		    argc, argv);
24056537f381Sas200622 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
24066537f381Sas200622 		if (rc != DCMD_OK)
24076537f381Sas200622 			return (rc);
24086537f381Sas200622 	}
24096537f381Sas200622 
24106537f381Sas200622 	return (DCMD_OK);
24116537f381Sas200622 }
24126537f381Sas200622 
24136537f381Sas200622 /*
24146537f381Sas200622  * *****************************************************************************
24156537f381Sas200622  * **************************** Utility Funcions *******************************
24166537f381Sas200622  * *****************************************************************************
24176537f381Sas200622  */
24186537f381Sas200622 
24196537f381Sas200622 /*
24206537f381Sas200622  * smb_dcmd_getopt
24216537f381Sas200622  *
24226537f381Sas200622  * This function analyzes the arguments passed in and sets the bit corresponding
24236537f381Sas200622  * to the options found in the opts variable.
24246537f381Sas200622  *
24256537f381Sas200622  * Return Value
24266537f381Sas200622  *
24276537f381Sas200622  *	-1	An error occured during the decoding
24286537f381Sas200622  *	0	The decoding was successful
24296537f381Sas200622  */
24306537f381Sas200622 static int
24316537f381Sas200622 smb_dcmd_getopt(uint_t *opts, int argc, const mdb_arg_t *argv)
24326537f381Sas200622 {
24336537f381Sas200622 	*opts = 0;
24346537f381Sas200622 
24356537f381Sas200622 	if (mdb_getopts(argc, argv,
24366537f381Sas200622 	    's', MDB_OPT_SETBITS, SMB_OPT_SERVER, opts,
24376537f381Sas200622 	    'e', MDB_OPT_SETBITS, SMB_OPT_SESSION, opts,
24386537f381Sas200622 	    'r', MDB_OPT_SETBITS, SMB_OPT_REQUEST, opts,
24396537f381Sas200622 	    'u', MDB_OPT_SETBITS, SMB_OPT_USER, opts,
24406537f381Sas200622 	    't', MDB_OPT_SETBITS, SMB_OPT_TREE, opts,
24416537f381Sas200622 	    'f', MDB_OPT_SETBITS, SMB_OPT_OFILE, opts,
24426537f381Sas200622 	    'd', MDB_OPT_SETBITS, SMB_OPT_ODIR, opts,
24436537f381Sas200622 	    'w', MDB_OPT_SETBITS, SMB_OPT_WALK, opts,
24446537f381Sas200622 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, opts,
24456537f381Sas200622 	    NULL) != argc)
24466537f381Sas200622 		return (-1);
24476537f381Sas200622 
24486537f381Sas200622 	return (0);
24496537f381Sas200622 }
24506537f381Sas200622 
24516537f381Sas200622 /*
24526537f381Sas200622  * smb_dcmd_setopt
24536537f381Sas200622  *
24546537f381Sas200622  * This function set the arguments corresponding to the bits set in opts.
24556537f381Sas200622  *
24566537f381Sas200622  * Return Value
24576537f381Sas200622  *
24586537f381Sas200622  *	Number of arguments set.
24596537f381Sas200622  */
24606537f381Sas200622 static int
24616537f381Sas200622 smb_dcmd_setopt(uint_t opts, int max_argc, mdb_arg_t *argv)
24626537f381Sas200622 {
24636537f381Sas200622 	int	i;
24646537f381Sas200622 	int	argc = 0;
24656537f381Sas200622 
24666537f381Sas200622 	for (i = 0; i < SMB_MDB_MAX_OPTS; i++) {
2467148c5f43SAlan Wright 		if ((opts & smb_opts[i].o_value) && (argc < max_argc)) {
24686537f381Sas200622 			argv->a_type = MDB_TYPE_STRING;
2469148c5f43SAlan Wright 			argv->a_un.a_str = smb_opts[i].o_name;
24706537f381Sas200622 			argc++;
24716537f381Sas200622 			argv++;
24726537f381Sas200622 		}
24736537f381Sas200622 	}
24746537f381Sas200622 	return (argc);
24756537f381Sas200622 }
24766537f381Sas200622 
24776537f381Sas200622 /*
24786537f381Sas200622  * smb_obj_expand
24796537f381Sas200622  */
24806537f381Sas200622 static int
24816537f381Sas200622 smb_obj_expand(uintptr_t addr, uint_t opts, const smb_exp_t *x, ulong_t indent)
24826537f381Sas200622 {
24836537f381Sas200622 	int		rc = 0;
24846537f381Sas200622 	int		argc;
24856537f381Sas200622 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
24866537f381Sas200622 
24876537f381Sas200622 	argc = smb_dcmd_setopt(opts | SMB_OPT_WALK, SMB_MDB_MAX_OPTS, argv);
24886537f381Sas200622 
24896537f381Sas200622 	(void) mdb_inc_indent(indent);
24906537f381Sas200622 	while (x->ex_dcmd) {
24916537f381Sas200622 		if (x->ex_mask & opts) {
24926537f381Sas200622 			rc = mdb_pwalk_dcmd("list", x->ex_dcmd, argc, argv,
24936537f381Sas200622 			    addr + x->ex_offset);
24946537f381Sas200622 
24956537f381Sas200622 			if (rc) {
24966537f381Sas200622 				mdb_warn("failed to walk the list of %s in %p",
24976537f381Sas200622 				    x->ex_name, addr + x->ex_offset);
24986537f381Sas200622 				break;
24996537f381Sas200622 			}
25006537f381Sas200622 		}
25016537f381Sas200622 		x++;
25026537f381Sas200622 	}
25036537f381Sas200622 	(void) mdb_dec_indent(indent);
25046537f381Sas200622 	return (rc);
25056537f381Sas200622 }
25066537f381Sas200622 
25076537f381Sas200622 /*
25086537f381Sas200622  * smb_obj_list
25096537f381Sas200622  *
25106537f381Sas200622  * Function called by the DCMDs when no address is provided. It expands the
25116537f381Sas200622  * tree under the object type associated with the calling DCMD (based on the
25126537f381Sas200622  * flags passed in).
25136537f381Sas200622  *
25146537f381Sas200622  * Return Value
25156537f381Sas200622  *
25166537f381Sas200622  *	DCMD_OK
25176537f381Sas200622  *	DCMD_ERR
25186537f381Sas200622  */
25196537f381Sas200622 static int
25206537f381Sas200622 smb_obj_list(const char *name, uint_t opts, uint_t flags)
25216537f381Sas200622 {
25226537f381Sas200622 	int		argc;
25236537f381Sas200622 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
25246537f381Sas200622 
25256537f381Sas200622 	argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, argv);
25266537f381Sas200622 
25276537f381Sas200622 	if (mdb_call_dcmd("smblist", 0, flags, argc, argv)) {
25286537f381Sas200622 		mdb_warn("failed to list %s", name);
25296537f381Sas200622 		return (DCMD_ERR);
25306537f381Sas200622 	}
25316537f381Sas200622 	return (DCMD_OK);
2532da6c28aaSamw }
2533fc724630SAlan Wright 
2534fc724630SAlan Wright static int
2535fc724630SAlan Wright smb_worker_findstack(uintptr_t addr)
2536fc724630SAlan Wright {
2537fc724630SAlan Wright 	char		cmd[80];
2538fc724630SAlan Wright 	mdb_arg_t	cmdarg;
2539fc724630SAlan Wright 
2540fc724630SAlan Wright 	mdb_inc_indent(2);
2541fc724630SAlan Wright 	mdb_snprintf(cmd, sizeof (cmd), "<.$c%d", 16);
2542fc724630SAlan Wright 	cmdarg.a_type = MDB_TYPE_STRING;
2543fc724630SAlan Wright 	cmdarg.a_un.a_str = cmd;
2544fc724630SAlan Wright 	(void) mdb_call_dcmd("findstack", addr, DCMD_ADDRSPEC, 1, &cmdarg);
2545fc724630SAlan Wright 	mdb_dec_indent(2);
2546fc724630SAlan Wright 	mdb_printf("\n");
2547fc724630SAlan Wright 	return (DCMD_OK);
2548fc724630SAlan Wright }
2549