From c3f93271ef447f9f16cd3002307c630c5f149f5a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 30 Jan 2014 10:29:49 +0100 Subject: [PATCH] dbwrap_tool: add option "--non-persistent" and force excatly one of "--[non-]persistent" We want to force users of dbwrap_tool to explicitly specify persistent or non-persistent. Otherwise, one could easily by accident wipe a whole database that is actually persistent but not currently opened by a samba process, just by openeing the DB with the default non-persistent mode... Signed-off-by: Michael Adam Reviewed-by: Stefan Metzmacher --- source3/utils/dbwrap_tool.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c index 406e89ee4de..ffca6b6d62a 100644 --- a/source3/utils/dbwrap_tool.c +++ b/source3/utils/dbwrap_tool.c @@ -411,6 +411,7 @@ int main(int argc, const char **argv) enum dbwrap_type type; const char *valuestr = "0"; int persistent = 0; + int non_persistent = 0; int tdb_flags = TDB_DEFAULT; TALLOC_CTX *mem_ctx = talloc_stackframe(); @@ -420,7 +421,13 @@ int main(int argc, const char **argv) struct poptOption popt_options[] = { POPT_AUTOHELP POPT_COMMON_SAMBA - { "persistent", 0, POPT_ARG_NONE, &persistent, 0, "treat the database as persistent", NULL }, + { "non-persistent", 0, POPT_ARG_NONE, &non_persistent, 0, + "treat the database as non-persistent " + "(CAVEAT: This mode might wipe your database!)", + NULL }, + { "persistent", 0, POPT_ARG_NONE, &persistent, 0, + "treat the database as persistent", + NULL }, POPT_TABLEEND }; int opt; @@ -463,6 +470,16 @@ int main(int argc, const char **argv) goto done; } + if ((persistent == 0 && non_persistent == 0) || + (persistent == 1 && non_persistent == 1)) + { + d_fprintf(stderr, "ERROR: you must specify exactly one " + "of --persistent and --non-persistent\n"); + goto done; + } else if (non_persistent == 1) { + tdb_flags |= TDB_CLEAR_IF_FIRST; + } + dbname = extra_argv[0]; opname = extra_argv[1]; @@ -563,10 +580,6 @@ int main(int argc, const char **argv) goto done; } - if (persistent == 0) { - tdb_flags |= TDB_CLEAR_IF_FIRST; - } - switch (op) { case OP_FETCH: case OP_STORE: -- 2.11.4.GIT