[SCM] Samba Shared Repository - branch master updated

Christof Schmitt cs at samba.org
Tue Apr 16 18:38:02 UTC 2024


The branch, master has been updated
       via  7532c798d13 docs: Document new tdbdump -x option
       via  1a55ee1107b tdb: Add test for tdbdump -x
       via  5f5290c2714 tdb: Add tdbdump option to output all data as hex values
       via  f6a47de2dbd tdb: Add test for tdbdump command
       via  3d290e31523 tdb: Return failure as exit status from test_tdbbackup.sh
      from  48493735e2d s3: winbindd: winbindd_pam: fix leak in extract_pac_vrfy_sigs

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7532c798d137daa28bd2f9b440cd44af96275787
Author: Christof Schmitt <cs at samba.org>
Date:   Thu Mar 7 16:41:11 2024 -0700

    docs: Document new tdbdump -x option
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Christof Schmitt <cs at samba.org>
    Autobuild-Date(master): Tue Apr 16 18:37:17 UTC 2024 on atb-devel-224

commit 1a55ee1107bf76d49eaef7545c6f88511bf1d34e
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Apr 12 15:48:02 2024 -0700

    tdb: Add test for tdbdump -x
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 5f5290c27140cbea2b9ab9b080a69ff691653b52
Author: Christof Schmitt <cs at samba.org>
Date:   Thu Mar 7 16:38:53 2024 -0700

    tdb: Add tdbdump option to output all data as hex values
    
    This can be useful for debugging tdb databases, the hex output of the
    key can be used for "net tdb" or ctdb commands.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit f6a47de2dbdb04096cf4bf147d149317cec3a235
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Apr 12 15:44:38 2024 -0700

    tdb: Add test for tdbdump command
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 3d290e31523b5d6c6b6c05cbda2e42983b3bdbb0
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Apr 12 15:22:06 2024 -0700

    tdb: Return failure as exit status from test_tdbbackup.sh
    
    When this test is called from wscript, only the exit code is checked.
    Track failures and return as non-zero exit code.
    
    Signed-off-by: Christof Schmitt <cs at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/tdb/man/tdbdump.8.xml      |  8 ++++++
 lib/tdb/test/sample_tdb.txt    | 12 +++++++++
 lib/tdb/test/sample_tdb_x.txt  | 12 +++++++++
 lib/tdb/test/test_tdbbackup.sh | 15 ++++++++---
 lib/tdb/test/test_tdbdump.sh   | 58 ++++++++++++++++++++++++++++++++++++++++++
 lib/tdb/tools/tdbdump.c        | 51 +++++++++++++++++++++++++------------
 lib/tdb/wscript                |  3 ++-
 7 files changed, 138 insertions(+), 21 deletions(-)
 create mode 100644 lib/tdb/test/sample_tdb.txt
 create mode 100644 lib/tdb/test/sample_tdb_x.txt
 create mode 100755 lib/tdb/test/test_tdbdump.sh


Changeset truncated at 500 lines:

diff --git a/lib/tdb/man/tdbdump.8.xml b/lib/tdb/man/tdbdump.8.xml
index 31e6888862e..442f36fbcd6 100644
--- a/lib/tdb/man/tdbdump.8.xml
+++ b/lib/tdb/man/tdbdump.8.xml
@@ -23,6 +23,7 @@
 		<arg choice="opt">-k <replaceable>keyname</replaceable></arg>
 		<arg choice="opt">-e</arg>
 		<arg choice="opt">-h</arg>
+		<arg choice="opt">-x</arg>
 		<arg choice="req">filename</arg>
 	</cmdsynopsis>
 </refsynopsisdiv>
@@ -69,6 +70,13 @@
 		</para></listitem>
 		</varlistentry>
 
+		<varlistentry>
+		<term>-x</term>
+		<listitem><para>
+		The <command>-x</command> changes the output data to a hex dump, from the default mix of ASCII and hex dump.
+		</para></listitem>
+		</varlistentry>
+
 	</variablelist>
 </refsect1>
 
