From shaun@inerd.com  Sat Feb 24 17:35:23 2007
Return-Path: <shaun@inerd.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id AF2E816A400
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 24 Feb 2007 17:35:23 +0000 (UTC)
	(envelope-from shaun@inerd.com)
Received: from dione.picobyte.net (81-86-230-94.dsl.pipex.com [81.86.230.94])
	by mx1.freebsd.org (Postfix) with ESMTP id 3E51A13C4A3
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 24 Feb 2007 17:35:20 +0000 (UTC)
	(envelope-from shaun@inerd.com)
Received: from charon.picobyte.net (charon.picobyte.net [IPv6:2001:4bd0:201e::fe03])
	by dione.picobyte.net (Postfix) with ESMTP id DEC29B862
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 24 Feb 2007 17:14:54 +0000 (GMT)
Message-Id: <1172337294.33605@charon.picobyte.net>
Date: Sat, 24 Feb 2007 17:14:54 -0000
From: Shaun Amott <shaun@FreeBSD.org>
Reply-To: Shaun Amott <shaun@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] ypserv: Add option to bind to specific port
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         109494
>Category:       bin
>Synopsis:       [patch] [request] ypserv(8): Add option to bind to specific port
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    matteo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 24 17:40:08 GMT 2007
>Closed-Date:    Mon Mar 31 11:01:41 UTC 2008
>Last-Modified:  Mon Mar 31 11:01:41 UTC 2008
>Originator:     Shaun Amott
>Release:        FreeBSD 6.2-PRERELEASE i386
>Organization:
>Environment:

>Description:

The attached patch adds adds an option to the ypserv daemon which
allows the user to specify a specific port number to bind to, making
(e.g.) packet filtering easier.

>How-To-Repeat:

>Fix:

--- ypserv.diff begins here ---
Index: yp_main.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/ypserv/yp_main.c,v
retrieving revision 1.28
diff -u -r1.28 yp_main.c
--- yp_main.c	20 May 2005 13:04:10 -0000	1.28
+++ yp_main.c	24 Feb 2007 16:34:03 -0000
@@ -80,6 +80,7 @@
 extern int _rpcsvcstate;	 /* Set when a request is serviced */
 char *progname = "ypserv";
 char *yp_dir = _PATH_YP;
+long yp_port = -1;
 /*int debug = 0;*/
 int do_dns = 0;
 int resfd;
@@ -231,7 +232,7 @@
 	socklen_t asize = sizeof (saddr);
 	int ch;
 
-	while ((ch = getopt(argc, argv, "hdnp:")) != -1) {
+	while ((ch = getopt(argc, argv, "hdnp:P:")) != -1) {
 		switch (ch) {
 		case 'd':
 			debug = ypdb_debug = 1;
@@ -242,6 +243,13 @@
 		case 'p':
 			yp_dir = optarg;
 			break;
+		case 'P':
+			if ((yp_port = strtoul(optarg, NULL, 10)) == ULONG_MAX) {
+				err(1,"invalid port number provided");
+			} else if (yp_port > IPPORT_MAX) {
+				errx(1,"port number out of range");
+			}
+			break;
 		case 'h':
 		default:
 			usage();
@@ -277,6 +285,21 @@
 		(void) pmap_unset(YPPROG, 1);
 	}
 
+	if (yp_port >= 0) {
+		if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+			err(1,"cannot create udp socket");
+		}
+
+		memset((char *)&saddr, 0, sizeof(saddr));
+		saddr.sin_family = AF_INET;
+		saddr.sin_addr.s_addr = htonl(INADDR_ANY);
+		saddr.sin_port = htons(yp_port);
+
+		if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
+			err(1,"cannot bind udp socket");
+		}
+	}
+
 	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
 		transp = svcudp_create(sock);
 		if (transp == NULL) {
@@ -295,6 +318,21 @@
 		}
 	}
 
+	if (yp_port >= 0) {
+		if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+			err(1,"cannot create tcp socket");
+		}
+
+		memset((char *)&saddr, 0, sizeof(saddr));
+		saddr.sin_family = AF_INET;
+		saddr.sin_addr.s_addr = htonl(INADDR_ANY);
+		saddr.sin_port = htons(yp_port);
+
+		if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
+			err(1,"cannot bind tcp socket");
+		}
+	}
+
 	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
 		transp = svctcp_create(sock, 0, 0);
 		if (transp == NULL) {
Index: ypserv.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/ypserv/ypserv.8,v
retrieving revision 1.41
diff -u -r1.41 ypserv.8
--- ypserv.8	13 Feb 2005 23:45:54 -0000	1.41
+++ ypserv.8	24 Feb 2007 16:34:03 -0000
@@ -40,6 +40,7 @@
 .Nm
 .Op Fl n
 .Op Fl d
+.Op Fl P Ar port
 .Op Fl p Ar path
 .Sh DESCRIPTION
 .Tn NIS
@@ -403,6 +404,9 @@
 other requests.)
 This makes it easier to trace the server with
 a debugging tool.
