Cosmetic fixes for root AXFR

Andris Kalnozols andris at hpl.hp.com
Mon Feb 21 22:04:42 UTC 2000


Dig and nslookup malform the $ORIGIN directive and initial SOA RR
when displaying a transfer of the root zone.  Also, the trailing
dot is being unnecessarily appended to the owner and RDATA fields
in this context.  Here are the suggested patches.

Andris Kalnozols
HP Laboratories


--- src/bin/dig/dig.c.orig	Thu Nov  4 21:05:14 1999
+++ src/bin/dig/dig.c	Mon Feb 21 12:21:06 2000
@@ -1570,8 +1570,12 @@
 		}
 		name = ns_rr_name(rr);
 		if (origin[0] == '\0' && name[0] != '\0') {
-			fprintf(file, "$ORIGIN %s.\n", name);
-			strcpy(origin, name);
+			if (strcmp(name, ".") != 0)
+				strcpy(origin, name);
+			fprintf(file, "$ORIGIN %s.\n", origin);
+			if (strcmp(name, ".") == 0)
+				strcpy(origin, name);
+			strcpy(name_ctx, "@");
 		}
 		if (ns_sprintrr(&handle, &rr, name_ctx, origin,
 				buf, sizeof buf) < 0) {
--- src/bin/nslookup/list.c.orig	Fri Oct 15 12:49:08 1999
+++ src/bin/nslookup/list.c	Mon Feb 21 10:25:52 2000
@@ -422,8 +422,12 @@
 			}
 			name = ns_rr_name(rr);
 			if (origin[0] == '\0' && name[0] != '\0') {
-				fprintf(filePtr, "$ORIGIN %s.\n", name);
-				strcpy(origin, name);
+				if (strcmp(name, ".") != 0)
+					strcpy(origin, name);
+				fprintf(filePtr, "$ORIGIN %s.\n", origin);
+				if (strcmp(name, ".") == 0)
+					strcpy(origin, name);
+				strcpy(name_ctx, "@");
 			}
 			if (qtype == T_ANY || ns_rr_type(rr) == qtype) {
 				if (ns_sprintrr(&handle, &rr, name_ctx, origin,
--- src/lib/nameser/ns_print.c.orig	Mon Oct 18 19:06:54 1999
+++ src/lib/nameser/ns_print.c	Sun Feb 20 15:06:57 2000
@@ -127,9 +127,10 @@
 			T(addstr("@\t\t\t", 4, &buf, &buflen));
 		} else {
 			T(addstr(name, len, &buf, &buflen));
-			/* Origin not used and no trailing dot? */
-			if ((!origin || !origin[0] || name[len] == '\0') &&
-			    name[len - 1] != '.') {
+			/* Origin not used or not root, and no trailing dot? */
+			if (((origin == NULL || origin[0] == '\0') ||
+			    (origin[0] != '.' && origin[1] != '\0' &&
+			    name[len] == '\0')) && name[len - 1] != '.') {
 				T(addstr(".", 1, &buf, &buflen));
 				len++;
 			}
@@ -751,20 +752,22 @@
 	if (n < 0)
 		goto enospc;	/* Guess. */
 	newlen = prune_origin(*buf, origin);
-	if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') &&
-	    (newlen == 0 || (*buf)[newlen - 1] != '.')) {
-		/* No trailing dot. */
-		if (newlen + 2 > *buflen)
-			goto enospc;	/* No room for ".\0". */
-		(*buf)[newlen++] = '.';
-		(*buf)[newlen] = '\0';
-	}
 	if (newlen == 0) {
 		/* Use "@" instead of name. */
 		if (newlen + 2 > *buflen)
 			goto enospc;        /* No room for "@\0". */
 		(*buf)[newlen++] = '@';
 		(*buf)[newlen] = '\0';
+	} else {
+		if (((origin == NULL || origin[0] == '\0') ||
+		    (origin[0] != '.' && origin[1] != '\0' &&
+		    (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') {
+			/* No trailing dot. */
+			if (newlen + 2 > *buflen)
+				goto enospc;	/* No room for ".\0". */
+			(*buf)[newlen++] = '.';
+			(*buf)[newlen] = '\0';
+		}
 	}
 	*pp += n;
 	addlen(newlen, buf, buflen);



More information about the bind-workers mailing list