diff --git a/lib/tdb/test/sample_tdb.txt b/lib/tdb/test/sample_tdb.txt
new file mode 100644
index 00000000000..b9e028353e2
--- /dev/null
+++ b/lib/tdb/test/sample_tdb.txt
@@ -0,0 +1,12 @@
+{
+key(11) = "nbt_server\00"
+data(35) = "972.2147483648/1085706313786795392\00"
+}
+{
+key(15) = "winbind_server\00"
+data(25) = "977/12826542715097898407\00"
+}
+{
+key(14) = "notify-daemon\00"
+data(24) = "992/6389638235474936598\00"
+}
diff --git a/lib/tdb/test/sample_tdb_x.txt b/lib/tdb/test/sample_tdb_x.txt
new file mode 100644
index 00000000000..dbba20b4813
--- /dev/null
+++ b/lib/tdb/test/sample_tdb_x.txt
@@ -0,0 +1,12 @@
+{
+key(11) = "6E62745F73657276657200"
+data(35) = "3937322E323134373438333634382F3130383537303633313337383637393533393200"
+}
+{
+key(15) = "77696E62696E645F73657276657200"
+data(25) = "3937372F313238323635343237313530393738393834303700"
+}
+{
+key(14) = "6E6F746966792D6461656D6F6E00"
+data(24) = "3939322F3633383936333832333534373439333635393800"
+}
diff --git a/lib/tdb/test/test_tdbbackup.sh b/lib/tdb/test/test_tdbbackup.sh
index 8552ea1029b..7bc025ca42b 100755
--- a/lib/tdb/test/test_tdbbackup.sh
+++ b/lib/tdb/test/test_tdbbackup.sh
@@ -8,6 +8,7 @@ if [ $# -lt 1 ]; then
 fi
 
 LDBFILE=$1
+failed=0
 
 timestamp()
 {
@@ -42,16 +43,22 @@ testit()
 
 $BINDIR/tdbdump $LDBFILE | sort >orig_dump
 
-testit "normal tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak
+testit "normal tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak  \
+	|| failed=$((failed + 1))
 $BINDIR/tdbdump $LDBFILE.bak | sort >bak_dump
-testit "cmp between tdbdumps of original and backup" cmp orig_dump bak_dump
+testit "cmp between tdbdumps of original and backup" cmp orig_dump bak_dump \
+	|| failed=$((failed + 1))
 rm $LDBFILE.bak
 rm bak_dump
 
-testit "readonly tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak -r
+testit "readonly tdbbackup on tdb file" $BINDIR/tdbbackup $LDBFILE -s .bak -r \
+	|| failed=$((failed + 1))
 $BINDIR/tdbdump $LDBFILE.bak | sort >bak_dump
-testit "cmp between tdbdumps of original and back dbs" cmp orig_dump bak_dump
+testit "cmp between tdbdumps of original and back dbs" cmp orig_dump bak_dump \
+	|| failed=$((failed + 1))
 rm $LDBFILE.bak
 rm bak_dump
 
 rm orig_dump
+
+exit $failed
diff --git a/lib/tdb/test/test_tdbdump.sh b/lib/tdb/test/test_tdbdump.sh
new file mode 100755
index 00000000000..2849313e50c
--- /dev/null
+++ b/lib/tdb/test/test_tdbdump.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+# Test dumping of tdb database
+# Copyright (C) 2024 Christof Schmitt <cs at samba.org>
+
+if [ $# -lt 3 ]; then
+	echo "Usage: $0 TDB_FILE EXPECTED_DUMP EXPECTED_DUMP_X"
+	exit 1
+fi
+
+TDB_FILE=$1
+EXPECTED_DUMP=$2
+EXPECTED_DUMP_X=$3
+TEMP_DUMP=tempdump.txt
+
+failed=0
+
+timestamp()
+{
+	date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/'
+}
+
+subunit_fail_test()
+{
+	timestamp
+	printf 'failure: %s [\n' "$1"
+	cat -
+	echo "]"
+}
+
+testit()
+{
+	name="$1"
+	shift
+	cmdline="$@"
+	timestamp
+	printf 'test: %s\n' "$1"
+	output=$($cmdline 2>&1)
+	status=$?
+	if [ x$status = x0 ]; then
+		timestamp
+		printf 'success: %s\n' "$name"
+	else
+		echo "$output" | subunit_fail_test "$name"
+	fi
+	return $status
+}
+
+$BINDIR/tdbdump $TDB_FILE > $TEMP_DUMP
+testit "Verifying tdbdump" cmp $TEMP_DUMP $EXPECTED_DUMP \
+	|| failed=$(expr $failed + 1)
+
+$BINDIR/tdbdump -x $TDB_FILE > $TEMP_DUMP
+testit "Verifying tdbdump -x" cmp $TEMP_DUMP $EXPECTED_DUMP_X \
+	|| failed=$(expr $failed + 1)
+
+rm $TEMP_DUMP
+
+exit $failed
diff --git a/lib/tdb/tools/tdbdump.c b/lib/tdb/tools/tdbdump.c
index 9f1ab91fbec..f1ee56d17b7 100644
--- a/lib/tdb/tools/tdbdump.c
+++ b/lib/tdb/tools/tdbdump.c
@@ -24,12 +24,19 @@
 #include "system/wait.h"
 #include "tdb.h"
 
-static void print_data(TDB_DATA d)
+struct traverse_state {
+	bool hex_output;
+	const char *keyname;
+};
+
+static void print_data(TDB_DATA d, bool hex_output)
 {
 	unsigned char *p = (unsigned char *)d.dptr;
 	int len = d.dsize;
 	while (len--) {
-		if (isprint(*p) && !strchr("\"\\", *p)) {
+		if (hex_output) {
+			printf("%02X", *p);
+		} else if(isprint(*p) && !strchr("\"\\", *p)) {
 			fputc(*p, stdout);
 		} else {
 			printf("\\%02X", *p);
@@ -40,12 +47,14 @@ static void print_data(TDB_DATA d)
 
 static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
 {
+	struct traverse_state *traverse = state;
+
 	printf("{\n");
 	printf("key(%zu) = \"", key.dsize);
-	print_data(key);
+	print_data(key, traverse->hex_output);
 	printf("\"\n");
 	printf("data(%zu) = \"", dbuf.dsize);
-	print_data(dbuf);
+	print_data(dbuf, traverse->hex_output);
 	printf("\"\n");
 	printf("}\n");
 	return 0;
@@ -86,18 +95,21 @@ static void log_stderr(struct tdb_context *tdb, enum tdb_debug_level level,
 	va_end(ap);
 }
 
-static void emergency_walk(TDB_DATA key, TDB_DATA dbuf, void *keyname)
+static void emergency_walk(TDB_DATA key, TDB_DATA dbuf, void *state)
 {
-	if (keyname) {
-		if (key.dsize != strlen(keyname))
+	struct traverse_state *traverse = state;
+
+	if (traverse->keyname) {
+		if (key.dsize != strlen(traverse->keyname))
 			return;
-		if (memcmp(key.dptr, keyname, key.dsize) != 0)
+		if (memcmp(key.dptr, traverse->keyname, key.dsize) != 0)
 			return;
 	}
-	traverse_fn(NULL, key, dbuf, NULL);
+	traverse_fn(NULL, key, dbuf, traverse);
 }
 
-static int dump_tdb(const char *fname, const char *keyname, bool emergency)
+static int dump_tdb(const char *fname, const char *keyname,
+		    bool emergency, bool hex_output)
 {
 	TDB_CONTEXT *tdb;
 	TDB_DATA key, value;
@@ -120,10 +132,14 @@ static int dump_tdb(const char *fname, const char *keyname, bool emergency)
 	}
 
 	if (emergency) {
-		return tdb_rescue(tdb, emergency_walk, discard_const(keyname)) == 0;
+		struct traverse_state traverse =
+			{ .hex_output = hex_output,
+			  .keyname = keyname };
+		return tdb_rescue(tdb, emergency_walk, &traverse) == 0;
 	}
 	if (!keyname) {
-		return tdb_traverse(tdb, traverse_fn, NULL) == -1 ? 1 : 0;
+		struct traverse_state traverse = { .hex_output = hex_output };
+		return tdb_traverse(tdb, traverse_fn, &traverse) == -1 ? 1 : 0;
 	} else {
 		key.dptr = discard_const_p(uint8_t, keyname);
 		key.dsize = strlen(keyname);
@@ -131,7 +147,7 @@ static int dump_tdb(const char *fname, const char *keyname, bool emergency)
 		if (!value.dptr) {
 			return 1;
 		} else {
-			print_data(value);
+			print_data(value, hex_output);
 			free(value.dptr);
 		}
 	}
@@ -150,7 +166,7 @@ static void usage( void)
  int main(int argc, char *argv[])
 {
 	char *fname, *keyname=NULL;
-	bool emergency = false;
+	bool emergency = false, hex_output = false;
 	int c;
 
 	if (argc < 2) {
@@ -158,7 +174,7 @@ static void usage( void)
 		exit(1);
 	}
 
-	while ((c = getopt( argc, argv, "hk:e")) != -1) {
+	while ((c = getopt( argc, argv, "hk:ex")) != -1) {
 		switch (c) {
 		case 'h':
 			usage();
@@ -169,6 +185,9 @@ static void usage( void)
 		case 'e':
 			emergency = true;
 			break;
+		case 'x':
+			hex_output = true;
+			break;
 		default:
 			usage();
 			exit( 1);
@@ -177,5 +196,5 @@ static void usage( void)
 
 	fname = argv[optind];
 
-	return dump_tdb(fname, keyname, emergency);
+	return dump_tdb(fname, keyname, emergency, hex_output);
 }
diff --git a/lib/tdb/wscript b/lib/tdb/wscript
index 2c587fbee44..04121498723 100644
--- a/lib/tdb/wscript
+++ b/lib/tdb/wscript
@@ -216,7 +216,8 @@ def testonly(ctx):
         if not os.path.exists(link):
             os.symlink(ctx.path.make_node('test').abspath(), link)
 
-        sh_tests = ["test/test_tdbbackup.sh test/jenkins-be-hash.tdb"]
+        sh_tests = ["test/test_tdbbackup.sh test/jenkins-be-hash.tdb",
+                    "test/test_tdbdump.sh test/sample_tdb.tdb test/sample_tdb.txt test/sample_tdb_x.txt"]
 
         for sh_test in sh_tests:
             cmd = "BINDIR=%s %s" % (blddir, sh_test)


-- 
Samba Shared Repository



More information about the samba-cvs mailing list