1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/*
Unix SMB/CIFS implementation.
GUMS backends helper functions
Copyright (C) Simo Sorce 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
extern DOM_SID global_sid_World;
extern DOM_SID global_sid_Builtin;
extern DOM_SID global_sid_Builtin_Administrators;
extern DOM_SID global_sid_Builtin_Power_Users;
extern DOM_SID global_sid_Builtin_Account_Operators;
extern DOM_SID global_sid_Builtin_Server_Operators;
extern DOM_SID global_sid_Builtin_Print_Operators;
extern DOM_SID global_sid_Builtin_Backup_Operators;
extern DOM_SID global_sid_Builtin_Replicator;
extern DOM_SID global_sid_Builtin_Users;
extern DOM_SID global_sid_Builtin_Guests;
/* defines */
#define ALLOC_CHECK(str, ptr, err, label) do { if ((ptr) == NULL) { DEBUG(0, ("%s: out of memory!\n", str)); err = NT_STATUS_NO_MEMORY; goto label; } } while(0)
#define NTSTATUS_CHECK(err, label, str1, str2) do { if (NT_STATUS_IS_ERR(err)) { DEBUG(0, ("%s: %s\n", str1, str2)); } } while(0)
/****************************************************************************
Check if a user is a mapped group.
This function will check if the group SID is mapped onto a
system managed gid or onto a winbind manged sid.
In the first case it will be threated like a mapped group
and the backend should take the member list with a getgrgid
and ignore any user that have been possibly set into the group
object.
In the second case, the group is a fully SAM managed group
served back to the system through winbind. In this case the
members of a Local group are "unrolled" to cope with the fact
that unix cannot contain groups inside groups.
The backend MUST never call any getgr* / getpw* function or
loops with winbind may happen.
****************************************************************************/
#if 0
NTSTATUS is_mapped_group(BOOL *mapped, const DOM_SID *sid)
{
NTSTATUS result;
gid_t id;
/* look if mapping exist, do not make idmap alloc an uid if SID is not found */
result = idmap_get_gid_from_sid(&id, sid, False);
if (NT_STATUS_IS_OK(result)) {
*mapped = gid_is_in_winbind_range(id);
} else {
*mapped = False;
}
return result;
}
#endif
#define ALIAS_DEFAULT_SACL_SA_RIGHTS 0x01050013
#define ALIAS_DEFAULT_DACL_SA_RIGHTS \
(READ_CONTROL_ACCESS | \
SA_RIGHT_ALIAS_LOOKUP_INFO | \
SA_RIGHT_ALIAS_GET_MEMBERS) /* 0x0002000c */
#define ALIAS_DEFAULT_SACL_SEC_ACE_FLAG (SEC_ACE_FLAG_FAILED_ACCESS | SEC_ACE_FLAG_SUCCESSFUL_ACCESS) /* 0xc0 */
NTSTATUS create_builtin_alias_default_sec_desc(SEC_DESC **sec_desc, TALLOC_CTX *ctx)
{
DOM_SID *world = &global_sid_World;
DOM_SID *admins = &global_sid_Builtin_Administrators;
SEC_ACCESS sa;
SEC_ACE sacl_ace;
SEC_ACE dacl_aces[2];
SEC_ACL *sacl = NULL;
SEC_ACL *dacl = NULL;
size_t psize;
init_sec_access(&sa, ALIAS_DEFAULT_SACL_SA_RIGHTS);
init_sec_ace(&sacl_ace, world, SEC_ACE_TYPE_SYSTEM_AUDIT, sa, ALIAS_DEFAULT_SACL_SEC_ACE_FLAG);
sacl = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &sacl_ace);
if (!sacl) {
DEBUG(0, ("build_init_sec_desc: Failed to make SEC_ACL.\n"));
return NT_STATUS_NO_MEMORY;
}
init_sec_access(&sa, ALIAS_DEFAULT_DACL_SA_RIGHTS);
init_sec_ace(&(dacl_aces[0]), world, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
init_sec_access(&sa, SA_RIGHT_ALIAS_ALL_ACCESS);
init_sec_ace(&(dacl_aces[1]), admins, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
dacl = make_sec_acl(ctx, NT4_ACL_REVISION, 2, dacl_aces);
if (!sacl) {
DEBUG(0, ("build_init_sec_desc: Failed to make SEC_ACL.\n"));
return NT_STATUS_NO_MEMORY;
}
*sec_desc = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, admins, admins, sacl, dacl, &psize);
if (!(*sec_desc)) {
DEBUG(0,("get_share_security: Failed to make SEC_DESC.\n"));
return NT_STATUS_NO_MEMORY;
}
return NT_STATUS_OK;
}
NTSTATUS sec_desc_add_ace_to_dacl(SEC_DESC *sec_desc, TALLOC_CTX *ctx, DOM_SID *sid, uint32 mask)
{
NTSTATUS result;
SEC_ACE *new_aces;
unsigned num_aces;
int i;
num_aces = sec_desc->dacl->num_aces + 1;
result = sec_ace_add_sid(ctx, &new_aces, sec_desc->dacl->ace, &num_aces, sid, mask);
if (NT_STATUS_IS_OK(result)) {
sec_desc->dacl->ace = new_aces;
sec_desc->dacl->num_aces = num_aces;
sec_desc->dacl->size = SEC_ACL_HEADER_SIZE;
for (i = 0; i < num_aces; i++) {
sec_desc->dacl->size += sec_desc->dacl->ace[i].size;
}
}
return result;
}
NTSTATUS gums_make_domain(DOM_SID *sid, const char *name, const char *description)
{
NTSTATUS ret;
GUMS_OBJECT *go;
GUMS_FUNCTIONS *fns;
if (!NT_STATUS_IS_OK(ret = get_gums_fns(&fns)))
return ret;
if (!NT_STATUS_IS_OK(ret = gums_create_object(&go, GUMS_OBJ_DOMAIN)))
return ret;
ret = gums_set_object_sid(go, sid);
NTSTATUS_CHECK(ret, done, "gums_make_alias", "unable to set sid!");
ret = gums_set_object_name(go, name);
NTSTATUS_CHECK(ret, done, "gums_make_alias", "unable to set name!");
if (description) {
ret = gums_set_object_description(go, description);
NTSTATUS_CHECK(ret, done, "gums_make_alias", "unable to set description!");
}
/* make security descriptor * /
ret = create_builtin_alias_default_sec_desc(&((*go).sec_desc), (*go).mem_ctx);
NTSTATUS_CHECK(ret, error, "gums_init_backend", "create_builtin_alias_default_sec_desc");
*/
ret = fns->set_object(go);
gums_destroy_object(&go);
return ret;
}
NTSTATUS gums_make_alias(DOM_SID *sid, const char *name, const char *description)
{
NTSTATUS ret;
GUMS_OBJECT *go;
GUMS_FUNCTIONS *fns;
if (!NT_STATUS_IS_OK(ret = get_gums_fns(&fns)))
return ret;
if (!NT_STATUS_IS_OK(ret = gums_create_object(&go, GUMS_OBJ_ALIAS)))
return ret;
ret = gums_set_object_sid(go, sid);
NTSTATUS_CHECK(ret, done, "gums_make_alias", "unable to set sid!");
ret = gums_set_object_name(go, name);
NTSTATUS_CHECK(ret, done, "gums_make_alias", "unable to set name!");
if (description) {
ret = gums_set_object_description(go, description);
NTSTATUS_CHECK(ret, done, "gums_make_alias", "unable to set description!");
}
/* make security descriptor * /
ret = create_builtin_alias_default_sec_desc(&((*go).sec_desc), (*go).mem_ctx);
NTSTATUS_CHECK(ret, error, "gums_init_backend", "create_builtin_alias_default_sec_desc");
*/
ret = fns->set_object(go);
gums_destroy_object(&go);
return ret;
}
NTSTATUS gums_init_domain(DOM_SID *sid, const char *name)
{
NTSTATUS ret;
/* Add the weelknown Builtin Domain */
if (!NT_STATUS_IS_OK(ret = gums_make_domain(
sid,
name,
NULL
))) {
return ret;
}
/* Add default users and groups */
/* Administrator
Guest
Domain Administrators
Domain Users
Domain Guests
*/
return ret;
}
NTSTATUS gums_init_builtin_domain(void)
{
NTSTATUS ret;
generate_wellknown_sids();
/* Add the weelknown Builtin Domain */
if (!NT_STATUS_IS_OK(ret = gums_make_domain(
&global_sid_Builtin,
"BUILTIN",
"Builtin Domain"
))) {
return ret;
}
/* Add the well known Builtin Local Groups */
/* Administrators */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Administrators,
"Administrators",
"Members can fully administer the computer/domain"
))) {
return ret;
}
/* Administrator privilege set */
/* From BDC join trace:
SeSecurityPrivilege, SeBackupPrivilege, SeRestorePrivilege,
SeSystemtimePrivilege, SeShutdownPrivilege,
SeRemoteShutdownPrivilege, SeTakeOwnershipPrivilege,
SeDebugPrivilege, SeSystemEnvironmentPrivilege,
SeSystemProfilePrivilege, SeProfileSingleProcessPrivilege,
SeIncreaseBasePriorityPrivilege, SeLocalDriverPrivilege,
SeCreatePagefilePrivilege, SeIncreaseQuotaPrivilege
*/
/* Power Users */
/* Domain Controllers Does NOT have Power Users (?) */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Power_Users,
"Power Users",
"Power Users"
))) {
return ret;
}
/* Power Users privilege set */
/* (?) */
/* Account Operators */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Account_Operators,
"Account Operators",
"Members can administer domain user and group accounts"
))) {
return ret;
}
/* make privilege set */
/* From BDC join trace:
SeShutdownPrivilege
*/
/* Server Operators */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Server_Operators,
"Server Operators",
"Members can administer domain servers"
))) {
return ret;
}
/* make privilege set */
/* From BDC join trace:
SeBackupPrivilege, SeRestorePrivilege, SeSystemtimePrivilege,
SeShutdownPrivilege, SeRemoteShutdownPrivilege
*/
/* Print Operators */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Print_Operators,
"Print Operators",
"Members can administer domain printers"
))) {
return ret;
}
/* make privilege set */
/* From BDC join trace:
SeShutdownPrivilege
*/
/* Backup Operators */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Backup_Operators,
"Backup Operators",
"Members can bypass file security to backup files"
))) {
return ret;
}
/* make privilege set */
/* From BDC join trace:
SeBackupPrivilege, SeRestorePrivilege, SeShutdownPrivilege
*/
/* Replicator */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Replicator,
"Replicator",
"Supports file replication in a domain"
))) {
return ret;
}
/* make privilege set */
/* From BDC join trace:
SeBackupPrivilege, SeRestorePrivilege, SeShutdownPrivilege
*/
/* Users */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Users,
"Users",
"Ordinary users"
))) {
return ret;
}
/* Users specific ACEs * /
sec_desc_add_ace_to_dacl(go->sec_desc, go->mem_ctx, &global_sid_Builtin_Account_Operators, ALIAS_DEFAULT_DACL_SA_RIGHTS);
sec_desc_add_ace_to_dacl(go->sec_desc, go->mem_ctx, &global_sid_Builtin_Power_Users, ALIAS_DEFAULT_DACL_SA_RIGHTS);
*/
/* Guests */
if (!NT_STATUS_IS_OK(ret = gums_make_alias(
&global_sid_Builtin_Guests,
"Guests",
"Users granted guest access to the computer/domain"
))) {
return ret;
}
return ret;
}
|