Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/lib/secdesc.c

    r414 r745  
    2222
    2323#include "includes.h"
     24
     25
     26
     27
     28
     29
     30
     31
     32
    2433
    2534/* Map generic permissions to file object specific permissions */
     
    3645********************************************************************/
    3746
    38 uint32_t get_sec_info(const SEC_DESC *sd)
     47uint32_t get_sec_info(const *sd)
    3948{
    4049        uint32_t sec_info = ALL_SECURITY_INFORMATION;
     
    4352
    4453        if (sd->owner_sid == NULL) {
    45                 sec_info &= ~OWNER_SECURITY_INFORMATION;
     54                sec_info &= ~;
    4655        }
    4756        if (sd->group_sid == NULL) {
    48                 sec_info &= ~GROUP_SECURITY_INFORMATION;
     57                sec_info &= ~;
    4958        }
    5059        if (sd->sacl == NULL) {
    51                 sec_info &= ~SACL_SECURITY_INFORMATION;
     60                sec_info &= ~S;
    5261        }
    5362        if (sd->dacl == NULL) {
    54                 sec_info &= ~DACL_SECURITY_INFORMATION;
     63                sec_info &= ~;
    5564        }
    5665
     
    6473********************************************************************/
    6574
    66 SEC_DESC_BUF *sec_desc_merge(TALLOC_CTX *ctx, SEC_DESC_BUF *new_sdb, SEC_DESC_BUF *old_sdb)
    67 {
    68         DOM_SID *owner_sid, *group_sid;
    69         SEC_DESC_BUF *return_sdb;
    70         SEC_ACL *dacl, *sacl;
    71         SEC_DESC *psd = NULL;
     75 *old_sdb)
     76{
     77        *owner_sid, *group_sid;
     78        *return_sdb;
     79        *dacl, *sacl;
     80        *psd = NULL;
    7281        uint16 secdesc_type;
    7382        size_t secdesc_size;
     
    109118}
    110119
    111 /*******************************************************************
    112  Creates a SEC_DESC structure
    113 ********************************************************************/
    114 
    115 SEC_DESC *make_sec_desc(TALLOC_CTX *ctx,
     120struct security_descriptor *sec_desc_merge(TALLOC_CTX *ctx, struct security_descriptor *new_sdb, struct security_descriptor *old_sdb)
     121{
     122        struct dom_sid *owner_sid, *group_sid;
     123        struct security_acl *dacl, *sacl;
     124        struct security_descriptor *psd = NULL;
     125        uint16 secdesc_type;
     126        size_t secdesc_size;
     127
     128        /* Copy over owner and group sids.  There seems to be no flag for
     129           this so just check the pointer values. */
     130
     131        owner_sid = new_sdb->owner_sid ? new_sdb->owner_sid :
     132                old_sdb->owner_sid;
     133
     134        group_sid = new_sdb->group_sid ? new_sdb->group_sid :
     135                old_sdb->group_sid;
     136
     137        secdesc_type = new_sdb->type;
     138
     139        /* Ignore changes to the system ACL.  This has the effect of making
     140           changes through the security tab audit button not sticking.
     141           Perhaps in future Samba could implement these settings somehow. */
     142
     143        sacl = NULL;
     144        secdesc_type &= ~SEC_DESC_SACL_PRESENT;
     145
     146        /* Copy across discretionary ACL */
     147
     148        if (secdesc_type & SEC_DESC_DACL_PRESENT) {
     149                dacl = new_sdb->dacl;
     150        } else {
     151                dacl = old_sdb->dacl;
     152        }
     153
     154        /* Create new security descriptor from bits */
     155        psd = make_sec_desc(ctx, new_sdb->revision, secdesc_type,
     156                            owner_sid, group_sid, sacl, dacl, &secdesc_size);
     157
     158        return psd;
     159}
     160
     161/*******************************************************************
     162 Creates a struct security_descriptor structure
     163********************************************************************/
     164
     165#define  SEC_DESC_HEADER_SIZE (2 * sizeof(uint16) + 4 * sizeof(uint32))
     166
     167struct security_descriptor *make_sec_desc(TALLOC_CTX *ctx,
    116168                        enum security_descriptor_revision revision,
    117169                        uint16 type,
    118                         const DOM_SID *owner_sid, const DOM_SID *grp_sid,
    119                         SEC_ACL *sacl, SEC_ACL *dacl, size_t *sd_size)
    120 {
    121         SEC_DESC *dst;
     170                        const *grp_sid,
     171                        *dacl, size_t *sd_size)
     172{
     173        *dst;
    122174        uint32 offset     = 0;
    123175
    124176        *sd_size = 0;
    125177
    126         if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)
     178        if(( dst = TALLOC_ZERO_P(ctx, )) == NULL)
    127179                return NULL;
    128180
     
    140192        dst->dacl      = NULL;
    141193
    142         if(owner_sid && ((dst->owner_sid = sid_dup_talloc(dst,owner_sid)) == NULL))
     194        if(owner_sid && ((dst->owner_sid = (dst,owner_sid)) == NULL))
    143195                goto error_exit;
    144196
    145         if(grp_sid && ((dst->group_sid = sid_dup_talloc(dst,grp_sid)) == NULL))
     197        if(grp_sid && ((dst->group_sid = (dst,grp_sid)) == NULL))
    146198                goto error_exit;
    147199
     
    166218
    167219        if (dst->owner_sid != NULL) {
    168                 offset += ndr_size_dom_sid(dst->owner_sid, NULL, 0);
     220                offset += ndr_size_dom_sid(dst->owner_sid, 0);
    169221        }
    170222
    171223        if (dst->group_sid != NULL) {
    172                 offset += ndr_size_dom_sid(dst->group_sid, NULL, 0);
     224                offset += ndr_size_dom_sid(dst->group_sid, 0);
    173225        }
    174226
     
    183235
    184236/*******************************************************************
    185  Duplicate a SEC_DESC structure. 
    186 ********************************************************************/
    187 
    188 SEC_DESC *dup_sec_desc(TALLOC_CTX *ctx, const SEC_DESC *src)
     237 Duplicate a
     238********************************************************************/
     239
     240 *src)
    189241{
    190242        size_t dummy;
     
    209261
    210262        ndr_err = ndr_push_struct_blob(
    211                 &blob, mem_ctx, NULL, secdesc,
     263                &blob, mem_ctx, secdesc,
    212264                (ndr_push_flags_fn_t)ndr_push_security_descriptor);
    213265
     
    215267                DEBUG(0, ("ndr_push_security_descriptor failed: %s\n",
    216268                          ndr_errstr(ndr_err)));
    217                 return ndr_map_error2ntstatus(ndr_err);;
     269                return ndr_map_error2ntstatus(ndr_err);
    218270        }
    219271
     
    235287
    236288        ndr_err = ndr_push_struct_blob(
    237                 &blob, mem_ctx, NULL, secdesc_buf,
     289                &blob, mem_ctx, secdesc_buf,
    238290                (ndr_push_flags_fn_t)ndr_push_sec_desc_buf);
    239291
     
    241293                DEBUG(0, ("ndr_push_sec_desc_buf failed: %s\n",
    242294                          ndr_errstr(ndr_err)));
    243                 return ndr_map_error2ntstatus(ndr_err);;
     295                return ndr_map_error2ntstatus(ndr_err);
    244296        }
    245297
     
    270322        blob = data_blob_const(data, len);
    271323
    272         ndr_err = ndr_pull_struct_blob(
    273                 &blob, result, NULL, result,
     324        ndr_err = ndr_pull_struct_blob(&blob, result, result,
    274325                (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
    275326
     
    278329                          ndr_errstr(ndr_err)));
    279330                TALLOC_FREE(result);
    280                 return ndr_map_error2ntstatus(ndr_err);;
     331                return ndr_map_error2ntstatus(ndr_err);
    281332        }
    282333
     
    307358        blob = data_blob_const(data, len);
    308359
    309         ndr_err = ndr_pull_struct_blob(
    310                 &blob, result, NULL, result,
     360        ndr_err = ndr_pull_struct_blob(&blob, result, result,
    311361                (ndr_pull_flags_fn_t)ndr_pull_sec_desc_buf);
    312362
     
    315365                          ndr_errstr(ndr_err)));
    316366                TALLOC_FREE(result);
    317                 return ndr_map_error2ntstatus(ndr_err);;
     367                return ndr_map_error2ntstatus(ndr_err);
    318368        }
    319369
     
    323373
    324374/*******************************************************************
    325  Creates a SEC_DESC structure with typical defaults.
    326 ********************************************************************/
    327 
    328 SEC_DESC *make_standard_sec_desc(TALLOC_CTX *ctx, const DOM_SID *owner_sid, const DOM_SID *grp_sid,
    329                                  SEC_ACL *dacl, size_t *sd_size)
     375 Creates a structure with typical defaults.
     376********************************************************************/
     377
     378 *grp_sid,
     379                                  *dacl, size_t *sd_size)
    330380{
    331381        return make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
     
    335385
    336386/*******************************************************************
    337  Creates a SEC_DESC_BUF structure.
    338 ********************************************************************/
    339 
    340 SEC_DESC_BUF *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, SEC_DESC *sec_desc)
    341 {
    342         SEC_DESC_BUF *dst;
    343 
    344         if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL)
     387 Creates a structure.
     388********************************************************************/
     389
     390 *sec_desc)
     391{
     392        *dst;
     393
     394        if((dst = TALLOC_ZERO_P(ctx, )) == NULL)
    345395                return NULL;
    346396
     
    356406
    357407/*******************************************************************
    358  Duplicates a SEC_DESC_BUF structure.
    359 ********************************************************************/
    360 
    361 SEC_DESC_BUF *dup_sec_desc_buf(TALLOC_CTX *ctx, SEC_DESC_BUF *src)
     408 Duplicates a structure.
     409********************************************************************/
     410
     411 *src)
    362412{
    363413        if(src == NULL)
     
    368418
    369419/*******************************************************************
    370  Add a new SID with its permissions to SEC_DESC.
    371 ********************************************************************/
    372 
    373 NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, SEC_DESC **psd, DOM_SID *sid, uint32 mask, size_t *sd_size)
    374 {
    375         SEC_DESC *sd   = 0;
    376         SEC_ACL  *dacl = 0;
    377         SEC_ACE  *ace  = 0;
     420 Add a new SID with its permissions to .
     421********************************************************************/
     422
     423NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, *sid, uint32 mask, size_t *sd_size)
     424{
     425        *sd   = 0;
     426          *dacl = 0;
     427          *ace  = 0;
    378428        NTSTATUS  status;
    379429
     
    401451
    402452/*******************************************************************
    403  Modify a SID's permissions in a SEC_DESC.
    404 ********************************************************************/
    405 
    406 NTSTATUS sec_desc_mod_sid(SEC_DESC *sd, DOM_SID *sid, uint32 mask)
     453 Modify a SID's permissions in a .
     454********************************************************************/
     455
     456NTSTATUS sec_desc_mod_sid( *sid, uint32 mask)
    407457{
    408458        NTSTATUS status;
     
    420470
    421471/*******************************************************************
    422  Delete a SID from a SEC_DESC.
    423 ********************************************************************/
    424 
    425 NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, SEC_DESC **psd, DOM_SID *sid, size_t *sd_size)
    426 {
    427         SEC_DESC *sd   = 0;
    428         SEC_ACL  *dacl = 0;
    429         SEC_ACE  *ace  = 0;
     472 Delete a SID from a .
     473********************************************************************/
     474
     475NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, *sid, size_t *sd_size)
     476{
     477        *sd   = 0;
     478          *dacl = 0;
     479          *ace  = 0;
    430480        NTSTATUS  status;
    431481
     
    453503
    454504/*
    455  * Determine if an ACE is inheritable
     505 * Determine if an is inheritable
    456506 */
    457507
    458 static bool is_inheritable_ace(const SEC_ACE *ace,
     508static bool is_inheritable_ace(const *ace,
    459509                                bool container)
    460510{
     
    480530 */
    481531
    482 bool sd_has_inheritable_components(const SEC_DESC *parent_ctr, bool container)
     532bool sd_has_inheritable_components(const *parent_ctr, bool container)
    483533{
    484534        unsigned int i;
    485         const SEC_ACL *the_acl = parent_ctr->dacl;
     535        const *the_acl = parent_ctr->dacl;
    486536
    487537        for (i = 0; i < the_acl->num_aces; i++) {
    488                 const SEC_ACE *ace = &the_acl->aces[i];
     538                const *ace = &the_acl->aces[i];
    489539
    490540                if (is_inheritable_ace(ace, container)) {
     
    500550
    501551NTSTATUS se_create_child_secdesc(TALLOC_CTX *ctx,
    502                                         SEC_DESC **ppsd,
     552                                        **ppsd,
    503553                                        size_t *psize,
    504                                         const SEC_DESC *parent_ctr,
    505                                         const DOM_SID *owner_sid,
    506                                         const DOM_SID *group_sid,
     554                                        const *parent_ctr,
     555                                        const *owner_sid,
     556                                        const *group_sid,
    507557                                        bool container)
    508558{
    509         SEC_ACL *new_dacl = NULL, *the_acl = NULL;
    510         SEC_ACE *new_ace_list = NULL;
     559        *new_dacl = NULL, *the_acl = NULL;
     560        *new_ace_list = NULL;
    511561        unsigned int new_ace_list_ndx = 0, i;
    512562
     
    525575                }
    526576
    527                 if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE,
     577                if (!(new_ace_list = TALLOC_ARRAY(ctx,