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