2 Copyright (C) Nadezhda Ivanova 2009
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.
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.
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/>.
19 * Name: create_descriptor
21 * Component: routines for calculating and creating security descriptors
22 * as described in MS-DTYP 2.5.2.2
27 * Author: Nadezhda Ivanova
30 #include "libcli/security/security.h"
32 /* the mapping function for generic rights for DS.(GA,GR,GW,GX)
33 * The mapping function is passed as an argument to the
34 * descriptor calculating routine and depends on the security
35 * manager that calls the calculating routine.
36 * TODO: need similar mappings for the file system and
37 * registry security managers in order to make this code
38 * generic for all security managers
41 uint32_t map_generic_rights_ds(uint32_t access_mask)
43 if (access_mask & SEC_GENERIC_ALL){
44 access_mask |= SEC_ADS_GENERIC_ALL;
45 access_mask = ~SEC_GENERIC_ALL;
48 if (access_mask & SEC_GENERIC_EXECUTE){
49 access_mask |= SEC_ADS_GENERIC_EXECUTE;
50 access_mask = ~SEC_GENERIC_EXECUTE;
53 if (access_mask & SEC_GENERIC_WRITE){
54 access_mask |= SEC_ADS_GENERIC_WRITE;
55 access_mask &= ~SEC_GENERIC_WRITE;
58 if (access_mask & SEC_GENERIC_READ){
59 access_mask |= SEC_ADS_GENERIC_READ;
60 access_mask &= ~SEC_GENERIC_READ;
66 struct security_descriptor *create_security_descriptor(TALLOC_CTX *mem_ctx,
67 struct security_descriptor *parent_sd,
68 struct security_descriptor *creator_sd,
70 struct GUID *object_list,
71 uint32_t inherit_flags,
72 struct security_token *token,
73 struct dom_sid *default_owner, /* valid only for DS, NULL for the other RSs */
74 struct dom_sid *default_group, /* valid only for DS, NULL for the other RSs */
75 uint32_t (*generic_map)(uint32_t access_mask))
77 struct security_descriptor *new_sd;
78 struct dom_sid *new_owner = NULL;
79 struct dom_sid *new_group = NULL;
81 new_sd = security_descriptor_initialise(mem_ctx);
84 if (!creator_sd || !creator_sd->owner_sid){
85 if (inherit_flags & SEC_OWNER_FROM_PARENT)
86 new_owner = parent_sd->owner_sid;
87 else if (!default_owner)
88 new_owner = token->user_sid;
90 new_owner = default_owner;
93 new_owner = creator_sd->owner_sid;
95 if (!creator_sd || !creator_sd->group_sid){
96 if (inherit_flags & SEC_GROUP_FROM_PARENT && parent_sd)
97 new_group = parent_sd->group_sid;
98 else if (!default_group)
99 new_group = token->group_sid;
100 else new_group = default_group;
103 new_group = creator_sd->group_sid;
105 new_sd->owner_sid = talloc_memdup(new_sd, new_owner, sizeof(struct dom_sid));
106 new_sd->group_sid = talloc_memdup(new_sd, new_group, sizeof(struct dom_sid));
107 if (!new_sd->owner_sid || !new_sd->group_sid){
112 if (creator_sd && creator_sd->type & SEC_DESC_DACL_PRESENT){
113 new_sd->dacl = security_acl_dup(new_sd, creator_sd->dacl);
114 new_sd->type |= SEC_DESC_DACL_PRESENT;