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 09:04:23 +0930 |
commit | ffde8678910ae838588ab380b48a544333f81241 (patch) | |
tree | b5f638507486bdbb3036417861270265fb115604 /lib/tdb | |
parent | 90f463b25f7bb0bc944732773c56e356834ea203 (diff) | |
download | samba-ffde8678910ae838588ab380b48a544333f81241.tar.gz samba-ffde8678910ae838588ab380b48a544333f81241.tar.bz2 samba-ffde8678910ae838588ab380b48a544333f81241.zip |
tdb: tdbdump should log errors, and fail in that case.
Dumping a corrupt database should not exit silently with 0 status!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb')
-rw-r--r-- | lib/tdb/tools/tdbdump.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/tdb/tools/tdbdump.c b/lib/tdb/tools/tdbdump.c index 027fda3d42..bb11200ec4 100644 --- a/lib/tdb/tools/tdbdump.c +++ b/lib/tdb/tools/tdbdump.c @@ -51,19 +51,55 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *stat return 0; } +static void log_stderr(struct tdb_context *tdb, enum tdb_debug_level level, + const char *fmt, ...) +{ + va_list ap; + char *ptr = NULL; + int debuglevel = 0; + int ret; + const char *name = tdb_name(tdb); + const char *prefix = ""; + + if (!name) + name = "unnamed"; + + switch (level) { + case TDB_DEBUG_ERROR: + prefix = "ERROR: "; + break; + case TDB_DEBUG_WARNING: + prefix = "WARNING: "; + break; + case TDB_DEBUG_TRACE: + return; + + default: + case TDB_DEBUG_FATAL: + prefix = "FATAL: "; + break; + } + + va_start(ap, fmt); + fprintf(stderr, "tdb(%s): %s", name, prefix); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + static int dump_tdb(const char *fname, const char *keyname) { TDB_CONTEXT *tdb; TDB_DATA key, value; + struct tdb_logging_context logfn = { log_stderr }; - tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); + tdb = tdb_open_ex(fname, 0, 0, O_RDONLY, 0, &logfn, NULL); if (!tdb) { printf("Failed to open %s\n", fname); return 1; } if (!keyname) { - tdb_traverse(tdb, traverse_fn, NULL); + return tdb_traverse(tdb, traverse_fn, NULL) == -1 ? 1 : 0; } else { key.dptr = discard_const_p(uint8_t, keyname); key.dsize = strlen(keyname); |