Support for getting the tdbload right

Rusty Russell rusty at rustcorp.com.au
Thu Sep 23 20:50:13 MDT 2010


On Wed, 22 Sep 2010 12:12:14 pm Matthieu Patou wrote:
>   Hi Rusty,
> 
> I come to you to see if you can help me to fix the tdbload (that is 
> currently called tdbundump) program.

Trivial parsing error.  Looks like the format of tdb dump changed to include
the length in brackets.  This patch fixes it to accept either the old or new
formats.

Hope this helps!
Rusty.

diff --git a/lib/tdb/tools/tdbundump.c b/lib/tdb/tools/tdbundump.c
index a20c011..c8a1988 100644
--- a/lib/tdb/tools/tdbundump.c
+++ b/lib/tdb/tools/tdbundump.c
@@ -58,7 +58,17 @@ static int append(TDB_DATA *x, size_t *size, int c)
 	return 0;
 }
 
-static int skip_over(const char *str) {
+static int swallow_optlen(void)
+{
+	int c;
+	do {
+		c = getchar();
+	} while (isdigit(c));
+	return c;
+}
+
+static int skip_over(const char *str, bool opt_len)
+{
 	unsigned int i;
 	int c;
 	for (i = 0; i < strlen(str); i++) {
@@ -67,6 +77,14 @@ static int skip_over(const char *str) {
 			return EOF;
 		}
 		if (c != str[i]) {
+			if (opt_len && c == '(') {
+				c = swallow_optlen();
+				if (c == ')') {
+					/* OK, *now* we expect the rest. */
+					i--;
+					continue;
+				}
+			}
 			fprintf(stderr, "Expected char 0x%x, saw 0x%x\n", str[i], c);
 			return 1;
 		}
@@ -152,7 +170,7 @@ static int undump_tdb(const char *fname)
 	while (1) {
 		key.dsize = 0;
 		data.dsize = 0;
-		i = skip_over(before);
+		i = skip_over(before, true);
 		if (i == EOF) {
 			if (tdb_close(tdb)) {
 				fprintf(stderr, "Error closing tdb\n");
@@ -166,14 +184,14 @@ static int undump_tdb(const char *fname)
 		if (read_data(&key, &keysize) != 0) {
 			return 1;
 		}
-		if (skip_over(between) != 0) {
+		if (skip_over(between, true) != 0) {
 			fprintf(stderr, "Error or EOF\n");
 			return 1;
 		}
 		if (read_data(&data, &datasize) != 0) {
 			return 1;
 		}
-		if (skip_over(after) != 0) {
+		if (skip_over(after, false) != 0) {
 			fprintf(stderr, "Error or EOF\n");
 			return 1;
 		}


More information about the samba-technical mailing list