Subject: Re: lib/13794: RES_OPTIONS=debug is broken due to res_init.o build issue
To: NetBSD GNATS submissions and followups <gnats-bugs@gnats.netbsd.org>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 08/27/2001 17:29:04
[ On Monday, August 27, 2001 at 10:14:43 (-0400), John Hawkinson wrote: ]
> Subject: lib/13794: RES_OPTIONS=debug is broken due to res_init.o build issue
>
> Conversly, changing the #ifdef DEBUG to #ifdef RES_DEBUG in res_init.c
> would probably complicate merging.

Not that much since such lines will rarely change in the vendor sources:

I've not had any conflicts needing manual resolution since I introduced
thse changes quite some time ago (since before the last resolver update).

(This patch also includes my "ALLOW_HOSTALIASES" patch which allows you
to permanently disable support for the HOSTALIASES env var; as well as a
few minor documentation tweaks.)

Index: Makefile.inc
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/Makefile.inc,v
retrieving revision 1.1.1.6
diff -c -r1.1.1.6 Makefile.inc
*** Makefile.inc	12 Jun 2001 21:12:26 -0000	1.1.1.6
--- Makefile.inc	13 Jun 2001 15:32:48 -0000
***************
*** 15,20 ****
--- 15,21 ----
  	res_mkquery.c res_query.c res_send.c send.c sethostent.c
  
  SRCS+=	__dn_comp.c __res_close.c __res_send.c _inet_aton.c _inet_pton.c
+ CPPFLAGS+=-DRESOLVDEBUG
  CPPFLAGS+=-DRESOLVSORT -I.
  
  # IPv6
Index: getaddrinfo.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/getaddrinfo.c,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 getaddrinfo.c
*** getaddrinfo.c	25 Mar 2001 06:24:28 -0000	1.1.1.3
--- getaddrinfo.c	7 May 2001 20:59:49 -0000
***************
*** 1696,1702 ****
  		type = t->qtype;
  		answer = t->answer;
  		anslen = t->anslen;
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query(%s, %d, %d)\n", name, class, type);
  #endif
--- 1696,1702 ----
  		type = t->qtype;
  		answer = t->answer;
  		anslen = t->anslen;
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query(%s, %d, %d)\n", name, class, type);
  #endif
