*/
#include "replace.h"
+#include <assert.h>
#include "lib/util/debug.h"
#include "lib/util/fault.h"
#include "lib/util/talloc_stack.h"
* 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;
}
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)
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. */
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);
*/
#include "includes.h"
+#include <assert.h>
#include "dbwrap/dbwrap.h"
#include "dbwrap/dbwrap_private.h"
#include "dbwrap/dbwrap_rbt.h"
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;
}
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);
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;
{
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");
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;