From owner-freebsd-bugs@FreeBSD.ORG Sun Feb 25 10:10:14 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B7E9F16A401 for ; Sun, 25 Feb 2007 10:10:14 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 58AE713C48D for ; Sun, 25 Feb 2007 10:10:14 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l1PAAEWC072766 for ; Sun, 25 Feb 2007 10:10:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l1PAADQH072765; Sun, 25 Feb 2007 10:10:13 GMT (envelope-from gnats) Date: Sun, 25 Feb 2007 10:10:13 GMT Message-Id: <200702251010.l1PAADQH072765@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Maxim Konovalov Cc: Subject: Re: bin/109494: [PATCH] ypserv: Add option to bind to specific port X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Maxim Konovalov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Feb 2007 10:10:14 -0000 The following reply was made to PR bin/109494; it has been noted by GNATS. From: Maxim Konovalov To: Shaun Amott 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