[Midnightbsd-cvs] src: usr.sbin/mountd: merge
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Nov 23 17:23:29 EST 2008
Log Message:
-----------
merge
Modified Files:
--------------
src/usr.sbin/mountd:
Makefile (r1.1.1.2 -> r1.2)
exports.5 (r1.1.1.1 -> r1.2)
mountd.8 (r1.1.1.1 -> r1.2)
mountd.c (r1.1.1.2 -> r1.2)
-------------- next part --------------
Index: mountd.8
===================================================================
RCS file: /home/cvs/src/usr.sbin/mountd/mountd.8,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/mountd/mountd.8 -L usr.sbin/mountd/mountd.8 -u -r1.1.1.1 -r1.2
--- usr.sbin/mountd/mountd.8
+++ usr.sbin/mountd/mountd.8
@@ -26,9 +26,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)mountd.8 8.4 (Berkeley) 4/28/95
-.\" $FreeBSD: src/usr.sbin/mountd/mountd.8,v 1.27 2004/08/07 04:27:51 imp Exp $
+.\" $FreeBSD: src/usr.sbin/mountd/mountd.8,v 1.30 2007/02/03 00:15:46 pjd Exp $
.\"
-.Dd April 28, 1995
+.Dd February 3, 2007
.Dt MOUNTD 8
.Os
.Sh NAME
@@ -40,7 +40,7 @@
.Nm
.Op Fl 2dlnr
.Op Fl p Ar port
-.Op Ar exportsfile
+.Op Ar exportsfile ...
.Sh DESCRIPTION
The
.Nm
@@ -64,6 +64,9 @@
protocol to mount file systems from this server.
.It Fl d
Output debugging information.
+.Nm
+will not detach from the controlling terminal and will print
+debugging messages to stderr.
.It Fl l
Cause all succeeded
.Nm
@@ -103,6 +106,7 @@
.It Ar exportsfile
Specify an alternate location
for the exports file.
+More than one exports file can be specified.
.El
.Pp
When
Index: exports.5
===================================================================
RCS file: /home/cvs/src/usr.sbin/mountd/exports.5,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/mountd/exports.5 -L usr.sbin/mountd/exports.5 -u -r1.1.1.1 -r1.2
--- usr.sbin/mountd/exports.5
+++ usr.sbin/mountd/exports.5
@@ -26,7 +26,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)exports.5 8.3 (Berkeley) 3/29/95
-.\" $FreeBSD: src/usr.sbin/mountd/exports.5,v 1.27 2004/08/07 04:27:51 imp Exp $
+.\" $FreeBSD: src/usr.sbin/mountd/exports.5,v 1.28 2006/01/29 08:44:05 jkoshy Exp $
.\"
.Dd March 29, 1995
.Dt EXPORTS 5
@@ -180,7 +180,7 @@
.Pp
A
.Sm off
-.Fl index No = Sy file
+.Fl index No = Pa file
.Sm on
option can be used to specify a file whose handle will be returned if
a directory is looked up using the public filehandle
@@ -275,14 +275,14 @@
.Ed
.Pp
Given that
-.Sy /usr ,
-.Sy /u
+.Pa /usr ,
+.Pa /u
and
-.Sy /u2
+.Pa /u2
are
local file system mount points, the above example specifies the following:
.Pp
-.Sy /usr
+.Pa /usr
is exported to hosts
.Em friends
where friends is specified in the netgroup file
@@ -299,23 +299,23 @@
it is exported to the rest of the world as read-only with
all users mapped to the user and groups associated with ``nobody''.
.Pp
-.Sy /u
+.Pa /u
is exported to all hosts on the subnetwork
.Em 131.104.48
with root mapped to the uid for ``bin'' and with no group access.
.Pp
-.Sy /u2
+.Pa /u2
is exported to the hosts in ``friends'' with root mapped to uid and groups
associated with ``root'';
it is exported to all hosts on network ``cis-net'' allowing mounts at any
directory within /u2.
.Pp
The file system rooted at
-.Sy /cdrom
+.Pa /cdrom
will exported read-only to the entire network 192.168.33.0/24, including
all its subdirectories.
Since
-.Sy /cdrom
+.Pa /cdrom
is the conventional mountpoint for a CD-ROM device, this export will
fail if no CD-ROM medium is currently mounted there since that line
would then attempt to export a subdirectory of the root file system
@@ -331,15 +331,15 @@
will notify
.Xr mountd 8
about this situation, and the
-.Sy /cdrom
+.Pa /cdrom
file system will be exported as intended.
Note that without using the
.Fl alldirs
option, the export would always succeed.
While there is no CD-ROM medium mounted under
-.Sy /cdrom ,
+.Pa /cdrom ,
it would export the (normally empty) directory
-.Sy /cdrom
+.Pa /cdrom
of the root file system instead.
.Sh SEE ALSO
.Xr netgroup 5 ,
Index: mountd.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/mountd/mountd.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L usr.sbin/mountd/mountd.c -L usr.sbin/mountd/mountd.c -u -r1.1.1.2 -r1.2
--- usr.sbin/mountd/mountd.c
+++ usr.sbin/mountd/mountd.c
@@ -43,7 +43,7 @@
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/mountd/mountd.c,v 1.81.2.1 2006/01/15 17:50:37 delphij Exp $");
+__FBSDID("$FreeBSD: src/usr.sbin/mountd/mountd.c,v 1.94 2007/04/13 10:25:49 pjd Exp $");
#include <sys/param.h>
#include <sys/mount.h>
@@ -62,10 +62,6 @@
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
#include <nfsserver/nfs.h>
-#include <ufs/ufs/ufsmount.h>
-#include <fs/msdosfs/msdosfsmount.h>
-#include <fs/ntfs/ntfsmount.h>
-#include <isofs/cd9660/cd9660_mount.h> /* XXX need isofs in include */
#include <arpa/inet.h>
@@ -83,6 +79,7 @@
#include <string.h>
#include <unistd.h>
#include "pathnames.h"
+#include "mntopts.h"
#ifdef DEBUG
#include <stdarg.h>
@@ -208,7 +205,8 @@
struct exportlist *exphead;
struct mountlist *mlhead;
struct grouplist *grphead;
-char exname[MAXPATHLEN];
+char *exnames_default[2] = { _PATH_EXPORTS, NULL };
+char **exnames;
struct xucred def_anon = {
XUCRED_VERSION,
(uid_t)-2,
@@ -325,11 +323,10 @@
grphead = (struct grouplist *)NULL;
exphead = (struct exportlist *)NULL;
mlhead = (struct mountlist *)NULL;
- if (argc == 1) {
- strncpy(exname, *argv, MAXPATHLEN-1);
- exname[MAXPATHLEN-1] = '\0';
- } else
- strcpy(exname, _PATH_EXPORTS);
+ if (argc > 0)
+ exnames = argv;
+ else
+ exnames = exnames_default;
openlog("mountd", LOG_PID, LOG_DAEMON);
if (debug)
warnx("getting export list");
@@ -346,6 +343,7 @@
}
signal(SIGHUP, huphandler);
signal(SIGTERM, terminate);
+ signal(SIGPIPE, SIG_IGN);
pidfile_write(pfh);
@@ -543,7 +541,7 @@
{
fprintf(stderr,
"usage: mountd [-2] [-d] [-l] [-n] [-p <port>] [-r] "
- "[export_file]\n");
+ "[export_file ...]\n");
exit(1);
}
@@ -955,82 +953,20 @@
FILE *exp_file;
/*
- * Get the export list
+ * Get the export list from one, currently open file
*/
-void
-get_exportlist()
+static void
+get_exportlist_one()
{
struct exportlist *ep, *ep2;
struct grouplist *grp, *tgrp;
struct exportlist **epp;
struct dirlist *dirhead;
- struct statfs fsb, *fsp;
+ struct statfs fsb;
struct xucred anon;
char *cp, *endcp, *dirp, *hst, *usr, *dom, savedc;
- int len, has_host, exflags, got_nondir, dirplen, num, i, netgrp;
+ int len, has_host, exflags, got_nondir, dirplen, netgrp;
- dirp = NULL;
- dirplen = 0;
-
- /*
- * First, get rid of the old list
- */
- ep = exphead;
- while (ep) {
- ep2 = ep;
- ep = ep->ex_next;
- free_exp(ep2);
- }
- exphead = (struct exportlist *)NULL;
-
- grp = grphead;
- while (grp) {
- tgrp = grp;
- grp = grp->gr_next;
- free_grp(tgrp);
- }
- grphead = (struct grouplist *)NULL;
-
- /*
- * And delete exports that are in the kernel for all local
- * filesystems.
- * XXX: Should know how to handle all local exportable filesystems
- * instead of just "ufs".
- */
- num = getmntinfo(&fsp, MNT_NOWAIT);
- for (i = 0; i < num; i++) {
- union {
- struct ufs_args ua;
- struct iso_args ia;
- struct msdosfs_args da;
- struct ntfs_args na;
- } targs;
-
- if (!strcmp(fsp->f_fstypename, "ufs") ||
- !strcmp(fsp->f_fstypename, "msdosfs") ||
- !strcmp(fsp->f_fstypename, "ntfs") ||
- !strcmp(fsp->f_fstypename, "cd9660")) {
- bzero(&targs, sizeof targs);
- targs.ua.fspec = NULL;
- targs.ua.export.ex_flags = MNT_DELEXPORT;
- if (mount(fsp->f_fstypename, fsp->f_mntonname,
- fsp->f_flags | MNT_UPDATE, (caddr_t)&targs) < 0 &&
- errno != ENOENT)
- syslog(LOG_ERR,
- "can't delete exports for %s: %m",
- fsp->f_mntonname);
- }
- fsp++;
- }
-
- /*
- * Read in the exports file and build the list, calling
- * mount() as we go along to push the export rules into the kernel.
- */
- if ((exp_file = fopen(exname, "r")) == NULL) {
- syslog(LOG_ERR, "can't open %s", exname);
- exit(2);
- }
dirhead = (struct dirlist *)NULL;
while (get_line()) {
if (debug)
@@ -1248,7 +1184,143 @@
dirhead = (struct dirlist *)NULL;
}
}
- fclose(exp_file);
+}
+
+/*
+ * Get the export list from all specified files
+ */
+void
+get_exportlist()
+{
+ struct exportlist *ep, *ep2;
+ struct grouplist *grp, *tgrp;
+ struct export_args export;
+ struct iovec *iov;
+ struct statfs *fsp, *mntbufp;
+ struct xvfsconf vfc;
+ char *dirp;
+ char errmsg[255];
+ int dirplen, num, i;
+ int iovlen;
+ int done;
+
+ bzero(&export, sizeof(export));
+ export.ex_flags = MNT_DELEXPORT;
+ dirp = NULL;
+ dirplen = 0;
+ iov = NULL;
+ iovlen = 0;
+ bzero(errmsg, sizeof(errmsg));
+
+ /*
+ * First, get rid of the old list
+ */
+ ep = exphead;
+ while (ep) {
+ ep2 = ep;
+ ep = ep->ex_next;
+ free_exp(ep2);
+ }
+ exphead = (struct exportlist *)NULL;
+
+ grp = grphead;
+ while (grp) {
+ tgrp = grp;
+ grp = grp->gr_next;
+ free_grp(tgrp);
+ }
+ grphead = (struct grouplist *)NULL;
+
+ /*
+ * And delete exports that are in the kernel for all local
+ * filesystems.
+ * XXX: Should know how to handle all local exportable filesystems.
+ */
+ num = getmntinfo(&mntbufp, MNT_NOWAIT);
+
+ if (num > 0) {
+ build_iovec(&iov, &iovlen, "fstype", NULL, 0);
+ build_iovec(&iov, &iovlen, "fspath", NULL, 0);
+ build_iovec(&iov, &iovlen, "from", NULL, 0);
+ build_iovec(&iov, &iovlen, "update", NULL, 0);
+ build_iovec(&iov, &iovlen, "export", &export, sizeof(export));
+ build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
+ }
+
+ for (i = 0; i < num; i++) {
+ fsp = &mntbufp[i];
+ if (getvfsbyname(fsp->f_fstypename, &vfc) != 0) {
+ syslog(LOG_ERR, "getvfsbyname() failed for %s",
+ fsp->f_fstypename);
+ continue;
+ }
+
+ /*
+ * Do not delete export for network filesystem by
+ * passing "export" arg to nmount().
+ * It only makes sense to do this for local filesystems.
+ */
+ if (vfc.vfc_flags & VFCF_NETWORK)
+ continue;
+
+ iov[1].iov_base = fsp->f_fstypename;
+ iov[1].iov_len = strlen(fsp->f_fstypename) + 1;
+ iov[3].iov_base = fsp->f_mntonname;
+ iov[3].iov_len = strlen(fsp->f_mntonname) + 1;
+ iov[5].iov_base = fsp->f_mntfromname;
+ iov[5].iov_len = strlen(fsp->f_mntfromname) + 1;
+
+ /*
+ * Kick out MNT_ROOTFS. It should not be passed from
+ * userland to kernel. It should only be used
+ * internally in the kernel.
+ */
+ if (fsp->f_flags & MNT_ROOTFS) {
+ fsp->f_flags &= ~MNT_ROOTFS;
+ }
+
+ if (nmount(iov, iovlen, fsp->f_flags) < 0 &&
+ errno != ENOENT && errno != ENOTSUP) {
+ syslog(LOG_ERR,
+ "can't delete exports for %s: %m %s",
+ fsp->f_mntonname, errmsg);
+ }
+ }
+
+ if (iov != NULL) {
+ /* Free strings allocated by strdup() in getmntopts.c */
+ free(iov[0].iov_base); /* fstype */
+ free(iov[2].iov_base); /* fspath */
+ free(iov[4].iov_base); /* from */
+ free(iov[6].iov_base); /* update */
+ free(iov[8].iov_base); /* export */
+ free(iov[10].iov_base); /* errmsg */
+
+ /* free iov, allocated by realloc() */
+ free(iov);
+ iovlen = 0;
+ }
+
+ /*
+ * Read in the exports file and build the list, calling
+ * nmount() as we go along to push the export rules into the kernel.
+ */
+ done = 0;
+ for (i = 0; exnames[i] != NULL; i++) {
+ if (debug)
+ warnx("reading exports from %s", exnames[i]);
+ if ((exp_file = fopen(exnames[i], "r")) == NULL) {
+ syslog(LOG_WARNING, "can't open %s", exnames[i]);
+ continue;
+ }
+ get_exportlist_one();
+ fclose(exp_file);
+ done++;
+ }
+ if (done == 0) {
+ syslog(LOG_ERR, "can't open any exports file");
+ exit(2);
+ }
}
/*
@@ -1778,79 +1850,85 @@
}
/*
- * Do the mount syscall with the update flag to push the export info into
+ * Do the nmount() syscall with the update flag to push the export info into
* the kernel.
*/
int
-do_mount(ep, grp, exflags, anoncrp, dirp, dirplen, fsb)
- struct exportlist *ep;
- struct grouplist *grp;
- int exflags;
- struct xucred *anoncrp;
- char *dirp;
- int dirplen;
- struct statfs *fsb;
+do_mount(struct exportlist *ep, struct grouplist *grp, int exflags,
+ struct xucred *anoncrp, char *dirp, int dirplen, struct statfs *fsb)
{
struct statfs fsb1;
struct addrinfo *ai;
- struct export_args *eap;
- char *cp = NULL;
+ struct export_args eap;
+ char errmsg[255];
+ char *cp;
int done;
- char savedc = '\0';
- union {
- struct ufs_args ua;
- struct iso_args ia;
- struct msdosfs_args da;
- struct ntfs_args na;
- } args;
-
- bzero(&args, sizeof args);
- /* XXX, we assume that all xx_args look like ufs_args. */
- args.ua.fspec = 0;
- eap = &args.ua.export;
-
- eap->ex_flags = exflags;
- eap->ex_anon = *anoncrp;
- eap->ex_indexfile = ep->ex_indexfile;
+ char savedc;
+ struct iovec *iov;
+ int iovlen;
+ int ret;
+
+ cp = NULL;
+ savedc = '\0';
+ iov = NULL;
+ iovlen = 0;
+ ret = 0;
+
+ bzero(&eap, sizeof(eap));
+ bzero(errmsg, sizeof(errmsg));
+ eap.ex_flags = exflags;
+ eap.ex_anon = *anoncrp;
+ eap.ex_indexfile = ep->ex_indexfile;
if (grp->gr_type == GT_HOST)
ai = grp->gr_ptr.gt_addrinfo;
else
ai = NULL;
done = FALSE;
+
+ build_iovec(&iov, &iovlen, "fstype", NULL, 0);
+ build_iovec(&iov, &iovlen, "fspath", NULL, 0);
+ build_iovec(&iov, &iovlen, "from", NULL, 0);
+ build_iovec(&iov, &iovlen, "update", NULL, 0);
+ build_iovec(&iov, &iovlen, "export", &eap, sizeof(eap));
+ build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
+
while (!done) {
switch (grp->gr_type) {
case GT_HOST:
if (ai->ai_addr->sa_family == AF_INET6 && have_v6 == 0)
goto skip;
- eap->ex_addr = ai->ai_addr;
- eap->ex_addrlen = ai->ai_addrlen;
- eap->ex_masklen = 0;
+ eap.ex_addr = ai->ai_addr;
+ eap.ex_addrlen = ai->ai_addrlen;
+ eap.ex_masklen = 0;
break;
case GT_NET:
if (grp->gr_ptr.gt_net.nt_net.ss_family == AF_INET6 &&
have_v6 == 0)
goto skip;
- eap->ex_addr =
+ eap.ex_addr =
(struct sockaddr *)&grp->gr_ptr.gt_net.nt_net;
- eap->ex_addrlen = args.ua.export.ex_addr->sa_len;
- eap->ex_mask =
+ eap.ex_addrlen =
+ ((struct sockaddr *)&grp->gr_ptr.gt_net.nt_net)->sa_len;
+ eap.ex_mask =
(struct sockaddr *)&grp->gr_ptr.gt_net.nt_mask;
- eap->ex_masklen = args.ua.export.ex_mask->sa_len;
+ eap.ex_masklen = ((struct sockaddr *)&grp->gr_ptr.gt_net.nt_mask)->sa_len;
break;
case GT_DEFAULT:
- eap->ex_addr = NULL;
- eap->ex_addrlen = 0;
- eap->ex_mask = NULL;
- eap->ex_masklen = 0;
+ eap.ex_addr = NULL;
+ eap.ex_addrlen = 0;
+ eap.ex_mask = NULL;
+ eap.ex_masklen = 0;
break;
case GT_IGNORE:
- return(0);
+ ret = 0;
+ goto error_exit;
break;
default:
syslog(LOG_ERR, "bad grouptype");
if (cp)
*cp = savedc;
- return (1);
+ ret = 1;
+ goto error_exit;
};
/*
@@ -1860,21 +1938,35 @@
* Also, needs to know how to export all types of local
* exportable filesystems and not just "ufs".
*/
- while (mount(fsb->f_fstypename, dirp,
- fsb->f_flags | MNT_UPDATE, (caddr_t)&args) < 0) {
+ iov[1].iov_base = fsb->f_fstypename; /* "fstype" */
+ iov[1].iov_len = strlen(fsb->f_fstypename) + 1;
+ iov[3].iov_base = fsb->f_mntonname; /* "fspath" */
+ iov[3].iov_len = strlen(fsb->f_mntonname) + 1;
+ iov[5].iov_base = fsb->f_mntfromname; /* "from" */
+ iov[5].iov_len = strlen(fsb->f_mntfromname) + 1;
+
+ /*
+ * Remount the filesystem, but chop off the MNT_ROOTFS flag
+ * as it is used internally (and will result in an error if
+ * specified)
+ */
+ while (nmount(iov, iovlen, fsb->f_flags & ~MNT_ROOTFS) < 0) {
if (cp)
*cp-- = savedc;
else
cp = dirp + dirplen - 1;
- if (opt_flags & OP_QUIET)
- return (1);
+ if (opt_flags & OP_QUIET) {
+ ret = 1;
+ goto error_exit;
+ }
if (errno == EPERM) {
if (debug)
warnx("can't change attributes for %s",
dirp);
syslog(LOG_ERR,
"can't change attributes for %s", dirp);
- return (1);
+ ret = 1;
+ goto error_exit;
}
if (opt_flags & OP_ALLDIRS) {
if (errno == EINVAL)
@@ -1885,7 +1977,8 @@
syslog(LOG_ERR,
"could not remount %s: %m",
dirp);
- return (1);
+ ret = 1;
+ goto error_exit;
}
/* back up over the last component */
while (*cp == '/' && cp > dirp)
@@ -1895,8 +1988,10 @@
if (cp == dirp) {
if (debug)
warnx("mnt unsucc");
- syslog(LOG_ERR, "can't export %s", dirp);
- return (1);
+ syslog(LOG_ERR, "can't export %s %s", dirp,
+ errmsg);
+ ret = 1;
+ goto error_exit;
}
savedc = *cp;
*cp = '\0';
@@ -1904,8 +1999,10 @@
if (statfs(dirp, &fsb1) != 0 || bcmp(&fsb1.f_fsid,
&fsb->f_fsid, sizeof(fsb1.f_fsid)) != 0) {
*cp = savedc;
- syslog(LOG_ERR, "can't export %s", dirp);
- return (1);
+ syslog(LOG_ERR, "can't export %s %s", dirp,
+ errmsg);
+ ret = 1;
+ goto error_exit;
}
}
skip:
@@ -1916,7 +2013,20 @@
}
if (cp)
*cp = savedc;
- return (0);
+error_exit:
+ /* free strings allocated by strdup() in getmntopts.c */
+ if (iov != NULL) {
+ free(iov[0].iov_base); /* fstype */
+ free(iov[2].iov_base); /* fspath */
+ free(iov[4].iov_base); /* from */
+ free(iov[6].iov_base); /* update */
+ free(iov[8].iov_base); /* export */
+ free(iov[10].iov_base); /* errmsg */
+
+ /* free iov, allocated by realloc() */
+ free(iov);
+ }
+ return (ret);
}
/*
Index: Makefile
===================================================================
RCS file: /home/cvs/src/usr.sbin/mountd/Makefile,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L usr.sbin/mountd/Makefile -L usr.sbin/mountd/Makefile -u -r1.1.1.2 -r1.2
--- usr.sbin/mountd/Makefile
+++ usr.sbin/mountd/Makefile
@@ -1,10 +1,15 @@
# From: @(#)Makefile 8.3 (Berkeley) 1/25/94
-# $FreeBSD: src/usr.sbin/mountd/Makefile,v 1.15.10.1 2006/01/15 17:50:37 delphij Exp $
+# $FreeBSD: src/usr.sbin/mountd/Makefile,v 1.17 2006/05/23 17:10:17 rodrigc Exp $
PROG= mountd
+SRCS= mountd.c getmntopts.c
MAN= exports.5 netgroup.5 mountd.8
-WARNS?= 2
+MOUNT= ${.CURDIR}/../../sbin/mount
+CFLAGS+= -I${MOUNT}
+WARNS?= 2
+
+.PATH: ${MOUNT}
DPADD= ${LIBUTIL}
LDADD= -lutil
More information about the Midnightbsd-cvs
mailing list