s3:registry: update the seqnum in the subkey cache at the end of regval_store_keys
[ddiss/samba.git] / source3 / registry / reg_backend_db.c
index b9d4ff64625c6ea9983ef2728afdf36d932baa6b..e0fe7c121151b23f70293f155de2c6ba788b4aa5 100644 (file)
@@ -28,6 +28,7 @@
 #include "reg_backend_db.h"
 #include "reg_objects.h"
 #include "nt_printing.h"
+#include "util_tdb.h"
 #include "dbwrap.h"
 
 #undef DBGC_CLASS
@@ -319,7 +320,7 @@ static NTSTATUS init_registry_data_action(struct db_context *db,
 
                /* preserve existing values across restarts. Only add new ones */
 
-               if (!regval_ctr_key_exists(values,
+               if (!regval_ctr_value_exists(values,
                                        builtin_registry_values[i].valuename))
                {
                        regdb_ctr_add_value(values,
@@ -363,7 +364,7 @@ WERROR init_registry_data(void)
                regdb_fetch_values_internal(regdb,
                                            builtin_registry_values[i].path,
                                            values);
-               if (!regval_ctr_key_exists(values,
+               if (!regval_ctr_value_exists(values,
                                        builtin_registry_values[i].valuename))
                {
                        TALLOC_FREE(values);
@@ -983,7 +984,11 @@ static NTSTATUS regdb_store_keys_action(struct db_context *db,
                TALLOC_FREE(path);
        }
 
-       werr = WERR_OK;
+       /*
+        * Update the seqnum in the container to possibly
+        * prevent next read from going to disk
+        */
+       werr = regsubkey_ctr_set_seqnum(store_ctx->ctr, db->get_seqnum(db));
 
 done:
        talloc_free(mem_ctx);
@@ -1516,6 +1521,11 @@ static bool scan_parent_subkeys(struct db_context *db, const char *parent,
                        goto fail;
                }
 
+               DEBUG(2, (__location__ " WARNING: recreating the sorted "
+                         "subkeys cache for key '%s' from scan_parent_subkeys "
+                         "this should not happen (too frequently)...\n",
+                         path));
+
                status = create_sorted_subkeys_internal(path, key);
                if (!NT_STATUS_IS_OK(status)) {
                        res = db->transaction_cancel(db);
@@ -1701,7 +1711,8 @@ static int regdb_unpack_values(struct regval_ctr *values, uint8 *buf, int buflen
                                (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));
+               DEBUG(10, ("regdb_unpack_values: value[%d]: name[%s] len[%d]\n",
+                          i, valuename, size));
        }
 
        return len;
@@ -1755,7 +1766,7 @@ static int regdb_fetch_values_internal(struct db_context *db, const char* key,
        TDB_DATA value;
        WERROR werr;
 
-       DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key));
+       DEBUG(10,("regdb_fetch_values: Looking for values of key [%s]\n", key));
 
        if (!regdb_key_exists(db, key)) {
                goto done;
@@ -1798,8 +1809,9 @@ static bool regdb_store_values_internal(struct db_context *db, const char *key,
        int len;
        NTSTATUS status;
        bool result = false;
+       WERROR werr;
 
-       DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key));
+       DEBUG(10,("regdb_store_values: Looking for values of key [%s]\n", key));
 
        if (!regdb_key_exists(db, key)) {
                goto done;
@@ -1840,8 +1852,17 @@ static bool regdb_store_values_internal(struct db_context *db, const char *key,
        }
 
        status = dbwrap_trans_store_bystring(db, keystr, data, TDB_REPLACE);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("regdb_store_values_internal: error storing: %s\n", nt_errstr(status)));
+               goto done;
+       }
 
-       result = NT_STATUS_IS_OK(status);
+       /*
+        * update the seqnum in the cache to prevent the next read
+        * from going to disk
+        */
+       werr = regval_ctr_set_seqnum(values, db->get_seqnum(db));
+       result = W_ERROR_IS_OK(status);
 
 done:
        TALLOC_FREE(ctx);