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