LCOV - code coverage report
Current view: top level - libcli/security - create_descriptor.c (source / functions) Hit Total Coverage
Test: coverage report for recycleplus df22b230 Lines: 204 248 82.3 %
Date: 2024-02-14 10:14:15 Functions: 9 9 100.0 %

          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       58393 : uint32_t map_generic_rights_ds(uint32_t access_mask)
      55             : {
      56       58393 :         if (access_mask & SEC_GENERIC_ALL) {
      57         386 :                 access_mask |= SEC_ADS_GENERIC_ALL;
      58         386 :                 access_mask &= ~SEC_GENERIC_ALL;
      59             :         }
      60             : 
      61       58393 :         if (access_mask & SEC_GENERIC_EXECUTE) {
      62           0 :                 access_mask |= SEC_ADS_GENERIC_EXECUTE;
      63           0 :                 access_mask &= ~SEC_GENERIC_EXECUTE;
      64             :         }
      65             : 
      66       58393 :         if (access_mask & SEC_GENERIC_WRITE) {
      67           0 :                 access_mask |= SEC_ADS_GENERIC_WRITE;
      68           0 :                 access_mask &= ~SEC_GENERIC_WRITE;
      69             :         }
      70             : 
      71       58393 :         if (access_mask & SEC_GENERIC_READ) {
      72           0 :                 access_mask |= SEC_ADS_GENERIC_READ;
      73           0 :                 access_mask &= ~SEC_GENERIC_READ;
      74             :         }
      75             : 
      76       58393 :         return access_mask;
      77             : }
      78             : 
      79             : /* Not sure what this has to be,
      80             : * and it does not seem to have any influence */
      81     3910005 : static bool object_in_list(const struct GUID *object_list, const struct GUID *object)
      82             : {
      83             :         size_t i;
      84             : 
      85     3910005 :         if (object_list == NULL) {
      86           0 :                 return true;
      87             :         }
      88             : 
      89     3910005 :         if (GUID_all_zero(object)) {
      90           0 :                 return true;
      91             :         }
      92             : 
      93     7325942 :         for (i=0; ; i++) {
      94     7325942 :                 if (GUID_all_zero(&object_list[i])) {
      95     3415937 :                         return false;
      96             :                 }
      97     3910005 :                 if (!GUID_equal(&object_list[i], object)) {
      98     3415937 :                         continue;
      99             :                 }
     100             : 
     101      494068 :                 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     8062776 : static bool desc_ace_has_generic(const struct security_ace *ace)
     111             : {
     112     8062776 :         if (ace->access_mask & SEC_GENERIC_ALL || ace->access_mask & SEC_GENERIC_READ ||
     113     8062390 :             ace->access_mask & SEC_GENERIC_WRITE || ace->access_mask & SEC_GENERIC_EXECUTE) {
     114         386 :                 return true;
     115             :         }
     116    16066773 :         if (dom_sid_equal(&ace->trustee, &global_sid_Creator_Owner) ||
     117     8004383 :             dom_sid_equal(&ace->trustee, &global_sid_Creator_Group)) {
     118       58007 :                 return true;
     119             :         }
     120     8004383 :         return false;
     121             : }
     122             : 
     123             : /* creates an ace in which the generic information is expanded */
     124             : 
     125       58393 : static void desc_expand_generic(struct security_ace *new_ace,
     126             :                                 struct dom_sid *owner,
     127             :                                 struct dom_sid *group)
     128             : {
     129       58393 :         new_ace->access_mask = map_generic_rights_ds(new_ace->access_mask);
     130       58393 :         if (dom_sid_equal(&new_ace->trustee, &global_sid_Creator_Owner)) {
     131       58007 :                 new_ace->trustee = *owner;
     132             :         }
     133       58393 :         if (dom_sid_equal(&new_ace->trustee, &global_sid_Creator_Group)) {
     134           0 :                 new_ace->trustee = *group;
     135             :         }
     136       58393 :         new_ace->flags = 0x0;
     137       58393 : }
     138             : 
     139     2268333 : 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     2268333 :         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
     148     2268333 :         struct security_acl *tmp_acl = talloc_zero(mem_ctx, struct security_acl);
     149     2268333 :         if (!tmp_acl) {
     150           0 :                 return NULL;
     151             :         }
     152             : 
     153     2268333 :         if (!acl) {
     154      475539 :                 return NULL;
     155             :         }
     156             : 
     157    20752102 :         for (i=0; i < acl->num_aces; i++) {
     158    18959308 :                 const struct security_ace *ace = &acl->aces[i];
     159    18959308 :                 const struct GUID *inherited_object = NULL;
     160    18959308 :                 const struct GUID *inherited_property = NULL;
     161    18959308 :                 struct security_ace *tmp_ace = NULL;
     162    18959308 :                 bool applies = false;
     163    18959308 :                 bool inherited_only = false;
     164    18959308 :                 bool expand_ace = false;
     165    18959308 :                 bool expand_only = false;
     166             : 
     167    18959308 :                 if (is_container && (ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT)) {
     168     7522988 :                         applies = true;
     169    11436320 :                 } else if (!is_container && (ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
     170           0 :                         applies = true;
     171             :                 }
     172             : 
     173    18959308 :                 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    11436320 :                         if (!(ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT)) {
     185    11436239 :                                 continue;
     186             :                         }
     187             :                 }
     188             : 
     189     7523069 :                 switch (ace->type) {
     190     3392613 :                 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     3392613 :                         break;
     196             : 
     197     4130456 :                 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     4130456 :                         if (ace->object.object.flags & SEC_ACE_OBJECT_TYPE_PRESENT) {
     202     3488169 :                                 inherited_property = &ace->object.object.type.type;
     203             :                         }
     204     4130456 :                         if (ace->object.object.flags & SEC_ACE_INHERITED_OBJECT_TYPE_PRESENT) {
     205     3910005 :                                 inherited_object = &ace->object.object.inherited_type.inherited_type;
     206             :                         }
     207             : 
     208     4130456 :                         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     3415937 :                                 applies = false;
     214             :                         }
     215             : 
     216     4130456 :                         break;
     217             :                 }
     218             : 
     219     7523069 :                 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     7523069 :                 } 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     4107051 :                         expand_ace = desc_ace_has_generic(ace);
     248     4107051 :                         if (expand_ace) {
     249        2539 :                                 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     3416018 :                         inherited_only = true;
     261             :                 }
     262             : 
     263     7523069 :                 if (expand_ace) {
     264        2539 :                         tmp_acl->aces = talloc_realloc(tmp_acl,
     265             :                                                        tmp_acl->aces,
     266             :                                                        struct security_ace,
     267             :                                                        tmp_acl->num_aces+1);
     268        2539 :                         if (tmp_acl->aces == NULL) {
     269           0 :                                 talloc_free(tmp_ctx);
     270           0 :                                 return NULL;
     271             :                         }
     272             : 
     273        2539 :                         tmp_ace = &tmp_acl->aces[tmp_acl->num_aces];
     274        2539 :                         tmp_acl->num_aces++;
     275             : 
     276        2539 :                         *tmp_ace = *ace;
     277             : 
     278             :                         /*
     279             :                          * Expand generic access bits as well as special
     280             :                          * sids.
     281             :                          */
     282        2539 :                         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        2539 :                         tmp_ace->flags |= SEC_ACE_FLAG_INHERITED_ACE;
     290        2539 :                         tmp_ace->flags &= ~SEC_ACE_FLAG_CONTAINER_INHERIT;
     291        2539 :                         tmp_ace->flags &= ~SEC_ACE_FLAG_OBJECT_INHERIT;
     292        2539 :                         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        2539 :                         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        2539 :                         if (inherited_property == NULL) {
     310        2503 :                                 switch (tmp_ace->type) {
     311        2503 :                                 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        2503 :                                         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        2539 :                         if (expand_only) {
     333           0 :                                 continue;
     334             :                         }
     335             :                 }
     336             : 
     337     7523069 :                 tmp_acl->aces = talloc_realloc(tmp_acl,
     338             :                                                tmp_acl->aces,
     339             :                                                struct security_ace,
     340             :                                                tmp_acl->num_aces+1);
     341     7523069 :                 if (tmp_acl->aces == NULL) {
     342           0 :                         talloc_free(tmp_ctx);
     343           0 :                         return NULL;
     344             :                 }
     345             : 
     346     7523069 :                 tmp_ace = &tmp_acl->aces[tmp_acl->num_aces];
     347     7523069 :                 tmp_acl->num_aces++;
     348             : 
     349     7523069 :                 *tmp_ace = *ace;
     350     7523069 :                 tmp_ace->flags |= SEC_ACE_FLAG_INHERITED_ACE;
     351             : 
     352     7523069 :                 if (inherited_only) {
     353     3418557 :                         tmp_ace->flags |= SEC_ACE_FLAG_INHERIT_ONLY;
     354             :                 } else {
     355     4104512 :                         tmp_ace->flags &= ~SEC_ACE_FLAG_INHERIT_ONLY;
     356             :                 }
     357             : 
     358     7523069 :                 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     1792794 :         if (tmp_acl->num_aces == 0) {
     365       25136 :                 return NULL;
     366             :         }
     367     1767658 :         if (acl) {
     368     1767658 :                 tmp_acl->revision = acl->revision;
     369             :         }
     370     1767658 :         return tmp_acl;
     371             : }
     372             : 
     373     2305402 : 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     2305402 :         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
     383     2305402 :         struct security_acl *tmp_acl = talloc_zero(tmp_ctx, struct security_acl);
     384             :         struct security_acl *new_acl;
     385             : 
     386     2305402 :         if (!acl)
     387      638342 :                 return NULL;
     388             : 
     389     1667060 :         if (!tmp_acl)
     390           0 :                 return NULL;
     391             : 
     392     1667060 :         tmp_acl->revision = acl->revision;
     393     1667060 :         DBG_DEBUG("acl revision %d\n", acl->revision);
     394             : 
     395     8699398 :         for (i=0; i < acl->num_aces; i++){
     396     7032338 :                 struct security_ace *ace = &acl->aces[i];
     397             :                 /* Remove ID flags from user-provided ACEs
     398             :                  * if we break inheritance, ignore them otherwise */
     399     7032338 :                 if (ace->flags & SEC_ACE_FLAG_INHERITED_ACE) {
     400     3055987 :                         if (is_protected) {
     401           9 :                                 ace->flags &= ~SEC_ACE_FLAG_INHERITED_ACE;
     402             :                         } else {
     403     3055978 :                                 continue;
     404             :                         }
     405             :                 }
     406             : 
     407     3976360 :                 if (ace->flags & SEC_ACE_FLAG_INHERIT_ONLY &&
     408       20635 :                     !(ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT ||
     409          76 :                       ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT))
     410          76 :                         continue;
     411             : 
     412     3976284 :                 tmp_acl->aces = talloc_realloc(tmp_acl,
     413             :                                                tmp_acl->aces,
     414             :                                                struct security_ace,
     415             :                                                tmp_acl->num_aces+1);
     416     3976284 :                 tmp_acl->aces[tmp_acl->num_aces] = *ace;
     417     3976284 :                 tmp_acl->num_aces++;
     418     3976284 :                 if (ace->flags & SEC_ACE_FLAG_INHERIT_ONLY) {
     419       20559 :                         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     3955725 :                 if (desc_ace_has_generic(ace)) {
     425       55854 :                         if (!(ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT)) {
     426       55171 :                                 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         683 :                                 tmp_acl->aces[tmp_acl->num_aces-1].flags |= SEC_ACE_FLAG_INHERIT_ONLY;
     432         683 :                                 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         683 :                                 tmp_acl->aces[tmp_acl->num_aces] = *ace;
     437         683 :                                 desc_expand_generic(&tmp_acl->aces[tmp_acl->num_aces],
     438             :                                                     owner,
     439             :                                                     group);
     440         683 :                                 tmp_acl->num_aces++;
     441             :                         }
     442             :                 }
     443             :         }
     444     1667060 :         new_acl = security_acl_dup(mem_ctx,tmp_acl);
     445             : 
     446     1667060 :         if (new_acl)
     447     1667060 :                 new_acl->revision = acl->revision;
     448             : 
     449     1667060 :         talloc_free(tmp_ctx);
     450     1667060 :         return new_acl;
     451             : }
     452             : 
     453     3458253 : static void cr_descr_log_descriptor(struct security_descriptor *sd,
     454             :                                     const char *message,
     455             :                                     int level)
     456             : {
     457     3458253 :         if (sd) {
     458     3456980 :                 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        1273 :                 DEBUG(level,("%s: NULL\n", message));
     464             :         }
     465     3458253 : }
     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     1152751 : 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     1152751 :         int level = 10;
     494             : 
     495     1152751 :         if (!parent_sd || !(inherit_flags & SEC_DACL_AUTO_INHERIT)) {
     496        1223 :                 inherited_dacl = NULL;
     497     1151528 :         } else if (creator_sd && (creator_sd->type & SEC_DESC_DACL_PROTECTED)) {
     498       20170 :                 inherited_dacl = NULL;
     499             :         } else {
     500     1131358 :                 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     1152751 :         if (!parent_sd || !(inherit_flags & SEC_SACL_AUTO_INHERIT)) {
     510        1223 :                 inherited_sacl = NULL;
     511     1151528 :         } else if (creator_sd && (creator_sd->type & SEC_DESC_SACL_PROTECTED)) {
     512       14553 :                 inherited_sacl = NULL;
     513             :         } else {
     514     1136975 :                 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     1152751 :         if (!creator_sd || (inherit_flags & SEC_DEFAULT_DESCRIPTOR)) {
     523          50 :                 user_dacl = NULL;
     524          50 :                 user_sacl = NULL;
     525             :         } else {
     526     1152701 :                 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     1152701 :                                              creator_sd->type & SEC_DESC_DACL_PROTECTED);
     533     1152701 :                 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     1152701 :                                              creator_sd->type & SEC_DESC_SACL_PROTECTED);
     540             :         }
     541     1152751 :         cr_descr_log_descriptor(parent_sd, __location__"parent_sd", level);
     542     1152751 :         cr_descr_log_descriptor(creator_sd,__location__ "creator_sd", level);
     543             : 
     544     1152751 :         new_sd->dacl = security_acl_concatenate(new_sd, user_dacl, inherited_dacl);
     545     1152751 :         if (new_sd->dacl) {
     546     1152504 :                 new_sd->type |= SEC_DESC_DACL_PRESENT;
     547             :         }
     548     1152751 :         if (inherited_dacl) {
     549     1109273 :                 new_sd->type |= SEC_DESC_DACL_AUTO_INHERITED;
     550             :         }
     551             : 
     552     1152751 :         new_sd->sacl = security_acl_concatenate(new_sd, user_sacl, inherited_sacl);
     553     1152751 :         if (new_sd->sacl) {
     554      660035 :                 new_sd->type |= SEC_DESC_SACL_PRESENT;
     555             :         }
     556     1152751 :         if (inherited_sacl) {
     557      658385 :                 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     1152751 :         if (creator_sd)
     562     1152701 :                 new_sd->type |= creator_sd->type;
     563     1152751 :         cr_descr_log_descriptor(new_sd, __location__"final sd", level);
     564     1152751 :         return true;
     565             : }
     566             : 
     567     1152751 : 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     1152751 :         struct dom_sid *new_owner = NULL;
     580     1152751 :         struct dom_sid *new_group = NULL;
     581             : 
     582     1152751 :         new_sd = security_descriptor_initialise(mem_ctx);
     583     1152751 :         if (!new_sd) {
     584           0 :                 return NULL;
     585             :         }
     586             : 
     587     1152751 :         if (!creator_sd || !creator_sd->owner_sid) {
     588      651987 :                 if ((inherit_flags & SEC_OWNER_FROM_PARENT) && parent_sd) {
     589           0 :                         new_owner = parent_sd->owner_sid;
     590      651987 :                 } else if (!default_owner) {
     591       13170 :                         new_owner = &token->sids[PRIMARY_USER_SID_INDEX];
     592             :                 } else {
     593      638817 :                         new_owner = default_owner;
     594      638817 :                         new_sd->type |= SEC_DESC_OWNER_DEFAULTED;
     595             :                 }
     596             :         } else {
     597      500764 :                 new_owner = creator_sd->owner_sid;
     598             :         }
     599             : 
     600     1152751 :         if (!creator_sd || !creator_sd->group_sid){
     601      652131 :                 if ((inherit_flags & SEC_GROUP_FROM_PARENT) && parent_sd) {
     602           0 :                         new_group = parent_sd->group_sid;
     603      652131 :                 } else if (!default_group && token->num_sids > PRIMARY_GROUP_SID_INDEX) {
     604       11827 :                         new_group = &token->sids[PRIMARY_GROUP_SID_INDEX];
     605      640304 :                 } else if (!default_group) {
     606             :                         /* This will happen only for anonymous, which has no other groups */
     607        1361 :                         new_group = &token->sids[PRIMARY_USER_SID_INDEX];
     608             :                 } else {
     609      638943 :                         new_group = default_group;
     610      638943 :                         new_sd->type |= SEC_DESC_GROUP_DEFAULTED;
     611             :                 }
     612             :         } else {
     613      500620 :                 new_group = creator_sd->group_sid;
     614             :         }
     615             : 
     616     1152751 :         new_sd->owner_sid = talloc_memdup(new_sd, new_owner, sizeof(struct dom_sid));
     617     1152751 :         new_sd->group_sid = talloc_memdup(new_sd, new_group, sizeof(struct dom_sid));
     618     1152751 :         if (!new_sd->owner_sid || !new_sd->group_sid){
     619           0 :                 talloc_free(new_sd);
     620           0 :                 return NULL;
     621             :         }
     622             : 
     623     1152751 :         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     1152751 :         return new_sd;
     631             : }

Generated by: LCOV version 1.14