]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dbwrap: add flags to dbwrap_wipe()
authorRalph Boehme <slow@samba.org>
Thu, 23 Oct 2025 16:41:41 +0000 (18:41 +0200)
committerRalph Boehme <slow@samba.org>
Fri, 17 Jul 2026 10:18:35 +0000 (10:18 +0000)
Will be used later to pass flags=DBWRAP_DROP_PERSISTENT for databases with
DBWRAP_FLAG_PER_REC_PERSISTENT, requesting to wipe the persistent backup
database.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
lib/dbwrap/dbwrap.c
lib/dbwrap/dbwrap.h
lib/dbwrap/dbwrap_private.h
lib/dbwrap/dbwrap_rbt.c
lib/dbwrap/dbwrap_tdb.c
source3/rpc_server/fss/srv_fss_state.c
source3/utils/dbwrap_tool.c
source3/utils/net_registry_check.c

index c4a6ed52864f44ea1229b94626a148b924723401..8f3988c46bc7a5a20e499853110fd7cd31d3712d 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include "replace.h"
+#include <assert.h>
 #include "lib/util/debug.h"
 #include "lib/util/fault.h"
 #include "lib/util/talloc_stack.h"
@@ -48,9 +49,14 @@ static int delete_record(struct db_record *rec, void *data)
  * Fallback wipe implementation using traverse and delete if no genuine
  * wipe operation is provided
  */
-static int dbwrap_fallback_wipe(struct db_context *db)
+static int dbwrap_fallback_wipe(struct db_context *db,
+                               struct dbwrap_wipe_flags flags)
 {
-       NTSTATUS status = dbwrap_trans_traverse(db, delete_record, NULL);
+       NTSTATUS status;
+
+       assert(dbwrap_wipe_flags_default(flags));
+
+       status = dbwrap_trans_traverse(db, delete_record, NULL);
        return NT_STATUS_IS_OK(status) ? 0 : -1;
 }
 
@@ -613,12 +619,20 @@ NTSTATUS dbwrap_do_locked(struct db_context *db, TDB_DATA key,
        return NT_STATUS_OK;
 }
 
-int dbwrap_wipe(struct db_context *db)
+int dbwrap_wipe(struct db_context *db, struct dbwrap_wipe_flags flags)
 {
        if (db->wipe == NULL) {
-               return dbwrap_fallback_wipe(db);
+               return dbwrap_fallback_wipe(db, flags);
        }
-       return db->wipe(db);
+       return db->wipe(db, flags);
+}
+
+bool dbwrap_wipe_flags_default(struct dbwrap_wipe_flags flags)
+{
+       struct dbwrap_wipe_flags def_flags = {
+               .wipe_default = true,
+       };
+       return memcmp(&flags, &def_flags, sizeof(flags)) == 0;
 }
 
 int dbwrap_check(struct db_context *db)
index b1127bc612eda428321617fe52e81a5374ab9b3e..9df3576bb8a48e534d462c669c4aef5865699dfb 100644 (file)
@@ -161,7 +161,24 @@ struct tevent_req *dbwrap_parse_record_send(
        void *private_data,
        enum dbwrap_req_state *req_state);
 NTSTATUS dbwrap_parse_record_recv(struct tevent_req *req);
-int dbwrap_wipe(struct db_context *db);
+
+/**
+ * Wipe a database
+ *
+ * @param[in]  db           Database to wipe
+
+ * @param[in] flags         DBWRAP_DROP_PERSISTENT: On databases opened with
+ *                          DBWRAP_FLAG_PER_REC_PERSISTENT, wipe the persistent
+ *                          backup database.
+ *
+ * @return                  0 on success, -1 on error
+ **/
+struct dbwrap_wipe_flags {
+       bool wipe_default : 1;
+       bool wipe_persistent_backup_db : 1;
+};
+int dbwrap_wipe(struct db_context *db, struct dbwrap_wipe_flags flags);
+bool dbwrap_wipe_flags_default(struct dbwrap_wipe_flags flags);
 int dbwrap_check(struct db_context *db);
 int dbwrap_get_seqnum(struct db_context *db);
 /* Returns 0 if unknown. */
