xref: /titanic_50/usr/src/cmd/mdb/common/modules/smbsrv/smbsrv.c (revision 380bdfdf3b87cbfda20ccdf5d4fa7c129623622b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
25  */
26 
27 #include <mdb/mdb_modapi.h>
28 #include <mdb/mdb_ks.h>
29 #include <sys/thread.h>
30 #include <sys/taskq_impl.h>
31 #include <smbsrv/smb_vops.h>
32 #include <smbsrv/smb.h>
33 #include <smbsrv/smb_ktypes.h>
34 
35 #define	SMB_DCMD_INDENT		2
36 #define	ACE_TYPE_TABLEN		(ACE_ALL_TYPES + 1)
37 #define	ACE_TYPE_ENTRY(_v_)	{_v_, #_v_}
38 #define	SMB_COM_ENTRY(_v_, _x_)	{#_v_, _x_}
39 
40 #define	SMB_MDB_MAX_OPTS	9
41 
42 #define	SMB_OPT_SERVER		0x00000001
43 #define	SMB_OPT_SESSION		0x00000002
44 #define	SMB_OPT_REQUEST		0x00000004
45 #define	SMB_OPT_USER		0x00000008
46 #define	SMB_OPT_TREE		0x00000010
47 #define	SMB_OPT_OFILE		0x00000020
48 #define	SMB_OPT_ODIR		0x00000040
49 #define	SMB_OPT_WALK		0x00000100
50 #define	SMB_OPT_VERBOSE		0x00000200
51 #define	SMB_OPT_ALL_OBJ		0x000000FF
52 
53 /*
54  * Structure associating an ACE type to a string.
55  */
56 typedef struct {
57 	uint8_t		ace_type_value;
58 	const char	*ace_type_sting;
59 } ace_type_entry_t;
60 
61 /*
62  * Structure containing strings describing an SMB command.
63  */
64 typedef struct {
65 	const char	*smb_com;
66 	const char	*smb_andx;
67 } smb_com_entry_t;
68 
69 /*
70  * Structure describing an object to be expanded (displayed).
71  */
72 typedef struct {
73 	uint_t		ex_mask;
74 	size_t		ex_offset;
75 	const char	*ex_dcmd;
76 	const char	*ex_name;
77 } smb_exp_t;
78 
79 /*
80  * List of supported options. Ther order has the match the bits SMB_OPT_xxx.
81  */
82 typedef struct smb_mdb_opts {
83 	char		*o_name;
84 	uint32_t	o_value;
85 } smb_mdb_opts_t;
86 
87 static smb_mdb_opts_t smb_opts[SMB_MDB_MAX_OPTS] =
88 {
89 	{ "-s", SMB_OPT_SERVER	},
90 	{ "-e", SMB_OPT_SESSION	},
91 	{ "-r", SMB_OPT_REQUEST	},
92 	{ "-u", SMB_OPT_USER	},
93 	{ "-t", SMB_OPT_TREE	},
94 	{ "-f", SMB_OPT_OFILE	},
95 	{ "-d", SMB_OPT_ODIR	},
96 	{ "-w", SMB_OPT_WALK	},
97 	{ "-v", SMB_OPT_VERBOSE	}
98 };
99 
100 static smb_com_entry_t	smb_com[256] =
101 {
102 	SMB_COM_ENTRY(SMB_COM_CREATE_DIRECTORY, "No"),
103 	SMB_COM_ENTRY(SMB_COM_DELETE_DIRECTORY, "No"),
104 	SMB_COM_ENTRY(SMB_COM_OPEN, "No"),
105 	SMB_COM_ENTRY(SMB_COM_CREATE, "No"),
106 	SMB_COM_ENTRY(SMB_COM_CLOSE, "No"),
107 	SMB_COM_ENTRY(SMB_COM_FLUSH, "No"),
108 	SMB_COM_ENTRY(SMB_COM_DELETE, "No"),
109 	SMB_COM_ENTRY(SMB_COM_RENAME, "No"),
110 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION, "No"),
111 	SMB_COM_ENTRY(SMB_COM_SET_INFORMATION, "No"),
112 	SMB_COM_ENTRY(SMB_COM_READ, "No"),
113 	SMB_COM_ENTRY(SMB_COM_WRITE, "No"),
114 	SMB_COM_ENTRY(SMB_COM_LOCK_BYTE_RANGE, "No"),
115 	SMB_COM_ENTRY(SMB_COM_UNLOCK_BYTE_RANGE, "No"),
116 	SMB_COM_ENTRY(SMB_COM_CREATE_TEMPORARY, "No"),
117 	SMB_COM_ENTRY(SMB_COM_CREATE_NEW, "No"),
118 	SMB_COM_ENTRY(SMB_COM_CHECK_DIRECTORY, "No"),
119 	SMB_COM_ENTRY(SMB_COM_PROCESS_EXIT, "No"),
120 	SMB_COM_ENTRY(SMB_COM_SEEK, "No"),
121 	SMB_COM_ENTRY(SMB_COM_LOCK_AND_READ, "No"),
122 	SMB_COM_ENTRY(SMB_COM_WRITE_AND_UNLOCK, "No"),
123 	SMB_COM_ENTRY(0x15, "?"),
124 	SMB_COM_ENTRY(0x16, "?"),
125 	SMB_COM_ENTRY(0x17, "?"),
126 	SMB_COM_ENTRY(0x18, "?"),
127 	SMB_COM_ENTRY(0x19, "?"),
128 	SMB_COM_ENTRY(SMB_COM_READ_RAW, "No"),
129 	SMB_COM_ENTRY(SMB_COM_READ_MPX, "No"),
130 	SMB_COM_ENTRY(SMB_COM_READ_MPX_SECONDARY, "No"),
131 	SMB_COM_ENTRY(SMB_COM_WRITE_RAW, "No"),
132 	SMB_COM_ENTRY(SMB_COM_WRITE_MPX, "No"),
133 	SMB_COM_ENTRY(SMB_COM_WRITE_MPX_SECONDARY, "No"),
134 	SMB_COM_ENTRY(SMB_COM_WRITE_COMPLETE, "No"),
135 	SMB_COM_ENTRY(SMB_COM_QUERY_SERVER, "No"),
136 	SMB_COM_ENTRY(SMB_COM_SET_INFORMATION2, "No"),
137 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION2, "No"),
138 	SMB_COM_ENTRY(SMB_COM_LOCKING_ANDX, "No"),
139 	SMB_COM_ENTRY(SMB_COM_TRANSACTION, "No"),
140 	SMB_COM_ENTRY(SMB_COM_TRANSACTION_SECONDARY, "No"),
141 	SMB_COM_ENTRY(SMB_COM_IOCTL, "No"),
142 	SMB_COM_ENTRY(SMB_COM_IOCTL_SECONDARY, "No"),
143 	SMB_COM_ENTRY(SMB_COM_COPY, "No"),
144 	SMB_COM_ENTRY(SMB_COM_MOVE, "No"),
145 	SMB_COM_ENTRY(SMB_COM_ECHO, "No"),
146 	SMB_COM_ENTRY(SMB_COM_WRITE_AND_CLOSE, "No"),
147 	SMB_COM_ENTRY(SMB_COM_OPEN_ANDX, "No"),
148 	SMB_COM_ENTRY(SMB_COM_READ_ANDX, "No"),
149 	SMB_COM_ENTRY(SMB_COM_WRITE_ANDX, "No"),
150 	SMB_COM_ENTRY(SMB_COM_NEW_FILE_SIZE, "No"),
151 	SMB_COM_ENTRY(SMB_COM_CLOSE_AND_TREE_DISC, "No"),
152 	SMB_COM_ENTRY(SMB_COM_TRANSACTION2, "No"),
153 	SMB_COM_ENTRY(SMB_COM_TRANSACTION2_SECONDARY, "No"),
154 	SMB_COM_ENTRY(SMB_COM_FIND_CLOSE2, "No"),
155 	SMB_COM_ENTRY(SMB_COM_FIND_NOTIFY_CLOSE, "No"),
156 	SMB_COM_ENTRY(0x36, "?"),
157 	SMB_COM_ENTRY(0x37, "?"),
158 	SMB_COM_ENTRY(0x38, "?"),
159 	SMB_COM_ENTRY(0x39, "?"),
160 	SMB_COM_ENTRY(0x3A, "?"),
161 	SMB_COM_ENTRY(0x3B, "?"),
162 	SMB_COM_ENTRY(0x3C, "?"),
163 	SMB_COM_ENTRY(0x3D, "?"),
164 	SMB_COM_ENTRY(0x3E, "?"),
165 	SMB_COM_ENTRY(0x3F, "?"),
166 	SMB_COM_ENTRY(0x40, "?"),
167 	SMB_COM_ENTRY(0x41, "?"),
168 	SMB_COM_ENTRY(0x42, "?"),
169 	SMB_COM_ENTRY(0x43, "?"),
170 	SMB_COM_ENTRY(0x44, "?"),
171 	SMB_COM_ENTRY(0x45, "?"),
172 	SMB_COM_ENTRY(0x46, "?"),
173 	SMB_COM_ENTRY(0x47, "?"),
174 	SMB_COM_ENTRY(0x48, "?"),
175 	SMB_COM_ENTRY(0x49, "?"),
176 	SMB_COM_ENTRY(0x4A, "?"),
177 	SMB_COM_ENTRY(0x4B, "?"),
178 	SMB_COM_ENTRY(0x4C, "?"),
179 	SMB_COM_ENTRY(0x4D, "?"),
180 	SMB_COM_ENTRY(0x4E, "?"),
181 	SMB_COM_ENTRY(0x4F, "?"),
182 	SMB_COM_ENTRY(0x50, "?"),
183 	SMB_COM_ENTRY(0x51, "?"),
184 	SMB_COM_ENTRY(0x52, "?"),
185 	SMB_COM_ENTRY(0x53, "?"),
186 	SMB_COM_ENTRY(0x54, "?"),
187 	SMB_COM_ENTRY(0x55, "?"),
188 	SMB_COM_ENTRY(0x56, "?"),
189 	SMB_COM_ENTRY(0x57, "?"),
190 	SMB_COM_ENTRY(0x58, "?"),
191 	SMB_COM_ENTRY(0x59, "?"),
192 	SMB_COM_ENTRY(0x5A, "?"),
193 	SMB_COM_ENTRY(0x5B, "?"),
194 	SMB_COM_ENTRY(0x5C, "?"),
195 	SMB_COM_ENTRY(0x5D, "?"),
196 	SMB_COM_ENTRY(0x5E, "?"),
197 	SMB_COM_ENTRY(0x5F, "?"),
198 	SMB_COM_ENTRY(0x60, "?"),
199 	SMB_COM_ENTRY(0x61, "?"),
200 	SMB_COM_ENTRY(0x62, "?"),
201 	SMB_COM_ENTRY(0x63, "?"),
202 	SMB_COM_ENTRY(0x64, "?"),
203 	SMB_COM_ENTRY(0x65, "?"),
204 	SMB_COM_ENTRY(0x66, "?"),
205 	SMB_COM_ENTRY(0x67, "?"),
206 	SMB_COM_ENTRY(0x68, "?"),
207 	SMB_COM_ENTRY(0x69, "?"),
208 	SMB_COM_ENTRY(0x6A, "?"),
209 	SMB_COM_ENTRY(0x6B, "?"),
210 	SMB_COM_ENTRY(0x6C, "?"),
211 	SMB_COM_ENTRY(0x6D, "?"),
212 	SMB_COM_ENTRY(0x6E, "?"),
213 	SMB_COM_ENTRY(0x6F, "?"),
214 	SMB_COM_ENTRY(SMB_COM_TREE_CONNECT, "No"),
215 	SMB_COM_ENTRY(SMB_COM_TREE_DISCONNECT, "No"),
216 	SMB_COM_ENTRY(SMB_COM_NEGOTIATE, "No"),
217 	SMB_COM_ENTRY(SMB_COM_SESSION_SETUP_ANDX, "No"),
218 	SMB_COM_ENTRY(SMB_COM_LOGOFF_ANDX, "No"),
219 	SMB_COM_ENTRY(SMB_COM_TREE_CONNECT_ANDX, "No"),
220 	SMB_COM_ENTRY(0x76, "?"),
221 	SMB_COM_ENTRY(0x77, "?"),
222 	SMB_COM_ENTRY(0x78, "?"),
223 	SMB_COM_ENTRY(0x79, "?"),
224 	SMB_COM_ENTRY(0x7A, "?"),
225 	SMB_COM_ENTRY(0x7B, "?"),
226 	SMB_COM_ENTRY(0x7C, "?"),
227 	SMB_COM_ENTRY(0x7D, "?"),
228 	SMB_COM_ENTRY(0x7E, "?"),
229 	SMB_COM_ENTRY(0x7F, "?"),
230 	SMB_COM_ENTRY(SMB_COM_QUERY_INFORMATION_DISK, "No"),
231 	SMB_COM_ENTRY(SMB_COM_SEARCH, "No"),
232 	SMB_COM_ENTRY(SMB_COM_FIND, "No"),
233 	SMB_COM_ENTRY(SMB_COM_FIND_UNIQUE, "No"),
234 	SMB_COM_ENTRY(SMB_COM_FIND_CLOSE, "No"),
235 	SMB_COM_ENTRY(0x85, "?"),
236 	SMB_COM_ENTRY(0x86, "?"),
237 	SMB_COM_ENTRY(0x87, "?"),
238 	SMB_COM_ENTRY(0x88, "?"),
239 	SMB_COM_ENTRY(0x89, "?"),
240 	SMB_COM_ENTRY(0x8A, "?"),
241 	SMB_COM_ENTRY(0x8B, "?"),
242 	SMB_COM_ENTRY(0x8C, "?"),
243 	SMB_COM_ENTRY(0x8D, "?"),
244 	SMB_COM_ENTRY(0x8E, "?"),
245 	SMB_COM_ENTRY(0x8F, "?"),
246 	SMB_COM_ENTRY(0x90, "?"),
247 	SMB_COM_ENTRY(0x91, "?"),
248 	SMB_COM_ENTRY(0x92, "?"),
249 	SMB_COM_ENTRY(0x93, "?"),
250 	SMB_COM_ENTRY(0x94, "?"),
251 	SMB_COM_ENTRY(0x95, "?"),
252 	SMB_COM_ENTRY(0x96, "?"),
253 	SMB_COM_ENTRY(0x97, "?"),
254 	SMB_COM_ENTRY(0x98, "?"),
255 	SMB_COM_ENTRY(0x99, "?"),
256 	SMB_COM_ENTRY(0x9A, "?"),
257 	SMB_COM_ENTRY(0x9B, "?"),
258 	SMB_COM_ENTRY(0x9C, "?"),
259 	SMB_COM_ENTRY(0x9D, "?"),
260 	SMB_COM_ENTRY(0x9E, "?"),
261 	SMB_COM_ENTRY(0x9F, "?"),
262 	SMB_COM_ENTRY(SMB_COM_NT_TRANSACT, "No"),
263 	SMB_COM_ENTRY(SMB_COM_NT_TRANSACT_SECONDARY, "No"),
264 	SMB_COM_ENTRY(SMB_COM_NT_CREATE_ANDX, "No"),
265 	SMB_COM_ENTRY(0xA3, "?"),
266 	SMB_COM_ENTRY(SMB_COM_NT_CANCEL, "No"),
267 	SMB_COM_ENTRY(SMB_COM_NT_RENAME, "No"),
268 	SMB_COM_ENTRY(0xA6, "?"),
269 	SMB_COM_ENTRY(0xA7, "?"),
270 	SMB_COM_ENTRY(0xA8, "?"),
271 	SMB_COM_ENTRY(0xA9, "?"),
272 	SMB_COM_ENTRY(0xAA, "?"),
273 	SMB_COM_ENTRY(0xAB, "?"),
274 	SMB_COM_ENTRY(0xAC, "?"),
275 	SMB_COM_ENTRY(0xAD, "?"),
276 	SMB_COM_ENTRY(0xAE, "?"),
277 	SMB_COM_ENTRY(0xAF, "?"),
278 	SMB_COM_ENTRY(0xB0, "?"),
279 	SMB_COM_ENTRY(0xB1, "?"),
280 	SMB_COM_ENTRY(0xB2, "?"),
281 	SMB_COM_ENTRY(0xB3, "?"),
282 	SMB_COM_ENTRY(0xB4, "?"),
283 	SMB_COM_ENTRY(0xB5, "?"),
284 	SMB_COM_ENTRY(0xB6, "?"),
285 	SMB_COM_ENTRY(0xB7, "?"),
286 	SMB_COM_ENTRY(0xB8, "?"),
287 	SMB_COM_ENTRY(0xB9, "?"),
288 	SMB_COM_ENTRY(0xBA, "?"),
289 	SMB_COM_ENTRY(0xBB, "?"),
290 	SMB_COM_ENTRY(0xBC, "?"),
291 	SMB_COM_ENTRY(0xBD, "?"),
292 	SMB_COM_ENTRY(0xBE, "?"),
293 	SMB_COM_ENTRY(0xBF, "?"),
294 	SMB_COM_ENTRY(SMB_COM_OPEN_PRINT_FILE, "No"),
295 	SMB_COM_ENTRY(SMB_COM_WRITE_PRINT_FILE, "No"),
296 	SMB_COM_ENTRY(SMB_COM_CLOSE_PRINT_FILE, "No"),
297 	SMB_COM_ENTRY(SMB_COM_GET_PRINT_QUEUE, "No"),
298 	SMB_COM_ENTRY(0xC4, "?"),
299 	SMB_COM_ENTRY(0xC5, "?"),
300 	SMB_COM_ENTRY(0xC6, "?"),
301 	SMB_COM_ENTRY(0xC7, "?"),
302 	SMB_COM_ENTRY(0xC8, "?"),
303 	SMB_COM_ENTRY(0xC9, "?"),
304 	SMB_COM_ENTRY(0xCA, "?"),
305 	SMB_COM_ENTRY(0xCB, "?"),
306 	SMB_COM_ENTRY(0xCC, "?"),
307 	SMB_COM_ENTRY(0xCD, "?"),
308 	SMB_COM_ENTRY(0xCE, "?"),
309 	SMB_COM_ENTRY(0xCF, "?"),
310 	SMB_COM_ENTRY(0xD0, "?"),
311 	SMB_COM_ENTRY(0xD1, "?"),
312 	SMB_COM_ENTRY(0xD2, "?"),
313 	SMB_COM_ENTRY(0xD3, "?"),
314 	SMB_COM_ENTRY(0xD4, "?"),
315 	SMB_COM_ENTRY(0xD5, "?"),
316 	SMB_COM_ENTRY(0xD6, "?"),
317 	SMB_COM_ENTRY(0xD7, "?"),
318 	SMB_COM_ENTRY(SMB_COM_READ_BULK, "No"),
319 	SMB_COM_ENTRY(SMB_COM_WRITE_BULK, "No"),
320 	SMB_COM_ENTRY(SMB_COM_WRITE_BULK_DATA, "No"),
321 	SMB_COM_ENTRY(0xDB, "?"),
322 	SMB_COM_ENTRY(0xDC, "?"),
323 	SMB_COM_ENTRY(0xDD, "?"),
324 	SMB_COM_ENTRY(0xDE, "?"),
325 	SMB_COM_ENTRY(0xDF, "?"),
326 	SMB_COM_ENTRY(0xE0, "?"),
327 	SMB_COM_ENTRY(0xE1, "?"),
328 	SMB_COM_ENTRY(0xE2, "?"),
329 	SMB_COM_ENTRY(0xE3, "?"),
330 	SMB_COM_ENTRY(0xE4, "?"),
331 	SMB_COM_ENTRY(0xE5, "?"),
332 	SMB_COM_ENTRY(0xE6, "?"),
333 	SMB_COM_ENTRY(0xE7, "?"),
334 	SMB_COM_ENTRY(0xE8, "?"),
335 	SMB_COM_ENTRY(0xE9, "?"),
336 	SMB_COM_ENTRY(0xEA, "?"),
337 	SMB_COM_ENTRY(0xEB, "?"),
338 	SMB_COM_ENTRY(0xEC, "?"),
339 	SMB_COM_ENTRY(0xED, "?"),
340 	SMB_COM_ENTRY(0xEE, "?"),
341 	SMB_COM_ENTRY(0xEF, "?"),
342 	SMB_COM_ENTRY(0xF0, "?"),
343 	SMB_COM_ENTRY(0xF1, "?"),
344 	SMB_COM_ENTRY(0xF2, "?"),
345 	SMB_COM_ENTRY(0xF3, "?"),
346 	SMB_COM_ENTRY(0xF4, "?"),
347 	SMB_COM_ENTRY(0xF5, "?"),
348 	SMB_COM_ENTRY(0xF6, "?"),
349 	SMB_COM_ENTRY(0xF7, "?"),
350 	SMB_COM_ENTRY(0xF8, "?"),
351 	SMB_COM_ENTRY(0xF9, "?"),
352 	SMB_COM_ENTRY(0xFA, "?"),
353 	SMB_COM_ENTRY(0xFB, "?"),
354 	SMB_COM_ENTRY(0xFC, "?"),
355 	SMB_COM_ENTRY(0xFD, "?"),
356 	SMB_COM_ENTRY(0xFE, "?"),
357 	SMB_COM_ENTRY(0xFF, "?")
358 };
359 
360 static int smb_dcmd_list(uintptr_t, uint_t, int, const mdb_arg_t *);
361 static void smb_dcmd_list_help(void);
362 static int smb_dcmd_server(uintptr_t, uint_t, int, const mdb_arg_t *);
363 static void smb_dcmd_session_help(void);
364 static int smb_dcmd_session(uintptr_t, uint_t, int, const mdb_arg_t *);
365 static int smb_dcmd_request(uintptr_t, uint_t, int, const mdb_arg_t *);
366 static void smb_dcmd_user_help(void);
367 static int smb_dcmd_user(uintptr_t, uint_t, int, const mdb_arg_t *);
368 static void smb_dcmd_tree_help(void);
369 static int smb_dcmd_tree(uintptr_t, uint_t, int, const mdb_arg_t *);
370 static int smb_dcmd_odir(uintptr_t, uint_t, int, const mdb_arg_t *);
371 static int smb_dcmd_ofile(uintptr_t, uint_t, int, const mdb_arg_t *);
372 static int smb_dcmd_kshare(uintptr_t, uint_t, int, const mdb_arg_t *);
373 static int smb_dcmd_vfs(uintptr_t, uint_t, int, const mdb_arg_t *);
374 static int smb_vfs_walk_init(mdb_walk_state_t *);
375 static int smb_vfs_walk_step(mdb_walk_state_t *);
376 static void smb_node_help(void);
377 static int smb_dcmd_node(uintptr_t, uint_t, int, const mdb_arg_t *);
378 static int smb_node_walk_init(mdb_walk_state_t *);
379 static int smb_node_walk_step(mdb_walk_state_t *);
380 static int smb_lock(uintptr_t, uint_t, int, const mdb_arg_t *);
381 static int smb_oplock(uintptr_t, uint_t, int, const mdb_arg_t *);
382 static int smb_oplock_grant(uintptr_t, uint_t, int, const mdb_arg_t *);
383 static int smb_ace(uintptr_t, uint_t, int, const mdb_arg_t *);
384 static int smb_ace_walk_init(mdb_walk_state_t *);
385 static int smb_ace_walk_step(mdb_walk_state_t *);
386 static int smb_acl(uintptr_t, uint_t, int, const mdb_arg_t *);
387 static int smb_sd(uintptr_t, uint_t, int, const mdb_arg_t *);
388 static int smb_sid(uintptr_t, uint_t, int, const mdb_arg_t *);
389 static int smb_sid_print(uintptr_t);
390 static int smb_fssd(uintptr_t, uint_t, int, const mdb_arg_t *);
391 static int smb_dcmd_getopt(uint_t *, int, const mdb_arg_t *);
392 static int smb_dcmd_setopt(uint_t, int, mdb_arg_t *);
393 static int smb_obj_expand(uintptr_t, uint_t, const smb_exp_t *, ulong_t);
394 static int smb_obj_list(const char *, uint_t, uint_t);
395 static int smb_worker_findstack(uintptr_t);
396 static int smb_stats(uintptr_t, uint_t, int, const mdb_arg_t *);
397 
398 /*
399  * MDB module linkage information:
400  *
401  * We declare a list of structures describing our dcmds, a list of structures
402  * describing our walkers and a function named _mdb_init to return a pointer
403  * to our module information.
404  */
405 static const mdb_dcmd_t dcmds[] = {
406 	{   "smblist",
407 	    "[-seutfdwv]",
408 	    "print tree of SMB objects",
409 	    smb_dcmd_list,
410 	    smb_dcmd_list_help },
411 	{   "smbsrv",
412 	    "[-seutfdwv]",
413 	    "print smb_server information",
414 	    smb_dcmd_server },
415 	{   "smbshares",
416 	    "[-v]",
417 	    "print smb_kshare_t information",
418 	    smb_dcmd_kshare },
419 	{   "smbvfs",
420 	    "[-v]",
421 	    "print smb_vfs information",
422 	    smb_dcmd_vfs },
423 	{   "smbnode",
424 	    "?[-vps]",
425 	    "print smb_node_t information",
426 	    smb_dcmd_node,
427 	    smb_node_help },
428 	{   "smbsess",
429 	    "[-utfdwv]",
430 	    "print smb_session_t information",
431 	    smb_dcmd_session,
432 	    smb_dcmd_session_help},
433 	{   "smbreq",
434 	    ":[-v]",
435 	    "print smb_request_t information",
436 	    smb_dcmd_request },
437 	{   "smblock", ":[-v]",
438 	    "print smb_lock_t information", smb_lock },
439 	{   "smbuser",
440 	    ":[-vdftq]",
441 	    "print smb_user_t information",
442 	    smb_dcmd_user,
443 	    smb_dcmd_user_help },
444 	{   "smbtree",
445 	    ":[-vdf]",
446 	    "print smb_tree_t information",
447 	    smb_dcmd_tree,
448 	    smb_dcmd_tree_help },
449 	{   "smbodir",
450 	    ":[-v]",
451 	    "print smb_odir_t information",
452 	    smb_dcmd_odir },
453 	{   "smbofile",
454 	    "[-v]",
455 	    "print smb_file_t information",
456 	    smb_dcmd_ofile },
457 	{   "smboplock", NULL,
458 	    "print smb_oplock_t information", smb_oplock },
459 	{   "smboplockgrant", NULL,
460 	    "print smb_oplock_grant_t information", smb_oplock_grant },
461 	{   "smbstat", NULL,
462 	    "print all smb dispatched requests statistics",
463 	    smb_stats },
464 	{   "smbace", "[-v]",
465 	    "print smb_ace_t information", smb_ace },
466 	{   "smbacl", "[-v]",
467 	    "print smb_acl_t information", smb_acl },
468 	{   "smbsid", "[-v]",
469 	    "print smb_sid_t information", smb_sid },
470 	{   "smbsd", "[-v]",
471 	    "print smb_sd_t information", smb_sd },
472 	{   "smbfssd", "[-v]",
473 	    "print smb_fssd_t information", smb_fssd },
474 	{ NULL }
475 };
476 
477 static const mdb_walker_t walkers[] = {
478 	{   "smbnode_walker",
479 	    "walk list of smb_node_t structures",
480 	    smb_node_walk_init,
481 	    smb_node_walk_step,
482 	    NULL,
483 	    NULL },
484 	{   "smbvfs_walker",
485 	    "walk list of smb_vfs_t structures",
486 	    smb_vfs_walk_init,
487 	    smb_vfs_walk_step,
488 	    NULL,
489 	    NULL },
490 	{   "smbace_walker",
491 	    "walk list of smb_ace_t structures",
492 	    smb_ace_walk_init,
493 	    smb_ace_walk_step,
494 	    NULL,
495 	    NULL },
496 	{ NULL }
497 };
498 
499 static const mdb_modinfo_t modinfo = {
500 	MDB_API_VERSION, dcmds, walkers
501 };
502 
503 const mdb_modinfo_t *
504 _mdb_init(void)
505 {
506 	return (&modinfo);
507 }
508 
509 /*
510  * *****************************************************************************
511  * ****************************** Top level DCMD *******************************
512  * *****************************************************************************
513  */
514 
515 static void
516 smb_dcmd_list_help(void)
517 {
518 	mdb_printf(
519 	    "Displays the list of objects using an indented tree format.\n"
520 	    "If no option is specified the entire tree is displayed\n\n");
521 	(void) mdb_dec_indent(2);
522 	mdb_printf("%<b>OPTIONS%</b>\n");
523 	(void) mdb_inc_indent(2);
524 	mdb_printf(
525 	    "-v\tDisplay verbose information\n"
526 	    "-s\tDisplay the list of servers\n"
527 	    "-e\tDisplay the list of sessions\n"
528 	    "-r\tDisplay the list of smb requests\n"
529 	    "-u\tDisplay the list of users\n"
530 	    "-t\tDisplay the list of trees\n"
531 	    "-f\tDisplay the list of open files\n"
532 	    "-d\tDisplay the list of open searches\n");
533 }
534 
535 /*
536  * ::smblist
537  *
538  * This function lists the objects specified on the command line. If no object
539  * is specified the entire tree (server through ofile and odir) is displayed.
540  *
541  */
542 /*ARGSUSED*/
543 static int
544 smb_dcmd_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
545 {
546 	GElf_Sym	sym;
547 	uint_t		opts = 0;
548 	int		new_argc;
549 	mdb_arg_t	new_argv[SMB_MDB_MAX_OPTS];
550 
551 	if (smb_dcmd_getopt(&opts, argc, argv))
552 		return (DCMD_USAGE);
553 
554 	if (!(opts & ~(SMB_OPT_WALK | SMB_OPT_VERBOSE)))
555 		opts |= SMB_OPT_ALL_OBJ;
556 
557 	opts |= SMB_OPT_WALK;
558 
559 	new_argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, new_argv);
560 
561 	if (mdb_lookup_by_name("smb_servers", &sym) == -1) {
562 		mdb_warn("failed to find symbol smb_servers");
563 		return (DCMD_ERR);
564 	}
565 
566 	addr = (uintptr_t)sym.st_value + offsetof(smb_llist_t, ll_list);
567 
568 	if (mdb_pwalk_dcmd("list", "smbsrv", new_argc, new_argv, addr))
569 		return (DCMD_ERR);
570 	return (DCMD_OK);
571 }
572 
573 /*
574  * *****************************************************************************
575  * ***************************** smb_server_t **********************************
576  * *****************************************************************************
577  */
578 
579 static const char *smb_server_state[SMB_SERVER_STATE_SENTINEL] =
580 {
581 	"CREATED",
582 	"CONFIGURED",
583 	"RUNNING",
584 	"STOPPING",
585 	"DELETING"
586 };
587 
588 /*
589  * List of objects that can be expanded under a server structure.
590  */
591 static const smb_exp_t smb_server_exp[] =
592 {
593 	{ SMB_OPT_ALL_OBJ,
594 	    offsetof(smb_server_t, sv_nbt_daemon.ld_session_list.ll_list),
595 	    "smbsess", "smb_session"},
596 	{ SMB_OPT_ALL_OBJ,
597 	    offsetof(smb_server_t, sv_tcp_daemon.ld_session_list.ll_list),
598 	    "smbsess", "smb_session"},
599 	{ 0, 0, NULL, NULL }
600 };
601 
602 /*
603  * ::smbsrv
604  *
605  * smbsrv dcmd - Print out smb_server structures.
606  */
607 /*ARGSUSED*/
608 static int
609 smb_dcmd_server(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
610 {
611 	uint_t		opts;
612 	ulong_t		indent = 0;
613 
614 	if (smb_dcmd_getopt(&opts, argc, argv))
615 		return (DCMD_USAGE);
616 
617 	if (!(flags & DCMD_ADDRSPEC))
618 		return (smb_obj_list("smb_server", opts | SMB_OPT_SERVER,
619 		    flags));
620 
621 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SERVER)) ||
622 	    !(opts & SMB_OPT_WALK)) {
623 		smb_server_t	*sv;
624 		const char	*state;
625 
626 		sv = mdb_alloc(sizeof (smb_server_t), UM_SLEEP | UM_GC);
627 		if (mdb_vread(sv, sizeof (smb_server_t), addr) == -1) {
628 			mdb_warn("failed to read smb_server at %p", addr);
629 			return (DCMD_ERR);
630 		}
631 
632 		indent = SMB_DCMD_INDENT;
633 
634 		if (opts & SMB_OPT_VERBOSE) {
635 			mdb_arg_t	argv;
636 
637 			argv.a_type = MDB_TYPE_STRING;
638 			argv.a_un.a_str = "smb_server_t";
639 			if (mdb_call_dcmd("print", addr, flags, 1, &argv))
640 				return (DCMD_ERR);
641 		} else {
642 			if (DCMD_HDRSPEC(flags))
643 				mdb_printf(
644 				    "%<b>%<u>%-?s% "
645 				    "%-4s% "
646 				    "%-32s% "
647 				    "%</u>%</b>\n",
648 				    "SERVER", "ZONE", "STATE");
649 
650 			if (sv->sv_state >= SMB_SERVER_STATE_SENTINEL)
651 				state = "UNKNOWN";
652 			else
653 				state = smb_server_state[sv->sv_state];
654 
655 			mdb_printf("%-?p %-4d %-32s \n",
656 			    addr, sv->sv_zid, state);
657 		}
658 	}
659 	if (smb_obj_expand(addr, opts, smb_server_exp, indent))
660 		return (DCMD_ERR);
661 	return (DCMD_OK);
662 }
663 
664 /*
665  * *****************************************************************************
666  * ***************************** smb_session_t *********************************
667  * *****************************************************************************
668  */
669 
670 static const char *smb_session_state[SMB_SESSION_STATE_SENTINEL] =
671 {
672 	"INITIALIZED",
673 	"DISCONNECTED",
674 	"CONNECTED",
675 	"ESTABLISHED",
676 	"NEGOTIATED",
677 	"OPLOCK_BREAKING",
678 	"TERMINATED"
679 };
680 
681 /*
682  * List of objects that can be expanded under a session structure.
683  */
684 static const smb_exp_t smb_session_exp[] =
685 {
686 	{ SMB_OPT_REQUEST,
687 	    offsetof(smb_session_t, s_req_list.sl_list),
688 	    "smbreq", "smb_request"},
689 	{ SMB_OPT_USER,
690 	    offsetof(smb_session_t, s_user_list.ll_list),
691 	    "smbuser", "smb_user"},
692 	{ SMB_OPT_TREE | SMB_OPT_OFILE | SMB_OPT_ODIR,
693 	    offsetof(smb_session_t, s_tree_list.ll_list),
694 	    "smbtree", "smb_tree"},
695 	{ 0, 0, NULL, NULL}
696 };
697 
698 static void
699 smb_dcmd_session_help(void)
700 {
701 	mdb_printf(
702 	    "Display the contents of smb_session_t, with optional"
703 	    " filtering.\n\n");
704 	(void) mdb_dec_indent(2);
705 	mdb_printf("%<b>OPTIONS%</b>\n");
706 	(void) mdb_inc_indent(2);
707 	mdb_printf(
708 	    "-v\tDisplay verbose smb_session information\n"
709 	    "-r\tDisplay the list of smb requests attached\n"
710 	    "-u\tDisplay the list of users attached\n");
711 }
712 
713 /*
714  * ::smbsess
715  *
716  * smbsess dcmd - Print out the smb_session structure.
717  */
718 static int
719 smb_dcmd_session(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
720 {
721 	uint_t		opts;
722 	ulong_t		indent = 0;
723 
724 	if (smb_dcmd_getopt(&opts, argc, argv))
725 		return (DCMD_USAGE);
726 
727 	if (!(flags & DCMD_ADDRSPEC)) {
728 		opts |= SMB_OPT_SESSION;
729 		opts &= ~SMB_OPT_SERVER;
730 		return (smb_obj_list("smb_session", opts, flags));
731 	}
732 
733 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_SESSION)) ||
734 	    !(opts & SMB_OPT_WALK)) {
735 		smb_session_t	*se;
736 		const char	*state;
737 
738 		indent = SMB_DCMD_INDENT;
739 
740 		se = mdb_alloc(sizeof (*se), UM_SLEEP | UM_GC);
741 		if (mdb_vread(se, sizeof (*se), addr) == -1) {
742 			mdb_warn("failed to read smb_session at %p", addr);
743 			return (DCMD_ERR);
744 		}
745 		if (se->s_state >= SMB_SESSION_STATE_SENTINEL)
746 			state = "INVALID";
747 		else
748 			state = smb_session_state[se->s_state];
749 
750 		if (opts & SMB_OPT_VERBOSE) {
751 			mdb_printf("%<b>%<u>SMB session information "
752 			    "(%p): %</u>%</b>\n", addr);
753 			switch (se->ipaddr.a_family) {
754 			case AF_INET:
755 				mdb_printf("Client IP address: %I\n",
756 				    se->ipaddr.a_ipv4);
757 				mdb_printf("Local IP Address: %I\n",
758 				    se->local_ipaddr.a_ipv4);
759 				break;
760 			case AF_INET6:
761 				mdb_printf("Client IP address: %N\n",
762 				    &(se->ipaddr.a_ipv6));
763 				mdb_printf("Local IP Address: %N\n",
764 				    &(se->local_ipaddr.a_ipv6));
765 				break;
766 			default:
767 				mdb_printf("Client IP address: unknown\n");
768 				mdb_printf("Local IP Address: unknown\n");
769 			}
770 			mdb_printf("Session KID: %u\n", se->s_kid);
771 			mdb_printf("Workstation Name: %s\n",
772 			    se->workstation);
773 			mdb_printf("Session state: %u (%s)\n", se->s_state,
774 			    state);
775 			mdb_printf("Number of Users: %u\n",
776 			    se->s_user_list.ll_count);
777 			mdb_printf("Number of Trees: %u\n", se->s_tree_cnt);
778 			mdb_printf("Number of Files: %u\n", se->s_file_cnt);
779 			mdb_printf("Number of Shares: %u\n", se->s_dir_cnt);
780 			mdb_printf("Number of active Transact.: %u\n\n",
781 			    se->s_xa_list.ll_count);
782 		} else {
783 			char	cipaddr[INET6_ADDRSTRLEN];
784 			char	lipaddr[INET6_ADDRSTRLEN];
785 			int	ipaddrstrlen;
786 
787 			switch (se->ipaddr.a_family) {
788 			case AF_INET:
789 				ipaddrstrlen = INET_ADDRSTRLEN;
790 				(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
791 				    "%I", se->ipaddr.a_ipv4);
792 				(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
793 				    "%I", se->local_ipaddr.a_ipv4);
794 				break;
795 			case AF_INET6:
796 				ipaddrstrlen = INET6_ADDRSTRLEN;
797 				(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
798 				    "%N", &(se->ipaddr.a_ipv6));
799 				(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
800 				    "%N", &(se->local_ipaddr.a_ipv6));
801 				break;
802 			default:
803 				ipaddrstrlen = INET_ADDRSTRLEN;
804 				(void) mdb_snprintf(cipaddr, sizeof (cipaddr),
805 				    "unknown");
806 				(void) mdb_snprintf(lipaddr, sizeof (lipaddr),
807 				    "unknown");
808 			}
809 
810 			if (DCMD_HDRSPEC(flags)) {
811 				mdb_printf(
812 				    "%<b>%<u>%-?s %-*s %-*s %-16s%</u>%</b>\n",
813 				    "SESSION", ipaddrstrlen, "CLIENT_IP_ADDR",
814 				    ipaddrstrlen, "LOCAL_IP_ADDR", "STATE");
815 			}
816 			mdb_printf("%-?p %-*s %-*s %s\n", addr, ipaddrstrlen,
817 			    cipaddr, ipaddrstrlen, lipaddr, state);
818 		}
819 	}
820 	if (smb_obj_expand(addr, opts, smb_session_exp, indent))
821 		return (DCMD_ERR);
822 	return (DCMD_OK);
823 }
824 
825 /*
826  * *****************************************************************************
827  * **************************** smb_request_t **********************************
828  * *****************************************************************************
829  */
830 
831 static const char *smb_request_state[SMB_REQ_STATE_SENTINEL] =
832 {
833 	"FREE",
834 	"INITIALIZING",
835 	"SUBMITTED",
836 	"ACTIVE",
837 	"WAITING_EVENT",
838 	"EVENT_OCCURRED",
839 	"WAITING_LOCK",
840 	"COMPLETED",
841 	"CANCELED",
842 	"CLEANED_UP"
843 };
844 
845 #define	SMB_REQUEST_BANNER	\
846 	"%<b>%<u>%-?s %-?s %-14s %-14s %-16s %-32s%</u>%</b>\n"
847 #define	SMB_REQUEST_FORMAT	\
848 	"%-?p %-?p %-14lld %-14lld %-16s %s\n"
849 
850 static int
851 smb_dcmd_request(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
852 {
853 	uint_t		opts;
854 
855 	if (smb_dcmd_getopt(&opts, argc, argv))
856 		return (DCMD_USAGE);
857 
858 	if (!(flags & DCMD_ADDRSPEC)) {
859 		opts |= SMB_OPT_REQUEST;
860 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_USER);
861 		return (smb_obj_list("smb_request", opts, flags));
862 	}
863 
864 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_REQUEST)) ||
865 	    !(opts & SMB_OPT_WALK)) {
866 		smb_request_t	*sr;
867 		const char	*state;
868 		uint64_t	waiting;
869 		uint64_t	running;
870 
871 		sr = mdb_alloc(sizeof (*sr), UM_SLEEP | UM_GC);
872 		if (mdb_vread(sr, sizeof (*sr), addr) == -1) {
873 			mdb_warn("failed to read smb_request at %p", addr);
874 			return (DCMD_ERR);
875 		}
876 		if (sr->sr_magic != SMB_REQ_MAGIC) {
877 			mdb_warn("not an smb_request_t (%p)>", addr);
878 			return (DCMD_ERR);
879 		}
880 		waiting = 0;
881 		running = 0;
882 		if (sr->sr_time_submitted != 0) {
883 			if (sr->sr_time_active != 0) {
884 				waiting = sr->sr_time_active -
885 				    sr->sr_time_submitted;
886 				running = mdb_gethrtime() -
887 				    sr->sr_time_active;
888 			} else {
889 				waiting = mdb_gethrtime() -
890 				    sr->sr_time_submitted;
891 			}
892 		}
893 		waiting /= NANOSEC;
894 		running /= NANOSEC;
895 
896 		if (sr->sr_state >= SMB_REQ_STATE_SENTINEL)
897 			state = "INVALID";
898 		else
899 			state = smb_request_state[sr->sr_state];
900 
901 		if (opts & SMB_OPT_VERBOSE) {
902 			mdb_printf(
903 			    "%</b>%</u>SMB request information (%p):"
904 			    "%</u>%</b>\n\n", addr);
905 
906 			mdb_printf(
907 			    "first SMB COM: %u (%s)\n"
908 			    "current SMB COM: %u (%s)\n"
909 			    "state: %u (%s)\n"
910 			    "TID(tree): %u (%p)\n"
911 			    "UID(user): %u (%p)\n"
912 			    "FID(file): %u (%p)\n"
913 			    "PID: %u\n"
914 			    "MID: %u\n\n"
915 			    "waiting time: %lld\n"
916 			    "running time: %lld\n",
917 			    sr->first_smb_com,
918 			    smb_com[sr->first_smb_com].smb_com,
919 			    sr->smb_com,
920 			    smb_com[sr->smb_com].smb_com,
921 			    sr->sr_state, state,
922 			    sr->smb_tid, sr->tid_tree,
923 			    sr->smb_uid, sr->uid_user,
924 			    sr->smb_fid, sr->fid_ofile,
925 			    sr->smb_pid,
926 			    sr->smb_mid,
927 			    waiting,
928 			    running);
929 
930 			smb_worker_findstack((uintptr_t)sr->sr_worker);
931 		} else {
932 			if (DCMD_HDRSPEC(flags))
933 				mdb_printf(
934 				    SMB_REQUEST_BANNER,
935 				    "ADDR",
936 				    "WORKER",
937 				    "WAITING(s)",
938 				    "RUNNING(s)",
939 				    "STATE",
940 				    "COMMAND");
941 
942 			mdb_printf(SMB_REQUEST_FORMAT,
943 			    addr,
944 			    sr->sr_worker,
945 			    waiting,
946 			    running,
947 			    state,
948 			    smb_com[sr->smb_com].smb_com);
949 		}
950 	}
951 	return (DCMD_OK);
952 }
953 
954 /*
955  * *****************************************************************************
956  * ****************************** smb_user_t ***********************************
957  * *****************************************************************************
958  */
959 
960 static const char *smb_user_state[SMB_USER_STATE_SENTINEL] =
961 {
962 	"LOGGED_IN",
963 	"LOGGING_OFF",
964 	"LOGGED_OFF"
965 };
966 
967 static void
968 smb_dcmd_user_help(void)
969 {
970 	mdb_printf(
971 	    "Display the contents of smb_user_t, with optional filtering.\n\n");
972 	(void) mdb_dec_indent(2);
973 	mdb_printf("%<b>OPTIONS%</b>\n");
974 	(void) mdb_inc_indent(2);
975 	mdb_printf(
976 	    "-v\tDisplay verbose smb_user information\n");
977 }
978 
979 static int
980 smb_dcmd_user(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
981 {
982 	uint_t		opts;
983 
984 	if (smb_dcmd_getopt(&opts, argc, argv))
985 		return (DCMD_USAGE);
986 
987 	if (!(flags & DCMD_ADDRSPEC)) {
988 		opts |= SMB_OPT_USER;
989 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST);
990 		return (smb_obj_list("smb_user", opts, flags));
991 	}
992 
993 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_USER)) ||
994 	    !(opts & SMB_OPT_WALK)) {
995 		smb_user_t	*user;
996 		char		*account;
997 
998 		user = mdb_alloc(sizeof (*user), UM_SLEEP | UM_GC);
999 		if (mdb_vread(user, sizeof (*user), addr) == -1) {
1000 			mdb_warn("failed to read smb_user at %p", addr);
1001 			return (DCMD_ERR);
1002 		}
1003 		account = mdb_zalloc(user->u_domain_len + user->u_name_len + 2,
1004 		    UM_SLEEP | UM_GC);
1005 
1006 		if (user->u_domain_len)
1007 			(void) mdb_vread(account, user->u_domain_len,
1008 			    (uintptr_t)user->u_domain);
1009 
1010 		strcat(account, "\\");
1011 
1012 		if (user->u_name_len)
1013 			(void) mdb_vread(account + strlen(account),
1014 			    user->u_name_len, (uintptr_t)user->u_name);
1015 
1016 		if (opts & SMB_OPT_VERBOSE) {
1017 			const char	*state;
1018 
1019 			if (user->u_state >= SMB_USER_STATE_SENTINEL)
1020 				state = "INVALID";
1021 			else
1022 				state = smb_user_state[user->u_state];
1023 
1024 			mdb_printf("%<b>%<u>SMB user information (%p):"
1025 			    "%</u>%</b>\n", addr);
1026 			mdb_printf("UID: %u\n", user->u_uid);
1027 			mdb_printf("State: %d (%s)\n", user->u_state, state);
1028 			mdb_printf("Flags: 0x%08x\n", user->u_flags);
1029 			mdb_printf("Privileges: 0x%08x\n", user->u_privileges);
1030 			mdb_printf("Credential: %p\n", user->u_cred);
1031 			mdb_printf("Reference Count: %d\n", user->u_refcnt);
1032 			mdb_printf("User Account: %s\n\n", account);
1033 		} else {
1034 			if (DCMD_HDRSPEC(flags))
1035 				mdb_printf(
1036 				    "%<b>%<u>%?-s "
1037 				    "%-5s "
1038 				    "%-32s%</u>%</b>\n",
1039 				    "USER", "UID", "ACCOUNT");
1040 
1041 			mdb_printf("%-?p %-5u %-32s\n", addr, user->u_uid,
1042 			    account);
1043 		}
1044 	}
1045 	return (DCMD_OK);
1046 }
1047 
1048 /*
1049  * *****************************************************************************
1050  * ****************************** smb_tree_t ***********************************
1051  * *****************************************************************************
1052  */
1053 
1054 static const char *smb_tree_state[SMB_TREE_STATE_SENTINEL] =
1055 {
1056 	"CONNECTED",
1057 	"DISCONNECTING",
1058 	"DISCONNECTED"
1059 };
1060 
1061 /*
1062  * List of objects that can be expanded under a tree structure.
1063  */
1064 static const smb_exp_t smb_tree_exp[] =
1065 {
1066 	{ SMB_OPT_OFILE,
1067 	    offsetof(smb_tree_t, t_ofile_list.ll_list),
1068 	    "smbofile", "smb_ofile"},
1069 	{ SMB_OPT_ODIR,
1070 	    offsetof(smb_tree_t, t_odir_list.ll_list),
1071 	    "smbodir", "smb_odir"},
1072 	{ 0, 0, NULL, NULL}
1073 };
1074 
1075 static void
1076 smb_dcmd_tree_help(void)
1077 {
1078 	mdb_printf(
1079 	    "Display the contents of smb_tree_t, with optional filtering.\n\n");
1080 	(void) mdb_dec_indent(2);
1081 	mdb_printf("%<b>OPTIONS%</b>\n");
1082 	(void) mdb_inc_indent(2);
1083 	mdb_printf(
1084 	    "-v\tDisplay verbose smb_tree information\n"
1085 	    "-d\tDisplay the list of smb_odirs attached\n"
1086 	    "-f\tDisplay the list of smb_ofiles attached\n");
1087 }
1088 
1089 static int
1090 smb_dcmd_tree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1091 {
1092 	uint_t		opts;
1093 	ulong_t		indent = 0;
1094 
1095 	if (smb_dcmd_getopt(&opts, argc, argv))
1096 		return (DCMD_USAGE);
1097 
1098 	if (!(flags & DCMD_ADDRSPEC)) {
1099 		opts |= SMB_OPT_TREE;
1100 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1101 		    SMB_OPT_USER);
1102 		return (smb_obj_list("smb_tree", opts, flags));
1103 	}
1104 
1105 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_TREE)) ||
1106 	    !(opts & SMB_OPT_WALK)) {
1107 		smb_tree_t	*tree;
1108 
1109 		indent = SMB_DCMD_INDENT;
1110 
1111 		tree = mdb_alloc(sizeof (*tree), UM_SLEEP | UM_GC);
1112 		if (mdb_vread(tree, sizeof (*tree), addr) == -1) {
1113 			mdb_warn("failed to read smb_tree at %p", addr);
1114 			return (DCMD_ERR);
1115 		}
1116 		if (opts & SMB_OPT_VERBOSE) {
1117 			const char	*state;
1118 
1119 			if (tree->t_state >= SMB_TREE_STATE_SENTINEL)
1120 				state = "INVALID";
1121 			else
1122 				state = smb_tree_state[tree->t_state];
1123 
1124 			mdb_printf("%<b>%<u>SMB tree information (%p):"
1125 			    "%</u>%</b>\n\n", addr);
1126 			mdb_printf("TID: %04x\n", tree->t_tid);
1127 			mdb_printf("State: %d (%s)\n", tree->t_state, state);
1128 			mdb_printf("Share: %s\n", tree->t_sharename);
1129 			mdb_printf("Resource: %s\n", tree->t_resource);
1130 			mdb_printf("Type: %s\n", tree->t_typename);
1131 			mdb_printf("Volume: %s\n", tree->t_volume);
1132 			mdb_printf("Umask: %04x\n", tree->t_umask);
1133 			mdb_printf("Flags: %08x\n", tree->t_flags);
1134 			mdb_printf("SMB Node: %llx\n", tree->t_snode);
1135 			mdb_printf("Reference Count: %d\n\n", tree->t_refcnt);
1136 		} else {
1137 			if (DCMD_HDRSPEC(flags))
1138 				mdb_printf(
1139 				    "%<b>%<u>%-?s %-5s %-16s %-32s%</u>%</b>\n",
1140 				    "TREE", "TID", "SHARE NAME", "RESOURCE");
1141 
1142 			mdb_printf("%-?p %-5u %-16s %-32s\n", addr,
1143 			    tree->t_tid, tree->t_sharename, tree->t_resource);
1144 		}
1145 	}
1146 	if (smb_obj_expand(addr, opts, smb_tree_exp, indent))
1147 		return (DCMD_ERR);
1148 	return (DCMD_OK);
1149 }
1150 
1151 /*
1152  * *****************************************************************************
1153  * ****************************** smb_odir_t ***********************************
1154  * *****************************************************************************
1155  */
1156 
1157 static const char *smb_odir_state[SMB_ODIR_STATE_SENTINEL] =
1158 {
1159 	"OPEN",
1160 	"IN_USE",
1161 	"CLOSING",
1162 	"CLOSED"
1163 };
1164 
1165 static int
1166 smb_dcmd_odir(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1167 {
1168 	uint_t		opts;
1169 
1170 	if (smb_dcmd_getopt(&opts, argc, argv))
1171 		return (DCMD_USAGE);
1172 
1173 	if (!(flags & DCMD_ADDRSPEC)) {
1174 		opts |= SMB_OPT_ODIR;
1175 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1176 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_OFILE);
1177 		return (smb_obj_list("smb_odir", opts, flags));
1178 	}
1179 
1180 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_ODIR)) ||
1181 	    !(opts & SMB_OPT_WALK)) {
1182 		smb_odir_t	*od;
1183 
1184 		od = mdb_alloc(sizeof (*od), UM_SLEEP | UM_GC);
1185 		if (mdb_vread(od, sizeof (*od), addr) == -1) {
1186 			mdb_warn("failed to read smb_odir at %p", addr);
1187 			return (DCMD_ERR);
1188 		}
1189 		if (opts & SMB_OPT_VERBOSE) {
1190 			const char	*state;
1191 
1192 			if (od->d_state >= SMB_ODIR_STATE_SENTINEL)
1193 				state = "INVALID";
1194 			else
1195 				state = smb_odir_state[od->d_state];
1196 
1197 			mdb_printf(
1198 			    "%<b>%<u>SMB odir information (%p):%</u>%</b>\n\n",
1199 			    addr);
1200 			mdb_printf("State: %d (%s)\n", od->d_state, state);
1201 			mdb_printf("SID: %u\n", od->d_odid);
1202 			mdb_printf("User: %p\n", od->d_user);
1203 			mdb_printf("Tree: %p\n", od->d_tree);
1204 			mdb_printf("Reference Count: %d\n", od->d_refcnt);
1205 			mdb_printf("Pattern: %s\n", od->d_pattern);
1206 			mdb_printf("SMB Node: %p\n\n", od->d_dnode);
1207 		} else {
1208 			if (DCMD_HDRSPEC(flags))
1209 				mdb_printf(
1210 				    "%<b>%<u>%-?s "
1211 				    "%-5s "
1212 				    "%-?s "
1213 				    "%-16s%</u>%</b>\n",
1214 				    "ODIR", "SID", "VNODE", "PATTERN");
1215 
1216 			mdb_printf("%?p %-5u %-16p %s\n",
1217 			    addr, od->d_odid, od->d_dnode, od->d_pattern);
1218 		}
1219 	}
1220 	return (DCMD_OK);
1221 }
1222 
1223 /*
1224  * *****************************************************************************
1225  * ****************************** smb_ofile_t **********************************
1226  * *****************************************************************************
1227  */
1228 
1229 static const char *smb_ofile_state[SMB_OFILE_STATE_SENTINEL] =
1230 {
1231 	"OPEN",
1232 	"CLOSING",
1233 	"CLOSED"
1234 };
1235 
1236 static int
1237 smb_dcmd_ofile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1238 {
1239 	uint_t		opts;
1240 
1241 	if (smb_dcmd_getopt(&opts, argc, argv))
1242 		return (DCMD_USAGE);
1243 
1244 	if (!(flags & DCMD_ADDRSPEC)) {
1245 		opts |= SMB_OPT_OFILE;
1246 		opts &= ~(SMB_OPT_SERVER | SMB_OPT_SESSION | SMB_OPT_REQUEST |
1247 		    SMB_OPT_USER | SMB_OPT_TREE | SMB_OPT_ODIR);
1248 		return (smb_obj_list("smb_ofile", opts, flags));
1249 	}
1250 
1251 	if (((opts & SMB_OPT_WALK) && (opts & SMB_OPT_OFILE)) ||
1252 	    !(opts & SMB_OPT_WALK)) {
1253 		smb_ofile_t	*of;
1254 
1255 		of = mdb_alloc(sizeof (*of), UM_SLEEP | UM_GC);
1256 		if (mdb_vread(of, sizeof (*of), addr) == -1) {
1257 			mdb_warn("failed to read smb_ofile at %p", addr);
1258 			return (DCMD_ERR);
1259 		}
1260 		if (opts & SMB_OPT_VERBOSE) {
1261 			const char	*state;
1262 
1263 			if (of->f_state >= SMB_OFILE_STATE_SENTINEL)
1264 				state = "INVALID";
1265 			else
1266 				state = smb_ofile_state[of->f_state];
1267 
1268 			mdb_printf(
1269 			    "%<b>%<u>SMB ofile information (%p):%</u>%</b>\n\n",
1270 			    addr);
1271 			mdb_printf("FID: %u\n", of->f_fid);
1272 			mdb_printf("State: %d (%s)\n", of->f_state, state);
1273 			mdb_printf("SMB Node: %p\n", of->f_node);
1274 			mdb_printf("LLF Offset: 0x%llx (%s)\n",
1275 			    of->f_llf_pos,
1276 			    ((of->f_flags & SMB_OFLAGS_LLF_POS_VALID) ?
1277 			    "Valid" : "Invalid"));
1278 			mdb_printf("Flags: 0x%08x\n", of->f_flags);
1279 			mdb_printf("User: %p\n", of->f_user);
1280 			mdb_printf("Tree: %p\n", of->f_tree);
1281 			mdb_printf("Credential: %p\n\n", of->f_cr);
1282 		} else {
1283 			if (DCMD_HDRSPEC(flags))
1284 				mdb_printf(
1285 				    "%<b>%<u>%-?s "
1286 				    "%-5s "
1287 				    "%-?s "
1288 				    "%-?s%</u>%</b>\n",
1289 				    "OFILE", "FID", "SMB NODE", "CRED");
1290 
1291 			mdb_printf("%?p %-5u %-p %p\n", addr,
1292 			    of->f_fid, of->f_node, of->f_cr);
1293 		}
1294 	}
1295 	return (DCMD_OK);
1296 }
1297 
1298 /*
1299  * *****************************************************************************
1300  * ******************************** smb_kshare_t *******************************
1301  * *****************************************************************************
1302  */
1303 
1304 static int
1305 smb_kshare_cb(uintptr_t addr, const void *data, void *arg)
1306 {
1307 	uint_t *opts = arg;
1308 	uintptr_t ta, sa;
1309 	char name[32];
1310 	char path[64];
1311 	_NOTE(ARGUNUSED(data));
1312 
1313 	if (*opts & SMB_OPT_VERBOSE) {
1314 		mdb_arg_t	argv;
1315 
1316 		argv.a_type = MDB_TYPE_STRING;
1317 		argv.a_un.a_str = "smb_kshare_t";
1318 		/* Don't fail the walk if this fails. */
1319 		mdb_call_dcmd("print", addr, 0, 1, &argv);
1320 	} else {
1321 		/*
1322 		 * Summary line for a kshare
1323 		 * Don't fail the walk if any of these fail.
1324 		 */
1325 		ta = addr + OFFSETOF(smb_kshare_t, shr_name);
1326 		if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
1327 		    mdb_readstr(name, sizeof (name), sa) <= 0)
1328 			strcpy(name, "?");
1329 
1330 		ta = addr + OFFSETOF(smb_kshare_t, shr_path);
1331 		if (mdb_vread(&sa, sizeof (sa), ta) < 0 ||
1332 		    mdb_readstr(path, sizeof (path), sa) <= 0)
1333 			strcpy(path, "?");
1334 
1335 		mdb_printf("%-?p ", addr);	/* smb_kshare_t */
1336 		mdb_printf("%-16s ", name);
1337 		mdb_printf("%-s", path);
1338 		mdb_printf("\n");
1339 	}
1340 
1341 	return (WALK_NEXT);
1342 }
1343 
1344 /*
1345  * ::smbshares
1346  *
1347  * dcmd - Print out smb_kshare structures.
1348  *	requires addr of an smb_server_t
1349  */
1350 /*ARGSUSED*/
1351 static int
1352 smb_dcmd_kshare(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1353 {
1354 	uint_t		opts = 0;
1355 
1356 	if (mdb_getopts(argc, argv,
1357 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, &opts,
1358 	    NULL) != argc)
1359 		return (DCMD_USAGE);
1360 
1361 	if (!(flags & DCMD_ADDRSPEC))
1362 		return (DCMD_USAGE);
1363 	addr += OFFSETOF(smb_server_t, sv_export.e_share_avl.avl_tree);
1364 
1365 	if (DCMD_HDRSPEC(flags)) {
1366 		mdb_printf(
1367 		    "%<b>%<u>"
1368 		    "%-?s "
1369 		    "%-16s "
1370 		    "%-s"
1371 		    "%</u>%</b>\n",
1372 		    "smb_kshare_t", "name", "path");
1373 	}
1374 
1375 	if (mdb_pwalk("genunix`avl", smb_kshare_cb, &opts, addr) == -1) {
1376 		mdb_warn("cannot walk smb_kshare avl");
1377 		return (DCMD_ERR);
1378 	}
1379 
1380 	return (DCMD_OK);
1381 }
1382 
1383 /*
1384  * *****************************************************************************
1385  * ******************************** smb_vfs_t **********************************
1386  * *****************************************************************************
1387  */
1388 
1389 /*
1390  * ::smbvfs
1391  *
1392  * smbvfs dcmd - Prints out smb_vfs structures.
1393  */
1394 /*ARGSUSED*/
1395 static int
1396 smb_dcmd_vfs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1397 {
1398 	int		verbose = FALSE;
1399 	smb_vfs_t	*sf;
1400 	vnode_t		*vn;
1401 	char		*path;
1402 
1403 	if (mdb_getopts(argc, argv,
1404 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1405 	    NULL) != argc)
1406 		return (DCMD_USAGE);
1407 
1408 	/*
1409 	 * If no smb_vfs address was specified on the command line, we can
1410 	 * print out all smb_vfs by invoking the smb_vfs walker, using
1411 	 * this dcmd itself as the callback.
1412 	 */
1413 	if (!(flags & DCMD_ADDRSPEC)) {
1414 		if (mdb_walk_dcmd("smbvfs_walker", "smbvfs",
1415 		    argc, argv) == -1) {
1416 			mdb_warn("failed to walk 'smb_vfs'");
1417 			return (DCMD_ERR);
1418 		}
1419 		return (DCMD_OK);
1420 	}
1421 
1422 	if (DCMD_HDRSPEC(flags)) {
1423 		mdb_printf(
1424 		    "%<b>%<u>"
1425 		    "%-?s "
1426 		    "%-10s "
1427 		    "%-16s "
1428 		    "%-16s"
1429 		    "%-s"
1430 		    "%</u>%</b>\n",
1431 		    "SMB_VFS", "REFCNT", "VFS", "VNODE", "ROOT");
1432 	}
1433 
1434 	sf = mdb_alloc(sizeof (*sf), UM_SLEEP | UM_GC);
1435 	if (mdb_vread(sf, sizeof (*sf), addr) == -1) {
1436 		mdb_warn("failed to read smb_vfs at %p", addr);
1437 		return (DCMD_ERR);
1438 	}
1439 
1440 	vn = mdb_alloc(sizeof (*vn), UM_SLEEP | UM_GC);
1441 	if (mdb_vread(vn, sizeof (*vn),
1442 	    (uintptr_t)sf->sv_rootvp) == -1) {
1443 		mdb_warn("failed to read vnode at %p", sf->sv_rootvp);
1444 		return (DCMD_ERR);
1445 	}
1446 
1447 	path = mdb_zalloc(MAXPATHLEN, UM_SLEEP | UM_GC);
1448 	(void) mdb_vread(path, MAXPATHLEN, (uintptr_t)vn->v_path);
1449 
1450 	mdb_printf(
1451 	    "%-?p %-10d %-?p %-?p %-s\n", addr, sf->sv_refcnt,
1452 	    sf->sv_vfsp, sf->sv_rootvp, path);
1453 
1454 	return (DCMD_OK);
1455 }
1456 
1457 /*
1458  * Initialize the smb_vfs_t walker to point to the smb_export
1459  * in the specified smb_server_t instance.  (no global walks)
1460  */
1461 static int
1462 smb_vfs_walk_init(mdb_walk_state_t *wsp)
1463 {
1464 
1465 	if (wsp->walk_addr == NULL) {
1466 		mdb_printf("require address of an smb_server_t\n");
1467 		return (WALK_ERR);
1468 	}
1469 
1470 	wsp->walk_addr +=
1471 	    OFFSETOF(smb_server_t, sv_export.e_vfs_list.ll_list);
1472 
1473 	if (mdb_layered_walk("list", wsp) == -1) {
1474 		mdb_warn("failed to walk list of VFS");
1475 		return (WALK_ERR);
1476 	}
1477 
1478 	return (WALK_NEXT);
1479 }
1480 
1481 static int
1482 smb_vfs_walk_step(mdb_walk_state_t *wsp)
1483 {
1484 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1485 	    wsp->walk_cbdata));
1486 }
1487 
1488 /*
1489  * *****************************************************************************
1490  * ******************************* smb_node_t **********************************
1491  * *****************************************************************************
1492  */
1493 
1494 static void
1495 smb_node_help(void)
1496 {
1497 	mdb_printf(
1498 	    "Display the contents of smb_node_t, with optional filtering.\n\n");
1499 	(void) mdb_dec_indent(2);
1500 	mdb_printf("%<b>OPTIONS%</b>\n");
1501 	(void) mdb_inc_indent(2);
1502 	mdb_printf(
1503 	    "-v\tDisplay verbose smb_node information\n"
1504 	    "-p\tDisplay the full path of the vnode associated\n"
1505 	    "-s\tDisplay the stack of the last 16 calls that modified the "
1506 	    "reference\n\tcount\n");
1507 }
1508 
1509 /*
1510  * ::smbnode
1511  *
1512  * smb_node dcmd - Print out smb_node structure.
1513  */
1514 static int
1515 smb_dcmd_node(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1516 {
1517 	smb_node_t	node;
1518 	int		rc;
1519 	int		verbose = FALSE;
1520 	int		print_full_path = FALSE;
1521 	int		stack_trace = FALSE;
1522 	vnode_t		vnode;
1523 	char		od_name[MAXNAMELEN];
1524 	char		path_name[1024];
1525 	uintptr_t	list_addr, oplock_addr;
1526 
1527 	if (mdb_getopts(argc, argv,
1528 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1529 	    'p', MDB_OPT_SETBITS, TRUE, &print_full_path,
1530 	    's', MDB_OPT_SETBITS, TRUE, &stack_trace,
1531 	    NULL) != argc)
1532 		return (DCMD_USAGE);
1533 
1534 	/*
1535 	 * If no smb_node address was specified on the command line, we can
1536 	 * print out all smb nodes by invoking the smb_node walker, using
1537 	 * this dcmd itself as the callback.
1538 	 */
1539 	if (!(flags & DCMD_ADDRSPEC)) {
1540 		if (mdb_walk_dcmd("smbnode_walker", "smbnode",
1541 		    argc, argv) == -1) {
1542 			mdb_warn("failed to walk 'smb_node'");
1543 			return (DCMD_ERR);
1544 		}
1545 		return (DCMD_OK);
1546 	}
1547 
1548 	/*
1549 	 * If this is the first invocation of the command, print a nice
1550 	 * header line for the output that will follow.
1551 	 */
1552 	if (DCMD_HDRSPEC(flags)) {
1553 		if (verbose) {
1554 			mdb_printf("%<b>%<u>SMB node information:%</u>%</b>\n");
1555 		} else {
1556 			mdb_printf(
1557 			    "%<b>%<u>%-?s "
1558 			    "%-?s "
1559 			    "%-18s "
1560 			    "%-6s "
1561 			    "%-6s "
1562 			    "%-8s "
1563 			    "%-6s%</u>%</b>\n",
1564 			    "ADDR", "VP", "NODE-NAME", "OFILES", "LOCKS",
1565 			    "OPLOCK", "REF");
1566 		}
1567 	}
1568 
1569 	/*
1570 	 * For each smb_node, we just need to read the smb_node_t struct, read
1571 	 * and then print out the following fields.
1572 	 */
1573 	if (mdb_vread(&node, sizeof (node), addr) == sizeof (node)) {
1574 		(void) mdb_snprintf(od_name, sizeof (od_name), "%s",
1575 		    node.od_name);
1576 		if (print_full_path) {
1577 			if (mdb_vread(&vnode, sizeof (vnode_t),
1578 			    (uintptr_t)node.vp) == sizeof (vnode_t)) {
1579 				if (mdb_readstr(path_name, sizeof (path_name),
1580 				    (uintptr_t)vnode.v_path) != 0) {
1581 					(void) mdb_snprintf(od_name,
1582 					    sizeof (od_name), "N/A");
1583 				}
1584 			}
1585 		}
1586 		if (verbose) {
1587 			mdb_printf("VP: %p\n", node.vp);
1588 			mdb_printf("Name: %s\n", od_name);
1589 			if (print_full_path)
1590 				mdb_printf("V-node Path: %s\n", path_name);
1591 			mdb_printf("Ofiles: %u\n", node.n_ofile_list.ll_count);
1592 			mdb_printf("Range Locks: %u\n",
1593 			    node.n_lock_list.ll_count);
1594 			if (node.n_lock_list.ll_count != 0) {
1595 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1596 				list_addr = addr +
1597 				    offsetof(smb_node_t, n_lock_list) +
1598 				    offsetof(smb_llist_t, ll_list);
1599 				if (mdb_pwalk_dcmd("list", "smblock", 0,
1600 				    NULL, list_addr)) {
1601 					mdb_warn("failed to walk node's active"
1602 					    " locks");
1603 				}
1604 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1605 			}
1606 			if (node.n_oplock.ol_count == 0) {
1607 				mdb_printf("Opportunistic Locks: 0\n");
1608 			} else {
1609 				oplock_addr =
1610 				    addr + offsetof(smb_node_t, n_oplock);
1611 				mdb_printf("Opportunistic Lock: %p\n",
1612 				    oplock_addr);
1613 				rc = mdb_call_dcmd("smboplock", oplock_addr,
1614 				    flags, argc, argv);
1615 				if (rc != DCMD_OK)
1616 					return (rc);
1617 			}
1618 			mdb_printf("Reference Count: %u\n\n", node.n_refcnt);
1619 		} else {
1620 			mdb_printf("%-?p %-?p %-18s %-6d %-6d %-8d %-6d ",
1621 			    addr, node.vp, od_name, node.n_ofile_list.ll_count,
1622 			    node.n_lock_list.ll_count,
1623 			    node.n_oplock.ol_count, node.n_refcnt);
1624 
1625 			if (print_full_path)
1626 				mdb_printf("\t%s\n", path_name);
1627 		}
1628 		if (stack_trace && node.n_audit_buf) {
1629 			int ctr;
1630 			smb_audit_buf_node_t *anb;
1631 
1632 			anb = mdb_alloc(sizeof (smb_audit_buf_node_t),
1633 			    UM_SLEEP | UM_GC);
1634 
1635 			if (mdb_vread(anb, sizeof (*anb),
1636 			    (uintptr_t)node.n_audit_buf) != sizeof (*anb)) {
1637 				mdb_warn("failed to read audit buffer");
1638 				return (DCMD_ERR);
1639 			}
1640 			ctr = anb->anb_max_index + 1;
1641 			anb->anb_index--;
1642 			anb->anb_index &= anb->anb_max_index;
1643 
1644 			while (ctr) {
1645 				smb_audit_record_node_t	*anr;
1646 
1647 				anr = anb->anb_records + anb->anb_index;
1648 
1649 				if (anr->anr_depth) {
1650 					char c[MDB_SYM_NAMLEN];
1651 					GElf_Sym sym;
1652 					int i;
1653 
1654 					mdb_printf("\nRefCnt: %u\t",
1655 					    anr->anr_refcnt);
1656 
1657 					for (i = 0;
1658 					    i < anr->anr_depth;
1659 					    i++) {
1660 						if (mdb_lookup_by_addr(
1661 						    anr->anr_stack[i],
1662 						    MDB_SYM_FUZZY,
1663 						    c, sizeof (c),
1664 						    &sym) == -1) {
1665 							continue;
1666 						}
1667 						mdb_printf("%s+0x%1x",
1668 						    c,
1669 						    anr->anr_stack[i] -
1670 						    (uintptr_t)sym.st_value);
1671 						++i;
1672 						break;
1673 					}
1674 
1675 					while (i < anr->anr_depth) {
1676 						if (mdb_lookup_by_addr(
1677 						    anr->anr_stack[i],
1678 						    MDB_SYM_FUZZY,
1679 						    c, sizeof (c),
1680 						    &sym) == -1) {
1681 							++i;
1682 							continue;
1683 						}
1684 						mdb_printf("\n\t\t%s+0x%1x",
1685 						    c,
1686 						    anr->anr_stack[i] -
1687 						    (uintptr_t)sym.st_value);
1688 						++i;
1689 					}
1690 					mdb_printf("\n");
1691 				}
1692 				anb->anb_index--;
1693 				anb->anb_index &= anb->anb_max_index;
1694 				ctr--;
1695 			}
1696 		}
1697 	} else {
1698 		mdb_warn("failed to read struct smb_node at %p", addr);
1699 		return (DCMD_ERR);
1700 	}
1701 
1702 	return (DCMD_OK);
1703 }
1704 
1705 /*
1706  * Initialize the smb_node_t walker by reading the value of smb_node_hash_table
1707  * in the kernel's symbol table. Only global walk supported.
1708  */
1709 static int
1710 smb_node_walk_init(mdb_walk_state_t *wsp)
1711 {
1712 	GElf_Sym	sym;
1713 	int		i;
1714 	uintptr_t	node_hash_table_addr;
1715 
1716 	if (wsp->walk_addr == NULL) {
1717 		if (mdb_lookup_by_name("smb_node_hash_table", &sym) == -1) {
1718 			mdb_warn("failed to find 'smb_node_hash_table'");
1719 			return (WALK_ERR);
1720 		}
1721 		node_hash_table_addr = (uintptr_t)sym.st_value;
1722 	} else {
1723 		mdb_printf("smb_node walk only supports global walks\n");
1724 		return (WALK_ERR);
1725 	}
1726 
1727 	for (i = 0; i < SMBND_HASH_MASK + 1; i++) {
1728 		wsp->walk_addr = node_hash_table_addr +
1729 		    (i * sizeof (smb_llist_t)) + offsetof(smb_llist_t, ll_list);
1730 		if (mdb_layered_walk("list", wsp) == -1) {
1731 			mdb_warn("failed to walk 'list'");
1732 			return (WALK_ERR);
1733 		}
1734 	}
1735 
1736 	return (WALK_NEXT);
1737 }
1738 
1739 static int
1740 smb_node_walk_step(mdb_walk_state_t *wsp)
1741 {
1742 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
1743 	    wsp->walk_cbdata));
1744 }
1745 
1746 /*
1747  * *****************************************************************************
1748  * ****************************** smb_lock_t ***********************************
1749  * *****************************************************************************
1750  */
1751 
1752 static int
1753 smb_lock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1754 {
1755 	smb_lock_t	lock;
1756 	int		verbose = FALSE;
1757 	uintptr_t	list_addr;
1758 	char		*lock_type;
1759 
1760 	if (mdb_getopts(argc, argv,
1761 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
1762 	    NULL) != argc)
1763 		return (DCMD_USAGE);
1764 
1765 	/*
1766 	 * An smb_lock_t address must be specified.
1767 	 */
1768 	if (!(flags & DCMD_ADDRSPEC))
1769 		return (DCMD_USAGE);
1770 
1771 	/*
1772 	 * If this is the first invocation of the command, print a nice
1773 	 * header line for the output that will follow.
1774 	 */
1775 	if (DCMD_HDRSPEC(flags)) {
1776 		if (verbose)
1777 			mdb_printf("SMB lock information:\n\n");
1778 		else
1779 			mdb_printf("%<u>%-?s %4s %16s %8s %9s%</u>\n",
1780 			    "Locks: ", "TYPE", "START", "LENGTH",
1781 			    "CONFLICTS");
1782 	}
1783 
1784 	if (mdb_vread(&lock, sizeof (lock), addr) == sizeof (lock)) {
1785 		switch (lock.l_type) {
1786 		case SMB_LOCK_TYPE_READWRITE:
1787 			lock_type = "RW";
1788 			break;
1789 		case SMB_LOCK_TYPE_READONLY:
1790 			lock_type = "RO";
1791 			break;
1792 		default:
1793 			lock_type = "N/A";
1794 			break;
1795 		}
1796 		if (verbose) {
1797 			mdb_printf("Type             :\t%s (%u)\n",
1798 			    lock_type, lock.l_type);
1799 			mdb_printf("Start            :\t%llx\n",
1800 			    lock.l_start);
1801 			mdb_printf("Length           :\t%lx\n",
1802 			    lock.l_length);
1803 			mdb_printf("Session          :\t%p\n",
1804 			    lock.l_session);
1805 			mdb_printf("File             :\t%p\n",
1806 			    lock.l_file);
1807 			mdb_printf("User ID          :\t%u\n",
1808 			    lock.l_uid);
1809 			mdb_printf("Process ID       :\t%u\n",
1810 			    lock.l_pid);
1811 			mdb_printf("Conflicts        :\t%u\n",
1812 			    lock.l_conflict_list.sl_count);
1813 			if (lock.l_conflict_list.sl_count != 0) {
1814 				(void) mdb_inc_indent(SMB_DCMD_INDENT);
1815 				list_addr = addr +
1816 				    offsetof(smb_lock_t, l_conflict_list) +
1817 				    offsetof(smb_slist_t, sl_list);
1818 				if (mdb_pwalk_dcmd("list", "smb_lock",
1819 				    0, NULL, list_addr)) {
1820 					mdb_warn("failed to walk conflict "
1821 					    "locks ");
1822 				}
1823 				(void) mdb_dec_indent(SMB_DCMD_INDENT);
1824 			}
1825 			mdb_printf("Blocked by       :\t%p\n",
1826 			    lock.l_blocked_by);
1827 			mdb_printf("Flags            :\t0x%x\n",
1828 			    lock.l_flags);
1829 			mdb_printf("\n");
1830 		} else {
1831 			mdb_printf("%?p %4s %16llx %08lx %9x", addr,
1832 			    lock_type, lock.l_start, lock.l_length,
1833 			    lock.l_conflict_list.sl_count);
1834 		}
1835 	} else {
1836 		mdb_warn("failed to read struct smb_request at %p", addr);
1837 		return (DCMD_ERR);
1838 	}
1839 
1840 	return (DCMD_OK);
1841 }
1842 
1843 /*
1844  * *****************************************************************************
1845  * ************************** smb_oplock_grant_t *******************************
1846  * *****************************************************************************
1847  */
1848 /*ARGSUSED*/
1849 static int
1850 smb_oplock_grant(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1851 {
1852 	smb_oplock_grant_t	grant;
1853 	char			 *level;
1854 
1855 	if (!(flags & DCMD_ADDRSPEC))
1856 		return (DCMD_USAGE);
1857 
1858 	/*
1859 	 * If this is the first invocation of the command, print a nice
1860 	 * header line for the output that will follow.
1861 	 */
1862 	if (DCMD_HDRSPEC(flags)) {
1863 		mdb_printf("%<u>%-16s %-10s %-16s%</u>\n",
1864 		    "Grants:", "LEVEL", "OFILE");
1865 	}
1866 
1867 	if (mdb_vread(&grant, sizeof (grant), addr) == sizeof (grant)) {
1868 		switch (grant.og_level) {
1869 		case SMB_OPLOCK_EXCLUSIVE:
1870 			level = "EXCLUSIVE";
1871 			break;
1872 		case SMB_OPLOCK_BATCH:
1873 			level = "BATCH";
1874 			break;
1875 		case SMB_OPLOCK_LEVEL_II:
1876 			level = "LEVEL_II";
1877 			break;
1878 		default:
1879 			level = "UNKNOWN";
1880 			break;
1881 		}
1882 
1883 		mdb_printf("%-16p %-10s %-16p", addr, level, grant.og_ofile);
1884 	}
1885 	return (DCMD_OK);
1886 }
1887 
1888 /*
1889  * *****************************************************************************
1890  * ***************************** smb_oplock_t **********************************
1891  * *****************************************************************************
1892  */
1893 /*ARGSUSED*/
1894 static int
1895 smb_oplock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1896 {
1897 	smb_oplock_t	oplock;
1898 	uintptr_t	list_addr;
1899 
1900 	if (!(flags & DCMD_ADDRSPEC))
1901 		return (DCMD_USAGE);
1902 
1903 	if (mdb_vread(&oplock, sizeof (oplock), addr) != sizeof (oplock)) {
1904 		mdb_warn("failed to read struct smb_oplock at %p", addr);
1905 		return (DCMD_ERR);
1906 	}
1907 
1908 	if (oplock.ol_count == 0)
1909 		return (DCMD_OK);
1910 
1911 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
1912 	switch (oplock.ol_break) {
1913 	case SMB_OPLOCK_BREAK_TO_NONE:
1914 		mdb_printf("Break Pending: BREAK_TO_NONE\n");
1915 		break;
1916 	case SMB_OPLOCK_BREAK_TO_LEVEL_II:
1917 		mdb_printf(
1918 		    "Break Pending: BREAK_TO_LEVEL_II\n");
1919 		break;
1920 	default:
1921 		break;
1922 	}
1923 
1924 	list_addr = addr + offsetof(smb_oplock_t, ol_grants);
1925 
1926 	if (mdb_pwalk_dcmd("list", "smboplockgrant",
1927 	    argc, argv, list_addr)) {
1928 		mdb_warn("failed to walk oplock grants");
1929 	}
1930 
1931 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
1932 
1933 	return (DCMD_OK);
1934 }
1935 
1936 /*
1937  * ::smbstat
1938  *
1939  * Prints SMB requests statistics.
1940  */
1941 /*ARGSUSED*/
1942 static int
1943 smb_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1944 {
1945 	smb_server_t	*sv;
1946 
1947 	if (!(flags & DCMD_ADDRSPEC))
1948 		return (DCMD_USAGE);
1949 
1950 	sv = mdb_alloc(sizeof (*sv), UM_SLEEP | UM_GC);
1951 	if (mdb_vread(sv, sizeof (*sv), addr) == -1) {
1952 		mdb_warn("failed to read server object at %p", addr);
1953 		return (DCMD_ERR);
1954 	}
1955 	if (sv->sv_magic != SMB_SERVER_MAGIC) {
1956 		mdb_warn("not an smb_server_t (%p)>", addr);
1957 		return (DCMD_ERR);
1958 	}
1959 	mdb_printf(
1960 	    "\n%<b>  nbt   tcp users trees files pipes%</b>\n"
1961 	    "%5d %5d %5d %5d %5d %5d\n",
1962 	    sv->sv_nbt_sess,
1963 	    sv->sv_tcp_sess,
1964 	    sv->sv_users,
1965 	    sv->sv_trees,
1966 	    sv->sv_files,
1967 	    sv->sv_pipes);
1968 
1969 	return (DCMD_OK);
1970 }
1971 
1972 /*
1973  * *****************************************************************************
1974  * ******************************** smb_ace_t **********************************
1975  * *****************************************************************************
1976  */
1977 static const ace_type_entry_t	ace_types[ACE_TYPE_TABLEN] =
1978 {
1979 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_ACE_TYPE),
1980 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_ACE_TYPE),
1981 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_ACE_TYPE),
1982 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_ACE_TYPE),
1983 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE),
1984 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE),
1985 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_OBJECT_ACE_TYPE),
1986 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE),
1987 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE),
1988 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE),
1989 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE),
1990 	ACE_TYPE_ENTRY(ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE),
1991 	ACE_TYPE_ENTRY(ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE),
1992 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE),
1993 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE),
1994 	ACE_TYPE_ENTRY(ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE),
1995 	ACE_TYPE_ENTRY(ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE),
1996 	ACE_TYPE_ENTRY(0x11),
1997 	ACE_TYPE_ENTRY(0x12),
1998 	ACE_TYPE_ENTRY(0x13),
1999 	ACE_TYPE_ENTRY(0x14),
2000 	ACE_TYPE_ENTRY(0x15),
2001 	ACE_TYPE_ENTRY(0x16),
2002 	ACE_TYPE_ENTRY(0x17),
2003 	ACE_TYPE_ENTRY(0x18),
2004 	ACE_TYPE_ENTRY(0x19),
2005 	ACE_TYPE_ENTRY(0x1A),
2006 	ACE_TYPE_ENTRY(0x1B),
2007 	ACE_TYPE_ENTRY(0x1C),
2008 	ACE_TYPE_ENTRY(0x1D),
2009 	ACE_TYPE_ENTRY(0x1E),
2010 	ACE_TYPE_ENTRY(0x1F)
2011 };
2012 
2013 static const mdb_bitmask_t ace_flag_bits[] = {
2014 	{ "OBJECT_INHERIT_ACE", OBJECT_INHERIT_ACE, OBJECT_INHERIT_ACE },
2015 	{ "CONTAINER_INHERIT_ACE", CONTAINER_INHERIT_ACE,
2016 	    CONTAINER_INHERIT_ACE },
2017 	{ "NO_PROPOGATE_INHERIT_ACE", NO_PROPOGATE_INHERIT_ACE,
2018 	    NO_PROPOGATE_INHERIT_ACE },
2019 	{ "INHERIT_ONLY_ACE", INHERIT_ONLY_ACE, INHERIT_ONLY_ACE },
2020 	{ "INHERITED_ACE", INHERITED_ACE, INHERITED_ACE },
2021 	{ "SUCCESSFUL_ACCESS_ACE_FLAG", SUCCESSFUL_ACCESS_ACE_FLAG,
2022 	    SUCCESSFUL_ACCESS_ACE_FLAG },
2023 	{ "FAILED_ACCESS_ACE_FLAG", FAILED_ACCESS_ACE_FLAG,
2024 	    FAILED_ACCESS_ACE_FLAG },
2025 	{ NULL, 0, 0 }
2026 };
2027 
2028 /*
2029  * ::smbace
2030  */
2031 static int
2032 smb_ace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2033 {
2034 	smb_ace_t	ace;
2035 	int		verbose = FALSE;
2036 	const char	*ptr;
2037 	int		rc;
2038 
2039 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2040 	    NULL) != argc)
2041 		return (DCMD_USAGE);
2042 
2043 	/*
2044 	 * An smb_ace address is required.
2045 	 */
2046 	if (!(flags & DCMD_ADDRSPEC))
2047 		return (DCMD_USAGE);
2048 
2049 	if (mdb_vread(&ace, sizeof (ace), addr) != sizeof (ace)) {
2050 		mdb_warn("failed to read struct smb_ace at %p", addr);
2051 		return (DCMD_ERR);
2052 	}
2053 
2054 	if (verbose) {
2055 		if (ace.se_hdr.se_type < ACE_TYPE_TABLEN)
2056 			ptr = ace_types[ace.se_hdr.se_type].ace_type_sting;
2057 		else
2058 			ptr = "Unknown";
2059 
2060 		mdb_printf("ACE Type: 0x%02x (%s)\n", ace.se_hdr.se_type, ptr);
2061 		mdb_printf("ACE Flags: %b\n", (int)ace.se_hdr.se_flags,
2062 		    ace_flag_bits);
2063 		mdb_printf("ACE Wire Size: 0x%04x\n", ace.se_hdr.se_bsize);
2064 		mdb_printf("ACE Mask: 0x%08x\n", ace.se_mask);
2065 		mdb_printf("ACE SID: ");
2066 	} else {
2067 		if (DCMD_HDRSPEC(flags))
2068 			mdb_printf(
2069 			    "%<b>%<u>%?-s %-4s %-4s %-8s %s%</u>%</b>\n",
2070 			    "ACE", "TYPE", "FLAGS", "MASK", "SID");
2071 		mdb_printf("%?p 0x%02x 0x%02x 0x%08x ", addr,
2072 		    ace.se_hdr.se_type, ace.se_hdr.se_flags, ace.se_mask);
2073 	}
2074 	rc = smb_sid_print((uintptr_t)ace.se_sid);
2075 	mdb_printf("\n");
2076 	return (rc);
2077 }
2078 
2079 static int
2080 smb_ace_walk_init(mdb_walk_state_t *wsp)
2081 {
2082 	if (wsp->walk_addr == 0) {
2083 		mdb_printf("smb_ace walk only supports local walks\n");
2084 		return (WALK_ERR);
2085 	}
2086 
2087 	wsp->walk_addr += offsetof(smb_acl_t, sl_sorted);
2088 
2089 	if (mdb_layered_walk("list", wsp) == -1) {
2090 		mdb_warn("failed to walk list of ACEs");
2091 		return (WALK_ERR);
2092 	}
2093 
2094 	return (WALK_NEXT);
2095 }
2096 
2097 static int
2098 smb_ace_walk_step(mdb_walk_state_t *wsp)
2099 {
2100 	return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
2101 	    wsp->walk_cbdata));
2102 }
2103 
2104 /*
2105  * *****************************************************************************
2106  * ******************************** smb_acl_t **********************************
2107  * *****************************************************************************
2108  */
2109 
2110 /*
2111  * ::smbacl
2112  */
2113 static int
2114 smb_acl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2115 {
2116 	smb_acl_t	acl;
2117 
2118 	/* An smb_acl address is required. */
2119 	if (!(flags & DCMD_ADDRSPEC))
2120 		return (DCMD_USAGE);
2121 
2122 	if (mdb_vread(&acl, sizeof (acl), addr) != sizeof (acl)) {
2123 		mdb_warn("failed to read struct smb_acl at %p", addr);
2124 		return (DCMD_ERR);
2125 	}
2126 
2127 	mdb_printf("ACL Revision: %d\n", acl.sl_revision);
2128 	mdb_printf("ACL Size on Wire: %d\n", acl.sl_bsize);
2129 	mdb_printf("ACL Number of ACEs: %d\n", acl.sl_acecnt);
2130 
2131 	(void) mdb_inc_indent(SMB_DCMD_INDENT);
2132 	if (mdb_pwalk_dcmd("smbace_walker", "smbace", argc, argv, addr)) {
2133 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2134 		mdb_warn("failed to walk list of ACEs for ACL %p", addr);
2135 		return (DCMD_ERR);
2136 	}
2137 	(void) mdb_dec_indent(SMB_DCMD_INDENT);
2138 	return (DCMD_OK);
2139 }
2140 
2141 /*
2142  * *****************************************************************************
2143  * ********************************* smb_sd_t **********************************
2144  * *****************************************************************************
2145  */
2146 
2147 /*
2148  * ::smbsd
2149  */
2150 static int
2151 smb_sd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2152 {
2153 	smb_sd_t	sd;
2154 	int		rc;
2155 
2156 	/*
2157 	 * An smb_sid address is required.
2158 	 */
2159 	if (!(flags & DCMD_ADDRSPEC))
2160 		return (DCMD_USAGE);
2161 
2162 	if (mdb_vread(&sd, sizeof (sd), addr) != sizeof (sd)) {
2163 		mdb_warn("failed to read struct smb_sd at %p", addr);
2164 		return (DCMD_ERR);
2165 	}
2166 
2167 	mdb_printf("SD Revision: %d\n", sd.sd_revision);
2168 	mdb_printf("SD Control: %04x\n", sd.sd_control);
2169 	if (sd.sd_control & SE_OWNER_DEFAULTED)
2170 		mdb_printf("\t    SE_OWNER_DEFAULTED\n");
2171 	if (sd.sd_control & SE_GROUP_DEFAULTED)
2172 		mdb_printf("\t    SE_GROUP_DEFAULTED\n");
2173 	if (sd.sd_control & SE_DACL_PRESENT)
2174 		mdb_printf("\t    SE_DACL_PRESENT\n");
2175 	if (sd.sd_control & SE_DACL_DEFAULTED)
2176 		mdb_printf("\t    SE_DACL_DEFAULTED\n");
2177 	if (sd.sd_control & SE_SACL_PRESENT)
2178 		mdb_printf("\t    SE_SACL_PRESENT\n");
2179 	if (sd.sd_control & SE_SACL_DEFAULTED)
2180 		mdb_printf("\t    SE_SACL_DEFAULTED\n");
2181 	if (sd.sd_control & SE_DACL_AUTO_INHERIT_REQ)
2182 		mdb_printf("\t    SE_DACL_AUTO_INHERIT_REQ\n");
2183 	if (sd.sd_control & SE_SACL_AUTO_INHERIT_REQ)
2184 		mdb_printf("\t    SE_SACL_AUTO_INHERIT_REQ\n");
2185 	if (sd.sd_control & SE_DACL_AUTO_INHERITED)
2186 		mdb_printf("\t    SE_DACL_AUTO_INHERITED\n");
2187 	if (sd.sd_control & SE_SACL_AUTO_INHERITED)
2188 		mdb_printf("\t    SE_SACL_AUTO_INHERITED\n");
2189 	if (sd.sd_control & SE_DACL_PROTECTED)
2190 		mdb_printf("\t    SE_DACL_PROTECTED\n");
2191 	if (sd.sd_control & SE_SACL_PROTECTED)
2192 		mdb_printf("\t    SE_SACL_PROTECTED\n");
2193 	if (sd.sd_control & SE_SELF_RELATIVE)
2194 		mdb_printf("\t    SE_SELF_RELATIVE\n");
2195 
2196 	mdb_printf("SID of Owner: ");
2197 	rc = smb_sid_print((uintptr_t)sd.sd_owner);
2198 	if (rc != DCMD_OK)
2199 		return (rc);
2200 	mdb_printf("\nSID of Group: ");
2201 	rc = smb_sid_print((uintptr_t)sd.sd_group);
2202 	if (rc != DCMD_OK)
2203 		return (rc);
2204 	mdb_printf("\n");
2205 
2206 	if (sd.sd_control & SE_SACL_PRESENT && sd.sd_sacl) {
2207 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
2208 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
2209 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_sacl, flags,
2210 		    argc, argv);
2211 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2212 		if (rc != DCMD_OK)
2213 			return (rc);
2214 	}
2215 	if (sd.sd_control & SE_DACL_PRESENT && sd.sd_dacl) {
2216 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
2217 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
2218 		rc = mdb_call_dcmd("smbacl", (uintptr_t)sd.sd_dacl, flags,
2219 		    argc, argv);
2220 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2221 		if (rc != DCMD_OK)
2222 			return (rc);
2223 	}
2224 
2225 	return (DCMD_OK);
2226 }
2227 
2228 /*
2229  * *****************************************************************************
2230  * ********************************* smb_sid_t *********************************
2231  * *****************************************************************************
2232  */
2233 
2234 /*
2235  * ::smbsid
2236  */
2237 /*ARGSUSED*/
2238 static int
2239 smb_sid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2240 {
2241 	/*
2242 	 * An smb_sid address is required.
2243 	 */
2244 	if (!(flags & DCMD_ADDRSPEC))
2245 		return (DCMD_USAGE);
2246 
2247 	return (smb_sid_print(addr));
2248 }
2249 
2250 /*
2251  * smb_sid_print
2252  */
2253 static int
2254 smb_sid_print(uintptr_t addr)
2255 {
2256 	smb_sid_t	sid;
2257 	smb_sid_t	*psid;
2258 	size_t		sid_size;
2259 	int		i;
2260 	uint64_t	authority;
2261 
2262 	sid_size = offsetof(smb_sid_t, sid_subauth);
2263 
2264 	if (mdb_vread(&sid, sid_size, addr) != sid_size) {
2265 		mdb_warn("failed to read struct smb_sid at %p", addr);
2266 		return (DCMD_ERR);
2267 	}
2268 
2269 	sid_size += sid.sid_subauthcnt * sizeof (sid.sid_subauth[0]);
2270 
2271 	psid = mdb_zalloc(sid_size, UM_SLEEP | UM_GC);
2272 	if (mdb_vread(psid, sid_size, addr) != sid_size) {
2273 		mdb_warn("failed to read struct smb_sid at %p", addr);
2274 		return (DCMD_ERR);
2275 	}
2276 
2277 	mdb_printf("S-%d", psid->sid_revision);
2278 	authority = 0;
2279 	for (i = 0; i < NT_SID_AUTH_MAX; i++) {
2280 		authority += ((uint64_t)psid->sid_authority[i]) <<
2281 		    (8 * (NT_SID_AUTH_MAX - 1) - i);
2282 	}
2283 	mdb_printf("-%ll", authority);
2284 
2285 	for (i = 0; i < psid->sid_subauthcnt; i++)
2286 		mdb_printf("-%d", psid->sid_subauth[i]);
2287 
2288 	return (DCMD_OK);
2289 }
2290 
2291 /*
2292  * *****************************************************************************
2293  * ********************************* smb_fssd_t ********************************
2294  * *****************************************************************************
2295  */
2296 
2297 /*
2298  * ::smbfssd
2299  */
2300 static int
2301 smb_fssd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2302 {
2303 	smb_fssd_t	fssd;
2304 	int		rc;
2305 
2306 	/*
2307 	 * An smb_fssd address is required.
2308 	 */
2309 	if (!(flags & DCMD_ADDRSPEC))
2310 		return (DCMD_USAGE);
2311 
2312 	if (mdb_vread(&fssd, sizeof (fssd), addr) != sizeof (fssd)) {
2313 		mdb_warn("failed to read struct smb_fssd at %p", addr);
2314 		return (DCMD_ERR);
2315 	}
2316 
2317 	mdb_printf("FSSD secinfo: 0x%x\n", fssd.sd_secinfo);
2318 	if (fssd.sd_secinfo & SMB_OWNER_SECINFO)
2319 		mdb_printf("FSSD uid: %d\n", fssd.sd_uid);
2320 	if (fssd.sd_secinfo & SMB_GROUP_SECINFO)
2321 		mdb_printf("FSSD gid: %d\n", fssd.sd_gid);
2322 	if (fssd.sd_secinfo & SMB_SACL_SECINFO && fssd.sd_zsacl) {
2323 		mdb_printf("%<b>%<u>System ACL%</u>%</b>\n");
2324 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
2325 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zsacl, flags,
2326 		    argc, argv);
2327 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2328 		if (rc != DCMD_OK)
2329 			return (rc);
2330 	}
2331 	if (fssd.sd_secinfo & SMB_DACL_SECINFO && fssd.sd_zdacl) {
2332 		mdb_printf("%<b>%<u>Discretionary ACL%</u>%</b>\n");
2333 		(void) mdb_inc_indent(SMB_DCMD_INDENT);
2334 		rc = mdb_call_dcmd("smbacl", (uintptr_t)fssd.sd_zdacl, flags,
2335 		    argc, argv);
2336 		(void) mdb_dec_indent(SMB_DCMD_INDENT);
2337 		if (rc != DCMD_OK)
2338 			return (rc);
2339 	}
2340 
2341 	return (DCMD_OK);
2342 }
2343 
2344 /*
2345  * *****************************************************************************
2346  * **************************** Utility Funcions *******************************
2347  * *****************************************************************************
2348  */
2349 
2350 /*
2351  * smb_dcmd_getopt
2352  *
2353  * This function analyzes the arguments passed in and sets the bit corresponding
2354  * to the options found in the opts variable.
2355  *
2356  * Return Value
2357  *
2358  *	-1	An error occured during the decoding
2359  *	0	The decoding was successful
2360  */
2361 static int
2362 smb_dcmd_getopt(uint_t *opts, int argc, const mdb_arg_t *argv)
2363 {
2364 	*opts = 0;
2365 
2366 	if (mdb_getopts(argc, argv,
2367 	    's', MDB_OPT_SETBITS, SMB_OPT_SERVER, opts,
2368 	    'e', MDB_OPT_SETBITS, SMB_OPT_SESSION, opts,
2369 	    'r', MDB_OPT_SETBITS, SMB_OPT_REQUEST, opts,
2370 	    'u', MDB_OPT_SETBITS, SMB_OPT_USER, opts,
2371 	    't', MDB_OPT_SETBITS, SMB_OPT_TREE, opts,
2372 	    'f', MDB_OPT_SETBITS, SMB_OPT_OFILE, opts,
2373 	    'd', MDB_OPT_SETBITS, SMB_OPT_ODIR, opts,
2374 	    'w', MDB_OPT_SETBITS, SMB_OPT_WALK, opts,
2375 	    'v', MDB_OPT_SETBITS, SMB_OPT_VERBOSE, opts,
2376 	    NULL) != argc)
2377 		return (-1);
2378 
2379 	return (0);
2380 }
2381 
2382 /*
2383  * smb_dcmd_setopt
2384  *
2385  * This function set the arguments corresponding to the bits set in opts.
2386  *
2387  * Return Value
2388  *
2389  *	Number of arguments set.
2390  */
2391 static int
2392 smb_dcmd_setopt(uint_t opts, int max_argc, mdb_arg_t *argv)
2393 {
2394 	int	i;
2395 	int	argc = 0;
2396 
2397 	for (i = 0; i < SMB_MDB_MAX_OPTS; i++) {
2398 		if ((opts & smb_opts[i].o_value) && (argc < max_argc)) {
2399 			argv->a_type = MDB_TYPE_STRING;
2400 			argv->a_un.a_str = smb_opts[i].o_name;
2401 			argc++;
2402 			argv++;
2403 		}
2404 	}
2405 	return (argc);
2406 }
2407 
2408 /*
2409  * smb_obj_expand
2410  */
2411 static int
2412 smb_obj_expand(uintptr_t addr, uint_t opts, const smb_exp_t *x, ulong_t indent)
2413 {
2414 	int		rc = 0;
2415 	int		argc;
2416 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
2417 
2418 	argc = smb_dcmd_setopt(opts | SMB_OPT_WALK, SMB_MDB_MAX_OPTS, argv);
2419 
2420 	(void) mdb_inc_indent(indent);
2421 	while (x->ex_dcmd) {
2422 		if (x->ex_mask & opts) {
2423 			rc = mdb_pwalk_dcmd("list", x->ex_dcmd, argc, argv,
2424 			    addr + x->ex_offset);
2425 
2426 			if (rc) {
2427 				mdb_warn("failed to walk the list of %s in %p",
2428 				    x->ex_name, addr + x->ex_offset);
2429 				break;
2430 			}
2431 		}
2432 		x++;
2433 	}
2434 	(void) mdb_dec_indent(indent);
2435 	return (rc);
2436 }
2437 
2438 /*
2439  * smb_obj_list
2440  *
2441  * Function called by the DCMDs when no address is provided. It expands the
2442  * tree under the object type associated with the calling DCMD (based on the
2443  * flags passed in).
2444  *
2445  * Return Value
2446  *
2447  *	DCMD_OK
2448  *	DCMD_ERR
2449  */
2450 static int
2451 smb_obj_list(const char *name, uint_t opts, uint_t flags)
2452 {
2453 	int		argc;
2454 	mdb_arg_t	argv[SMB_MDB_MAX_OPTS];
2455 
2456 	argc = smb_dcmd_setopt(opts, SMB_MDB_MAX_OPTS, argv);
2457 
2458 	if (mdb_call_dcmd("smblist", 0, flags, argc, argv)) {
2459 		mdb_warn("failed to list %s", name);
2460 		return (DCMD_ERR);
2461 	}
2462 	return (DCMD_OK);
2463 }
2464 
2465 static int
2466 smb_worker_findstack(uintptr_t addr)
2467 {
2468 	kthread_t	t;
2469 	taskq_t		tq;
2470 	char		cmd[80];
2471 	mdb_arg_t	cmdarg;
2472 
2473 	if (mdb_vread(&t, sizeof (kthread_t), addr) == -1) {
2474 		mdb_warn("failed to read kthread_t at %p", addr);
2475 		return (DCMD_ERR);
2476 	}
2477 
2478 	if (mdb_vread(&tq, sizeof (taskq_t), (uintptr_t)t.t_taskq) == -1)
2479 		tq.tq_name[0] = '\0';
2480 
2481 	mdb_inc_indent(2);
2482 
2483 	mdb_printf("PC: %a", t.t_pc);
2484 	if (t.t_tid == 0) {
2485 		if (tq.tq_name[0] != '\0')
2486 			mdb_printf("    TASKQ: %s\n", tq.tq_name);
2487 		else
2488 			mdb_printf("    THREAD: %a()\n", t.t_startpc);
2489 	}
2490 
2491 	mdb_snprintf(cmd, sizeof (cmd), "<.$c%d", 16);
2492 	cmdarg.a_type = MDB_TYPE_STRING;
2493 	cmdarg.a_un.a_str = cmd;
2494 	(void) mdb_call_dcmd("findstack", addr, DCMD_ADDRSPEC, 1, &cmdarg);
2495 	mdb_dec_indent(2);
2496 	mdb_printf("\n");
2497 	return (DCMD_OK);
2498 }
2499