Subject: lib/libc/net/rcmd.c: solaris compatibility
To: None <tech-net@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-net
Date: 02/23/2000 01:44:15
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <15468.951237847.1@coconut.itojun.org>
Content-Transfer-Encoding: 7bit

	I was asked about "solaris compatibility" (support platform without
	sa_len) for src/lib/libc/net/rcmd.c.  I'm happy to do that, but this
	would need function prototype change to visible functions, which
	usually means (1) backward compat function or (2) libc shlib major
	bump.

	The situation here is like this:
	- The functions are not globally declared (they are not static, but
	  function signatures are not in headers, name starts with underbars).
	- The functions are introduced very recently (maybe 1 month?)
	- They are not very standard
	What is the right way here?
	(0) don't change it
	(1) just commit it
	(2) supply backward compat function
	(3) libc shlib major bump

itojun

------- =_aaaaaaaaaa0
Content-Type: message/rfc822

To: Bernd.Ernesti@xlink.net (Bernd Ernesti)
In-reply-to: Bernd.Ernesti's message of Tue, 22 Feb 2000 12:20:59 +0100.
      <200002221121.MAA12837@oban.xlink.net>
Subject: Re: Changes in the NetBSD libc/net/rcmd.c breaks zoularis
From: itojun@iijlab.net
Date: Tue, 22 Feb 2000 23:23:34 +0900
Message-ID: <13338.951229414@coconut.itojun.org>
Sender: itojun@coconut.itojun.org


>> 	I see, I'll try to check those.  Basically I need to make it
>> 	compile on platforms without sa_len/sin_len, am I correct?
>I think so.

	Oh my... I need to change ABI if I would like to address this...
	this will need major version bump for libc....
	(need to pass "salen" separately from sockaddr)

itojun


Index: rcmd.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/net/rcmd.c,v
retrieving revision 1.39
diff -c -r1.39 rcmd.c
*** rcmd.c	2000/02/18 04:16:54	1.39
--- rcmd.c	2000/02/22 14:21:54
***************
*** 78,91 ****
  int	orcmd_af __P((char **, u_int, const char *, const char *, const char *,
  	    int *, int));
  int	__ivaliduser __P((FILE *, u_int32_t, const char *, const char *));
! int	__ivaliduser_sa __P((FILE *, struct sockaddr *, const char *,
  	    const char *));
  static	int rshrcmd __P((char **, u_int32_t, const char *, const char *,
  	    const char *, int *, const char *));
  static	int resrcmd __P((struct addrinfo *, char **, u_int32_t, const char *,
  	    const char *, const char *, int *));
! static	int __icheckhost __P((struct sockaddr *, const char *));
! static	char *__gethostloop __P((struct sockaddr *));
  
  int
  rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
--- 78,91 ----
  int	orcmd_af __P((char **, u_int, const char *, const char *, const char *,
  	    int *, int));
  int	__ivaliduser __P((FILE *, u_int32_t, const char *, const char *));
! int	__ivaliduser_sa __P((FILE *, struct sockaddr *, socklen_t, const char *,
  	    const char *));
  static	int rshrcmd __P((char **, u_int32_t, const char *, const char *,
  	    const char *, int *, const char *));
  static	int resrcmd __P((struct addrinfo *, char **, u_int32_t, const char *,
  	    const char *, const char *, int *));
! static	int __icheckhost __P((struct sockaddr *, socklen_t, const char *));
! static	char *__gethostloop __P((struct sockaddr *, socklen_t));
  
  int
  rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
***************
*** 637,643 ****
--- 637,645 ----
  
  	memset(&sin, 0, sizeof(sin));
  	sin.sin_family = AF_INET;
+ #ifdef BSD4_4
  	sin.sin_len = sizeof(struct sockaddr_in);
+ #endif
  	memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr));
  	return iruserok_sa(&sin, sizeof(struct sockaddr_in), superuser, luser,
  		    ruser);
***************
*** 669,683 ****
  	_DIAGASSERT(luser != NULL);
  
  	sa = (struct sockaddr *)raddr;
- #ifdef lint
- 	rlen = rlen;
- #endif
  
  	first = 1;
  	hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r");
  again:
  	if (hostf) {
! 		if (__ivaliduser_sa(hostf, sa, luser, ruser) == 0) {
  			(void)fclose(hostf);
  			return (0);
  		}
--- 671,682 ----
  	_DIAGASSERT(luser != NULL);
  
  	sa = (struct sockaddr *)raddr;
  
  	first = 1;
  	hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r");
  again:
  	if (hostf) {
! 		if (__ivaliduser_sa(hostf, sa, rlen, luser, ruser) == 0) {
  			(void)fclose(hostf);
  			return (0);
  		}
***************
*** 748,762 ****
  
  	memset(&sin, 0, sizeof(sin));
  	sin.sin_family = AF_INET;
  	sin.sin_len = sizeof(struct sockaddr_in);
  	memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr));
! 	return __ivaliduser_sa(hostf, (struct sockaddr *)&sin, luser, ruser);
  }
  
  int
