summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-05-25 23:27:28 +0200
committerMichael Adam <obnox@samba.org>2009-05-26 00:51:40 +0200
commitdfe06d21bdc4c715e02c9f80c4bc7144a0d9ee59 (patch)
tree93ded73cada6642822ff62a299c62bb197c44cc2 /source3
parentfb262f79fab00374023e59476e8d05a1015a7041 (diff)
downloadsamba-dfe06d21bdc4c715e02c9f80c4bc7144a0d9ee59.tar.gz
samba-dfe06d21bdc4c715e02c9f80c4bc7144a0d9ee59.tar.bz2
samba-dfe06d21bdc4c715e02c9f80c4bc7144a0d9ee59.zip
s3:dbwrap_tool: add "erase" opearation
Michael
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/dbwrap_tool.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 5172112a4c..c25620f64f 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -23,7 +23,7 @@
extern bool AllowDebugChange;
-typedef enum { OP_FETCH, OP_STORE, OP_DELETE } dbwrap_op;
+typedef enum { OP_FETCH, OP_STORE, OP_DELETE, OP_ERASE } dbwrap_op;
typedef enum { TYPE_INT32, TYPE_UINT32 } dbwrap_type;
@@ -111,6 +111,32 @@ static int dbwrap_tool_delete(struct db_context *db,
return 0;
}
+static int delete_fn(struct db_record *rec, void *priv)
+{
+ rec->delete_rec(rec);
+ return 0;
+}
+
+/**
+ * dbwrap_tool_erase: erase the whole data base
+ * the keyname argument is not used.
+ */
+static int dbwrap_tool_erase(struct db_context *db,
+ const char *keyname,
+ void *data)
+{
+ int ret;
+
+ ret = db->traverse(db, delete_fn, NULL);
+
+ if (ret < 0) {
+ d_fprintf(stderr, "ERROR erasing the database\n");
+ return -1;
+ }
+
+ return 0;
+}
+
struct dbwrap_op_dispatch_table {
dbwrap_op op;
dbwrap_type type;
@@ -126,6 +152,7 @@ struct dbwrap_op_dispatch_table dispatch_table[] = {
{ OP_STORE, TYPE_UINT32, dbwrap_tool_store_uint32 },
{ OP_DELETE, TYPE_INT32, dbwrap_tool_delete },
{ OP_DELETE, TYPE_UINT32, dbwrap_tool_delete },
+ { OP_ERASE, TYPE_INT32, dbwrap_tool_erase },
{ 0, 0, NULL },
};
@@ -140,7 +167,7 @@ int main(int argc, const char **argv)
const char *dbname;
const char *opname;
dbwrap_op op;
- const char *keyname;
+ const char *keyname = "";
const char *keytype = "int32";
dbwrap_type type;
const char *valuestr = "0";
@@ -156,10 +183,10 @@ int main(int argc, const char **argv)
AllowDebugChange = false;
lp_load(get_dyn_CONFIGFILE(), true, false, false, true);
- if ((argc != 4) && (argc != 5) && (argc != 6)) {
+ if ((argc < 3) || (argc > 6)) {
d_fprintf(stderr,
- "USAGE: %s <database> <op> <key> [<type> [<value>]]\n"
- " ops: fetch, store, delete\n"
+ "USAGE: %s <database> <op> [<key> [<type> [<value>]]]\n"
+ " ops: fetch, store, delete, erase\n"
" types: int32, uint32\n",
argv[0]);
goto done;
@@ -167,7 +194,6 @@ int main(int argc, const char **argv)
dbname = argv[1];
opname = argv[2];
- keyname = argv[3];
if (strcmp(opname, "store") == 0) {
if (argc != 6) {
@@ -177,6 +203,7 @@ int main(int argc, const char **argv)
}
valuestr = argv[5];
keytype = argv[4];
+ keyname = argv[3];
op = OP_STORE;
} else if (strcmp(opname, "fetch") == 0) {
if (argc != 5) {
@@ -186,13 +213,22 @@ int main(int argc, const char **argv)
}
op = OP_FETCH;
keytype = argv[4];
+ keyname = argv[3];
} else if (strcmp(opname, "delete") == 0) {
if (argc != 4) {
d_fprintf(stderr, "ERROR: operation 'delete' does "
"not allow type nor value argument\n");
goto done;
}
+ keyname = argv[3];
op = OP_DELETE;
+ } else if (strcmp(opname, "erase") == 0) {
+ if (argc != 3) {
+ d_fprintf(stderr, "ERROR: operation 'erase' does "
+ "not take a key argument\n");
+ goto done;
+ }
+ op = OP_ERASE;
} else {
d_fprintf(stderr,
"ERROR: invalid op '%s' specified\n"