Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

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

    r740 r988  
    2222#include "../libcli/security/security.h"
    2323#include "../librpc/gen_ndr/ndr_security.h"
    24 #include "dbwrap.h"
     24#include "dbwrap/dbwrap.h"
     25#include "dbwrap/dbwrap_open.h"
    2526#include "util_tdb.h"
    2627
     
    4142static int delete_fn(struct db_record *rec, void *priv)
    4243{
    43         rec->delete_rec(rec);
     44        dbwrap_record_delete(rec);
    4445        return 0;
    4546}
     
    5859        bool *p_upgrade_ok = (bool *)priv;
    5960        NTSTATUS status;
     61        TDB_DATA key;
     62        TDB_DATA value;
     63
     64        key = dbwrap_record_get_key(rec);
    6065
    6166        /* Is there space for a one character sharename ? */
    62         if (rec->key.dsize <= prefix_len+2) {
     67        if (key.dsize <= prefix_len+2) {
    6368                return 0;
    6469        }
    6570
    6671        /* Does it start with the share key prefix ? */
    67         if (memcmp(rec->key.dptr, SHARE_SECURITY_DB_KEY_PREFIX_STR,
     72        if (memcmp(key.dptr, SHARE_SECURITY_DB_KEY_PREFIX_STR,
    6873                        prefix_len) != 0) {
    6974                return 0;
     
    7176
    7277        /* Is it a null terminated string as a key ? */
    73         if (rec->key.dptr[rec->key.dsize-1] != '\0') {
     78        if (key.dptr[key.dsize-1] != '\0') {
    7479                return 0;
    7580        }
    7681
    7782        /* Bytes after the prefix are the sharename string. */
    78         servicename = (char *)&rec->key.dptr[prefix_len];
     83        servicename = (char *)&key.dptr[prefix_len];
    7984        c_servicename = canonicalize_servicename(talloc_tos(), servicename);
    8085        if (!c_servicename) {
     
    8994
    9095        /* Oops. Need to canonicalize name, delete old then store new. */
    91         status = rec->delete_rec(rec);
     96        status = dbwrap_record_delete(rec);
    9297        if (!NT_STATUS_IS_OK(status)) {
    9398                DEBUG(1, ("upgrade_v2_to_v3: Failed to delete secdesc for "
    94                           "%s: %s\n", rec->key.dptr, nt_errstr(status)));
     99                          "%s: %s\n", (const char *)key.dptr,
     100                          nt_errstr(status)));
    95101                TALLOC_FREE(c_servicename);
    96102                *p_upgrade_ok = false;
     
    98104        } else {
    99105                DEBUG(10, ("upgrade_v2_to_v3: deleted secdesc for "
    100                           "%s\n", rec->key.dptr ));
     106                          "%s\n", (const char *)key.dptr));
    101107        }
    102108
     
    107113        }
    108114
     115        value = dbwrap_record_get_value(rec);
    109116        status = dbwrap_store(share_db,
    110117                                string_term_tdb_data(newkey),
    111                                 rec->value,
     118                                value,
    112119                                TDB_REPLACE);
    113120
     
    133140{
    134141        const char *vstring = "INFO/version";
    135         int32 vers_id;
    136         int ret;
     142        int32_t vers_id = 0;
    137143        bool upgrade_ok = true;
     144        NTSTATUS status;
     145        char *db_path;
    138146
    139147        if (share_db != NULL) {
     
    141149        }
    142150
    143         share_db = db_open(NULL, state_path("share_info.tdb"), 0,
    144                                  TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
     151        db_path = state_path("share_info.tdb");
     152        if (db_path == NULL) {
     153                return false;
     154        }
     155
     156        share_db = db_open(NULL, db_path, 0,
     157                           TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
     158                           DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
    145159        if (share_db == NULL) {
    146160                DEBUG(0,("Failed to open share info database %s (%s)\n",
    147                         state_path("share_info.tdb"), strerror(errno) ));
     161                         db_path, strerror(errno)));
     162                TALLOC_FREE(db_path);
    148163                return False;
    149164        }
    150 
    151         vers_id = dbwrap_fetch_int32(share_db, vstring);
     165        TALLOC_FREE(db_path);
     166
     167        status = dbwrap_fetch_int32_bystring(share_db, vstring, &vers_id);
     168        if (!NT_STATUS_IS_OK(status)) {
     169                vers_id = 0;
     170        }
     171
    152172        if (vers_id == SHARE_DATABASE_VERSION_V3) {
    153173                return true;
    154174        }
    155175
    156         if (share_db->transaction_start(share_db) != 0) {
     176        if (dbwrap_transaction_start(share_db) != 0) {
    157177                DEBUG(0, ("transaction_start failed\n"));
    158178                TALLOC_FREE(share_db);
     
    160180        }
    161181
    162         vers_id = dbwrap_fetch_int32(share_db, vstring);
     182        status = dbwrap_fetch_int32_bystring(share_db, vstring, &vers_id);
     183        if (!NT_STATUS_IS_OK(status)) {
     184                vers_id = 0;
     185        }
     186
    163187        if (vers_id == SHARE_DATABASE_VERSION_V3) {
    164188                /*
    165189                 * Race condition
    166190                 */
    167                 if (share_db->transaction_cancel(share_db)) {
     191                if (dbwrap_transaction_cancel(share_db)) {
    168192                        smb_panic("transaction_cancel failed");
    169193                }
     
    177201                /* Written on a bigendian machine with old fetch_int code. Save as le. */
    178202
    179                 if (dbwrap_store_int32(share_db, vstring,
    180                                        SHARE_DATABASE_VERSION_V2) != 0) {
    181                         DEBUG(0, ("dbwrap_store_int32 failed\n"));
     203                status = dbwrap_store_int32_bystring(
     204                        share_db, vstring, SHARE_DATABASE_VERSION_V2);
     205                if (!NT_STATUS_IS_OK(status)) {
     206                        DEBUG(0, ("dbwrap_store_int32 failed: %s\n",
     207                                  nt_errstr(status)));
    182208                        goto cancel;
    183209                }
     
    186212
    187213        if (vers_id != SHARE_DATABASE_VERSION_V2) {
    188                 ret = share_db->traverse(share_db, delete_fn, NULL);
    189                 if (ret < 0) {
     214                status = dbwrap_traverse(share_db, delete_fn, NULL, NULL);
     215                if (!NT_STATUS_IS_OK(status)) {
    190216                        DEBUG(0, ("traverse failed\n"));
    191217                        goto cancel;
    192218                }
    193                 if (dbwrap_store_int32(share_db, vstring,
    194                                        SHARE_DATABASE_VERSION_V2) != 0) {
    195                         DEBUG(0, ("dbwrap_store_int32 failed\n"));
     219                status = dbwrap_store_int32_bystring(
     220                        share_db, vstring, SHARE_DATABASE_VERSION_V2);
     221                if (!NT_STATUS_IS_OK(status)) {
     222                        DEBUG(0, ("dbwrap_store_int32 failed: %s\n",
     223                                  nt_errstr(status)));
    196224                        goto cancel;
    197225                }
     
    200228        /* Finally upgrade to version 3, with canonicalized sharenames. */
    201229
    202         ret = share_db->traverse(share_db, upgrade_v2_to_v3, &upgrade_ok);
    203         if (ret < 0 || upgrade_ok == false) {
     230        status = dbwrap_traverse(share_db, upgrade_v2_to_v3, &upgrade_ok, NULL);
     231        if (!NT_STATUS_IS_OK(status) || upgrade_ok == false) {
    204232                DEBUG(0, ("traverse failed\n"));
    205233                goto cancel;
    206234        }
    207         if (dbwrap_store_int32(share_db, vstring,
    208                                SHARE_DATABASE_VERSION_V3) != 0) {
    209                 DEBUG(0, ("dbwrap_store_int32 failed\n"));
     235        status = dbwrap_store_int32_bystring(
     236                share_db, vstring, SHARE_DATABASE_VERSION_V3);
     237        if (!NT_STATUS_IS_OK(status)) {
     238                DEBUG(0, ("dbwrap_store_int32 failed: %s\n",
     239                          nt_errstr(status)));
    210240                goto cancel;
    211241        }
    212242
    213         if (share_db->transaction_commit(share_db) != 0) {
     243        if (dbwrap_transaction_commit(share_db) != 0) {
    214244                DEBUG(0, ("transaction_commit failed\n"));
    215245                return false;
     
    219249
    220250 cancel:
    221         if (share_db->transaction_cancel(share_db)) {
     251        if (dbwrap_transaction_cancel(share_db)) {
    222252                smb_panic("transaction_cancel failed");
    223253        }
     
    231261 ********************************************************************/
    232262
    233 struct security_descriptor *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32 def_access)
     263struct security_descriptor *get_share_security_default( TALLOC_CTX *ctx, size_t *psize, uint32_t def_access)
    234264{
    235265        uint32_t sa;
     
    237267        struct security_acl *psa = NULL;
    238268        struct security_descriptor *psd = NULL;
    239         uint32 spec_access = def_access;
     269        uint32_t spec_access = def_access;
    240270
    241271        se_map_generic(&spec_access, &file_generic_mapping);
     
    288318        TALLOC_FREE(c_servicename);
    289319
    290         data = dbwrap_fetch_bystring(share_db, talloc_tos(), key);
     320        status = dbwrap_fetch_bystring(share_db, talloc_tos(), key, &data);
    291321
    292322        TALLOC_FREE(key);
    293323
    294         if (data.dptr == NULL) {
     324        if (!NT_STATUS_IS_OK(status)) {
    295325                return get_share_security_default(ctx, psize,
    296                                                   GENERIC_ALL_ACCESS);
     326                                                  SEC_RIGHTS_DIR_ALL);
    297327        }
    298328
     
    302332
    303333        if (!NT_STATUS_IS_OK(status)) {
    304                 DEBUG(0, ("unmarshall_sec_desc failed: %s\n",
    305                           nt_errstr(status)));
    306334                return get_share_security_default(ctx, psize,
    307                                                   GENERIC_ALL_ACCESS);
     335                                                  SEC_RIGHTS_DIR_ALL);
    308336        }
    309337
     
    312340        } else {
    313341                return get_share_security_default(ctx, psize,
    314                                                   GENERIC_ALL_ACCESS);
     342                                                  SEC_RIGHTS_DIR_ALL);
    315343        }
    316344
     
    413441bool share_access_check(const struct security_token *token,
    414442                        const char *sharename,
    415                         uint32 desired_access,
     443                        uint32_t desired_access,
    416444                        uint32_t *pgranted)
    417445{
    418         uint32 granted;
     446        uint32_t granted;
    419447        NTSTATUS status;
    420448        struct security_descriptor *psd = NULL;
     
    424452
    425453        if (!psd) {
    426                 return True;
    427         }
    428 
    429         status = se_access_check(psd, token, desired_access, &granted);
     454                if (pgranted != NULL) {
     455                        *pgranted = desired_access;
     456                }
     457                return false;
     458        }
     459
     460        status = se_file_access_check(psd, token, true, desired_access, &granted);
    430461
    431462        TALLOC_FREE(psd);
     
    470501        num_aces += count_chars(pacl,',');
    471502
    472         ace_list = TALLOC_ARRAY(ctx, struct security_ace, num_aces);
     503        ace_list = talloc_array(ctx, struct security_ace, num_aces);
    473504        if (!ace_list) {
    474505                return False;
     
    477508        for (i = 0; i < num_aces; i++) {
    478509                uint32_t sa;
    479                 uint32 g_access;
    480                 uint32 s_access;
     510                uint32_t g_access;
     511                uint32_t s_access;
    481512                struct dom_sid sid;
    482513                char *sidstr;
Note: See TracChangeset for help on using the changeset viewer.