Changeset 233 for branches/samba-3.2.x/source/registry
- Timestamp:
- May 27, 2009, 11:39:15 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.2.x/source/registry/reg_backend_db.c
r133 r233 488 488 489 489 for (i=0; i<num_subkeys; i++) { 490 len += tdb_pack(buffer+len, buflen-len, "f", 491 regsubkey_ctr_specific_key(ctr, i)); 492 if (len > buflen) { 493 /* allocate some extra space */ 494 buffer = (uint8 *)SMB_REALLOC(buffer, len*2); 490 size_t thistime; 491 492 thistime = tdb_pack(buffer+len, buflen-len, "f", 493 regsubkey_ctr_specific_key(ctr, i)); 494 if (len+thistime > buflen) { 495 size_t thistime2; 496 /* 497 * tdb_pack hasn't done anything because of the short 498 * buffer, allocate extra space. 499 */ 500 buffer = SMB_REALLOC_ARRAY(buffer, uint8_t, 501 (len+thistime)*2); 495 502 if(buffer == NULL) { 496 503 DEBUG(0, ("regdb_store_keys: Failed to realloc " 497 "memory of size [%d]\n", len*2)); 504 "memory of size [%d]\n", 505 (len+thistime)*2)); 498 506 ret = false; 499 507 goto done; 500 508 } 501 buflen = len*2; 502 len = tdb_pack(buffer+len, buflen-len, "f", 503 regsubkey_ctr_specific_key(ctr, i)); 504 } 509 buflen = (len+thistime)*2; 510 thistime2 = tdb_pack( 511 buffer+len, buflen-len, "f", 512 regsubkey_ctr_specific_key(ctr, i)); 513 if (thistime2 != thistime) { 514 DEBUG(0, ("tdb_pack failed\n")); 515 ret = false; 516 goto done; 517 } 518 } 519 len += thistime; 505 520 } 506 521 … … 713 728 int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr) 714 729 { 715 WERROR werr;716 730 char *path = NULL; 717 731 uint32 num_items; … … 756 770 len = tdb_unpack( buf, buflen, "d", &num_items); 757 771 772 /* 773 * The following code breaks the abstraction that reg_objects.c sets 774 * up with regsubkey_ctr_addkey(). But if we use that with the current 775 * data structure of ctr->subkeys being an unsorted array, we end up 776 * with an O(n^2) algorithm for retrieving keys from the tdb 777 * file. This is pretty pointless, as we have to trust the data 778 * structure on disk not to have duplicates anyway. The alternative to 779 * breaking this abstraction would be to set up a more sophisticated 780 * data structure in REGSUBKEY_CTR. 781 * 782 * This makes "net conf list" for a registry with >1000 shares 783 * actually usable :-) 784 */ 785 786 ctr->subkeys = talloc_array(ctr, char *, num_items); 787 if (ctr->subkeys == NULL) { 788 DEBUG(5, ("regdb_fetch_keys: could not allocate subkeys\n")); 789 goto fail; 790 } 791 ctr->num_subkeys = num_items; 792 758 793 for (i=0; i<num_items; i++) { 759 794 len += tdb_unpack(buf+len, buflen-len, "f", subkeyname); 760 werr = regsubkey_ctr_addkey(ctr, subkeyname); 761 if (!W_ERROR_IS_OK(werr)) { 762 DEBUG(5, ("regdb_fetch_keys: regsubkey_ctr_addkey " 763 "failed: %s\n", dos_errstr(werr))); 795 ctr->subkeys[i] = talloc_strdup(ctr->subkeys, subkeyname); 796 if (ctr->subkeys[i] == NULL) { 797 DEBUG(5, ("regdb_fetch_keys: could not allocate " 798 "subkeyname\n")); 799 TALLOC_FREE(ctr->subkeys); 800 ctr->num_subkeys = 0; 764 801 goto fail; 765 802 }
Note:
See TracChangeset
for help on using the changeset viewer.