+.It Fl P Ar port
+Force ypserv to bind to a specific TCP/UDP port, rather than selecting
+its own.
 .It Fl p Ar path
 Normally,
 .Nm
--- ypserv.diff ends here ---
>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: Shaun Amott <shaun@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/109494: [PATCH] ypserv: Add option to bind to specific port
Date: Sun, 25 Feb 2007 13:07:43 +0300 (MSK)

 Hi Shaun,
 
 [...]
 > >Description:
 >
 > The attached patch adds adds an option to the ypserv daemon which
 > allows the user to specify a specific port number to bind to, making
 > (e.g.) packet filtering easier.
 >
 > >How-To-Repeat:
 >
 > >Fix:
 >
 > --- ypserv.diff begins here ---
 > Index: yp_main.c
 > ===================================================================
 > RCS file: /home/ncvs/src/usr.sbin/ypserv/yp_main.c,v
 > retrieving revision 1.28
 > diff -u -r1.28 yp_main.c
 > --- yp_main.c	20 May 2005 13:04:10 -0000	1.28
 > +++ yp_main.c	24 Feb 2007 16:34:03 -0000
 > @@ -80,6 +80,7 @@
 >  extern int _rpcsvcstate;	 /* Set when a request is serviced */
 >  char *progname = "ypserv";
 >  char *yp_dir = _PATH_YP;
 > +long yp_port = -1;
 >  /*int debug = 0;*/
 >  int do_dns = 0;
 >  int resfd;
 > @@ -231,7 +232,7 @@
 >  	socklen_t asize = sizeof (saddr);
 >  	int ch;
 >
 > -	while ((ch = getopt(argc, argv, "hdnp:")) != -1) {
 > +	while ((ch = getopt(argc, argv, "hdnp:P:")) != -1) {
 >  		switch (ch) {
 >  		case 'd':
 >  			debug = ypdb_debug = 1;
 > @@ -242,6 +243,13 @@
 >  		case 'p':
 >  			yp_dir = optarg;
 >  			break;
 > +		case 'P':
 > +			if ((yp_port = strtoul(optarg, NULL, 10)) == ULONG_MAX) {
 > +				err(1,"invalid port number provided");
 > +			} else if (yp_port > IPPORT_MAX) {
 > +				errx(1,"port number out of range");
 > +			}
 > +			break;
 
 strtoul() usage above is not entirely correct.  Better to use
 strtonum(3) instead.
 
 >  		case 'h':
 >  		default:
 >  			usage();
 > @@ -277,6 +285,21 @@
 >  		(void) pmap_unset(YPPROG, 1);
 >  	}
 >
 > +	if (yp_port >= 0) {
 > +		if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 > +			err(1,"cannot create udp socket");
 > +		}
 > +
 > +		memset((char *)&saddr, 0, sizeof(saddr));
 > +		saddr.sin_family = AF_INET;
 > +		saddr.sin_addr.s_addr = htonl(INADDR_ANY);
 > +		saddr.sin_port = htons(yp_port);
 > +
 > +		if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
 > +			err(1,"cannot bind udp socket");
 > +		}
 > +	}
 > +
 >  	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
 >  		transp = svcudp_create(sock);
 >  		if (transp == NULL) {
 > @@ -295,6 +318,21 @@
 >  		}
 >  	}
 >
 > +	if (yp_port >= 0) {
 > +		if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
 > +			err(1,"cannot create tcp socket");
 > +		}
 > +
 > +		memset((char *)&saddr, 0, sizeof(saddr));
 > +		saddr.sin_family = AF_INET;
 > +		saddr.sin_addr.s_addr = htonl(INADDR_ANY);
 > +		saddr.sin_port = htons(yp_port);
 > +
 > +		if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
 > +			err(1,"cannot bind tcp socket");
 > +		}
 > +	}
 > +
 >  	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
 >  		transp = svctcp_create(sock, 0, 0);
 >  		if (transp == NULL) {
 [...]
 
 That breaks ypserv(8) for ipv6.  Look at NetBSD ypserv -p
 implementation.
 
 -- maxim

From: Erwin Van de Velde <erwin.vandevelde@ua.ac.be>
To: bug-followup@freebsd.org, shaun@freebsd.org
Cc:  
Subject: Re: bin/109494: [PATCH] ypserv(8): Add option to bind to specific port
Date: Fri, 1 Jun 2007 17:02:01 +0200

 Hi, 
 
 Is anyone still looking at this? The Linux implementation supports this and it 
 would come really in handy since in the network I maintain, the RPC traffic 
 has to pass through one firewall. I can not open up all ports just to make 
 sure NIS works.
 
 Best regards,
 Erwin Van de Velde
 
 -- 
 ========================================================
 Erwin Van de Velde
 ========================================================
 Phd Student
 Dept. of Mathematics and Computer Sciences
 PATS (Performance Analysis of Telecommunication Systems)
 University of Antwerp
 Middelheimlaan 1
 2020 Antwerpen, Belgium
 G2.36
 Phone: ++32 3 265 35 19
 Mail: erwin.vandevelde@ua.ac.be
 URL: http://www.pats.ua.ac.be/erwin.vandevelde
 ========================================================

From: Mike Makonnen <mtm@FreeBSD.Org>
To: Shaun Amott <shaun@FreeBSD.org>
Cc: bug-followup@FreeBSD.Org, Maxim Konovalov <maxim@macomnet.ru>
Subject: Re: bin/109494: [PATCH] ypserv(8): Add option to bind to specific port
Date: Sun, 21 Oct 2007 21:24:36 +0300

 --IS0zKkzwUGydFO0o
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hi guys,
 
 > [...]
 > 
 > That breaks ypserv(8) for ipv6.  Look at NetBSD ypserv -p
 > implementation.
 > 
 > -- maxim
 
 I'm not sure I agree. As far as I can see our version of ypserv does
 not support IPv6:
 
 yp_main.c:
 %%%
     256         if (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {
     257                 int ssize = sizeof (int);
     258 
     259                 if (saddr.sin_family != AF_INET)
     260                         exit(1);
 %%% 
 
 So, I think for the purposes of this PR it's ok if it doesn't include
 a patch for IPv6. And even if it did, none of the other yp* daemons
 seem to support IPv6. Also, it appears to be using the older Transport-
 Dependant RPC functions. With that in mind what do you think of the
 following patch? It's based on the submitted patch but cleaned up to
 be more concise, style(9)'ed, and made to fit in better with the
 existing code.
 
 Cheers.
 -- 
 Mike Makonnen         | GPG-KEY: http://people.freebsd.org/~mtm/mtm.asc
 mmakonnen @ gmail.com | AC7B 5672 2D11 F4D0 EBF8  5279 5359 2B82 7CD4 1F55
 mtm @ FreeBSD.Org     | FreeBSD - http://www.freebsd.org
 
 --IS0zKkzwUGydFO0o
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=ypserv-patch
 
 Index: usr.sbin/ypserv/yp_main.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/ypserv/yp_main.c,v
 retrieving revision 1.28
 diff -u -r1.28 yp_main.c
 --- usr.sbin/ypserv/yp_main.c	20 May 2005 13:04:10 -0000	1.28
 +++ usr.sbin/ypserv/yp_main.c	20 Oct 2007 21:48:55 -0000
 @@ -84,6 +84,16 @@
  int do_dns = 0;
  int resfd;
  
 +struct socktype {
 +	const char *st_name;
 +	int	   st_type;
 +};
 +static struct socktype stlist[] = {
 +	{ "tcp", SOCK_STREAM },
 +	{ "udp", SOCK_DGRAM },
 +	{ NULL, 0 }
 +};
 +
  static
  void _msgout(char* msg)
  {
 @@ -230,8 +240,11 @@
  	struct sockaddr_in saddr;
  	socklen_t asize = sizeof (saddr);
  	int ch;
 +	in_port_t yp_port = 0;
 +	char *errstr;
 +	struct socktype *st;
  
 -	while ((ch = getopt(argc, argv, "hdnp:")) != -1) {
 +	while ((ch = getopt(argc, argv, "hdnp:P:")) != -1) {
  		switch (ch) {
  		case 'd':
  			debug = ypdb_debug = 1;
 @@ -242,6 +255,14 @@
  		case 'p':
  			yp_dir = optarg;
  			break;
 +		case 'P':
 +			yp_port = (in_port_t)strtonum(optarg, 1, 65535,
 +			    (const char **)&errstr);
 +			if (yp_port == 0 && errstr != NULL) {
 +				_msgout("invalid port number provided");
 +				exit(1);
 +			}
 +			break;
  		case 'h':
  		default:
  			usage();
 @@ -277,6 +298,39 @@
  		(void) pmap_unset(YPPROG, 1);
  	}
  
 +	/*
 +	 * Initialize TCP/UDP sockets.
 +	 */
 +	memset((char *)&saddr, 0, sizeof(saddr));
 +	saddr.sin_family = AF_INET;
 +	saddr.sin_addr.s_addr = htonl(INADDR_ANY);
 +	saddr.sin_port = htons(yp_port);
 +	for (st = stlist; st->st_name != NULL; st++) {
 +		/* Do not bind the socket if the user didn't specify a port */
 +		if (yp_port == 0)
 +			break;
 +
 +		sock = socket(AF_INET, st->st_type, 0);
 +		if (sock == -1) {
 +			if ((asprintf(&errstr, "cannot create a %s socket",
 +			    st->st_name)) == -1)
 +				err(1, "unexpected failure in asprintf()");
 +			_msgout(errstr);
 +			free((void *)errstr);
 +			exit(1);
 +		}
 +		if (bind(sock, (struct sockaddr *) &saddr, sizeof(saddr))
 +		    == -1) {
 +			if ((asprintf(&errstr, "cannot bind %s socket",
 +			    st->st_name)) == -1)
 +				err(1, "unexpected failure in asprintf()");
 +			_msgout(errstr);
 +			free((void *)errstr);
 +			exit(1);
 +		}
 +		errstr = NULL;
 +	}
 +
  	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
  		transp = svcudp_create(sock);
  		if (transp == NULL) {
 Index: usr.sbin/ypserv/ypserv.8
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/ypserv/ypserv.8,v
 retrieving revision 1.41
 diff -u -r1.41 ypserv.8
 --- usr.sbin/ypserv/ypserv.8	13 Feb 2005 23:45:54 -0000	1.41
 +++ usr.sbin/ypserv/ypserv.8	20 Oct 2007 19:30:01 -0000
 @@ -40,6 +40,7 @@
  .Nm
  .Op Fl n
  .Op Fl d
 +.Op Fl P Ar port
  .Op Fl p Ar path
  .Sh DESCRIPTION
  .Tn NIS
 @@ -403,6 +404,9 @@
  other requests.)
  This makes it easier to trace the server with
  a debugging tool.
 +.It Fl P Ar port
 +Force ypserv to bind to a specific TCP/UDP port, rather than selecting
 +its own.
  .It Fl p Ar path
  Normally,
  .Nm
 
 --IS0zKkzwUGydFO0o--
Responsible-Changed-From-To: freebsd-bugs->	 matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Mar 23 Ott 2007 06:39:36 UTC 
Responsible-Changed-Why:  
I'll take care of this PR in a near future.. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=109494 

From: Shaun Amott <shaun@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	Erwin Van de Velde <erwin.vandevelde@ua.ac.be>
Subject: Re: bin/109494: [PATCH] ypserv(8): Add option to bind to specific
	port
Date: Sat, 26 Jan 2008 14:42:51 +0000

 --qDbXVdCdHGoSgWSk
 Content-Type: text/plain; charset=iso-8859-1
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Sorry for the delay in responding folks. Thanks for the feedback.
 
 The updated patch looks fine to me. And, I agree with Mike about IPv6.
 
 Looks like matteo is now handling this PR. :-)
 
 --=20
 Shaun Amott // PGP: 0x6B387A9A
 "A foolish consistency is the hobgoblin
 of little minds." - Ralph Waldo Emerson
 
 --qDbXVdCdHGoSgWSk
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD8DBQFHm0bqkmhdCGs4epoRAlYlAJ9Bwcyh3vRuwVtxAYF4HZigNgEsDQCgpt5z
 zBcBYPAPttoqetkkKY+uT1g=
 =9ZeS
 -----END PGP SIGNATURE-----
 
 --qDbXVdCdHGoSgWSk--
State-Changed-From-To: open->patched 
State-Changed-By: matteo 
State-Changed-When: Dom 3 Feb 2008 17:39:56 UTC 
State-Changed-Why:  
I committed mtm@'s patch to HEAD. MFC coming in a week 

http://www.freebsd.org/cgi/query-pr.cgi?pr=109494 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/109494: commit references a PR
Date: Sun,  3 Feb 2008 17:39:46 +0000 (UTC)

 matteo      2008-02-03 17:39:37 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.sbin/ypserv      yp_main.c ypserv.8 
   Log:
   Add -P <port> option to allow binding to a specific port.
   
   PR:             bin/109494
   Submitted by:   mtm
   MFC after:      1 week
   
   Revision  Changes    Path
   1.29      +56 -2     src/usr.sbin/ypserv/yp_main.c
   1.42      +5 -1      src/usr.sbin/ypserv/ypserv.8
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/109494: commit references a PR
Date: Sun, 30 Mar 2008 19:39:35 +0000 (UTC)

 matteo      2008-03-30 19:39:29 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     usr.sbin/ypserv      yp_main.c ypserv.8 
   Log:
   Add -P <port> option to allow binding to a specific port.
   
   PR:             bin/109494
   Submitted by:   mtm
   
   Revision   Changes    Path
   1.28.10.1  +56 -2     src/usr.sbin/ypserv/yp_main.c
   1.41.10.1  +5 -1      src/usr.sbin/ypserv/ypserv.8
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: matteo 
State-Changed-When: Lun 31 Mar 2008 11:01:28 UTC 
State-Changed-Why:  
MFC'ed to RELENG_7 

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