3 Copyright (C) Andrew Tridgell 2001
4 Copyright (C) Rusty Russell 2011
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/>.
21 #ifdef HAVE_LIBREPLACE
23 #include <system/filesys.h>
24 #include <system/locale.h>
28 #include <sys/types.h>
35 static void print_data(NTDB_DATA d
)
37 unsigned char *p
= (unsigned char *)d
.dptr
;
40 if (isprint(*p
) && !strchr("\"\\", *p
)) {
49 static int traverse_fn(struct ntdb_context
*ntdb
, NTDB_DATA key
, NTDB_DATA dbuf
, void *state
)
52 printf("key(%d) = \"", (int)key
.dsize
);
55 printf("data(%d) = \"", (int)dbuf
.dsize
);
62 static int dump_ntdb(const char *fname
, const char *keyname
)
64 struct ntdb_context
*ntdb
;
67 ntdb
= ntdb_open(fname
, 0, O_RDONLY
, 0, NULL
);
69 printf("Failed to open %s\n", fname
);
74 ntdb_traverse(ntdb
, traverse_fn
, NULL
);
76 key
= ntdb_mkdata(keyname
, strlen(keyname
));
77 if (ntdb_fetch(ntdb
, key
, &value
) != 0) {
88 static void usage( void)
90 printf( "Usage: ntdbdump [options] <filename>\n\n");
91 printf( " -h this help message\n");
92 printf( " -k keyname dumps value of keyname\n");
95 int main(int argc
, char *argv
[])
97 char *fname
, *keyname
=NULL
;
101 printf("Usage: ntdbdump <fname>\n");
105 while ((c
= getopt( argc
, argv
, "hk:")) != -1) {
119 fname
= argv
[optind
];
121 return dump_ntdb(fname
, keyname
);