s3:registry: improve debug messages about regdb refcount changes
[metze/samba/wip.git] / source3 / registry / reg_backend_db.c
index d250228d3c83ce26517f8a9c8e901c9dfcc912cc..8445d528166d3c097027aba202b75db6fcff7e25 100644 (file)
@@ -27,6 +27,8 @@
 #include "reg_util_internal.h"
 #include "reg_backend_db.h"
 #include "reg_objects.h"
+#include "nt_printing.h"
+#include "dbwrap.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_REGISTRY
@@ -59,6 +61,9 @@ static const char *builtin_registry_paths[] = {
        KEY_PRINTING_2K,
        KEY_PRINTING_PORTS,
        KEY_PRINTING,
+       KEY_PRINTING "\\Forms",
+       KEY_PRINTING "\\Printers",
+       KEY_PRINTING "\\Environments\\Windows NT x86\\Print Processors\\winprint",
        KEY_SHARES,
        KEY_EVENTLOG,
        KEY_SMBCONF,
@@ -99,7 +104,7 @@ static struct builtin_regkey_value builtin_registry_values[] = {
        { KEY_PRINTING_2K,
                "DefaultSpoolDirectory", REG_SZ, { "C:\\Windows\\System32\\Spool\\Printers" } },
        { KEY_EVENTLOG,
-               "DisplayName", REG_SZ, { "Event Log" } }, 
+               "DisplayName", REG_SZ, { "Event Log" } },
        { KEY_EVENTLOG,
                "ErrorControl", REG_DWORD, { (char*)0x00000001 } },
        { NULL, NULL, 0, { NULL } }
@@ -412,10 +417,8 @@ static int regdb_normalize_keynames_fn(struct db_record *rec,
                          (const char *) rec->key.dptr,
                          keyname));
 
-               new_rec.value.dptr = rec->value.dptr;
-               new_rec.value.dsize = rec->value.dsize;
-               new_rec.key.dptr = (unsigned char *) keyname;
-               new_rec.key.dsize = strlen(keyname);
+               new_rec.value = rec->value;
+               new_rec.key = string_term_tdb_data(keyname);
                new_rec.private_data = rec->private_data;
 
                /* Delete the original record and store the normalized key */