***************
*** 1708,1714 ****
  			n = res_opt(n, buf, sizeof(buf), anslen);
  #endif
  		if (n <= 0) {
! #ifdef DEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";; res_query: mkquery failed\n");
  #endif
--- 1708,1714 ----
  			n = res_opt(n, buf, sizeof(buf), anslen);
  #endif
  		if (n <= 0) {
! #ifdef RESOLVDEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";; res_query: mkquery failed\n");
  #endif
***************
*** 1718,1724 ****
  		n = res_send(buf, n, answer, anslen);
  #if 0
  		if (n < 0) {
! #ifdef DEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";; res_query: send error\n");
  #endif
--- 1718,1724 ----
  		n = res_send(buf, n, answer, anslen);
  #if 0
  		if (n < 0) {
! #ifdef RESOLVDEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";; res_query: send error\n");
  #endif
***************
*** 1729,1735 ****
  
  		if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
  			rcode = hp->rcode;	/* record most recent error */
! #ifdef DEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";; rcode = %d, ancount=%d\n", hp->rcode,
  				    ntohs(hp->ancount));
--- 1729,1735 ----
  
  		if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
  			rcode = hp->rcode;	/* record most recent error */
! #ifdef RESOLVDEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";; rcode = %d, ancount=%d\n", hp->rcode,
  				    ntohs(hp->ancount));
***************
*** 1801,1811 ****
--- 1801,1813 ----
  	if (cp > name && *--cp == '.')
  		trailing_dot++;
  
+ #ifdef ALLOW_HOSTALIASES
  	/*
  	 * if there aren't any dots, it could be a user-level alias
  	 */
  	if (!dots && (cp = __hostalias(name)) != NULL)
  		return (res_queryN(cp, target));
+ #endif
  
  	/*
  	 * If there are dots in the name already, let's just give it a try
***************
*** 1931,1937 ****
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef DEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_querydomain(%s, %s)\n",
  			name, domain?domain:"<Nil>");
--- 1933,1939 ----
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef RESOLVDEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_querydomain(%s, %s)\n",
  			name, domain?domain:"<Nil>");
Index: gethnamaddr.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/gethnamaddr.c,v
retrieving revision 1.1.1.6
diff -c -r1.1.1.6 gethnamaddr.c
*** gethnamaddr.c	12 Jun 2001 21:12:27 -0000	1.1.1.6
--- gethnamaddr.c	13 Jun 2001 15:32:48 -0000
***************
*** 145,151 ****
      char ac;
  } align;
  
! #ifdef DEBUG
  static void dprintf __P((char *, ...))
  	__attribute__((__format__(__printf__, 1, 2)));
  #endif
--- 145,151 ----
      char ac;
  } align;
  
! #ifdef RESOLVDEBUG
  static void dprintf __P((char *, ...))
  	__attribute__((__format__(__printf__, 1, 2)));
  #endif
***************
*** 185,191 ****
  };
  
  
! #ifdef DEBUG
  static void
  dprintf(char *msg, ...)
  {
--- 185,191 ----
  };
  
  
! #ifdef RESOLVDEBUG
  static void
  dprintf(char *msg, ...)
  {
***************
*** 576,581 ****
--- 576,582 ----
  	host.h_addrtype = af;
  	host.h_length = size;
  
+ #ifdef ALLOW_HOSTALIASES
  	/*
  	 * if there aren't any dots, it could be a user-level alias.
  	 * this is also done in res_query() since we are not the only
***************
*** 583,588 ****
--- 584,590 ----
  	 */
  	if (!strchr(name, '.') && (cp = __hostalias(name)))
  		name = cp;
+ #endif
  
  	/*
  	 * disallow names consisting only of digits/dots, unless
Index: gethostbyname.3
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/gethostbyname.3,v
retrieving revision 1.1.1.6
diff -c -r1.1.1.6 gethostbyname.3
*** gethostbyname.3	12 Jun 2001 21:12:27 -0000	1.1.1.6
--- gethostbyname.3	13 Jun 2001 15:32:48 -0000
***************
*** 121,128 ****
  and
  .Fn gethostbyname2
  will search for the named host in the current domain and its parents
! unless the name ends in a dot.
! If the name contains no dot, and if the environment variable
  .Dq Ev HOSTALIASES
  contains the name of an alias file, the alias file will first be searched
  for an alias matching the input name.
--- 121,129 ----
  and
  .Fn gethostbyname2
  will search for the named host in the current domain and its parents
! unless the name ends in a dot.  If the name contains no dot, and if
! support for the following feature has been compiled into the system (it
! is not by default), and if the environment variable
  .Dq Ev HOSTALIASES
  contains the name of an alias file, the alias file will first be searched
  for an alias matching the input name.
Index: getnameinfo.3
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/getnameinfo.3,v
retrieving revision 1.1.1.4
diff -c -r1.1.1.4 getnameinfo.3
*** getnameinfo.3	12 Jun 2001 21:12:28 -0000	1.1.1.4
--- getnameinfo.3	13 Jun 2001 15:32:48 -0000
***************
*** 261,266 ****
--- 261,267 ----
  .El
  .\"
  .Sh SEE ALSO
+ .Xr gai_strerror 3 ,
  .Xr getaddrinfo 3 ,
  .Xr gethostbyaddr 3 ,
  .Xr getservbyport 3 ,
Index: getnetnamadr.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/getnetnamadr.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 getnetnamadr.c
*** getnetnamadr.c	25 Mar 2001 06:24:30 -0000	1.1.1.5
--- getnetnamadr.c	7 May 2001 21:00:25 -0000
***************
*** 319,325 ****
  	anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)(void *)&buf,
  	    sizeof(buf));
  	if (anslen < 0) {
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf("res_query failed\n");
  #endif
--- 319,325 ----
  	anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)(void *)&buf,
  	    sizeof(buf));
  	if (anslen < 0) {
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf("res_query failed\n");
  #endif
***************
*** 424,430 ****
  	anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)(void *)&buf,
  	    sizeof(buf));
  	if (anslen < 0) {
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf("res_query failed\n");
  #endif
--- 424,430 ----
  	anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)(void *)&buf,
  	    sizeof(buf));
  	if (anslen < 0) {
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf("res_query failed\n");
  #endif
Index: inet.3
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/inet.3,v
retrieving revision 1.1.1.4
diff -c -r1.1.1.4 inet.3
*** inet.3	25 Mar 2001 06:24:35 -0000	1.1.1.4
--- inet.3	25 Mar 2001 20:34:41 -0000
***************
*** 115,120 ****
--- 115,121 ----
  functions return numbers suitable for use
  as Internet addresses and Internet network
  numbers, respectively.
+ The return values of both functions are in network byte order.
  .Pp
  The function
  .Fn inet_ntop
***************
*** 151,160 ****
  break apart Internet host addresses, returning the network number and
  local network address part, respectively (both in host order).
  .Pp
! All Internet addresses are returned in network
! order (bytes ordered from left to right).
  All network numbers and local address parts are
  returned as machine format integer values.
  .Sh INTERNET ADDRESSES (IP VERSION 4)
  Values specified using the
  .Qq dotted quad
--- 152,165 ----
  break apart Internet host addresses, returning the network number and
  local network address part, respectively (both in host order).
  .Pp
! All Internet addresses (in
! .Ft struct in_addr
! form) are in network byte order (bytes ordered with the most significant
! byte from left to right, i.e. big endian, i.e. 4321).
! .Pp
  All network numbers and local address parts are
  returned as machine format integer values.
+ .\"
  .Sh INTERNET ADDRESSES (IP VERSION 4)
  Values specified using the
  .Qq dotted quad
Index: res_debug.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/res_debug.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 res_debug.c
*** res_debug.c	25 Mar 2001 06:24:43 -0000	1.1.1.5
--- res_debug.c	26 Mar 2001 00:29:15 -0000
***************
*** 1086,1091 ****
--- 1086,1097 ----
  	case RES_DNSRCH:	return "dnsrch";
  	case RES_INSECURE1:	return "insecure1";
  	case RES_INSECURE2:	return "insecure2";
+ #ifdef ALLOW_HOSTALIASES
+ 	case RES_NOALIASES:	return "noaliases";
+ #else
+ 	case RES_NOALIASES:	return "noaliases(always)";
+ #endif
+ 	case RES_USE_INET6:	return "inet6";
  #ifdef RES_USE_EDNS0
  	case RES_USE_EDNS0:	return "edns0";
  #endif
Index: res_init.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/res_init.c,v
retrieving revision 1.1.1.6
diff -c -r1.1.1.6 res_init.c
*** res_init.c	25 Mar 2001 06:24:43 -0000	1.1.1.6
--- res_init.c	7 May 2001 21:00:59 -0000
***************
*** 494,507 ****
  			dots--;
  		}
  		*pp = NULL;
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG) {
  			printf(";; res_init()... default dnsrch list:\n");
  			for (pp = _res.dnsrch; *pp; pp++)
  				printf(";;\t%s\n", *pp);
  			printf(";;\t..END..\n");
  		}
! #endif /* DEBUG */
  #endif /* !RFC1535 */
  	}
  
--- 494,507 ----
  			dots--;
  		}
  		*pp = NULL;
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG) {
  			printf(";; res_init()... default dnsrch list:\n");
  			for (pp = _res.dnsrch; *pp; pp++)
  				printf(";;\t%s\n", *pp);
  			printf(";;\t..END..\n");
  		}
