diff options
author | Michael Adam <obnox@samba.org> | 2009-05-26 00:47:15 +0200 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2009-05-27 09:47:10 +0200 |
commit | c216d96511ffb8ac4edfbf0c491a5ecccd7b63fb (patch) | |
tree | e854957e99daf0c037d439ffa97c1ce0b875fc45 /source3/utils | |
parent | a0e356b5fe134f72d9c9a04914f4e7a4d4a8f9d0 (diff) | |
download | samba-c216d96511ffb8ac4edfbf0c491a5ecccd7b63fb.tar.gz |
s3:dbwrap_tool: add listkeys operation
Michael
(cherry picked from commit 714acfac013a46c3677c3eb72ad57db6d97c7d61)
(cherry picked from commit 816776d2f81c1ae90e52612af76aaafeaeb04598)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/dbwrap_tool.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c index 59d8f2885ac..38b39032650 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, OP_ERASE } dbwrap_op; +typedef enum { OP_FETCH, OP_STORE, OP_DELETE, OP_ERASE, OP_LISTKEYS } dbwrap_op; typedef enum { TYPE_INT32, TYPE_UINT32 } dbwrap_type; @@ -137,6 +137,41 @@ static int dbwrap_tool_erase(struct db_context *db, return 0; } +static int listkey_fn(struct db_record *rec, void *private_data) +{ + int length = rec->key.dsize; + unsigned char *p = (unsigned char *)rec->key.dptr; + + while (length--) { + if (isprint(*p) && !strchr("\"\\", *p)) { + d_printf("%c", *p); + } else { + d_printf("\\%02X", *p); + } + p++; + } + + d_printf("\n"); + + return 0; +} + +static int dbwrap_tool_listkeys(struct db_context *db, + const char *keyname, + void *data) +{ + int ret; + + ret = db->traverse_read(db, listkey_fn, NULL); + + if (ret < 0) { + d_fprintf(stderr, "ERROR listing db keys\n"); + return -1; + } + + return 0; +} + struct dbwrap_op_dispatch_table { dbwrap_op op; dbwrap_type type; @@ -152,6 +187,7 @@ struct dbwrap_op_dispatch_table dispatch_table[] = { { OP_STORE, TYPE_UINT32, dbwrap_tool_store_uint32 }, { OP_DELETE, TYPE_INT32, dbwrap_tool_delete }, { OP_ERASE, TYPE_INT32, dbwrap_tool_erase }, + { OP_LISTKEYS, TYPE_INT32, dbwrap_tool_listkeys }, { 0, 0, NULL }, }; @@ -185,7 +221,7 @@ int main(int argc, const char **argv) if ((argc < 3) || (argc > 6)) { d_fprintf(stderr, "USAGE: %s <database> <op> [<key> [<type> [<value>]]]\n" - " ops: fetch, store, delete, erase\n" + " ops: fetch, store, delete, erase, listkeys\n" " types: int32, uint32\n", argv[0]); goto done; @@ -228,6 +264,13 @@ int main(int argc, const char **argv) goto done; } op = OP_ERASE; + } else if (strcmp(opname, "listkeys") == 0) { + if (argc != 3) { + d_fprintf(stderr, "ERROR: operation 'listkeys' does " + "not take a key argument\n"); + goto done; + } + op = OP_LISTKEYS; } else { d_fprintf(stderr, "ERROR: invalid op '%s' specified\n" |