source: vendor/3.6.23/source3/lib/util_wellknown.c

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 4.6 KB
Line 
1/*
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
8
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.
13
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.
18
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/>.
21*/
22
23#include "includes.h"
24#include "../libcli/security/security.h"
25
26struct rid_name_map {
27 uint32 rid;
28 const char *name;
29};
30
31struct sid_name_map_info
32{
33 const struct dom_sid *sid;
34 const char *name;
35 const struct rid_name_map *known_users;
36};
37
38static const struct rid_name_map everyone_users[] = {
39 { 0, "Everyone" },
40 { 0, NULL}};
41
42static const struct rid_name_map creator_owner_users[] = {
43 { 0, "Creator Owner" },
44 { 1, "Creator Group" },
45 { 0, NULL}};
46
47static const struct rid_name_map nt_authority_users[] = {
48 { 1, "Dialup" },
49 { 2, "Network"},
50 { 3, "Batch"},
51 { 4, "Interactive"},
52 { 6, "Service"},
53 { 7, "AnonymousLogon"},
54 { 7, "Anonymous Logon"},
55 { 8, "Proxy"},
56 { 9, "ServerLogon"},
57 { 10, "Self"},
58 { 11, "Authenticated Users"},
59 { 12, "Restricted"},
60 { 13, "Terminal Server User"},
61 { 14, "Remote Interactive Logon"},
62 { 15, "This Organization"},
63 { 18, "SYSTEM"},
64 { 19, "Local Service"},
65 { 20, "Network Service"},
66 { 0, NULL}};
67
68static struct sid_name_map_info special_domains[] = {
69 { &global_sid_World_Domain, "", everyone_users },
70 { &global_sid_Creator_Owner_Domain, "", creator_owner_users },
71 { &global_sid_NT_Authority, "NT Authority", nt_authority_users },
72 { NULL, NULL, NULL }};
73
74bool sid_check_is_wellknown_domain(const struct dom_sid *sid, const char **name)
75{
76 int i;
77
78 for (i=0; special_domains[i].sid != NULL; i++) {
79 if (dom_sid_equal(sid, special_domains[i].sid)) {
80 if (name != NULL) {
81 *name = special_domains[i].name;
82 }
83 return True;
84 }
85 }
86 return False;
87}
88
89bool sid_check_is_in_wellknown_domain(const struct dom_sid *sid)
90{
91 struct dom_sid dom_sid;
92
93 sid_copy(&dom_sid, sid);
94 sid_split_rid(&dom_sid, NULL);
95
96 return sid_check_is_wellknown_domain(&dom_sid, NULL);
97}
98
99/**************************************************************************
100 Looks up a known username from one of the known domains.
101***************************************************************************/
102
103bool lookup_wellknown_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
104 const char **domain, const char **name)
105{
106 int i;
107 struct dom_sid dom_sid;
108 uint32 rid;
109 const struct rid_name_map *users = NULL;
110
111 sid_copy(&dom_sid, sid);
112 if (!sid_split_rid(&dom_sid, &rid)) {
113 DEBUG(2, ("Could not split rid from SID\n"));
114 return False;
115 }
116
117 for (i=0; special_domains[i].sid != NULL; i++) {
118 if (dom_sid_equal(&dom_sid, special_domains[i].sid)) {
119 *domain = talloc_strdup(mem_ctx,
120 special_domains[i].name);
121 users = special_domains[i].known_users;
122 break;
123 }
124 }
125
126 if (users == NULL) {
127 DEBUG(10, ("SID %s is no special sid\n", sid_string_dbg(sid)));
128 return False;
129 }
130
131 for (i=0; users[i].name != NULL; i++) {
132 if (rid == users[i].rid) {
133 *name = talloc_strdup(mem_ctx, users[i].name);
134 return True;
135 }
136 }
137
138 DEBUG(10, ("RID of special SID %s not found\n", sid_string_dbg(sid)));
139
140 return False;
141}
142
143/**************************************************************************
144 Try and map a name to one of the well known SIDs.
145***************************************************************************/
146
147bool lookup_wellknown_name(TALLOC_CTX *mem_ctx, const char *name,
148 struct dom_sid *sid, const char **domain)
149{
150 int i, j;
151
152 DEBUG(10,("map_name_to_wellknown_sid: looking up %s\n", name));
153
154 for (i=0; special_domains[i].sid != NULL; i++) {
155 const struct rid_name_map *users =
156 special_domains[i].known_users;
157
158 if (users == NULL)
159 continue;
160
161 for (j=0; users[j].name != NULL; j++) {
162 if ( strequal(users[j].name, name) ) {
163 sid_compose(sid, special_domains[i].sid,
164 users[j].rid);
165 *domain = talloc_strdup(
166 mem_ctx, special_domains[i].name);
167 return True;
168 }
169 }
170 }
171
172 return False;
173}
Note: See TracBrowser for help on using the repository browser.