xref: /onnv-gate/usr/src/uts/common/smbsrv/smb_sid.h (revision 11447:b5b2a9bd508f)
16432Sas200622 /*
26432Sas200622  * CDDL HEADER START
36432Sas200622  *
46432Sas200622  * The contents of this file are subject to the terms of the
56432Sas200622  * Common Development and Distribution License (the "License").
66432Sas200622  * You may not use this file except in compliance with the License.
76432Sas200622  *
86432Sas200622  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96432Sas200622  * or http://www.opensolaris.org/os/licensing.
106432Sas200622  * See the License for the specific language governing permissions
116432Sas200622  * and limitations under the License.
126432Sas200622  *
136432Sas200622  * When distributing Covered Code, include this CDDL HEADER in each
146432Sas200622  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156432Sas200622  * If applicable, add the following below this CDDL HEADER, with the
166432Sas200622  * fields enclosed by brackets "[]" replaced with your own identifying
176432Sas200622  * information: Portions Copyright [yyyy] [name of copyright owner]
186432Sas200622  *
196432Sas200622  * CDDL HEADER END
206432Sas200622  */
216432Sas200622 /*
22*11447Samw@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
236432Sas200622  * Use is subject to license terms.
246432Sas200622  */
256432Sas200622 
266432Sas200622 #ifndef _SMB_SID_H
276432Sas200622 #define	_SMB_SID_H
286432Sas200622 
296432Sas200622 /*
308474SJose.Borrego@Sun.COM  * Security Identifier (SID) interface definition.
316432Sas200622  */
326432Sas200622 #include <smbsrv/wintypes.h>
336432Sas200622 
346432Sas200622 #ifdef __cplusplus
356432Sas200622 extern "C" {
366432Sas200622 #endif
376432Sas200622 
386432Sas200622 /*
396432Sas200622  * Predefined global user RIDs.
406432Sas200622  */
416432Sas200622 #define	DOMAIN_USER_RID_ADMIN		(0x000001F4L)	/* 500 */
426432Sas200622 #define	DOMAIN_USER_RID_GUEST		(0x000001F5L)	/* 501 */
436432Sas200622 #define	DOMAIN_USER_RID_KRBTGT		(0x000001F6L)	/* 502 */
446432Sas200622 
456432Sas200622 /*
466432Sas200622  * Predefined global group RIDs.
476432Sas200622  */
486432Sas200622 #define	DOMAIN_GROUP_RID_ADMINS		(0x00000200L)	/* 512 */
49*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_USERS		(0x00000201L)	/* 513 */
50*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_GUESTS		(0x00000202L)	/* 514 */
51*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_COMPUTERS	(0x00000203L)	/* 515 */
52*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_CONTROLLERS	(0x00000204L)	/* 516 */
53*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_CERT_ADMINS	(0x00000205L)	/* 517 */
54*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_SCHEMA_ADMINS	(0x00000206L)	/* 518 */
55*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_EP_ADMINS	(0x00000207L)	/* 519 */
56*11447Samw@Sun.COM #define	DOMAIN_GROUP_RID_GP_CREATOR	(0x00000208L)	/* 520 */
576432Sas200622 
586432Sas200622 
596432Sas200622 /*
606432Sas200622  * Predefined local alias RIDs.
616432Sas200622  */
626432Sas200622 #define	DOMAIN_ALIAS_RID_ADMINS		(0x00000220L)	/* 544 */
636432Sas200622 #define	DOMAIN_ALIAS_RID_USERS		(0x00000221L)
646432Sas200622 #define	DOMAIN_ALIAS_RID_GUESTS		(0x00000222L)
656432Sas200622 #define	DOMAIN_ALIAS_RID_POWER_USERS	(0x00000223L)
666432Sas200622 #define	DOMAIN_ALIAS_RID_ACCOUNT_OPS	(0x00000224L)
676432Sas200622 #define	DOMAIN_ALIAS_RID_SYSTEM_OPS	(0x00000225L)
686432Sas200622 #define	DOMAIN_ALIAS_RID_PRINT_OPS	(0x00000226L)
696432Sas200622 #define	DOMAIN_ALIAS_RID_BACKUP_OPS	(0x00000227L)
706432Sas200622 #define	DOMAIN_ALIAS_RID_REPLICATOR	(0x00000228L)
716432Sas200622 
726432Sas200622 
736432Sas200622 /*
746432Sas200622  * Universal and NT well-known SIDs
756432Sas200622  */
76*11447Samw@Sun.COM #define	NT_NULL_AUTH_SIDSTR			"S-1-0"
776432Sas200622 #define	NT_NULL_SIDSTR				"S-1-0-0"
78*11447Samw@Sun.COM #define	NT_WORLD_AUTH_SIDSTR			"S-1-1"
796432Sas200622 #define	NT_WORLD_SIDSTR				"S-1-1-0"
80*11447Samw@Sun.COM #define	NT_LOCAL_AUTH_SIDSTR			"S-1-2"
816432Sas200622 #define	NT_LOCAL_SIDSTR				"S-1-2-0"
82*11447Samw@Sun.COM #define	NT_CREATOR_AUTH_SIDSTR			"S-1-3"
836432Sas200622 #define	NT_CREATOR_OWNER_ID_SIDSTR		"S-1-3-0"
846432Sas200622 #define	NT_CREATOR_GROUP_ID_SIDSTR		"S-1-3-1"
856432Sas200622 #define	NT_CREATOR_OWNER_SERVER_ID_SIDSTR	"S-1-3-2"
866432Sas200622 #define	NT_CREATOR_GROUP_SERVER_ID_SIDSTR	"S-1-3-3"
87*11447Samw@Sun.COM #define	NT_OWNER_RIGHTS_SIDSTR			"S-1-3-4"
88*11447Samw@Sun.COM #define	NT_GROUP_RIGHTS_SIDSTR			"S-1-3-5"
896432Sas200622 #define	NT_NON_UNIQUE_IDS_SIDSTR		"S-1-4"
906432Sas200622 #define	NT_AUTHORITY_SIDSTR			"S-1-5"
916432Sas200622 #define	NT_DIALUP_SIDSTR			"S-1-5-1"
926432Sas200622 #define	NT_NETWORK_SIDSTR			"S-1-5-2"
936432Sas200622 #define	NT_BATCH_SIDSTR				"S-1-5-3"
946432Sas200622 #define	NT_INTERACTIVE_SIDSTR			"S-1-5-4"
95*11447Samw@Sun.COM #define	NT_LOGON_SESSION_SIDSTR			"S-1-5-5"
966432Sas200622 #define	NT_SERVICE_SIDSTR			"S-1-5-6"
976432Sas200622 #define	NT_ANONYMOUS_LOGON_SIDSTR		"S-1-5-7"
986432Sas200622 #define	NT_PROXY_SIDSTR				"S-1-5-8"
996432Sas200622 #define	NT_SERVER_LOGON_SIDSTR			"S-1-5-9"
1006432Sas200622 #define	NT_SELF_SIDSTR				"S-1-5-10"
1016432Sas200622 #define	NT_AUTHENTICATED_USER_SIDSTR		"S-1-5-11"
1026432Sas200622 #define	NT_RESTRICTED_CODE_SIDSTR		"S-1-5-12"
103*11447Samw@Sun.COM #define	NT_TERMINAL_SERVER_SIDSTR		"S-1-5-13"
1046432Sas200622 #define	NT_LOCAL_SYSTEM_SIDSTR			"S-1-5-18"
1056432Sas200622 #define	NT_NON_UNIQUE_SIDSTR			"S-1-5-21"
1066432Sas200622 #define	NT_BUILTIN_DOMAIN_SIDSTR		"S-1-5-32"
107*11447Samw@Sun.COM #define	NT_BUILTIN_CURRENT_OWNER_SIDSTR		"S-1-5-32-766"
108*11447Samw@Sun.COM #define	NT_BUILTIN_CURRENT_GROUP_SIDSTR		"S-1-5-32-767"
1096432Sas200622 
1106432Sas200622 
1116432Sas200622 /*
1126432Sas200622  * SID type indicators (SID_NAME_USE).
1136432Sas200622  */
1146432Sas200622 #define	SidTypeNull			0
1156432Sas200622 #define	SidTypeUser			1
1166432Sas200622 #define	SidTypeGroup			2
1176432Sas200622 #define	SidTypeDomain			3
1186432Sas200622 #define	SidTypeAlias			4
1196432Sas200622 #define	SidTypeWellKnownGroup		5
1206432Sas200622 #define	SidTypeDeletedAccount		6
1216432Sas200622 #define	SidTypeInvalid			7
1226432Sas200622 #define	SidTypeUnknown			8
1236432Sas200622 #define	SidTypeComputer			9
12411337SWilliam.Krier@Sun.COM #define	SidTypeLabel			10
1256432Sas200622 
1266432Sas200622 
1276432Sas200622 /*
1286432Sas200622  * Identifier authorities for various domains.
1296432Sas200622  */
1306432Sas200622 #define	NT_SID_NULL_AUTH		0
1316432Sas200622 #define	NT_SID_WORLD_AUTH		1
1326432Sas200622 #define	NT_SID_LOCAL_AUTH		2
1336432Sas200622 #define	NT_SID_CREATOR_AUTH		3
1346432Sas200622 #define	NT_SID_NON_UNIQUE_AUTH		4
1356432Sas200622 #define	NT_SID_NT_AUTH			5
1366432Sas200622 
1376432Sas200622 
1386432Sas200622 #define	NT_SECURITY_NULL_AUTH		{0, 0, 0, 0, 0, 0}
1396432Sas200622 #define	NT_SECURITY_WORLD_AUTH		{0, 0, 0, 0, 0, 1}
1406432Sas200622 #define	NT_SECURITY_LOCAL_AUTH		{0, 0, 0, 0, 0, 2}
1416432Sas200622 #define	NT_SECURITY_CREATOR_AUTH	{0, 0, 0, 0, 0, 3}
1426432Sas200622 #define	NT_SECURITY_NON_UNIQUE_AUTH	{0, 0, 0, 0, 0, 4}
1436432Sas200622 #define	NT_SECURITY_NT_AUTH		{0, 0, 0, 0, 0, 5}
1446432Sas200622 #define	NT_SECURITY_UNIX_AUTH		{0, 0, 0, 0, 0, 99}
1456432Sas200622 
1466432Sas200622 
1476432Sas200622 #define	SECURITY_NULL_RID			(0x00000000L)
1486432Sas200622 #define	SECURITY_WORLD_RID			(0x00000000L)
1496432Sas200622 #define	SECURITY_LOCAL_RID			(0X00000000L)
1506432Sas200622 
1516432Sas200622 #define	SECURITY_CREATOR_OWNER_RID		(0x00000000L)
1526432Sas200622 #define	SECURITY_CREATOR_GROUP_RID		(0x00000001L)
1536432Sas200622 #define	SECURITY_CREATOR_OWNER_SERVER_RID	(0x00000002L)
1546432Sas200622 #define	SECURITY_CREATOR_GROUP_SERVER_RID	(0x00000003L)
155*11447Samw@Sun.COM #define	SECURITY_OWNER_RIGHTS_RID		(0x00000004L)
156*11447Samw@Sun.COM #define	SECURITY_GROUP_RIGHTS_RID		(0x00000005L)
157*11447Samw@Sun.COM #define	SECURITY_CURRENT_OWNER_RID		(0x000002FEL)
158*11447Samw@Sun.COM #define	SECURITY_CURRENT_GROUP_RID		(0x000002FFL)
1596432Sas200622 
1606432Sas200622 #define	SECURITY_DIALUP_RID			(0x00000001L)
1616432Sas200622 #define	SECURITY_NETWORK_RID			(0x00000002L)
1626432Sas200622 #define	SECURITY_BATCH_RID			(0x00000003L)
1636432Sas200622 #define	SECURITY_INTERACTIVE_RID		(0x00000004L)
1646432Sas200622 #define	SECURITY_LOGON_IDS_RID			(0x00000005L)
1656432Sas200622 #define	SECURITY_LOGON_IDS_RID_COUNT		(3L)
1666432Sas200622 #define	SECURITY_SERVICE_RID			(0x00000006L)
1676432Sas200622 #define	SECURITY_ANONYMOUS_LOGON_RID		(0x00000007L)
1686432Sas200622 #define	SECURITY_PROXY_RID			(0x00000008L)
1696432Sas200622 #define	SECURITY_ENTERPRISE_CONTROLLERS_RID	(0x00000009L)
1706432Sas200622 #define	SECURITY_SERVER_LOGON_RID	SECURITY_ENTERPRISE_CONTROLLERS_RID
1716432Sas200622 #define	SECURITY_PRINCIPAL_SELF_RID		(0x0000000AL)
1726432Sas200622 #define	SECURITY_AUTHENTICATED_USER_RID		(0x0000000BL)
1736432Sas200622 #define	SECURITY_RESTRICTED_CODE_RID		(0x0000000CL)
1746432Sas200622 
1756432Sas200622 #define	SECURITY_LOCAL_SYSTEM_RID		(0x00000012L)
1766432Sas200622 #define	SECURITY_NT_NON_UNIQUE			(0x00000015L)
1776432Sas200622 #define	SECURITY_BUILTIN_DOMAIN_RID		(0x00000020L)
1786432Sas200622 
1796432Sas200622 
1806432Sas200622 #define	NT_SID_NON_UNIQUE_SUBAUTH 21
1816432Sas200622 
1826432Sas200622 
1836432Sas200622 /*
1846432Sas200622  * Common definition for a SID.
1856432Sas200622  */
1866432Sas200622 #define	NT_SID_REVISION		1
1876432Sas200622 #define	NT_SID_AUTH_MAX		6
1886432Sas200622 #define	NT_SID_SUBAUTH_MAX	15
1896432Sas200622 
1906432Sas200622 
1916432Sas200622 /*
1926432Sas200622  * Security Identifier (SID)
1936432Sas200622  *
1946432Sas200622  * The security identifier (SID) uniquely identifies a user, group or
1956432Sas200622  * a domain. It consists of a revision number, the identifier authority,
1966432Sas200622  * and a list of sub-authorities. The revision number is currently 1.
1976432Sas200622  * The identifier authority identifies which system issued the SID. The
1986432Sas200622  * sub-authorities of a domain SID uniquely identify a domain. A user
1996432Sas200622  * or group SID consists of a domain SID with the user or group id
2006432Sas200622  * appended. The user or group id (also known as a relative id (RID)
2016432Sas200622  * uniquely identifies a user within a domain. A user or group SID
2026432Sas200622  * uniquely identifies a user or group across all domains. The SidType
2036432Sas200622  * values identify the various types of SID.
2046432Sas200622  *
2056432Sas200622  *      1   1   1   1   1   1
2066432Sas200622  *      5   4   3   2   1   0   9   8   7   6   5   4   3   2   1   0
2076432Sas200622  *   +---------------------------------------------------------------+
2086432Sas200622  *   |      SubAuthorityCount        |Reserved1 (SBZ)|   Revision    |
2096432Sas200622  *   +---------------------------------------------------------------+
2106432Sas200622  *   |                   IdentifierAuthority[0]                      |
2116432Sas200622  *   +---------------------------------------------------------------+
2126432Sas200622  *   |                   IdentifierAuthority[1]                      |
2136432Sas200622  *   +---------------------------------------------------------------+
2146432Sas200622  *   |                   IdentifierAuthority[2]                      |
2156432Sas200622  *   +---------------------------------------------------------------+
2166432Sas200622  *   |                                                               |
2176432Sas200622  *   +- -  -  -  -  -  -  -  SubAuthority[]  -  -  -  -  -  -  -  - -+
2186432Sas200622  *   |                                                               |
2196432Sas200622  *   +---------------------------------------------------------------+
2206432Sas200622  *
2216432Sas200622  */
2226432Sas200622 /*
2236432Sas200622  * Note: NT defines the Identifier Authority as a separate
2246432Sas200622  * structure (SID_IDENTIFIER_AUTHORITY) containing a literal
2256432Sas200622  * definition of a 6 byte vector but the effect is the same
2266432Sas200622  * as defining it as a member value.
2276432Sas200622  */
2286432Sas200622 typedef struct smb_sid {
2296432Sas200622 	uint8_t sid_revision;
2306432Sas200622 	uint8_t sid_subauthcnt;
2316432Sas200622 	uint8_t sid_authority[NT_SID_AUTH_MAX];
2326432Sas200622 	uint32_t sid_subauth[ANY_SIZE_ARRAY];
2336432Sas200622 } smb_sid_t;
2346432Sas200622 
2356432Sas200622 /*
2368670SJose.Borrego@Sun.COM  * Only group attributes are defined. No user attributes defined.
2378670SJose.Borrego@Sun.COM  */
2388670SJose.Borrego@Sun.COM #define	SE_GROUP_MANDATORY		0x00000001
2398670SJose.Borrego@Sun.COM #define	SE_GROUP_ENABLED_BY_DEFAULT	0x00000002
2408670SJose.Borrego@Sun.COM #define	SE_GROUP_ENABLED		0x00000004
2418670SJose.Borrego@Sun.COM #define	SE_GROUP_OWNER			0x00000008
2428670SJose.Borrego@Sun.COM #define	SE_GROUP_USE_FOR_DENY_ONLY	0x00000010
2438670SJose.Borrego@Sun.COM #define	SE_GROUP_LOGON_ID		0xC0000000
2448670SJose.Borrego@Sun.COM 
2458670SJose.Borrego@Sun.COM /*
2468670SJose.Borrego@Sun.COM  * smb_id_t consists of both the Windows security identifier
2478670SJose.Borrego@Sun.COM  * and its corresponding POSIX/ephemeral ID.
2488670SJose.Borrego@Sun.COM  */
2498670SJose.Borrego@Sun.COM typedef struct smb_id {
2508670SJose.Borrego@Sun.COM 	uint32_t	i_attrs;
2518670SJose.Borrego@Sun.COM 	smb_sid_t	*i_sid;
2528670SJose.Borrego@Sun.COM 	uid_t		i_id;
2538670SJose.Borrego@Sun.COM } smb_id_t;
2548670SJose.Borrego@Sun.COM 
2558670SJose.Borrego@Sun.COM typedef struct smb_ids {
2568670SJose.Borrego@Sun.COM 	uint32_t	i_cnt;
2578670SJose.Borrego@Sun.COM 	smb_id_t	*i_ids;
2588670SJose.Borrego@Sun.COM } smb_ids_t;
2598670SJose.Borrego@Sun.COM 
2608670SJose.Borrego@Sun.COM /*
2616432Sas200622  * The maximum size of a SID in string format
2626432Sas200622  */
2636432Sas200622 #define	SMB_SID_STRSZ		256
2646432Sas200622 
2656432Sas200622 boolean_t smb_sid_isvalid(smb_sid_t *);
2666432Sas200622 int smb_sid_len(smb_sid_t *);
2676432Sas200622 smb_sid_t *smb_sid_dup(smb_sid_t *);
2686432Sas200622 smb_sid_t *smb_sid_splice(smb_sid_t *, uint32_t);
2696432Sas200622 int smb_sid_getrid(smb_sid_t *, uint32_t *);
2708670SJose.Borrego@Sun.COM smb_sid_t *smb_sid_split(smb_sid_t *, uint32_t *);
2716432Sas200622 boolean_t smb_sid_cmp(smb_sid_t *, smb_sid_t *);
2726432Sas200622 boolean_t smb_sid_islocal(smb_sid_t *);
2736432Sas200622 boolean_t smb_sid_indomain(smb_sid_t *, smb_sid_t *);
2746432Sas200622 void smb_sid_free(smb_sid_t *);
2756432Sas200622 int smb_sid_splitstr(char *, uint32_t *);
2766432Sas200622 void smb_sid_tostr(smb_sid_t *, char *);
2776432Sas200622 smb_sid_t *smb_sid_fromstr(char *);
2786432Sas200622 char *smb_sid_type2str(uint16_t);
2796432Sas200622 
2808670SJose.Borrego@Sun.COM void smb_ids_free(smb_ids_t *);
2818670SJose.Borrego@Sun.COM 
2826432Sas200622 #ifdef __cplusplus
2836432Sas200622 }
2846432Sas200622 #endif
2856432Sas200622 
2866432Sas200622 
2876432Sas200622 #endif /* _SMB_SID_H */
288