2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2001
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <ccan/tdb/tdb.h>
27 #include <sys/types.h>
31 static void print_data(TDB_DATA d)
33 unsigned char *p = (unsigned char *)d.dptr;
36 if (isprint(*p) && !strchr("\"\\", *p)) {
45 static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
48 printf("key(%d) = \"", (int)key.dsize);
51 printf("data(%d) = \"", (int)dbuf.dsize);
58 static int dump_tdb(const char *fname, const char *keyname)
63 tdb = tdb_open(fname, 0, 0, O_RDONLY, 0);
65 printf("Failed to open %s\n", fname);
70 tdb_traverse(tdb, traverse_fn, NULL);
72 key.dptr = (void *)keyname;
73 key.dsize = strlen( keyname);
74 value = tdb_fetch(tdb, key);
86 static void usage( void)
88 printf( "Usage: tdbdump [options] <filename>\n\n");
89 printf( " -h this help message\n");
90 printf( " -k keyname dumps value of keyname\n");
93 int main(int argc, char *argv[])
95 char *fname, *keyname=NULL;
99 printf("Usage: tdbdump <fname>\n");
103 while ((c = getopt( argc, argv, "hk:")) != -1) {
117 fname = argv[optind];
119 return dump_tdb(fname, keyname);