From owner-freebsd-bugs@FreeBSD.ORG Sat Feb 24 17:40:09 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 81E3516A406 for ; Sat, 24 Feb 2007 17:40:09 +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 646F813C474 for ; Sat, 24 Feb 2007 17:40:09 +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 l1OHe9pw092524 for ; Sat, 24 Feb 2007 17:40:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l1OHe9mP092523; Sat, 24 Feb 2007 17:40:09 GMT (envelope-from gnats) Resent-Date: Sat, 24 Feb 2007 17:40:09 GMT Resent-Message-Id: <200702241740.l1OHe9mP092523@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Shaun Amott Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AF2E816A400 for ; 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 ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: 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: Shaun Amott List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Feb 2007 17:40:09 -0000 >Number: 109494 >Category: bin >Synopsis: [PATCH] ypserv: Add option to bind to specific port >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Feb 24 17:40:08 GMT 2007 >Closed-Date: >Last-Modified: >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: >Unformatted: