summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorLars Müller <lmuelle@samba.org>2006-01-27 21:49:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:06:17 -0500
commit0f46bfdce61a438c61fba922bad1e5c910d88a10 (patch)
tree10124f09c4622acf314b7d0e9dbf9182579d0655 /source3
parent6f08a557bae46eb9a2f992dfcdc6c1954f55c703 (diff)
downloadsamba-0f46bfdce61a438c61fba922bad1e5c910d88a10.tar.gz
samba-0f46bfdce61a438c61fba922bad1e5c910d88a10.tar.bz2
samba-0f46bfdce61a438c61fba922bad1e5c910d88a10.zip
r13197: Add -k switch to dump the data of a single key.
(This used to be commit 23503ff45f2a377728bc5ebb1e6db2755bb5ca2b)
Diffstat (limited to 'source3')
-rw-r--r--source3/tdb/tdbdump.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/source3/tdb/tdbdump.c b/source3/tdb/tdbdump.c
index 6cac0bc5cc..b702fb0735 100644
--- a/source3/tdb/tdbdump.c
+++ b/source3/tdb/tdbdump.c
@@ -59,9 +59,10 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *stat
return 0;
}
-static int dump_tdb(const char *fname)
+static int dump_tdb(const char *fname, const char *keyname)
{
TDB_CONTEXT *tdb;
+ TDB_DATA key, value;
tdb = tdb_open(fname, 0, 0, O_RDONLY, 0);
if (!tdb) {
@@ -69,20 +70,55 @@ static int dump_tdb(const char *fname)
return 1;
}
- tdb_traverse(tdb, traverse_fn, NULL);
+ if (!keyname) {
+ tdb_traverse(tdb, traverse_fn, NULL);
+ } else {
+ key.dptr = (char *)keyname;
+ key.dsize = strlen( keyname);
+ value = tdb_fetch(tdb, key);
+ if (!value.dptr) {
+ return 1;
+ } else {
+ print_data(value);
+ free(value.dptr);
+ }
+ }
+
return 0;
}
+static void usage( void)
+{
+ printf( "Usage: tdbdump [options] <filename>\n\n");
+ printf( " -h this help message\n");
+ printf( " -k keyname dumps value of keyname\n");
+}
+
int main(int argc, char *argv[])
{
- char *fname;
+ char *fname, *keyname=NULL;
+ int c;
if (argc < 2) {
printf("Usage: tdbdump <fname>\n");
exit(1);
}
- fname = argv[1];
+ while ((c = getopt( argc, argv, "hk:")) != -1) {
+ switch (c) {
+ case 'h':
+ usage();
+ exit( 0);
+ case 'k':
+ keyname = optarg;
+ break;
+ default:
+ usage();
+ exit( 1);
+ }
+ }
+
+ fname = argv[optind];
- return dump_tdb(fname);
+ return dump_tdb(fname, keyname);
}