summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-10-04 09:04:23 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-10-04 03:16:06 +0200
commit100d38d6e0fae1dc666ae43941570c9f106b73c2 (patch)
treecc6e290bd67404206354f03224559f4cc5a921ca
parentffde8678910ae838588ab380b48a544333f81241 (diff)
downloadsamba-100d38d6e0fae1dc666ae43941570c9f106b73c2.tar.gz
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
-rw-r--r--lib/tdb/manpages/tdbdump.8.xml31
-rw-r--r--lib/tdb/tools/tdbdump.c25
2 files changed, 53 insertions, 3 deletions
diff --git a/lib/tdb/manpages/tdbdump.8.xml b/lib/tdb/manpages/tdbdump.8.xml
index 90465e53e87..34201932434 100644
--- a/lib/tdb/manpages/tdbdump.8.xml
+++ b/lib/tdb/manpages/tdbdump.8.xml
@@ -19,6 +19,9 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>tdbdump</command>
+ <arg choice="opt">-k <replaceable>keyname</replaceable></arg>
+ <arg choice="opt">-e</arg>
+ <arg choice="opt">-h</arg>
<arg choice="req">filename</arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -39,6 +42,34 @@
</para>
</refsect1>
+<refsect1>
+ <title>OPTIONS</title>
+
+ <variablelist>
+
+ <varlistentry>
+ <term>-h</term>
+ <listitem><para>
+ Get help information.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-k <replaceable>keyname</replaceable></term>
+ <listitem><para>
+ The <command>-k</command> option restricts dumping to a single key, if found.
+ </para> </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-e</term>
+ <listitem><para>
+ The <command>-e</command> tries to dump out from a corrupt database. Naturally, such a dump is unreliable, at best.
+ </para></listitem>
+ </varlistentry>
+
+ </variablelist>
+</refsect1>
<refsect1>
<title>VERSION</title>
diff --git a/lib/tdb/tools/tdbdump.c b/lib/tdb/tools/tdbdump.c
index bb11200ec4a..bcd395fd5af 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);
}