! #endif /* RESOLVDEBUG */
  #endif /* !RFC1535 */
  	}
  
***************
*** 522,528 ****
  	_DIAGASSERT(options != NULL);
  	_DIAGASSERT(source != NULL);
  
! #ifdef DEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_setoptions(\"%s\", \"%s\")...\n",
  		       options, source);
--- 522,528 ----
  	_DIAGASSERT(options != NULL);
  	_DIAGASSERT(source != NULL);
  
! #ifdef RESOLVDEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_setoptions(\"%s\", \"%s\")...\n",
  		       options, source);
***************
*** 538,549 ****
  				_res.ndots = i;
  			else
  				_res.ndots = RES_MAXNDOTS;
! #ifdef DEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";;\tndots=%d\n", _res.ndots);
  #endif
  		} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
! #ifdef DEBUG
  			if (!(_res.options & RES_DEBUG)) {
  				printf(";; res_setoptions(\"%s\", \"%s\")..\n",
  				       options, source);
--- 538,549 ----
  				_res.ndots = i;
  			else
  				_res.ndots = RES_MAXNDOTS;
! #ifdef RESOLVDEBUG
  			if (_res.options & RES_DEBUG)
  				printf(";;\tndots=%d\n", _res.ndots);
  #endif
  		} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
! #ifdef RESOLVDEBUG
  			if (!(_res.options & RES_DEBUG)) {
  				printf(";; res_setoptions(\"%s\", \"%s\")..\n",
  				       options, source);
Index: res_mkquery.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/res_mkquery.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 res_mkquery.c
*** res_mkquery.c	25 Mar 2001 06:24:44 -0000	1.1.1.5
--- res_mkquery.c	7 May 2001 21:01:21 -0000
***************
*** 110,116 ****
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef DEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_mkquery(%d, %s, %d, %d)\n",
  		       op, dname, class, type);
--- 110,116 ----
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef RESOLVDEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_mkquery(%d, %s, %d, %d)\n",
  		       op, dname, class, type);
