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