Ignore:
Timestamp:
May 27, 2009, 11:39:15 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/registry/reg_backend_db.c

    r133 r233  
    488488
    489489        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);
    495502                        if(buffer == NULL) {
    496503                                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));
    498506                                ret = false;
    499507                                goto done;
    500508                        }
    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;
    505520        }
    506521
     
    713728int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
    714729{
    715         WERROR werr;
    716730        char *path = NULL;
    717731        uint32 num_items;
     
    756770        len = tdb_unpack( buf, buflen, "d", &num_items);
    757771
     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
    758793        for (i=0; i<num_items; i++) {
    759794                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;
    764801                        goto fail;
    765802                }
Note: See TracChangeset for help on using the changeset viewer.