Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/secdesc.c

    r414 r740  
    2222
    2323#include "includes.h"
     24#include "../librpc/gen_ndr/ndr_security.h"
     25#include "../libcli/security/security.h"
     26
     27#define ALL_SECURITY_INFORMATION (SECINFO_OWNER|SECINFO_GROUP|\
     28                                        SECINFO_DACL|SECINFO_SACL|\
     29                                        SECINFO_UNPROTECTED_SACL|\
     30                                        SECINFO_UNPROTECTED_DACL|\
     31                                        SECINFO_PROTECTED_SACL|\
     32                                        SECINFO_PROTECTED_DACL)
    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 struct security_descriptor *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 &= ~SECINFO_OWNER;
    4655        }
    4756        if (sd->group_sid == NULL) {
    48                 sec_info &= ~GROUP_SECURITY_INFORMATION;
     57                sec_info &= ~SECINFO_GROUP;
    4958        }
    5059        if (sd->sacl == NULL) {
    51                 sec_info &= ~SACL_SECURITY_INFORMATION;
     60                sec_info &= ~SECINFO_SACL;
    5261        }
    5362        if (sd->dacl == NULL) {
    54                 sec_info &= ~DACL_SECURITY_INFORMATION;
     63                sec_info &= ~SECINFO_DACL;
    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;
     75struct sec_desc_buf *sec_desc_merge_buf(TALLOC_CTX *ctx, struct sec_desc_buf *new_sdb, struct sec_desc_buf *old_sdb)
     76{
     77        struct dom_sid *owner_sid, *group_sid;
     78        struct sec_desc_buf *return_sdb;
     79        struct security_acl *dacl, *sacl;
     80        struct security_descriptor *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 struct dom_sid *owner_sid, const struct dom_sid *grp_sid,
     171                        struct security_acl *sacl, struct security_acl *dacl, size_t *sd_size)
     172{
     173        struct security_descriptor *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, struct security_descriptor)) == 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 = dom_sid_dup(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 = dom_sid_dup(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 struct security_descriptor structure.
     238********************************************************************/
     239
     240struct security_descriptor *dup_sec_desc(TALLOC_CTX *ctx, const struct security_descriptor *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 struct security_descriptor structure with typical defaults.
     376********************************************************************/
     377
     378struct security_descriptor *make_standard_sec_desc(TALLOC_CTX *ctx, const struct dom_sid *owner_sid, const struct dom_sid *grp_sid,
     379                                 struct security_acl *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 struct sec_desc_buf structure.
     388********************************************************************/
     389
     390struct sec_desc_buf *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, struct security_descriptor *sec_desc)
     391{
     392        struct sec_desc_buf *dst;
     393
     394        if((dst = TALLOC_ZERO_P(ctx, struct sec_desc_buf)) == 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 struct sec_desc_buf structure.
     409********************************************************************/
     410
     411struct sec_desc_buf *dup_sec_desc_buf(TALLOC_CTX *ctx, struct sec_desc_buf *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 struct security_descriptor.
     421********************************************************************/
     422
     423NTSTATUS sec_desc_add_sid(TALLOC_CTX *ctx, struct security_descriptor **psd, const struct dom_sid *sid, uint32 mask, size_t *sd_size)
     424{
     425        struct security_descriptor *sd   = 0;
     426        struct security_acl  *dacl = 0;
     427        struct security_ace  *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 struct security_descriptor.
     454********************************************************************/
     455
     456NTSTATUS sec_desc_mod_sid(struct security_descriptor *sd, struct dom_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 struct security_descriptor.
     473********************************************************************/
     474
     475NTSTATUS sec_desc_del_sid(TALLOC_CTX *ctx, struct security_descriptor **psd, struct dom_sid *sid, size_t *sd_size)
     476{
     477        struct security_descriptor *sd   = 0;
     478        struct security_acl  *dacl = 0;
     479        struct security_ace  *ace  = 0;
    430480        NTSTATUS  status;
    431481
     
    453503
    454504/*
    455  * Determine if an ACE is inheritable
     505 * Determine if an struct security_ace is inheritable
    456506 */
    457507
    458 static bool is_inheritable_ace(const SEC_ACE *ace,
     508static bool is_inheritable_ace(const struct security_ace *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 struct security_descriptor *parent_ctr, bool container)
    483533{
    484534        unsigned int i;
    485         const SEC_ACL *the_acl = parent_ctr->dacl;
     535        const struct security_acl *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 struct security_ace *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                                        struct security_descriptor **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 struct security_descriptor *parent_ctr,
     555                                        const struct dom_sid *owner_sid,
     556                                        const struct dom_sid *group_sid,
    507557                                        bool container)
    508558{
    509         SEC_ACL *new_dacl = NULL, *the_acl = NULL;
    510         SEC_ACE *new_ace_list = NULL;
     559        struct security_acl *new_dacl = NULL, *the_acl = NULL;
     560        struct security_ace *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, struct security_ace,
    528578                                                2*the_acl->num_aces))) {
    529579                        return NT_STATUS_NO_MEMORY;
     
    534584
    535585        for (i = 0; i < the_acl->num_aces; i++) {
    536                 const SEC_ACE *ace = &the_acl->aces[i];
    537                 SEC_ACE *new_ace = &new_ace_list[new_ace_list_ndx];
    538                 const DOM_SID *ptrustee = &ace->trustee;
    539                 const DOM_SID *creator = NULL;
     586                const struct security_ace *ace = &the_acl->aces[i];
     587                struct security_ace *new_ace = &new_ace_list[new_ace_list_ndx];
     588                const struct dom_sid *ptrustee = &ace->trustee;
     589                const struct dom_sid *creator = NULL;
    540590                uint8 new_flags = ace->flags;
    541591
     
    559609
    560610                /* The CREATOR sids are special when inherited */
    561                 if (sid_equal(ptrustee, &global_sid_Creator_Owner)) {
     611                if (dom_sid_equal(ptrustee, &global_sid_Creator_Owner)) {
    562612                        creator = &global_sid_Creator_Owner;
    563613                        ptrustee = owner_sid;
    564                 } else if (sid_equal(ptrustee, &global_sid_Creator_Group)) {
     614                } else if (dom_sid_equal(ptrustee, &global_sid_Creator_Group)) {
    565615                        creator = &global_sid_Creator_Group;
    566616                        ptrustee = group_sid;
     
    635685
    636686NTSTATUS se_create_child_secdesc_buf(TALLOC_CTX *ctx,
    637                                         SEC_DESC_BUF **ppsdb,
    638                                         const SEC_DESC *parent_ctr,
     687                                        struct sec_desc_buf **ppsdb,
     688                                        const struct security_descriptor *parent_ctr,
    639689                                        bool container)
    640690{
    641691        NTSTATUS status;
    642692        size_t size = 0;
    643         SEC_DESC *sd = NULL;
     693        struct security_descriptor *sd = NULL;
    644694
    645695        *ppsdb = NULL;
Note: See TracChangeset for help on using the changeset viewer.