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/sharesec.c

    r414 r745  
    1919
    2020#include "includes.h"
     21
     22
     23
     24
     25
    2126
    2227/*******************************************************************
     
    2732#define SHARE_DATABASE_VERSION_V1 1
    2833#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
    29 
     34#define SHARE_DATABASE_VERSION_V3 3 /* canonicalized sharenames as lower case */
     35
     36#define SHARE_SECURITY_DB_KEY_PREFIX_STR "SECDESC/"
    3037/* Map generic permissions to file object specific permissions */
    3138
     
    3845}
    3946
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
    40132bool share_info_db_init(void)
    41133{
    42134        const char *vstring = "INFO/version";
    43135        int32 vers_id;
     136
     137
    44138
    45139        if (share_db != NULL) {
     
    56150
    57151        vers_id = dbwrap_fetch_int32(share_db, vstring);
    58         if (vers_id == SHARE_DATABASE_VERSION_V2) {
     152        if (vers_id == SHARE_DATABASE_VERSION_V) {
    59153                return true;
    60154        }
     
    67161
    68162        vers_id = dbwrap_fetch_int32(share_db, vstring);
    69         if (vers_id == SHARE_DATABASE_VERSION_V2) {
     163        if (vers_id == SHARE_DATABASE_VERSION_V) {
    70164                /*
    71165                 * Race condition
     
    77171        }
    78172
     173
     174
    79175        /* Cope with byte-reversed older versions of the db. */
    80176        if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
     
    90186
    91187        if (vers_id != SHARE_DATABASE_VERSION_V2) {
    92                 int ret;
    93188                ret = share_db->traverse(share_db, delete_fn, NULL);
    94189                if (ret < 0) {
     
    103198        }
    104199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
    105213        if (share_db->transaction_commit(share_db) != 0) {
    106214                DEBUG(0, ("transaction_commit failed\n"));
     
    123231 ********************************************************************/
    124232
    125 SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)
     233 *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)
    126234{
    127235        uint32_t sa;
    128         SEC_ACE ace;
    129         SEC_ACL *psa = NULL;
    130         SEC_DESC *psd = NULL;
     236        ace;
     237        *psa = NULL;
     238        *psd = NULL;
    131239        uint32 spec_access = def_access;
    132240
     
    154262 ********************************************************************/
    155263
    156 SEC_DESC *get_share_security( TALLOC_CTX *ctx, const char *servicename,
     264 *get_share_security( TALLOC_CTX *ctx, const char *servicename,
    157265                              size_t *psize)
    158266{
    159267        char *key;
    160         SEC_DESC *psd = NULL;
     268        *psd = NULL;
    161269        TDB_DATA data;
     270
    162271        NTSTATUS status;
    163272
     273
     274
     275
     276
    164277        if (!share_info_db_init()) {
     278
    165279                return NULL;
    166280        }
    167281
    168         if (!(key = talloc_asprintf(ctx, "SECDESC/%s", servicename))) {
     282        if (!(key = talloc_asprintf(ctx, SHARE_SECURITY_DB_KEY_PREFIX_STR "%s", c_servicename))) {
     283                TALLOC_FREE(c_servicename);
    169284                DEBUG(0, ("talloc_asprintf failed\n"));
    170285                return NULL;
    171286        }
     287
     288
    172289
    173290        data = dbwrap_fetch_bystring(share_db, talloc_tos(), key);
     
    187304                DEBUG(0, ("unmarshall_sec_desc failed: %s\n",
    188305                          nt_errstr(status)));
    189                 return NULL;
    190         }
    191 
    192         if (psd)
    193                 *psize = ndr_size_security_descriptor(psd, NULL, 0);
     306                return get_share_security_default(ctx, psize,
     307                                                  GENERIC_ALL_ACCESS);
     308        }
     309
     310        if (psd) {
     311                *psize = ndr_size_security_descriptor(psd, 0);
     312        } else {
     313                return get_share_security_default(ctx, psize,
     314                                                  GENERIC_ALL_ACCESS);
     315        }
    194316
    195317        return psd;
     
    200322 ********************************************************************/
    201323
    202 bool set_share_security(const char *share_name, SEC_DESC *psd)
    203 {
    204         TALLOC_CTX *frame;
     324bool set_share_security(const char *share_name, *psd)
     325{
     326        TALLOC_CTX *frame;
    205327        char *key;
    206328        bool ret = False;
    207329        TDB_DATA blob;
    208330        NTSTATUS status;
     331
     332
     333
     334
     335
    209336
    210337        if (!share_info_db_init()) {
    211                 return False;
    212         }
    213 
    214         frame = talloc_stackframe();
     338                goto out;
     339        }
    215340
    216341        status = marshall_sec_desc(frame, psd, &blob.dptr, &blob.dsize);
     
    222347        }
    223348
    224         if (!(key = talloc_asprintf(frame, "SECDESC/%s", share_name))) {
     349        if (!(key = talloc_asprintf(frame, share_name))) {
    225350                DEBUG(0, ("talloc_asprintf failed\n"));
    226351                goto out;
     
    252377        char *key;
    253378        NTSTATUS status;
     379
     380
     381
     382
     383
    254384
    255385        if (!share_info_db_init()) {
     386
    256387                return False;
    257388        }
    258389
    259         if (!(key = talloc_asprintf(talloc_tos(), "SECDESC/%s",
    260                                     servicename))) {
     390        if (!(key = talloc_asprintf(talloc_tos(), SHARE_SECURITY_DB_KEY_PREFIX_STR "%s",
     391                                    c_servicename))) {
     392                TALLOC_FREE(c_servicename);
    261393                return False;
    262394        }
     
    266398        if (!NT_STATUS_IS_OK(status)) {
    267399                DEBUG(0, ("delete_share_security: Failed to delete entry for "
    268                           "share %s: %s\n", servicename, nt_errstr(status)));
     400                          "share %s: %s\n", c_servicename, nt_errstr(status)));
     401                TALLOC_FREE(c_servicename);
    269402                return False;
    270403        }
    271404
     405
    272406        return True;
    273407}
     
    277411********************************************************************/
    278412
    279 bool share_access_check(const NT_USER_TOKEN *token, const char *sharename,
    280                         uint32 desired_access)
     413bool share_access_check(const struct security_token *token,
     414                        const char *sharename,
     415                        uint32 desired_access,
     416                        uint32_t *pgranted)
    281417{
    282418        uint32 granted;
    283419        NTSTATUS status;
    284         SEC_DESC *psd = NULL;
     420        *psd = NULL;
    285421        size_t sd_size;
    286422
     
    294430
    295431        TALLOC_FREE(psd);
     432
     433
     434
     435
    296436
    297437        return NT_STATUS_IS_OK(status);
     
    302442***************************************************************************/
    303443
    304 bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, SEC_DESC **ppsd)
     444bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, **ppsd)
    305445{
    306446        size_t s_size = 0;
    307447        const char *pacl = acl_str;
    308448        int num_aces = 0;
    309         SEC_ACE *ace_list = NULL;
    310         SEC_ACL *psa = NULL;
    311         SEC_DESC *psd = NULL;
     449        *ace_list = NULL;
     450        *psa = NULL;
     451        *psd = NULL;
    312452        size_t sd_size = 0;
    313453        int i;
     
    317457        /* If the acl string is blank return "Everyone:R" */
    318458        if (!*acl_str) {
    319                 SEC_DESC *default_psd = get_share_security_default(ctx, &s_size, GENERIC_READ_ACCESS);
     459                *default_psd = get_share_security_default(ctx, &s_size, GENERIC_READ_ACCESS);
    320460                if (!default_psd) {
    321461                        return False;
     
    330470        num_aces += count_chars(pacl,',');
    331471
    332         ace_list = TALLOC_ARRAY(ctx, SEC_ACE, num_aces);
     472        ace_list = TALLOC_ARRAY(ctx, , num_aces);
    333473        if (!ace_list) {
    334474                return False;
     
    339479                uint32 g_access;
    340480                uint32 s_access;
    341                 DOM_SID sid;
     481                sid;
    342482                char *sidstr;
    343483                enum security_ace_type type = SEC_ACE_TYPE_ACCESS_ALLOWED;
Note: See TracChangeset for help on using the changeset viewer.