2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#) Copyright (c) 1992, 1993, 1994 The Regents of the University of California. All rights reserved.
37 * @(#)mount_nfs.c 8.11 (Berkeley) 5/4/95
38 * $FreeBSD: src/sbin/mount_nfs/mount_nfs.c,v 1.36.2.6 2003/05/13 14:45:40 trhodes Exp $
39 * $DragonFly: src/sbin/mount_nfs/mount_nfs.c,v 1.5 2003/09/28 14:39:19 hmp Exp $
42 #include <sys/param.h>
43 #include <sys/mount.h>
45 #include <sys/syslog.h>
48 #include <rpc/pmap_clnt.h>
49 #include <rpc/pmap_prot.h>
51 #include <vfs/nfs/rpcv2.h>
52 #include <vfs/nfs/nfsproto.h>
53 #include <vfs/nfs/nfs.h>
54 #include <vfs/nfs/nqnfs.h>
56 #include <arpa/inet.h>
72 #define ALTF_NOCONN 0x2
73 #define ALTF_DUMBTIMR 0x4
75 #define ALTF_KERB 0x10
76 #define ALTF_NFSV3 0x20
77 #define ALTF_RDIRPLUS 0x40
78 #define ALTF_MNTUDP 0x80
79 #define ALTF_RESVPORT 0x100
80 #define ALTF_SEQPACKET 0x200
81 #define ALTF_NQNFS 0x400
82 #define ALTF_SOFT 0x800
83 #define ALTF_TCP 0x1000
84 #define ALTF_PORT 0x2000
85 #define ALTF_NFSV2 0x4000
86 #define ALTF_ACREGMIN 0x8000
87 #define ALTF_ACREGMAX 0x10000
88 #define ALTF_ACDIRMIN 0x20000
89 #define ALTF_ACDIRMAX 0x40000
91 struct mntopt mopts[] = {
96 { "bg", 0, ALTF_BG, 1 },
97 { "conn", 1, ALTF_NOCONN, 1 },
98 { "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
99 { "intr", 0, ALTF_INTR, 1 },
101 { "kerb", 0, ALTF_KERB, 1 },
103 { "nfsv3", 0, ALTF_NFSV3, 1 },
104 { "rdirplus", 0, ALTF_RDIRPLUS, 1 },
105 { "mntudp", 0, ALTF_MNTUDP, 1 },
106 { "resvport", 0, ALTF_RESVPORT, 1 },
107 { "nqnfs", 0, ALTF_NQNFS, 1 },
108 { "soft", 0, ALTF_SOFT, 1 },
109 { "tcp", 0, ALTF_TCP, 1 },
110 { "port=", 0, ALTF_PORT, 1 },
111 { "nfsv2", 0, ALTF_NFSV2, 1 },
112 { "acregmin=", 0, ALTF_ACREGMIN, 1 },
113 { "acregmax=", 0, ALTF_ACREGMAX, 1 },
114 { "acdirmin=", 0, ALTF_ACDIRMIN, 1 },
115 { "acdirmax=", 0, ALTF_ACDIRMAX, 1 },
119 struct nfs_args nfsdefargs = {
121 (struct sockaddr *)0,
122 sizeof (struct sockaddr_in),
150 u_char nfh[NFSX_V3FHMAX];
156 int nfsproto = IPPROTO_UDP;
167 char realm[REALM_SZ];
172 struct nfsrpc_nickverf kverf;
173 struct nfsrpc_fullblock kin, kout;
177 NFSKERBKEYSCHED_T kerb_keysched;
180 /* Return codes for nfs_tryproto. */
183 TRYRET_TIMEOUT, /* No response received. */
184 TRYRET_REMOTEERR, /* Error received from remote server. */
185 TRYRET_LOCALERR /* Local failure. */
188 int getnfsargs __P((char *, struct nfs_args *));
189 void set_rpc_maxgrouplist __P((int));
190 void usage __P((void)) __dead2;
191 int xdr_dir __P((XDR *, char *));
192 int xdr_fh __P((XDR *, struct nfhret *));
193 enum tryret nfs_tryproto(struct nfs_args *nfsargsp, struct sockaddr_in *sin,
194 char *hostp, char *spec, char **errstr);
195 enum tryret returncode(enum clnt_stat stat, struct rpc_err *rpcerr);
198 * Used to set mount flags with getmntopts. Call with dir=TRUE to
199 * initialize altflags from the current mount flags. Call with
200 * dir=FALSE to update mount flags with the new value of altflags after
201 * the call to getmntopts.
204 set_flags(int* altflags, int* nfsflags, int dir)
208 if (*nfsflags & NFSMNT_##nf) \
209 *altflags |= ALTF_##af; \
211 *altflags &= ~ALTF_##af; \
213 if (*altflags & ALTF_##af) \
214 *nfsflags |= NFSMNT_##nf; \
216 *nfsflags &= ~NFSMNT_##nf; \
240 main(int argc, char **argv)
243 register struct nfs_args *nfsargsp;
244 struct nfs_args nfsargs;
245 struct nfsd_cargs ncd;
246 int mntflags, altflags, nfssvc_flag, num;
247 char *name, *p, *spec;
248 char mntpath[MAXPATHLEN];
255 (void)strcpy(realm, KRB_REALM);
256 if (sizeof (struct nfsrpc_nickverf) != RPCX_NICKVERF ||
257 sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK ||
258 ((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED ||
259 ((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED)
260 fprintf(stderr, "Yikes! NFSKERB structs not packed!!\n");
265 nfsargs = nfsdefargs;
267 while ((c = getopt(argc, argv,
268 "23a:bcdD:g:I:iKL:lm:No:PqR:r:sTt:w:x:U")) != -1)
277 num = strtol(optarg, &p, 10);
279 errx(1, "illegal -a value -- %s", optarg);
280 nfsargsp->readahead = num;
281 nfsargsp->flags |= NFSMNT_READAHEAD;
287 nfsargsp->flags |= NFSMNT_NOCONN;
290 num = strtol(optarg, &p, 10);
292 errx(1, "illegal -D value -- %s", optarg);
293 nfsargsp->deadthresh = num;
294 nfsargsp->flags |= NFSMNT_DEADTHRESH;
297 nfsargsp->flags |= NFSMNT_DUMBTIMR;
300 num = strtol(optarg, &p, 10);
302 errx(1, "illegal -g value -- %s", optarg);
303 set_rpc_maxgrouplist(num);
304 nfsargsp->maxgrouplist = num;
305 nfsargsp->flags |= NFSMNT_MAXGRPS;
308 num = strtol(optarg, &p, 10);
310 errx(1, "illegal -I value -- %s", optarg);
311 nfsargsp->readdirsize = num;
312 nfsargsp->flags |= NFSMNT_READDIRSIZE;
315 nfsargsp->flags |= NFSMNT_INT;
319 nfsargsp->flags |= NFSMNT_KERB;
323 num = strtol(optarg, &p, 10);
325 errx(1, "illegal -L value -- %s", optarg);
326 nfsargsp->leaseterm = num;
327 nfsargsp->flags |= NFSMNT_LEASETERM;
330 nfsargsp->flags |= NFSMNT_RDIRPLUS;
334 (void)strncpy(realm, optarg, REALM_SZ - 1);
335 realm[REALM_SZ - 1] = '\0';
339 nfsargsp->flags &= ~NFSMNT_RESVPORT;
343 set_flags(&altflags, &nfsargsp->flags, TRUE);
345 altflags |= ALTF_NFSV2;
346 else if (mountmode == V3)
347 altflags |= ALTF_NFSV3;
348 getmntopts(optarg, mopts, &mntflags, &altflags);
349 set_flags(&altflags, &nfsargsp->flags, FALSE);
351 * Handle altflags which don't map directly to
354 if(altflags & ALTF_BG)
356 if(altflags & ALTF_MNTUDP)
358 if(altflags & ALTF_TCP) {
359 nfsargsp->sotype = SOCK_STREAM;
360 nfsproto = IPPROTO_TCP;
362 if(altflags & ALTF_PORT)
363 port_no = atoi(strstr(optarg, "port=") + 5);
365 if(altflags & ALTF_NFSV2)
367 if(altflags & ALTF_NFSV3)
369 if(altflags & ALTF_ACREGMIN)
370 nfsargsp->acregmin = atoi(strstr(optarg,
372 if(altflags & ALTF_ACREGMAX)
373 nfsargsp->acregmax = atoi(strstr(optarg,
375 if(altflags & ALTF_ACDIRMIN)
376 nfsargsp->acdirmin = atoi(strstr(optarg,
378 if(altflags & ALTF_ACDIRMAX)
379 nfsargsp->acdirmax = atoi(strstr(optarg,
383 /* obsolete for NFSMNT_RESVPORT, now default */
387 nfsargsp->flags |= NFSMNT_NQNFS;
390 num = strtol(optarg, &p, 10);
392 errx(1, "illegal -R value -- %s", optarg);
396 num = strtol(optarg, &p, 10);
398 errx(1, "illegal -r value -- %s", optarg);
399 nfsargsp->rsize = num;
400 nfsargsp->flags |= NFSMNT_RSIZE;
403 nfsargsp->flags |= NFSMNT_SOFT;
406 nfsargsp->sotype = SOCK_STREAM;
407 nfsproto = IPPROTO_TCP;
410 num = strtol(optarg, &p, 10);
412 errx(1, "illegal -t value -- %s", optarg);
413 nfsargsp->timeo = num;
414 nfsargsp->flags |= NFSMNT_TIMEO;
417 num = strtol(optarg, &p, 10);
419 errx(1, "illegal -w value -- %s", optarg);
420 nfsargsp->wsize = num;
421 nfsargsp->flags |= NFSMNT_WSIZE;
424 num = strtol(optarg, &p, 10);
426 errx(1, "illegal -x value -- %s", optarg);
427 nfsargsp->retrans = num;
428 nfsargsp->flags |= NFSMNT_RETRANS;
449 /* The default is to keep retrying forever. */
451 if (!getnfsargs(spec, nfsargsp))
454 /* resolve the mountpoint with realpath(3) */
455 (void)checkpath(name, mntpath);
457 error = getvfsbyname("nfs", &vfc);
458 if (error && vfsisloadable("nfs")) {
460 err(EX_OSERR, "vfsload(nfs)");
461 endvfsent(); /* clear cache */
462 error = getvfsbyname("nfs", &vfc);
465 errx(EX_OSERR, "nfs filesystem is not available");
467 if (mount(vfc.vfc_name, mntpath, mntflags, nfsargsp))
468 err(1, "%s", mntpath);
469 if (nfsargsp->flags & (NFSMNT_NQNFS | NFSMNT_KERB)) {
470 if ((opflags & ISBGRND) == 0) {
471 if (daemon(0, 0) != 0)
474 openlog("mount_nfs", LOG_PID, LOG_DAEMON);
475 nfssvc_flag = NFSSVC_MNTD;
476 ncd.ncd_dirp = mntpath;
477 while (nfssvc(nfssvc_flag, (caddr_t)&ncd) < 0) {
478 if (errno != ENEEDAUTH) {
479 syslog(LOG_ERR, "nfssvc err %m");
483 NFSSVC_MNTD | NFSSVC_GOTAUTH | NFSSVC_AUTHINFAIL;
486 * Set up as ncd_authuid for the kerberos call.
487 * Must set ruid to ncd_authuid and reset the
488 * ticket name iff ncd_authuid is not the same
489 * as last time, so that the right ticket file
491 * Get the Kerberos credential structure so that
492 * we have the session key and get a ticket for
494 * For more info see the IETF Draft "Authentication
497 if (ncd.ncd_authuid != last_ruid) {
499 (void)sprintf(buf, "%s%d",
500 TKT_ROOT, ncd.ncd_authuid);
501 krb_set_tkt_string(buf);
502 last_ruid = ncd.ncd_authuid;
504 setreuid(ncd.ncd_authuid, 0);
505 kret = krb_get_cred(NFS_KERBSRV, inst, realm, &kcr);
506 if (kret == RET_NOTKT) {
507 kret = get_ad_tkt(NFS_KERBSRV, inst, realm,
509 if (kret == KSUCCESS)
510 kret = krb_get_cred(NFS_KERBSRV, inst, realm,
513 if (kret == KSUCCESS)
514 kret = krb_mk_req(&ktick.kt, NFS_KERBSRV, inst,
518 * Fill in the AKN_FULLNAME authenticator and verifier.
519 * Along with the Kerberos ticket, we need to build
520 * the timestamp verifier and encrypt it in CBC mode.
522 if (kret == KSUCCESS &&
523 ktick.kt.length <= (RPCAUTH_MAXSIZ-3*NFSX_UNSIGNED)
524 && gettimeofday(&ktv, (struct timezone *)0) == 0) {
525 ncd.ncd_authtype = RPCAUTH_KERB4;
526 ncd.ncd_authstr = (u_char *)&ktick;
527 ncd.ncd_authlen = nfsm_rndup(ktick.kt.length) +
529 ncd.ncd_verfstr = (u_char *)&kverf;
530 ncd.ncd_verflen = sizeof (kverf);
531 memmove(ncd.ncd_key, kcr.session,
532 sizeof (kcr.session));
533 kin.t1 = htonl(ktv.tv_sec);
534 kin.t2 = htonl(ktv.tv_usec);
535 kin.w1 = htonl(NFS_KERBTTL);
536 kin.w2 = htonl(NFS_KERBTTL - 1);
537 bzero((caddr_t)kivec, sizeof (kivec));
540 * Encrypt kin in CBC mode using the session
546 * Finally, fill the timestamp verifier into the
547 * authenticator and verifier.
549 ktick.kind = htonl(RPCAKN_FULLNAME);
550 kverf.kind = htonl(RPCAKN_FULLNAME);
551 NFS_KERBW1(ktick.kt) = kout.w1;
552 ktick.kt.length = htonl(ktick.kt.length);
553 kverf.verf.t1 = kout.t1;
554 kverf.verf.t2 = kout.t2;
555 kverf.verf.w2 = kout.w2;
556 nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH;
566 getnfsargs(char *spec, struct nfs_args *nfsargsp)
569 struct sockaddr_in saddr;
571 int speclen, remoteerr;
572 char *hostp, *delimp, *errstr;
577 static char nam[MNAMELEN + 1];
579 if ((delimp = strrchr(spec, ':')) != NULL) {
582 } else if ((delimp = strrchr(spec, '@')) != NULL) {
583 warnx("path@server syntax is deprecated, use server:path");
586 warnx("no <host>:<dirpath> nfs-name");
592 * If there has been a trailing slash at mounttime it seems
593 * that some mountd implementations fail to remove the mount
594 * entries from their mountlist while unmounting.
596 for (speclen = strlen(spec);
597 speclen > 1 && spec[speclen - 1] == '/';
599 spec[speclen - 1] = '\0';
600 if (strlen(hostp) + strlen(spec) + 1 > MNAMELEN) {
601 warnx("%s:%s: %s", hostp, spec, strerror(ENAMETOOLONG));
604 /* Make both '@' and ':' notations equal */
605 if (*hostp != '\0') {
607 memmove(nam, hostp, len);
609 memmove(nam + len + 1, spec, speclen);
610 nam[len + speclen + 1] = '\0';
614 * Handle an internet host address and reverse resolve it if
617 bzero(&saddr, sizeof saddr);
618 saddr.sin_family = AF_INET;
619 saddr.sin_len = sizeof saddr;
621 saddr.sin_port = htons(port_no);
622 if (isdigit(*hostp)) {
623 if ((saddr.sin_addr.s_addr = inet_addr(hostp)) == -1) {
624 warnx("bad net address %s", hostp);
627 } else if ((hp = gethostbyname(hostp)) != NULL)
628 memmove(&saddr.sin_addr, hp->h_addr,
629 MIN(hp->h_length, sizeof(saddr.sin_addr)));
631 warnx("can't get net id for host");
635 if ((nfsargsp->flags & NFSMNT_KERB)) {
636 if ((hp = gethostbyaddr((char *)&saddr.sin_addr.s_addr,
637 sizeof (u_long), AF_INET)) == (struct hostent *)0) {
638 warnx("can't reverse resolve net address");
641 memmove(&saddr.sin_addr, hp->h_addr,
642 MIN(hp->h_length, sizeof(saddr.sin_addr)));
643 strncpy(inst, hp->h_name, INST_SZ);
644 inst[INST_SZ - 1] = '\0';
645 if (cp = strchr(inst, '.'))
650 ret = TRYRET_LOCALERR;
653 ret = nfs_tryproto(nfsargsp, &saddr, hostp, spec, &errstr);
654 if (ret == TRYRET_SUCCESS)
656 if (ret != TRYRET_LOCALERR)
658 if ((opflags & ISBGRND) == 0)
659 fprintf(stderr, "%s\n", errstr);
661 /* Exit if all errors were local. */
666 * If retrycnt == 0, we are to keep retrying forever.
667 * Otherwise decrement it, and exit if it hits zero.
669 if (retrycnt != 0 && --retrycnt == 0)
672 if ((opflags & (BGRND | ISBGRND)) == BGRND) {
673 warnx("Cannot immediately mount %s:%s, backgrounding",
676 if (daemon(0, 0) != 0)
681 nfsargsp->hostname = nam;
682 /* Add mounted filesystem to PATH_MOUNTTAB */
683 if (!add_mtab(hostp, spec))
684 warnx("can't update %s for %s:%s", PATH_MOUNTTAB, hostp, spec);
689 * Try to set up the NFS arguments according to the address
690 * (and possibly port) specified by `sinp'.
692 * Returns TRYRET_SUCCESS if successful, or:
693 * TRYRET_TIMEOUT The server did not respond.
694 * TRYRET_REMOTEERR The server reported an error.
695 * TRYRET_LOCALERR Local failure.
697 * In all error cases, *errstr will be set to a statically-allocated string
698 * describing the error.
701 nfs_tryproto(struct nfs_args *nfsargsp, struct sockaddr_in *sinp, char *hostp,
702 char *spec, char **errstr)
704 static char errbuf[256];
705 struct sockaddr_in sin, tmpsin;
706 struct nfhret nfhret;
708 struct rpc_err rpcerr;
710 int doconnect, nfsvers, mntvers, so;
712 enum mountmode trymntmode;
714 trymntmode = mountmode;
717 sin = tmpsin = *sinp;
720 if (trymntmode == V2) {
728 /* Check that the server (nfsd) responds on the port we have chosen. */
732 if (nfsargsp->sotype == SOCK_STREAM)
733 clp = clnttcp_create(&sin, RPCPROG_NFS, nfsvers, &so, 0, 0);
735 clp = clntudp_create(&sin, RPCPROG_NFS, nfsvers, try, &so);
737 snprintf(errbuf, sizeof errbuf, "%s:%s: %s",
738 hostp, spec, clnt_spcreateerror("nfsd: RPCPROG_NFS"));
739 return (returncode(rpc_createerr.cf_stat,
740 &rpc_createerr.cf_error));
742 if (nfsargsp->sotype == SOCK_DGRAM &&
743 !(nfsargsp->flags & NFSMNT_NOCONN)) {
745 * Use connect(), to match what the kernel does. This
746 * catches cases where the server responds from the
747 * wrong source address.
750 if (!clnt_control(clp, CLSET_CONNECT, (char *)&doconnect)) {
752 snprintf(errbuf, sizeof errbuf,
753 "%s:%s: CLSET_CONNECT failed", hostp, spec);
754 return (TRYRET_LOCALERR);
760 stat = clnt_call(clp, NFSPROC_NULL, xdr_void, NULL, xdr_void, NULL,
762 if (stat != RPC_SUCCESS) {
763 if (stat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
768 clnt_geterr(clp, &rpcerr);
769 snprintf(errbuf, sizeof errbuf, "%s:%s: %s",
770 hostp, spec, clnt_sperror(clp, "NFSPROC_NULL"));
772 return (returncode(stat, &rpcerr));
776 /* Send the RPCMNT_MOUNT RPC to get the root filehandle. */
781 if (mnttcp_ok && nfsargsp->sotype == SOCK_STREAM)
782 clp = clnttcp_create(&tmpsin, RPCPROG_MNT, mntvers, &so, 0, 0);
784 clp = clntudp_create(&tmpsin, RPCPROG_MNT, mntvers, try, &so);
786 snprintf(errbuf, sizeof errbuf, "%s:%s: %s",
787 hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create"));
788 return (returncode(rpc_createerr.cf_stat,
789 &rpc_createerr.cf_error));
791 clp->cl_auth = authunix_create_default();
792 if (nfsargsp->flags & NFSMNT_KERB)
793 nfhret.auth = RPCAUTH_KERB4;
795 nfhret.auth = RPCAUTH_UNIX;
796 nfhret.vers = mntvers;
797 stat = clnt_call(clp, RPCMNT_MOUNT, xdr_dir, spec, xdr_fh, &nfhret,
799 auth_destroy(clp->cl_auth);
800 if (stat != RPC_SUCCESS) {
801 if (stat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
806 clnt_geterr(clp, &rpcerr);
807 snprintf(errbuf, sizeof errbuf, "%s:%s: %s",
808 hostp, spec, clnt_sperror(clp, "RPCPROG_MNT"));
810 return (returncode(stat, &rpcerr));
814 if (nfhret.stat != 0) {
815 snprintf(errbuf, sizeof errbuf, "%s:%s: %s",
816 hostp, spec, strerror(nfhret.stat));
817 return (TRYRET_REMOTEERR);
821 * Store the filehandle and server address in nfsargsp, making
822 * sure to copy any locally allocated structures.
824 nfsargsp->addrlen = sin.sin_len;
825 nfsargsp->addr = malloc(nfsargsp->addrlen);
826 nfsargsp->fhsize = nfhret.fhsize;
827 nfsargsp->fh = malloc(nfsargsp->fhsize);
828 if (nfsargsp->addr == NULL || nfsargsp->fh == NULL)
830 bcopy(&sin, nfsargsp->addr, nfsargsp->addrlen);
831 bcopy(nfhret.nfh, nfsargsp->fh, nfsargsp->fhsize);
834 nfsargsp->flags |= NFSMNT_NFSV3;
836 nfsargsp->flags &= ~NFSMNT_NFSV3;
838 return (TRYRET_SUCCESS);
842 * Catagorise a RPC return status and error into an `enum tryret'
846 returncode(enum clnt_stat stat, struct rpc_err *rpcerr)
850 return (TRYRET_TIMEOUT);
851 case RPC_PMAPFAILURE:
852 case RPC_PROGNOTREGISTERED:
853 case RPC_PROGVERSMISMATCH:
854 /* XXX, these can be local or remote. */
857 return (TRYRET_REMOTEERR);
858 case RPC_SYSTEMERROR:
859 switch (rpcerr->re_errno) {
861 return (TRYRET_TIMEOUT);
865 return (TRYRET_REMOTEERR);
871 return (TRYRET_LOCALERR);
875 * xdr routines for mount rpc's
878 xdr_dir(XDR *xdrsp, char *dirp)
880 return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
884 xdr_fh(XDR *xdrsp, register struct nfhret *np)
887 long auth, authcnt, authfnd = 0;
889 if (!xdr_u_long(xdrsp, &np->stat))
895 np->fhsize = NFSX_V2FH;
896 return (xdr_opaque(xdrsp, (caddr_t)np->nfh, NFSX_V2FH));
898 if (!xdr_long(xdrsp, &np->fhsize))
900 if (np->fhsize <= 0 || np->fhsize > NFSX_V3FHMAX)
902 if (!xdr_opaque(xdrsp, (caddr_t)np->nfh, np->fhsize))
904 if (!xdr_long(xdrsp, &authcnt))
906 for (i = 0; i < authcnt; i++) {
907 if (!xdr_long(xdrsp, &auth))
909 if (auth == np->auth)
913 * Some servers, such as DEC's OSF/1 return a nil authenticator
914 * list to indicate RPCAUTH_UNIX.
916 if (!authfnd && (authcnt > 0 || np->auth != RPCAUTH_UNIX))
926 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
927 "usage: mount_nfs [-23KNPTUbcdilqs] [-D deadthresh] [-I readdirsize]",
928 " [-L leaseterm] [-R retrycnt] [-a maxreadahead]",
929 " [-g maxgroups] [-m realm] [-o options] [-r readsize]",
930 " [-t timeout] [-w writesize] [-x retrans] rhost:path node");