diff options
author | dfr <dfr@FreeBSD.org> | 1997-05-01 12:30:02 +0000 |
---|---|---|
committer | dfr <dfr@FreeBSD.org> | 1997-05-01 12:30:02 +0000 |
commit | d2e6eb44ef8bfde31888bb875af1b4b32195777e (patch) | |
tree | b25bcf05ded566e149ee45c2833fe1bee3332128 /sbin | |
parent | 2eb033188f5de3b40d7eebd9d6f73ba3d81cce5e (diff) | |
download | FreeBSD-src-d2e6eb44ef8bfde31888bb875af1b4b32195777e.zip FreeBSD-src-d2e6eb44ef8bfde31888bb875af1b4b32195777e.tar.gz |
Test both the NFS and MOUNT protocols for v3 support before allowing a v3
mount. It is possible to have v3 MOUNT but only v2 NFS, for instance for
a custom user-mode server like CFS.
Reviewed by: "Louis A. Mamakos" <louie@TransSys.COM>
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/mount_nfs/mount_nfs.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index 6f8b9c5..944e091 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -45,7 +45,7 @@ static char copyright[] = static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95"; */ static const char rcsid[] = - "$Id: mount_nfs.c,v 1.20 1997/04/02 11:30:44 dfr Exp $"; + "$Id: mount_nfs.c,v 1.21 1997/04/18 16:23:10 dfr Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -568,6 +568,52 @@ main(argc, argv) exit(0); } +/* + * Return RPC_SUCCESS if server responds. + */ +enum clnt_stat +pingnfsserver(addr, version, sotype) + struct sockaddr_in *addr; + int version; + int sotype; +{ + struct sockaddr_in sin; + int tport; + CLIENT *clp; + int so = RPC_ANYSOCK; + enum clnt_stat stat; + struct timeval pertry, try; + + sin = *addr; + + if ((tport = port_no ? port_no : + pmap_getport(&sin, RPCPROG_NFS, version, nfsproto)) == 0) { + return rpc_createerr.cf_stat; + } + + sin.sin_port = htons(tport); + + pertry.tv_sec = 10; + pertry.tv_usec = 0; + if (sotype == SOCK_STREAM) + clp = clnttcp_create(&sin, RPCPROG_NFS, version, + &so, 0, 0); + else + clp = clntudp_create(&sin, RPCPROG_NFS, version, + pertry, &so); + if (clp == NULL) + return rpc_createerr.cf_stat; + + try.tv_sec = 10; + try.tv_usec = 0; + stat = clnt_call(clp, NFSPROC_NULL, + xdr_void, NULL, xdr_void, NULL, try); + + clnt_destroy(clp); + + return stat; +} + int getnfsargs(spec, nfsargsp) char *spec; @@ -685,6 +731,20 @@ tryagain: if ((opflags & ISBGRND) == 0) clnt_pcreateerror("NFS Portmap"); } else { + /* + * First ping the nfs server to see if it supports + * the version of the protocol we want to use. + */ + clnt_stat = pingnfsserver(&saddr, nfsvers, + nfsargsp->sotype); + if (clnt_stat == RPC_PROGVERSMISMATCH) { + if (mountmode == ANY) { + mountmode = V2; + goto tryagain; + } else { + errx(1, "Can't contact NFS server"); + } + } saddr.sin_port = 0; pertry.tv_sec = 10; pertry.tv_usec = 0; |