2 Unix SMB/CIFS implementation.
3 Lookup routines for well-known SIDs
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) Volker Lendecke 2005
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "../libcli/security/security.h"
31 struct sid_name_map_info
33 const struct dom_sid
*sid
;
35 const struct rid_name_map
*known_users
;
38 static const struct rid_name_map everyone_users
[] = {
42 static const struct rid_name_map local_authority_users
[] = {
44 { 1, "Console Logon" },
47 static const struct rid_name_map creator_owner_users
[] = {
48 { 0, "Creator Owner" },
49 { 1, "Creator Group" },
50 { 2, "Creator Owner Server" },
51 { 3, "Creator Group Server" },
52 { 4, "Owner Rights" },
55 static const struct rid_name_map nt_authority_users
[] = {
61 { 7, "Anonymous Logon"},
63 { 9, "Enterprise Domain Controllers"},
65 { 11, "Authenticated Users"},
67 { 13, "Terminal Server User"},
68 { 14, "Remote Interactive Logon"},
69 { 15, "This Organization"},
72 { 19, "Local Service"},
73 { 20, "Network Service"},
76 static struct sid_name_map_info special_domains
[] = {
77 { &global_sid_World_Domain
, "", everyone_users
},
78 { &global_sid_Local_Authority
, "", local_authority_users
},
79 { &global_sid_Creator_Owner_Domain
, "", creator_owner_users
},
80 { &global_sid_NT_Authority
, "NT Authority", nt_authority_users
},
81 { NULL
, NULL
, NULL
}};
83 bool sid_check_is_wellknown_domain(const struct dom_sid
*sid
, const char **name
)
87 for (i
=0; special_domains
[i
].sid
!= NULL
; i
++) {
88 if (dom_sid_equal(sid
, special_domains
[i
].sid
)) {
90 *name
= special_domains
[i
].name
;
98 bool sid_check_is_in_wellknown_domain(const struct dom_sid
*sid
)
100 struct dom_sid dom_sid
;
102 sid_copy(&dom_sid
, sid
);
103 sid_split_rid(&dom_sid
, NULL
);
105 return sid_check_is_wellknown_domain(&dom_sid
, NULL
);
108 /**************************************************************************
109 Looks up a known username from one of the known domains.
110 ***************************************************************************/
112 bool lookup_wellknown_sid(TALLOC_CTX
*mem_ctx
, const struct dom_sid
*sid
,
113 const char **domain
, const char **name
)
116 struct dom_sid dom_sid
;
118 const struct rid_name_map
*users
= NULL
;
120 sid_copy(&dom_sid
, sid
);
121 if (!sid_split_rid(&dom_sid
, &rid
)) {
122 DEBUG(2, ("Could not split rid from SID\n"));
126 for (i
=0; special_domains
[i
].sid
!= NULL
; i
++) {
127 if (dom_sid_equal(&dom_sid
, special_domains
[i
].sid
)) {
128 *domain
= talloc_strdup(mem_ctx
,
129 special_domains
[i
].name
);
130 users
= special_domains
[i
].known_users
;
136 DEBUG(10, ("SID %s is no special sid\n", sid_string_dbg(sid
)));
140 for (i
=0; users
[i
].name
!= NULL
; i
++) {
141 if (rid
== users
[i
].rid
) {
142 *name
= talloc_strdup(mem_ctx
, users
[i
].name
);
147 DEBUG(10, ("RID of special SID %s not found\n", sid_string_dbg(sid
)));
152 /**************************************************************************
153 Try and map a name to one of the well known SIDs.
154 ***************************************************************************/
156 bool lookup_wellknown_name(TALLOC_CTX
*mem_ctx
, const char *name
,
157 struct dom_sid
*sid
, const char **domain
)
161 DEBUG(10,("map_name_to_wellknown_sid: looking up %s\n", name
));
163 for (i
=0; special_domains
[i
].sid
!= NULL
; i
++) {
164 const struct rid_name_map
*users
=
165 special_domains
[i
].known_users
;
170 for (j
=0; users
[j
].name
!= NULL
; j
++) {
171 if ( strequal(users
[j
].name
, name
) ) {
172 sid_compose(sid
, special_domains
[i
].sid
,
174 *domain
= talloc_strdup(
175 mem_ctx
, special_domains
[i
].name
);