Line data Source code
1 : /*
2 : Copyright (C) Nadezhda Ivanova 2009
3 :
4 : This program is free software; you can redistribute it and/or modify
5 : it under the terms of the GNU General Public License as published by
6 : the Free Software Foundation; either version 3 of the License, or
7 : (at your option) any later version.
8 :
9 : This program is distributed in the hope that it will be useful,
10 : but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : GNU General Public License for more details.
13 :
14 : You should have received a copy of the GNU General Public License
15 : along with this program. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : /*
19 : * Name: create_descriptor
20 : *
21 : * Component: routines for calculating and creating security descriptors
22 : * as described in MS-DTYP 2.5.3.x
23 : *
24 : * Description:
25 : *
26 : *
27 : * Author: Nadezhda Ivanova
28 : */
29 : #include "includes.h"
30 : #include "libcli/security/security.h"
31 : #include "librpc/gen_ndr/ndr_security.h"
32 :
33 : /* Todos:
34 : * build the security token dacl as follows:
35 : * SYSTEM: GA, OWNER: GA, LOGIN_SID:GW|GE
36 : * Need session id information for the login SID. Probably
37 : * the best place for this is during token creation
38 : *
39 : * Implement SD Invariants
40 : * ACE sorting rules
41 : * LDAP_SERVER_SD_FLAGS_OID control
42 : * ADTS 7.1.3.3 needs to be clarified
43 : */
44 :
45 : /* the mapping function for generic rights for DS.(GA,GR,GW,GX)
46 : * The mapping function is passed as an argument to the
47 : * descriptor calculating routine and depends on the security
48 : * manager that calls the calculating routine.
49 : * TODO: need similar mappings for the file system and
50 : * registry security managers in order to make this code
51 : * generic for all security managers
52 : */
53 :
54 25328 : uint32_t map_generic_rights_ds(uint32_t access_mask)
55 : {
56 25328 : if (access_mask & SEC_GENERIC_ALL) {
57 84 : access_mask |= SEC_ADS_GENERIC_ALL;
58 84 : access_mask &= ~SEC_GENERIC_ALL;
59 : }
60 :
61 25328 : if (access_mask & SEC_GENERIC_EXECUTE) {
62 0 : access_mask |= SEC_ADS_GENERIC_EXECUTE;
63 0 : access_mask &= ~SEC_GENERIC_EXECUTE;
64 : }
65 :
66 25328 : if (access_mask & SEC_GENERIC_WRITE) {
67 0 : access_mask |= SEC_ADS_GENERIC_WRITE;
68 0 : access_mask &= ~SEC_GENERIC_WRITE;
69 : }
70 :
71 25328 : if (access_mask & SEC_GENERIC_READ) {
72 0 : access_mask |= SEC_ADS_GENERIC_READ;
73 0 : access_mask &= ~SEC_GENERIC_READ;
74 : }
75 :
76 25328 : return access_mask;
77 : }
78 :
79 : /* Not sure what this has to be,
80 : * and it does not seem to have any influence */
81 2387233 : static bool object_in_list(const struct GUID *object_list, const struct GUID *object)
82 : {
83 : size_t i;
84 :
85 2387233 : if (object_list == NULL) {
86 0 : return true;
87 : }
88 :
89 2387233 : if (GUID_all_zero(object)) {
90 0 : return true;
91 : }
92 :
93 4495641 : for (i=0; ; i++) {
94 6421371 : if (GUID_all_zero(&object_list[i])) {
95 2108408 : return false;
96 : }
97 2387233 : if (!GUID_equal(&object_list[i], object)) {
98 2108408 : continue;
99 : }
100 :
101 278825 : return true;
102 : }
103 :
104 : return false;
105 : }
106 :
107 : /* returns true if the ACE gontains generic information
108 : * that needs to be processed additionally */
109 :
110 7243472 : static bool desc_ace_has_generic(const struct security_ace *ace)
111 : {
112 13007836 : if (ace->access_mask & SEC_GENERIC_ALL || ace->access_mask & SEC_GENERIC_READ ||
113 13007752 : ace->access_mask & SEC_GENERIC_WRITE || ace->access_mask & SEC_GENERIC_EXECUTE) {
114 84 : return true;
115 : }
116 14461532 : if (dom_sid_equal(&ace->trustee, &global_sid_Creator_Owner) ||
117 7218144 : dom_sid_equal(&ace->trustee, &global_sid_Creator_Group)) {
118 25244 : return true;
119 : }
120 7218144 : return false;
121 : }
122 :
123 : /* creates an ace in which the generic information is expanded */
124 :
125 25328 : static void desc_expand_generic(struct security_ace *new_ace,
126 : struct dom_sid *owner,
127 : struct dom_sid *group)
128 : {
129 25328 : new_ace->access_mask = map_generic_rights_ds(new_ace->access_mask);
130 25328 : if (dom_sid_equal(&new_ace->trustee, &global_sid_Creator_Owner)) {
131 25244 : new_ace->trustee = *owner;
132 : }
133 25328 : if (dom_sid_equal(&new_ace->trustee, &global_sid_Creator_Group)) {
134 0 : new_ace->trustee = *group;
135 : }
136 25328 : new_ace->flags = 0x0;
137 25328 : }
138 :
139 1965599 : static struct security_acl *calculate_inherited_from_parent(TALLOC_CTX *mem_ctx,
140 : struct security_acl *acl,
141 : bool is_container,
142 : struct dom_sid *owner,
143 : struct dom_sid *group,
144 : struct GUID *object_list)
145 : {
146 : uint32_t i;
147 1965599 : TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
148 1965599 : struct security_acl *tmp_acl = talloc_zero(mem_ctx, struct security_acl);
149 1965599 : if (!tmp_acl) {
150 0 : return NULL;
151 : }
152 :
153 1965599 : if (!acl) {
154 350754 : return NULL;
155 : }
156 :
157 20482140 : for (i=0; i < acl->num_aces; i++) {
158 18867295 : const struct security_ace *ace = &acl->aces[i];
159 18867295 : const struct GUID *inherited_object = NULL;
160 18867295 : const struct GUID *inherited_property = NULL;
161 18867295 : struct security_ace *tmp_ace = NULL;
162 18867295 : bool applies = false;
163 18867295 : bool inherited_only = false;
164 18867295 : bool expand_ace = false;
165 18867295 : bool expand_only = false;
166 :
167 18867295 : if (is_container && (ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT)) {
168 6789255 : applies = true;
169 12078040 : } else if (!is_container && (ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
170 0 : applies = true;
171 : }
172 :
173 18867295 : if (!applies) {
174 : /*
175 : * If the ace doesn't apply to the
176 : * current node, we should only keep
177 : * it as SEC_ACE_FLAG_OBJECT_INHERIT
178 : * on a container. We'll add
179 : * SEC_ACE_FLAG_INHERITED_ACE
180 : * and SEC_ACE_FLAG_INHERIT_ONLY below.
181 : *
182 : * Otherwise we should completely ignore it.
183 : */
184 12078040 : if (!(ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
185 12077986 : continue;
186 : }
187 : }
188 :
189 6789309 : switch (ace->type) {
190 4268215 : case SEC_ACE_TYPE_ACCESS_ALLOWED:
191 : case SEC_ACE_TYPE_ACCESS_DENIED:
192 : case SEC_ACE_TYPE_SYSTEM_AUDIT:
193 : case SEC_ACE_TYPE_SYSTEM_ALARM:
194 : case SEC_ACE_TYPE_ALLOWED_COMPOUND:
195 4268215 : break;
196 :
197 2521094 : case SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT:
198 : case SEC_ACE_TYPE_ACCESS_DENIED_OBJECT:
199 : case SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT:
200 : case SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT:
201 2521094 : if (ace->object.object.flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
202 2130598 : inherited_property = &ace->object.object.type.type;
203 : }
204 2521094 : if (ace->object.object.flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
205 2387233 : inherited_object = &ace->object.object.inherited_type.inherited_type;
206 : }
207 :
208 2521094 : if (inherited_object != NULL && !object_in_list(object_list, inherited_object)) {
209 : /*
210 : * An explicit object class schemaId is given,
211 : * but doesn't belong to the current object.
212 : */
213 2108408 : applies = false;
214 : }
215 :
216 2521094 : break;
217 : }
218 :
219 6789309 : if (ace->flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT) {
220 0 : if (!applies) {
221 : /*
222 : * If the ACE doesn't apply to
223 : * the current object, we should
224 : * ignore it as it should not be
225 : * inherited any further
226 : */
227 0 : continue;
228 : }
229 : /*
230 : * We should only keep the expanded version
231 : * of the ACE on the current object.
232 : */
233 0 : expand_ace = true;
234 0 : expand_only = true;
235 6789309 : } else if (applies) {
236 : /*
237 : * We check if should also add
238 : * the expanded version of the ACE
239 : * in addition, in case we should
240 : * expand generic access bits or
241 : * special sids.
242 : *
243 : * In that case we need to
244 : * keep the original ACE with
245 : * SEC_ACE_FLAG_INHERIT_ONLY.
246 : */
247 4680847 : expand_ace = desc_ace_has_generic(ace);
248 4680847 : if (expand_ace) {
249 1571 : inherited_only = true;
250 : }
251 : } else {
252 : /*
253 : * If the ACE doesn't apply
254 : * to the current object,
255 : * we need to keep it with
256 : * SEC_ACE_FLAG_INHERIT_ONLY
257 : * in order to apply them to
258 : * grandchildren
259 : */
260 2108462 : inherited_only = true;
261 : }
262 :
263 6789309 : if (expand_ace) {
264 1571 : tmp_acl->aces = talloc_realloc(tmp_acl,
265 : tmp_acl->aces,
266 : struct security_ace,
267 : tmp_acl->num_aces+1);
268 1571 : if (tmp_acl->aces == NULL) {
269 0 : talloc_free(tmp_ctx);
270 0 : return NULL;
271 : }
272 :
273 1571 : tmp_ace = &tmp_acl->aces[tmp_acl->num_aces];
274 1571 : tmp_acl->num_aces++;
275 :
276 1571 : *tmp_ace = *ace;
277 :
278 : /*
279 : * Expand generic access bits as well as special
280 : * sids.
281 : */
282 1571 : desc_expand_generic(tmp_ace, owner, group);
283 :
284 : /*
285 : * Expanded ACEs are marked as inherited,
286 : * but never inherited any further to
287 : * grandchildren.
288 : */
289 1571 : tmp_ace->flags |= SEC_ACE_FLAG_INHERITED_ACE;
290 1571 : tmp_ace->flags &= ~SEC_ACE_FLAG_CONTAINER_INHERIT;
291 1571 : tmp_ace->flags &= ~SEC_ACE_FLAG_OBJECT_INHERIT;
292 1571 : tmp_ace->flags &= ~SEC_ACE_FLAG_NO_PROPAGATE_INHERIT;
293 :
294 : /*
295 : * Expanded ACEs never have an explicit
296 : * object class schemaId, so clear it
297 : * if present.
298 : */
299 1571 : if (inherited_object != NULL) {
300 0 : tmp_ace->object.object.flags &= ~SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT;
301 : }
302 :
303 : /*
304 : * If the ACE had an explicit object class
305 : * schemaId, but no attribute/propertySet
306 : * we need to downgrate the _OBJECT variants
307 : * to the normal ones.
308 : */
309 1571 : if (inherited_property == NULL) {
310 1571 : switch (tmp_ace->type) {
311 1571 : case SEC_ACE_TYPE_ACCESS_ALLOWED:
312 : case SEC_ACE_TYPE_ACCESS_DENIED:
313 : case SEC_ACE_TYPE_SYSTEM_AUDIT:
314 : case SEC_ACE_TYPE_SYSTEM_ALARM:
315 : case SEC_ACE_TYPE_ALLOWED_COMPOUND:
316 1571 : break;
317 0 : case SEC_ACE_TYPE_ACCESS_ALLOWED_OBJECT:
318 0 : tmp_ace->type = SEC_ACE_TYPE_ACCESS_ALLOWED;
319 0 : break;
320 0 : case SEC_ACE_TYPE_ACCESS_DENIED_OBJECT:
321 0 : tmp_ace->type = SEC_ACE_TYPE_ACCESS_DENIED;
322 0 : break;
323 0 : case SEC_ACE_TYPE_SYSTEM_ALARM_OBJECT:
324 0 : tmp_ace->type = SEC_ACE_TYPE_SYSTEM_ALARM;
325 0 : break;
326 0 : case SEC_ACE_TYPE_SYSTEM_AUDIT_OBJECT:
327 0 : tmp_ace->type = SEC_ACE_TYPE_SYSTEM_AUDIT;
328 0 : break;
329 : }
330 : }
331 :
332 1571 : if (expand_only) {
333 0 : continue;
334 : }
335 : }
336 :
337 6789309 : tmp_acl->aces = talloc_realloc(tmp_acl,
338 : tmp_acl->aces,
339 : struct security_ace,
340 : tmp_acl->num_aces+1);
341 6789309 : if (tmp_acl->aces == NULL) {
342 0 : talloc_free(tmp_ctx);
343 0 : return NULL;
344 : }
345 :
346 6789309 : tmp_ace = &tmp_acl->aces[tmp_acl->num_aces];
347 6789309 : tmp_acl->num_aces++;
348 :
349 6789309 : *tmp_ace = *ace;
350 6789309 : tmp_ace->flags |= SEC_ACE_FLAG_INHERITED_ACE;
351 :
352 6789309 : if (inherited_only) {
353 2110033 : tmp_ace->flags |= SEC_ACE_FLAG_INHERIT_ONLY;
354 : } else {
355 4679276 : tmp_ace->flags &= ~SEC_ACE_FLAG_INHERIT_ONLY;
356 : }
357 :
358 6789309 : if (ace->flags & SEC_ACE_FLAG_NO_PROPAGATE_INHERIT) {
359 0 : tmp_ace->flags &= ~SEC_ACE_FLAG_CONTAINER_INHERIT;
360 0 : tmp_ace->flags &= ~SEC_ACE_FLAG_OBJECT_INHERIT;
361 0 : tmp_ace->flags &= ~SEC_ACE_FLAG_NO_PROPAGATE_INHERIT;
362 : }
363 : }
364 1614845 : if (tmp_acl->num_aces == 0) {
365 18387 : return NULL;
366 : }
367 1596458 : if (acl) {
368 1596458 : tmp_acl->revision = acl->revision;
369 : }
370 1596458 : return tmp_acl;
371 : }
372 :
373 2001200 : static struct security_acl *process_user_acl(TALLOC_CTX *mem_ctx,
374 : struct security_acl *acl,
375 : bool is_container,
376 : struct dom_sid *owner,
377 : struct dom_sid *group,
378 : struct GUID *object_list,
379 : bool is_protected)
380 : {
381 : uint32_t i;
382 2001200 : TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
383 2001200 : struct security_acl *tmp_acl = talloc_zero(tmp_ctx, struct security_acl);
384 : struct security_acl *new_acl;
385 :
386 2001200 : if (!acl)
387 436239 : return NULL;
388 :
389 1564961 : if (!tmp_acl)
390 0 : return NULL;
391 :
392 1564961 : tmp_acl->revision = acl->revision;
393 1564961 : DBG_DEBUG("acl revision %d\n", acl->revision);
394 :
395 8699285 : for (i=0; i < acl->num_aces; i++){
396 7134324 : struct security_ace *ace = &acl->aces[i];
397 : /* Remove ID flags from user-provided ACEs
398 : * if we break inheritance, ignore them otherwise */
399 7134324 : if (ace->flags & SEC_ACE_FLAG_INHERITED_ACE) {
400 4556880 : if (is_protected) {
401 9 : ace->flags &= ~SEC_ACE_FLAG_INHERITED_ACE;
402 : } else {
403 4556871 : continue;
404 : }
405 : }
406 :
407 2591038 : if (ace->flags & SEC_ACE_FLAG_INHERIT_ONLY &&
408 14896 : !(ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT ||
409 76 : ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT))
410 76 : continue;
411 :
412 2577377 : tmp_acl->aces = talloc_realloc(tmp_acl,
413 : tmp_acl->aces,
414 : struct security_ace,
415 : tmp_acl->num_aces+1);
416 2577377 : tmp_acl->aces[tmp_acl->num_aces] = *ace;
417 2577377 : tmp_acl->num_aces++;
418 2577377 : if (ace->flags & SEC_ACE_FLAG_INHERIT_ONLY) {
419 14752 : continue;
420 : }
421 : /* if the ACE contains CO, CG, GA, GE, GR or GW, and is inheritable
422 : * it has to be expanded to two aces, the original as IO,
423 : * and another one where these are translated */
424 2562625 : if (desc_ace_has_generic(ace)) {
425 23757 : if (!(ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT)) {
426 23393 : desc_expand_generic(&tmp_acl->aces[tmp_acl->num_aces-1],
427 : owner,
428 : group);
429 : } else {
430 : /*The original ACE becomes read only */
431 364 : tmp_acl->aces[tmp_acl->num_aces-1].flags |= SEC_ACE_FLAG_INHERIT_ONLY;
432 364 : tmp_acl->aces = talloc_realloc(tmp_acl, tmp_acl->aces,
433 : struct security_ace,
434 : tmp_acl->num_aces+1);
435 : /* add a new ACE with expanded generic info */
436 364 : tmp_acl->aces[tmp_acl->num_aces] = *ace;
437 364 : desc_expand_generic(&tmp_acl->aces[tmp_acl->num_aces],
438 : owner,
439 : group);
440 364 : tmp_acl->num_aces++;
441 : }
442 : }
443 : }
444 1564961 : new_acl = security_acl_dup(mem_ctx,tmp_acl);
445 :
446 1564961 : if (new_acl)
447 1564961 : new_acl->revision = acl->revision;
448 :
449 1564961 : talloc_free(tmp_ctx);
450 1564961 : return new_acl;
451 : }
452 :
453 3001872 : static void cr_descr_log_descriptor(struct security_descriptor *sd,
454 : const char *message,
455 : int level)
456 : {
457 3001872 : if (sd) {
458 3000932 : DEBUG(level,("%s: %s\n", message,
459 : ndr_print_struct_string(0,(ndr_print_fn_t)ndr_print_security_descriptor,
460 : "", sd)));
461 : }
462 : else {
463 940 : DEBUG(level,("%s: NULL\n", message));
464 : }
465 3001872 : }
466 :
467 : #if 0
468 : static void cr_descr_log_acl(struct security_acl *acl,
469 : const char *message,
470 : int level)
471 : {
472 : if (acl) {
473 : DEBUG(level,("%s: %s\n", message,
474 : ndr_print_struct_string(0,(ndr_print_fn_t)ndr_print_security_acl,
475 : "", acl)));
476 : }
477 : else {
478 : DEBUG(level,("%s: NULL\n", message));
479 : }
480 : }
481 : #endif
482 :
483 1000624 : static bool compute_acl(struct security_descriptor *parent_sd,
484 : struct security_descriptor *creator_sd,
485 : bool is_container,
486 : uint32_t inherit_flags,
487 : struct GUID *object_list,
488 : uint32_t (*generic_map)(uint32_t access_mask),
489 : struct security_token *token,
490 : struct security_descriptor *new_sd) /* INOUT argument */
491 : {
492 : struct security_acl *user_dacl, *user_sacl, *inherited_dacl, *inherited_sacl;
493 1000624 : int level = 10;
494 :
495 1000624 : if (!parent_sd || !(inherit_flags & SEC_DACL_AUTO_INHERIT)) {
496 916 : inherited_dacl = NULL;
497 999708 : } else if (creator_sd && (creator_sd->type & SEC_DESC_DACL_PROTECTED)) {
498 19538 : inherited_dacl = NULL;
499 : } else {
500 980170 : inherited_dacl = calculate_inherited_from_parent(new_sd,
501 : parent_sd->dacl,
502 : is_container,
503 : new_sd->owner_sid,
504 : new_sd->group_sid,
505 : object_list);
506 : }
507 :
508 :
509 1000624 : if (!parent_sd || !(inherit_flags & SEC_SACL_AUTO_INHERIT)) {
510 916 : inherited_sacl = NULL;
511 999708 : } else if (creator_sd && (creator_sd->type & SEC_DESC_SACL_PROTECTED)) {
512 14279 : inherited_sacl = NULL;
513 : } else {
514 985429 : inherited_sacl = calculate_inherited_from_parent(new_sd,
515 : parent_sd->sacl,
516 : is_container,
517 : new_sd->owner_sid,
518 : new_sd->group_sid,
519 : object_list);
520 : }
521 :
522 1000624 : if (!creator_sd || (inherit_flags & SEC_DEFAULT_DESCRIPTOR)) {
523 24 : user_dacl = NULL;
524 24 : user_sacl = NULL;
525 : } else {
526 1000600 : user_dacl = process_user_acl(new_sd,
527 : creator_sd->dacl,
528 : is_container,
529 : new_sd->owner_sid,
530 : new_sd->group_sid,
531 : object_list,
532 1000600 : creator_sd->type & SEC_DESC_DACL_PROTECTED);
533 1000600 : user_sacl = process_user_acl(new_sd,
534 : creator_sd->sacl,
535 : is_container,
536 : new_sd->owner_sid,
537 : new_sd->group_sid,
538 : object_list,
539 1000600 : creator_sd->type & SEC_DESC_SACL_PROTECTED);
540 : }
541 1000624 : cr_descr_log_descriptor(parent_sd, __location__"parent_sd", level);
542 1000624 : cr_descr_log_descriptor(creator_sd,__location__ "creator_sd", level);
543 :
544 1000624 : new_sd->dacl = security_acl_concatenate(new_sd, user_dacl, inherited_dacl);
545 1000624 : if (new_sd->dacl) {
546 1000516 : new_sd->type |= SEC_DESC_DACL_PRESENT;
547 : }
548 1000624 : if (inherited_dacl) {
549 963788 : new_sd->type |= SEC_DESC_DACL_AUTO_INHERITED;
550 : }
551 :
552 1000624 : new_sd->sacl = security_acl_concatenate(new_sd, user_sacl, inherited_sacl);
553 1000624 : if (new_sd->sacl) {
554 634208 : new_sd->type |= SEC_DESC_SACL_PRESENT;
555 : }
556 1000624 : if (inherited_sacl) {
557 632670 : new_sd->type |= SEC_DESC_SACL_AUTO_INHERITED;
558 : }
559 : /* This is a hack to handle the fact that
560 : * apprantly any AI flag provided by the user is preserved */
561 1000624 : if (creator_sd)
562 1000600 : new_sd->type |= creator_sd->type;
563 1000624 : cr_descr_log_descriptor(new_sd, __location__"final sd", level);
564 1000624 : return true;
565 : }
566 :
567 1000624 : struct security_descriptor *create_security_descriptor(TALLOC_CTX *mem_ctx,
568 : struct security_descriptor *parent_sd,
569 : struct security_descriptor *creator_sd,
570 : bool is_container,
571 : struct GUID *object_list,
572 : uint32_t inherit_flags,
573 : struct security_token *token,
574 : struct dom_sid *default_owner, /* valid only for DS, NULL for the other RSs */
575 : struct dom_sid *default_group, /* valid only for DS, NULL for the other RSs */
576 : uint32_t (*generic_map)(uint32_t access_mask))
577 : {
578 : struct security_descriptor *new_sd;
579 1000624 : struct dom_sid *new_owner = NULL;
580 1000624 : struct dom_sid *new_group = NULL;
581 :
582 1000624 : new_sd = security_descriptor_initialise(mem_ctx);
583 1000624 : if (!new_sd) {
584 0 : return NULL;
585 : }
586 :
587 1000624 : if (!creator_sd || !creator_sd->owner_sid) {
588 588628 : if ((inherit_flags & SEC_OWNER_FROM_PARENT) && parent_sd) {
589 0 : new_owner = parent_sd->owner_sid;
590 325487 : } else if (!default_owner) {
591 6031 : new_owner = &token->sids[PRIMARY_USER_SID_INDEX];
592 : } else {
593 319456 : new_owner = default_owner;
594 319456 : new_sd->type |= SEC_DESC_OWNER_DEFAULTED;
595 : }
596 : } else {
597 675137 : new_owner = creator_sd->owner_sid;
598 : }
599 :
600 1000624 : if (!creator_sd || !creator_sd->group_sid){
601 588628 : if ((inherit_flags & SEC_GROUP_FROM_PARENT) && parent_sd) {
602 0 : new_group = parent_sd->group_sid;
603 325487 : } else if (!default_group && token->num_sids > PRIMARY_GROUP_SID_INDEX) {
604 5359 : new_group = &token->sids[PRIMARY_GROUP_SID_INDEX];
605 320128 : } else if (!default_group) {
606 : /* This will happen only for anonymous, which has no other groups */
607 672 : new_group = &token->sids[PRIMARY_USER_SID_INDEX];
608 : } else {
609 319456 : new_group = default_group;
610 319456 : new_sd->type |= SEC_DESC_GROUP_DEFAULTED;
611 : }
612 : } else {
613 675137 : new_group = creator_sd->group_sid;
614 : }
615 :
616 1000624 : new_sd->owner_sid = talloc_memdup(new_sd, new_owner, sizeof(struct dom_sid));
617 1000624 : new_sd->group_sid = talloc_memdup(new_sd, new_group, sizeof(struct dom_sid));
618 1000624 : if (!new_sd->owner_sid || !new_sd->group_sid){
619 0 : talloc_free(new_sd);
620 0 : return NULL;
621 : }
622 :
623 1000624 : if (!compute_acl(parent_sd, creator_sd,
624 : is_container, inherit_flags, object_list,
625 : generic_map,token,new_sd)){
626 0 : talloc_free(new_sd);
627 0 : return NULL;
628 : }
629 :
630 1000624 : return new_sd;
631 : }
|