@@ -464,6 +467,7 @@ static WERROR regdb_upgrade_v1_to_v2(void)
 {
        TALLOC_CTX *mem_ctx;
        int rc;
+       WERROR werr;
 
        mem_ctx = talloc_stackframe();
        if (mem_ctx == NULL) {
@@ -473,7 +477,13 @@ static WERROR regdb_upgrade_v1_to_v2(void)
        rc = regdb->traverse(regdb, regdb_normalize_keynames_fn, mem_ctx);
 
        talloc_destroy(mem_ctx);
-       return (rc == -1 ? WERR_REG_IO_FAILURE : WERR_OK);
+
+       if (rc == -1) {
+               return WERR_REG_IO_FAILURE;
+       }
+
+       werr = regdb_store_regdb_version(REGVER_V2);
+       return werr;
 }
 
 /***********************************************************************
@@ -487,8 +497,8 @@ WERROR regdb_init(void)
        WERROR werr;
 
        if (regdb) {
-               DEBUG(10, ("regdb_init: incrementing refcount (%d)\n",
-                         regdb_refcount));
+               DEBUG(10, ("regdb_init: incrementing refcount (%d->%d)\n",
+                          regdb_refcount, regdb_refcount+1));
                regdb_refcount++;
                return WERR_OK;
        }
@@ -504,33 +514,24 @@ WERROR regdb_init(void)
                                state_path("registry.tdb"), strerror(errno) ));
                        return werr;
                }
-               
+
                DEBUG(10,("regdb_init: Successfully created registry tdb\n"));
        }
 
        regdb_refcount = 1;
+       DEBUG(10, ("regdb_init: registry db openend. refcount reset (%d)\n",
+                  regdb_refcount));
 
        expected_version = REGVER_V2;
 
        vers_id = dbwrap_fetch_int32(regdb, vstring);
        if (vers_id == -1) {
-               NTSTATUS status;
-
                DEBUG(10, ("regdb_init: registry version uninitialized "
                           "(got %d), initializing to version %d\n",
                           vers_id, expected_version));
 
-               status = dbwrap_trans_store_int32(regdb, vstring, REGVER_V2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(1, ("regdb_init: error storing %s = %d: %s\n",
-                                 vstring, expected_version, nt_errstr(status)));
-                       return ntstatus_to_werror(status);
-               } else {
-                       DEBUG(10, ("regdb_init: stored %s = %d\n",
-                                 vstring, expected_version));
-               }
-
-               return WERR_OK;
+               werr = regdb_store_regdb_version(expected_version);
+               return werr;
        }
 
        if (vers_id > expected_version || vers_id == 0) {
@@ -541,8 +542,6 @@ WERROR regdb_init(void)
        }
 
        if (vers_id == REGVER_V1) {
-               NTSTATUS status;
-
                DEBUG(10, ("regdb_init: got registry db version %d, upgrading "
                           "to version %d\n", REGVER_V1, REGVER_V2));
 
@@ -556,16 +555,6 @@ WERROR regdb_init(void)
                        return werr;
                }
 
-               status = dbwrap_trans_store_int32(regdb, vstring, REGVER_V2);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(1, ("regdb_init: error storing %s = %d: %s\n",
-                                 vstring, REGVER_V2, nt_errstr(status)));
-                       regdb->transaction_cancel(regdb);
-                       return ntstatus_to_werror(status);
-               } else {
-                       DEBUG(10, ("regdb_init: stored %s = %d\n",
-                                 vstring, REGVER_V2));
-               }
                if (regdb->transaction_commit(regdb) != 0) {
                        return WERR_REG_IO_FAILURE;
                }
@@ -587,25 +576,27 @@ WERROR regdb_open( void )
        WERROR result = WERR_OK;
 
        if ( regdb ) {
-               DEBUG(10,("regdb_open: incrementing refcount (%d)\n", regdb_refcount));
+               DEBUG(10, ("regdb_open: incrementing refcount (%d->%d)\n",
+                          regdb_refcount, regdb_refcount+1));
                regdb_refcount++;
                return WERR_OK;
        }
-       
+
        become_root();
 
        regdb = db_open(NULL, state_path("registry.tdb"), 0,
                              REG_TDB_FLAGS, O_RDWR, 0600);
        if ( !regdb ) {
                result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
-               DEBUG(0,("regdb_open: Failed to open %s! (%s)\n", 
+               DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
                        state_path("registry.tdb"), strerror(errno) ));
        }
 
        unbecome_root();
 
        regdb_refcount = 1;
-       DEBUG(10,("regdb_open: refcount reset (%d)\n", regdb_refcount));
+       DEBUG(10, ("regdb_open: registry db opened. refcount reset (%d)\n",
+                  regdb_refcount));
 
        return result;
 }
@@ -621,7 +612,8 @@ int regdb_close( void )
 
        regdb_refcount--;
 
-       DEBUG(10,("regdb_close: decrementing refcount (%d)\n", regdb_refcount));
+       DEBUG(10, ("regdb_close: decrementing refcount (%d->%d)\n",
+                  regdb_refcount+1, regdb_refcount));
 
        if ( regdb_refcount > 0 )
                return 0;
@@ -1695,12 +1687,8 @@ static int regdb_unpack_values(struct regval_ctr *values, uint8 *buf, int buflen
                                  &size,
                                  &data_p);
 
-               /* add the new value. Paranoid protective code -- make sure data_p is valid */
-
-               if (size && data_p) {
-                       regval_ctr_addvalue(values, valuename, type,
-                                       (uint8_t *)data_p, size);
-               }
+               regval_ctr_addvalue(values, valuename, type,
+                               (uint8_t *)data_p, size);
                SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */
 
                DEBUG(8,("specific: [%s], len: %d\n", valuename, size));
@@ -1957,10 +1945,10 @@ bool regdb_values_need_update(struct regval_ctr *values)
        return (regdb_get_seqnum() != regval_ctr_get_seqnum(values));
 }
 
-/* 
+/*
  * Table of function pointers for default access
  */
+
 struct registry_ops regdb_ops = {
        .fetch_subkeys = regdb_fetch_keys,
        .fetch_values = regdb_fetch_values,