1994-05-27 12:33:43 +00:00
|
|
|
/*
|
1997-08-11 07:27:27 +00:00
|
|
|
* Copyright (c) 1989, 1993, 1995
|
1994-05-27 12:33:43 +00:00
|
|
|
* 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.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-11 07:27:27 +00:00
|
|
|
static const char copyright[] =
|
|
|
|
"@(#) Copyright (c) 1989, 1993, 1995\n\
|
1994-05-27 12:33:43 +00:00
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
2001-06-12 03:44:35 +00:00
|
|
|
#endif /* not lint */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-11 07:27:27 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)showmount.c 8.3 (Berkeley) 3/29/95";
|
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:08:13 +00:00
|
|
|
"$FreeBSD$";
|
2001-06-12 03:44:35 +00:00
|
|
|
#endif /* not lint */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
1996-03-11 13:00:12 +00:00
|
|
|
#include <sys/queue.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1997-08-11 07:27:27 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <netdb.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/pmap_clnt.h>
|
|
|
|
#include <rpc/pmap_prot.h>
|
2009-06-24 18:42:21 +00:00
|
|
|
#include <rpcsvc/mount.h>
|
1997-08-11 07:27:27 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
1997-08-11 07:27:27 +00:00
|
|
|
#include <stdlib.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <string.h>
|
1997-08-11 07:27:27 +00:00
|
|
|
#include <unistd.h>
|
2016-03-23 12:13:53 +00:00
|
|
|
#include <vis.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/* Constant defs */
|
|
|
|
#define ALL 1
|
|
|
|
#define DIRS 2
|
|
|
|
|
2016-03-23 12:13:53 +00:00
|
|
|
#define DODUMP 0x1
|
|
|
|
#define DOEXPORTS 0x2
|
|
|
|
#define DOPARSABLEEXPORTS 0x4
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
struct mountlist {
|
|
|
|
struct mountlist *ml_left;
|
|
|
|
struct mountlist *ml_right;
|
2009-06-24 18:42:21 +00:00
|
|
|
char ml_host[MNTNAMLEN+1];
|
|
|
|
char ml_dirp[MNTPATHLEN+1];
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct grouplist {
|
|
|
|
struct grouplist *gr_next;
|
2009-06-24 18:42:21 +00:00
|
|
|
char gr_name[MNTNAMLEN+1];
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct exportslist {
|
|
|
|
struct exportslist *ex_next;
|
|
|
|
struct grouplist *ex_groups;
|
2009-06-24 18:42:21 +00:00
|
|
|
char ex_dirp[MNTPATHLEN+1];
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct mountlist *mntdump;
|
2009-06-24 18:42:21 +00:00
|
|
|
static struct exportslist *exportslist;
|
1994-05-27 12:33:43 +00:00
|
|
|
static int type = 0;
|
1997-08-11 07:27:27 +00:00
|
|
|
|
2002-03-22 01:42:45 +00:00
|
|
|
void print_dump(struct mountlist *);
|
|
|
|
static void usage(void);
|
|
|
|
int xdr_mntdump(XDR *, struct mountlist **);
|
2009-06-24 18:42:21 +00:00
|
|
|
int xdr_exportslist(XDR *, struct exportslist **);
|
2002-03-22 01:42:45 +00:00
|
|
|
int tcp_callrpc(const char *host, int prognum, int versnum, int procnum,
|
|
|
|
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This command queries the NFS mount daemon for it's mount list and/or
|
|
|
|
* it's exports list and prints them out.
|
|
|
|
* See "NFS: Network File System Protocol Specification, RFC1094, Appendix A"
|
1995-06-27 11:07:30 +00:00
|
|
|
* and the "Network File System Protocol XXX.."
|
1994-05-27 12:33:43 +00:00
|
|
|
* for detailed information on the protocol.
|
|
|
|
*/
|
1997-08-11 07:27:27 +00:00
|
|
|
int
|
2010-01-02 10:09:20 +00:00
|
|
|
main(int argc, char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2016-03-23 12:13:53 +00:00
|
|
|
char strvised[MNTPATHLEN * 4 + 1];
|
1994-05-27 12:33:43 +00:00
|
|
|
register struct exportslist *exp;
|
|
|
|
register struct grouplist *grp;
|
2014-08-16 14:56:11 +00:00
|
|
|
register int rpcs = 0, mntvers = 3;
|
2001-12-03 21:25:28 +00:00
|
|
|
const char *host;
|
2016-03-23 12:13:53 +00:00
|
|
|
int ch, estat, nbytes;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2016-03-23 12:13:53 +00:00
|
|
|
while ((ch = getopt(argc, argv, "adEe13")) != -1)
|
2004-07-26 15:04:57 +00:00
|
|
|
switch (ch) {
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'a':
|
|
|
|
if (type == 0) {
|
|
|
|
type = ALL;
|
|
|
|
rpcs |= DODUMP;
|
|
|
|
} else
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
if (type == 0) {
|
|
|
|
type = DIRS;
|
|
|
|
rpcs |= DODUMP;
|
|
|
|
} else
|
|
|
|
usage();
|
|
|
|
break;
|
2016-03-23 12:13:53 +00:00
|
|
|
case 'E':
|
|
|
|
rpcs |= DOPARSABLEEXPORTS;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'e':
|
|
|
|
rpcs |= DOEXPORTS;
|
|
|
|
break;
|
2014-08-16 14:56:11 +00:00
|
|
|
case '1':
|
|
|
|
mntvers = 1;
|
|
|
|
break;
|
1995-06-27 11:07:30 +00:00
|
|
|
case '3':
|
|
|
|
mntvers = 3;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2016-03-23 12:13:53 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (argc > 0)
|
|
|
|
host = *argv;
|
|
|
|
else
|
|
|
|
host = "localhost";
|
|
|
|
|
|
|
|
if (rpcs == 0)
|
|
|
|
rpcs = DODUMP;
|
|
|
|
|
|
|
|
if (rpcs & DODUMP)
|
2009-06-24 18:42:21 +00:00
|
|
|
if ((estat = tcp_callrpc(host, MOUNTPROG, mntvers,
|
|
|
|
MOUNTPROC_DUMP, (xdrproc_t)xdr_void, (char *)0,
|
2003-10-26 04:58:44 +00:00
|
|
|
(xdrproc_t)xdr_mntdump, (char *)&mntdump)) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
clnt_perrno(estat);
|
1997-08-11 07:27:27 +00:00
|
|
|
errx(1, "can't do mountdump rpc");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2016-03-23 12:13:53 +00:00
|
|
|
if (rpcs & (DOEXPORTS | DOPARSABLEEXPORTS))
|
2009-06-24 18:42:21 +00:00
|
|
|
if ((estat = tcp_callrpc(host, MOUNTPROG, mntvers,
|
|
|
|
MOUNTPROC_EXPORT, (xdrproc_t)xdr_void, (char *)0,
|
|
|
|
(xdrproc_t)xdr_exportslist, (char *)&exportslist)) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
clnt_perrno(estat);
|
1997-08-11 07:27:27 +00:00
|
|
|
errx(1, "can't do exports rpc");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now just print out the results */
|
|
|
|
if (rpcs & DODUMP) {
|
|
|
|
switch (type) {
|
|
|
|
case ALL:
|
|
|
|
printf("All mount points on %s:\n", host);
|
|
|
|
break;
|
|
|
|
case DIRS:
|
|
|
|
printf("Directories on %s:\n", host);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Hosts on %s:\n", host);
|
|
|
|
break;
|
2016-04-15 22:31:22 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
print_dump(mntdump);
|
|
|
|
}
|
|
|
|
if (rpcs & DOEXPORTS) {
|
|
|
|
printf("Exports list on %s:\n", host);
|
2009-06-24 18:42:21 +00:00
|
|
|
exp = exportslist;
|
1994-05-27 12:33:43 +00:00
|
|
|
while (exp) {
|
2011-05-24 06:56:40 +00:00
|
|
|
printf("%-34s ", exp->ex_dirp);
|
1994-05-27 12:33:43 +00:00
|
|
|
grp = exp->ex_groups;
|
|
|
|
if (grp == NULL) {
|
|
|
|
printf("Everyone\n");
|
|
|
|
} else {
|
|
|
|
while (grp) {
|
|
|
|
printf("%s ", grp->gr_name);
|
|
|
|
grp = grp->gr_next;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
exp = exp->ex_next;
|
|
|
|
}
|
|
|
|
}
|
2016-03-23 12:13:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1997-08-11 07:27:27 +00:00
|
|
|
exit(0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1997-09-04 21:21:56 +00:00
|
|
|
/*
|
|
|
|
* tcp_callrpc has the same interface as callrpc, but tries to
|
|
|
|
* use tcp as transport method in order to handle large replies.
|
|
|
|
*/
|
|
|
|
int
|
2010-01-02 10:09:20 +00:00
|
|
|
tcp_callrpc(const char *host, int prognum, int versnum, int procnum,
|
|
|
|
xdrproc_t inproc, char *in, xdrproc_t outproc, char *out)
|
1997-09-04 21:21:56 +00:00
|
|
|
{
|
|
|
|
CLIENT *client;
|
|
|
|
struct timeval timeout;
|
|
|
|
int rval;
|
|
|
|
|
2001-04-05 17:18:36 +00:00
|
|
|
if ((client = clnt_create(host, prognum, versnum, "tcp")) == NULL &&
|
|
|
|
(client = clnt_create(host, prognum, versnum, "udp")) == NULL)
|
1997-09-04 21:21:56 +00:00
|
|
|
return ((int) rpc_createerr.cf_stat);
|
|
|
|
|
|
|
|
timeout.tv_sec = 25;
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
rval = (int) clnt_call(client, procnum,
|
|
|
|
inproc, in,
|
|
|
|
outproc, out,
|
|
|
|
timeout);
|
|
|
|
clnt_destroy(client);
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Xdr routine for retrieving the mount dump list
|
|
|
|
*/
|
1997-08-11 07:27:27 +00:00
|
|
|
int
|
2010-01-02 10:09:20 +00:00
|
|
|
xdr_mntdump(XDR *xdrsp, struct mountlist **mlp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
register struct mountlist *mp;
|
|
|
|
register struct mountlist *tp;
|
|
|
|
register struct mountlist **otp;
|
|
|
|
int val, val2;
|
|
|
|
int bool;
|
|
|
|
char *strp;
|
|
|
|
|
|
|
|
*mlp = (struct mountlist *)0;
|
|
|
|
if (!xdr_bool(xdrsp, &bool))
|
|
|
|
return (0);
|
|
|
|
while (bool) {
|
|
|
|
mp = (struct mountlist *)malloc(sizeof(struct mountlist));
|
|
|
|
if (mp == NULL)
|
|
|
|
return (0);
|
|
|
|
mp->ml_left = mp->ml_right = (struct mountlist *)0;
|
|
|
|
strp = mp->ml_host;
|
2009-06-24 18:42:21 +00:00
|
|
|
if (!xdr_string(xdrsp, &strp, MNTNAMLEN))
|
1994-05-27 12:33:43 +00:00
|
|
|
return (0);
|
|
|
|
strp = mp->ml_dirp;
|
2009-06-24 18:42:21 +00:00
|
|
|
if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
|
1994-05-27 12:33:43 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build a binary tree on sorted order of either host or dirp.
|
|
|
|
* Drop any duplications.
|
|
|
|
*/
|
|
|
|
if (*mlp == NULL) {
|
|
|
|
*mlp = mp;
|
|
|
|
} else {
|
|
|
|
tp = *mlp;
|
|
|
|
while (tp) {
|
|
|
|
val = strcmp(mp->ml_host, tp->ml_host);
|
|
|
|
val2 = strcmp(mp->ml_dirp, tp->ml_dirp);
|
|
|
|
switch (type) {
|
|
|
|
case ALL:
|
|
|
|
if (val == 0) {
|
|
|
|
if (val2 == 0) {
|
|
|
|
free((caddr_t)mp);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
val = val2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIRS:
|
|
|
|
if (val2 == 0) {
|
|
|
|
free((caddr_t)mp);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
val = val2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (val == 0) {
|
|
|
|
free((caddr_t)mp);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
break;
|
2016-04-15 22:31:22 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
if (val < 0) {
|
|
|
|
otp = &tp->ml_left;
|
|
|
|
tp = tp->ml_left;
|
|
|
|
} else {
|
|
|
|
otp = &tp->ml_right;
|
|
|
|
tp = tp->ml_right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*otp = mp;
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
if (!xdr_bool(xdrsp, &bool))
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Xdr routine to retrieve exports list
|
|
|
|
*/
|
1997-08-11 07:27:27 +00:00
|
|
|
int
|
2010-01-02 10:09:20 +00:00
|
|
|
xdr_exportslist(XDR *xdrsp, struct exportslist **exp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
register struct exportslist *ep;
|
|
|
|
register struct grouplist *gp;
|
|
|
|
int bool, grpbool;
|
|
|
|
char *strp;
|
|
|
|
|
|
|
|
*exp = (struct exportslist *)0;
|
|
|
|
if (!xdr_bool(xdrsp, &bool))
|
|
|
|
return (0);
|
|
|
|
while (bool) {
|
|
|
|
ep = (struct exportslist *)malloc(sizeof(struct exportslist));
|
|
|
|
if (ep == NULL)
|
|
|
|
return (0);
|
|
|
|
ep->ex_groups = (struct grouplist *)0;
|
|
|
|
strp = ep->ex_dirp;
|
2009-06-24 18:42:21 +00:00
|
|
|
if (!xdr_string(xdrsp, &strp, MNTPATHLEN))
|
1994-05-27 12:33:43 +00:00
|
|
|
return (0);
|
|
|
|
if (!xdr_bool(xdrsp, &grpbool))
|
|
|
|
return (0);
|
|
|
|
while (grpbool) {
|
|
|
|
gp = (struct grouplist *)malloc(sizeof(struct grouplist));
|
|
|
|
if (gp == NULL)
|
|
|
|
return (0);
|
|
|
|
strp = gp->gr_name;
|
2009-06-24 18:42:21 +00:00
|
|
|
if (!xdr_string(xdrsp, &strp, MNTNAMLEN))
|
1994-05-27 12:33:43 +00:00
|
|
|
return (0);
|
|
|
|
gp->gr_next = ep->ex_groups;
|
|
|
|
ep->ex_groups = gp;
|
|
|
|
if (!xdr_bool(xdrsp, &grpbool))
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
ep->ex_next = *exp;
|
|
|
|
*exp = ep;
|
|
|
|
if (!xdr_bool(xdrsp, &bool))
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1997-08-11 07:27:27 +00:00
|
|
|
static void
|
2010-01-02 10:09:20 +00:00
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2005-05-21 09:55:10 +00:00
|
|
|
fprintf(stderr, "usage: showmount [-a | -d] [-e3] [host]\n");
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the binary tree in inorder so that output is sorted.
|
|
|
|
*/
|
1997-08-11 07:27:27 +00:00
|
|
|
void
|
2010-01-02 10:09:20 +00:00
|
|
|
print_dump(struct mountlist *mp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (mp == NULL)
|
|
|
|
return;
|
|
|
|
if (mp->ml_left)
|
|
|
|
print_dump(mp->ml_left);
|
|
|
|
switch (type) {
|
|
|
|
case ALL:
|
|
|
|
printf("%s:%s\n", mp->ml_host, mp->ml_dirp);
|
|
|
|
break;
|
|
|
|
case DIRS:
|
|
|
|
printf("%s\n", mp->ml_dirp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s\n", mp->ml_host);
|
|
|
|
break;
|
2016-04-15 22:31:22 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
if (mp->ml_right)
|
|
|
|
print_dump(mp->ml_right);
|
|
|
|
}
|