From greg@greg.rim.or.jp  Sun Jul  9 02:35:32 1995
Received: from news.rim.or.jp (news.rim.or.jp [202.255.181.3])
          by freefall.cdrom.com (8.6.10/8.6.6) with ESMTP id CAA25084
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 9 Jul 1995 02:35:31 -0700
Received: (from uucp@localhost) by news.rim.or.jp (8.6.10+2.4W/3.3W-rim1.0) with UUCP id SAA11537 for FreeBSD-gnats-submit@freebsd.org; Sun, 9 Jul 1995 18:35:29 +0900
Received: from apollon.greg.rim.or.jp (apollon.greg.rim.or.jp [172.31.1.2]) by atena.greg.rim.or.jp (8.6.11/3.3Wb-uucp-sendmail-master-Ver-0.1-Beta) with ESMTP id QAA14696 for <FreeBSD-gnats-submit@freebsd.org>; Sun, 9 Jul 1995 16:27:00 +0900
Received: by apollon.greg.rim.or.jp (8.6.11/3.3Wb-uucp-sendmail-slave-Ver-0.1-Beta)
	id QAA07015; Sun, 9 Jul 1995 16:26:58 +0900
Message-Id: <199507090726.QAA07015@apollon.greg.rim.or.jp>
Date: Sun, 9 Jul 1995 16:26:58 +0900
From: greg@greg.rim.or.jp
Reply-To: greg@greg.rim.or.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject:
X-Send-Pr-Version: 3.2

>Number:         605
>Category:       misc
>Synopsis:       NIS: get*bynis routine problems
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    wpaul
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul  9 02:40:02 1995
>Closed-Date:    Sat Feb 5 04:31:55 PST 2000
>Last-Modified:  Sat Feb  5 04:33:38 PST 2000
>Originator:     Kensaku Masuda
>Release:        FreeBSD 2.0.5-RELEASE i386
>Organization:
// $BA}ED(B  $B7r:n(B greg@greg.rim.or.jp                  ////
    //             greg@apt.fxis.fujixerox.co.jp         //
   //  $BBg%P%0$OJb$$$FMh$J$$!"$@$+$iDY$7$K9T$/$s$@$M!*(B   //
  //// $B0lF|0l8D!";0F|$G;08D!";08DDY$7$FFs8D%P%0$k(B      //
>Environment:

	    At using NIS without DNS, /etc/hosts and/or /etc/networks
	has no entries without myself. But NIS map have them.

	ex)
		/etc/hosts
			127.0.0.1	localhost
			WWW.XXX.YYY.ZZ0	myname.mydomain myname

		/etc/networks
			loopback	127
			localnet	WWW.XXX.YYY

		hosts.byaddr
			127.0.0.1		localhost
			WWW.XXX.YYY.ZZ0		myname.mydomain	myname
			WWW.XXX,YYY.ZZ1		friend.mydomain	friend

		networks.byaddr
			mydomain	WWW.XXX.YYY
			loopback	127
			multicast	224

>Description:

	    Building a query problem with NIS in standard C library.

>How-To-Repeat:

	    Use NIS without DNS. and query not in the /etc/hosts.
	for example "netstat -r" / "ping unknwon.host.in.hosts" etc etc.......

>Fix:
	
diff -rc net.original/gethostbynis.c net/gethostbynis.c
*** net.original/gethostbynis.c	Sun Jul  9 15:41:15 1995
--- net/gethostbynis.c	Sun Jul  9 14:59:47 1995
***************
*** 111,115 ****
  _gethostbynisaddr(name)
  	char *name;
  {
! 	return _gethostbynis(name, "hosts.byaddr");
  }
--- 111,120 ----
  _gethostbynisaddr(name)
  	char *name;
  {
! 	static char buffer[64];
! 	unsigned char *tmp;
! 
! 	tmp = (unsigned char *)name;
! 	sprintf(buffer, "%u.%u.%u.%u", tmp[0], tmp[1], tmp[2], tmp[3]);
! 	return _gethostbynis(buffer, "hosts.byaddr");
  }
Only in net: gethostbynis.c.original
diff -rc net.original/getnetbynis.c net/getnetbynis.c
*** net.original/getnetbynis.c	Sun Jul  9 15:41:15 1995
--- net/getnetbynis.c	Sun Jul  9 15:32:26 1995
***************
*** 118,133 ****
  	struct in_addr in;
  	char *str, *cp;
  	struct netent *np;
  
  	if (type != AF_INET)
  		return (NULL);
  
! 	in.s_addr = addr;
  	str = inet_ntoa(in);
