386BSD 0.0 development
authorWilliam F. Jolitz <wjolitz@soda.berkeley.edu>
Fri, 19 Apr 1991 01:01:51 +0000 (17:01 -0800)
committerWilliam F. Jolitz <wjolitz@soda.berkeley.edu>
Fri, 19 Apr 1991 01:01:51 +0000 (17:01 -0800)
Work on file usr/src/usr.bin/shar/shar.sh
Work on file usr/src/usr.bin/showmount/showmount.8
Work on file usr/src/usr.bin/showmount/showmount.c

Co-Authored-By: Lynne Greer Jolitz <ljolitz@cardio.ucsf.edu>
Synthesized-from: 386BSD-0.0/src

usr/src/usr.bin/shar/shar.sh [new file with mode: 0644]
usr/src/usr.bin/showmount/showmount.8 [new file with mode: 0644]
usr/src/usr.bin/showmount/showmount.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/shar/shar.sh b/usr/src/usr.bin/shar/shar.sh
new file mode 100644 (file)
index 0000000..e7a6b6a
--- /dev/null
@@ -0,0 +1,74 @@
+#!/bin/sh -
+#
+# Copyright (c) 1990 The Regents of the University of California.
+# All rights reserved.
+#
+# 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. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#      This product includes software developed by the University of
+#      California, Berkeley and its contributors.
+# 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.
+#
+#      @(#)shar.sh     5.2 (Berkeley) 5/23/90
+#
+
+if [ $# -eq 0 ]; then
+       echo 'usage: shar file ...'
+       exit 1
+fi
+
+cat << EOF
+# This is a shell archive.  Save it in a file, remove anything before
+# this line, and then unpack it by entering "sh file".  Note, it may
+# create directories; files and directories will be owned by you and
+# have default permissions.
+#
+# This archive contains:
+#
+EOF
+
+for i
+do
+       echo "# $i"
+done
+
+echo "#"
+
+for i
+do
+       if [ -d $i ]; then
+               echo "echo c - $i"
+               echo "mkdir $i > /dev/null 2>&1"
+       else
+               echo "echo x - $i"
+               echo "sed 's/^X//' >$i << 'END-of-$i'"
+               sed 's/^/X/' $i
+               echo "END-of-$i"
+       fi
+done
+echo exit
+echo ""
+
+exit 0
diff --git a/usr/src/usr.bin/showmount/showmount.8 b/usr/src/usr.bin/showmount/showmount.8
new file mode 100644 (file)
index 0000000..7929b2a
--- /dev/null
@@ -0,0 +1,89 @@
+.\" Copyright (c) 1989, 1991 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. All advertising materials mentioning features or use of this software
+.\"    must display the following acknowledgement:
+.\"    This product includes software developed by the University of
+.\"    California, Berkeley and its contributors.
+.\" 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.
+.\"
+.\"     @(#)showmount.8        6.3 (Berkeley) 3/16/91
+.\"
+.Dd March 16, 1991
+.Dt SHOWMOUNT 8
+.Os BSD 4
+.Sh NAME
+.Nm showmount
+.Nd show remote nfs mounts on host
+.Sh SYNOPSIS
+.Nm showmount
+.Op Fl ade
+.Op Ar host
+.Sh DESCRIPTION
+.Nm Showmount
+shows status information about the
+.Tn NFS
+server on
+.Ar host .
+By default it prints the names of all hosts that have
+.Tn NFS
+file systems mounted
+on the host. See
+.%T "NFS: Network File System Protocol Specification" ,
+RFC 1094,
+Appendix A ,
+for a detailed desciption of the protocol.
+.Bl -tag -width Ds
+.It Fl a
+List all mount points in the form:
+.Bd -ragged -offset indent -compact
+.Ar host : Ns Ar dirpath
+.Ed
+.It Fl d
+List directory paths of mount points instead of hosts
+.It Fl e
+Show the
+.Ar host Ns 's
+exports list
+.El
+.Sh SEE ALSO
+.Xr mount 1 ,
+.Xr mountd 8
+.Sh BUGS
+The mount daemon running on the server only has an idea of the actual mounts,
+since the
+.Tn NFS
+server is stateless.
+.Nm Showmount
+will only display the information
+as accurately as the mount daemon reports it.
+.Sh HISTORY
+The
+.Nm
+command
+.Ud
diff --git a/usr/src/usr.bin/showmount/showmount.c b/usr/src/usr.bin/showmount/showmount.c
new file mode 100644 (file)
index 0000000..6f664d1
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * Copyright (c) 1989 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 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
+char copyright[] =
+"@(#) Copyright (c) 1989 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)showmount.c        6.5 (Berkeley) 3/1/91";
+#endif not lint
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <netdb.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <rpc/pmap_prot.h>
+#include <nfs/rpcv2.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Constant defs */
+#define        ALL     1
+#define        DIRS    2
+
+#define        DODUMP          0x1
+#define        DOEXPORTS       0x2
+
+struct mountlist {
+       struct mountlist *ml_left;
+       struct mountlist *ml_right;
+       char    ml_host[RPCMNT_NAMELEN+1];
+       char    ml_dirp[RPCMNT_PATHLEN+1];
+};
+
+struct grouplist {
+       struct grouplist *gr_next;
+       char    gr_name[RPCMNT_NAMELEN+1];
+};
+
+struct exportslist {
+       struct exportslist *ex_next;
+       struct grouplist *ex_groups;
+       char    ex_dirp[RPCMNT_PATHLEN+1];
+};
+
+static struct mountlist *mntdump;
+static struct exportslist *exports;
+static int type = 0;
+int xdr_mntdump(), xdr_exports();
+
+/*
+ * 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"
+ * for detailed information on the protocol.
+ */
+main(argc, argv)
+       int argc;
+       char **argv;
+{
+       register struct mountlist *mntp;
+       register struct exportslist *exp;
+       register struct grouplist *grp;
+       extern char *optarg;
+       extern int optind;
+       register int rpcs = 0;
+       char ch;
+       char *host;
+       int estat;
+
+       while ((ch = getopt(argc, argv, "ade")) != EOF)
+               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 |= DOEXPORTS;
+                       break;
+               case '?':
+               default:
+                       usage();
+               }
+       argc -= optind;
+       argv += optind;
+
+       if (argc > 0)
+               host = *argv;
+       else
+               host = "localhost";
+
+       if (rpcs == 0)
+               rpcs = DODUMP;
+
+       if (rpcs & DODUMP)
+               if ((estat = callrpc(host, RPCPROG_MNT, RPCMNT_VER1,
+                       RPCMNT_DUMP, xdr_void, (char *)0,
+                       xdr_mntdump, (char *)&mntdump)) != 0) {
+                       clnt_perrno(estat);
+                       fprintf(stderr, "Can't do Mountdump rpc\n");
+                       exit(1);
+               }
+       if (rpcs & DOEXPORTS)
+               if ((estat = callrpc(host, RPCPROG_MNT, RPCMNT_VER1,
+                       RPCMNT_EXPORT, xdr_void, (char *)0,
+                       xdr_exports, (char *)&exports)) != 0) {
+                       clnt_perrno(estat);
+                       fprintf(stderr, "Can't do Exports rpc\n");
+                       exit(1);
+               }
+
+       /* 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;
+               };
+               print_dump(mntdump);
+       }
+       if (rpcs & DOEXPORTS) {
+               printf("Exports list on %s:\n", host);
+               exp = exports;
+               while (exp) {
+                       printf("%-35s", exp->ex_dirp);
+                       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;
+               }
+       }
+}
+
+/*
+ * Xdr routine for retrieving the mount dump list
+ */
+xdr_mntdump(xdrsp, mlp)
+       XDR *xdrsp;
+       struct mountlist **mlp;
+{
+       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;
+               if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN))
+                       return (0);
+               strp = mp->ml_dirp;
+               if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN))
+                       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;
+                               };
+                               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
+ */
+xdr_exports(xdrsp, exp)
+       XDR *xdrsp;
+       struct exportslist **exp;
+{
+       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;
+               if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN))
+                       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;
+                       if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN))
+                               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);
+}
+
+usage()
+{
+       fprintf(stderr, "usage: showmount [-ade] host\n");
+       exit(1);
+}
+
+/*
+ * Print the binary tree in inorder so that output is sorted.
+ */
+print_dump(mp)
+       struct mountlist *mp;
+{
+
+       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;
+       };
+       if (mp->ml_right)
+               print_dump(mp->ml_right);
+}