The branch, v3-2-test has been updated
       via  4bb5df5831f54686fe719f0cddef1af048009e9b (commit)
      from  36ae846d15027df5e3a02ffabb08183dad9f6517 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 4bb5df5831f54686fe719f0cddef1af048009e9b
Author: Volker Lendecke <[email protected]>
Date:   Thu Feb 19 20:03:06 2009 +0100

    Fix a O(n^2) algorithm in regdb_fetch_keys()

-----------------------------------------------------------------------

Summary of changes:
 source/registry/reg_backend_db.c |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/registry/reg_backend_db.c b/source/registry/reg_backend_db.c
index 12ccc16..fb8b64a 100644
--- a/source/registry/reg_backend_db.c
+++ b/source/registry/reg_backend_db.c
@@ -727,7 +727,6 @@ fail:
 
 int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
 {
-       WERROR werr;
        char *path = NULL;
        uint32 num_items;
        uint8 *buf;
@@ -770,12 +769,35 @@ int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
 
        len = tdb_unpack( buf, buflen, "d", &num_items);
 
+       /*
+        * The following code breaks the abstraction that reg_objects.c sets
+        * up with regsubkey_ctr_addkey(). But if we use that with the current
+        * data structure of ctr->subkeys being an unsorted array, we end up
+        * with an O(n^2) algorithm for retrieving keys from the tdb
+        * file. This is pretty pointless, as we have to trust the data
+        * structure on disk not to have duplicates anyway. The alternative to
+        * breaking this abstraction would be to set up a more sophisticated
+        * data structure in REGSUBKEY_CTR.
+        *
+        * This makes "net conf list" for a registry with >1000 shares
+        * actually usable :-)
+        */
+
+       ctr->subkeys = talloc_array(ctr, char *, num_items);
+       if (ctr->subkeys == NULL) {
+               DEBUG(5, ("regdb_fetch_keys: could not allocate subkeys\n"));
+               goto fail;
+       }
+       ctr->num_subkeys = num_items;
+
        for (i=0; i<num_items; i++) {
                len += tdb_unpack(buf+len, buflen-len, "f", subkeyname);
-               werr = regsubkey_ctr_addkey(ctr, subkeyname);
-               if (!W_ERROR_IS_OK(werr)) {
-                       DEBUG(5, ("regdb_fetch_keys: regsubkey_ctr_addkey "
-                                 "failed: %s\n", dos_errstr(werr)));
+               ctr->subkeys[i] = talloc_strdup(ctr->subkeys, subkeyname);
+               if (ctr->subkeys[i] == NULL) {
+                       DEBUG(5, ("regdb_fetch_keys: could not allocate "
+                                 "subkeyname\n"));
+                       TALLOC_FREE(ctr->subkeys);
+                       ctr->num_subkeys = 0;
                        goto fail;
                }
        }


-- 
Samba Shared Repository

Reply via email to