Fix init_registry_data for subkeyless top-level keys.
authorGünther Deschner <gd@samba.org>
Fri, 29 Feb 2008 23:32:36 +0000 (00:32 +0100)
committerGünther Deschner <gd@samba.org>
Sat, 1 Mar 2008 00:02:15 +0000 (01:02 +0100)
On a fresh install with no existing registry.tdb, make sure we are able to
create our initial top-level entries.

Michael, Volker, please check.

Guenther

source/registry/reg_backend_db.c

index 52e0fd42892a9968fd73d1161f3a3bb6df658d1c..518078a0624e04add9ba99a5a4378af95a36808e 100644 (file)
@@ -454,7 +454,8 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
 
        regdb_fetch_keys(key, old_subkeys);
 
-       if (ctr->num_subkeys == old_subkeys->num_subkeys) {
+       if ((ctr->num_subkeys && old_subkeys->num_subkeys) &&
+           (ctr->num_subkeys == old_subkeys->num_subkeys)) {
 
                for (i = 0; i<ctr->num_subkeys; i++) {
                        if (strcmp(ctr->subkeys[i],
@@ -550,6 +551,22 @@ bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
        /* now create records for any subkeys that don't already exist */
 
        num_subkeys = regsubkey_ctr_numkeys(ctr);
+
+       if (num_subkeys == 0) {
+               if (!(subkeys = TALLOC_ZERO_P(ctr, REGSUBKEY_CTR)) ) {
+                       DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
+                       goto fail;
+               }
+
+               if (!regdb_store_keys_internal(key, subkeys)) {
+                       DEBUG(0,("regdb_store_keys: Failed to store "
+                                "new record for key [%s]\n", key));
+                       goto fail;
+               }
+               TALLOC_FREE(subkeys);
+
+       }
+
        for (i=0; i<num_subkeys; i++) {
                path = talloc_asprintf(ctx, "%s/%s",
                                        key,