Changeset 223 for branches/samba-3.3.x/source/registry/reg_api.c
- Timestamp:
- May 24, 2009, 7:51:24 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.3.x/source/registry/reg_api.c
r206 r223 95 95 static WERROR fill_subkey_cache(struct registry_key *key) 96 96 { 97 WERROR werr; 98 97 99 if (key->subkeys != NULL) { 98 100 if (!reg_subkeys_need_update(key->key, key->subkeys)) { … … 101 103 } 102 104 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); 106 107 107 108 if (fetch_reg_keys(key->key, key->subkeys) == -1) { … … 128 129 struct registry_key *regkey; 129 130 REGISTRY_KEY *key; 130 REGSUBKEY_CTR*subkeys = NULL;131 struct regsubkey_ctr *subkeys = NULL; 131 132 132 133 DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name)); … … 194 195 /* if the subkey count failed, bail out */ 195 196 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)) { 198 199 goto done; 199 200 } … … 309 310 } 310 311 311 if (idx >= key->subkeys->num_subkeys) {312 if (idx >= regsubkey_ctr_numkeys(key->subkeys)) { 312 313 return WERR_NO_MORE_ITEMS; 313 314 } 314 315 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 { 316 319 return WERR_NOMEM; 317 320 } … … 407 410 408 411 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); 414 418 *max_subkeylen = max_len; 415 419 *max_subkeysize = 0; /* Class length? */ … … 521 525 if (!W_ERROR_IS_OK(err)) goto done; 522 526 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); 531 529 532 530 /* … … 547 545 { 548 546 WERROR err; 549 TALLOC_CTX *mem_ctx;550 547 char *name, *end; 551 int num_subkeys;552 548 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) { 557 553 err = WERR_NOMEM; 558 goto error;554 goto done; 559 555 } 560 556 561 557 /* check if the key has subkeys */ 562 558 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) { 570 565 err = WERR_ACCESS_DENIED; 571 goto error;566 goto done; 572 567 } 573 568 574 569 /* no subkeys - proceed with delete */ 575 if ((end = strrchr(name, '\\')) != NULL) { 570 end = strrchr(name, '\\'); 571 if (end != NULL) { 576 572 *end = '\0'; 577 573 578 574 err = reg_openkey(mem_ctx, parent, name, 579 575 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); 583 577 584 578 parent = tmp_key; … … 588 582 if (name[0] == '\0') { 589 583 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 589 done: 615 590 TALLOC_FREE(mem_ctx); 616 591 return err; … … 727 702 REGISTRY_KEY registry_key; 728 703 REGVAL_CTR *values; 729 REGSUBKEY_CTR*subkeys;704 struct regsubkey_ctr *subkeys; 730 705 int i; 731 706 char *path = NULL; … … 749 724 /* now start parsing the values and subkeys */ 750 725 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); 755 728 756 729 values = TALLOC_ZERO_P(subkeys, REGVAL_CTR); … … 768 741 } 769 742 770 /* copy subkeys into the REGSUBKEY_CTR*/743 /* copy subkeys into the struct regsubkey_ctr */ 771 744 772 745 key->subkey_index = 0; … … 862 835 REGF_NK_REC *key; 863 836 REGVAL_CTR *values; 864 REGSUBKEY_CTR*subkeys;837 struct regsubkey_ctr *subkeys; 865 838 int i, num_subkeys; 866 839 char *key_tmp = NULL; … … 910 883 /* lookup the values and subkeys */ 911 884 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); 916 887 917 888 values = TALLOC_ZERO_P(subkeys, REGVAL_CTR); … … 1092 1063 struct registry_key *key; 1093 1064 char *subkey_name = NULL; 1065 uint32 i; 1094 1066 1095 1067 mem_ctx = talloc_new(ctx); … … 1105 1077 } 1106 1078 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); 1110 1088 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 } 1125 1093 1126 1094 if (del_key) { … … 1134 1102 } 1135 1103 1104 static 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 1136 1143 WERROR reg_deletekey_recursive(TALLOC_CTX *ctx, 1137 1144 struct registry_key *parent, 1138 1145 const char *path) 1139 1146 { 1140 return reg_deletekey_recursive_ internal(ctx, parent, path, true);1147 return reg_deletekey_recursive_trans(ctx, parent, path, true); 1141 1148 } 1142 1149 … … 1145 1152 const char *path) 1146 1153 { 1147 return reg_deletekey_recursive_ internal(ctx, parent, path, false);1154 return reg_deletekey_recursive_trans(ctx, parent, path, false); 1148 1155 } 1149 1156
Note:
See TracChangeset
for help on using the changeset viewer.