2005-05-16 01:18:34 +04:00
|
|
|
/* $NetBSD: mount_nfs.c,v 1.48 2005/05/15 21:18:34 dsl Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1994-06-08 23:23:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Macklem at The University of Guelph.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 23:23:02 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 09:31:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#ifndef lint
|
1997-09-15 09:31:35 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1996-02-18 14:58:24 +03:00
|
|
|
static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2005-05-16 01:18:34 +04:00
|
|
|
__RCSID("$NetBSD: mount_nfs.c,v 1.48 2005/05/15 21:18:34 dsl Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
1995-03-28 21:18:59 +04:00
|
|
|
#include <syslog.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
|
|
|
#ifdef ISO
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#endif
|
|
|
|
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef NFSKERB
|
2003-07-24 01:10:36 +04:00
|
|
|
#include <des.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#include <kerberosIV/krb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <nfs/rpcv2.h>
|
1996-02-18 14:58:24 +03:00
|
|
|
#include <nfs/nfsproto.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#include <nfs/nfs.h>
|
|
|
|
#include <nfs/nqnfs.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <nfs/nfsmount.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-02-03 06:32:43 +03:00
|
|
|
#include <string.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
#include <unistd.h>
|
2002-09-21 22:43:31 +04:00
|
|
|
#include <util.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2003-03-22 14:15:45 +03:00
|
|
|
#include <mntopts.h>
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2005-05-16 01:18:34 +04:00
|
|
|
#include "mount_nfs.h"
|
|
|
|
|
2003-04-11 21:39:09 +04:00
|
|
|
#define ALTF_BG 0x00000001
|
|
|
|
#define ALTF_CONN 0x00000002
|
|
|
|
#define ALTF_DUMBTIMR 0x00000004
|
|
|
|
#define ALTF_INTR 0x00000008
|
|
|
|
#define ALTF_KERB 0x00000010
|
|
|
|
#define ALTF_NFSV3 0x00000020
|
|
|
|
#define ALTF_RDIRPLUS 0x00000040
|
|
|
|
#define ALTF_MNTUDP 0x00000080
|
|
|
|
#define ALTF_NORESPORT 0x00000100
|
|
|
|
#define ALTF_SEQPACKET 0x00000200
|
|
|
|
#define ALTF_NQNFS 0x00000400
|
|
|
|
#define ALTF_SOFT 0x00000800
|
|
|
|
#define ALTF_TCP 0x00001000
|
|
|
|
#define ALTF_NFSV2 0x00002000
|
|
|
|
#define ALTF_PORT 0x00004000
|
|
|
|
#define ALTF_RSIZE 0x00008000
|
|
|
|
#define ALTF_WSIZE 0x00010000
|
|
|
|
#define ALTF_RDIRSIZE 0x00020000
|
|
|
|
#define ALTF_MAXGRPS 0x00040000
|
|
|
|
#define ALTF_LEASETERM 0x00080000
|
|
|
|
#define ALTF_READAHEAD 0x00100000
|
|
|
|
#define ALTF_DEADTHRESH 0x00200000
|
|
|
|
#define ALTF_TIMEO 0x00400000
|
|
|
|
#define ALTF_RETRANS 0x00800000
|
1996-02-18 14:58:24 +03:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static const struct mntopt mopts[] = {
|
1994-06-08 23:23:02 +04:00
|
|
|
MOPT_STDOPTS,
|
|
|
|
MOPT_FORCE,
|
|
|
|
MOPT_UPDATE,
|
2002-09-21 22:43:31 +04:00
|
|
|
MOPT_GETARGS,
|
1996-02-18 14:58:24 +03:00
|
|
|
{ "bg", 0, ALTF_BG, 1 },
|
1996-10-28 00:18:03 +03:00
|
|
|
{ "conn", 0, ALTF_CONN, 1 },
|
1996-02-18 14:58:24 +03:00
|
|
|
{ "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
|
|
|
|
{ "intr", 0, ALTF_INTR, 1 },
|
|
|
|
#ifdef NFSKERB
|
|
|
|
{ "kerb", 0, ALTF_KERB, 1 },
|
|
|
|
#endif
|
|
|
|
{ "nfsv3", 0, ALTF_NFSV3, 1 },
|
|
|
|
{ "rdirplus", 0, ALTF_RDIRPLUS, 1 },
|
|
|
|
{ "mntudp", 0, ALTF_MNTUDP, 1 },
|
1997-03-23 23:59:56 +03:00
|
|
|
{ "noresport", 0, ALTF_NORESPORT, 1 },
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef ISO
|
|
|
|
{ "seqpacket", 0, ALTF_SEQPACKET, 1 },
|
|
|
|
#endif
|
|
|
|
{ "nqnfs", 0, ALTF_NQNFS, 1 },
|
|
|
|
{ "soft", 0, ALTF_SOFT, 1 },
|
|
|
|
{ "tcp", 0, ALTF_TCP, 1 },
|
1996-05-24 02:52:49 +04:00
|
|
|
{ "nfsv2", 0, ALTF_NFSV2, 1 },
|
2003-04-11 21:39:09 +04:00
|
|
|
{ "port", 0, ALTF_PORT, 1 },
|
|
|
|
{ "rsize", 0, ALTF_RSIZE, 1 },
|
|
|
|
{ "wsize", 0, ALTF_WSIZE, 1 },
|
|
|
|
{ "rdirsize", 0, ALTF_RDIRSIZE, 1 },
|
|
|
|
{ "maxgrps", 0, ALTF_MAXGRPS, 1 },
|
|
|
|
{ "leaseterm", 0, ALTF_LEASETERM, 1 },
|
|
|
|
{ "readahead", 0, ALTF_READAHEAD, 1 },
|
|
|
|
{ "deadthresh", 0, ALTF_DEADTHRESH, 1 },
|
|
|
|
{ "timeo", 0, ALTF_TIMEO, 1 },
|
1994-06-08 23:23:02 +04:00
|
|
|
{ NULL }
|
2003-04-11 21:39:09 +04:00
|
|
|
|
1994-06-08 23:23:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nfs_args nfsdefargs = {
|
1996-02-18 14:58:24 +03:00
|
|
|
NFS_ARGSVERSION,
|
1994-06-08 23:23:02 +04:00
|
|
|
(struct sockaddr *)0,
|
|
|
|
sizeof (struct sockaddr_in),
|
|
|
|
SOCK_DGRAM,
|
|
|
|
0,
|
1996-02-18 14:58:24 +03:00
|
|
|
(u_char *)0,
|
1994-06-08 23:23:02 +04:00
|
|
|
0,
|
1997-03-23 23:59:56 +03:00
|
|
|
NFSMNT_NFSV3|NFSMNT_NOCONN|NFSMNT_RESVPORT,
|
1994-06-08 23:23:02 +04:00
|
|
|
NFS_WSIZE,
|
|
|
|
NFS_RSIZE,
|
1996-02-18 14:58:24 +03:00
|
|
|
NFS_READDIRSIZE,
|
|
|
|
10,
|
1994-06-08 23:23:02 +04:00
|
|
|
NFS_RETRANS,
|
|
|
|
NFS_MAXGRPS,
|
|
|
|
NFS_DEFRAHEAD,
|
|
|
|
NQ_DEFLEASE,
|
|
|
|
NQ_DEADTHRESH,
|
|
|
|
(char *)0,
|
|
|
|
};
|
|
|
|
|
2005-05-16 01:18:34 +04:00
|
|
|
int retrycnt = 0;
|
1994-06-08 23:23:02 +04:00
|
|
|
int opflags = 0;
|
1996-02-18 14:58:24 +03:00
|
|
|
int nfsproto = IPPROTO_UDP;
|
|
|
|
int force2 = 0;
|
|
|
|
int force3 = 0;
|
2000-06-09 04:06:36 +04:00
|
|
|
int mnttcp_ok = 1;
|
2003-04-11 21:39:09 +04:00
|
|
|
int port = 0;
|
1994-06-08 23:23:02 +04:00
|
|
|
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef NFSKERB
|
2000-10-30 23:56:57 +03:00
|
|
|
static char inst[INST_SZ];
|
|
|
|
static char realm[REALM_SZ];
|
|
|
|
static struct {
|
1996-02-18 14:58:24 +03:00
|
|
|
u_long kind;
|
|
|
|
KTEXT_ST kt;
|
|
|
|
} ktick;
|
2000-10-30 23:56:57 +03:00
|
|
|
static struct nfsrpc_nickverf kverf;
|
|
|
|
static struct nfsrpc_fullblock kin, kout;
|
|
|
|
static NFSKERBKEY_T kivec;
|
|
|
|
static CREDENTIALS kcr;
|
|
|
|
static struct timeval ktv;
|
|
|
|
static NFSKERBKEYSCHED_T kerb_keysched;
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif
|
|
|
|
|
2005-02-05 17:55:44 +03:00
|
|
|
static void shownfsargs(const struct nfs_args *);
|
1994-06-08 23:23:02 +04:00
|
|
|
#ifdef ISO
|
2005-02-05 17:55:44 +03:00
|
|
|
static struct iso_addr *iso_addr(const char *);
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif
|
2005-02-05 17:55:44 +03:00
|
|
|
int mount_nfs(int argc, char **argv);
|
|
|
|
/* void set_rpc_maxgrouplist(int); */
|
|
|
|
static void usage(void);
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
#ifndef MOUNT_NOMAIN
|
1994-06-08 23:23:02 +04:00
|
|
|
int
|
2005-02-05 17:55:44 +03:00
|
|
|
main(int argc, char **argv)
|
2000-10-30 23:56:57 +03:00
|
|
|
{
|
|
|
|
return mount_nfs(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
2005-02-05 17:55:44 +03:00
|
|
|
mount_nfs(int argc, char *argv[])
|
1994-06-08 23:23:02 +04:00
|
|
|
{
|
2002-06-16 06:27:31 +04:00
|
|
|
int c, retval;
|
1997-09-15 09:31:35 +04:00
|
|
|
struct nfs_args *nfsargsp;
|
1994-06-08 23:23:02 +04:00
|
|
|
struct nfs_args nfsargs;
|
|
|
|
struct nfsd_cargs ncd;
|
2002-10-21 07:58:07 +04:00
|
|
|
struct sockaddr_storage sa;
|
1996-02-18 14:58:24 +03:00
|
|
|
int mntflags, altflags, i, nfssvc_flag, num;
|
2005-01-31 08:19:18 +03:00
|
|
|
char name[MAXPATHLEN], *p, *spec, *ospec;
|
2003-04-11 21:39:09 +04:00
|
|
|
mntoptparse_t mp;
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef NFSKERB
|
1994-06-08 23:23:02 +04:00
|
|
|
uid_t last_ruid;
|
|
|
|
|
|
|
|
last_ruid = -1;
|
1994-07-27 07:16:06 +04:00
|
|
|
if (krb_get_lrealm(realm, 0) != KSUCCESS)
|
2003-07-13 12:05:58 +04:00
|
|
|
(void)strlcpy(realm, KRB_REALM, sizeof(realm));
|
1996-02-18 14:58:24 +03:00
|
|
|
if (sizeof (struct nfsrpc_nickverf) != RPCX_NICKVERF ||
|
|
|
|
sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK ||
|
|
|
|
((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED ||
|
|
|
|
((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED)
|
2002-10-01 07:08:56 +04:00
|
|
|
warnx("Yikes! NFSKERB structs not packed!!\n");
|
1994-06-08 23:23:02 +04:00
|
|
|
#endif
|
|
|
|
retrycnt = DEF_RETRY;
|
|
|
|
|
|
|
|
mntflags = 0;
|
1996-02-18 14:58:24 +03:00
|
|
|
altflags = 0;
|
1994-06-08 23:23:02 +04:00
|
|
|
nfsargs = nfsdefargs;
|
|
|
|
nfsargsp = &nfsargs;
|
|
|
|
while ((c = getopt(argc, argv,
|
1997-10-19 05:24:47 +04:00
|
|
|
"23a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
|
1994-06-08 23:23:02 +04:00
|
|
|
switch (c) {
|
1996-02-18 14:58:24 +03:00
|
|
|
case '3':
|
|
|
|
if (force2)
|
|
|
|
errx(1, "-2 and -3 are mutually exclusive");
|
|
|
|
force3 = 1;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
if (force3)
|
|
|
|
errx(1, "-2 and -3 are mutually exclusive");
|
|
|
|
force2 = 1;
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'a':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num < 0)
|
|
|
|
errx(1, "illegal -a value -- %s", optarg);
|
|
|
|
nfsargsp->readahead = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_READAHEAD;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
opflags |= BGRND;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
nfsargsp->flags |= NFSMNT_NOCONN;
|
|
|
|
break;
|
1996-10-28 00:18:03 +03:00
|
|
|
case 'C':
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NOCONN;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'D':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -D value -- %s", optarg);
|
|
|
|
nfsargsp->deadthresh = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_DEADTHRESH;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
nfsargsp->flags |= NFSMNT_DUMBTIMR;
|
|
|
|
break;
|
1994-06-24 16:04:53 +04:00
|
|
|
#if 0 /* XXXX */
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'g':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -g value -- %s", optarg);
|
|
|
|
set_rpc_maxgrouplist(num);
|
|
|
|
nfsargsp->maxgrouplist = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_MAXGRPS;
|
|
|
|
break;
|
1994-06-24 16:04:53 +04:00
|
|
|
#endif
|
1996-02-18 14:58:24 +03:00
|
|
|
case 'I':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -I value -- %s", optarg);
|
|
|
|
nfsargsp->readdirsize = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_READDIRSIZE;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'i':
|
|
|
|
nfsargsp->flags |= NFSMNT_INT;
|
|
|
|
break;
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef NFSKERB
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'K':
|
|
|
|
nfsargsp->flags |= NFSMNT_KERB;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'L':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num < 2)
|
|
|
|
errx(1, "illegal -L value -- %s", optarg);
|
|
|
|
nfsargsp->leaseterm = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_LEASETERM;
|
|
|
|
break;
|
|
|
|
case 'l':
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_RDIRPLUS;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef NFSKERB
|
1994-06-08 23:23:02 +04:00
|
|
|
case 'm':
|
2003-07-13 12:05:58 +04:00
|
|
|
(void)strlcpy(realm, optarg, sizeof(realm));
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'o':
|
2003-04-11 21:39:09 +04:00
|
|
|
mp = getmntopts(optarg, mopts, &mntflags, &altflags);
|
|
|
|
if (mp == NULL)
|
|
|
|
err(1, NULL);
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_BG)
|
1996-02-18 14:58:24 +03:00
|
|
|
opflags |= BGRND;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_CONN)
|
1996-10-28 00:18:03 +03:00
|
|
|
nfsargsp->flags &= ~NFSMNT_NOCONN;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_DUMBTIMR)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_DUMBTIMR;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_INTR)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_INT;
|
|
|
|
#ifdef NFSKERB
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_KERB)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_KERB;
|
|
|
|
#endif
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_NFSV3) {
|
1996-05-24 02:52:49 +04:00
|
|
|
if (force2)
|
2002-10-01 07:08:56 +04:00
|
|
|
errx(1, "conflicting version options");
|
1996-05-24 02:52:49 +04:00
|
|
|
force3 = 1;
|
|
|
|
}
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_NFSV2) {
|
1996-05-24 02:52:49 +04:00
|
|
|
if (force3)
|
2002-10-01 07:08:56 +04:00
|
|
|
errx(1, "conflicting version options");
|
1996-05-24 02:52:49 +04:00
|
|
|
force2 = 1;
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
|
|
|
}
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_RDIRPLUS)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_RDIRPLUS;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_MNTUDP)
|
1996-02-18 14:58:24 +03:00
|
|
|
mnttcp_ok = 0;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_NORESPORT)
|
1997-03-23 23:59:56 +03:00
|
|
|
nfsargsp->flags &= ~NFSMNT_RESVPORT;
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef ISO
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_SEQPACKET)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->sotype = SOCK_SEQPACKET;
|
|
|
|
#endif
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_NQNFS) {
|
1996-05-24 02:52:49 +04:00
|
|
|
if (force2)
|
2002-10-01 07:08:56 +04:00
|
|
|
errx(1, "nqnfs only available with v3");
|
1996-05-24 02:52:49 +04:00
|
|
|
force3 = 1;
|
|
|
|
nfsargsp->flags |= NFSMNT_NQNFS;
|
|
|
|
}
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_SOFT)
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->flags |= NFSMNT_SOFT;
|
2002-10-01 07:08:56 +04:00
|
|
|
if (altflags & ALTF_TCP) {
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsargsp->sotype = SOCK_STREAM;
|
|
|
|
nfsproto = IPPROTO_TCP;
|
|
|
|
}
|
2003-04-11 21:39:09 +04:00
|
|
|
if (altflags & ALTF_PORT) {
|
|
|
|
port = getmntoptnum(mp, "port");
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_RSIZE) {
|
|
|
|
nfsargsp->rsize =
|
|
|
|
(int)getmntoptnum(mp, "rsize");
|
|
|
|
nfsargsp->flags |= NFSMNT_RSIZE;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_WSIZE) {
|
2003-05-16 19:33:45 +04:00
|
|
|
nfsargsp->wsize =
|
2003-04-11 21:39:09 +04:00
|
|
|
(int)getmntoptnum(mp, "wsize");
|
|
|
|
nfsargsp->flags |= NFSMNT_WSIZE;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_RDIRSIZE) {
|
|
|
|
nfsargsp->rsize =
|
|
|
|
(int)getmntoptnum(mp, "rdirsize");
|
|
|
|
nfsargsp->flags |= NFSMNT_READDIRSIZE;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (altflags & ALTF_MAXGRPS) {
|
|
|
|
set_rpc_maxgrouplist(num);
|
|
|
|
nfsargsp->maxgrouplist =
|
|
|
|
(int)getmntoptnum(mp, "maxgrps");
|
|
|
|
nfsargsp->flags |= NFSMNT_MAXGRPS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (altflags & ALTF_LEASETERM) {
|
|
|
|
nfsargsp->leaseterm =
|
|
|
|
(int)getmntoptnum(mp, "leaseterm");
|
|
|
|
nfsargsp->flags |= NFSMNT_LEASETERM;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_READAHEAD) {
|
|
|
|
nfsargsp->readahead =
|
|
|
|
(int)getmntoptnum(mp, "readahead");
|
|
|
|
nfsargsp->flags |= NFSMNT_READAHEAD;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_DEADTHRESH) {
|
|
|
|
nfsargsp->deadthresh =
|
|
|
|
(int)getmntoptnum(mp, "deadthresh");
|
|
|
|
nfsargsp->flags |= NFSMNT_DEADTHRESH;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_TIMEO) {
|
|
|
|
nfsargsp->timeo =
|
|
|
|
(int)getmntoptnum(mp, "timeo");
|
|
|
|
nfsargsp->flags |= NFSMNT_TIMEO;
|
|
|
|
}
|
|
|
|
if (altflags & ALTF_RETRANS) {
|
|
|
|
nfsargsp->retrans =
|
|
|
|
(int)getmntoptnum(mp, "retrans");
|
|
|
|
nfsargsp->flags |= NFSMNT_RETRANS;
|
|
|
|
}
|
1996-02-18 14:58:24 +03:00
|
|
|
altflags = 0;
|
2003-04-11 21:39:09 +04:00
|
|
|
freemntopts(mp);
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
nfsargsp->flags |= NFSMNT_RESVPORT;
|
|
|
|
break;
|
|
|
|
case 'p':
|
1997-03-23 23:59:56 +03:00
|
|
|
nfsargsp->flags &= ~NFSMNT_RESVPORT;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'q':
|
1996-05-24 02:52:49 +04:00
|
|
|
if (force2)
|
2002-10-01 07:08:56 +04:00
|
|
|
errx(1, "nqnfs only available with v3");
|
1996-05-24 02:52:49 +04:00
|
|
|
force3 = 1;
|
|
|
|
nfsargsp->flags |= NFSMNT_NQNFS;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -R value -- %s", optarg);
|
|
|
|
retrycnt = num;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -r value -- %s", optarg);
|
|
|
|
nfsargsp->rsize = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_RSIZE;
|
|
|
|
break;
|
1997-03-23 23:59:56 +03:00
|
|
|
#ifdef ISO
|
|
|
|
case 'S':
|
|
|
|
nfsargsp->sotype = SOCK_SEQPACKET;
|
|
|
|
break;
|
|
|
|
#endif
|
1994-06-08 23:23:02 +04:00
|
|
|
case 's':
|
|
|
|
nfsargsp->flags |= NFSMNT_SOFT;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
nfsargsp->sotype = SOCK_STREAM;
|
1996-02-18 14:58:24 +03:00
|
|
|
nfsproto = IPPROTO_TCP;
|
1994-06-08 23:23:02 +04:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -t value -- %s", optarg);
|
|
|
|
nfsargsp->timeo = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_TIMEO;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -w value -- %s", optarg);
|
|
|
|
nfsargsp->wsize = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_WSIZE;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
num = strtol(optarg, &p, 10);
|
|
|
|
if (*p || num <= 0)
|
|
|
|
errx(1, "illegal -x value -- %s", optarg);
|
|
|
|
nfsargsp->retrans = num;
|
|
|
|
nfsargsp->flags |= NFSMNT_RETRANS;
|
|
|
|
break;
|
1997-10-19 05:24:47 +04:00
|
|
|
case 'X':
|
|
|
|
nfsargsp->flags |= NFSMNT_XLATECOOKIE;
|
|
|
|
break;
|
1996-02-18 14:58:24 +03:00
|
|
|
case 'U':
|
|
|
|
mnttcp_ok = 0;
|
|
|
|
break;
|
1994-06-08 23:23:02 +04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 2)
|
1994-12-29 03:48:42 +03:00
|
|
|
usage();
|
1994-06-08 23:23:02 +04:00
|
|
|
|
|
|
|
spec = *argv++;
|
2005-01-31 08:19:18 +03:00
|
|
|
if (realpath(*argv, name) == NULL) /* Check mounton path */
|
|
|
|
err(1, "realpath %s", *argv);
|
|
|
|
if (strncmp(*argv, name, MAXPATHLEN)) {
|
|
|
|
warnx("\"%s\" is a relative path.", *argv);
|
|
|
|
warnx("using \"%s\" instead.", name);
|
|
|
|
}
|
|
|
|
|
2002-10-01 07:08:56 +04:00
|
|
|
if ((ospec = strdup(spec)) == NULL) {
|
|
|
|
err(1, "strdup");
|
1999-06-25 23:28:35 +04:00
|
|
|
}
|
1994-06-08 23:23:02 +04:00
|
|
|
|
2002-10-21 07:58:07 +04:00
|
|
|
if ((mntflags & MNT_GETARGS) != 0) {
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
nfsargsp->addr = (struct sockaddr *)&sa;
|
|
|
|
nfsargsp->addrlen = sizeof(sa);
|
|
|
|
} else {
|
2002-09-21 22:43:31 +04:00
|
|
|
if (!getnfsargs(spec, nfsargsp))
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-06-16 06:27:31 +04:00
|
|
|
if ((retval = mount(MOUNT_NFS, name, mntflags, nfsargsp))) {
|
|
|
|
/* Did we just default to v3 on a v2-only kernel?
|
|
|
|
* If so, default to v2 & try again */
|
|
|
|
if ((errno == EPROGMISMATCH) && !force3) {
|
|
|
|
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
|
|
|
retval = mount(MOUNT_NFS, name, mntflags, nfsargsp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (retval)
|
1999-06-25 23:28:35 +04:00
|
|
|
err(1, "%s on %s", ospec, name);
|
2002-09-21 22:43:31 +04:00
|
|
|
if (mntflags & MNT_GETARGS) {
|
|
|
|
shownfsargs(nfsargsp);
|
2002-10-21 07:58:07 +04:00
|
|
|
return (0);
|
2002-09-21 22:43:31 +04:00
|
|
|
}
|
|
|
|
|
1994-06-08 23:23:02 +04:00
|
|
|
if (nfsargsp->flags & (NFSMNT_NQNFS | NFSMNT_KERB)) {
|
|
|
|
if ((opflags & ISBGRND) == 0) {
|
1997-09-15 09:31:35 +04:00
|
|
|
if ((i = fork()) != 0) {
|
1994-06-08 23:23:02 +04:00
|
|
|
if (i == -1)
|
|
|
|
err(1, "nqnfs 1");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
(void) setsid();
|
|
|
|
(void) close(STDIN_FILENO);
|
|
|
|
(void) close(STDOUT_FILENO);
|
|
|
|
(void) close(STDERR_FILENO);
|
|
|
|
(void) chdir("/");
|
|
|
|
}
|
2001-01-11 04:33:35 +03:00
|
|
|
openlog("mount_nfs", LOG_PID, LOG_DAEMON);
|
1994-06-08 23:23:02 +04:00
|
|
|
nfssvc_flag = NFSSVC_MNTD;
|
|
|
|
ncd.ncd_dirp = name;
|
|
|
|
while (nfssvc(nfssvc_flag, (caddr_t)&ncd) < 0) {
|
|
|
|
if (errno != ENEEDAUTH) {
|
|
|
|
syslog(LOG_ERR, "nfssvc err %m");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nfssvc_flag =
|
|
|
|
NFSSVC_MNTD | NFSSVC_GOTAUTH | NFSSVC_AUTHINFAIL;
|
1996-02-18 14:58:24 +03:00
|
|
|
#ifdef NFSKERB
|
1994-06-08 23:23:02 +04:00
|
|
|
/*
|
|
|
|
* Set up as ncd_authuid for the kerberos call.
|
|
|
|
* Must set ruid to ncd_authuid and reset the
|
|
|
|
* ticket name iff ncd_authuid is not the same
|
|
|
|
* as last time, so that the right ticket file
|
|
|
|
* is found.
|
1996-02-18 14:58:24 +03:00
|
|
|
* Get the Kerberos credential structure so that
|
|
|
|
* we have the seesion key and get a ticket for
|
|
|
|
* this uid.
|
|
|
|
* For more info see the IETF Draft "Authentication
|
|
|
|
* in ONC RPC".
|
1994-06-08 23:23:02 +04:00
|
|
|
*/
|
|
|
|
if (ncd.ncd_authuid != last_ruid) {
|
|
|
|
krb_set_tkt_string("");
|
|
|
|
last_ruid = ncd.ncd_authuid;
|
|
|
|
}
|
|
|
|
setreuid(ncd.ncd_authuid, 0);
|
1996-02-18 14:58:24 +03:00
|
|
|
kret = krb_get_cred(NFS_KERBSRV, inst, realm, &kcr);
|
|
|
|
if (kret == RET_NOTKT) {
|
|
|
|
kret = get_ad_tkt(NFS_KERBSRV, inst, realm,
|
|
|
|
DEFAULT_TKT_LIFE);
|
|
|
|
if (kret == KSUCCESS)
|
|
|
|
kret = krb_get_cred(NFS_KERBSRV, inst, realm,
|
|
|
|
&kcr);
|
|
|
|
}
|
|
|
|
if (kret == KSUCCESS)
|
|
|
|
kret = krb_mk_req(&ktick.kt, NFS_KERBSRV, inst,
|
|
|
|
realm, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the AKN_FULLNAME authenticator and verfier.
|
|
|
|
* Along with the Kerberos ticket, we need to build
|
|
|
|
* the timestamp verifier and encrypt it in CBC mode.
|
|
|
|
*/
|
|
|
|
if (kret == KSUCCESS &&
|
|
|
|
ktick.kt.length <= (RPCAUTH_MAXSIZ-3*NFSX_UNSIGNED)
|
|
|
|
&& gettimeofday(&ktv, (struct timezone *)0) == 0) {
|
|
|
|
ncd.ncd_authtype = RPCAUTH_KERB4;
|
|
|
|
ncd.ncd_authstr = (u_char *)&ktick;
|
|
|
|
ncd.ncd_authlen = nfsm_rndup(ktick.kt.length) +
|
|
|
|
3 * NFSX_UNSIGNED;
|
|
|
|
ncd.ncd_verfstr = (u_char *)&kverf;
|
|
|
|
ncd.ncd_verflen = sizeof (kverf);
|
|
|
|
memmove(ncd.ncd_key, kcr.session,
|
|
|
|
sizeof (kcr.session));
|
|
|
|
kin.t1 = htonl(ktv.tv_sec);
|
|
|
|
kin.t2 = htonl(ktv.tv_usec);
|
|
|
|
kin.w1 = htonl(NFS_KERBTTL);
|
|
|
|
kin.w2 = htonl(NFS_KERBTTL - 1);
|
1997-09-15 09:31:35 +04:00
|
|
|
memset((caddr_t)kivec, 0, sizeof (kivec));
|
1996-02-18 14:58:24 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Encrypt kin in CBC mode using the session
|
|
|
|
* key in kcr.
|
|
|
|
*/
|
|
|
|
XXX
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, fill the timestamp verifier into the
|
|
|
|
* authenticator and verifier.
|
|
|
|
*/
|
|
|
|
ktick.kind = htonl(RPCAKN_FULLNAME);
|
|
|
|
kverf.kind = htonl(RPCAKN_FULLNAME);
|
|
|
|
NFS_KERBW1(ktick.kt) = kout.w1;
|
|
|
|
ktick.kt.length = htonl(ktick.kt.length);
|
|
|
|
kverf.verf.t1 = kout.t1;
|
|
|
|
kverf.verf.t2 = kout.t2;
|
|
|
|
kverf.verf.w2 = kout.w2;
|
|
|
|
nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH;
|
1994-06-08 23:23:02 +04:00
|
|
|
}
|
|
|
|
setreuid(0, 0);
|
1996-02-18 14:58:24 +03:00
|
|
|
#endif /* NFSKERB */
|
1994-06-08 23:23:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2002-09-21 22:43:31 +04:00
|
|
|
static void
|
2005-02-05 17:55:44 +03:00
|
|
|
shownfsargs(const struct nfs_args *nfsargsp)
|
2002-09-21 22:43:31 +04:00
|
|
|
{
|
|
|
|
char fbuf[2048];
|
2002-10-21 07:58:07 +04:00
|
|
|
char host[NI_MAXHOST], serv[NI_MAXSERV];
|
|
|
|
int error;
|
2002-09-21 22:43:31 +04:00
|
|
|
|
|
|
|
(void)snprintb(fbuf, sizeof(fbuf), NFSMNT_BITS, nfsargsp->flags);
|
2002-10-21 07:58:07 +04:00
|
|
|
if (nfsargsp->addr != NULL) {
|
|
|
|
error = getnameinfo(nfsargsp->addr, nfsargsp->addrlen, host,
|
|
|
|
sizeof(host), serv, sizeof(serv),
|
|
|
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
|
|
|
if (error != 0)
|
|
|
|
warnx("getnameinfo: %s", gai_strerror(error));
|
|
|
|
} else
|
|
|
|
error = -1;
|
|
|
|
|
|
|
|
if (error == 0)
|
2003-04-10 08:40:38 +04:00
|
|
|
printf("addr=%s, port=%s, addrlen=%d, ",
|
2002-10-21 07:58:07 +04:00
|
|
|
host, serv, nfsargsp->addrlen);
|
2003-04-07 17:31:17 +04:00
|
|
|
printf("sotype=%d, proto=%d, fhsize=%d, "
|
2002-09-21 22:43:31 +04:00
|
|
|
"flags=%s, wsize=%d, rsize=%d, readdirsize=%d, timeo=%d, "
|
|
|
|
"retrans=%d, maxgrouplist=%d, readahead=%d, leaseterm=%d, "
|
|
|
|
"deadthresh=%d\n",
|
|
|
|
nfsargsp->sotype,
|
|
|
|
nfsargsp->proto,
|
|
|
|
nfsargsp->fhsize,
|
|
|
|
fbuf,
|
|
|
|
nfsargsp->wsize,
|
|
|
|
nfsargsp->rsize,
|
|
|
|
nfsargsp->readdirsize,
|
|
|
|
nfsargsp->timeo,
|
|
|
|
nfsargsp->retrans,
|
|
|
|
nfsargsp->maxgrouplist,
|
|
|
|
nfsargsp->readahead,
|
|
|
|
nfsargsp->leaseterm,
|
|
|
|
nfsargsp->deadthresh);
|
|
|
|
}
|
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static void
|
2005-02-05 17:55:44 +03:00
|
|
|
usage(void)
|
1994-06-08 23:23:02 +04:00
|
|
|
{
|
1999-11-21 03:53:58 +03:00
|
|
|
(void)fprintf(stderr, "usage: mount_nfs %s\n%s\n%s\n%s\n%s\n",
|
|
|
|
"[-23bcCdiKlpPqsTUX] [-a maxreadahead] [-D deadthresh]",
|
|
|
|
"\t[-g maxgroups] [-I readdirsize] [-L leaseterm] [-m realm]",
|
|
|
|
"\t[-o options] [-R retrycnt] [-r readsize] [-t timeout]",
|
|
|
|
"\t[-w writesize] [-x retrans]",
|
1994-06-08 23:23:02 +04:00
|
|
|
"\trhost:path node");
|
|
|
|
exit(1);
|
|
|
|
}
|