From marck@woozle.rinet.ru  Mon Apr 22 08:46:03 2002
Return-Path: <marck@woozle.rinet.ru>
Received: from woozle.rinet.ru (woozle.rinet.ru [195.54.192.68])
	by hub.freebsd.org (Postfix) with ESMTP id DA19637B405
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 22 Apr 2002 08:43:55 -0700 (PDT)
Received: (from marck@localhost)
	by woozle.rinet.ru (8.11.6/8.11.6) id g3MEqDw40708;
	Mon, 22 Apr 2002 18:52:13 +0400 (MSD)
	(envelope-from marck)
Message-Id: <200204221452.g3MEqDw40708@woozle.rinet.ru>
Date: Mon, 22 Apr 2002 18:52:13 +0400 (MSD)
From: Dmitry Morozovsky <marck@rinet.ru>
Reply-To: Dmitry Morozovsky <marck@rinet.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: portmap TCP binds strangeness
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         37343
>Category:       bin
>Synopsis:       portmap TCP binds strangeness
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 22 08:50:02 PDT 2002
>Closed-Date:    Tue Sep 18 12:24:39 GMT 2007
>Last-Modified:  Tue Sep 18 12:24:39 GMT 2007
>Originator:     Dmitry Morozovsky
>Release:        FreeBSD 4-STABLE i386
>Organization:
Cronyx Plus LLC (RiNet ISP)
>Environment:
System: FreeBSD 4-STABLE 


	
>Description:

	when portmap(8) running with -h option, it binds to TCP socket
with INADDR_ANY address, which seems incorrect.

	however, direct hack to bind to tcp sockets in for loop as UDP
binds do does not work (possibly because of looking to only the last socket
bound, but I did not dig into this issue deeply)

	In vast majority cases, there is only one -h option, so TCP bind may 
be restricted to this address.

>How-To-Repeat:

	portmap -h a.b.c.d
	netstat -an | grep 111

>Fix:

Really dirty hack.

Index: portmap.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/portmap/Attic/portmap.c,v
retrieving revision 1.10.2.2
diff -u -r1.10.2.2 portmap.c
--- portmap.c	2002/02/21 11:27:30	1.10.2.2
+++ portmap.c	2002/04/22 14:51:20
@@ -119,6 +119,7 @@
 	int sock, c;
 	char **hosts = NULL;
 	int nhosts = 0;
+	int nhosts2 = 0;
 	struct sockaddr_in addr;
 	int len = sizeof(struct sockaddr_in);
 	register struct pmaplist *pml;
@@ -166,6 +167,7 @@
 	else
 		hosts[nhosts - 1] = "127.0.0.1";
 
+	nhosts2 = nhosts;
 	/*
 	 * Add UDP socket(s) - bind to specific IPs if asked to
 	 */
@@ -202,8 +204,15 @@
 
 	/*
 	 * Add TCP socket
+	 * XXX dirty hack: bind only to the first address if -h is specified
 	 */
 	addr.sin_addr.s_addr = 0;
+	if (nhosts2 > 1) {
+	    if (inet_aton(hosts[0], &addr.sin_addr) < 0) {
+		    syslog(LOG_ERR, "bad IP address: %s", hosts[nhosts]);
+		    exit(1);
+	    }
+	}
 	if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
 		syslog(LOG_ERR, "cannot create tcp socket: %m");
 		exit(1);
>Release-Note:
>Audit-Trail:

From: Dmitry Morozovsky <marck@rinet.ru>
To: FreeBSD-gnats-submit@freebsd.org, <freebsd-bugs@freebsd.org>
Cc:  
Subject: Re: bin/37343: portmap TCP binds strangeness
Date: Mon, 22 Apr 2002 19:58:14 +0400 (MSD)

 as a followup...
 
 The main intention of this change is to make portmap useable for local NFS
 exports for jail host machine.
 
 Also, I don't know whether portbind (?) in -current has this problem, too.
 
 Sincerely,
 D.Marck                                   [DM5020, DM268-RIPE, DM3-RIPN]
 ------------------------------------------------------------------------
 *** Dmitry Morozovsky --- D.Marck --- Wild Woozle --- marck@rinet.ru ***
 ------------------------------------------------------------------------
 

From: "Denis N. Peplin" <info@volginfo.ru>
To: freebsd-gnats-submit@FreeBSD.org, marck@rinet.ru
Cc:  
Subject: Re: bin/37343: portmap TCP binds strangeness
Date: Fri, 10 Jan 2003 17:12:13 +0300

 Yet another hack.
 
 Index: portmap.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/portmap/Attic/portmap.c,v
 retrieving revision 1.10.2.3
 diff -u -r1.10.2.3 portmap.c
 --- portmap.c	6 May 2002 18:18:21 -0000	1.10.2.3
 +++ portmap.c	10 Jan 2003 14:01:47 -0000
 @@ -119,6 +119,7 @@
  	int sock, c;
  	char **hosts = NULL;
  	int nhosts = 0;
 +	int nhosts2 = 0;
  	struct sockaddr_in addr;
  	int len = sizeof(struct sockaddr_in);
  	register struct pmaplist *pml;
 @@ -165,7 +166,7 @@
  		hosts[0] = "0.0.0.0";
  	else
  		hosts[nhosts - 1] = "127.0.0.1";
 -
 +	nhosts2 = nhosts;
  	/*
  	 * Add UDP socket(s) - bind to specific IPs if asked to
  	 */
 @@ -203,7 +204,14 @@
  	/*
  	 * Add TCP socket
  	 */
 -	addr.sin_addr.s_addr = 0;
 +	nhosts = nhosts2;
 +	while (nhosts > 0) {
 +	    --nhosts;
 +
 +	    if (!inet_aton(hosts[nhosts], &addr.sin_addr)) {
 +		    syslog(LOG_ERR, "bad IP address: %s", hosts[nhosts]);
 +		    exit(1);
 +	    }
  	if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  		syslog(LOG_ERR, "cannot create tcp socket: %m");
  		exit(1);
 @@ -216,6 +224,7 @@
  	    == (SVCXPRT *)NULL) {
  		syslog(LOG_ERR, "couldn't do tcp_create");
  		exit(1);
 +	}
  	}
  	/* make an entry for ourself */
  	pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist));
 
State-Changed-From-To: open->closed 
State-Changed-By: matteo 
State-Changed-When: Tue Sep 18 12:23:48 UTC 2007 
State-Changed-Why:  
rpcbind grew an -h option which, even if not perfect yet, should solve this issue, if ever this issue still exists. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37343 
>Unformatted:
