/* $NetBSD: showmount.c,v 1.25 2025/06/05 08:08:41 bad Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
* 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.
* 3. 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1995\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
static struct mountlist *mntdump;
static struct exportslist *exports;
static int type = 0;
static void print_dump(struct mountlist *);
__dead static void usage(void);
static int xdr_mntdump(XDR *, struct mountlist **);
static int xdr_exports(XDR *, struct exportslist **);
static int tcp_callrpc(const char *host, int prognum, int versnum,
int procnum, xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
/*
* This command queries the NFS mount daemon for its mount list and/or
* its exports list and prints them out.
* See "NFS: Network File System Protocol Specification, RFC1094, Appendix A"
* and the "Network File System Protocol XXX.."
* for detailed information on the protocol.
*/
int
main(int argc, char **argv)
{
struct exportslist *exp;
struct grouplist *grp;
int estat, rpcs = 0, mntvers = 1;
const char *host;
int ch;
int nbytes;
char strvised[1024 * 4 + 1];
while ((ch = getopt(argc, argv, "adEe3")) != -1)
switch((char)ch) {
case 'a':
if (type == 0) {
type = ALL;
rpcs |= DODUMP;
} else
usage();
break;
case 'd':
if (type == 0) {
type = DIRS;
rpcs |= DODUMP;
} else
usage();
break;
case 'E':
rpcs |= DOPARSABLEEXPORTS;
break;
case 'e':
rpcs |= DOEXPORTS;
break;
case '3':
mntvers = 3;
break;
case '?':
default:
usage();
}
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");
}
/*
* Xdr routine for retrieving the mount dump list
*/
static int
xdr_mntdump(XDR *xdrsp, struct mountlist **mlp)
{
struct mountlist *mp, **otp, *tp;
int bool_int, val, val2;
char *strp;