***************
*** 121,127 ****
  	/*CONSTCOND*/
  	if (sizeof(HEADER) != HFIXEDSZ) {
  		/* XXX should raise compile time error, not runtime error */
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; HFIXEDSZ mismatch with sizeof(HEADER)\n");
  #endif
--- 121,127 ----
  	/*CONSTCOND*/
  	if (sizeof(HEADER) != HFIXEDSZ) {
  		/* XXX should raise compile time error, not runtime error */
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; HFIXEDSZ mismatch with sizeof(HEADER)\n");
  #endif
Index: res_query.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/res_query.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 res_query.c
*** res_query.c	25 Mar 2001 06:24:44 -0000	1.1.1.5
--- res_query.c	7 May 2001 21:01:39 -0000
***************
*** 124,130 ****
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef DEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_query(%s, %d, %d)\n", name, class, type);
  #endif
--- 124,130 ----
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef RESOLVDEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_query(%s, %d, %d)\n", name, class, type);
  #endif
***************
*** 136,142 ****
  		n = res_opt(n, buf, sizeof(buf), anslen);
  #endif
  	if (n <= 0) {
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: mkquery failed\n");
  #endif
--- 136,142 ----
  		n = res_opt(n, buf, sizeof(buf), anslen);
  #endif
  	if (n <= 0) {
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: mkquery failed\n");
  #endif
***************
*** 145,151 ****
  	}
  	n = res_send(buf, n, answer, anslen);
  	if (n < 0) {
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: send error\n");
  #endif
--- 145,151 ----
  	}
  	n = res_send(buf, n, answer, anslen);
  	if (n < 0) {
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: send error\n");
  #endif
***************
*** 154,160 ****
  	}
  
  	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
! #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; rcode = %d, ancount=%d\n", hp->rcode,
  			    ntohs(hp->ancount));
--- 154,160 ----
  	}
  
  	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
! #ifdef RESOLVDEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; rcode = %d, ancount=%d\n", hp->rcode,
  			    ntohs(hp->ancount));
***************
*** 217,227 ****
--- 217,229 ----
  	if (cp > name && *--cp == '.')
  		trailing_dot++;
  
+ #ifdef ALLOW_HOSTALIASES
  	/*
  	 * if there aren't any dots, it could be a user-level alias
  	 */
  	if (!dots && (cp = __hostalias(name)) != NULL)
  		return (res_query(cp, class, type, answer, anslen));
+ #endif
  
  	/*
  	 * If there are dots in the name already, let's just give it a try
***************
*** 351,357 ****
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef DEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_querydomain(%s, %s, %d, %d)\n",
  			name, domain?domain:"<Nil>", class, type);
--- 353,359 ----
  		h_errno = NETDB_INTERNAL;
  		return (-1);
  	}
! #ifdef RESOLVDEBUG
  	if (_res.options & RES_DEBUG)
  		printf(";; res_querydomain(%s, %s, %d, %d)\n",
  			name, domain?domain:"<Nil>", class, type);
***************
*** 383,388 ****
--- 385,391 ----
  	return (res_query(longname, class, type, answer, anslen));
  }
  
+ #ifdef ALLOW_HOSTALIASES
  const char *
  __hostalias(name)
  	const char *name;
***************
*** 440,442 ****
--- 443,446 ----
  	(void)fclose(fp);
  	return (NULL);
  }
+ #endif
Index: res_send.c
===================================================================
RCS file: /cvs/NetBSD/src/lib/libc/net/res_send.c,v
retrieving revision 1.1.1.5
diff -c -r1.1.1.5 res_send.c
*** res_send.c	25 Mar 2001 06:24:44 -0000	1.1.1.5
--- res_send.c	7 May 2001 21:02:20 -0000
***************
*** 117,123 ****
  
  #define CAN_RECONNECT 1
  
! #ifndef DEBUG
  #   define Dprint(cond, args) /*empty*/
  #   define DprintQ(cond, args, query, size) /*empty*/
  #   define Aerror(file, string, error, address) /*empty*/
--- 117,123 ----
  
  #define CAN_RECONNECT 1
  
! #ifndef RESOLVDEBUG
  #   define Dprint(cond, args) /*empty*/
  #   define DprintQ(cond, args, query, size) /*empty*/
  #   define Aerror(file, string, error, address) /*empty*/


-- 
							Greg A. Woods

+1 416 218-0098      VE3TCP      <gwoods@acm.org>     <woods@robohack.ca>
Planix, Inc. <woods@planix.com>;   Secrets of the Weird <woods@weird.com>