Changeset 751 for trunk/server/source3/registry/reg_api.c
- Timestamp:
- Nov 29, 2012, 1:59:04 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/server/source3/registry/reg_api.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/registry/reg_api.c
r745 r751 90 90 } 91 91 92 92 93 werr = regval_ctr_init(key, &(key->values)); 93 94 W_ERROR_NOT_OK_RETURN(werr); … … 116 117 if (fetch_reg_keys(key->key, key->subkeys) == -1) { 117 118 TALLOC_FREE(key->subkeys); 118 return WERR_ NO_MORE_ITEMS;119 return WERR_; 119 120 } 120 121 … … 137 138 struct registry_key *regkey; 138 139 struct registry_key_handle *key; 139 struct regsubkey_ctr *subkeys = NULL;140 140 141 141 DEBUG(7,("regkey_open_onelevel: name = [%s]\n", name)); … … 151 151 } 152 152 153 if ( !(W_ERROR_IS_OK(result = regdb_open())) ) { 153 result = regdb_open(); 154 if (!(W_ERROR_IS_OK(result))) { 154 155 goto done; 155 156 } … … 194 195 /* Look up the table of registry I/O operations */ 195 196 196 if ( !(key->ops = reghook_cache_find( key->name )) ) { 197 key->ops = reghook_cache_find( key->name ); 198 if (key->ops == NULL) { 197 199 DEBUG(0,("reg_open_onelevel: Failed to assign " 198 200 "registry_ops to [%s]\n", key->name )); … … 201 203 } 202 204 203 /* check if the path really exists; failed is indicated by -1 */ 204 /* if the subkey count failed, bail out */ 205 206 result = regsubkey_ctr_init(key, &subkeys); 205 /* FIXME: Existence is currently checked by fetching the subkeys */ 206 207 result = fill_subkey_cache(regkey); 207 208 if (!W_ERROR_IS_OK(result)) { 208 209 goto done; 209 210 } 210 211 if ( fetch_reg_keys( key, subkeys ) == -1 ) {212 result = WERR_BADFILE;213 goto done;214 }215 216 TALLOC_FREE( subkeys );217 211 218 212 if ( !regkey_access_check( key, access_desired, &key->access_granted, … … 257 251 struct registry_key *direct_parent = parent; 258 252 WERROR err; 259 char *p, *path , *to_free;253 char *p, *path; 260 254 size_t len; 261 262 if (!(path = SMB_STRDUP(name))) { 263 return WERR_NOMEM; 264 } 265 to_free = path; 255 TALLOC_CTX *frame = talloc_stackframe(); 256 257 path = talloc_strdup(frame, name); 258 if (path == NULL) { 259 err = WERR_NOMEM; 260 goto error; 261 } 266 262 267 263 len = strlen(path); … … 275 271 struct registry_key *tmp; 276 272 277 if (!(name_component = SMB_STRNDUP(path, (p - path)))) { 273 name_component = talloc_strndup(frame, path, (p - path)); 274 if (name_component == NULL) { 278 275 err = WERR_NOMEM; 279 276 goto error; 280 277 } 281 278 282 err = regkey_open_onelevel( mem_ctx, direct_parent,279 err = regkey_open_onelevel(, direct_parent, 283 280 name_component, parent->token, 284 281 KEY_ENUMERATE_SUB_KEYS, &tmp); 285 SAFE_FREE(name_component);286 282 287 283 if (!W_ERROR_IS_OK(err)) { 288 284 goto error; 289 285 } 290 if (direct_parent != parent) {291 TALLOC_FREE(direct_parent);292 }293 286 294 287 direct_parent = tmp; … … 298 291 err = regkey_open_onelevel(mem_ctx, direct_parent, path, parent->token, 299 292 desired_access, pkey); 300 error: 301 if (direct_parent != parent) { 302 TALLOC_FREE(direct_parent); 303 } 304 SAFE_FREE(to_free); 293 294 error: 295 talloc_free(frame); 305 296 return err; 306 297 } … … 376 367 } 377 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 378 406 WERROR reg_queryvalue(TALLOC_CTX *mem_ctx, struct registry_key *key, 379 407 const char *name, struct registry_value **pval) … … 394 422 blob = regval_ctr_specific_value(key->values, i); 395 423 if (strequal(regval_name(blob), name)) { 396 return reg_enumvalue(mem_ctx, key, i, NULL, pval); 424 /* 425 * don't use reg_enumvalue here: 426 * re-reading the values from the disk 427 * would change the indexing and break 428 * this function. 429 */ 430 return reg_enumvalue_nocachefill(mem_ctx, key, i, 431 NULL, pval); 397 432 } 398 433 } … … 523 558 char *path, *end; 524 559 WERROR err; 525 526 if (!(mem_ctx = talloc_new(ctx))) return WERR_NOMEM; 527 528 if (!(path = talloc_strdup(mem_ctx, subkeypath))) { 560 uint32_t access_granted; 561 562 mem_ctx = talloc_new(ctx); 563 if (mem_ctx == NULL) { 564 return WERR_NOMEM; 565 } 566 567 path = talloc_strdup(mem_ctx, subkeypath); 568 if (path == NULL) { 529 569 err = WERR_NOMEM; 570 571 572 573 574 575 576 530 577 goto done; 531 578 } … … 540 587 KEY_ENUMERATE_SUB_KEYS, &tmp, &action); 541 588 if (!W_ERROR_IS_OK(err)) { 542 goto done;589 goto done; 543 590 } 544 591 … … 561 608 *paction = REG_OPENED_EXISTING_KEY; 562 609 } 563 goto done;610 goto done; 564 611 } 565 612 … … 568 615 * Something but "notfound" has happened, so bail out 569 616 */ 570 goto done;617 goto done; 571 618 } 572 619 573 620 /* 574 * We have to make a copy of the current key, as we opened it only 575 * with ENUM_SUBKEY access. 621 * We may (e.g. in the iteration) have opened the key with ENUM_SUBKEY. 622 * Instead of re-opening the key with CREATE_SUB_KEY, we simply 623 * duplicate the access check here and skip the expensive full open. 576 624 */ 577 578 err = reg_openkey(mem_ctx, key, "", KEY_CREATE_SUB_KEY,579 &create_parent);580 if (!W_ERROR_IS_OK(err)) {625 if (!regkey_access_check(key->key, KEY_CREATE_SUB_KEY, &access_granted, 626 627 628 581 629 goto done; 582 630 } … … 586 634 */ 587 635 588 err = fill_subkey_cache(create_parent);589 if (!W_ERROR_IS_OK(err)) goto done;590 591 636 err = create_reg_subkey(key->key, path); 592 W_ERROR_NOT_OK_GOTO_DONE(err); 637 if (!W_ERROR_IS_OK(err)) { 638 goto trans_done; 639 } 593 640 594 641 /* … … 596 643 */ 597 644 598 err = reg_openkey(ctx, create_parent, path, desired_access, pkey);645 err = reg_openkey(ctx, , path, desired_access, pkey); 599 646 if (W_ERROR_IS_OK(err) && (paction != NULL)) { 600 647 *paction = REG_CREATED_NEW_KEY; 648 649 650 651 652 653 654 655 656 657 658 659 660 601 661 } 602 662 … … 623 683 W_ERROR_NOT_OK_GOTO_DONE(err); 624 684 685 686 687 688 689 690 691 625 692 err = fill_subkey_cache(key); 626 W_ERROR_NOT_OK_GOTO _DONE(err);693 W_ERROR_NOT_OK_GOTO); 627 694 628 695 if (regsubkey_ctr_numkeys(key->subkeys) > 0) { 629 696 err = WERR_ACCESS_DENIED; 630 goto done;697 goto done; 631 698 } 632 699 … … 638 705 err = reg_openkey(mem_ctx, parent, name, 639 706 KEY_CREATE_SUB_KEY, &tmp_key); 640 W_ERROR_NOT_OK_GOTO _DONE(err);707 W_ERROR_NOT_OK_GOTO); 641 708 642 709 parent = tmp_key; … … 646 713 if (name[0] == '\0') { 647 714 err = WERR_INVALID_PARAM; 648 goto done;715 goto done; 649 716 } 650 717 651 718 err = delete_reg_subkey(parent->key, name); 719 720 721 722 723 724 725 726 727 728 729 730 731 652 732 653 733 done: … … 667 747 } 668 748 669 if (!W_ERROR_IS_OK(err = fill_value_cache(key))) { 749 err = regdb_transaction_start(); 750 if (!W_ERROR_IS_OK(err)) { 751 DEBUG(0, ("reg_setvalue: Failed to start transaction: %s\n", 752 win_errstr(err))); 670 753 return err; 754 755 756 757 758 759 671 760 } 672 761 … … 676 765 (regval_size(existing) == val->data.length) && 677 766 (memcmp(regval_data_p(existing), val->data.data, 678 val->data.length) == 0)) { 679 return WERR_OK; 767 val->data.length) == 0)) 768 { 769 err = WERR_OK; 770 goto done; 680 771 } 681 772 … … 685 776 if (res == 0) { 686 777 TALLOC_FREE(key->values); 687 return WERR_NOMEM; 778 err = WERR_NOMEM; 779 goto done; 688 780 } 689 781 690 782 if (!store_reg_values(key->key, key->values)) { 691 783 TALLOC_FREE(key->values); 692 return WERR_REG_IO_FAILURE; 693 } 694 695 return WERR_OK; 784 DEBUG(0, ("reg_setvalue: store_reg_values failed\n")); 785 err = WERR_REG_IO_FAILURE; 786 goto done; 787 } 788 789 err = WERR_OK; 790 791 done: 792 if (W_ERROR_IS_OK(err)) { 793 err = regdb_transaction_commit(); 794 if (!W_ERROR_IS_OK(err)) { 795 DEBUG(0, ("reg_setvalue: Error committing transaction: %s\n", win_errstr(err))); 796 } 797 } else { 798 WERROR err1 = regdb_transaction_cancel(); 799 if (!W_ERROR_IS_OK(err1)) { 800 DEBUG(0, ("reg_setvalue: Error cancelling transaction: %s\n", win_errstr(err1))); 801 } 802 } 803 804 return err; 696 805 } 697 806 … … 717 826 } 718 827 719 if (!W_ERROR_IS_OK(err = fill_value_cache(key))) { 828 err = regdb_transaction_start(); 829 if (!W_ERROR_IS_OK(err)) { 830 DEBUG(0, ("reg_deletevalue: Failed to start transaction: %s\n", 831 win_errstr(err))); 720 832 return err; 833 834 835 836 837 838 839 721 840 } 722 841 723 842 err = reg_value_exists(key, name); 724 843 if (!W_ERROR_IS_OK(err)) { 725 return err;844 ; 726 845 } 727 846 … … 730 849 if (!store_reg_values(key->key, key->values)) { 731 850 TALLOC_FREE(key->values); 732 return WERR_REG_IO_FAILURE; 733 } 734 735 return WERR_OK; 851 err = WERR_REG_IO_FAILURE; 852 DEBUG(0, ("reg_deletevalue: store_reg_values failed\n")); 853 goto done; 854 } 855 856 err = WERR_OK; 857 858 done: 859 if (W_ERROR_IS_OK(err)) { 860 err = regdb_transaction_commit(); 861 if (!W_ERROR_IS_OK(err)) { 862 DEBUG(0, ("reg_deletevalue: Error committing transaction: %s\n", win_errstr(err))); 863 } 864 } else { 865 WERROR err1 = regdb_transaction_cancel(); 866 if (!W_ERROR_IS_OK(err1)) { 867 DEBUG(0, ("reg_deletevalue: Error cancelling transaction: %s\n", win_errstr(err1))); 868 } 869 } 870 871 return err; 736 872 } 737 873
Note:
See TracChangeset
for help on using the changeset viewer.
