Subject: bin/1472: mount_nfs can't use different port numbers
To: None <gnats-bugs@gnats.netbsd.org>
From: None <carrel@cisco.com>
List: netbsd-bugs
Date: 09/17/1995 22:28:07
>Number:         1472
>Category:       bin
>Synopsis:       mount_nfs is unable to use port numbers other than 2049
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 18 16:50:01 1995
>Last-Modified:
>Originator:     David Carrel
>Organization:
	Just me.
>Release:        NetBSD-current supped 13 Sept 95
>Environment:
	Problem exists on all architectures.
System: NetBSD spy 1.0A NetBSD 1.0A (DAVE) #25: Wed Sep 13 22:38:12 PDT 1995 carrel@spy:/home/haydon/NetBSD/src/sys/arch/i386/compile/DAVE i386


>Description:
	mount_nfs is unable to use port numbers other than the standard NFS
port number (2049).  When using other NFS programs (like CFS) it is
convenient to have them use a different port so that regular NFS can still
operate.
>How-To-Repeat:
	Just try to use a different port.
>Fix:
	The following patch fixes mount_nfs.c and mount_nfs.8 to use the
"-S" option to set an alternate port number.  I really wanted to use "-p"
but that seems to be saved (by ifdef-ed code) for the ISO stuff.  I chose
"-S" for Socket since I could have "-p" for port.
	I have coded this in the style of the rest of the file.  Things
such as passing a pointer to a static structure can be very dangerous in
general, but the code was using that style and so I stuck to it.  It is
safe in this program.

Enjoy:

*** mount_nfs.c.orig	Sun Sep 17 19:25:51 1995
--- mount_nfs.c	Sun Sep 17 22:21:06 1995
***************
*** 157,162 ****
--- 157,163 ----
  #ifdef KERBEROS
  	uid_t last_ruid;
  #endif
+ 	static struct sockaddr_in saddr;
  
  #ifdef KERBEROS
  	last_ruid = -1;
***************
*** 168,175 ****
  	mntflags = 0;
  	nfsargs = nfsdefargs;
  	nfsargsp = &nfsargs;
  	while ((c = getopt(argc, argv,
! 	    "a:bcdD:g:iKklL:Mm:o:PpqR:r:sTt:w:x:")) != EOF)
  		switch (c) {
  		case 'a':
  			num = strtol(optarg, &p, 10);
--- 169,177 ----
  	mntflags = 0;
  	nfsargs = nfsdefargs;
  	nfsargsp = &nfsargs;
+ 	memset(&saddr, 0, sizeof(saddr));
  	while ((c = getopt(argc, argv,
! 	    "a:bcdD:g:iKklL:Mm:o:PpqR:r:S:sTt:w:x:")) != EOF)
  		switch (c) {
  		case 'a':
  			num = strtol(optarg, &p, 10);
***************
*** 261,266 ****
--- 263,275 ----
  			nfsargsp->rsize = num;
  			nfsargsp->flags |= NFSMNT_RSIZE;
  			break;
+ 		case 'S':
+ 			num = strtol(optarg, &p, 10);
+ 			if (*p || num <= 0)
+ 				errx(1, "illegal -S value -- %s", optarg);
+ 			saddr.sin_port = htons(num);
+ 			nfsargsp->addr = (struct sockaddr *) &saddr;
+ 			break;
  		case 's':
  			nfsargsp->flags |= NFSMNT_SOFT;
  			break;
***************
*** 376,382 ****
  #ifdef KERBEROS
  	char *cp;
  #endif
! 	u_short tport;
  	static struct nfhret nfhret;
  	static char nam[MNAMELEN + 1];
  
--- 385,391 ----
  #ifdef KERBEROS
  	char *cp;
  #endif
! 	u_short tport = 0;
  	static struct nfhret nfhret;
  	static char nam[MNAMELEN + 1];
  
***************
*** 455,463 ****
  	while (retrycnt > 0) {
  		saddr.sin_family = AF_INET;
  		saddr.sin_port = htons(PMAPPORT);
! 		if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
! 		    NFS_VER2, nfsargsp->sotype == SOCK_STREAM ? IPPROTO_TCP :
! 		    IPPROTO_UDP)) == 0) {
  			if ((opflags & ISBGRND) == 0)
  				clnt_pcreateerror("NFS Portmap");
  		} else {
--- 464,482 ----
  	while (retrycnt > 0) {
  		saddr.sin_family = AF_INET;
  		saddr.sin_port = htons(PMAPPORT);
! 		if (nfsargsp->addr) {
! 			struct sockaddr_in *t_saddr =
! 				(struct sockaddr_in *) nfsargsp->addr;
! 			tport = ntohs(t_saddr->sin_port);
! 			free(nfsargsp->addr);
! 			nfsargsp->addr = 0;
! 		}
! 		if (tport == 0) {
! 			tport = pmap_getport(&saddr, RPCPROG_NFS, NFS_VER2,
! 					     nfsargsp->sotype == SOCK_STREAM ?
! 					     IPPROTO_TCP : IPPROTO_UDP);
! 		}
! 		if (tport == 0) {
  			if ((opflags & ISBGRND) == 0)
  				clnt_pcreateerror("NFS Portmap");
  		} else {
*** mount_nfs.8.orig	Wed Aug 23 08:45:00 1995
--- mount_nfs.8	Sun Sep 17 22:07:37 1995
***************
*** 45,50 ****
--- 45,51 ----
  .Op Fl D Ar deadthresh
  .Op Fl L Ar leaseterm
  .Op Fl R Ar retrycnt
+ .Op Fl S Ar port_num
  .Op Fl a Ar maxreadahead
  .Op Fl g Ar maxgroups
  .Op Fl m Ar realm
***************
*** 106,111 ****
--- 107,115 ----
  This is recommended for servers that are not on the same LAN cable as
  the client.
  (NB: This is NOT supported by most non-BSD servers.)
+ .It Fl S
+ Set the value of the NFS server's UDP or TCP port number.  The default
+ value is the standard NFS port number.
  .It Fl a
  Set the read-ahead count to the specified value.
  This may be in the range of 0 - 4, and determines how many blocks

>Audit-Trail:
>Unformatted: