Ignore:
Timestamp:
May 24, 2009, 7:51:24 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update Samba 3.3 branch to 3.3.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.3.x/source/registry/reg_api.c

    r206 r223  
    9595static WERROR fill_subkey_cache(struct registry_key *key)
    9696{
     97        WERROR werr;
     98
    9799        if (key->subkeys != NULL) {
    98100                if (!reg_subkeys_need_update(key->key, key->subkeys)) {
     
    101103        }
    102104
    103         if (!(key->subkeys = TALLOC_ZERO_P(key, REGSUBKEY_CTR))) {
    104                 return WERR_NOMEM;
    105         }
     105        werr = regsubkey_ctr_init(key, &(key->subkeys));
     106        W_ERROR_NOT_OK_RETURN(werr);
    106107
    107108        if (fetch_reg_keys(key->key, key->subkeys) == -1) {
     
    128129        struct registry_key *regkey;
    129130        REGISTRY_KEY *key;
    130         REGSUBKEY_CTR   *subkeys = NULL;
     131        struct regsubkey_ctr    *subkeys = NULL;
    131132
    132133        DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name));
     
    194195        /* if the subkey count failed, bail out */
    195196
    196         if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) {
    197                 result = WERR_NOMEM;
     197        result = regsubkey_ctr_init(key, &subkeys);
     198        if (!W_ERROR_IS_OK(result)) {
    198199                goto done;
    199200        }
     
    309310        }
    310311
    311         if (idx >= key->subkeys->num_subkeys) {
     312        if (idx >= regsubkey_ctr_numkeys(key->subkeys)) {
    312313                return WERR_NO_MORE_ITEMS;
    313314        }
    314315
    315         if (!(*name = talloc_strdup(mem_ctx, key->subkeys->subkeys[idx]))) {
     316        if (!(*name = talloc_strdup(mem_ctx,
     317                        regsubkey_ctr_specific_key(key->subkeys, idx))))
     318        {
    316319                return WERR_NOMEM;
    317320        }
     
    407410
    408411        max_len = 0;
    409         for (i=0; i<key->subkeys->num_subkeys; i++) {
    410                 max_len = MAX(max_len, strlen(key->subkeys->subkeys[i]));
    411         }
    412 
    413         *num_subkeys = key->subkeys->num_subkeys;
     412        for (i=0; i< regsubkey_ctr_numkeys(key->subkeys); i++) {
     413                max_len = MAX(max_len,
     414                        strlen(regsubkey_ctr_specific_key(key->subkeys, i)));
     415        }
     416
     417        *num_subkeys = regsubkey_ctr_numkeys(key->subkeys);
    414418        *max_subkeylen = max_len;
    415419        *max_subkeysize = 0;    /* Class length? */
     
    521525        if (!W_ERROR_IS_OK(err)) goto done;
    522526
    523         err = regsubkey_ctr_addkey(create_parent->subkeys, path);
    524         if (!W_ERROR_IS_OK(err)) goto done;
    525 
    526         if (!store_reg_keys(create_parent->key, create_parent->subkeys)) {
    527                 TALLOC_FREE(create_parent->subkeys);
    528                 err = WERR_REG_IO_FAILURE;
    529                 goto done;
    530         }
     527        err = create_reg_subkey(key->key, path);
     528        W_ERROR_NOT_OK_GOTO_DONE(err);
    531529
    532530        /*
     
    547545{
    548546        WERROR err;
    549         TALLOC_CTX *mem_ctx;
    550547        char *name, *end;
    551         int num_subkeys;
    552548        struct registry_key *tmp_key, *key;
    553 
    554         if (!(mem_ctx = talloc_init("reg_createkey"))) return WERR_NOMEM;
    555 
    556         if (!(name = talloc_strdup(mem_ctx, path))) {
     549        TALLOC_CTX *mem_ctx = talloc_stackframe();
     550
     551        name = talloc_strdup(mem_ctx, path);
     552        if (name == NULL) {
    557553                err = WERR_NOMEM;
    558                 goto error;
     554                goto done;
    559555        }
    560556
    561557        /* check if the key has subkeys */
    562558        err = reg_openkey(mem_ctx, parent, name, REG_KEY_READ, &key);
    563         if (!W_ERROR_IS_OK(err)) {
    564                 goto error;
    565         }
    566         if (!W_ERROR_IS_OK(err = fill_subkey_cache(key))) {
    567                 goto error;
    568         }
    569         if (key->subkeys->num_subkeys > 0) {
     559        W_ERROR_NOT_OK_GOTO_DONE(err);
     560
     561        err = fill_subkey_cache(key);
     562        W_ERROR_NOT_OK_GOTO_DONE(err);
     563
     564        if (regsubkey_ctr_numkeys(key->subkeys) > 0) {
    570565                err = WERR_ACCESS_DENIED;
    571                 goto error;
     566                goto done;
    572567        }
    573568
    574569        /* no subkeys - proceed with delete */
    575         if ((end = strrchr(name, '\\')) != NULL) {
     570        end = strrchr(name, '\\');
     571        if (end != NULL) {
    576572                *end = '\0';
    577573
    578574                err = reg_openkey(mem_ctx, parent, name,
    579575                                  SEC_RIGHTS_CREATE_SUBKEY, &tmp_key);
    580                 if (!W_ERROR_IS_OK(err)) {
    581                         goto error;
    582                 }
     576                W_ERROR_NOT_OK_GOTO_DONE(err);
    583577
    584578                parent = tmp_key;
     
    588582        if (name[0] == '\0') {
    589583                err = WERR_INVALID_PARAM;
    590                 goto error;
    591         }
    592 
    593         if (!W_ERROR_IS_OK(err = fill_subkey_cache(parent))) {
    594                 goto error;
    595         }
    596 
    597         num_subkeys = parent->subkeys->num_subkeys;
    598 
    599         if (regsubkey_ctr_delkey(parent->subkeys, name) == num_subkeys) {
    600                 err = WERR_BADFILE;
    601                 goto error;
    602         }
    603 
    604         if (!store_reg_keys(parent->key, parent->subkeys)) {
    605                 TALLOC_FREE(parent->subkeys);
    606                 err = WERR_REG_IO_FAILURE;
    607                 goto error;
    608         }
    609 
    610         regkey_set_secdesc(key->key, NULL);
    611 
    612         err = WERR_OK;
    613 
    614  error:
     584                goto done;
     585        }
     586
     587        err = delete_reg_subkey(parent->key, name);
     588
     589done:
    615590        TALLOC_FREE(mem_ctx);
    616591        return err;
     
    727702        REGISTRY_KEY registry_key;
    728703        REGVAL_CTR *values;
    729         REGSUBKEY_CTR *subkeys;
     704        struct regsubkey_ctr *subkeys;
    730705        int i;
    731706        char *path = NULL;
     
    749724        /* now start parsing the values and subkeys */
    750725
    751         subkeys = TALLOC_ZERO_P(regfile->mem_ctx, REGSUBKEY_CTR);
    752         if (subkeys == NULL) {
    753                 return WERR_NOMEM;
    754         }
     726        result = regsubkey_ctr_init(regfile->mem_ctx, &subkeys);
     727        W_ERROR_NOT_OK_RETURN(result);
    755728
    756729        values = TALLOC_ZERO_P(subkeys, REGVAL_CTR);
     
    768741        }
    769742
    770         /* copy subkeys into the REGSUBKEY_CTR */
     743        /* copy subkeys into the struct regsubkey_ctr */
    771744
    772745        key->subkey_index = 0;
     
    862835        REGF_NK_REC *key;
    863836        REGVAL_CTR *values;
    864         REGSUBKEY_CTR *subkeys;
     837        struct regsubkey_ctr *subkeys;
    865838        int i, num_subkeys;
    866839        char *key_tmp = NULL;
     
    910883        /* lookup the values and subkeys */
    911884
    912         subkeys = TALLOC_ZERO_P(regfile->mem_ctx, REGSUBKEY_CTR);
    913         if (subkeys == NULL) {
    914                 return WERR_NOMEM;
    915         }
     885        result = regsubkey_ctr_init(regfile->mem_ctx, &subkeys);
     886        W_ERROR_NOT_OK_RETURN(result);
    916887
    917888        values = TALLOC_ZERO_P(subkeys, REGVAL_CTR);
     
    10921063        struct registry_key *key;
    10931064        char *subkey_name = NULL;
     1065        uint32 i;
    10941066
    10951067        mem_ctx = talloc_new(ctx);
     
    11051077        }
    11061078
    1107         while (W_ERROR_IS_OK(werr = reg_enumkey(mem_ctx, key, 0,
    1108                                                 &subkey_name, NULL)))
    1109         {
     1079        werr = fill_subkey_cache(key);
     1080        W_ERROR_NOT_OK_GOTO_DONE(werr);
     1081
     1082        /*
     1083         * loop from top to bottom for perfomance:
     1084         * this way, we need to rehash the regsubkey containers less
     1085         */
     1086        for (i = regsubkey_ctr_numkeys(key->subkeys) ; i > 0; i--) {
     1087                subkey_name = regsubkey_ctr_specific_key(key->subkeys, i-1);
    11101088                werr = reg_deletekey_recursive_internal(mem_ctx, key,
    1111                                                         subkey_name,
    1112                                                         true);
    1113                 if (!W_ERROR_IS_OK(werr)) {
    1114                         goto done;
    1115                 }
    1116         }
    1117         if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
    1118                 DEBUG(1, ("reg_deletekey_recursive_internal: "
    1119                           "Error enumerating subkeys: %s\n",
    1120                           dos_errstr(werr)));
    1121                 goto done;
    1122         }
    1123 
    1124         werr = WERR_OK;
     1089                                        subkey_name,
     1090                                        true);
     1091                W_ERROR_NOT_OK_GOTO_DONE(werr);
     1092        }
    11251093
    11261094        if (del_key) {
     
    11341102}
    11351103
     1104static WERROR reg_deletekey_recursive_trans(TALLOC_CTX *ctx,
     1105                                            struct registry_key *parent,
     1106                                            const char *path,
     1107                                            bool del_key)
     1108{
     1109        WERROR werr;
     1110
     1111        werr = regdb_transaction_start();
     1112        if (!W_ERROR_IS_OK(werr)) {
     1113                DEBUG(0, ("reg_deletekey_recursive_trans: "
     1114                          "error starting transaction: %s\n",
     1115                          dos_errstr(werr)));
     1116                return werr;
     1117        }
     1118
     1119        werr = reg_deletekey_recursive_internal(ctx, parent, path, del_key);
     1120
     1121        if (!W_ERROR_IS_OK(werr)) {
     1122                DEBUG(1, (__location__ " failed to delete key '%s' from key "
     1123                          "'%s': %s\n", path, parent->key->name,
     1124                          dos_errstr(werr)));
     1125                werr = regdb_transaction_cancel();
     1126                if (!W_ERROR_IS_OK(werr)) {
     1127                        DEBUG(0, ("reg_deletekey_recursive_trans: "
     1128                                  "error cancelling transaction: %s\n",
     1129                                  dos_errstr(werr)));
     1130                }
     1131        } else {
     1132                werr = regdb_transaction_commit();
     1133                if (!W_ERROR_IS_OK(werr)) {
     1134                        DEBUG(0, ("reg_deletekey_recursive_trans: "
     1135                                  "error committing transaction: %s\n",
     1136                                  dos_errstr(werr)));
     1137                }
     1138        }
     1139
     1140        return werr;
     1141}
     1142
    11361143WERROR reg_deletekey_recursive(TALLOC_CTX *ctx,
    11371144                               struct registry_key *parent,
    11381145                               const char *path)
    11391146{
    1140         return reg_deletekey_recursive_internal(ctx, parent, path, true);
     1147        return reg_deletekey_recursive_trans(ctx, parent, path, true);
    11411148}
    11421149
     
    11451152                                   const char *path)
    11461153{
    1147         return reg_deletekey_recursive_internal(ctx, parent, path, false);
     1154        return reg_deletekey_recursive_trans(ctx, parent, path, false);
    11481155}
    11491156
Note: See TracChangeset for help on using the changeset viewer.