diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-10-04 09:04:23 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-10-04 03:16:06 +0200 |
commit | 100d38d6e0fae1dc666ae43941570c9f106b73c2 (patch) | |
tree | cc6e290bd67404206354f03224559f4cc5a921ca /lib/tdb/tools/tdbdump.c | |
parent | ffde8678910ae838588ab380b48a544333f81241 (diff) | |
download | samba-100d38d6e0fae1dc666ae43941570c9f106b73c2.tar.gz samba-100d38d6e0fae1dc666ae43941570c9f106b73c2.tar.bz2 samba-100d38d6e0fae1dc666ae43941570c9f106b73c2.zip |
tdb: add -e option to tdbdump (and docment it).
This allows for an emergency best-effort dump. It's a little better than
strings(1).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Autobuild-User(master): Rusty Russell <rusty@rustcorp.com.au>
Autobuild-Date(master): Thu Oct 4 03:16:06 CEST 2012 on sn-devel-104
Diffstat (limited to 'lib/tdb/tools/tdbdump.c')
-rw-r--r-- | lib/tdb/tools/tdbdump.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/tdb/tools/tdbdump.c b/lib/tdb/tools/tdbdump.c index bb11200ec4..bcd395fd5a 100644 --- a/lib/tdb/tools/tdbdump.c +++ b/lib/tdb/tools/tdbdump.c @@ -86,7 +86,18 @@ static void log_stderr(struct tdb_context *tdb, enum tdb_debug_level level, va_end(ap); } -static int dump_tdb(const char *fname, const char *keyname) +static void emergency_walk(TDB_DATA key, TDB_DATA dbuf, void *keyname) +{ + if (keyname) { + if (key.dsize != strlen(keyname)) + return; + if (memcmp(key.dptr, keyname, key.dsize) != 0) + return; + } + traverse_fn(NULL, key, dbuf, NULL); +} + +static int dump_tdb(const char *fname, const char *keyname, bool emergency) { TDB_CONTEXT *tdb; TDB_DATA key, value; @@ -98,6 +109,9 @@ static int dump_tdb(const char *fname, const char *keyname) return 1; } + if (emergency) { + return tdb_rescue(tdb, emergency_walk, keyname) == 0; + } if (!keyname) { return tdb_traverse(tdb, traverse_fn, NULL) == -1 ? 1 : 0; } else { @@ -120,11 +134,13 @@ 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"); + printf( " -e emergency dump, for corrupt databases\n"); } int main(int argc, char *argv[]) { char *fname, *keyname=NULL; + bool emergency = false; int c; if (argc < 2) { @@ -132,7 +148,7 @@ static void usage( void) exit(1); } - while ((c = getopt( argc, argv, "hk:")) != -1) { + while ((c = getopt( argc, argv, "hk:e")) != -1) { switch (c) { case 'h': usage(); @@ -140,6 +156,9 @@ static void usage( void) case 'k': keyname = optarg; break; + case 'e': + emergency = true; + break; default: usage(); exit( 1); @@ -148,5 +167,5 @@ static void usage( void) fname = argv[optind]; - return dump_tdb(fname, keyname); + return dump_tdb(fname, keyname, emergency); } |