! __ivaliduser_sa(hostf, raddr, luser, ruser)
  	FILE *hostf;
  	struct sockaddr *raddr;
  	const char *luser, *ruser;
  {
  	register char *user, *p;
--- 747,765 ----
  
  	memset(&sin, 0, sizeof(sin));
  	sin.sin_family = AF_INET;
+ #ifdef BSD4_4
  	sin.sin_len = sizeof(struct sockaddr_in);
+ #endif
  	memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr));
! 	return __ivaliduser_sa(hostf, (struct sockaddr *)&sin,
! 	    sizeof(struct sockaddr_in), luser, ruser);
  }
  
  int
! __ivaliduser_sa(hostf, raddr, salen, luser, ruser)
  	FILE *hostf;
  	struct sockaddr *raddr;
+ 	socklen_t salen;
  	const char *luser, *ruser;
  {
  	register char *user, *p;
***************
*** 812,818 ****
  
  			case '@':
  				if (firsttime) {
! 					rhost = __gethostloop(raddr);
  					firsttime = 0;
  				}
  				if (rhost)
--- 815,821 ----
  
  			case '@':
  				if (firsttime) {
! 					rhost = __gethostloop(raddr, salen);
  					firsttime = 0;
  				}
  				if (rhost)
***************
*** 823,829 ****
  				break;
  
  			default:
! 				hostok = __icheckhost(raddr, &ahost[1]);
  				break;
  			}
  		else if (ahost[0] == '-')
--- 826,832 ----
  				break;
  
  			default:
! 				hostok = __icheckhost(raddr, salen, &ahost[1]);
  				break;
  			}
  		else if (ahost[0] == '-')
***************
*** 834,840 ****
  
  			case '@':
  				if (firsttime) {
! 					rhost = __gethostloop(raddr);
  					firsttime = 0;
  				}
  				if (rhost)
--- 837,843 ----
  
  			case '@':
  				if (firsttime) {
! 					rhost = __gethostloop(raddr, salen);
  					firsttime = 0;
  				}
  				if (rhost)
***************
*** 845,855 ****
  				break;
  
  			default:
! 				hostok = -__icheckhost(raddr, &ahost[1]);
  				break;
  			}
  		else
! 			hostok = __icheckhost(raddr, ahost);
  
  
  		if (auser[0] == '+')
--- 848,858 ----
  				break;
  
  			default:
! 				hostok = -__icheckhost(raddr, salen, &ahost[1]);
  				break;
  			}
  		else
! 			hostok = __icheckhost(raddr, salen, ahost);
  
  
  		if (auser[0] == '+')
***************
*** 908,915 ****
   * if af == AF_INET6.
   */
  static int
! __icheckhost(raddr, lhost)
  	struct sockaddr *raddr;
  	const char *lhost;
  {
  	struct addrinfo hints, *res, *r;
--- 911,919 ----
   * if af == AF_INET6.
   */
  static int
! __icheckhost(raddr, salen, lhost)
  	struct sockaddr *raddr;
+ 	socklen_t salen;
  	const char *lhost;
  {
  	struct addrinfo hints, *res, *r;
***************
*** 925,931 ****
  	_DIAGASSERT(lhost != NULL);
  
  	h1[0] = '\0';
! 	if (getnameinfo(raddr, raddr->sa_len, h1, sizeof(h1), NULL, 0,
  	    niflags) != 0)
  		return (0);
  
--- 929,935 ----
  	_DIAGASSERT(lhost != NULL);
  
  	h1[0] = '\0';
! 	if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0,
  	    niflags) != 0)
  		return (0);
  
***************
*** 966,973 ****
   * if af == AF_INET6.
   */
  static char *
! __gethostloop(raddr)
  	struct sockaddr *raddr;
  {
  	static char remotehost[NI_MAXHOST];
  	char h1[NI_MAXHOST], h2[NI_MAXHOST];
--- 970,978 ----
   * if af == AF_INET6.
   */
  static char *
! __gethostloop(raddr, salen)
  	struct sockaddr *raddr;
+ 	socklen_t salen;
  {
  	static char remotehost[NI_MAXHOST];
  	char h1[NI_MAXHOST], h2[NI_MAXHOST];
***************
*** 982,991 ****
  	_DIAGASSERT(raddr != NULL);
  
  	h1[0] = remotehost[0] = '\0';
! 	if (getnameinfo(raddr, raddr->sa_len, remotehost, sizeof(remotehost),
  	    NULL, 0, NI_NAMEREQD) != 0)
  		return (NULL);
! 	if (getnameinfo(raddr, raddr->sa_len, h1, sizeof(h1), NULL, 0,
  	    niflags) != 0)
  		return (NULL);
  
--- 987,996 ----
  	_DIAGASSERT(raddr != NULL);
  
  	h1[0] = remotehost[0] = '\0';
! 	if (getnameinfo(raddr, salen, remotehost, sizeof(remotehost),
  	    NULL, 0, NI_NAMEREQD) != 0)
  		return (NULL);
! 	if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0,
  	    niflags) != 0)
  		return (NULL);
  

------- =_aaaaaaaaaa0--