xref: /titanic_52/usr/src/uts/common/smbsrv/ntifs.h (revision d25a0be92761da6c8943a1cee6a5e689eca1bf64)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SMBSRV_NTIFS_H
27 #define	_SMBSRV_NTIFS_H
28 
29 /*
30  * This file provides definitions compatible with the NT Installable
31  * File System (IFS) interface. This header file also defines the Security
32  * Descriptor module from Windows.
33  */
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/acl.h>
40 #include <sys/list.h>
41 #include <smbsrv/smb_sid.h>
42 
43 /*
44  * The Volume and Directory bits are for SMB rather than NT.
45  * NT has an explicit Normal bit; this bit is implied in SMB
46  * when the Hidden, System and Directory bits are not set.
47  *
48  * File attributes and creation flags share the same 32-bit
49  * space.
50  */
51 #define	FILE_ATTRIBUTE_READONLY			0x00000001
52 #define	FILE_ATTRIBUTE_HIDDEN			0x00000002
53 #define	FILE_ATTRIBUTE_SYSTEM			0x00000004
54 #define	FILE_ATTRIBUTE_VOLUME			0x00000008
55 #define	FILE_ATTRIBUTE_DIRECTORY		0x00000010
56 #define	FILE_ATTRIBUTE_ARCHIVE			0x00000020
57 #define	FILE_ATTRIBUTE_DEVICE			0x00000040
58 #define	FILE_ATTRIBUTE_NORMAL			0x00000080
59 #define	FILE_ATTRIBUTE_TEMPORARY		0x00000100
60 #define	FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
61 #define	FILE_ATTRIBUTE_REPARSE_POINT		0x00000400
62 #define	FILE_ATTRIBUTE_COMPRESSED		0x00000800
63 #define	FILE_ATTRIBUTE_OFFLINE			0x00001000
64 #define	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000
65 #define	FILE_ATTRIBUTE_ENCRYPTED		0x00004000
66 #define	FILE_ATTRIBUTE_VIRTUAL			0x00010000
67 #define	FILE_FLAG_OPEN_NO_RECALL		0x00100000
68 #define	FILE_FLAG_OPEN_REPARSE_POINT		0x00200000
69 #define	FILE_FLAG_POSIX_SEMANTICS		0x01000000
70 #define	FILE_FLAG_BACKUP_SEMANTICS		0x02000000
71 #define	FILE_FLAG_DELETE_ON_CLOSE		0x04000000
72 #define	FILE_FLAG_SEQUENTIAL_SCAN		0x08000000
73 #define	FILE_FLAG_RANDOM_ACCESS			0x10000000
74 #define	FILE_FLAG_NO_BUFFERING			0x20000000
75 #define	FILE_FLAG_OVERLAPPED			0x40000000
76 #define	FILE_FLAG_WRITE_THROUGH			0x80000000
77 
78 #define	FILE_ATTRIBUTE_VALID_FLAGS		0x00001fb7
79 #define	FILE_ATTRIBUTE_VALID_SET_FLAGS		0x00001fa7
80 #define	FILE_ATTRIBUTE_MASK			0x00003FFF
81 
82 /*
83  * The create/open option flags: used in NtCreateAndx and NtTransactCreate
84  * SMB requests.
85  *
86  * The CreateOptions specify the options to be applied when creating or
87  * opening the file, as a compatible combination of the following flags:
88  *
89  * FILE_DIRECTORY_FILE
90  *	The file being created or opened is a directory file. With this
91  *	flag, the Disposition parameter must be set to one of FILE_CREATE,
92  *	FILE_OPEN, or FILE_OPEN_IF. With this flag, other compatible
93  *	CreateOptions flags include only the following:
94  *			FILE_SYNCHRONOUS_IO_ALERT
95  *			FILE_SYNCHRONOUS_IO_NONALERT
96  *			FILE_WRITE_THROUGH
97  *			FILE_OPEN_FOR_BACKUP_INTENT
98  *			FILE_OPEN_BY_FILE_ID
99  *
100  * FILE_NON_DIRECTORY_FILE
101  *	The file being opened must not be a directory file or this call
102  *	will fail. The file object being opened can represent a data file,
103  *	a logical, virtual, or physical device, or a volume.
104  *
105  * FILE_WRITE_THROUGH
106  *	System services, FSDs, and drivers that write data to the file must
107  *	actually transfer the data into the file before any requested write
108  *	operation is considered complete. This flag is automatically set if
109  *	the CreateOptions flag FILE_NO_INTERMEDIATE _BUFFERING is set.
110  *
111  * FILE_SEQUENTIAL_ONLY
112  *	All accesses to the file will be sequential.
113  *
114  * FILE_RANDOM_ACCESS
115  *	Accesses to the file can be random, so no sequential read-ahead
116  *	operations should be performed on the file by FSDs or the system.
117  *	FILE_NO_INTERMEDIATE _BUFFERING	The file cannot be cached or
118  *	buffered in a driver's internal buffers. This flag is incompatible
119  *	with the DesiredAccess FILE_APPEND_DATA flag.
120  *
121  * FILE_SYNCHRONOUS_IO_ALERT
122  *	All operations on the file are performed synchronously. Any wait
123  *	on behalf of the caller is subject to premature termination from
124  *	alerts. This flag also causes the I/O system to maintain the file
125  *	position context. If this flag is set, the DesiredAccess
126  *	SYNCHRONIZE flag also must be set.
127  *
128  * FILE_SYNCHRONOUS_IO _NONALERT
129  *	All operations on the file are performed synchronously. Waits in
130  *	the system to synchronize I/O queuing and completion are not subject
131  *	to alerts. This flag also causes the I/O system to maintain the file
132  *	position context. If this flag is set, the DesiredAccess SYNCHRONIZE
133  *	flag also must be set.
134  *
135  * FILE_CREATE_TREE _CONNECTION
136  *	Create a tree connection for this file in order to open it over the
137  *	network. This flag is irrelevant to device and intermediate drivers.
138  *
139  * FILE_COMPLETE_IF_OPLOCKED
140  *	Complete this operation immediately with an alternate success code
141  *	if the target file is oplocked, rather than blocking the caller's
142  *	thread. If the file is oplocked, another caller already has access
143  *	to the file over the network. This flag is irrelevant to device and
144  *	intermediate drivers.
145  *
146  * FILE_NO_EA_KNOWLEDGE
147  *	If the extended attributes on an existing file being opened indicate
148  *	that the caller must understand EAs to properly interpret the file,
149  *	fail this request because the caller does not understand how to deal
150  *	with EAs. Device and intermediate drivers can ignore this flag.
151  *
152  * FILE_DELETE_ON_CLOSE
153  *	Delete the file when the last reference to it is passed to close.
154  *
155  * FILE_OPEN_BY_FILE_ID
156  *	The file name contains the name of a device and a 64-bit ID to
157  *	be used to open the file. This flag is irrelevant to device and
158  *	intermediate drivers.
159  *
160  * FILE_OPEN_FOR_BACKUP _INTENT
161  *	The file is being opened for backup intent, hence, the system should
162  *	check for certain access rights and grant the caller the appropriate
163  *	accesses to the file before checking the input DesiredAccess against
164  *	the file's security descriptor. This flag is irrelevant to device
165  *	and intermediate drivers.
166  */
167 #define	FILE_DIRECTORY_FILE			0x00000001
168 #define	FILE_WRITE_THROUGH			0x00000002
169 #define	FILE_SEQUENTIAL_ONLY			0x00000004
170 #define	FILE_NO_INTERMEDIATE_BUFFERING		0x00000008
171 
172 #define	FILE_SYNCHRONOUS_IO_ALERT		0x00000010
173 #define	FILE_SYNCHRONOUS_IO_NONALERT		0x00000020
174 #define	FILE_NON_DIRECTORY_FILE			0x00000040
175 #define	FILE_CREATE_TREE_CONNECTION		0x00000080
176 
177 #define	FILE_COMPLETE_IF_OPLOCKED		0x00000100
178 #define	FILE_NO_EA_KNOWLEDGE			0x00000200
179 /* UNUSED					0x00000400 */
180 #define	FILE_RANDOM_ACCESS			0x00000800
181 
182 #define	FILE_DELETE_ON_CLOSE			0x00001000
183 #define	FILE_OPEN_BY_FILE_ID			0x00002000
184 #define	FILE_OPEN_FOR_BACKUP_INTENT		0x00004000
185 #define	FILE_NO_COMPRESSION			0x00008000
186 
187 #define	FILE_RESERVE_OPFILTER			0x00100000
188 #define	FILE_RESERVED0				0x00200000
189 #define	FILE_RESERVED1				0x00400000
190 #define	FILE_RESERVED2				0x00800000
191 
192 #define	FILE_VALID_OPTION_FLAGS			0x007fffff
193 #define	FILE_VALID_PIPE_OPTION_FLAGS		0x00000032
194 #define	FILE_VALID_MAILSLOT_OPTION_FLAGS	0x00000032
195 #define	FILE_VALID_SET_FLAGS			0x00000036
196 
197 /*
198  * Define the file information class values used by the NT DDK and HAL.
199  */
200 typedef enum _FILE_INFORMATION_CLASS {
201 	FileDirectoryInformation		= 1,
202 	FileFullDirectoryInformation,		/* 2 */
203 	FileBothDirectoryInformation,		/* 3 */
204 	FileBasicInformation,			/* 4 */
205 	FileStandardInformation,		/* 5 */
206 	FileInternalInformation,		/* 6 */
207 	FileEaInformation,			/* 7 */
208 	FileAccessInformation,			/* 8 */
209 	FileNameInformation,			/* 9 */
210 	FileRenameInformation,			/* 10 */
211 	FileLinkInformation,			/* 11 */
212 	FileNamesInformation,			/* 12 */
213 	FileDispositionInformation,		/* 13 */
214 	FilePositionInformation,		/* 14 */
215 	FileFullEaInformation,			/* 15 */
216 	FileModeInformation,			/* 16 */
217 	FileAlignmentInformation,		/* 17 */
218 	FileAllInformation,			/* 18 */
219 	FileAllocationInformation,		/* 19 */
220 	FileEndOfFileInformation,		/* 20 */
221 	FileAlternateNameInformation,		/* 21 */
222 	FileStreamInformation,			/* 22 */
223 	FilePipeInformation,			/* 23 */
224 	FilePipeLocalInformation,		/* 24 */
225 	FilePipeRemoteInformation,		/* 25 */
226 	FileMailslotQueryInformation,		/* 26 */
227 	FileMailslotSetInformation,		/* 27 */
228 	FileCompressionInformation,		/* 28 */
229 	FileObjectIdInformation,		/* 29 */
230 	FileCompletionInformation,		/* 30 */
231 	FileMoveClusterInformation,		/* 31 */
232 	FileQuotaInformation,			/* 32 */
233 	FileReparsePointInformation,		/* 33 */
234 	FileNetworkOpenInformation,		/* 34 */
235 	FileAttributeTagInformation,		/* 35 */
236 	FileTrackingInformation,		/* 36 */
237 	FileIdBothDirectoryInformation,		/* 37 */
238 	FileIdFullDirectoryInformation,		/* 38 */
239 	FileValidDataLengthInformation,		/* 39 */
240 	FileShortNameInformation,		/* 40 */
241 	FileInformationReserved41,		/* 41 */
242 	FileInformationReserved42,		/* 42 */
243 	FileInformationReserved43,		/* 43 */
244 	FileSfioReserveInformation,		/* 44 */
245 	FileSfioVolumeInformation,		/* 45 */
246 	FileHardLinkInformation,		/* 46 */
247 	FileInformationReserved47,		/* 47 */
248 	FileNormalizedNameInformation,		/* 48 */
249 	FileInformationReserved49,		/* 49 */
250 	FileIdGlobalTxDirectoryInformation,	/* 50 */
251 	FileInformationReserved51,		/* 51 */
252 	FileInformationReserved52,		/* 52 */
253 	FileInformationReserved53,		/* 53 */
254 	FileStandardLinkInformation,		/* 54 */
255 	FileMaximumInformation
256 } FILE_INFORMATION_CLASS;
257 
258 /*
259  * Discretionary Access Control List (DACL)
260  *
261  * A Discretionary Access Control List (DACL), often abbreviated to
262  * ACL, is a list of access controls which either allow or deny access
263  * for users or groups to a resource. There is a list header followed
264  * by a list of access control entries (ACE). Each ACE specifies the
265  * access allowed or denied to a single user or group (identified by
266  * a SID).
267  *
268  * There is another access control list object called a System Access
269  * Control List (SACL), which is used to control auditing, but no
270  * support is provideed for SACLs at this time.
271  *
272  * ACL header format:
273  *
274  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
275  *    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
276  *   +-------------------------------+---------------+---------------+
277  *   |            AclSize            |      Sbz1     |  AclRevision  |
278  *   +-------------------------------+---------------+---------------+
279  *   |              Sbz2             |           AceCount            |
280  *   +-------------------------------+-------------------------------+
281  *
282  * AclRevision specifies the revision level of the ACL. This value should
283  * be ACL_REVISION, unless the ACL contains an object-specific ACE, in which
284  * case this value must be ACL_REVISION_DS. All ACEs in an ACL must be at the
285  * same revision level.
286  *
287  * ACE header format:
288  *
289  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
290  *    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
291  *   +---------------+-------+-------+---------------+---------------+
292  *   |            AceSize            |    AceFlags   |     AceType   |
293  *   +---------------+-------+-------+---------------+---------------+
294  *
295  * Access mask format:
296  *
297  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
298  *    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
299  *   +---------------+---------------+-------------------------------+
300  *   |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
301  *   |R|W|E|A|     |S|               |                               |
302  *   +-+-------------+---------------+-------------------------------+
303  *
304  *   typedef struct ACCESS_MASK {
305  *       WORD SpecificRights;
306  *       BYTE StandardRights;
307  *       BYTE AccessSystemAcl : 1;
308  *       BYTE Reserved : 3;
309  *       BYTE GenericAll : 1;
310  *       BYTE GenericExecute : 1;
311  *       BYTE GenericWrite : 1;
312  *       BYTE GenericRead : 1;
313  *   } ACCESS_MASK;
314  *
315  */
316 
317 #define	ACL_REVISION1			1
318 #define	ACL_REVISION2			2
319 #define	MIN_ACL_REVISION2		ACL_REVISION2
320 #define	ACL_REVISION3			3
321 #define	ACL_REVISION4			4
322 #define	MAX_ACL_REVISION		ACL_REVISION4
323 
324 /*
325  * Current ACE and ACL revision Levels
326  */
327 #define	ACE_REVISION			1
328 #define	ACL_REVISION			ACL_REVISION2
329 #define	ACL_REVISION_DS			ACL_REVISION4
330 
331 
332 #define	ACCESS_ALLOWED_ACE_TYPE		0
333 #define	ACCESS_DENIED_ACE_TYPE		1
334 #define	SYSTEM_AUDIT_ACE_TYPE		2
335 #define	SYSTEM_ALARM_ACE_TYPE		3
336 
337 /*
338  *  se_flags
339  * ----------
340  * Specifies a set of ACE type-specific control flags. This member can be a
341  * combination of the following values.
342  *
343  * CONTAINER_INHERIT_ACE: Child objects that are containers, such as
344  *		directories, inherit the ACE as an effective ACE. The inherited
345  *		ACE is inheritable unless the NO_PROPAGATE_INHERIT_ACE bit flag
346  *		is also set.
347  *
348  * INHERIT_ONLY_ACE: Indicates an inherit-only ACE which does not control
349  *		access to the object to which it is attached.
350  *		If this flag is not set,
351  *		the ACE is an effective ACE which controls access to the object
352  *		to which it is attached.
353  * 		Both effective and inherit-only ACEs can be inherited
354  *		depending on the state of the other inheritance flags.
355  *
356  * INHERITED_ACE: Windows 2000/XP: Indicates that the ACE was inherited.
357  *		The system sets this bit when it propagates an
358  *		inherited ACE to a child object.
359  *
360  * NO_PROPAGATE_INHERIT_ACE: If the ACE is inherited by a child object, the
361  *		system clears the OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE
362  *		flags in the inherited ACE.
363  *		This prevents the ACE from being inherited by
364  *		subsequent generations of objects.
365  *
366  * OBJECT_INHERIT_ACE: Noncontainer child objects inherit the ACE as an
367  *		effective ACE.  For child objects that are containers,
368  *		the ACE is inherited as an inherit-only ACE unless the
369  *		NO_PROPAGATE_INHERIT_ACE bit flag is also set.
370  */
371 #define	OBJECT_INHERIT_ACE		0x01
372 #define	CONTAINER_INHERIT_ACE		0x02
373 #define	NO_PROPOGATE_INHERIT_ACE	0x04
374 #define	INHERIT_ONLY_ACE		0x08
375 #define	INHERITED_ACE			0x10
376 #define	INHERIT_MASK_ACE		0x1F
377 
378 
379 /*
380  * These flags are only used in system audit or alarm ACEs to
381  * indicate when an audit message should be generated, i.e.
382  * on successful access or on unsuccessful access.
383  */
384 #define	SUCCESSFUL_ACCESS_ACE_FLAG	0x40
385 #define	FAILED_ACCESS_ACE_FLAG		0x80
386 
387 /*
388  * se_bsize is the size, in bytes, of ACE as it appears on the wire.
389  * se_sln is used to sort the ACL when it's required.
390  */
391 typedef struct smb_acehdr {
392 	uint8_t		se_type;
393 	uint8_t		se_flags;
394 	uint16_t	se_bsize;
395 } smb_acehdr_t;
396 
397 typedef struct smb_ace {
398 	smb_acehdr_t	se_hdr;
399 	uint32_t	se_mask;
400 	list_node_t	se_sln;
401 	smb_sid_t	*se_sid;
402 } smb_ace_t;
403 
404 /*
405  * sl_bsize is the size of ACL in bytes as it appears on the wire.
406  */
407 typedef struct smb_acl {
408 	uint8_t		sl_revision;
409 	uint16_t	sl_bsize;
410 	uint16_t	sl_acecnt;
411 	smb_ace_t	*sl_aces;
412 	list_t		sl_sorted;
413 } smb_acl_t;
414 
415 /*
416  * ACE/ACL header size, in byte, as it appears on the wire
417  */
418 #define	SMB_ACE_HDRSIZE		4
419 #define	SMB_ACL_HDRSIZE		8
420 
421 /*
422  * Security Descriptor (SD)
423  *
424  * Security descriptors provide protection for objects, for example
425  * files and directories. It identifies the owner and primary group
426  * (SIDs) and contains an access control list. When a user tries to
427  * access an object his SID is compared to the permissions in the
428  * DACL to determine if access should be allowed or denied. Note that
429  * this is a simplification because there are other factors, such as
430  * default behavior and privileges to be taken into account (see also
431  * access tokens).
432  *
433  * The boolean flags have the following meanings when set:
434  *
435  * SE_OWNER_DEFAULTED indicates that the SID pointed to by the Owner
436  * field was provided by a defaulting mechanism rather than explicitly
437  * provided by the original provider of the security descriptor. This
438  * may affect the treatment of the SID with respect to inheritance of
439  * an owner.
440  *
441  * SE_GROUP_DEFAULTED indicates that the SID in the Group field was
442  * provided by a defaulting mechanism rather than explicitly provided
443  * by the original provider of the security descriptor.  This may
444  * affect the treatment of the SID with respect to inheritance of a
445  * primary group.
446  *
447  * SE_DACL_PRESENT indicates that the security descriptor contains a
448  * discretionary ACL. If this flag is set and the Dacl field of the
449  * SECURITY_DESCRIPTOR is null, then a null ACL is explicitly being
450  * specified.
451  *
452  * SE_DACL_DEFAULTED indicates that the ACL pointed to by the Dacl
453  * field was provided by a defaulting mechanism rather than explicitly
454  * provided by the original provider of the security descriptor. This
455  * may affect the treatment of the ACL with respect to inheritance of
456  * an ACL. This flag is ignored if the DaclPresent flag is not set.
457  *
458  * SE_SACL_PRESENT indicates that the security descriptor contains a
459  * system ACL pointed to by the Sacl field. If this flag is set and
460  * the Sacl field of the SECURITY_DESCRIPTOR is null, then an empty
461  * (but present) ACL is being specified.
462  *
463  * SE_SACL_DEFAULTED indicates that the ACL pointed to by the Sacl
464  * field was provided by a defaulting mechanism rather than explicitly
465  * provided by the original provider of the security descriptor. This
466  * may affect the treatment of the ACL with respect to inheritance of
467  * an ACL. This flag is ignored if the SaclPresent flag is not set.
468  *
469  * SE_DACL_PROTECTED Prevents ACEs set on the DACL of the parent container
470  * (and any objects above the parent container in the directory hierarchy)
471  * from being applied to the object's DACL.
472  *
473  * SE_SACL_PROTECTED Prevents ACEs set on the SACL of the parent container
474  * (and any objects above the parent container in the directory hierarchy)
475  * from being applied to the object's SACL.
476  *
477  * Note that the SE_DACL_PRESENT flag needs to be present to set
478  * SE_DACL_PROTECTED and SE_SACL_PRESENT needs to be present to set
479  * SE_SACL_PROTECTED.
480  *
481  * SE_SELF_RELATIVE indicates that the security descriptor is in self-
482  * relative form. In this form, all fields of the security descriptor
483  * are contiguous in memory and all pointer fields are expressed as
484  * offsets from the beginning of the security descriptor.
485  *
486  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
487  *    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
488  *   +---------------------------------------------------------------+
489  *   |            Control            |Reserved1 (SBZ)|   Revision    |
490  *   +---------------------------------------------------------------+
491  *   |                            Owner                              |
492  *   +---------------------------------------------------------------+
493  *   |                            Group                              |
494  *   +---------------------------------------------------------------+
495  *   |                            Sacl                               |
496  *   +---------------------------------------------------------------+
497  *   |                            Dacl                               |
498  *   +---------------------------------------------------------------+
499  *
500  */
501 
502 #define	SMB_OWNER_SECINFO	0x0001
503 #define	SMB_GROUP_SECINFO	0x0002
504 #define	SMB_DACL_SECINFO	0x0004
505 #define	SMB_SACL_SECINFO	0x0008
506 #define	SMB_ALL_SECINFO		0x000F
507 #define	SMB_ACL_SECINFO		(SMB_DACL_SECINFO | SMB_SACL_SECINFO)
508 
509 #define	SECURITY_DESCRIPTOR_REVISION	1
510 
511 
512 #define	SE_OWNER_DEFAULTED		0x0001
513 #define	SE_GROUP_DEFAULTED		0x0002
514 #define	SE_DACL_PRESENT			0x0004
515 #define	SE_DACL_DEFAULTED		0x0008
516 #define	SE_SACL_PRESENT			0x0010
517 #define	SE_SACL_DEFAULTED		0x0020
518 #define	SE_DACL_AUTO_INHERIT_REQ	0x0100
519 #define	SE_SACL_AUTO_INHERIT_REQ	0x0200
520 #define	SE_DACL_AUTO_INHERITED		0x0400
521 #define	SE_SACL_AUTO_INHERITED		0x0800
522 #define	SE_DACL_PROTECTED		0x1000
523 #define	SE_SACL_PROTECTED		0x2000
524 #define	SE_SELF_RELATIVE		0x8000
525 
526 #define	SE_DACL_INHERITANCE_MASK	0x1500
527 #define	SE_SACL_INHERITANCE_MASK	0x2A00
528 
529 /*
530  * Security descriptor structures:
531  *
532  * smb_sd_t     SD in SMB pointer form
533  * smb_fssd_t   SD in filesystem form
534  *
535  * Filesystems (e.g. ZFS/UFS) don't have something equivalent
536  * to SD. The items comprising a SMB SD are kept separately in
537  * filesystem. smb_fssd_t is introduced as a helper to provide
538  * the required abstraction for CIFS code.
539  */
540 
541 typedef struct smb_sd {
542 	uint8_t		sd_revision;
543 	uint16_t	sd_control;
544 	smb_sid_t 	*sd_owner;	/* SID file owner */
545 	smb_sid_t 	*sd_group;	/* SID group (for POSIX) */
546 	smb_acl_t 	*sd_sacl;	/* ACL System (audits) */
547 	smb_acl_t 	*sd_dacl;	/* ACL Discretionary (perm) */
548 } smb_sd_t;
549 
550 /*
551  * SD header size as it appears on the wire
552  */
553 #define	SMB_SD_HDRSIZE	20
554 
555 /*
556  * values for smb_fssd.sd_flags
557  */
558 #define	SMB_FSSD_FLAGS_DIR	0x01
559 
560 typedef struct smb_fssd {
561 	uint32_t	sd_secinfo;
562 	uint32_t	sd_flags;
563 	uid_t		sd_uid;
564 	gid_t		sd_gid;
565 	acl_t		*sd_zdacl;
566 	acl_t		*sd_zsacl;
567 } smb_fssd_t;
568 
569 void smb_sd_init(smb_sd_t *, uint8_t);
570 void smb_sd_term(smb_sd_t *);
571 uint32_t smb_sd_get_secinfo(smb_sd_t *);
572 uint32_t smb_sd_len(smb_sd_t *, uint32_t);
573 uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *);
574 
575 void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t);
576 void smb_fssd_term(smb_fssd_t *);
577 
578 void smb_acl_sort(smb_acl_t *);
579 void smb_acl_free(smb_acl_t *);
580 smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t);
581 smb_acl_t *smb_acl_from_zfs(acl_t *, uid_t, gid_t);
582 uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **);
583 uint16_t smb_acl_len(smb_acl_t *);
584 boolean_t smb_acl_isvalid(smb_acl_t *, int);
585 
586 void smb_fsacl_free(acl_t *);
587 acl_t *smb_fsacl_alloc(int, int);
588 
589 #ifdef __cplusplus
590 }
591 #endif
592 
593 #endif /* _SMBSRV_NTIFS_H */
594