]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
net/serverid: implement "--persistent" for "net serverid wipedbs"
authorRalph Boehme <slow@samba.org>
Tue, 25 Nov 2025 15:25:16 +0000 (16:25 +0100)
committerRalph Boehme <slow@samba.org>
Fri, 17 Jul 2026 10:18:37 +0000 (10:18 +0000)
Wipe the per-record backup databases.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/utils/net.c
source3/utils/net.h
source3/utils/net_serverid.c

index 0ce03f8213dac4f45dae2415a907709e4cd1b8aa..90fe60854f2753376ff69e55b0a01757e734caf1 100644 (file)
@@ -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
index 8a4218b529f902e5bbdfb83272ac931e8428cae7..745288a9cce3366ae06feb0158b6c5a844dcac1e 100644 (file)
@@ -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;
index 961e84622d4cadb00aa3cf0596f9b8dbd8b1cfee..292686ec821c57a54a0b4f8504b8cf5f41a2b06f 100644 (file)
@@ -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);