From: Ralph Boehme Date: Tue, 25 Nov 2025 15:25:16 +0000 (+0100) Subject: net/serverid: implement "--persistent" for "net serverid wipedbs" X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=221d0ef5d8fd72373c9cbfd97f614bf79ce9ef24;p=thirdparty%2Fsamba.git net/serverid: implement "--persistent" for "net serverid wipedbs" Wipe the per-record backup databases. Signed-off-by: Ralph Boehme Reviewed-by: Anoop C S --- diff --git a/source3/utils/net.c b/source3/utils/net.c index 0ce03f8213d..90fe60854f2 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -1321,6 +1321,13 @@ static struct functable net_func[] = { .argInfo = POPT_ARG_STRING, .arg = &c->opt_witness_forced_response, }, + /* Options for wipedbs */ + { + .longName = "persistent", + .argInfo = POPT_ARG_NONE, + .arg = &c->opt_persistent, + .descrip = "Wipe persistent backup databases", + }, POPT_COMMON_SAMBA POPT_COMMON_CONNECTION POPT_COMMON_CREDENTIALS diff --git a/source3/utils/net.h b/source3/utils/net.h index 8a4218b529f..745288a9cce 100644 --- a/source3/utils/net.h +++ b/source3/utils/net.h @@ -98,6 +98,7 @@ struct net_context { int opt_witness_new_node; const char *opt_witness_forced_response; const char *opt_krb5_ccache; + int opt_persistent; int opt_have_ip; struct sockaddr_storage opt_dest_ip; diff --git a/source3/utils/net_serverid.c b/source3/utils/net_serverid.c index 961e84622d4..292686ec821 100644 --- a/source3/utils/net_serverid.c +++ b/source3/utils/net_serverid.c @@ -32,6 +32,7 @@ #include "librpc/gen_ndr/ndr_smbXsrv.h" #include "source3/locking/share_mode_lock.h" #include "source3/smbd/scavenger.h" +#include "source3/locking/proto.h" struct wipedbs_record_marker { struct wipedbs_record_marker *prev, *next; @@ -75,6 +76,7 @@ struct wipedbs_state { struct timeval now; bool testmode; bool verbose; + bool wipe_persistent; }; static struct wipedbs_server_data *get_server_data(struct wipedbs_state *state, @@ -768,6 +770,33 @@ static int wipedbs_traverse_replay_records(struct db_record *rec, return 0; } +static int net_serverid_wipedbs_persistent(struct wipedbs_state *state) +{ + struct dbwrap_wipe_flags flags = {.wipe_persistent_backup_db=true}; + NTSTATUS status; + + status = smbXsrv_open_global_wipe(flags); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, "smbXsrv_open_global_wipe_persistent failed\n"); + return -1; + } + + status = locking_wipe(flags); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, "locking_wipe failed\n"); + return -1; + } + + status = brlock_wipe(flags); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr, "brlock_wipe failed\n"); + return -1; + } + + printf("Wiped persistent file state backup databases\n"); + return 0; +} + int net_serverid_wipedbs(struct net_context *c, int argc, const char **argv) { int ret = -1; @@ -779,7 +808,7 @@ int net_serverid_wipedbs(struct net_context *c, int argc, const char **argv) if (c->display_usage) { d_printf("%s\n%s", _("Usage:"), - _("net serverid wipedbs [--test] [--verbose]\n")); + _("net serverid wipedbs [--test] [--verbose] [--persistent]\n")); d_printf("%s\n%s", _("Example:"), _("net serverid wipedbs -v\n")); @@ -789,6 +818,7 @@ int net_serverid_wipedbs(struct net_context *c, int argc, const char **argv) state->now = timeval_current(); state->testmode = c->opt_testmode; state->verbose = c->opt_verbose; + state->wipe_persistent = c->opt_persistent; ok = locking_init(); if (!ok) { @@ -886,6 +916,14 @@ int net_serverid_wipedbs(struct net_context *c, int argc, const char **argv) state->stat.replay.todelete, state->stat.replay.failure); + if (state->wipe_persistent) { + ret = net_serverid_wipedbs_persistent(state); + if (ret != 0) { + fprintf(stderr, "Wiping persistent dbs failed\n"); + goto done; + } + } + ret = 0; done: talloc_free(state);