svn commit: r308292 - in stable/10: etc/autofs usr.bin/showmount
Edward Tomasz Napierala
trasz at FreeBSD.org
Fri Nov 4 14:06:22 UTC 2016
Author: trasz
Date: Fri Nov 4 14:06:21 2016
New Revision: 308292
URL: https://svnweb.freebsd.org/changeset/base/308292
Log:
MFC r297207:
Make the autofs(5) -hosts map more robust, primarily to make it correctly
handle NFS shares containing whitespace. This also adds the -E parameter
to showmount(8).
PR: 207596
Differential Revision: https://reviews.freebsd.org/D5649
Modified:
stable/10/etc/autofs/special_hosts
stable/10/usr.bin/showmount/showmount.8
stable/10/usr.bin/showmount/showmount.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/etc/autofs/special_hosts
==============================================================================
--- stable/10/etc/autofs/special_hosts Fri Nov 4 13:59:57 2016 (r308291)
+++ stable/10/etc/autofs/special_hosts Fri Nov 4 14:06:21 2016 (r308292)
@@ -10,8 +10,8 @@ if [ $# -eq 0 ]; then
exit 0
fi
-out=`showmount -e "$1"`
+out=`showmount -E "$1"`
[ $? -eq 0 ] || exit 1
echo "$out" | awk -v host="$1" \
- 'NR > 1 { printf "%s\t%s:%s ", $1, host, $1 } END { printf "\n" }'
+ '{ printf "\"%s\"\t\"%s:%s\" ", $0, host, $0 } END { printf "\n" }'
Modified: stable/10/usr.bin/showmount/showmount.8
==============================================================================
--- stable/10/usr.bin/showmount/showmount.8 Fri Nov 4 13:59:57 2016 (r308291)
+++ stable/10/usr.bin/showmount/showmount.8 Fri Nov 4 14:06:21 2016 (r308292)
@@ -31,7 +31,7 @@
.\" @(#)showmount.8 8.3 (Berkeley) 3/29/95
.\" $FreeBSD$
.\"
-.Dd August 16, 2014
+.Dd March 20, 2016
.Dt SHOWMOUNT 8
.Os
.Sh NAME
@@ -40,6 +40,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl a | d
+.Op Fl E
.Op Fl e
.Op Fl 1
.Op Fl 3
@@ -73,6 +74,12 @@ List all mount points in the form:
.Ed
.It Fl d
List directory paths of mount points instead of hosts.
+.It Fl E
+Show the
+.Ar host Ns 's
+exports list in a script-friendly format.
+Client addresses and the header are not shown, and special
+characters are escaped.
.It Fl e
Show the
.Ar host Ns 's
Modified: stable/10/usr.bin/showmount/showmount.c
==============================================================================
--- stable/10/usr.bin/showmount/showmount.c Fri Nov 4 13:59:57 2016 (r308291)
+++ stable/10/usr.bin/showmount/showmount.c Fri Nov 4 14:06:21 2016 (r308292)
@@ -61,13 +61,15 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <vis.h>
/* Constant defs */
#define ALL 1
#define DIRS 2
-#define DODUMP 0x1
-#define DOEXPORTS 0x2
+#define DODUMP 0x1
+#define DOEXPORTS 0x2
+#define DOPARSABLEEXPORTS 0x4
struct mountlist {
struct mountlist *ml_left;
@@ -108,13 +110,14 @@ int tcp_callrpc(const char *host, int pr
int
main(int argc, char **argv)
{
+ char strvised[MNTPATHLEN * 4 + 1];
register struct exportslist *exp;
register struct grouplist *grp;
register int rpcs = 0, mntvers = 3;
const char *host;
- int ch, estat;
+ int ch, estat, nbytes;
- while ((ch = getopt(argc, argv, "ade13")) != -1)
+ while ((ch = getopt(argc, argv, "adEe13")) != -1)
switch (ch) {
case 'a':
if (type == 0) {
@@ -130,6 +133,9 @@ main(int argc, char **argv)
} else
usage();
break;
+ case 'E':
+ rpcs |= DOPARSABLEEXPORTS;
+ break;
case 'e':
rpcs |= DOEXPORTS;
break;
@@ -146,6 +152,13 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if ((rpcs & DOPARSABLEEXPORTS) != 0) {
+ if ((rpcs & DOEXPORTS) != 0)
+ errx(1, "-E cannot be used with -e");
+ if ((rpcs & DODUMP) != 0)
+ errx(1, "-E cannot be used with -a or -d");
+ }
+
if (argc > 0)
host = *argv;
else
@@ -161,7 +174,7 @@ main(int argc, char **argv)
clnt_perrno(estat);
errx(1, "can't do mountdump rpc");
}
- if (rpcs & DOEXPORTS)
+ if (rpcs & (DOEXPORTS | DOPARSABLEEXPORTS))
if ((estat = tcp_callrpc(host, MOUNTPROG, mntvers,
MOUNTPROC_EXPORT, (xdrproc_t)xdr_void, (char *)0,
(xdrproc_t)xdr_exportslist, (char *)&exportslist)) != 0) {
@@ -202,6 +215,17 @@ main(int argc, char **argv)
exp = exp->ex_next;
}
}
+ if (rpcs & DOPARSABLEEXPORTS) {
+ exp = exportslist;
+ while (exp) {
+ nbytes = strsnvis(strvised, sizeof(strvised),
+ exp->ex_dirp, VIS_GLOB | VIS_NL, "\"'$");
+ if (nbytes == -1)
+ err(1, "strsnvis");
+ printf("%s\n", strvised);
+ exp = exp->ex_next;
+ }
+ }
exit(0);
}
More information about the svn-src-stable
mailing list