xref: /onnv-gate/usr/src/uts/common/smbsrv/ntifs.h (revision 11963:061945695ce1)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
2211447Samw@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw #ifndef _SMBSRV_NTIFS_H
275331Samw #define	_SMBSRV_NTIFS_H
285331Samw 
295331Samw /*
305331Samw  * This file provides definitions compatible with the NT Installable
319832Samw@Sun.COM  * File System (IFS) interface. This header file also defines the Security
329832Samw@Sun.COM  * Descriptor module from Windows.
335331Samw  */
345331Samw 
355331Samw #ifdef __cplusplus
365331Samw extern "C" {
375331Samw #endif
385331Samw 
399832Samw@Sun.COM #include <sys/acl.h>
409832Samw@Sun.COM #include <sys/list.h>
419832Samw@Sun.COM #include <smbsrv/smb_sid.h>
429832Samw@Sun.COM 
435331Samw /*
447052Samw  * The Volume and Directory bits are for SMB rather than NT.
457052Samw  * NT has an explicit Normal bit; this bit is implied in SMB
467052Samw  * when the Hidden, System and Directory bits are not set.
477052Samw  *
487052Samw  * File attributes and creation flags share the same 32-bit
497052Samw  * space.
505331Samw  */
517052Samw #define	FILE_ATTRIBUTE_READONLY			0x00000001
527052Samw #define	FILE_ATTRIBUTE_HIDDEN			0x00000002
537052Samw #define	FILE_ATTRIBUTE_SYSTEM			0x00000004
547052Samw #define	FILE_ATTRIBUTE_VOLUME			0x00000008
557052Samw #define	FILE_ATTRIBUTE_DIRECTORY		0x00000010
567052Samw #define	FILE_ATTRIBUTE_ARCHIVE			0x00000020
577052Samw #define	FILE_ATTRIBUTE_DEVICE			0x00000040
587052Samw #define	FILE_ATTRIBUTE_NORMAL			0x00000080
597052Samw #define	FILE_ATTRIBUTE_TEMPORARY		0x00000100
607052Samw #define	FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
617052Samw #define	FILE_ATTRIBUTE_REPARSE_POINT		0x00000400
627052Samw #define	FILE_ATTRIBUTE_COMPRESSED		0x00000800
637052Samw #define	FILE_ATTRIBUTE_OFFLINE			0x00001000
647052Samw #define	FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000
657052Samw #define	FILE_ATTRIBUTE_ENCRYPTED		0x00004000
667052Samw #define	FILE_ATTRIBUTE_VIRTUAL			0x00010000
677052Samw #define	FILE_FLAG_OPEN_NO_RECALL		0x00100000
687052Samw #define	FILE_FLAG_OPEN_REPARSE_POINT		0x00200000
697052Samw #define	FILE_FLAG_POSIX_SEMANTICS		0x01000000
707052Samw #define	FILE_FLAG_BACKUP_SEMANTICS		0x02000000
717052Samw #define	FILE_FLAG_DELETE_ON_CLOSE		0x04000000
727052Samw #define	FILE_FLAG_SEQUENTIAL_SCAN		0x08000000
737052Samw #define	FILE_FLAG_RANDOM_ACCESS			0x10000000
745331Samw #define	FILE_FLAG_NO_BUFFERING			0x20000000
757052Samw #define	FILE_FLAG_OVERLAPPED			0x40000000
767052Samw #define	FILE_FLAG_WRITE_THROUGH			0x80000000
777052Samw 
787052Samw #define	FILE_ATTRIBUTE_VALID_FLAGS		0x00001fb7
797052Samw #define	FILE_ATTRIBUTE_VALID_SET_FLAGS		0x00001fa7
807052Samw #define	FILE_ATTRIBUTE_MASK			0x00003FFF
815331Samw 
825331Samw /*
835331Samw  * The create/open option flags: used in NtCreateAndx and NtTransactCreate
845331Samw  * SMB requests.
855331Samw  *
865331Samw  * The CreateOptions specify the options to be applied when creating or
875331Samw  * opening the file, as a compatible combination of the following flags:
885331Samw  *
895331Samw  * FILE_DIRECTORY_FILE
905331Samw  *	The file being created or opened is a directory file. With this
915331Samw  *	flag, the Disposition parameter must be set to one of FILE_CREATE,
925331Samw  *	FILE_OPEN, or FILE_OPEN_IF. With this flag, other compatible
935331Samw  *	CreateOptions flags include only the following:
945331Samw  *			FILE_SYNCHRONOUS_IO_ALERT
955331Samw  *			FILE_SYNCHRONOUS_IO_NONALERT
965331Samw  *			FILE_WRITE_THROUGH
975331Samw  *			FILE_OPEN_FOR_BACKUP_INTENT
985331Samw  *			FILE_OPEN_BY_FILE_ID
995331Samw  *
1005331Samw  * FILE_NON_DIRECTORY_FILE
1015331Samw  *	The file being opened must not be a directory file or this call
1025331Samw  *	will fail. The file object being opened can represent a data file,
1035331Samw  *	a logical, virtual, or physical device, or a volume.
1045331Samw  *
1055331Samw  * FILE_WRITE_THROUGH
1065331Samw  *	System services, FSDs, and drivers that write data to the file must
1075331Samw  *	actually transfer the data into the file before any requested write
1085331Samw  *	operation is considered complete. This flag is automatically set if
1095331Samw  *	the CreateOptions flag FILE_NO_INTERMEDIATE _BUFFERING is set.
1105331Samw  *
1115331Samw  * FILE_SEQUENTIAL_ONLY
1125331Samw  *	All accesses to the file will be sequential.
1135331Samw  *
1145331Samw  * FILE_RANDOM_ACCESS
1155331Samw  *	Accesses to the file can be random, so no sequential read-ahead
1165331Samw  *	operations should be performed on the file by FSDs or the system.
1175331Samw  *	FILE_NO_INTERMEDIATE _BUFFERING	The file cannot be cached or
1185331Samw  *	buffered in a driver's internal buffers. This flag is incompatible
1195331Samw  *	with the DesiredAccess FILE_APPEND_DATA flag.
1205331Samw  *
1215331Samw  * FILE_SYNCHRONOUS_IO_ALERT
1225331Samw  *	All operations on the file are performed synchronously. Any wait
1235331Samw  *	on behalf of the caller is subject to premature termination from
1245331Samw  *	alerts. This flag also causes the I/O system to maintain the file
1255331Samw  *	position context. If this flag is set, the DesiredAccess
1265331Samw  *	SYNCHRONIZE flag also must be set.
1275331Samw  *
1285331Samw  * FILE_SYNCHRONOUS_IO _NONALERT
1295331Samw  *	All operations on the file are performed synchronously. Waits in
1305331Samw  *	the system to synchronize I/O queuing and completion are not subject
1315331Samw  *	to alerts. This flag also causes the I/O system to maintain the file
1325331Samw  *	position context. If this flag is set, the DesiredAccess SYNCHRONIZE
1335331Samw  *	flag also must be set.
1345331Samw  *
1355331Samw  * FILE_CREATE_TREE _CONNECTION
1365331Samw  *	Create a tree connection for this file in order to open it over the
1375331Samw  *	network. This flag is irrelevant to device and intermediate drivers.
1385331Samw  *
1395331Samw  * FILE_COMPLETE_IF_OPLOCKED
1405331Samw  *	Complete this operation immediately with an alternate success code
1415331Samw  *	if the target file is oplocked, rather than blocking the caller's
1425331Samw  *	thread. If the file is oplocked, another caller already has access
1435331Samw  *	to the file over the network. This flag is irrelevant to device and
1445331Samw  *	intermediate drivers.
1455331Samw  *
1465331Samw  * FILE_NO_EA_KNOWLEDGE
1475331Samw  *	If the extended attributes on an existing file being opened indicate
1485331Samw  *	that the caller must understand EAs to properly interpret the file,
1495331Samw  *	fail this request because the caller does not understand how to deal
1505331Samw  *	with EAs. Device and intermediate drivers can ignore this flag.
1515331Samw  *
1525331Samw  * FILE_DELETE_ON_CLOSE
1535331Samw  *	Delete the file when the last reference to it is passed to close.
1545331Samw  *
1555331Samw  * FILE_OPEN_BY_FILE_ID
1565331Samw  *	The file name contains the name of a device and a 64-bit ID to
1575331Samw  *	be used to open the file. This flag is irrelevant to device and
1585331Samw  *	intermediate drivers.
1595331Samw  *
1605331Samw  * FILE_OPEN_FOR_BACKUP _INTENT
1615331Samw  *	The file is being opened for backup intent, hence, the system should
1625331Samw  *	check for certain access rights and grant the caller the appropriate
1635331Samw  *	accesses to the file before checking the input DesiredAccess against
1645331Samw  *	the file's security descriptor. This flag is irrelevant to device
1655331Samw  *	and intermediate drivers.
1665331Samw  */
1675331Samw #define	FILE_DIRECTORY_FILE			0x00000001
1685331Samw #define	FILE_WRITE_THROUGH			0x00000002
1695331Samw #define	FILE_SEQUENTIAL_ONLY			0x00000004
1705331Samw #define	FILE_NO_INTERMEDIATE_BUFFERING		0x00000008
1715331Samw 
1725331Samw #define	FILE_SYNCHRONOUS_IO_ALERT		0x00000010
1735331Samw #define	FILE_SYNCHRONOUS_IO_NONALERT		0x00000020
1745331Samw #define	FILE_NON_DIRECTORY_FILE			0x00000040
1755331Samw #define	FILE_CREATE_TREE_CONNECTION		0x00000080
1765331Samw 
1775331Samw #define	FILE_COMPLETE_IF_OPLOCKED		0x00000100
1785331Samw #define	FILE_NO_EA_KNOWLEDGE			0x00000200
1795331Samw /* UNUSED					0x00000400 */
1805331Samw #define	FILE_RANDOM_ACCESS			0x00000800
1815331Samw 
1825331Samw #define	FILE_DELETE_ON_CLOSE			0x00001000
1835331Samw #define	FILE_OPEN_BY_FILE_ID			0x00002000
1845331Samw #define	FILE_OPEN_FOR_BACKUP_INTENT		0x00004000
1855331Samw #define	FILE_NO_COMPRESSION			0x00008000
1865331Samw 
1875331Samw #define	FILE_RESERVE_OPFILTER			0x00100000
1885331Samw #define	FILE_RESERVED0				0x00200000
1895331Samw #define	FILE_RESERVED1				0x00400000
1905331Samw #define	FILE_RESERVED2				0x00800000
1915331Samw 
1925331Samw #define	FILE_VALID_OPTION_FLAGS			0x007fffff
1935331Samw #define	FILE_VALID_PIPE_OPTION_FLAGS		0x00000032
1945331Samw #define	FILE_VALID_MAILSLOT_OPTION_FLAGS	0x00000032
1955331Samw #define	FILE_VALID_SET_FLAGS			0x00000036
1965331Samw 
1975331Samw /*
1985331Samw  * Define the file information class values used by the NT DDK and HAL.
1995331Samw  */
2005331Samw typedef enum _FILE_INFORMATION_CLASS {
20110001SJoyce.McIntosh@Sun.COM 	FileDirectoryInformation		= 1,
20210001SJoyce.McIntosh@Sun.COM 	FileFullDirectoryInformation,		/* 2 */
20310001SJoyce.McIntosh@Sun.COM 	FileBothDirectoryInformation,		/* 3 */
20410001SJoyce.McIntosh@Sun.COM 	FileBasicInformation,			/* 4 */
20510001SJoyce.McIntosh@Sun.COM 	FileStandardInformation,		/* 5 */
20610001SJoyce.McIntosh@Sun.COM 	FileInternalInformation,		/* 6 */
20710001SJoyce.McIntosh@Sun.COM 	FileEaInformation,			/* 7 */
20810001SJoyce.McIntosh@Sun.COM 	FileAccessInformation,			/* 8 */
20910001SJoyce.McIntosh@Sun.COM 	FileNameInformation,			/* 9 */
21010001SJoyce.McIntosh@Sun.COM 	FileRenameInformation,			/* 10 */
21110001SJoyce.McIntosh@Sun.COM 	FileLinkInformation,			/* 11 */
21210001SJoyce.McIntosh@Sun.COM 	FileNamesInformation,			/* 12 */
21310001SJoyce.McIntosh@Sun.COM 	FileDispositionInformation,		/* 13 */
21410001SJoyce.McIntosh@Sun.COM 	FilePositionInformation,		/* 14 */
21510001SJoyce.McIntosh@Sun.COM 	FileFullEaInformation,			/* 15 */
21610001SJoyce.McIntosh@Sun.COM 	FileModeInformation,			/* 16 */
21710001SJoyce.McIntosh@Sun.COM 	FileAlignmentInformation,		/* 17 */
21810001SJoyce.McIntosh@Sun.COM 	FileAllInformation,			/* 18 */
21910001SJoyce.McIntosh@Sun.COM 	FileAllocationInformation,		/* 19 */
22010001SJoyce.McIntosh@Sun.COM 	FileEndOfFileInformation,		/* 20 */
22110001SJoyce.McIntosh@Sun.COM 	FileAlternateNameInformation,		/* 21 */
22210001SJoyce.McIntosh@Sun.COM 	FileStreamInformation,			/* 22 */
22310001SJoyce.McIntosh@Sun.COM 	FilePipeInformation,			/* 23 */
22410001SJoyce.McIntosh@Sun.COM 	FilePipeLocalInformation,		/* 24 */
22510001SJoyce.McIntosh@Sun.COM 	FilePipeRemoteInformation,		/* 25 */
22610001SJoyce.McIntosh@Sun.COM 	FileMailslotQueryInformation,		/* 26 */
22710001SJoyce.McIntosh@Sun.COM 	FileMailslotSetInformation,		/* 27 */
22810001SJoyce.McIntosh@Sun.COM 	FileCompressionInformation,		/* 28 */
22910001SJoyce.McIntosh@Sun.COM 	FileObjectIdInformation,		/* 29 */
23010001SJoyce.McIntosh@Sun.COM 	FileCompletionInformation,		/* 30 */
23110001SJoyce.McIntosh@Sun.COM 	FileMoveClusterInformation,		/* 31 */
23210001SJoyce.McIntosh@Sun.COM 	FileQuotaInformation,			/* 32 */
23310001SJoyce.McIntosh@Sun.COM 	FileReparsePointInformation,		/* 33 */
23410001SJoyce.McIntosh@Sun.COM 	FileNetworkOpenInformation,		/* 34 */
23510001SJoyce.McIntosh@Sun.COM 	FileAttributeTagInformation,		/* 35 */
23610001SJoyce.McIntosh@Sun.COM 	FileTrackingInformation,		/* 36 */
23710001SJoyce.McIntosh@Sun.COM 	FileIdBothDirectoryInformation,		/* 37 */
23810001SJoyce.McIntosh@Sun.COM 	FileIdFullDirectoryInformation,		/* 38 */
23910001SJoyce.McIntosh@Sun.COM 	FileValidDataLengthInformation,		/* 39 */
24010001SJoyce.McIntosh@Sun.COM 	FileShortNameInformation,		/* 40 */
24110001SJoyce.McIntosh@Sun.COM 	FileInformationReserved41,		/* 41 */
24210001SJoyce.McIntosh@Sun.COM 	FileInformationReserved42,		/* 42 */
24310001SJoyce.McIntosh@Sun.COM 	FileInformationReserved43,		/* 43 */
24410001SJoyce.McIntosh@Sun.COM 	FileSfioReserveInformation,		/* 44 */
24510001SJoyce.McIntosh@Sun.COM 	FileSfioVolumeInformation,		/* 45 */
24610001SJoyce.McIntosh@Sun.COM 	FileHardLinkInformation,		/* 46 */
24710001SJoyce.McIntosh@Sun.COM 	FileInformationReserved47,		/* 47 */
24810001SJoyce.McIntosh@Sun.COM 	FileNormalizedNameInformation,		/* 48 */
24910001SJoyce.McIntosh@Sun.COM 	FileInformationReserved49,		/* 49 */
25010001SJoyce.McIntosh@Sun.COM 	FileIdGlobalTxDirectoryInformation,	/* 50 */
25110001SJoyce.McIntosh@Sun.COM 	FileInformationReserved51,		/* 51 */
25210001SJoyce.McIntosh@Sun.COM 	FileInformationReserved52,		/* 52 */
25310001SJoyce.McIntosh@Sun.COM 	FileInformationReserved53,		/* 53 */
25410001SJoyce.McIntosh@Sun.COM 	FileStandardLinkInformation,		/* 54 */
2555331Samw 	FileMaximumInformation
2565331Samw } FILE_INFORMATION_CLASS;
2575331Samw 
2589832Samw@Sun.COM /*
259*11963SAfshin.Ardakani@Sun.COM  * Define the file system information class values.
260*11963SAfshin.Ardakani@Sun.COM  */
261*11963SAfshin.Ardakani@Sun.COM typedef enum _FILE_FS_INFORMATION_CLASS {
262*11963SAfshin.Ardakani@Sun.COM 	FileFsVolumeInformation		= 1,
263*11963SAfshin.Ardakani@Sun.COM 	FileFsLabelInformation,		/* 2 */
264*11963SAfshin.Ardakani@Sun.COM 	FileFsSizeInformation,		/* 3 */
265*11963SAfshin.Ardakani@Sun.COM 	FileFsDeviceInformation,	/* 4 */
266*11963SAfshin.Ardakani@Sun.COM 	FileFsAttributeInformation,	/* 5 */
267*11963SAfshin.Ardakani@Sun.COM 	FileFsControlInformation,	/* 6 */
268*11963SAfshin.Ardakani@Sun.COM 	FileFsFullSizeInformation,	/* 7 */
269*11963SAfshin.Ardakani@Sun.COM 	FileFsObjectIdInformation,	/* 8 */
270*11963SAfshin.Ardakani@Sun.COM 	FileFsDriverPathInformation	/* 9 */
271*11963SAfshin.Ardakani@Sun.COM } FILE_FS_INFORMATION_CLASS;
272*11963SAfshin.Ardakani@Sun.COM 
273*11963SAfshin.Ardakani@Sun.COM /*
2749832Samw@Sun.COM  * Discretionary Access Control List (DACL)
2759832Samw@Sun.COM  *
2769832Samw@Sun.COM  * A Discretionary Access Control List (DACL), often abbreviated to
2779832Samw@Sun.COM  * ACL, is a list of access controls which either allow or deny access
2789832Samw@Sun.COM  * for users or groups to a resource. There is a list header followed
2799832Samw@Sun.COM  * by a list of access control entries (ACE). Each ACE specifies the
2809832Samw@Sun.COM  * access allowed or denied to a single user or group (identified by
2819832Samw@Sun.COM  * a SID).
2829832Samw@Sun.COM  *
2839832Samw@Sun.COM  * There is another access control list object called a System Access
2849832Samw@Sun.COM  * Control List (SACL), which is used to control auditing, but no
2859832Samw@Sun.COM  * support is provideed for SACLs at this time.
2869832Samw@Sun.COM  *
2879832Samw@Sun.COM  * ACL header format:
2889832Samw@Sun.COM  *
2899832Samw@Sun.COM  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
2909832Samw@Sun.COM  *    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
2919832Samw@Sun.COM  *   +-------------------------------+---------------+---------------+
2929832Samw@Sun.COM  *   |            AclSize            |      Sbz1     |  AclRevision  |
2939832Samw@Sun.COM  *   +-------------------------------+---------------+---------------+
2949832Samw@Sun.COM  *   |              Sbz2             |           AceCount            |
2959832Samw@Sun.COM  *   +-------------------------------+-------------------------------+
2969832Samw@Sun.COM  *
2979832Samw@Sun.COM  * AclRevision specifies the revision level of the ACL. This value should
2989832Samw@Sun.COM  * be ACL_REVISION, unless the ACL contains an object-specific ACE, in which
2999832Samw@Sun.COM  * case this value must be ACL_REVISION_DS. All ACEs in an ACL must be at the
3009832Samw@Sun.COM  * same revision level.
3019832Samw@Sun.COM  *
3029832Samw@Sun.COM  * ACE header format:
3039832Samw@Sun.COM  *
3049832Samw@Sun.COM  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
3059832Samw@Sun.COM  *    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
3069832Samw@Sun.COM  *   +---------------+-------+-------+---------------+---------------+
3079832Samw@Sun.COM  *   |            AceSize            |    AceFlags   |     AceType   |
3089832Samw@Sun.COM  *   +---------------+-------+-------+---------------+---------------+
3099832Samw@Sun.COM  *
3109832Samw@Sun.COM  * Access mask format:
3119832Samw@Sun.COM  *
3129832Samw@Sun.COM  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
3139832Samw@Sun.COM  *    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
3149832Samw@Sun.COM  *   +---------------+---------------+-------------------------------+
3159832Samw@Sun.COM  *   |G|G|G|G|Res'd|A| StandardRights|         SpecificRights        |
3169832Samw@Sun.COM  *   |R|W|E|A|     |S|               |                               |
3179832Samw@Sun.COM  *   +-+-------------+---------------+-------------------------------+
3189832Samw@Sun.COM  *
3199832Samw@Sun.COM  *   typedef struct ACCESS_MASK {
3209832Samw@Sun.COM  *       WORD SpecificRights;
3219832Samw@Sun.COM  *       BYTE StandardRights;
3229832Samw@Sun.COM  *       BYTE AccessSystemAcl : 1;
3239832Samw@Sun.COM  *       BYTE Reserved : 3;
3249832Samw@Sun.COM  *       BYTE GenericAll : 1;
3259832Samw@Sun.COM  *       BYTE GenericExecute : 1;
3269832Samw@Sun.COM  *       BYTE GenericWrite : 1;
3279832Samw@Sun.COM  *       BYTE GenericRead : 1;
3289832Samw@Sun.COM  *   } ACCESS_MASK;
3299832Samw@Sun.COM  *
3309832Samw@Sun.COM  */
3319832Samw@Sun.COM 
3329832Samw@Sun.COM #define	ACL_REVISION1			1
3339832Samw@Sun.COM #define	ACL_REVISION2			2
3349832Samw@Sun.COM #define	MIN_ACL_REVISION2		ACL_REVISION2
3359832Samw@Sun.COM #define	ACL_REVISION3			3
3369832Samw@Sun.COM #define	ACL_REVISION4			4
3379832Samw@Sun.COM #define	MAX_ACL_REVISION		ACL_REVISION4
3389832Samw@Sun.COM 
3399832Samw@Sun.COM /*
3409832Samw@Sun.COM  * Current ACE and ACL revision Levels
3419832Samw@Sun.COM  */
3429832Samw@Sun.COM #define	ACE_REVISION			1
3439832Samw@Sun.COM #define	ACL_REVISION			ACL_REVISION2
3449832Samw@Sun.COM #define	ACL_REVISION_DS			ACL_REVISION4
3459832Samw@Sun.COM 
3469832Samw@Sun.COM 
3479832Samw@Sun.COM #define	ACCESS_ALLOWED_ACE_TYPE		0
3489832Samw@Sun.COM #define	ACCESS_DENIED_ACE_TYPE		1
3499832Samw@Sun.COM #define	SYSTEM_AUDIT_ACE_TYPE		2
3509832Samw@Sun.COM #define	SYSTEM_ALARM_ACE_TYPE		3
3519832Samw@Sun.COM 
3529832Samw@Sun.COM /*
3539832Samw@Sun.COM  *  se_flags
3549832Samw@Sun.COM  * ----------
3559832Samw@Sun.COM  * Specifies a set of ACE type-specific control flags. This member can be a
3569832Samw@Sun.COM  * combination of the following values.
3579832Samw@Sun.COM  *
3589832Samw@Sun.COM  * CONTAINER_INHERIT_ACE: Child objects that are containers, such as
3599832Samw@Sun.COM  *		directories, inherit the ACE as an effective ACE. The inherited
3609832Samw@Sun.COM  *		ACE is inheritable unless the NO_PROPAGATE_INHERIT_ACE bit flag
3619832Samw@Sun.COM  *		is also set.
3629832Samw@Sun.COM  *
3639832Samw@Sun.COM  * INHERIT_ONLY_ACE: Indicates an inherit-only ACE which does not control
3649832Samw@Sun.COM  *		access to the object to which it is attached.
3659832Samw@Sun.COM  *		If this flag is not set,
3669832Samw@Sun.COM  *		the ACE is an effective ACE which controls access to the object
3679832Samw@Sun.COM  *		to which it is attached.
3689832Samw@Sun.COM  * 		Both effective and inherit-only ACEs can be inherited
3699832Samw@Sun.COM  *		depending on the state of the other inheritance flags.
3709832Samw@Sun.COM  *
3719832Samw@Sun.COM  * INHERITED_ACE: Windows 2000/XP: Indicates that the ACE was inherited.
3729832Samw@Sun.COM  *		The system sets this bit when it propagates an
3739832Samw@Sun.COM  *		inherited ACE to a child object.
3749832Samw@Sun.COM  *
3759832Samw@Sun.COM  * NO_PROPAGATE_INHERIT_ACE: If the ACE is inherited by a child object, the
3769832Samw@Sun.COM  *		system clears the OBJECT_INHERIT_ACE and CONTAINER_INHERIT_ACE
3779832Samw@Sun.COM  *		flags in the inherited ACE.
3789832Samw@Sun.COM  *		This prevents the ACE from being inherited by
3799832Samw@Sun.COM  *		subsequent generations of objects.
3809832Samw@Sun.COM  *
3819832Samw@Sun.COM  * OBJECT_INHERIT_ACE: Noncontainer child objects inherit the ACE as an
3829832Samw@Sun.COM  *		effective ACE.  For child objects that are containers,
3839832Samw@Sun.COM  *		the ACE is inherited as an inherit-only ACE unless the
3849832Samw@Sun.COM  *		NO_PROPAGATE_INHERIT_ACE bit flag is also set.
3859832Samw@Sun.COM  */
3869832Samw@Sun.COM #define	OBJECT_INHERIT_ACE		0x01
3879832Samw@Sun.COM #define	CONTAINER_INHERIT_ACE		0x02
3889832Samw@Sun.COM #define	NO_PROPOGATE_INHERIT_ACE	0x04
3899832Samw@Sun.COM #define	INHERIT_ONLY_ACE		0x08
3909832Samw@Sun.COM #define	INHERITED_ACE			0x10
3919832Samw@Sun.COM #define	INHERIT_MASK_ACE		0x1F
3929832Samw@Sun.COM 
3939832Samw@Sun.COM 
3949832Samw@Sun.COM /*
3959832Samw@Sun.COM  * These flags are only used in system audit or alarm ACEs to
3969832Samw@Sun.COM  * indicate when an audit message should be generated, i.e.
3979832Samw@Sun.COM  * on successful access or on unsuccessful access.
3989832Samw@Sun.COM  */
3999832Samw@Sun.COM #define	SUCCESSFUL_ACCESS_ACE_FLAG	0x40
4009832Samw@Sun.COM #define	FAILED_ACCESS_ACE_FLAG		0x80
4019832Samw@Sun.COM 
4029832Samw@Sun.COM /*
4039832Samw@Sun.COM  * se_bsize is the size, in bytes, of ACE as it appears on the wire.
4049832Samw@Sun.COM  * se_sln is used to sort the ACL when it's required.
4059832Samw@Sun.COM  */
4069832Samw@Sun.COM typedef struct smb_acehdr {
4079832Samw@Sun.COM 	uint8_t		se_type;
4089832Samw@Sun.COM 	uint8_t		se_flags;
4099832Samw@Sun.COM 	uint16_t	se_bsize;
4109832Samw@Sun.COM } smb_acehdr_t;
4119832Samw@Sun.COM 
4129832Samw@Sun.COM typedef struct smb_ace {
4139832Samw@Sun.COM 	smb_acehdr_t	se_hdr;
4149832Samw@Sun.COM 	uint32_t	se_mask;
4159832Samw@Sun.COM 	list_node_t	se_sln;
4169832Samw@Sun.COM 	smb_sid_t	*se_sid;
4179832Samw@Sun.COM } smb_ace_t;
4189832Samw@Sun.COM 
4199832Samw@Sun.COM /*
4209832Samw@Sun.COM  * sl_bsize is the size of ACL in bytes as it appears on the wire.
4219832Samw@Sun.COM  */
4229832Samw@Sun.COM typedef struct smb_acl {
4239832Samw@Sun.COM 	uint8_t		sl_revision;
4249832Samw@Sun.COM 	uint16_t	sl_bsize;
4259832Samw@Sun.COM 	uint16_t	sl_acecnt;
4269832Samw@Sun.COM 	smb_ace_t	*sl_aces;
4279832Samw@Sun.COM 	list_t		sl_sorted;
4289832Samw@Sun.COM } smb_acl_t;
4299832Samw@Sun.COM 
4309832Samw@Sun.COM /*
4319832Samw@Sun.COM  * ACE/ACL header size, in byte, as it appears on the wire
4329832Samw@Sun.COM  */
4339832Samw@Sun.COM #define	SMB_ACE_HDRSIZE		4
4349832Samw@Sun.COM #define	SMB_ACL_HDRSIZE		8
4359832Samw@Sun.COM 
4369832Samw@Sun.COM /*
4379832Samw@Sun.COM  * Security Descriptor (SD)
4389832Samw@Sun.COM  *
4399832Samw@Sun.COM  * Security descriptors provide protection for objects, for example
4409832Samw@Sun.COM  * files and directories. It identifies the owner and primary group
4419832Samw@Sun.COM  * (SIDs) and contains an access control list. When a user tries to
4429832Samw@Sun.COM  * access an object his SID is compared to the permissions in the
4439832Samw@Sun.COM  * DACL to determine if access should be allowed or denied. Note that
4449832Samw@Sun.COM  * this is a simplification because there are other factors, such as
4459832Samw@Sun.COM  * default behavior and privileges to be taken into account (see also
4469832Samw@Sun.COM  * access tokens).
4479832Samw@Sun.COM  *
4489832Samw@Sun.COM  * The boolean flags have the following meanings when set:
4499832Samw@Sun.COM  *
4509832Samw@Sun.COM  * SE_OWNER_DEFAULTED indicates that the SID pointed to by the Owner
4519832Samw@Sun.COM  * field was provided by a defaulting mechanism rather than explicitly
4529832Samw@Sun.COM  * provided by the original provider of the security descriptor. This
4539832Samw@Sun.COM  * may affect the treatment of the SID with respect to inheritance of
4549832Samw@Sun.COM  * an owner.
4559832Samw@Sun.COM  *
4569832Samw@Sun.COM  * SE_GROUP_DEFAULTED indicates that the SID in the Group field was
4579832Samw@Sun.COM  * provided by a defaulting mechanism rather than explicitly provided
4589832Samw@Sun.COM  * by the original provider of the security descriptor.  This may
4599832Samw@Sun.COM  * affect the treatment of the SID with respect to inheritance of a
4609832Samw@Sun.COM  * primary group.
4619832Samw@Sun.COM  *
4629832Samw@Sun.COM  * SE_DACL_PRESENT indicates that the security descriptor contains a
4639832Samw@Sun.COM  * discretionary ACL. If this flag is set and the Dacl field of the
4649832Samw@Sun.COM  * SECURITY_DESCRIPTOR is null, then a null ACL is explicitly being
4659832Samw@Sun.COM  * specified.
4669832Samw@Sun.COM  *
4679832Samw@Sun.COM  * SE_DACL_DEFAULTED indicates that the ACL pointed to by the Dacl
4689832Samw@Sun.COM  * field was provided by a defaulting mechanism rather than explicitly
4699832Samw@Sun.COM  * provided by the original provider of the security descriptor. This
4709832Samw@Sun.COM  * may affect the treatment of the ACL with respect to inheritance of
4719832Samw@Sun.COM  * an ACL. This flag is ignored if the DaclPresent flag is not set.
4729832Samw@Sun.COM  *
4739832Samw@Sun.COM  * SE_SACL_PRESENT indicates that the security descriptor contains a
4749832Samw@Sun.COM  * system ACL pointed to by the Sacl field. If this flag is set and
4759832Samw@Sun.COM  * the Sacl field of the SECURITY_DESCRIPTOR is null, then an empty
4769832Samw@Sun.COM  * (but present) ACL is being specified.
4779832Samw@Sun.COM  *
4789832Samw@Sun.COM  * SE_SACL_DEFAULTED indicates that the ACL pointed to by the Sacl
4799832Samw@Sun.COM  * field was provided by a defaulting mechanism rather than explicitly
4809832Samw@Sun.COM  * provided by the original provider of the security descriptor. This
4819832Samw@Sun.COM  * may affect the treatment of the ACL with respect to inheritance of
4829832Samw@Sun.COM  * an ACL. This flag is ignored if the SaclPresent flag is not set.
4839832Samw@Sun.COM  *
4849832Samw@Sun.COM  * SE_DACL_PROTECTED Prevents ACEs set on the DACL of the parent container
4859832Samw@Sun.COM  * (and any objects above the parent container in the directory hierarchy)
4869832Samw@Sun.COM  * from being applied to the object's DACL.
4879832Samw@Sun.COM  *
4889832Samw@Sun.COM  * SE_SACL_PROTECTED Prevents ACEs set on the SACL of the parent container
4899832Samw@Sun.COM  * (and any objects above the parent container in the directory hierarchy)
4909832Samw@Sun.COM  * from being applied to the object's SACL.
4919832Samw@Sun.COM  *
4929832Samw@Sun.COM  * Note that the SE_DACL_PRESENT flag needs to be present to set
4939832Samw@Sun.COM  * SE_DACL_PROTECTED and SE_SACL_PRESENT needs to be present to set
4949832Samw@Sun.COM  * SE_SACL_PROTECTED.
4959832Samw@Sun.COM  *
4969832Samw@Sun.COM  * SE_SELF_RELATIVE indicates that the security descriptor is in self-
4979832Samw@Sun.COM  * relative form. In this form, all fields of the security descriptor
4989832Samw@Sun.COM  * are contiguous in memory and all pointer fields are expressed as
4999832Samw@Sun.COM  * offsets from the beginning of the security descriptor.
5009832Samw@Sun.COM  *
5019832Samw@Sun.COM  *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
5029832Samw@Sun.COM  *    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
5039832Samw@Sun.COM  *   +---------------------------------------------------------------+
5049832Samw@Sun.COM  *   |            Control            |Reserved1 (SBZ)|   Revision    |
5059832Samw@Sun.COM  *   +---------------------------------------------------------------+
5069832Samw@Sun.COM  *   |                            Owner                              |
5079832Samw@Sun.COM  *   +---------------------------------------------------------------+
5089832Samw@Sun.COM  *   |                            Group                              |
5099832Samw@Sun.COM  *   +---------------------------------------------------------------+
5109832Samw@Sun.COM  *   |                            Sacl                               |
5119832Samw@Sun.COM  *   +---------------------------------------------------------------+
5129832Samw@Sun.COM  *   |                            Dacl                               |
5139832Samw@Sun.COM  *   +---------------------------------------------------------------+
5149832Samw@Sun.COM  *
5159832Samw@Sun.COM  */
5169832Samw@Sun.COM 
5179832Samw@Sun.COM #define	SMB_OWNER_SECINFO	0x0001
5189832Samw@Sun.COM #define	SMB_GROUP_SECINFO	0x0002
5199832Samw@Sun.COM #define	SMB_DACL_SECINFO	0x0004
5209832Samw@Sun.COM #define	SMB_SACL_SECINFO	0x0008
5219832Samw@Sun.COM #define	SMB_ALL_SECINFO		0x000F
5229832Samw@Sun.COM #define	SMB_ACL_SECINFO		(SMB_DACL_SECINFO | SMB_SACL_SECINFO)
5239832Samw@Sun.COM 
5249832Samw@Sun.COM #define	SECURITY_DESCRIPTOR_REVISION	1
5259832Samw@Sun.COM 
5269832Samw@Sun.COM 
5279832Samw@Sun.COM #define	SE_OWNER_DEFAULTED		0x0001
5289832Samw@Sun.COM #define	SE_GROUP_DEFAULTED		0x0002
5299832Samw@Sun.COM #define	SE_DACL_PRESENT			0x0004
5309832Samw@Sun.COM #define	SE_DACL_DEFAULTED		0x0008
5319832Samw@Sun.COM #define	SE_SACL_PRESENT			0x0010
5329832Samw@Sun.COM #define	SE_SACL_DEFAULTED		0x0020
5339832Samw@Sun.COM #define	SE_DACL_AUTO_INHERIT_REQ	0x0100
5349832Samw@Sun.COM #define	SE_SACL_AUTO_INHERIT_REQ	0x0200
5359832Samw@Sun.COM #define	SE_DACL_AUTO_INHERITED		0x0400
5369832Samw@Sun.COM #define	SE_SACL_AUTO_INHERITED		0x0800
5379832Samw@Sun.COM #define	SE_DACL_PROTECTED		0x1000
5389832Samw@Sun.COM #define	SE_SACL_PROTECTED		0x2000
5399832Samw@Sun.COM #define	SE_SELF_RELATIVE		0x8000
5409832Samw@Sun.COM 
5419832Samw@Sun.COM #define	SE_DACL_INHERITANCE_MASK	0x1500
5429832Samw@Sun.COM #define	SE_SACL_INHERITANCE_MASK	0x2A00
5439832Samw@Sun.COM 
5449832Samw@Sun.COM /*
5459832Samw@Sun.COM  * Security descriptor structures:
5469832Samw@Sun.COM  *
5479832Samw@Sun.COM  * smb_sd_t     SD in SMB pointer form
5489832Samw@Sun.COM  * smb_fssd_t   SD in filesystem form
5499832Samw@Sun.COM  *
5509832Samw@Sun.COM  * Filesystems (e.g. ZFS/UFS) don't have something equivalent
5519832Samw@Sun.COM  * to SD. The items comprising a SMB SD are kept separately in
5529832Samw@Sun.COM  * filesystem. smb_fssd_t is introduced as a helper to provide
5539832Samw@Sun.COM  * the required abstraction for CIFS code.
5549832Samw@Sun.COM  */
5559832Samw@Sun.COM 
5569832Samw@Sun.COM typedef struct smb_sd {
5579832Samw@Sun.COM 	uint8_t		sd_revision;
5589832Samw@Sun.COM 	uint16_t	sd_control;
5599832Samw@Sun.COM 	smb_sid_t 	*sd_owner;	/* SID file owner */
5609832Samw@Sun.COM 	smb_sid_t 	*sd_group;	/* SID group (for POSIX) */
5619832Samw@Sun.COM 	smb_acl_t 	*sd_sacl;	/* ACL System (audits) */
5629832Samw@Sun.COM 	smb_acl_t 	*sd_dacl;	/* ACL Discretionary (perm) */
5639832Samw@Sun.COM } smb_sd_t;
5649832Samw@Sun.COM 
5659832Samw@Sun.COM /*
5669832Samw@Sun.COM  * SD header size as it appears on the wire
5679832Samw@Sun.COM  */
5689832Samw@Sun.COM #define	SMB_SD_HDRSIZE	20
5699832Samw@Sun.COM 
5709832Samw@Sun.COM /*
5719832Samw@Sun.COM  * values for smb_fssd.sd_flags
5729832Samw@Sun.COM  */
5739832Samw@Sun.COM #define	SMB_FSSD_FLAGS_DIR	0x01
5749832Samw@Sun.COM 
5759832Samw@Sun.COM typedef struct smb_fssd {
5769832Samw@Sun.COM 	uint32_t	sd_secinfo;
5779832Samw@Sun.COM 	uint32_t	sd_flags;
5789832Samw@Sun.COM 	uid_t		sd_uid;
5799832Samw@Sun.COM 	gid_t		sd_gid;
5809832Samw@Sun.COM 	acl_t		*sd_zdacl;
5819832Samw@Sun.COM 	acl_t		*sd_zsacl;
5829832Samw@Sun.COM } smb_fssd_t;
5839832Samw@Sun.COM 
5849832Samw@Sun.COM void smb_sd_init(smb_sd_t *, uint8_t);
5859832Samw@Sun.COM void smb_sd_term(smb_sd_t *);
5869832Samw@Sun.COM uint32_t smb_sd_get_secinfo(smb_sd_t *);
5879832Samw@Sun.COM uint32_t smb_sd_len(smb_sd_t *, uint32_t);
5889832Samw@Sun.COM uint32_t smb_sd_tofs(smb_sd_t *, smb_fssd_t *);
5899832Samw@Sun.COM 
5909832Samw@Sun.COM void smb_fssd_init(smb_fssd_t *, uint32_t, uint32_t);
5919832Samw@Sun.COM void smb_fssd_term(smb_fssd_t *);
5929832Samw@Sun.COM 
5939832Samw@Sun.COM void smb_acl_sort(smb_acl_t *);
5949832Samw@Sun.COM void smb_acl_free(smb_acl_t *);
5959832Samw@Sun.COM smb_acl_t *smb_acl_alloc(uint8_t, uint16_t, uint16_t);
59611447Samw@Sun.COM smb_acl_t *smb_acl_from_zfs(acl_t *);
5979832Samw@Sun.COM uint32_t smb_acl_to_zfs(smb_acl_t *, uint32_t, int, acl_t **);
5989832Samw@Sun.COM uint16_t smb_acl_len(smb_acl_t *);
5999832Samw@Sun.COM boolean_t smb_acl_isvalid(smb_acl_t *, int);
6009832Samw@Sun.COM 
6019832Samw@Sun.COM void smb_fsacl_free(acl_t *);
6029832Samw@Sun.COM acl_t *smb_fsacl_alloc(int, int);
6039832Samw@Sun.COM 
6045331Samw #ifdef __cplusplus
6055331Samw }
6065331Samw #endif
6075331Samw 
6085331Samw #endif /* _SMBSRV_NTIFS_H */
609