BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / amd / amd / amq_subr.c
index bd3a939..355c66e 100644 (file)
@@ -1,6 +1,4 @@
 /*
 /*
- * $Id: amq_subr.c,v 5.2 90/06/23 22:19:20 jsp Rel $
- *
  * Copyright (c) 1990 Jan-Simon Pendry
  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
  * Copyright (c) 1990 The Regents of the University of California.
  * Copyright (c) 1990 Jan-Simon Pendry
  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
  * Copyright (c) 1990 The Regents of the University of California.
@@ -9,21 +7,38 @@
  * This code is derived from software contributed to Berkeley by
  * Jan-Simon Pendry at Imperial College, London.
  *
  * This code is derived from software contributed to Berkeley by
  * Jan-Simon Pendry at Imperial College, London.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
+ *
+ *     @(#)amq_subr.c  5.3 (Berkeley) 5/12/91
+ *
+ * $Id: amq_subr.c,v 5.2.1.6 91/05/07 22:17:47 jsp Alpha $
  *
  *
- *     @(#)amq_subr.c  5.1 (Berkeley) 6/29/90
  */
 /*
  * Auxilliary routines for amq tool
  */
 /*
  * Auxilliary routines for amq tool
@@ -31,8 +46,7 @@
 
 #include "am.h"
 #include "amq.h"
 
 #include "am.h"
 #include "amq.h"
-
-#include <sys/param.h>
+#include <ctype.h>
 
 /*ARGSUSED*/
 voidp
 
 /*ARGSUSED*/
 voidp
@@ -99,25 +113,9 @@ struct svc_req *rqstp;
 {
        static amq_mount_tree_list aml;
 
 {
        static amq_mount_tree_list aml;
 
-#ifdef oldcode
-       static am_node **mvec;
-       int i;
-       int n = 0;
-
-       mvec = (struct am_node **)
-               xrealloc(mvec, (1+last_used_map) * sizeof(am_node *));
-       for (i = last_used_map; i >= 0; --i) {
-               am_node *mp = exported_ap[i];
-               if (mp && (mp->am_flags & AMF_ROOT))
-                       mvec[n++] = mp;
-       }
-
-       aml.amq_mount_tree_list_val = (amq_mount_tree_p *) mvec;
-       aml.amq_mount_tree_list_len = n;
-#else
        aml.amq_mount_tree_list_val = (amq_mount_tree_p *) &exported_ap[0];
        aml.amq_mount_tree_list_len = 1;        /* XXX */
        aml.amq_mount_tree_list_val = (amq_mount_tree_p *) &exported_ap[0];
        aml.amq_mount_tree_list_len = 1;        /* XXX */
-#endif /* oldcode */
+
        return &aml;
 }
 
        return &aml;
 }
 
@@ -159,6 +157,8 @@ struct svc_req *rqstp;
                if (amd_state == Run) {
                        plog(XLOG_INFO, "amq says flush cache");
                        do_mapc_reload = 0;
                if (amd_state == Run) {
                        plog(XLOG_INFO, "amq says flush cache");
                        do_mapc_reload = 0;
+                       flush_nfs_fhandle_cache((fserver *) 0);
+                       flush_srvr_nfs_cache();
                }
                break;
        }
                }
                break;
        }
@@ -174,6 +174,78 @@ extern qelem mfhead;
        return (amq_mount_info_list *) &mfhead; /* XXX */
 }
 
        return (amq_mount_info_list *) &mfhead; /* XXX */
 }
 
