summaryrefslogtreecommitdiff
path: root/lib/tdb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tdb')
-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 90465e53e8..3420193243 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 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);
}