source: branches/samba-3.2.x/source/lib/util_sid.c@ 233

Last change on this file since 233 was 228, checked in by Herwig Bauernfeind, 17 years ago

Update 3.2 branch to 3.2.6

File size: 22.0 KB
RevLine 
[149]1/*
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 <[email protected]> 2005
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "includes.h"
26
27/*
28 * Some useful sids, more well known sids can be found at
29 * http://support.microsoft.com/kb/243330/EN-US/
30 */
31
32
33const DOM_SID global_sid_World_Domain = /* Everyone domain */
34{ 1, 0, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
35const DOM_SID global_sid_World = /* Everyone */
36{ 1, 1, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
37const DOM_SID global_sid_Creator_Owner_Domain = /* Creator Owner domain */
38{ 1, 0, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
39const DOM_SID global_sid_NT_Authority = /* NT Authority */
40{ 1, 0, {0,0,0,0,0,5}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
41const DOM_SID global_sid_System = /* System */
42{ 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
43const DOM_SID global_sid_NULL = /* NULL sid */
44{ 1, 1, {0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
45const DOM_SID global_sid_Authenticated_Users = /* All authenticated rids */
46{ 1, 1, {0,0,0,0,0,5}, {11,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
47#if 0
48/* for documentation */
49const DOM_SID global_sid_Restriced = /* Restriced Code */
50{ 1, 1, {0,0,0,0,0,5}, {12,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
51#endif
52const DOM_SID global_sid_Network = /* Network rids */
53{ 1, 1, {0,0,0,0,0,5}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
54
55const DOM_SID global_sid_Creator_Owner = /* Creator Owner */
56{ 1, 1, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
57const DOM_SID global_sid_Creator_Group = /* Creator Group */
58{ 1, 1, {0,0,0,0,0,3}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
59const DOM_SID global_sid_Anonymous = /* Anonymous login */
60{ 1, 1, {0,0,0,0,0,5}, {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
61
62const DOM_SID global_sid_Builtin = /* Local well-known domain */
63{ 1, 1, {0,0,0,0,0,5}, {32,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
64const DOM_SID global_sid_Builtin_Administrators = /* Builtin administrators */
65{ 1, 2, {0,0,0,0,0,5}, {32,544,0,0,0,0,0,0,0,0,0,0,0,0,0}};
66const DOM_SID global_sid_Builtin_Users = /* Builtin users */
67{ 1, 2, {0,0,0,0,0,5}, {32,545,0,0,0,0,0,0,0,0,0,0,0,0,0}};
68const DOM_SID global_sid_Builtin_Guests = /* Builtin guest users */
69{ 1, 2, {0,0,0,0,0,5}, {32,546,0,0,0,0,0,0,0,0,0,0,0,0,0}};
70const DOM_SID global_sid_Builtin_Power_Users = /* Builtin power users */
71{ 1, 2, {0,0,0,0,0,5}, {32,547,0,0,0,0,0,0,0,0,0,0,0,0,0}};
72const DOM_SID global_sid_Builtin_Account_Operators = /* Builtin account operators */
73{ 1, 2, {0,0,0,0,0,5}, {32,548,0,0,0,0,0,0,0,0,0,0,0,0,0}};
74const DOM_SID global_sid_Builtin_Server_Operators = /* Builtin server operators */
75{ 1, 2, {0,0,0,0,0,5}, {32,549,0,0,0,0,0,0,0,0,0,0,0,0,0}};
76const DOM_SID global_sid_Builtin_Print_Operators = /* Builtin print operators */
77{ 1, 2, {0,0,0,0,0,5}, {32,550,0,0,0,0,0,0,0,0,0,0,0,0,0}};
78const DOM_SID global_sid_Builtin_Backup_Operators = /* Builtin backup operators */
79{ 1, 2, {0,0,0,0,0,5}, {32,551,0,0,0,0,0,0,0,0,0,0,0,0,0}};
80const DOM_SID global_sid_Builtin_Replicator = /* Builtin replicator */
81{ 1, 2, {0,0,0,0,0,5}, {32,552,0,0,0,0,0,0,0,0,0,0,0,0,0}};
82const DOM_SID global_sid_Builtin_PreWin2kAccess = /* Builtin pre win2k access */
83{ 1, 2, {0,0,0,0,0,5}, {32,554,0,0,0,0,0,0,0,0,0,0,0,0,0}};
84
85const DOM_SID global_sid_Unix_Users = /* Unmapped Unix users */
86{ 1, 1, {0,0,0,0,0,22}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
87const DOM_SID global_sid_Unix_Groups = /* Unmapped Unix groups */
88{ 1, 1, {0,0,0,0,0,22}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
89
90/* Unused, left here for documentary purposes */
91#if 0
92#define SECURITY_NULL_SID_AUTHORITY 0
93#define SECURITY_WORLD_SID_AUTHORITY 1
94#define SECURITY_LOCAL_SID_AUTHORITY 2
95#define SECURITY_CREATOR_SID_AUTHORITY 3
96#define SECURITY_NT_AUTHORITY 5
97#endif
98
99/*
100 * An NT compatible anonymous token.
101 */
102
103static DOM_SID anon_sid_array[3] =
104{ { 1, 1, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
105 { 1, 1, {0,0,0,0,0,5}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
106 { 1, 1, {0,0,0,0,0,5}, {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} };
107NT_USER_TOKEN anonymous_token = { 3, anon_sid_array, SE_NONE };
108
109static DOM_SID system_sid_array[1] =
110{ { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} };
111NT_USER_TOKEN system_token = { 1, system_sid_array, SE_ALL_PRIVS };
112
113/****************************************************************************
114 Lookup string names for SID types.
115****************************************************************************/
116
117static const struct {
118 enum lsa_SidType sid_type;
119 const char *string;
120} sid_name_type[] = {
121 {SID_NAME_USER, "User"},
122 {SID_NAME_DOM_GRP, "Domain Group"},
123 {SID_NAME_DOMAIN, "Domain"},
124 {SID_NAME_ALIAS, "Local Group"},
125 {SID_NAME_WKN_GRP, "Well-known Group"},
126 {SID_NAME_DELETED, "Deleted Account"},
127 {SID_NAME_INVALID, "Invalid Account"},
128 {SID_NAME_UNKNOWN, "UNKNOWN"},
129 {SID_NAME_COMPUTER, "Computer"},
130
131 {(enum lsa_SidType)0, NULL}
132};
133
134const char *sid_type_lookup(uint32 sid_type)
135{
136 int i = 0;
137
138 /* Look through list */
139 while(sid_name_type[i].sid_type != 0) {
140 if (sid_name_type[i].sid_type == sid_type)
141 return sid_name_type[i].string;
142 i++;
143 }
144
145 /* Default return */
146 return "SID *TYPE* is INVALID";
147}
148
149/**************************************************************************
150 Create the SYSTEM token.
151***************************************************************************/
152
153NT_USER_TOKEN *get_system_token(void)
154{
155 return &system_token;
156}
157
158/******************************************************************
159 get the default domain/netbios name to be used when dealing
160 with our passdb list of accounts
161******************************************************************/
162
163const char *get_global_sam_name(void)
164{
165 if ((lp_server_role() == ROLE_DOMAIN_PDC) || (lp_server_role() == ROLE_DOMAIN_BDC)) {
166 return lp_workgroup();
167 }
168 return global_myname();
169}
170
171/*****************************************************************
172 Convert a SID to an ascii string.
173*****************************************************************/
174
175char *sid_to_fstring(fstring sidstr_out, const DOM_SID *sid)
176{
177 char *str = sid_string_talloc(talloc_tos(), sid);
178 fstrcpy(sidstr_out, str);
179 TALLOC_FREE(str);
180 return sidstr_out;
181}
182
183/*****************************************************************
184 Essentially a renamed dom_sid_string from librpc/ndr with a
185 panic if it didn't work
186
187 This introduces a dependency on librpc/ndr/sid.o which can easily
188 be turned around if necessary
189*****************************************************************/
190
191char *sid_string_talloc(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
192{
193 char *result = dom_sid_string(mem_ctx, sid);
194 SMB_ASSERT(result != NULL);
195 return result;
196}
197
198/*****************************************************************
199 Useful function for debug lines.
200*****************************************************************/
201
202char *sid_string_dbg(const DOM_SID *sid)
203{
204 return sid_string_talloc(debug_ctx(), sid);
205}
206
207/*****************************************************************
208 Use with care!
209*****************************************************************/
210
211char *sid_string_tos(const DOM_SID *sid)
212{
213 return sid_string_talloc(talloc_tos(), sid);
214}
215
216/*****************************************************************
217 Convert a string to a SID. Returns True on success, False on fail.