+static int ok_security(rqstp)
+struct svc_req *rqstp;
+{
+       struct sockaddr_in *sin;
+
+       sin = svc_getcaller(rqstp->rq_xprt);
+       if (ntohs(sin->sin_port) >= 1024 ||
+           !(sin->sin_addr.s_addr == htonl(0x7f000001) ||
+             sin->sin_addr.s_addr == myipaddr.s_addr)) {
+               char dq[20];
+               plog(XLOG_INFO, "AMQ request from %s.%d DENIED",
+                    inet_dquad(dq, sin->sin_addr.s_addr),
+                    ntohs(sin->sin_port));
+               return(0);
+       }
+       return(1);
+}
+
+int *
+amqproc_mount_1(argp, rqstp)
+voidp argp;
+struct svc_req *rqstp;
+{
+       static int rc;
+       char *s = *(amq_string *) argp;
+       char *cp;
+
+       plog(XLOG_INFO, "amq requested mount of %s", s);
+       /*
+        * Minimalist security check.
+        */
+       if (!ok_security(rqstp)) {
+               rc = EACCES;
+               return &rc;
+       }
+
+       /*
+        * Find end of key
+        */
+       for (cp = (char *) s; *cp&&(!isascii(*cp)||!isspace(*cp)); cp++)
+               ;
+
+       if (!*cp) {
+               plog(XLOG_INFO, "amqproc_mount: Invalid arguments");
+               rc = EINVAL;
+               return &rc;
+       }
+       *cp++ = '\0';
+
+       /*
+        * Find start of value
+        */
+       while (*cp && isascii(*cp) && isspace(*cp))
+               cp++;
+
+       root_newmap(s, cp, (char *) 0);
+       rc = mount_auto_node(s, (voidp) root_node);
+       if (rc < 0)
+               return 0;
+       return &rc;
+}
+
+amq_string *
+amqproc_getvers_1(argp, rqstp)
+voidp argp;
+struct svc_req *rqstp;
+{
+static amq_string res;
+       res = version;
+       return &res;
+}
+
 /*
  * XDR routines.
  */
 /*
  * XDR routines.
  */
@@ -206,7 +278,7 @@ xdr_amq_setopt(xdrs, objp)
  * More XDR routines  - Should be used for OUTPUT ONLY.
  */
 bool_t
  * More XDR routines  - Should be used for OUTPUT ONLY.
  */
 bool_t
-xdr_amq_mount_tree(xdrs, objp)
+xdr_amq_mount_tree_node(xdrs, objp)
        XDR *xdrs;
        amq_mount_tree *objp;
 {
        XDR *xdrs;
        amq_mount_tree *objp;
 {
@@ -245,10 +317,43 @@ xdr_amq_mount_tree(xdrs, objp)
        if (!xdr_int(xdrs, &mp->am_stats.s_statfs)) {
                return (FALSE);
        }
        if (!xdr_int(xdrs, &mp->am_stats.s_statfs)) {
                return (FALSE);
        }
-       if (!xdr_pointer(xdrs, (char **)&mp->am_osib, sizeof(amq_mount_tree), xdr_amq_mount_tree)) {
+       return (TRUE);
+}
+
+bool_t
+xdr_amq_mount_subtree(xdrs, objp)
+       XDR *xdrs;
+       amq_mount_tree *objp;
+{
+       am_node *mp = (am_node *) objp;
+
+       if (!xdr_amq_mount_tree_node(xdrs, objp)) {
+               return (FALSE);
+       }
+       if (!xdr_pointer(xdrs, (char **)&mp->am_osib, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
+               return (FALSE);
+       }
+       if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
+               return (FALSE);
+       }
+       return (TRUE);
+}
+
+bool_t
+xdr_amq_mount_tree(xdrs, objp)
+       XDR *xdrs;
+       amq_mount_tree *objp;
+{
+       am_node *mp = (am_node *) objp;
+       am_node *mnil = 0;
+
+       if (!xdr_amq_mount_tree_node(xdrs, objp)) {
+               return (FALSE);
+       }
+       if (!xdr_pointer(xdrs, (char **)&mnil, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
                return (FALSE);
        }
                return (FALSE);
        }
-       if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_tree)) {
+       if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
                return (FALSE);
        }
        return (TRUE);
                return (FALSE);
        }
        return (TRUE);
@@ -301,6 +406,7 @@ xdr_amq_mount_tree_list(xdrs, objp)
        return (TRUE);
 }
 
        return (TRUE);
 }
 
+bool_t
 xdr_amq_mount_info_qelem(xdrs, qhead)
        XDR *xdrs;
        qelem *qhead;
 xdr_amq_mount_info_qelem(xdrs, qhead)
        XDR *xdrs;
        qelem *qhead;