index 3dc7bb20e457dcf03a5e623ce7b8e9206da3733b..b88e9bf3d88f62ddce9f02fe65d9aea455e132ef 100644 (file)
@@ -73,7 +73,7 @@ struct db_context {
                                         void *private_data),
                              void *private_data);
        int (*exists)(struct db_context *db,TDB_DATA key);
-       int (*wipe)(struct db_context *db);
+       int (*wipe)(struct db_context *db, struct dbwrap_wipe_flags flags);
        int (*check)(struct db_context *db);
        size_t (*id)(struct db_context *db, uint8_t *id, size_t idlen);
 
index 6cd8d936db6a1a47882fc44af8cc395df1c461ae..e1c01623ef03c2af5742e176345ed07fe9873b5e 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include <assert.h>
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_private.h"
 #include "dbwrap/dbwrap_rbt.h"
@@ -407,11 +408,15 @@ static int db_rbt_exists(struct db_context *db, TDB_DATA key)
        return db_rbt_search_internal(db, key, NULL);
 }
 
-static int db_rbt_wipe(struct db_context *db)
+static int db_rbt_wipe(struct db_context *db, struct dbwrap_wipe_flags flags)
 {
        struct db_rbt_ctx *old_ctx = talloc_get_type_abort(
                db->private_data, struct db_rbt_ctx);
-       struct db_rbt_ctx *new_ctx = talloc_zero(db, struct db_rbt_ctx);
+       struct db_rbt_ctx *new_ctx = NULL;
+
+       assert(dbwrap_wipe_flags_default(flags));
+
+       new_ctx = talloc_zero(db, struct db_rbt_ctx);
        if (new_ctx == NULL) {
                return -1;
        }
index 582cea6b97fe7e3076b667226aef146827629596..0a7552aab4729103725c43679a93fdcc956121ef 100644 (file)
@@ -224,7 +224,7 @@ static int db_tdb_exists(struct db_context *db, TDB_DATA key)
        return tdb_exists(ctx->wtdb->tdb, key);
 }
 
-static int db_tdb_wipe(struct db_context *db)
+static int db_tdb_wipe(struct db_context *db, struct dbwrap_wipe_flags flags)
 {
        struct db_tdb_ctx *ctx = talloc_get_type_abort(
                db->private_data, struct db_tdb_ctx);
index 8597c36a74ebaae1a8d6f485ac289f7d2e3f902d..0f684064c599ebf41ca4df563658a0541089e0d4 100644 (file)
@@ -210,7 +210,7 @@ _PRIVATE_ NTSTATUS fss_state_store(TALLOC_CTX *mem_ctx,
                goto err_ctx_free;
        }
 
-       ret = dbwrap_wipe(db);
+       ret = dbwrap_wipe(db, (struct dbwrap_wipe_flags){.wipe_default=true});
        if (ret != 0) {
                status = NT_STATUS_UNSUCCESSFUL;
                goto err_db_free;
index 66380a98b5c31d91075e7d5dda9b0a0f23ec561e..0888ce6a90f59ced73503a491ba6b504d3f40335 100644 (file)
@@ -291,7 +291,7 @@ static int dbwrap_tool_erase(struct db_context *db,
 {
        int ret;
 
-       ret = dbwrap_wipe(db);
+       ret = dbwrap_wipe(db, (struct dbwrap_wipe_flags){.wipe_default=true});
 
        if (ret != 0) {
                d_fprintf(stderr, "ERROR erasing the database\n");
index aa5e65ecf81db1a576bd01afd593620c98349e56..71c62f7f2011c3f9bb5273bc64b98c690b50e08c 100644 (file)
@@ -1239,7 +1239,10 @@ static bool check_ctx_write_new_db(struct check_ctx *ctx) {
        assert(ctx->odb);
 
        if (ctx->opt.wipe) {
-               int ret = dbwrap_wipe(ctx->odb);
+               int ret = dbwrap_wipe(ctx->odb,
+                                     (struct dbwrap_wipe_flags){
+                                             .wipe_default=true
+                                     });
                if (ret != 0) {
                        DEBUG(0, ("wiping %s failed\n", ctx->opt.output));
                        return false;