xref: /illumos-gate/usr/src/uts/common/smbsrv/smb_ktypes.h (revision faa1795a28a5c712eed6d0a3f84d98c368a316c6)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Structures and type definitions for the SMB module.
28  */
29 
30 #ifndef _SMBSRV_SMB_KTYPES_H
31 #define	_SMBSRV_SMB_KTYPES_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/note.h>
40 #include <sys/systm.h>
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/synch.h>
44 #include <sys/taskq.h>
45 #include <sys/acl.h>
46 #include <sys/sdt.h>
47 #include <sys/vnode.h>
48 #include <sys/cred.h>
49 #include <sys/fem.h>
50 #include <sys/door.h>
51 #include <smbsrv/smb.h>
52 #include <smbsrv/lmshare.h>
53 #include <smbsrv/smbinfo.h>
54 #include <smbsrv/mbuf.h>
55 
56 #include <smbsrv/smb_vops.h>
57 #include <smbsrv/smb_fsd.h>
58 #include <smbsrv/mlsvc.h>
59 
60 struct smb_request;
61 struct smb_server;
62 typedef struct smb_sd smb_sd_t;
63 
64 int smb_noop(void *, size_t, int);
65 
66 #define	SMB_AUDIT_STACK_DEPTH	16
67 #define	SMB_AUDIT_BUF_MAX_REC	16
68 #define	SMB_AUDIT_NODE		0x00000001
69 
70 extern uint32_t smb_audit_flags;
71 
72 typedef struct {
73 	uint32_t		anr_refcnt;
74 	int			anr_depth;
75 	pc_t			anr_stack[SMB_AUDIT_STACK_DEPTH];
76 } smb_audit_record_node_t;
77 
78 typedef struct {
79 	int			anb_index;
80 	int			anb_max_index;
81 	smb_audit_record_node_t	anb_records[SMB_AUDIT_BUF_MAX_REC];
82 } smb_audit_buf_node_t;
83 
84 #define	SMB_WORKER_PRIORITY	99
85 /*
86  * Thread State Machine
87  * --------------------
88  *
89  *			    T5			   T0
90  * smb_thread_destroy()	<-------+		+------- smb_thread_init()
91  *                              |		|
92  *				|		v
93  *			+-----------------------------+
94  *			|   SMB_THREAD_STATE_EXITED   |<---+
95  *			+-----------------------------+	   |
96  *				      | T1		   |
97  *				      v			   |
98  *			+-----------------------------+	   |
99  *			|  SMB_THREAD_STATE_STARTING  |	   |
100  *			+-----------------------------+	   |
101  *				     | T2		   | T4
102  *				     v			   |
103  *			+-----------------------------+	   |
104  *			|  SMB_THREAD_STATE_RUNNING   |	   |
105  *			+-----------------------------+	   |
106  *				     | T3		   |
107  *				     v			   |
108  *			+-----------------------------+	   |
109  *			|  SMB_THREAD_STATE_EXITING   |----+
110  *			+-----------------------------+
111  *
112  * Transition T0
113  *
114  *    This transition is executed in smb_thread_init().
115  *
116  * Transition T1
117  *
118  *    This transition is executed in smb_thread_start().
119  *
120  * Transition T2
121  *
122  *    This transition is executed by the thread itself when it starts running.
123  *
124  * Transition T3
125  *
126  *    This transition is executed by the thread itself in
127  *    smb_thread_entry_point() just before calling thread_exit().
128  *
129  *
130  * Transition T4
131  *
132  *    This transition is executed in smb_thread_stop().
133  *
134  * Transition T5
135  *
136  *    This transition is executed in smb_thread_destroy().
137  *
138  * Comments
139  * --------
140  *
141  *    The field smb_thread_aw_t contains a function pointer that knows how to
142  *    awake the thread. It is a temporary solution to work around the fact that
143  *    kernel threads (not part of a userspace process) cannot be signaled.
144  */
145 typedef enum smb_thread_state {
146 	SMB_THREAD_STATE_STARTING = 0,
147 	SMB_THREAD_STATE_RUNNING,
148 	SMB_THREAD_STATE_EXITING,
149 	SMB_THREAD_STATE_EXITED
150 } smb_thread_state_t;
151 
152 struct _smb_thread;
153 
154 typedef void (*smb_thread_ep_t)(struct _smb_thread *, void *ep_arg);
155 typedef void (*smb_thread_aw_t)(struct _smb_thread *, void *aw_arg);
156 
157 #define	SMB_THREAD_MAGIC	0x534D4254	/* SMBT */
158 
159 typedef struct _smb_thread {
160 	uint32_t		sth_magic;
161 	char			sth_name[16];
162 	smb_thread_state_t	sth_state;
163 	kthread_t		*sth_th;
164 	kt_did_t		sth_did;
165 	smb_thread_ep_t		sth_ep;
166 	void			*sth_ep_arg;
167 	smb_thread_aw_t		sth_aw;
168 	void			*sth_aw_arg;
169 	boolean_t		sth_kill;
170 	kmutex_t		sth_mtx;
171 	kcondvar_t		sth_cv;
172 } smb_thread_t;
173 
174 /*
175  * Pool of IDs
176  * -----------
177  *
178  *    A pool of IDs is a pool of 16 bit numbers. It is implemented as a bitmap.
179  *    A bit set to '1' indicates that that particular value has been allocated.
180  *    The allocation process is done shifting a bit through the whole bitmap.
181  *    The current position of that index bit is kept in the smb_idpool_t
182  *    structure and represented by a byte index (0 to buffer size minus 1) and
183  *    a bit index (0 to 7).
184  *
185  *    The pools start with a size of 8 bytes or 64 IDs. Each time the pool runs
186  *    out of IDs its current size is doubled until it reaches its maximum size
187  *    (8192 bytes or 65536 IDs). The IDs 0 and 65535 are never given out which
188  *    means that a pool can have a maximum number of 65534 IDs available.
189  */
190 #define	SMB_IDPOOL_MAGIC	0x4944504C	/* IDPL */
191 #define	SMB_IDPOOL_MIN_SIZE	64	/* Number of IDs to begin with */
192 #define	SMB_IDPOOL_MAX_SIZE	64 * 1024
193 
194 typedef struct smb_idpool {
195 	uint32_t	id_magic;
196 	kmutex_t	id_mutex;
197 	uint8_t		*id_pool;
198 	uint32_t	id_size;
199 	uint8_t		id_bit;
200 	uint8_t		id_bit_idx;
201 	uint32_t	id_idx;
202 	uint32_t	id_idx_msk;
203 	uint32_t	id_free_counter;
204 	uint32_t	id_max_free_counter;
205 } smb_idpool_t;
206 
207 /*
208  * Maximum size of a Netbios Request.
209  *   0x1FFFF -> Maximum size of the data
210  *   4 -> Size of the Netbios header
211  */
212 #define	NETBIOS_REQ_MAX_SIZE	(0x1FFFF + 0x4)
213 
214 #define	SMB_TXBUF_MAGIC		0X54584246	/* 'TXBF' */
215 typedef struct {
216 	uint32_t	tb_magic;
217 	list_node_t	tb_lnd;
218 	int		tb_len;
219 	uint8_t		tb_data[NETBIOS_REQ_MAX_SIZE];
220 } smb_txbuf_t;
221 
222 #define	SMB_TXLST_MAGIC		0X544C5354	/* 'TLST' */
223 typedef struct {
224 	uint32_t	tl_magic;
225 	kmutex_t	tl_mutex;
226 	boolean_t	tl_active;
227 	list_t		tl_list;
228 } smb_txlst_t;
229 
230 /*
231  * Maximum buffer size for NT is 37KB.  If all clients are Windows 2000, this
232  * can be changed to 64KB.  37KB must be used with a mix of NT/Windows 2000
233  * clients because NT loses directory entries when values greater than 37KB are
234  * used.
235  *
236  * Note: NBT_MAXBUF will be subtracted from the specified max buffer size to
237  * account for the NBT header.
238  */
239 #define	NBT_MAXBUF		8
240 #define	SMB_NT_MAXBUF		(37 * 1024)
241 
242 #define	OUTBUFSIZE		(65 * 1024)
243 #define	SMBHEADERSIZE		32
244 #define	SMBND_HASH_MASK		(0xFF)
245 #define	MAX_IOVEC		512
246 #define	MAX_READREF		(8 * 1024)
247 
248 #define	SMB_WORKER_MIN		4
249 #define	SMB_WORKER_DEFAULT	64
250 #define	SMB_WORKER_MAX		1024
251 
252 /*
253  * Fix align a pointer or offset appropriately so that fields will not
254  * cross word boundaries.
255  */
256 #define	PTRALIGN(x) \
257 	(((uintptr_t)(x) + (uintptr_t)(_POINTER_ALIGNMENT) - 1l) & \
258 	    ~((uintptr_t)(_POINTER_ALIGNMENT) - 1l))
259 
260 /*
261  * native os types are defined in win32/smbinfo.h
262  */
263 
264 /*
265  * All 4 different time / date formats that will bee seen in SMB
266  */
267 typedef struct {
268 	uint16_t	Day	: 5;
269 	uint16_t	Month	: 4;
270 	uint16_t	Year	: 7;
271 } SMB_DATE;
272 
273 typedef struct {
274 	uint16_t	TwoSeconds : 5;
275 	uint16_t	Minutes	   : 6;
276 	uint16_t	Hours	   : 5;
277 } SMB_TIME;
278 
279 
280 typedef uint32_t 	UTIME;		/* seconds since Jan 1 1970 */
281 
282 typedef struct smb_malloc_list {
283 	struct smb_malloc_list	*forw;
284 	struct smb_malloc_list	*back;
285 } smb_malloc_list;
286 
287 typedef struct smb_llist {
288 	krwlock_t	ll_lock;
289 	list_t		ll_list;
290 	uint32_t	ll_count;
291 	uint64_t	ll_wrop;
292 } smb_llist_t;
293 
294 typedef struct smb_slist {
295 	kmutex_t	sl_mutex;
296 	kcondvar_t	sl_cv;
297 	list_t		sl_list;
298 	uint32_t	sl_count;
299 	boolean_t	sl_waiting;
300 } smb_slist_t;
301 
302 typedef struct smb_session_list {
303 	krwlock_t	se_lock;
304 	uint64_t	se_wrop;
305 	struct {
306 		list_t		lst;
307 		uint32_t	count;
308 	} se_rdy;
309 	struct {
310 		list_t		lst;
311 		uint32_t	count;
312 	} se_act;
313 } smb_session_list_t;
314 
315 typedef struct {
316 	kcondvar_t	rwx_cv;
317 	kmutex_t	rwx_mutex;
318 	krwlock_t	rwx_lock;
319 	boolean_t	rwx_waiting;
320 } smb_rwx_t;
321 
322 /* NOTIFY CHANGE */
323 
324 typedef struct smb_notify_change_req {
325 	list_node_t		nc_lnd;
326 	struct smb_node		*nc_node;
327 	uint32_t		nc_reply_type;
328 	uint32_t		nc_flags;
329 } smb_notify_change_req_t;
330 
331 /*
332  * SMB operates over a NetBIOS-over-TCP transport (NBT) or directly
333  * over TCP, which is also known as direct hosted NetBIOS-less SMB
334  * or SMB-over-TCP.
335  *
336  * NBT messages have a 4-byte header that defines the message type
337  * (8-bits), a 7-bit flags field and a 17-bit length.
338  *
339  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
340  * |      TYPE     |     FLAGS   |E|            LENGTH             |
341  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
342  *
343  * 8-bit type      Defined in RFC 1002
344  * 7-bit flags     Bits 0-6 reserved (must be 0)
345  *                 Bit 7: Length extension bit (E)
346  * 17-bit length   Includes bit 7 of the flags byte
347  *
348  *
349  * SMB-over-TCP is defined to use a modified version of the NBT header
350  * containing an 8-bit message type and 24-bit message length.
351  *
352  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
353  * |      TYPE     |                  LENGTH                       |
354  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
355  *
356  * 8-bit type      Must be 0
357  * 24-bit length
358  *
359  * The following structure is used to represent a generic, in-memory
360  * SMB transport header; it is not intended to map directly to either
361  * of the over-the-wire formats.
362  */
363 typedef struct {
364 	uint8_t		xh_type;
365 	uint32_t	xh_length;
366 } smb_xprt_t;
367 
368 struct mbuf_chain {
369 	volatile uint32_t	flags;		/* Various flags */
370 	struct mbuf_chain	*shadow_of;	/* I'm shadowing someone */
371 	struct mbuf		*chain;		/* Start of chain */
372 	int32_t			max_bytes;	/* max # of bytes for chain */
373 	int32_t			chain_offset;	/* Current offset into chain */
374 };
375 
376 int MBC_LENGTH(struct mbuf_chain *);
377 void MBC_SETUP(struct mbuf_chain *, uint32_t);
378 void MBC_INIT(struct mbuf_chain *, uint32_t);
379 void MBC_FLUSH(struct mbuf_chain *);
380 void MBC_ATTACH_MBUF(struct mbuf_chain *, struct mbuf *);
381 void MBC_APPEND_MBUF(struct mbuf_chain *, struct mbuf *);
382 void MBC_ATTACH_BUF(struct mbuf_chain *MBC, unsigned char *BUF, int LEN);
383 int MBC_SHADOW_CHAIN(struct mbuf_chain *SUBMBC, struct mbuf_chain *MBC,
384     int OFF, int LEN);
385 
386 #define	MBC_ROOM_FOR(b, n) (((b)->chain_offset + (n)) <= (b)->max_bytes)
387 
388 typedef struct smb_oplock {
389 	struct smb_ofile	*op_ofile;
390 	uint32_t		op_flags;
391 } smb_oplock_t;
392 
393 #define	OPLOCK_FLAG_BREAKING	1
394 
395 #define	OPLOCK_RELEASE_LOCK_RELEASED	0
396 #define	OPLOCK_RELEASE_FILE_CLOSED	1
397 
398 #define	DOS_ATTR_VALID	0x80000000
399 
400 #define	SMB_VFS_MAGIC	0x534D4256	/* 'SMBV' */
401 
402 typedef struct smb_vfs {
403 	uint32_t		sv_magic;
404 	list_node_t		sv_lnd;
405 	uint32_t		sv_refcnt;
406 	vfs_t			*sv_vfsp;
407 	vnode_t			*sv_rootvp;
408 } smb_vfs_t;
409 
410 #define	SMB_NODE_MAGIC 0x4E4F4445	/* 'NODE' */
411 
412 typedef enum {
413 	SMB_NODE_STATE_AVAILABLE = 0,
414 	SMB_NODE_STATE_DESTROYING
415 } smb_node_state_t;
416 
417 typedef struct smb_node {
418 	uint32_t		n_magic;
419 	smb_rwx_t		n_lock;
420 	krwlock_t		n_share_lock;
421 	list_node_t		n_lnd;
422 	smb_node_state_t	n_state;
423 	uint32_t		n_refcnt;
424 	uint32_t		n_hashkey;
425 	struct smb_request	*n_sr;
426 	kmem_cache_t		*n_cache;
427 	smb_llist_t		*n_hash_bucket;
428 	uint64_t		n_orig_session_id;
429 	uint32_t		n_orig_uid;
430 	smb_llist_t		n_ofile_list;
431 	smb_llist_t		n_lock_list;
432 	volatile int		flags;	/* FILE_NOTIFY_CHANGE_* */
433 	volatile int		waiting_event; /* # of clients requesting FCN */
434 	smb_attr_t		attr;
435 	unsigned int		what;
436 	u_offset_t		n_size;
437 	smb_oplock_t		n_oplock;
438 	struct smb_node		*dir_snode; /* Directory of node */
439 	struct smb_node		*unnamed_stream_node; /* set in stream nodes */
440 	/* Credentials for delayed delete */
441 	cred_t			*delete_on_close_cred;
442 	char			od_name[MAXNAMELEN];
443 	timestruc_t		set_mtime;
444 	fs_desc_t		tree_fsd;
445 	vnode_t			*vp;
446 	smb_audit_buf_node_t	*n_audit_buf;
447 
448 } smb_node_t;
449 
450 #define	NODE_FLAGS_NOTIFY_CHANGE	0x10000fff
451 #define	NODE_OPLOCKS_IN_FORCE		0x0000f000
452 #define	NODE_OPLOCK_NONE		0x00000000
453 #define	NODE_EXCLUSIVE_OPLOCK		0x00001000
454 #define	NODE_BATCH_OPLOCK		0x00002000
455 #define	NODE_LEVEL_II_OPLOCK		0x00003000
456 #define	NODE_CAP_LEVEL_II		0x00010000
457 #define	NODE_PROTOCOL_LOCK		0x00020000
458 #define	NODE_READ_ONLY			0x00040000
459 #define	NODE_CREATED_READONLY		0x00080000
460 #define	NODE_FLAGS_WRITE_THROUGH	0x00100000
461 #define	NODE_FLAGS_SYNCATIME		0x00200000
462 #define	NODE_FLAGS_LOCKED		0x00400000
463 #define	NODE_FLAGS_ATTR_VALID		0x00800000
464 #define	NODE_XATTR_DIR			0x01000000
465 #define	NODE_FLAGS_CREATED		0x04000000
466 #define	NODE_FLAGS_CHANGED		0x08000000
467 #define	NODE_FLAGS_WATCH_TREE		0x10000000
468 #define	NODE_FLAGS_SET_SIZE		0x20000000
469 #define	NODE_FLAGS_DELETE_ON_CLOSE	0x40000000
470 #define	NODE_FLAGS_EXECUTABLE		0x80000000
471 
472 #define	NODE_IS_READONLY(node)					\
473 	((node->attr.sa_dosattr & FILE_ATTRIBUTE_READONLY) ||	\
474 	(node->flags & NODE_READ_ONLY) ||			\
475 	(node->flags & NODE_CREATED_READONLY))
476 
477 #define	OPLOCK_TYPE(n)			((n)->flags & NODE_OPLOCKS_IN_FORCE)
478 #define	OPLOCKS_IN_FORCE(n)		(OPLOCK_TYPE(n) != NODE_OPLOCK_NONE)
479 #define	EXCLUSIVE_OPLOCK_IN_FORCE(n)	\
480 	(OPLOCK_TYPE(n) == NODE_EXCLUSIVE_OPLOCK)
481 #define	BATCH_OPLOCK_IN_FORCE(n)	(OPLOCK_TYPE(n) == NODE_BATCH_OPLOCK)
482 #define	LEVEL_II_OPLOCK_IN_FORCE(n)	(OPLOCK_TYPE(n) == NODE_LEVEL_II_OPLOCK)
483 
484 /*
485  * Based on section 2.6.1.2 (Connection Management) of the June 13,
486  * 1996 CIFS spec, a server may terminate the transport connection
487  * due to inactivity. The client software is expected to be able to
488  * automatically reconnect to the server if this happens. Like much
489  * of the useful background information, this section appears to
490  * have been dropped from later revisions of the document.
491  *
492  * Each session has an activity timestamp that's updated whenever a
493  * request is dispatched. If the session is idle, i.e. receives no
494  * requests, for SMB_SESSION_INACTIVITY_TIMEOUT minutes it will be
495  * closed.
496  *
497  * Each session has an I/O semaphore to serialize communication with
498  * the client. For example, after receiving a raw-read request, the
499  * server is not allowed to send an oplock break to the client until
500  * after it has sent the raw-read data.
501  */
502 #define	SMB_SESSION_INACTIVITY_TIMEOUT		(15 * 60)
503 
504 #define	SMB_SESSION_OFILE_MAX				(16 * 1024)
505 
506 /*
507  * When a connection is set up we need to remember both the client
508  * (peer) IP address and the local IP address used to establish the
509  * connection. When a client connects with a vc number of zero, we
510  * are supposed to abort any existing connections with that client
511  * (see notes in smb_negotiate.c and smb_session_setup_andx.c). For
512  * servers with multiple network interfaces or IP aliases, however,
513  * each interface has to be managed independently since the client
514  * is not aware of the server configuration. We have to allow the
515  * client to establish a connection on each interface with a vc
516  * number of zero without aborting the other connections.
517  *
518  * ipaddr:       the client (peer) IP address for the session.
519  * local_ipaddr: the local IP address used to connect to the server.
520  */
521 
522 #define	SMB_MAC_KEYSZ	512
523 
524 struct smb_sign {
525 	unsigned int seqnum;
526 	unsigned int mackey_len;
527 	unsigned int flags;
528 	unsigned char mackey[SMB_MAC_KEYSZ];
529 };
530 
531 #define	SMB_SIGNING_ENABLED	1
532 #define	SMB_SIGNING_CHECK	2
533 
534 /*
535  * Session State Machine
536  * ---------------------
537  *
538  * +-----------------------------+	     +------------------------------+
539  * | SMB_SESSION_STATE_CONNECTED |           | SMB_SESSION_STATE_TERMINATED |
540  * +-----------------------------+           +------------------------------+
541  *		T0|					     ^
542  *		  +--------------------+		     |T13
543  *		  v		       |T14                  |
544  * +-------------------------------+   |    +--------------------------------+
545  * | SMB_SESSION_STATE_ESTABLISHED |---+--->| SMB_SESSION_STATE_DISCONNECTED |
546  * +-------------------------------+        +--------------------------------+
547  *		T1|				^	   ^ ^ ^
548  *		  +----------+			|T9        | | |
549  *                           v			|          | | |
550  *                  +------------------------------+       | | |
551  *                  | SMB_SESSION_STATE_NEGOTIATED |       | | |
552  *                  +------------------------------+       | | |
553  *	                 ^|   ^|   | ^                     | | |
554  *      +----------------+|   ||   | |                     | | |
555  *      |+----------------+   || T7| |T8                   | | |
556  *      ||                    ||   | |                     | | |
557  *      ||   +----------------+|   | |                     | | |
558  *      ||   |+----------------+   | |                     | | |
559  *	||   ||			   v |                     | | |
560  *      ||   ||   +-----------------------------------+ T10| | |
561  *      ||   ||   | SMB_SESSION_STATE_OPLOCK_BREAKING |----+ | |
562  *      ||   ||   +-----------------------------------+      | |
563  *	||   ||T5                                            | |
564  *      ||   |+-->+-----------------------------------+	  T11| |
565  *      ||   |T6  | SMB_SESSION_STATE_READ_RAW_ACTIVE |------+ |
566  *      ||   +----+-----------------------------------+        |
567  *	||T3                                                   |
568  *      |+------->+------------------------------------+    T12|
569  *      |T4       | SMB_SESSION_STATE_WRITE_RAW_ACTIVE |-------+
570  *      +---------+------------------------------------+
571  *
572  * Transition T0
573  *
574  *
575  *
576  * Transition T1
577  *
578  *
579  *
580  * Transition T2
581  *
582  *
583  *
584  * Transition T3
585  *
586  *
587  *
588  * Transition T4
589  *
590  *
591  *
592  * Transition T5
593  *
594  *
595  *
596  * Transition T6
597  *
598  *
599  *
600  * Transition T7
601  *
602  *
603  *
604  * Transition T8
605  *
606  *
607  *
608  * Transition T9
609  *
610  *
611  *
612  * Transition T10
613  *
614  *
615  *
616  * Transition T11
617  *
618  *
619  *
620  * Transition T12
621  *
622  *
623  *
624  * Transition T13
625  *
626  *
627  *
628  * Transition T14
629  *
630  *
631  *
632  */
633 #define	SMB_SESSION_MAGIC 0x53455353	/* 'SESS' */
634 
635 typedef enum {
636 	SMB_SESSION_STATE_INITIALIZED = 0,
637 	SMB_SESSION_STATE_DISCONNECTED,
638 	SMB_SESSION_STATE_CONNECTED,
639 	SMB_SESSION_STATE_ESTABLISHED,
640 	SMB_SESSION_STATE_NEGOTIATED,
641 	SMB_SESSION_STATE_OPLOCK_BREAKING,
642 	SMB_SESSION_STATE_WRITE_RAW_ACTIVE,
643 	SMB_SESSION_STATE_TERMINATED
644 } smb_session_state_t;
645 
646 typedef struct smb_session {
647 	uint32_t		s_magic;
648 	smb_rwx_t		s_lock;
649 	list_node_t		s_lnd;
650 	uint64_t		s_kid;
651 	smb_session_state_t	s_state;
652 	uint32_t		s_flags;
653 	int			s_write_raw_status;
654 	kthread_t		*s_thread;
655 	kt_did_t		s_ktdid;
656 	smb_kmod_cfg_t		s_cfg;
657 	kmem_cache_t		*s_cache;
658 	kmem_cache_t		*s_cache_request;
659 	struct smb_server	*s_server;
660 	uint32_t		s_gmtoff;
661 	uint32_t		keep_alive;
662 	uint64_t		opentime;
663 	uint16_t		vcnumber;
664 	uint16_t		s_local_port;
665 	uint32_t		ipaddr;
666 	uint32_t		local_ipaddr;
667 	char 			workstation[SMB_PI_MAX_HOST];
668 	int			dialect;
669 	int			native_os;
670 	uint32_t		capabilities;
671 	struct smb_sign		signing;
672 
673 	struct sonode		*sock;
674 
675 	smb_slist_t		s_req_list;
676 	smb_llist_t		s_xa_list;
677 	smb_llist_t		s_user_list;
678 	smb_idpool_t		s_uid_pool;
679 	smb_txlst_t		s_txlst;
680 
681 	volatile uint32_t	s_tree_cnt;
682 	volatile uint32_t	s_file_cnt;
683 	volatile uint32_t	s_dir_cnt;
684 
685 	uint16_t		secmode;
686 	uint32_t		sesskey;
687 	uint32_t		challenge_len;
688 	unsigned char		challenge_key[8];
689 	unsigned char		MAC_key[44];
690 	int64_t			activity_timestamp;
691 	/*
692 	 * Maximum negotiated buffer size between SMB client and server
693 	 * in SMB_SESSION_SETUP_ANDX
694 	 */
695 	uint16_t		smb_msg_size;
696 	uchar_t			*outpipe_data;
697 	int			outpipe_datalen;
698 	int			outpipe_cookie;
699 } smb_session_t;
700 
701 #define	SMB_USER_MAGIC 0x55534552	/* 'USER' */
702 
703 #define	SMB_USER_FLAG_GUEST			SMB_ATF_GUEST
704 #define	SMB_USER_FLAG_IPC			SMB_ATF_ANON
705 #define	SMB_USER_FLAG_ADMIN			SMB_ATF_ADMIN
706 #define	SMB_USER_FLAG_POWER_USER		SMB_ATF_POWERUSER
707 #define	SMB_USER_FLAG_BACKUP_OPERATOR		SMB_ATF_BACKUPOP
708 
709 #define	SMB_USER_PRIV_TAKE_OWNERSHIP	0x00000001
710 #define	SMB_USER_PRIV_BACKUP		0x00000002
711 #define	SMB_USER_PRIV_RESTORE		0x00000004
712 #define	SMB_USER_PRIV_SECURITY		0x00000008
713 
714 
715 typedef enum {
716 	SMB_USER_STATE_LOGGED_IN = 0,
717 	SMB_USER_STATE_LOGGING_OFF,
718 	SMB_USER_STATE_LOGGED_OFF
719 } smb_user_state_t;
720 
721 typedef struct smb_user {
722 	uint32_t		u_magic;
723 	list_node_t		u_lnd;
724 	kmutex_t		u_mutex;
725 	smb_user_state_t	u_state;
726 
727 	struct smb_server	*u_server;
728 	smb_session_t		*u_session;
729 	uint16_t		u_name_len;
730 	char			*u_name;
731 	uint16_t		u_domain_len;
732 	char			*u_domain;
733 	time_t			u_logon_time;
734 	cred_t			*u_cred;
735 
736 	smb_llist_t		u_tree_list;
737 	smb_idpool_t		u_tid_pool;
738 
739 	uint32_t		u_refcnt;
740 	uint32_t		u_flags;
741 	uint32_t		u_privileges;
742 	uint16_t		u_uid;
743 	uint32_t		u_audit_sid;
744 } smb_user_t;
745 
746 #define	SMB_TREE_MAGIC 	0x54524545	/* 'TREE' */
747 #define	SMB_TREE_TYPENAME_SZ 	8
748 
749 typedef enum {
750 	SMB_TREE_STATE_CONNECTED = 0,
751 	SMB_TREE_STATE_DISCONNECTING,
752 	SMB_TREE_STATE_DISCONNECTED
753 } smb_tree_state_t;
754 
755 typedef struct smb_tree {
756 	uint32_t		t_magic;
757 	kmutex_t		t_mutex;
758 	list_node_t		t_lnd;
759 	smb_tree_state_t	t_state;
760 
761 	struct smb_server	*t_server;
762 	smb_session_t		*t_session;
763 	smb_user_t		*t_user;
764 	smb_node_t		*t_snode;
765 
766 	smb_llist_t		t_ofile_list;
767 	smb_idpool_t		t_fid_pool;
768 
769 	smb_llist_t		t_odir_list;
770 	smb_idpool_t		t_sid_pool;
771 
772 	uint32_t		t_refcnt;
773 	uint32_t		t_flags;
774 	int32_t			t_res_type;
775 	uint16_t		t_tid;
776 	uint16_t		t_access;
777 	uint16_t		t_umask;
778 	char			t_sharename[MAXNAMELEN];
779 	char			t_resource[MAXPATHLEN];
780 	char			t_typename[SMB_TREE_TYPENAME_SZ];
781 	fs_desc_t		t_fsd;
782 	acl_type_t		t_acltype;
783 } smb_tree_t;
784 
785 /* Tree access bits */
786 #define	SMB_TREE_NO_ACCESS		0x0000
787 #define	SMB_TREE_READ_ONLY		0x0001
788 #define	SMB_TREE_READ_WRITE		0x0002
789 
790 /*
791  * Tree flags
792  *
793  * SMB_TREE_FLAG_ACLONCREATE        Underlying FS supports ACL on create.
794  *
795  * SMB_TREE_FLAG_ACEMASKONACCESS    Underlying FS understands 32-bit access mask
796  */
797 #define	SMB_TREE_FLAG_OPEN		0x0001
798 #define	SMB_TREE_FLAG_CLOSE		0x0002
799 #define	SMB_TREE_FLAG_ACLONCREATE	0x0004
800 #define	SMB_TREE_FLAG_ACEMASKONACCESS	0x0008
801 #define	SMB_TREE_FLAG_IGNORE_CASE	0x0010
802 #define	SMB_TREE_FLAG_NFS_MOUNTED	0x0020
803 #define	SMB_TREE_FLAG_UFS		0x0040
804 #define	SMB_TREE_CLOSED(tree) ((tree)->t_flags & SMB_TREE_FLAG_CLOSE)
805 
806 /*
807  * SMB_TREE_CASE_INSENSITIVE returns whether operations on a given tree
808  * will be case-insensitive or not.  SMB_TREE_FLAG_IGNORE_CASE is set at
809  * share set up time based on file system capability and client preference.
810  */
811 
812 #define	SMB_TREE_CASE_INSENSITIVE(sr)                                 \
813 	(((sr) && (sr)->tid_tree) ?                                     \
814 	((sr)->tid_tree->t_flags & SMB_TREE_FLAG_IGNORE_CASE) : 0)
815 
816 /*
817  * SMB_TREE_ROOT_FS is called by certain smb_fsop_* functions to make sure
818  * that a given vnode is in the same file system as the share root.
819  */
820 
821 #define	SMB_TREE_ROOT_FS(sr, node)                                      \
822 	(((sr) && (sr)->tid_tree) ?                                      \
823 	((sr)->tid_tree->t_snode->vp->v_vfsp == (node)->vp->v_vfsp) : 1)
824 
825 #define	SMB_TREE_IS_READ_ONLY(sr) \
826 	((sr) && ((sr)->tid_tree->t_access == SMB_TREE_READ_ONLY))
827 
828 
829 #define	PIPE_STATE_AUTH_VERIFY	0x00000001
830 
831 /*
832  * The of_ftype	of an open file should contain the SMB_FTYPE value
833  * (cifs.h) returned when the file/pipe was opened. The following
834  * assumptions are currently made:
835  *
836  * File Type	    Node       PipeInfo
837  * ---------	    --------   --------
838  * SMB_FTYPE_DISK       Valid      Null
839  * SMB_FTYPE_BYTE_PIPE  Undefined  Undefined
840  * SMB_FTYPE_MESG_PIPE  Null       Valid
841  * SMB_FTYPE_PRINTER    Undefined  Undefined
842  * SMB_FTYPE_UNKNOWN    Undefined  Undefined
843  */
844 
845 /*
846  * Some flags for ofile structure
847  *
848  *	SMB_OFLAGS_SET_DELETE_ON_CLOSE
849  *   Set this flag when the corresponding open operation whose
850  *   DELETE_ON_CLOSE bit of the CreateOptions is set. If any
851  *   open file instance has this bit set, the NODE_FLAGS_DELETE_ON_CLOSE
852  *   will be set for the file node upon close.
853  */
854 
855 #define	SMB_OFLAGS_SET_DELETE_ON_CLOSE	0x0004
856 #define	SMB_OFLAGS_LLF_POS_VALID	0x0008
857 
858 #define	SMB_OFILE_MAGIC 	0x4F464C45	/* 'OFLE' */
859 
860 typedef enum {
861 	SMB_OFILE_STATE_OPEN = 0,
862 	SMB_OFILE_STATE_CLOSING,
863 	SMB_OFILE_STATE_CLOSED
864 } smb_ofile_state_t;
865 
866 typedef struct smb_ofile {
867 	uint32_t		f_magic;
868 	kmutex_t		f_mutex;
869 	list_node_t		f_lnd;
870 	list_node_t		f_nnd;
871 	smb_ofile_state_t	f_state;
872 
873 	struct smb_server	*f_server;
874 	smb_session_t		*f_session;
875 	smb_user_t		*f_user;
876 	smb_tree_t		*f_tree;
877 	smb_node_t		*f_node;
878 
879 	mlsvc_pipe_t		*f_pipe_info;
880 
881 	uint32_t		f_uniqid;
882 	uint32_t		f_refcnt;
883 	uint64_t		f_seek_pos;
884 	uint32_t		f_flags;
885 	uint32_t		f_granted_access;
886 	uint32_t		f_share_access;
887 	uint32_t		f_create_options;
888 	uint16_t		f_fid;
889 	uint16_t		f_opened_by_pid;
890 	uint16_t		f_ftype;
891 	uint64_t		f_llf_pos;
892 	cred_t			*f_cr;
893 } smb_ofile_t;
894 
895 /* odir flags bits */
896 #define	SMB_DIR_FLAG_OPEN	0x0001
897 #define	SMB_DIR_FLAG_CLOSE	0x0002
898 #define	SMB_DIR_CLOSED(dir) ((dir)->d_flags & SMB_DIR_FLAG_CLOSE)
899 
900 #define	SMB_ODIR_MAGIC 	0x4F444952	/* 'ODIR' */
901 
902 typedef enum {
903 	SMB_ODIR_STATE_OPEN = 0,
904 	SMB_ODIR_STATE_CLOSING,
905 	SMB_ODIR_STATE_CLOSED
906 } smb_odir_state_t;
907 
908 typedef struct smb_odir {
909 	uint32_t		d_magic;
910 	kmutex_t		d_mutex;
911 	list_node_t		d_lnd;
912 	smb_odir_state_t	d_state;
913 
914 	smb_session_t		*d_session;
915 	smb_user_t		*d_user;
916 	smb_tree_t		*d_tree;
917 
918 	uint32_t		d_refcnt;
919 	uint32_t		d_cookie;
920 	uint16_t		d_sid;
921 	uint16_t		d_opened_by_pid;
922 	uint16_t		d_sattr;
923 	char			d_pattern[MAXNAMELEN];
924 	struct smb_node		*d_dir_snode;
925 	unsigned int 		d_wildcards;
926 } smb_odir_t;
927 
928 typedef struct smb_odir_context {
929 	uint32_t		dc_cookie;
930 	uint16_t		dc_dattr;
931 	char			dc_name[MAXNAMELEN]; /* Real 'Xxxx.yyy.xx' */
932 	char			dc_name83[14];    /* w/ dot 'XXXX    .XX ' */
933 	char			dc_shortname[14]; /* w/ dot 'XXXX.XX' */
934 	smb_attr_t		dc_attr;
935 } smb_odir_context_t;
936 
937 #define	SMB_LOCK_MAGIC 	0x4C4F434B	/* 'LOCK' */
938 
939 typedef struct smb_lock {
940 	uint32_t		l_magic;
941 	kmutex_t		l_mutex;
942 	list_node_t		l_lnd;
943 	kcondvar_t		l_cv;
944 
945 	list_node_t		l_conflict_lnd;
946 	smb_slist_t		l_conflict_list;
947 
948 	smb_session_t		*l_session;
949 	smb_ofile_t		*l_file;
950 	struct smb_request	*l_sr;
951 
952 	uint32_t		l_flags;
953 	uint64_t		l_session_kid;
954 	struct smb_lock		*l_blocked_by; /* Debug info only */
955 
956 	uint16_t		l_pid;
957 	uint16_t		l_uid;
958 	uint32_t		l_type;
959 	uint64_t		l_start;
960 	uint64_t		l_length;
961 	clock_t			l_end_time;
962 } smb_lock_t;
963 
964 #define	SMB_LOCK_FLAG_INDEFINITE	0x0004
965 #define	SMB_LOCK_INDEFINITE_WAIT(lock) \
966 	((lock)->l_flags & SMB_LOCK_FLAG_INDEFINITE)
967 
968 #define	SMB_LOCK_TYPE_READWRITE		101
969 #define	SMB_LOCK_TYPE_READONLY		102
970 
971 typedef struct vardata_block {
972 	uint8_t			tag;
973 	uint16_t		len;
974 	struct uio 		uio;
975 	struct iovec		iovec[MAX_IOVEC];
976 } smb_vdb_t;
977 
978 #define	SMB_RW_MAGIC		0x52445257	/* 'RDRW' */
979 
980 typedef struct smb_rw_param {
981 	uint32_t rw_magic;
982 	smb_vdb_t rw_vdb;
983 	uint64_t rw_offset;
984 	uint32_t rw_last_write;
985 	uint16_t rw_mode;
986 	uint16_t rw_count;
987 	uint16_t rw_mincnt;
988 	uint16_t rw_dsoff;		/* SMB data offset */
989 	uint8_t rw_andx;		/* SMB secondary andx command */
990 } smb_rw_param_t;
991 
992 struct smb_fqi {			/* fs_query_info */
993 	char			*path;
994 	uint16_t		srch_attr;
995 	struct smb_node		*dir_snode;
996 	smb_attr_t		dir_attr;
997 	char			last_comp[MAXNAMELEN];
998 	int			last_comp_was_found;
999 	char			last_comp_od[MAXNAMELEN];
1000 	struct smb_node		*last_snode;
1001 	smb_attr_t		last_attr;
1002 };
1003 
1004 #define	SMB_NULL_FQI_NODES(fqi) \
1005 	(fqi).last_snode = NULL;	\
1006 	(fqi).dir_snode = NULL;
1007 
1008 #define	FQM_DIR_MUST_EXIST	1
1009 #define	FQM_PATH_MUST_EXIST	2
1010 #define	FQM_PATH_MUST_NOT_EXIST 3
1011 
1012 #define	MYF_OPLOCK_MASK		0x000000F0
1013 #define	MYF_OPLOCK_NONE		0x00000000
1014 #define	MYF_EXCLUSIVE_OPLOCK	0x00000010
1015 #define	MYF_BATCH_OPLOCK	0x00000020
1016 #define	MYF_LEVEL_II_OPLOCK	0x00000030
1017 #define	MYF_MUST_BE_DIRECTORY	0x00000100
1018 
1019 #define	MYF_OPLOCK_TYPE(o)	    ((o) & MYF_OPLOCK_MASK)
1020 #define	MYF_OPLOCKS_REQUEST(o)	    (MYF_OPLOCK_TYPE(o) != MYF_OPLOCK_NONE)
1021 #define	MYF_IS_EXCLUSIVE_OPLOCK(o)  (MYF_OPLOCK_TYPE(o) == MYF_EXCLUSIVE_OPLOCK)
1022 #define	MYF_IS_BATCH_OPLOCK(o)	    (MYF_OPLOCK_TYPE(o) == MYF_BATCH_OPLOCK)
1023 #define	MYF_IS_LEVEL_II_OPLOCK(o)   (MYF_OPLOCK_TYPE(o) == MYF_LEVEL_II_OPLOCK)
1024 
1025 #define	OPLOCK_MIN_TIMEOUT	(5 * 1000)
1026 #define	OPLOCK_STD_TIMEOUT	(15 * 1000)
1027 #define	OPLOCK_RETRIES		2
1028 
1029 typedef struct {
1030 	uint32_t severity;
1031 	uint32_t status;
1032 	uint16_t errcls;
1033 	uint16_t errcode;
1034 } smb_error_t;
1035 
1036 /*
1037  * SMB Request State Machine
1038  * -------------------------
1039  *
1040  *                  T4               +------+		T0
1041  *      +--------------------------->| FREE |---------------------------+
1042  *      |                            +------+                           |
1043  * +-----------+                                                        |
1044  * | COMPLETED |                                                        |
1045  * +-----------+
1046  *      ^                                                               |
1047  *      | T15                      +----------+                         v
1048  * +------------+        T6        |          |                 +--------------+
1049  * | CLEANED_UP |<-----------------| CANCELED |                 | INITIALIZING |
1050  * +------------+                  |          |                 +--------------+
1051  *      |    ^                     +----------+                         |
1052  *      |    |                        ^  ^ ^ ^                          |
1053  *      |    |          +-------------+  | | |                          |
1054  *      |    |    T3    |                | | |               T13        | T1
1055  *      |    +-------------------------+ | | +----------------------+   |
1056  *      +----------------------------+ | | |                        |   |
1057  *         T16          |            | | | +-----------+            |   |
1058  *                      |           \/ | | T5          |            |   v
1059  * +-----------------+  |   T12     +--------+         |     T2    +-----------+
1060  * | EVENT_OCCURRED  |------------->| ACTIVE |<--------------------| SUBMITTED |
1061  * +-----------------+  |           +--------+         |           +-----------+
1062  *        ^             |              | ^ |           |
1063  *        |             |           T8 | | |  T7       |
1064  *        | T10      T9 |   +----------+ | +-------+   |  T11
1065  *        |             |   |            +-------+ |   |
1066  *        |             |   |               T14  | |   |
1067  *        |             |   v                    | v   |
1068  *      +----------------------+                +--------------+
1069  *	|     WAITING_EVENT    |                | WAITING_LOCK |
1070  *      +----------------------+                +--------------+
1071  *
1072  *
1073  *
1074  *
1075  *
1076  * Transition T0
1077  *
1078  * This transition occurs when the request is allocated and is still under the
1079  * control of the session thread.
1080  *
1081  * Transition T1
1082  *
1083  * This transition occurs when the session thread dispatches a task to treat the
1084  * request.
1085  *
1086  * Transition T2
1087  *
1088  *
1089  *
1090  * Transition T3
1091  *
1092  * A request completes and smbsr_cleanup is called to release resources
1093  * associated with the request (but not the smb_request_t itself).  This
1094  * includes references on smb_ofile_t, smb_node_t, and other structures.
1095  * CLEANED_UP state exists to detect if we attempt to cleanup a request
1096  * multiple times and to allow us to detect that we are accessing a
1097  * request that has already been cleaned up.
1098  *
1099  * Transition T4
1100  *
1101  *
1102  *
1103  * Transition T5
1104  *
1105  *
1106  *
1107  * Transition T6
1108  *
1109  *
1110  *
1111  * Transition T7
1112  *
1113  *
1114  *
1115  * Transition T8
1116  *
1117  *
1118  *
1119  * Transition T9
1120  *
1121  *
1122  *
1123  * Transition T10
1124  *
1125  *
1126  *
1127  * Transition T11
1128  *
1129  *
1130  *
1131  * Transition T12
1132  *
1133  *
1134  *
1135  * Transition T13
1136  *
1137  *
1138  *
1139  * Transition T14
1140  *
1141  *
1142  *
1143  * Transition T15
1144  *
1145  * Request processing is completed (control returns from smb_dispatch)
1146  *
1147  * Transition T16
1148  *
1149  * Multipart (andx) request was cleaned up with smbsr_cleanup but more "andx"
1150  * sections remain to be processed.
1151  *
1152  */
1153 
1154 #define	SMB_REQ_MAGIC 		0x534D4252	/* 'SMBR' */
1155 
1156 typedef enum smb_req_state {
1157 	SMB_REQ_STATE_FREE = 0,
1158 	SMB_REQ_STATE_INITIALIZING,
1159 	SMB_REQ_STATE_SUBMITTED,
1160 	SMB_REQ_STATE_ACTIVE,
1161 	SMB_REQ_STATE_WAITING_EVENT,
1162 	SMB_REQ_STATE_EVENT_OCCURRED,
1163 	SMB_REQ_STATE_WAITING_LOCK,
1164 	SMB_REQ_STATE_COMPLETED,
1165 	SMB_REQ_STATE_CANCELED,
1166 	SMB_REQ_STATE_CLEANED_UP
1167 } smb_req_state_t;
1168 
1169 typedef struct smb_request {
1170 	uint32_t		sr_magic;
1171 	kmutex_t		sr_mutex;
1172 	list_node_t		sr_session_lnd;
1173 	smb_req_state_t		sr_state;
1174 	boolean_t		sr_keep;
1175 	kmem_cache_t		*sr_cache;
1176 	struct smb_server	*sr_server;
1177 	uint32_t		sr_gmtoff;
1178 	smb_session_t		*session;
1179 	smb_kmod_cfg_t		*sr_cfg;
1180 	smb_notify_change_req_t	sr_ncr;
1181 
1182 	/* Info from session service header */
1183 	uint32_t		sr_req_length; /* Excluding NBT header */
1184 
1185 	/* Request buffer excluding NBT header */
1186 	void			*sr_request_buf;
1187 
1188 	/* Fields for raw writes */
1189 	uint32_t		sr_raw_data_length;
1190 	void			*sr_raw_data_buf;
1191 
1192 	smb_lock_t		*sr_awaiting;
1193 	struct mbuf_chain	command;
1194 	struct mbuf_chain	reply;
1195 	struct mbuf_chain	raw_data;
1196 	smb_malloc_list		request_storage;
1197 	struct smb_xa		*r_xa;
1198 	int			andx_prev_wct;
1199 	int 			cur_reply_offset;
1200 	int			orig_request_hdr;
1201 	unsigned int		reply_seqnum;	/* reply sequence number */
1202 	unsigned char		first_smb_com;	/* command code */
1203 	unsigned char		smb_com;	/* command code */
1204 
1205 	uint8_t			smb_rcls;	/* error code class */
1206 	uint8_t			smb_reh;	/* rsvd (AH DOS INT-24 ERR) */
1207 	uint16_t		smb_err;	/* error code */
1208 	smb_error_t		smb_error;
1209 
1210 	uint8_t			smb_flg;	/* flags */
1211 	uint16_t		smb_flg2;	/* flags */
1212 	uint16_t		smb_pid_high;	/* high part of pid */
1213 	unsigned char		smb_sig[8];	/* signiture */
1214 	uint16_t		smb_tid;	/* tree id #  */
1215 	uint16_t		smb_pid;	/* caller's process id # */
1216 	uint16_t		smb_uid;	/* user id # */
1217 	uint16_t		smb_mid;	/* mutiplex id #  */
1218 	unsigned char		smb_wct;	/* count of parameter words */
1219 	uint16_t		smb_bcc;	/* data byte count */
1220 
1221 	/* Parameters */
1222 	struct mbuf_chain	smb_vwv;	/* variable width value */
1223 
1224 	/* Data */
1225 	struct mbuf_chain	smb_data;
1226 
1227 	uint16_t		smb_fid;	/* not in hdr, but common */
1228 	uint16_t		smb_sid;	/* not in hdr, but common */
1229 
1230 	unsigned char		andx_com;
1231 	uint16_t		andx_off;
1232 
1233 	struct smb_tree		*tid_tree;
1234 	struct smb_ofile	*fid_ofile;
1235 	struct smb_odir		*sid_odir;
1236 	smb_user_t		*uid_user;
1237 
1238 	union {
1239 	    struct tcon {
1240 		char		*path;
1241 		char		*service;
1242 		int		pwdlen;
1243 		char		*password;
1244 		uint16_t	flags;
1245 	    } tcon;
1246 
1247 	    struct open_param {
1248 		struct smb_fqi	fqi;
1249 		uint16_t	omode;
1250 		uint16_t	oflags;
1251 		uint16_t	ofun;
1252 		uint32_t	my_flags;
1253 		uint32_t	timeo;
1254 		uint32_t	dattr;
1255 		timestruc_t	utime;
1256 		uint64_t	dsize;
1257 		uint32_t	desired_access;
1258 		uint32_t	share_access;
1259 		uint32_t	create_options;
1260 		uint32_t	create_disposition;
1261 		uint32_t	ftype, devstate;
1262 		uint32_t	action_taken;
1263 		uint64_t	fileid;
1264 		uint32_t	rootdirfid;
1265 		/* This is only set by NTTransactCreate */
1266 		smb_sd_t	*sd;
1267 	    } open;
1268 
1269 	    struct dirop {
1270 		struct smb_fqi	fqi;
1271 		struct smb_fqi	dst_fqi;
1272 	    } dirop;
1273 
1274 	    smb_rw_param_t	*rw;
1275 	    uint32_t		timestamp;
1276 	} arg;
1277 
1278 	cred_t			*user_cr;
1279 } smb_request_t;
1280 
1281 #define	SMB_READ_PROTOCOL(smb_nh_ptr) \
1282 	LE_IN32(((smb_nethdr_t *)(smb_nh_ptr))->sh_protocol)
1283 
1284 #define	SMB_PROTOCOL_MAGIC_INVALID(rd_sr) \
1285 	(SMB_READ_PROTOCOL((rd_sr)->sr_request_buf) != SMB_PROTOCOL_MAGIC)
1286 
1287 #define	SMB_READ_COMMAND(smb_nh_ptr) \
1288 	(((smb_nethdr_t *)(smb_nh_ptr))->sh_command)
1289 
1290 #define	SMB_IS_WRITERAW(rd_sr) \
1291 	(SMB_READ_COMMAND((rd_sr)->sr_request_buf) == SMB_COM_WRITE_RAW)
1292 
1293 
1294 #define	SR_FLG_OFFSET			9
1295 
1296 #define	MAX_TRANS_NAME	64
1297 
1298 #define	SMB_XA_FLAG_OPEN	0x0001
1299 #define	SMB_XA_FLAG_CLOSE	0x0002
1300 #define	SMB_XA_FLAG_COMPLETE	0x0004
1301 #define	SMB_XA_CLOSED(xa) (!((xa)->xa_flags & SMB_XA_FLAG_OPEN))
1302 
1303 #define	SMB_XA_MAGIC		0x534D4258	/* 'SMBX' */
1304 
1305 typedef struct smb_xa {
1306 	uint32_t		xa_magic;
1307 	kmutex_t		xa_mutex;
1308 	list_node_t		xa_lnd;
1309 
1310 	uint32_t		xa_refcnt;
1311 	uint32_t		xa_flags;
1312 
1313 	struct smb_session	*xa_session;
1314 
1315 	unsigned char		smb_com;	/* which TRANS type */
1316 	unsigned char		smb_flg;	/* flags */
1317 	uint16_t		smb_flg2;	/* flags */
1318 	uint16_t		smb_tid;	/* tree id number */
1319 	uint16_t		smb_pid;	/* caller's process id number */
1320 	uint16_t		smb_uid;	/* user id number */
1321 	uint32_t		smb_func;	/* NT_TRANS function */
1322 
1323 	uint16_t		xa_smb_mid;	/* mutiplex id number */
1324 	uint16_t		xa_smb_fid;	/* TRANS2 secondary */
1325 
1326 	unsigned int		reply_seqnum;	/* reply sequence number */
1327 
1328 	uint32_t	smb_tpscnt;	/* total parameter bytes being sent */
1329 	uint32_t	smb_tdscnt;	/* total data bytes being sent */
1330 	uint32_t	smb_mprcnt;	/* max parameter bytes to return */
1331 	uint32_t	smb_mdrcnt;	/* max data bytes to return */
1332 	uint32_t	smb_msrcnt;	/* max setup words to return */
1333 	uint32_t	smb_flags;	/* additional information: */
1334 				/*  bit 0 - if set, disconnect TID in smb_tid */
1335 				/*  bit 1 - if set, transaction is one way */
1336 				/*  (no final response) */
1337 	int32_t	smb_timeout;	/* number of milliseconds to await completion */
1338 	uint32_t	smb_suwcnt;	/* set up word count */
1339 
1340 
1341 	char			*xa_smb_trans_name;
1342 
1343 	int			req_disp_param;
1344 	int			req_disp_data;
1345 
1346 	struct mbuf_chain	req_setup_mb;
1347 	struct mbuf_chain	req_param_mb;
1348 	struct mbuf_chain	req_data_mb;
1349 
1350 	struct mbuf_chain	rep_setup_mb;
1351 	struct mbuf_chain	rep_param_mb;
1352 	struct mbuf_chain	rep_data_mb;
1353 } smb_xa_t;
1354 
1355 
1356 #define	SDDF_NO_FLAGS			0
1357 #define	SDDF_SUPPRESS_TID		0x0001
1358 #define	SDDF_SUPPRESS_UID		0x0002
1359 
1360 /*
1361  * SMB dispatch return codes.
1362  */
1363 typedef enum {
1364 	SDRC_SUCCESS = 0,
1365 	SDRC_ERROR,
1366 	SDRC_DROP_VC,
1367 	SDRC_NO_REPLY,
1368 	SDRC_NOT_IMPLEMENTED
1369 } smb_sdrc_t;
1370 
1371 #define	VAR_BCC		((short)-1)
1372 
1373 #define	SMB_SERVER_MAGIC	0x53534552	/* 'SSER' */
1374 
1375 typedef struct {
1376 	kstat_named_t	state;
1377 	kstat_named_t	open_files;
1378 	kstat_named_t	open_trees;
1379 	kstat_named_t	open_users;
1380 } smb_server_stats_t;
1381 
1382 typedef struct {
1383 	kthread_t		*ld_kth;
1384 	kt_did_t		ld_ktdid;
1385 	struct sonode		*ld_so;
1386 	struct sockaddr_in	ld_sin;
1387 	smb_session_list_t	ld_session_list;
1388 } smb_listener_daemon_t;
1389 
1390 typedef enum smb_server_state {
1391 	SMB_SERVER_STATE_CREATED = 0,
1392 	SMB_SERVER_STATE_CONFIGURED,
1393 	SMB_SERVER_STATE_RUNNING,
1394 	SMB_SERVER_STATE_DELETING
1395 } smb_server_state_t;
1396 
1397 typedef struct smb_server {
1398 	uint32_t		sv_magic;
1399 	kcondvar_t		sv_cv;
1400 	kmutex_t		sv_mutex;
1401 	list_node_t		sv_lnd;
1402 	smb_server_state_t	sv_state;
1403 	uint32_t		sv_refcnt;
1404 	proc_t			*sv_proc;
1405 	zoneid_t		sv_zid;
1406 	smb_listener_daemon_t	sv_nbt_daemon;
1407 	smb_listener_daemon_t	sv_tcp_daemon;
1408 	krwlock_t		sv_cfg_lock;
1409 	smb_kmod_cfg_t		sv_cfg;
1410 	smb_session_t		*sv_session;
1411 
1412 	kstat_t			*sv_ksp;
1413 	kmutex_t		sv_ksp_mutex;
1414 	char			sv_ksp_name[KSTAT_STRLEN];
1415 	smb_server_stats_t	sv_ks_data;
1416 
1417 	door_handle_t		sv_lmshrd;
1418 
1419 	uint32_t		si_gmtoff;
1420 
1421 	smb_thread_t		si_thread_timers;
1422 
1423 	taskq_t			*sv_thread_pool;
1424 
1425 	kmem_cache_t		*si_cache_vfs;
1426 	kmem_cache_t		*si_cache_request;
1427 	kmem_cache_t		*si_cache_session;
1428 	kmem_cache_t		*si_cache_user;
1429 	kmem_cache_t		*si_cache_tree;
1430 	kmem_cache_t		*si_cache_ofile;
1431 	kmem_cache_t		*si_cache_odir;
1432 	kmem_cache_t		*si_cache_node;
1433 
1434 	volatile uint32_t	sv_open_trees;
1435 	volatile uint32_t	sv_open_files;
1436 	volatile uint32_t	sv_open_users;
1437 
1438 	smb_node_t		*si_root_smb_node;
1439 	smb_llist_t		sv_vfs_list;
1440 } smb_server_t;
1441 
1442 #define	SMB_INFO_NETBIOS_SESSION_SVC_RUNNING	0x0001
1443 #define	SMB_INFO_NETBIOS_SESSION_SVC_FAILED	0x0002
1444 #define	SMB_INFO_USER_LEVEL_SECURITY		0x40000000
1445 #define	SMB_INFO_ENCRYPT_PASSWORDS		0x80000000
1446 
1447 #define	SMB_NEW_KID()	atomic_inc_64_nv(&smb_kids)
1448 #define	SMB_UNIQ_FID()	atomic_inc_32_nv(&smb_fids)
1449 
1450 /*
1451  * This is to be used by Trans2SetFileInfo
1452  * and Trans2SetPathInfo
1453  */
1454 typedef struct smb_trans2_setinfo {
1455 	uint16_t level;
1456 	struct smb_xa *ts_xa;
1457 	struct smb_node *node;
1458 	char *path;
1459 	char name[MAXNAMELEN];
1460 } smb_trans2_setinfo_t;
1461 
1462 #define	SMB_IS_STREAM(node) ((node)->unnamed_stream_node)
1463 
1464 #ifdef DEBUG
1465 extern uint_t smb_tsd_key;
1466 #endif
1467 
1468 typedef struct smb_tsd {
1469 	void (*proc)();
1470 	void *arg;
1471 	char name[100];
1472 } smb_tsd_t;
1473 
1474 #define	SMB_INVALID_AMASK		-1
1475 #define	SMB_INVALID_SHAREMODE		-1
1476 #define	SMB_INVALID_CRDISPOSITION	-1
1477 
1478 typedef struct smb_dispatch_table {
1479 	smb_sdrc_t		(*sdt_pre_op)(smb_request_t *);
1480 	smb_sdrc_t		(*sdt_function)(smb_request_t *);
1481 	void			(*sdt_post_op)(smb_request_t *);
1482 	char			sdt_dialect;
1483 	unsigned char		sdt_flags;
1484 	krw_t			sdt_slock_mode;
1485 	kstat_named_t		sdt_dispatch_stats; /* invocations */
1486 } smb_dispatch_table_t;
1487 
1488 /*
1489  * Discretionary Access Control List (DACL)
1490  *
1491  * A Discretionary Access Control List (DACL), often abbreviated to
1492  * ACL, is a list of access controls which either allow or deny access
1493  * for users or groups to a resource. There is a list header followed
1494  * by a list of access control entries (ACE). Each ACE specifies the
1495  * access allowed or denied to a single user or group (identified by
1496  * a SID).
1497  *
1498  * There is another access control list object called a System Access
1499  * Control List (SACL), which is used to control auditing, but no
1500  * support is provideed for SACLs at this time.
1501  *
1502  * ACL header format:
1503  *
1504  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1505  *    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
1506  *   +-------------------------------+---------------+---------------+
1507  *   |            AclSize            |      Sbz1     |  AclRevision  |
1508  *   +-------------------------------+---------------+---------------+
1509  *   |              Sbz2             |           AceCount            |
1510  *   +-------------------------------+-------------------------------+
1511  *
1512  * AclRevision specifies the revision level of the ACL. This value should
1513  * be ACL_REVISION, unless the ACL contains an object-specific ACE, in which
1514  * case this value must be ACL_REVISION_DS. All ACEs in an ACL must be at the
1515  * same revision level.
1516  *
1517  * ACE header format:
1518  *
1519  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1520  *    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
1521  *   +---------------+-------+-------+---------------+---------------+
1522  *   |            AceSize            |    AceFlags   |     AceType   |
1523  *   +---------------+-------+-------+---------------+---------------+
1524  *
1525  * Access mask format:
1526  *
1527  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1528  *    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
1529  *   +---------------+---------------+-------------------------------+
1530  *   |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
1531  *   |R|W|E|A|     |S|               |                               |
1532  *   +-+-------------+---------------+-------------------------------+
1533  *
1534  *   typedef struct ACCESS_MASK {
1535  *       WORD SpecificRights;
1536  *       BYTE StandardRights;
1537  *       BYTE AccessSystemAcl : 1;
1538  *       BYTE Reserved : 3;
1539  *       BYTE GenericAll : 1;
1540  *       BYTE GenericExecute : 1;
1541  *       BYTE GenericWrite : 1;
1542  *       BYTE GenericRead : 1;
1543  *   } ACCESS_MASK;
1544  *
1545  */
1546 
1547 #define	ACL_REVISION1			1
1548 #define	ACL_REVISION2			2
1549 #define	MIN_ACL_REVISION2		ACL_REVISION2
1550 #define	ACL_REVISION3			3
1551 #define	ACL_REVISION4			4
1552 #define	MAX_ACL_REVISION		ACL_REVISION4
1553 
1554 /*
1555  * Current ACE and ACL revision Levels
1556  */
1557 #define	ACE_REVISION			1
1558 #define	ACL_REVISION			ACL_REVISION2
1559 #define	ACL_REVISION_DS			ACL_REVISION4
1560 
1561 
1562 #define	ACCESS_ALLOWED_ACE_TYPE		0
1563 #define	ACCESS_DENIED_ACE_TYPE		1
1564 #define	SYSTEM_AUDIT_ACE_TYPE		2
1565 #define	SYSTEM_ALARM_ACE_TYPE		3
1566 
1567 /*
1568  *  se_flags
1569  * ----------
1570  * Specifies a set of ACE type-specific control flags. This member can be a
1571  * combination of the following values.
1572  *
1573  * CONTAINER_INHERIT_ACE: Child objects that are containers, such as
1574  *		directories, inherit the ACE as an effective ACE. The inherited
1575  *		ACE is inheritable unless the NO_PROPAGATE_INHERIT_ACE bit flag
1576  *		is also set.
1577  *
1578  * INHERIT_ONLY_ACE: Indicates an inherit-only ACE which does not control
1579  *		access to the object to which it is attached.
1580  *		If this flag is not set,
1581  *		the ACE is an effective ACE which controls access to the object
1582  *		to which it is attached.
1583  * 		Both effective and inherit-only ACEs can be inherited
1584  *		depending on the state of the other inheritance flags.
1585  *
1586  * INHERITED_ACE: Windows 2000/XP: Indicates that the ACE was inherited.
1587  *		The system sets this bit when it propagates an
1588  *		inherited ACE to a child object.
1589  *
1590  * NO_PROPAGATE_INHERIT_ACE: If the ACE is inherited by a child object, the
1591  *		system clears the OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE
1592  *		flags in the inherited ACE.
1593  *		This prevents the ACE from being inherited by
1594  *		subsequent generations of objects.
1595  *
1596  * OBJECT_INHERIT_ACE: Noncontainer child objects inherit the ACE as an
1597  *		effective ACE.  For child objects that are containers,
1598  *		the ACE is inherited as an inherit-only ACE unless the
1599  *		NO_PROPAGATE_INHERIT_ACE bit flag is also set.
1600  */
1601 #define	OBJECT_INHERIT_ACE		0x01
1602 #define	CONTAINER_INHERIT_ACE		0x02
1603 #define	NO_PROPOGATE_INHERIT_ACE	0x04
1604 #define	INHERIT_ONLY_ACE		0x08
1605 #define	INHERITED_ACE			0x10
1606 #define	INHERIT_MASK_ACE		0x1F
1607 
1608 
1609 /*
1610  * These flags are only used in system audit or alarm ACEs to
1611  * indicate when an audit message should be generated, i.e.
1612  * on successful access or on unsuccessful access.
1613  */
1614 #define	SUCCESSFUL_ACCESS_ACE_FLAG	0x40
1615 #define	FAILED_ACCESS_ACE_FLAG		0x80
1616 
1617 /*
1618  * se_bsize is the size, in bytes, of ACE as it appears on the wire.
1619  * se_sln is used to sort the ACL when it's required.
1620  */
1621 typedef struct smb_acehdr {
1622 	uint8_t		se_type;
1623 	uint8_t		se_flags;
1624 	uint16_t	se_bsize;
1625 } smb_acehdr_t;
1626 
1627 typedef struct smb_ace {
1628 	smb_acehdr_t	se_hdr;
1629 	uint32_t	se_mask;
1630 	list_node_t	se_sln;
1631 	nt_sid_t	*se_sid;
1632 } smb_ace_t;
1633 
1634 /*
1635  * sl_bsize is the size of ACL in bytes as it appears on the wire.
1636  */
1637 typedef struct smb_acl {
1638 	uint8_t		sl_revision;
1639 	uint16_t	sl_bsize;
1640 	uint16_t	sl_acecnt;
1641 	smb_ace_t	*sl_aces;
1642 	list_t		sl_sorted;
1643 } smb_acl_t;
1644 
1645 /*
1646  * ACE/ACL header size, in byte, as it appears on the wire
1647  */
1648 #define	SMB_ACE_HDRSIZE		4
1649 #define	SMB_ACL_HDRSIZE		8
1650 
1651 /*
1652  * Security Descriptor (SD)
1653  *
1654  * Security descriptors provide protection for objects, for example
1655  * files and directories. It identifies the owner and primary group
1656  * (SIDs) and contains an access control list. When a user tries to
1657  * access an object his SID is compared to the permissions in the
1658  * DACL to determine if access should be allowed or denied. Note that
1659  * this is a simplification because there are other factors, such as
1660  * default behavior and privileges to be taken into account (see also
1661  * access tokens).
1662  *
1663  * The boolean flags have the following meanings when set:
1664  *
1665  * SE_OWNER_DEFAULTED indicates that the SID pointed to by the Owner
1666  * field was provided by a defaulting mechanism rather than explicitly
1667  * provided by the original provider of the security descriptor. This
1668  * may affect the treatment of the SID with respect to inheritance of
1669  * an owner.
1670  *
1671  * SE_GROUP_DEFAULTED indicates that the SID in the Group field was
1672  * provided by a defaulting mechanism rather than explicitly provided
1673  * by the original provider of the security descriptor.  This may
1674  * affect the treatment of the SID with respect to inheritance of a
1675  * primary group.
1676  *
1677  * SE_DACL_PRESENT indicates that the security descriptor contains a
1678  * discretionary ACL. If this flag is set and the Dacl field of the
1679  * SECURITY_DESCRIPTOR is null, then a null ACL is explicitly being
1680  * specified.
1681  *
1682  * SE_DACL_DEFAULTED indicates that the ACL pointed to by the Dacl
1683  * field was provided by a defaulting mechanism rather than explicitly
1684  * provided by the original provider of the security descriptor. This
1685  * may affect the treatment of the ACL with respect to inheritance of
1686  * an ACL. This flag is ignored if the DaclPresent flag is not set.
1687  *
1688  * SE_SACL_PRESENT indicates that the security descriptor contains a
1689  * system ACL pointed to by the Sacl field. If this flag is set and
1690  * the Sacl field of the SECURITY_DESCRIPTOR is null, then an empty
1691  * (but present) ACL is being specified.
1692  *
1693  * SE_SACL_DEFAULTED indicates that the ACL pointed to by the Sacl
1694  * field was provided by a defaulting mechanism rather than explicitly
1695  * provided by the original provider of the security descriptor. This
1696  * may affect the treatment of the ACL with respect to inheritance of
1697  * an ACL. This flag is ignored if the SaclPresent flag is not set.
1698  *
1699  * SE_DACL_PROTECTED Prevents ACEs set on the DACL of the parent container
1700  * (and any objects above the parent container in the directory hierarchy)
1701  * from being applied to the object's DACL.
1702  *
1703  * SE_SACL_PROTECTED Prevents ACEs set on the SACL of the parent container
1704  * (and any objects above the parent container in the directory hierarchy)
1705  * from being applied to the object's SACL.
1706  *
1707  * Note that the SE_DACL_PRESENT flag needs to be present to set
1708  * SE_DACL_PROTECTED and SE_SACL_PRESENT needs to be present to set
1709  * SE_SACL_PROTECTED.
1710  *
1711  * SE_SELF_RELATIVE indicates that the security descriptor is in self-
1712  * relative form. In this form, all fields of the security descriptor
1713  * are contiguous in memory and all pointer fields are expressed as
1714  * offsets from the beginning of the security descriptor.
1715  *
1716  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1717  *    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
1718  *   +---------------------------------------------------------------+
1719  *   |            Control            |Reserved1 (SBZ)|   Revision    |
1720  *   +---------------------------------------------------------------+
1721  *   |                            Owner                              |
1722  *   +---------------------------------------------------------------+
1723  *   |                            Group                              |
1724  *   +---------------------------------------------------------------+
1725  *   |                            Sacl                               |
1726  *   +---------------------------------------------------------------+
1727  *   |                            Dacl                               |
1728  *   +---------------------------------------------------------------+
1729  *
1730  */
1731 
1732 #define	SMB_OWNER_SECINFO	0x0001
1733 #define	SMB_GROUP_SECINFO	0x0002
1734 #define	SMB_DACL_SECINFO	0x0004
1735 #define	SMB_SACL_SECINFO	0x0008
1736 #define	SMB_ALL_SECINFO		0x000F
1737 #define	SMB_ACL_SECINFO		(SMB_DACL_SECINFO | SMB_SACL_SECINFO)
1738 
1739 #define	SECURITY_DESCRIPTOR_REVISION	1
1740 
1741 
1742 #define	SE_OWNER_DEFAULTED		0x0001
1743 #define	SE_GROUP_DEFAULTED		0x0002
1744 #define	SE_DACL_PRESENT			0x0004
1745 #define	SE_DACL_DEFAULTED		0x0008
1746 #define	SE_SACL_PRESENT			0x0010
1747 #define	SE_SACL_DEFAULTED		0x0020
1748 #define	SE_DACL_AUTO_INHERIT_REQ	0x0100
1749 #define	SE_SACL_AUTO_INHERIT_REQ	0x0200
1750 #define	SE_DACL_AUTO_INHERITED		0x0400
1751 #define	SE_SACL_AUTO_INHERITED		0x0800
1752 #define	SE_DACL_PROTECTED		0x1000
1753 #define	SE_SACL_PROTECTED		0x2000
1754 #define	SE_SELF_RELATIVE		0x8000
1755 
1756 #define	SE_DACL_INHERITANCE_MASK	0x1500
1757 #define	SE_SACL_INHERITANCE_MASK	0x2A00
1758 
1759 /*
1760  * Security descriptor structures:
1761  *
1762  * smb_sd_t     SD in SMB pointer form
1763  * smb_fssd_t   SD in filesystem form
1764  *
1765  * Filesystems (e.g. ZFS/UFS) don't have something equivalent
1766  * to SD. The items comprising a SMB SD are kept separately in
1767  * filesystem. smb_fssd_t is introduced as a helper to provide
1768  * the required abstraction for CIFS code.
1769  */
1770 
1771 struct smb_sd {
1772 	uint8_t		sd_revision;
1773 	uint16_t	sd_control;
1774 	nt_sid_t 	*sd_owner;	/* SID file owner */
1775 	nt_sid_t 	*sd_group;	/* SID group (for POSIX) */
1776 	smb_acl_t 	*sd_sacl;	/* ACL System (audits) */
1777 	smb_acl_t 	*sd_dacl;	/* ACL Discretionary (perm) */
1778 };
1779 
1780 /*
1781  * SD header size as it appears on the wire
1782  */
1783 #define	SMB_SD_HDRSIZE	20
1784 
1785 /*
1786  * values for smb_fssd.sd_flags
1787  */
1788 #define	SMB_FSSD_FLAGS_DIR	0x01
1789 
1790 typedef struct smb_fssd {
1791 	uint32_t	sd_secinfo;
1792 	uint32_t	sd_flags;
1793 	uid_t		sd_uid;
1794 	gid_t		sd_gid;
1795 	acl_t		*sd_zdacl;
1796 	acl_t		*sd_zsacl;
1797 } smb_fssd_t;
1798 
1799 #ifdef	__cplusplus
1800 }
1801 #endif
1802 
1803 #endif /* _SMBSRV_SMB_KTYPES_H */
1804