2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Luke Kenneth Caseson Leighton 1998-1999
6 Copyright (C) Jeremy Allison 1999
7 Copyright (C) Stefan (metze) Metzmacher 2002
8 Copyright (C) Simo Sorce 2002
9 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005
10 Copyright (C) Andrew Bartlett 2010
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "lib/util/samba_util.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
29 #include "../librpc/gen_ndr/netlogon.h"
30 #include "../libcli/security/security.h"
31 #include "auth/auth.h"
38 * Some useful sids, more well known sids can be found at
39 * http://support.microsoft.com/kb/243330/EN-US/
44 const struct dom_sid global_sid_World_Domain
= /* Everyone domain */
45 { 1, 0, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
47 const struct dom_sid global_sid_World
= /* Everyone */
48 { 1, 1, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
50 const struct dom_sid global_sid_Local_Authority
= /* Local Authority */
51 { 1, 0, {0,0,0,0,0,2}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
53 const struct dom_sid global_sid_Creator_Owner_Domain
= /* Creator Owner domain */
54 { 1, 0, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
56 const struct dom_sid global_sid_NT_Authority
= /* NT Authority */
57 { 1, 0, {0,0,0,0,0,5}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
59 const struct dom_sid global_sid_System
= /* System */
60 { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
62 const struct dom_sid global_sid_NULL
= /* NULL sid */
63 { 1, 1, {0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
65 const struct dom_sid global_sid_Self
= /* SELF */
66 { 1, 1, {0,0,0,0,0,5}, {10,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
68 const struct dom_sid global_sid_Authenticated_Users
= /* All authenticated rids */
69 { 1, 1, {0,0,0,0,0,5}, {11,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
71 /* for documentation S-1-5-12 */
72 const struct dom_sid global_sid_Restricted
= /* Restricted Code */
73 { 1, 1, {0,0,0,0,0,5}, {12,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
77 const struct dom_sid global_sid_Asserted_Identity
= /* Asserted Identity */
78 { 1, 0, {0,0,0,0,0,18}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
80 const struct dom_sid global_sid_Asserted_Identity_Authentication_Authority
= /* Asserted Identity Authentication Authority */
81 { 1, 1, {0,0,0,0,0,18}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
83 const struct dom_sid global_sid_Asserted_Identity_Service
= /* Asserted Identity Service */
84 { 1, 1, {0,0,0,0,0,18}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
87 const struct dom_sid global_sid_Fresh_Public_Key_Identity
= /* Fresh Public Key Identity */
88 { 1, 1, {0,0,0,0,0,18}, {3,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
91 const struct dom_sid global_sid_Network
= /* Network rids */
92 { 1, 1, {0,0,0,0,0,5}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
95 const struct dom_sid global_sid_Creator_Owner
= /* Creator Owner */
96 { 1, 1, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
98 const struct dom_sid global_sid_Creator_Group
= /* Creator Group */
99 { 1, 1, {0,0,0,0,0,3}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
101 const struct dom_sid global_sid_Owner_Rights
= /* Owner Rights */
102 { 1, 1, {0,0,0,0,0,3}, {4,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
104 const struct dom_sid global_sid_Anonymous
= /* Anonymous login */
105 { 1, 1, {0,0,0,0,0,5}, {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
107 const struct dom_sid global_sid_Enterprise_DCs
= /* Enterprise DCs */
108 { 1, 1, {0,0,0,0,0,5}, {9,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
109 /* S-1-5-21-0-0-0-496 */
110 const struct dom_sid global_sid_Compounded_Authentication
= /* Compounded Authentication */
111 {1, 5, {0,0,0,0,0,5}, {21,0,0,0,496,0,0,0,0,0,0,0,0,0,0}};
112 /* S-1-5-21-0-0-0-497 */
113 const struct dom_sid global_sid_Claims_Valid
= /* Claims Valid */
114 {1, 5, {0,0,0,0,0,5}, {21,0,0,0,497,0,0,0,0,0,0,0,0,0,0}};
116 const struct dom_sid global_sid_Builtin
= /* Local well-known domain */
117 { 1, 1, {0,0,0,0,0,5}, {32,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
119 const struct dom_sid global_sid_Builtin_Administrators
= /* Builtin administrators */
120 { 1, 2, {0,0,0,0,0,5}, {32,544,0,0,0,0,0,0,0,0,0,0,0,0,0}};
122 const struct dom_sid global_sid_Builtin_Users
= /* Builtin users */
123 { 1, 2, {0,0,0,0,0,5}, {32,545,0,0,0,0,0,0,0,0,0,0,0,0,0}};
125 const struct dom_sid global_sid_Builtin_Guests
= /* Builtin guest users */
126 { 1, 2, {0,0,0,0,0,5}, {32,546,0,0,0,0,0,0,0,0,0,0,0,0,0}};
128 const struct dom_sid global_sid_Builtin_Power_Users
= /* Builtin power users */
129 { 1, 2, {0,0,0,0,0,5}, {32,547,0,0,0,0,0,0,0,0,0,0,0,0,0}};
131 const struct dom_sid global_sid_Builtin_Account_Operators
= /* Builtin account operators */
132 { 1, 2, {0,0,0,0,0,5}, {32,548,0,0,0,0,0,0,0,0,0,0,0,0,0}};
134 const struct dom_sid global_sid_Builtin_Server_Operators
= /* Builtin server operators */
135 { 1, 2, {0,0,0,0,0,5}, {32,549,0,0,0,0,0,0,0,0,0,0,0,0,0}};
137 const struct dom_sid global_sid_Builtin_Print_Operators
= /* Builtin print operators */
138 { 1, 2, {0,0,0,0,0,5}, {32,550,0,0,0,0,0,0,0,0,0,0,0,0,0}};
140 const struct dom_sid global_sid_Builtin_Backup_Operators
= /* Builtin backup operators */
141 { 1, 2, {0,0,0,0,0,5}, {32,551,0,0,0,0,0,0,0,0,0,0,0,0,0}};
143 const struct dom_sid global_sid_Builtin_Replicator
= /* Builtin replicator */
144 { 1, 2, {0,0,0,0,0,5}, {32,552,0,0,0,0,0,0,0,0,0,0,0,0,0}};
146 const struct dom_sid global_sid_Builtin_PreWin2kAccess
= /* Builtin pre win2k access */
147 { 1, 2, {0,0,0,0,0,5}, {32,554,0,0,0,0,0,0,0,0,0,0,0,0,0}};
150 const struct dom_sid global_sid_Unix_Users
= /* Unmapped Unix users */
151 { 1, 1, {0,0,0,0,0,22}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
153 const struct dom_sid global_sid_Unix_Groups
= /* Unmapped Unix groups */
154 { 1, 1, {0,0,0,0,0,22}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
157 * http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx
160 const struct dom_sid global_sid_Unix_NFS
= /* MS NFS and Apple style */
161 { 1, 1, {0,0,0,0,0,5}, {88,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
163 const struct dom_sid global_sid_Unix_NFS_Users
= /* Unix uid, MS NFS and Apple style */
164 { 1, 2, {0,0,0,0,0,5}, {88,1,0,0,0,0,0,0,0,0,0,0,0,0,0}};
166 const struct dom_sid global_sid_Unix_NFS_Groups
= /* Unix gid, MS NFS and Apple style */
167 { 1, 2, {0,0,0,0,0,5}, {88,2,0,0,0,0,0,0,0,0,0,0,0,0,0}};
169 const struct dom_sid global_sid_Unix_NFS_Mode
= /* Unix mode */
170 { 1, 2, {0,0,0,0,0,5}, {88,3,0,0,0,0,0,0,0,0,0,0,0,0,0}};
171 /* Unused, left here for documentary purposes */
173 const struct dom_sid global_sid_Unix_NFS_Other
= /* Unix other, MS NFS and Apple style */
174 { 1, 2, {0,0,0,0,0,5}, {88,4,0,0,0,0,0,0,0,0,0,0,0,0,0}};
177 /* Information passing via security token */
178 const struct dom_sid global_sid_Samba_SMB3
=
179 {1, 1, {0,0,0,0,0,22}, {1397571891, }};
181 const struct dom_sid global_sid_Samba_NPA_Flags
= {1,
188 /* Unused, left here for documentary purposes */
190 #define SECURITY_NULL_SID_AUTHORITY 0
191 #define SECURITY_WORLD_SID_AUTHORITY 1
192 #define SECURITY_LOCAL_SID_AUTHORITY 2
193 #define SECURITY_CREATOR_SID_AUTHORITY 3
194 #define SECURITY_NT_AUTHORITY 5
197 static struct dom_sid system_sid_array
[1] =
198 { { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} };
199 static const struct security_token system_token
= {
200 .num_sids
= ARRAY_SIZE(system_sid_array
),
201 .sids
= system_sid_array
,
202 .privilege_mask
= SE_ALL_PRIVS
205 /****************************************************************************
206 Lookup string names for SID types.
207 ****************************************************************************/
209 const char *sid_type_lookup(uint32_t sid_type
)
212 case SID_NAME_USE_NONE
:
218 case SID_NAME_DOM_GRP
:
219 return "Domain Group";
221 case SID_NAME_DOMAIN
:
225 return "Local Group";
227 case SID_NAME_WKN_GRP
:
228 return "Well-known Group";
230 case SID_NAME_DELETED
:
231 return "Deleted Account";
233 case SID_NAME_INVALID
:
234 return "Invalid Account";
236 case SID_NAME_UNKNOWN
:
239 case SID_NAME_COMPUTER
:
243 return "Mandatory Label";
248 return "SID *TYPE* is INVALID";
251 /**************************************************************************
252 Create the SYSTEM token.
253 ***************************************************************************/
255 const struct security_token
*get_system_token(void)
257 return &system_token
;
260 bool sid_compose(struct dom_sid
*dst
, const struct dom_sid
*domain_sid
, uint32_t rid
)
262 sid_copy(dst
, domain_sid
);
263 return sid_append_rid(dst
, rid
);
266 /*****************************************************************
267 Removes the last rid from the end of a sid
268 *****************************************************************/
270 bool sid_split_rid(struct dom_sid
*sid
, uint32_t *rid
)
272 if (sid
->num_auths
> 0) {
275 *rid
= sid
->sub_auths
[sid
->num_auths
];
282 /*****************************************************************
283 Return the last rid from the end of a sid
284 *****************************************************************/
286 bool sid_peek_rid(const struct dom_sid
*sid
, uint32_t *rid
)
291 if (sid
->num_auths
> 0) {
292 *rid
= sid
->sub_auths
[sid
->num_auths
- 1];
298 /*****************************************************************
299 Return the last rid from the end of a sid
300 and check the sid against the exp_dom_sid
301 *****************************************************************/
303 bool sid_peek_check_rid(const struct dom_sid
*exp_dom_sid
, const struct dom_sid
*sid
, uint32_t *rid
)
305 if (!exp_dom_sid
|| !sid
|| !rid
)
308 if (sid
->num_auths
!= (exp_dom_sid
->num_auths
+1)) {
312 if (dom_sid_compare_domain(exp_dom_sid
, sid
)!=0){
317 return sid_peek_rid(sid
, rid
);
320 /*****************************************************************
322 *****************************************************************/
324 void sid_copy(struct dom_sid
*dst
, const struct dom_sid
*src
)
328 *dst
= (struct dom_sid
) {
329 .sid_rev_num
= src
->sid_rev_num
,
330 .num_auths
= src
->num_auths
,
333 memcpy(&dst
->id_auth
[0], &src
->id_auth
[0], sizeof(src
->id_auth
));
335 for (i
= 0; i
< src
->num_auths
; i
++)
336 dst
->sub_auths
[i
] = src
->sub_auths
[i
];
339 /*****************************************************************
340 Parse a on-the-wire SID to a struct dom_sid.
341 *****************************************************************/
343 ssize_t
sid_parse(const uint8_t *inbuf
, size_t len
, struct dom_sid
*sid
)
345 DATA_BLOB in
= data_blob_const(inbuf
, len
);
346 enum ndr_err_code ndr_err
;
348 ndr_err
= ndr_pull_struct_blob_all(
349 &in
, NULL
, sid
, (ndr_pull_flags_fn_t
)ndr_pull_dom_sid
);
350 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
353 return ndr_size_dom_sid(sid
, 0);
356 /********************************************************************
357 Add SID to an array of SIDs
358 ********************************************************************/
360 NTSTATUS
add_sid_to_array(TALLOC_CTX
*mem_ctx
, const struct dom_sid
*sid
,
361 struct dom_sid
**sids
, uint32_t *num
)
365 if ((*num
) == UINT32_MAX
) {
366 return NT_STATUS_INTEGER_OVERFLOW
;
369 tmp
= talloc_realloc(mem_ctx
, *sids
, struct dom_sid
, (*num
)+1);
372 return NT_STATUS_NO_MEMORY
;
376 sid_copy(&((*sids
)[*num
]), sid
);
383 /********************************************************************
384 Add SID to an array of SIDs ensuring that it is not already there
385 ********************************************************************/
387 NTSTATUS
add_sid_to_array_unique(TALLOC_CTX
*mem_ctx
, const struct dom_sid
*sid
,
388 struct dom_sid
**sids
, uint32_t *num_sids
)
392 contains
= sids_contains_sid(*sids
, *num_sids
, sid
);
397 return add_sid_to_array(mem_ctx
, sid
, sids
, num_sids
);
401 * Appends a SID and attribute to an array of auth_SidAttr.
403 * @param [in] mem_ctx Talloc memory context on which to allocate the array.
404 * @param [in] sid The SID to append.
405 * @param [in] attrs SE_GROUP_* flags to go with the SID.
406 * @param [inout] sids A pointer to the auth_SidAttr array.
407 * @param [inout] num A pointer to the size of the auth_SidArray array.
408 * @returns NT_STATUS_OK on success.
410 NTSTATUS
add_sid_to_array_attrs(TALLOC_CTX
*mem_ctx
,
411 const struct dom_sid
*sid
, uint32_t attrs
,
412 struct auth_SidAttr
**sids
, uint32_t *num
)
414 struct auth_SidAttr
*tmp
= NULL
;
416 if ((*num
) == UINT32_MAX
) {
417 return NT_STATUS_INTEGER_OVERFLOW
;
420 tmp
= talloc_realloc(mem_ctx
, *sids
, struct auth_SidAttr
, (*num
)+1);
423 return NT_STATUS_NO_MEMORY
;
427 sid_copy(&((*sids
)[*num
].sid
), sid
);
428 (*sids
)[*num
].attrs
= attrs
;
436 * Appends a SID and attribute to an array of auth_SidAttr,
437 * ensuring that it is not already there.
439 * @param [in] mem_ctx Talloc memory context on which to allocate the array.
440 * @param [in] sid The SID to append.
441 * @param [in] attrs SE_GROUP_* flags to go with the SID.
442 * @param [inout] sids A pointer to the auth_SidAttr array.
443 * @param [inout] num_sids A pointer to the size of the auth_SidArray array.
444 * @returns NT_STATUS_OK on success.
446 NTSTATUS
add_sid_to_array_attrs_unique(TALLOC_CTX
*mem_ctx
,
447 const struct dom_sid
*sid
, uint32_t attrs
,
448 struct auth_SidAttr
**sids
, uint32_t *num_sids
)
452 contains
= sids_contains_sid_attrs(*sids
, *num_sids
, sid
, attrs
);
457 return add_sid_to_array_attrs(mem_ctx
, sid
, attrs
, sids
, num_sids
);
460 /********************************************************************
461 Remove SID from an array
462 ********************************************************************/
464 void del_sid_from_array(const struct dom_sid
*sid
, struct dom_sid
**sids
,
467 struct dom_sid
*sid_list
= *sids
;
470 for ( i
=0; i
<*num
; i
++ ) {
472 /* if we find the SID, then decrement the count
473 and break out of the loop */
475 if (dom_sid_equal(sid
, &sid_list
[i
])) {
481 /* This loop will copy the remainder of the array
482 if i < num of sids in the array */
484 for ( ; i
<*num
; i
++ ) {
485 sid_copy( &sid_list
[i
], &sid_list
[i
+1] );
489 bool add_rid_to_array_unique(TALLOC_CTX
*mem_ctx
,
490 uint32_t rid
, uint32_t **pp_rids
, size_t *p_num
)
494 for (i
=0; i
<*p_num
; i
++) {
495 if ((*pp_rids
)[i
] == rid
)
499 *pp_rids
= talloc_realloc(mem_ctx
, *pp_rids
, uint32_t, *p_num
+1);
501 if (*pp_rids
== NULL
) {
506 (*pp_rids
)[*p_num
] = rid
;
511 bool is_null_sid(const struct dom_sid
*sid
)
513 static const struct dom_sid null_sid
= {0};
514 return dom_sid_equal(sid
, &null_sid
);
518 * Return true if an array of SIDs contains a certain SID.
520 * @param [in] sids The SID array.
521 * @param [in] num_sids The size of the SID array.
522 * @param [in] sid The SID in question.
523 * @returns true if the array contains the SID.
525 bool sids_contains_sid(const struct dom_sid
*sids
,
526 const uint32_t num_sids
,
527 const struct dom_sid
*sid
)
531 for (i
= 0; i
< num_sids
; i
++) {
532 if (dom_sid_equal(&sids
[i
], sid
)) {
540 * Return true if an array of auth_SidAttr contains a certain SID.
542 * @param [in] sids The auth_SidAttr array.
543 * @param [in] num_sids The size of the auth_SidArray array.
544 * @param [in] sid The SID in question.
545 * @returns true if the array contains the SID.
547 bool sid_attrs_contains_sid(const struct auth_SidAttr
*sids
,
548 const uint32_t num_sids
,
549 const struct dom_sid
*sid
)
553 for (i
= 0; i
< num_sids
; i
++) {
554 if (dom_sid_equal(&sids
[i
].sid
, sid
)) {
562 * Return true if an array of auth_SidAttr contains a certain SID with certain
565 * @param [in] sids The auth_SidAttr array.
566 * @param [in] num_sids The size of the auth_SidArray array.
567 * @param [in] sid The SID in question.
568 * @param [in] attrs The attributes of the SID.
569 * @returns true if the array contains the SID.
571 bool sids_contains_sid_attrs(const struct auth_SidAttr
*sids
,
572 const uint32_t num_sids
,
573 const struct dom_sid
*sid
,
578 for (i
= 0; i
< num_sids
; i
++) {
579 if (attrs
!= sids
[i
].attrs
) {
582 if (!dom_sid_equal(&sids
[i
].sid
, sid
)) {
592 * See [MS-LSAT] 3.1.1.1.1 Predefined Translation Database and Corresponding View
594 struct predefined_name_mapping
{
596 enum lsa_SidType type
;
600 struct predefined_domain_mapping
{
604 const struct predefined_name_mapping
*names
;
607 /* S-1-${AUTHORITY} */
608 #define _SID0(authority) \
609 { 1, 0, {0,0,0,0,0,authority}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
610 /* S-1-${AUTHORITY}-${SUB1} */
611 #define _SID1(authority,sub1) \
612 { 1, 1, {0,0,0,0,0,authority}, {sub1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
613 /* S-1-${AUTHORITY}-${SUB1}-${SUB2} */
614 #define _SID2(authority,sub1,sub2) \
615 { 1, 2, {0,0,0,0,0,authority}, {sub1,sub2,0,0,0,0,0,0,0,0,0,0,0,0,0}}
620 static const struct predefined_name_mapping predefined_names_S_1_0
[] = {
623 .type
= SID_NAME_WKN_GRP
,
624 .sid
= _SID1(0, 0), /* S-1-0-0 */
631 static const struct predefined_name_mapping predefined_names_S_1_1
[] = {
634 .type
= SID_NAME_WKN_GRP
,
635 .sid
= _SID1(1, 0), /* S-1-1-0 */
642 static const struct predefined_name_mapping predefined_names_S_1_2
[] = {
645 .type
= SID_NAME_WKN_GRP
,
646 .sid
= _SID1(2, 0), /* S-1-2-0 */
653 static const struct predefined_name_mapping predefined_names_S_1_3
[] = {
655 .name
= "CREATOR OWNER",
656 .type
= SID_NAME_WKN_GRP
,
657 .sid
= _SID1(3, 0), /* S-1-3-0 */
660 .name
= "CREATOR GROUP",
661 .type
= SID_NAME_WKN_GRP
,
662 .sid
= _SID1(3, 1), /* S-1-3-1 */
665 .name
= "CREATOR OWNER SERVER",
666 .type
= SID_NAME_WKN_GRP
,
667 .sid
= _SID1(3, 0), /* S-1-3-2 */
670 .name
= "CREATOR GROUP SERVER",
671 .type
= SID_NAME_WKN_GRP
,
672 .sid
= _SID1(3, 1), /* S-1-3-3 */
675 .name
= "OWNER RIGHTS",
676 .type
= SID_NAME_WKN_GRP
,
677 .sid
= _SID1(3, 4), /* S-1-3-4 */
682 * S-1-5 only 'NT Pseudo Domain'
684 static const struct predefined_name_mapping predefined_names_S_1_5p
[] = {
686 .name
= "NT Pseudo Domain",
687 .type
= SID_NAME_DOMAIN
,
688 .sid
= _SID0(5), /* S-1-5 */
693 * S-1-5 'NT AUTHORITY'
695 static const struct predefined_name_mapping predefined_names_S_1_5a
[] = {
698 .type
= SID_NAME_WKN_GRP
,
699 .sid
= _SID1(5, 1), /* S-1-5-1 */
703 .type
= SID_NAME_WKN_GRP
,
704 .sid
= _SID1(5, 2), /* S-1-5-2 */
708 .type
= SID_NAME_WKN_GRP
,
709 .sid
= _SID1(5, 3), /* S-1-5-3 */
712 .name
= "INTERACTIVE",
713 .type
= SID_NAME_WKN_GRP
,
714 .sid
= _SID1(5, 4), /* S-1-5-4 */
718 .type
= SID_NAME_WKN_GRP
,
719 .sid
= _SID1(5, 6), /* S-1-5-6 */
722 .name
= "ANONYMOUS LOGON",
723 .type
= SID_NAME_WKN_GRP
,
724 .sid
= _SID1(5, 7), /* S-1-5-7 */
728 .type
= SID_NAME_WKN_GRP
,
729 .sid
= _SID1(5, 8), /* S-1-5-8 */
732 .name
= "ENTERPRISE DOMAIN CONTROLLERS",
733 .type
= SID_NAME_WKN_GRP
,
734 .sid
= _SID1(5, 9), /* S-1-5-9 */
738 .type
= SID_NAME_WKN_GRP
,
739 .sid
= _SID1(5, 10), /* S-1-5-10 */
742 .name
= "Authenticated Users",
743 .type
= SID_NAME_WKN_GRP
,
744 .sid
= _SID1(5, 11), /* S-1-5-11 */
747 .name
= "RESTRICTED",
748 .type
= SID_NAME_WKN_GRP
,
749 .sid
= _SID1(5, 12), /* S-1-5-12 */
752 .name
= "TERMINAL SERVER USER",
753 .type
= SID_NAME_WKN_GRP
,
754 .sid
= _SID1(5, 13), /* S-1-5-13 */
757 .name
= "REMOTE INTERACTIVE LOGON",
758 .type
= SID_NAME_WKN_GRP
,
759 .sid
= _SID1(5, 14), /* S-1-5-14 */
762 .name
= "This Organization",
763 .type
= SID_NAME_WKN_GRP
,
764 .sid
= _SID1(5, 15), /* S-1-5-15 */
768 .type
= SID_NAME_WKN_GRP
,
769 .sid
= _SID1(5, 17), /* S-1-5-17 */
773 .type
= SID_NAME_WKN_GRP
,
774 .sid
= _SID1(5, 18), /* S-1-5-18 */
777 .name
= "LOCAL SERVICE",
778 .type
= SID_NAME_WKN_GRP
,
779 .sid
= _SID1(5, 19), /* S-1-5-19 */
782 .name
= "NETWORK SERVICE",
783 .type
= SID_NAME_WKN_GRP
,
784 .sid
= _SID1(5, 20), /* S-1-5-20 */
787 .name
= "WRITE RESTRICTED",
788 .type
= SID_NAME_WKN_GRP
,
789 .sid
= _SID1(5, 33), /* S-1-5-33 */
792 .name
= "Other Organization",
793 .type
= SID_NAME_WKN_GRP
,
794 .sid
= _SID1(5, 1000), /* S-1-5-1000 */
801 static const struct predefined_name_mapping predefined_names_S_1_5_32
[] = {
804 .type
= SID_NAME_DOMAIN
,
805 .sid
= _SID1(5, 32), /* S-1-5-32 */
812 static const struct predefined_name_mapping predefined_names_S_1_5_64
[] = {
814 .name
= "NTLM Authentication",
815 .type
= SID_NAME_WKN_GRP
,
816 .sid
= _SID2(5, 64, 10), /* S-1-5-64-10 */
819 .name
= "SChannel Authentication",
820 .type
= SID_NAME_WKN_GRP
,
821 .sid
= _SID2(5, 64, 14), /* S-1-5-64-14 */
824 .name
= "Digest Authentication",
825 .type
= SID_NAME_WKN_GRP
,
826 .sid
= _SID2(5, 64, 21), /* S-1-5-64-21 */
833 static const struct predefined_name_mapping predefined_names_S_1_7
[] = {
836 .type
= SID_NAME_DOMAIN
,
837 .sid
= _SID0(7), /* S-1-7 */
844 static const struct predefined_name_mapping predefined_names_S_1_16
[] = {
846 .name
= "Mandatory Label",
847 .type
= SID_NAME_DOMAIN
,
848 .sid
= _SID0(16), /* S-1-16 */
851 .name
= "Untrusted Mandatory Level",
852 .type
= SID_NAME_LABEL
,
853 .sid
= _SID1(16, 0), /* S-1-16-0 */
856 .name
= "Low Mandatory Level",
857 .type
= SID_NAME_LABEL
,
858 .sid
= _SID1(16, 4096), /* S-1-16-4096 */
861 .name
= "Medium Mandatory Level",
862 .type
= SID_NAME_LABEL
,
863 .sid
= _SID1(16, 8192), /* S-1-16-8192 */
866 .name
= "High Mandatory Level",
867 .type
= SID_NAME_LABEL
,
868 .sid
= _SID1(16, 12288), /* S-1-16-12288 */
871 .name
= "System Mandatory Level",
872 .type
= SID_NAME_LABEL
,
873 .sid
= _SID1(16, 16384), /* S-1-16-16384 */
876 .name
= "Protected Process Mandatory Level",
877 .type
= SID_NAME_LABEL
,
878 .sid
= _SID1(16, 20480), /* S-1-16-20480 */
882 static const struct predefined_domain_mapping predefined_domains
[] = {
885 .sid
= _SID0(0), /* S-1-0 */
886 .num_names
= ARRAY_SIZE(predefined_names_S_1_0
),
887 .names
= predefined_names_S_1_0
,
891 .sid
= _SID0(1), /* S-1-1 */
892 .num_names
= ARRAY_SIZE(predefined_names_S_1_1
),
893 .names
= predefined_names_S_1_1
,
897 .sid
= _SID0(2), /* S-1-2 */
898 .num_names
= ARRAY_SIZE(predefined_names_S_1_2
),
899 .names
= predefined_names_S_1_2
,
903 .sid
= _SID0(3), /* S-1-3 */
904 .num_names
= ARRAY_SIZE(predefined_names_S_1_3
),
905 .names
= predefined_names_S_1_3
,
909 .sid
= _SID0(3), /* S-1-3 */
910 .num_names
= ARRAY_SIZE(predefined_names_S_1_3
),
911 .names
= predefined_names_S_1_3
,
914 * S-1-5 is split here
916 * 'NT Pseudo Domain' has precedence before 'NT AUTHORITY'.
918 * In a LookupSids with multiple sids e.g. S-1-5 and S-1-5-7
919 * the domain section (struct lsa_DomainInfo) gets
920 * 'NT Pseudo Domain' with S-1-5. If asked in reversed order
921 * S-1-5-7 and then S-1-5, you get struct lsa_DomainInfo
922 * with 'NT AUTHORITY' and S-1-5.
925 .domain
= "NT Pseudo Domain",
926 .sid
= _SID0(5), /* S-1-5 */
927 .num_names
= ARRAY_SIZE(predefined_names_S_1_5p
),
928 .names
= predefined_names_S_1_5p
,
931 .domain
= "NT AUTHORITY",
932 .sid
= _SID0(5), /* S-1-5 */
933 .num_names
= ARRAY_SIZE(predefined_names_S_1_5a
),
934 .names
= predefined_names_S_1_5a
,
938 .sid
= _SID1(5, 32), /* S-1-5-32 */
939 .num_names
= ARRAY_SIZE(predefined_names_S_1_5_32
),
940 .names
= predefined_names_S_1_5_32
,
943 * 'NT AUTHORITY' again with S-1-5-64 this time
946 .domain
= "NT AUTHORITY",
947 .sid
= _SID1(5, 64), /* S-1-5-64 */
948 .num_names
= ARRAY_SIZE(predefined_names_S_1_5_64
),
949 .names
= predefined_names_S_1_5_64
,
952 .domain
= "Internet$",
953 .sid
= _SID0(7), /* S-1-7 */
954 .num_names
= ARRAY_SIZE(predefined_names_S_1_7
),
955 .names
= predefined_names_S_1_7
,
958 .domain
= "Mandatory Label",
959 .sid
= _SID0(16), /* S-1-16 */
960 .num_names
= ARRAY_SIZE(predefined_names_S_1_16
),
961 .names
= predefined_names_S_1_16
,
965 NTSTATUS
dom_sid_lookup_predefined_name(const char *name
,
966 const struct dom_sid
**sid
,
967 enum lsa_SidType
*type
,
968 const struct dom_sid
**authority_sid
,
969 const char **authority_name
)
972 const char *domain
= "";
973 size_t domain_len
= 0;
978 *type
= SID_NAME_UNKNOWN
;
979 *authority_sid
= NULL
;
980 *authority_name
= NULL
;
986 p
= strchr(name
, '\\');
989 domain_len
= PTR_DIFF(p
, domain
);
993 match
= strequal(name
, "");
996 * Strange, but that's what W2012R2 does.
1001 for (di
= 0; di
< ARRAY_SIZE(predefined_domains
); di
++) {
1002 const struct predefined_domain_mapping
*d
=
1003 &predefined_domains
[di
];
1006 if (domain_len
!= 0) {
1009 cmp
= strncasecmp(d
->domain
, domain
, domain_len
);
1015 for (ni
= 0; ni
< d
->num_names
; ni
++) {
1016 const struct predefined_name_mapping
*n
=
1019 match
= strequal(n
->name
, name
);
1026 *authority_sid
= &d
->sid
;
1027 *authority_name
= d
->domain
;
1028 return NT_STATUS_OK
;
1032 return NT_STATUS_NONE_MAPPED
;
1035 bool dom_sid_lookup_is_predefined_domain(const char *domain
)
1040 if (domain
== NULL
) {
1044 match
= strequal(domain
, "");
1047 * Strange, but that's what W2012R2 does.
1052 for (di
= 0; di
< ARRAY_SIZE(predefined_domains
); di
++) {
1053 const struct predefined_domain_mapping
*d
=
1054 &predefined_domains
[di
];
1057 cmp
= strcasecmp(d
->domain
, domain
);
1068 NTSTATUS
dom_sid_lookup_predefined_sid(const struct dom_sid
*sid
,
1070 enum lsa_SidType
*type
,
1071 const struct dom_sid
**authority_sid
,
1072 const char **authority_name
)
1075 bool match_domain
= false;
1078 *type
= SID_NAME_UNKNOWN
;
1079 *authority_sid
= NULL
;
1080 *authority_name
= NULL
;
1083 return NT_STATUS_INVALID_SID
;
1086 for (di
= 0; di
< ARRAY_SIZE(predefined_domains
); di
++) {
1087 const struct predefined_domain_mapping
*d
=
1088 &predefined_domains
[di
];
1092 cmp
= dom_sid_compare_auth(&d
->sid
, sid
);
1097 match_domain
= true;
1099 for (ni
= 0; ni
< d
->num_names
; ni
++) {
1100 const struct predefined_name_mapping
*n
=
1103 cmp
= dom_sid_compare(&n
->sid
, sid
);
1110 *authority_sid
= &d
->sid
;
1111 *authority_name
= d
->domain
;
1112 return NT_STATUS_OK
;
1116 if (!match_domain
) {
1117 return NT_STATUS_INVALID_SID
;
1120 return NT_STATUS_NONE_MAPPED
;