! 	cp = str + strlen(str) - 2;
! 	while(!strcmp(cp, ".0")) {
! 		*cp = '\0';
! 		cp = str + strlen(str) - 2;
  	}
  
  	return _getnetbynis(str, "networks.byaddr");
--- 118,148 ----
  	struct in_addr in;
  	char *str, *cp;
  	struct netent *np;
+ 	unsigned char name[4];
+ 	unsigned char tmp[4];
  
  	if (type != AF_INET)
  		return (NULL);
  
! 	/*
! 	 * It's a quick hack, please rewrite into a beautifully.
! 	 * By Kensaku Masuda <greg@greg.rim.or.jp> 1995/07/09
! 	 */
! 	memcpy(tmp, &addr, sizeof(tmp));
! 	name[3] = tmp[2];
! 	name[2] = tmp[1];
! 	name[1] = tmp[0];
! 	name[0] = tmp[3];
! 	in.s_addr = name[0] << 24 | name[1] << 16 | name[2] << 8 | name[3];
  	str = inet_ntoa(in);
! 	for(cp = str + strlen(str) ; str != cp ; cp--) {
! 		if(*cp == '.') {
! 			if(strcmp(cp, ".0") == 0) {
! 				*cp = 0;
! 			} else {
! 				break;
! 			}
! 		}
  	}
  
  	return _getnetbynis(str, "networks.byaddr");

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->wpaul 
Responsible-Changed-By: scrappy 
Responsible-Changed-When: Sun May 26 16:31:26 PDT 1996 
Responsible-Changed-Why:  
last major change to some of the get*bynis functions...patch included 

From: Jeroen Ruigrok/Asmodai <asmodai@wxs.nl>
To: FreeBSD Gnats <freebsd-gnats-submit@freebsd.org>,
	wpaul@freebsd.org
Cc:  
Subject: Re: misc/605: NIS: get*bynis routine problems
Date: Sat, 6 Nov 1999 12:05:54 +0100

 This PR describes the problems of resolving hosts which aren't in
 /etc/hosts but which should be pingable or viewable in netstat -r if
 propogated by means of NIS.
 
 Using a 3.3-STABLE client and a 3.2-STABLE server:
 
 /etc/hosts only details the server
 
 try to ping another host like my own machine from the NIS client:
 
 bash-2.03# ping lucifer
 PING lucifer.bart.nl (194.158.168.74): 56 data bytes
 ping: sendto: No route to host
 ping: sendto: No route to host
 
 The sendto failures are due to my host being an official addressed one
 and the client being on a private space IP network.  But the resolving
 works.
 
 Now for a private space companion host:
 
 bash-2.03# ping idun10
 PING idun10 (10.0.170.118): 56 data bytes
 64 bytes from 10.0.170.118: icmp_seq=0 ttl=255 time=0.174 ms
 64 bytes from 10.0.170.118: icmp_seq=1 ttl=255 time=0.152 ms
 
 bash-2.03# ping hermod10
 PING hermod10 (10.0.170.122): 56 data bytes
 64 bytes from 10.0.170.122: icmp_seq=0 ttl=255 time=0.163 ms
 64 bytes from 10.0.170.122: icmp_seq=1 ttl=255 time=0.154 ms
 
 bash-2.03# netstat -r
 Routing tables
 
 Internet:
 Destination        Gateway            Flags     Refs     Use     Netif Expire
 10                 link#1             UC          0        0     fxp0
 10.0.170.11        0:90:27:8f:8d:67   UHLW        1      632     fxp0    996
 idun10             0:90:27:90:1b:d2   UHLW        1      657     fxp0   1197
 hermod10           0:90:27:8f:8b:1c   UHLW        0        4     fxp0    400
 bragi10            0:90:27:8f:8e:9e   UHLW        2     3262      lo0
 10.255.255.255     ff:ff:ff:ff:ff:ff  UHLWb       0        2     fxp0
 localhost          localhost          UH          0     6386      lo0
 
 The /etc/host.conf order is hosts, nis, bind
 
 The only hosts in /etc/hosts are bragi10 and idun10
 
 So it appears that this has been fixed at least since 3.2-STABLE from August.
 I have no means to test lower versions at the moment.
 
 -- 
 Jeroen Ruigrok van der Werven/Asmodai                  asmodai(at)wxs.nl
 The BSD Programmer's Documentation Project <http://home.wxs.nl/~asmodai>
 Network/Security Specialist        BSD: Technical excellence at its best
 There are 3 kinds of lies: lies, damned lies, and statistics.
 
State-Changed-From-To: open->closed 
State-Changed-By: asmodai 
State-Changed-When: Sat Feb 5 04:31:55 PST 2000 
State-Changed-Why:  
As the audit-trail shows, I verified the workings of this since 3.2-S 
of August 1999. 
>Unformatted:


