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