Changeset 746 for vendor/current/source3/registry
- Timestamp:
- Nov 27, 2012, 4:56:06 PM (13 years ago)
- Location:
- vendor/current/source3/registry
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/registry/reg_api.c
r740 r746 90 90 } 91 91 92 TALLOC_FREE(key->values); 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_BADFILE; 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(frame, 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 static WERROR reg_enumvalue_nocachefill(TALLOC_CTX *mem_ctx, 370 struct registry_key *key, 371 uint32 idx, char **pname, 372 struct registry_value **pval) 373 { 374 struct registry_value *val; 375 struct regval_blob *blob; 376 377 if (!(key->key->access_granted & KEY_QUERY_VALUE)) { 378 return WERR_ACCESS_DENIED; 379 } 380 381 if (idx >= regval_ctr_numvals(key->values)) { 382 return WERR_NO_MORE_ITEMS; 383 } 384 385 blob = regval_ctr_specific_value(key->values, idx); 386 387 val = talloc_zero(mem_ctx, struct registry_value); 388 if (val == NULL) { 389 return WERR_NOMEM; 390 } 391 392 val->type = regval_type(blob); 393 val->data = data_blob_talloc(mem_ctx, regval_data_p(blob), regval_size(blob)); 394 395 if (pname 396 && !(*pname = talloc_strdup( 397 mem_ctx, regval_name(blob)))) { 398 TALLOC_FREE(val); 399 return WERR_NOMEM; 400 } 401 402 *pval = val; 403 return WERR_OK; 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 goto done; 571 } 572 573 err = regdb_transaction_start(); 574 if (!W_ERROR_IS_OK(err)) { 575 DEBUG(0, ("reg_createkey: failed to start transaction: %s\n", 576 win_errstr(err))); 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 trans_done; 543 590 } 544 591 … … 561 608 *paction = REG_OPENED_EXISTING_KEY; 562 609 } 563 goto done;610 goto trans_done; 564 611 } 565 612 … … 568 615 * Something but "notfound" has happened, so bail out 569 616 */ 570 goto done;617 goto trans_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 key->token)) 627 { 628 err = WERR_ACCESS_DENIED; 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, key, path, desired_access, pkey); 599 646 if (W_ERROR_IS_OK(err) && (paction != NULL)) { 600 647 *paction = REG_CREATED_NEW_KEY; 648 } 649 650 trans_done: 651 if (W_ERROR_IS_OK(err)) { 652 err = regdb_transaction_commit(); 653 if (!W_ERROR_IS_OK(err)) { 654 DEBUG(0, ("reg_createkey: Error committing transaction: %s\n", win_errstr(err))); 655 } 656 } else { 657 WERROR err1 = regdb_transaction_cancel(); 658 if (!W_ERROR_IS_OK(err1)) { 659 DEBUG(0, ("reg_createkey: Error cancelling transaction: %s\n", win_errstr(err1))); 660 } 601 661 } 602 662 … … 623 683 W_ERROR_NOT_OK_GOTO_DONE(err); 624 684 685 err = regdb_transaction_start(); 686 if (!W_ERROR_IS_OK(err)) { 687 DEBUG(0, ("reg_deletekey: Error starting transaction: %s\n", 688 win_errstr(err))); 689 goto done; 690 } 691 625 692 err = fill_subkey_cache(key); 626 W_ERROR_NOT_OK_GOTO _DONE(err);693 W_ERROR_NOT_OK_GOTO(err, trans_done); 627 694 628 695 if (regsubkey_ctr_numkeys(key->subkeys) > 0) { 629 696 err = WERR_ACCESS_DENIED; 630 goto done;697 goto trans_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(err, trans_done); 641 708 642 709 parent = tmp_key; … … 646 713 if (name[0] == '\0') { 647 714 err = WERR_INVALID_PARAM; 648 goto done;715 goto trans_done; 649 716 } 650 717 651 718 err = delete_reg_subkey(parent->key, name); 719 720 trans_done: 721 if (W_ERROR_IS_OK(err)) { 722 err = regdb_transaction_commit(); 723 if (!W_ERROR_IS_OK(err)) { 724 DEBUG(0, ("reg_deletekey: Error committing transaction: %s\n", win_errstr(err))); 725 } 726 } else { 727 WERROR err1 = regdb_transaction_cancel(); 728 if (!W_ERROR_IS_OK(err1)) { 729 DEBUG(0, ("reg_deletekey: Error cancelling transaction: %s\n", win_errstr(err1))); 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 err = fill_value_cache(key); 757 if (!W_ERROR_IS_OK(err)) { 758 DEBUG(0, ("reg_setvalue: Error filling value cache: %s\n", win_errstr(err))); 759 goto done; 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 err = fill_value_cache(key); 836 if (!W_ERROR_IS_OK(err)) { 837 DEBUG(0, ("reg_deletevalue; Error filling value cache: %s\n", 838 win_errstr(err))); 839 goto done; 721 840 } 722 841 723 842 err = reg_value_exists(key, name); 724 843 if (!W_ERROR_IS_OK(err)) { 725 return err;844 goto done; 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 -
vendor/current/source3/registry/reg_backend_db.c
r740 r746 321 321 /* preserve existing values across restarts. Only add new ones */ 322 322 323 if (!regval_ctr_ key_exists(values,323 if (!regval_ctr_value_exists(values, 324 324 builtin_registry_values[i].valuename)) 325 325 { … … 365 365 builtin_registry_values[i].path, 366 366 values); 367 if (!regval_ctr_ key_exists(values,367 if (!regval_ctr_value_exists(values, 368 368 builtin_registry_values[i].valuename)) 369 369 { … … 985 985 } 986 986 987 werr = WERR_OK; 987 /* 988 * Update the seqnum in the container to possibly 989 * prevent next read from going to disk 990 */ 991 werr = regsubkey_ctr_set_seqnum(store_ctx->ctr, db->get_seqnum(db)); 988 992 989 993 done: … … 1612 1616 TALLOC_CTX *frame = talloc_stackframe(); 1613 1617 TDB_DATA value; 1618 int seqnum[2], count; 1614 1619 1615 1620 DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL")); … … 1621 1626 } 1622 1627 1623 werr = regsubkey_ctr_ set_seqnum(ctr, db->get_seqnum(db));1628 werr = regsubkey_ctr_reinit(ctr); 1624 1629 W_ERROR_NOT_OK_GOTO_DONE(werr); 1625 1630 1626 value = regdb_fetch_key_internal(db, frame, key); 1631 count = 0; 1632 ZERO_STRUCT(value); 1633 seqnum[0] = db->get_seqnum(db); 1634 1635 do { 1636 count++; 1637 TALLOC_FREE(value.dptr); 1638 value = regdb_fetch_key_internal(db, frame, key); 1639 seqnum[count % 2] = db->get_seqnum(db); 1640 1641 } while (seqnum[0] != seqnum[1]); 1642 1643 if (count > 1) { 1644 DEBUG(5, ("regdb_fetch_keys_internal: it took %d attempts to " 1645 "fetch key '%s' with constant seqnum\n", 1646 count, key)); 1647 } 1648 1649 werr = regsubkey_ctr_set_seqnum(ctr, seqnum[0]); 1650 if (!W_ERROR_IS_OK(werr)) { 1651 goto done; 1652 } 1627 1653 1628 1654 if (value.dsize == 0 || value.dptr == NULL) { … … 1639 1665 goto done; 1640 1666 } 1641 1642 werr = regsubkey_ctr_reinit(ctr);1643 W_ERROR_NOT_OK_GOTO_DONE(werr);1644 1667 1645 1668 for (i=0; i<num_items; i++) { … … 1708 1731 SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */ 1709 1732 1710 DEBUG(8,("specific: [%s], len: %d\n", valuename, size)); 1733 DEBUG(10, ("regdb_unpack_values: value[%d]: name[%s] len[%d]\n", 1734 i, valuename, size)); 1711 1735 } 1712 1736 … … 1761 1785 TDB_DATA value; 1762 1786 WERROR werr; 1763 1764 DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key)); 1787 int seqnum[2], count; 1788 1789 DEBUG(10,("regdb_fetch_values: Looking for values of key [%s]\n", key)); 1765 1790 1766 1791 if (!regdb_key_exists(db, key)) { 1792 DEBUG(10, ("regb_fetch_values: key [%s] does not exist\n", 1793 key)); 1794 ret = -1; 1767 1795 goto done; 1768 1796 } … … 1773 1801 } 1774 1802 1775 werr = regval_ctr_set_seqnum(values, db->get_seqnum(db)); 1776 W_ERROR_NOT_OK_GOTO_DONE(werr); 1777 1778 value = regdb_fetch_key_internal(db, ctx, keystr); 1803 ZERO_STRUCT(value); 1804 count = 0; 1805 seqnum[0] = db->get_seqnum(db); 1806 1807 do { 1808 count++; 1809 TALLOC_FREE(value.dptr); 1810 value = regdb_fetch_key_internal(db, ctx, keystr); 1811 seqnum[count % 2] = db->get_seqnum(db); 1812 } while (seqnum[0] != seqnum[1]); 1813 1814 if (count > 1) { 1815 DEBUG(5, ("regdb_fetch_values_internal: it took %d attempts " 1816 "to fetch key '%s' with constant seqnum\n", 1817 count, key)); 1818 } 1819 1820 werr = regval_ctr_set_seqnum(values, seqnum[0]); 1821 if (!W_ERROR_IS_OK(werr)) { 1822 goto done; 1823 } 1779 1824 1780 1825 if (!value.dptr) { … … 1805 1850 NTSTATUS status; 1806 1851 bool result = false; 1807 1808 DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key)); 1852 WERROR werr; 1853 1854 DEBUG(10,("regdb_store_values: Looking for values of key [%s]\n", key)); 1809 1855 1810 1856 if (!regdb_key_exists(db, key)) { … … 1847 1893 1848 1894 status = dbwrap_trans_store_bystring(db, keystr, data, TDB_REPLACE); 1849 1850 result = NT_STATUS_IS_OK(status); 1895 if (!NT_STATUS_IS_OK(status)) { 1896 DEBUG(0, ("regdb_store_values_internal: error storing: %s\n", nt_errstr(status))); 1897 goto done; 1898 } 1899 1900 /* 1901 * update the seqnum in the cache to prevent the next read 1902 * from going to disk 1903 */ 1904 werr = regval_ctr_set_seqnum(values, db->get_seqnum(db)); 1905 result = W_ERROR_IS_OK(status); 1851 1906 1852 1907 done: -
vendor/current/source3/registry/reg_backend_smbconf.c
r740 r746 82 82 } 83 83 84 static bool smbconf_subkeys_need_update(struct regsubkey_ctr *subkeys) 85 { 86 return regdb_ops.subkeys_need_update(subkeys); 87 } 88 89 static bool smbconf_values_need_update(struct regval_ctr *values) 90 { 91 return regdb_ops.values_need_update(values); 92 } 84 93 85 94 /* … … 97 106 .get_secdesc = smbconf_get_secdesc, 98 107 .set_secdesc = smbconf_set_secdesc, 108 .subkeys_need_update = smbconf_subkeys_need_update, 109 .values_need_update = smbconf_values_need_update, 99 110 }; -
vendor/current/source3/registry/reg_format.c
r740 r746 25 25 */ 26 26 27 #include "includes.h" 27 28 #include "reg_format.h" 28 29 #include "reg_parse.h" … … 326 327 } 327 328 329 static bool is_zero_terminated_ucs2(const uint8_t* data, size_t len) { 330 const size_t idx = len/sizeof(smb_ucs2_t); 331 const smb_ucs2_t *str = (const smb_ucs2_t*)data; 332 333 if ((len % sizeof(smb_ucs2_t)) != 0) { 334 return false; 335 } 336 337 if (idx == 0) { 338 return false; 339 } 340 341 return (str[idx-1] == 0); 342 } 343 328 344 int reg_format_value(struct reg_format* f, const char* name, uint32_t type, 329 345 const uint8_t* data, size_t len) … … 334 350 switch (type) { 335 351 case REG_SZ: 336 if (!(f->flags & REG_FMT_HEX_SZ)) { 352 if (!(f->flags & REG_FMT_HEX_SZ) 353 && is_zero_terminated_ucs2(data, len)) 354 { 337 355 char* str = NULL; 338 356 size_t dlen; -
vendor/current/source3/registry/reg_objects.c
r740 r746 447 447 **********************************************************************/ 448 448 449 bool regval_ctr_ key_exists(struct regval_ctr *ctr, const char *value)449 bool regval_ctr_value_exists(struct regval_ctr *ctr, const char *value) 450 450 { 451 451 int i; … … 458 458 return False; 459 459 } 460 461 /** 462 * Get a value by its name 463 */ 464 struct regval_blob *regval_ctr_value_byname(struct regval_ctr *ctr, 465 const char *value) 466 { 467 int i; 468 469 for (i=0; i<ctr->num_values; i++) { 470 if (strequal(ctr->values[i]->valuename,value)) { 471 return ctr->values[i]; 472 } 473 } 474 475 return NULL; 476 } 477 460 478 461 479 /*********************************************************************** -
vendor/current/source3/registry/reg_objects.h
r740 r746 56 56 struct regval_blob* regval_ctr_specific_value(struct regval_ctr *ctr, 57 57 uint32_t idx); 58 bool regval_ctr_key_exists(struct regval_ctr *ctr, const char *value); 58 struct regval_blob *regval_ctr_value_byname(struct regval_ctr *ctr, 59 const char *value); 60 bool regval_ctr_value_exists(struct regval_ctr *ctr, const char *value); 59 61 struct regval_blob *regval_compose(TALLOC_CTX *ctx, const char *name, 60 62 uint32_t type, -
vendor/current/source3/registry/reg_parse.c
r740 r746 794 794 (long unsigned)(linenum+1), pos)); 795 795 796 assert( ilen> 0);796 assert((*ilen) > 0); 797 797 do { 798 798 size_t il = 1; 799 799 DEBUGADD(0, ("<%02x>", (unsigned char)**iptr)); 800 800 801 if ( olen> 0) {801 if ((*olen) > 0) { 802 802 *(*optr)++ = '\?'; 803 803 (*iptr)++; -
vendor/current/source3/registry/regfio.c
r740 r746 1468 1468 return NULL; 1469 1469 1470 memcpy( hbin->header, "hbin", sizeof(HBIN_HDR_SIZE));1470 memcpy( hbin->header, "hbin", HBIN_HDR_SIZE); 1471 1471 1472 1472
Note:
See TracChangeset
for help on using the changeset viewer.