From: Aaron Haslett Date: Mon, 20 May 2019 04:19:51 +0000 (+1200) Subject: ldb: ldbdump key and pack format version comments X-Git-Tag: ldb-2.0.5~695 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a666a99e4dc594bc153cd26b24cddd547c1cc750;p=thirdparty%2Fsamba.git ldb: ldbdump key and pack format version comments For testing we need to know the actual KV level key of records and each record's pack format version. This patch makes ldbdump add comments with that info. We will parse it out in python tests. Signed-off-by: Aaron Haslett Reviewed-by: Andrew Bartlett Reviewed-by: Gary Lockyer Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Wed May 22 05:58:17 UTC 2019 on sn-devel-184 --- diff --git a/lib/ldb/tools/ldbdump.c b/lib/ldb/tools/ldbdump.c index eb237e89b44..5cdb7d850a3 100644 --- a/lib/ldb/tools/ldbdump.c +++ b/lib/ldb/tools/ldbdump.c @@ -36,6 +36,26 @@ static struct ldb_context *ldb; bool show_index = false; bool validate_contents = false; +static void print_data(TDB_DATA d) +{ + unsigned char *p = (unsigned char *)d.dptr; + int len = d.dsize; + while (len--) { + if (isprint(*p) && !strchr("\"\\", *p)) { + fputc(*p, stdout); + } else { + printf("\\%02X", *p); + } + p++; + } +} + +static unsigned int pull_uint32(uint8_t *p) +{ + return p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); +} + + static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA _dbuf, void *state) { int ret, i, j; @@ -79,6 +99,10 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA _dbuf, void *sta } } + printf("# key: "); + print_data(key); + printf("\n# pack format: %#010x\n", pull_uint32(_dbuf.dptr)); + if (!validate_contents || ldb_dn_is_special(msg->dn)) { ldb_ldif_write_file(ldb, stdout, &ldif); TALLOC_FREE(msg);