* amd/Makefile.am: Added new files sun_map.h, sun_map.c,
authorDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Sat, 6 Aug 2005 19:45:07 +0000 (19:45 +0000)
committerDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Sat, 6 Aug 2005 19:45:07 +0000 (19:45 +0000)
sun_map_parse.y, and sun_map_tok.l.  These files add support for
parsing Sun style maps.  The yacc/lex files needed custom rules so
they don't cause symbol conflicts with each other.

* amd/amd.h: Added "#define INFO_MAX_LINE_LEN" that specifies the
line limit for info services.

* amd/info_exec.c: Replaced MAX_LINE_LEN with INFO_MAX_LINE_LEN

* amd/info_file.c: Replaced MAX_LINE_LEN with INFO_MAX_LINE_LEN,
added support for parsing Sun style maps.  The support for Sun
maps is done using the sun_entry2amd() function.  This function is
called for each entry line that is read only when Sun parsing is
enabled.  For each entry line that is passed to the function a copy of
the Amd equivalent is returned.

* amd/sun_map.h: new header file for Sun style map support

* amd/sun_map.c: new soruce file for Sun style map support

* amd/sun_map_parse.y: new yacc file for parsing Sun style maps

* amd/sun_map_tok.l: new lex file for parsing Sun style maps

ChangeLog
amd/Makefile.am
amd/amd.h
amd/info_exec.c
amd/info_file.c
amd/sun_map.c [new file with mode: 0644]
amd/sun_map.h [new file with mode: 0644]
amd/sun_map_parse.y [new file with mode: 0644]
amd/sun_map_tok.l [new file with mode: 0644]

index 81035a34cf71a9cebc8a7315daa200dcee2151b5..c80c6b3981a9c0ba6e6901d7014653c8fcf73f10 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2005-08-06  Daniel P. Ottavio  <dottavio@ic.sunysb.edu>
+
+       * amd/Makefile.am: Added new files sun_map.h, sun_map.c,
+       sun_map_parse.y, and sun_map_tok.l.  These files add support for
+       parsing Sun style maps.  The yacc/lex files needed custom rules so
+       they don't cause symbol conflicts with each other.  
+       
+       * amd/amd.h: Added "#define INFO_MAX_LINE_LEN" that specifies the
+       line limit for info services.
+
+       * amd/info_exec.c: Replaced MAX_LINE_LEN with INFO_MAX_LINE_LEN
+
+       * amd/info_file.c: Replaced MAX_LINE_LEN with INFO_MAX_LINE_LEN,
+       added support for parsing Sun style maps.  The support for Sun
+       maps is done using the sun_entry2amd() function.  This function is
+       called for each entry line that is read only when Sun parsing is
+       enabled.  For each entry line that is passed to the function a copy of
+       the Amd equivalent is returned.
+
+       * amd/sun_map.h: new header file for Sun style map support
+
+       * amd/sun_map.c: new soruce file for Sun style map support
+
+       * amd/sun_map_parse.y: new yacc file for parsing Sun style maps
+
+       * amd/sun_map_tok.l: new lex file for parsing Sun style maps
+
 2005-08-06  Erez Zadok  <ezk@cs.sunysb.edu>
 
        * doc/am-utils.texi (sun_map_syntax Parameter): document new
index 4d4fcbb6e7ace0718f8f9892feff1f70a7dc2100..936b8b85ab4d3081bef177b6a859e631e018f6ec 100644 (file)
@@ -13,7 +13,7 @@ man_MANS = amd.8
 TESTS = test1.sh
 
 # headers this depends on, not to be installed
-noinst_HEADERS = amd.h
+noinst_HEADERS = amd.h sun_map.h
 
 # *.y must be listed before *.l, because of a bug in automake-1.2
 # which will not generate the .h needs for the lex file from the yacc file.
@@ -58,7 +58,9 @@ amd_SOURCES =                 \
        rpc_fwd.c               \
        sched.c                 \
        srvr_amfs_auto.c        \
-       srvr_nfs.c
+       srvr_nfs.c              \
+       \
+       sun_map.c               
 
 # the complete list of all optional sources
 EXTRA_amd_SOURCES =    \
@@ -94,14 +96,25 @@ EXTRA_amd_SOURCES = \
 # filesystem types this system supports.
 # AMD_INFO_OBJS: a list of info_*.o objects added, depending on which map
 # types this system supports.
-EXTRA_amd_OBJECTS = @AMD_FS_OBJS@ @AMD_INFO_OBJS@
-LDADD = $(EXTRA_amd_OBJECTS) get_args.o ../libamu/libamu.la
+EXTRA_amd_OBJECTS = @AMD_FS_OBJS@ @AMD_INFO_OBJS@ sun_map_parse.o sun_map_tok.o
+LDADD = $(EXTRA_amd_OBJECTS) get_args.o ../libamu/libamu.la 
 # must manually add f/lex library to LIBS, and not to LDADD.
 LIBS = @LIBS@ @LEXLIB@ @WRAPLIB@
 
+# custom yacc/lex rules for the Sun map parser
+sun_map_parse.o : sun_map_parse.c
+
+sun_map_parse.c : sun_map_parse.y
+       $(YACC) -d -psun_map_ -o$@ $< 
+
+sun_map_tok.o : sun_map_tok.c
+
+sun_map_tok.c : sun_map_tok.l
+       $(LEX) -Psun_map_ -o$@ $<
+
 # additional files to distribute and clean
 EXTRA_DIST = ops_TEMPLATE.c $(man_MANS) $(TESTS)
-CLEANFILES = conf_tok.c conf_parse.c conf_parse.h
+CLEANFILES = conf_tok.c conf_parse.c conf_parse.h sun_map_parse.c sun_map_tok.c sun_map_parse.h
 DISTCLEANFILES = build_version.h
 
 # do not distribute files that should be generated by lex/yacc locally
@@ -133,3 +146,4 @@ $(amd_OBJECTS) $(EXTRA_amd_OBJECTS):                \
 # auto-generate build number
 build_version.h: $(amd_OBJECTS) $(EXTRA_amd_OBJECTS) get_args.c
        $(top_srcdir)/m4/update_build_version
+
index 3c949886e908ab07fcf2664708bc67547c5aa2ac..47895a7176d56b791587d618f28281703ec4954d 100644 (file)
--- a/amd/amd.h
+++ b/amd/amd.h
  * that support mtab on file.
  */
 #ifdef MOUNT_TABLE_ON_FILE
-# define DEBUG_MNTTAB_FILE               "/tmp/mnttab"
+# define DEBUG_MNTTAB_FILE              "/tmp/mnttab"
 #endif /* MOUNT_TABLE_ON_FILE */
 
+/* Max line length that info services can handle */
+#define INFO_MAX_LINE_LEN               1500
+
 /* options for amd.conf */
 #define CFM_BROWSABLE_DIRS             0x00000001
 #define CFM_MOUNT_TYPE_AUTOFS          0x00000002 /* use kernel autofs support */
index 74d2619c42ffc8601e283ec19dbef26cc1b97561..333f664b14a761a9c2c153982fc865ac2c74a898 100644 (file)
@@ -53,7 +53,6 @@
 #include <am_defs.h>
 #include <amd.h>
 
-#define        MAX_LINE_LEN            1500
 
 /* forward declarations */
 int exec_init(mnt_map *m, char *map, time_t *tp);
@@ -167,7 +166,7 @@ read_line(char *buf, int size, int fd)
 static int
 exec_parse_qanswer(int fd, char *map, char *key, char **pval, time_t *tp)
 {
-  char qanswer[MAX_LINE_LEN], *dc = 0;
+  char qanswer[INFO_MAX_LINE_LEN], *dc = 0;
   int chuck = 0;
   int line_no = 0;
 
index a961e69ab87baa1c0c17957bd5c8003826dbf2f2..9ce8e961982ddbf4a9a6802ac2f569c104bfd6f8 100644 (file)
@@ -50,8 +50,7 @@
 #endif /* HAVE_CONFIG_H */
 #include <am_defs.h>
 #include <amd.h>
-
-#define        MAX_LINE_LEN    1500
+#include <sun_map.h>
 
 /* forward declarations */
 int file_init_or_mtime(mnt_map *m, char *map, time_t *tp);
@@ -102,7 +101,7 @@ file_search_or_reload(FILE *fp,
                      mnt_map *m,
                      void (*fn) (mnt_map *m, char *, char *))
 {
-  char key_val[MAX_LINE_LEN];
+  char key_val[INFO_MAX_LINE_LEN];
   int chuck = 0;
   int line_no = 0;
 
@@ -159,7 +158,11 @@ file_search_or_reload(FILE *fp,
        /*
         * Return a copy of the data
         */
-       char *dc = strdup(cp);
+       char *dc;
+       if (m->cfm->cfm_flags & CFM_SUN_MAP_SYNTAX)
+         dc = sun_entry2amd(cp);
+       else
+         dc = strdup(cp);
        if (fn) {
          (*fn) (m, strdup(kp), dc);
        } else {
diff --git a/amd/sun_map.c b/amd/sun_map.c
new file mode 100644 (file)
index 0000000..ad0daca
--- /dev/null
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2005 Daniel Ottavio
+ * Copyright (c) 1997-2005 Erez Zadok
+ * 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.
+ * All rights reserved.
+ *
+ * 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, 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 acknowledgment:
+ *      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.
+ *
+ *
+ * File: am-utils/amd/sun_map.c
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+#include <am_defs.h>
+#include <amd.h>
+#include <sun_map.h>
+
+
+/*
+ * Allocate a sun_mmap struct.
+ * 
+ * return - sun_amap* on success, NULL no memory
+ */
+struct sun_mmap *sun_mmap_alloc() {
+
+  struct sun_mmap *retval;
+
+  retval = (struct sun_mmap*)xmalloc(sizeof(struct sun_mmap));
+  memset(retval,0,sizeof(struct sun_mmap));
+  
+  return retval;
+}
+
+/*
+ * Allocate a sun_map struct.
+ * 
+ * return - sun_map* on success, NULL no memory
+ */
+struct sun_map *sun_map_alloc() {
+  
+  struct sun_map *retval;
+
+  retval = (struct sun_map*)xmalloc(sizeof(struct sun_map));
+  memset(retval,0,sizeof(struct sun_map));
+  
+  return retval;
+}
+
+/*
+ * Allocate a sun_entry struct.
+ * 
+ * return - sun_entry* on success, NULL no memory
+ */
+struct sun_entry *sun_entry_alloc() {
+  
+  struct sun_entry *retval;
+  
+  retval = (struct sun_entry*)xmalloc(sizeof(struct sun_entry));
+  memset(retval,0,sizeof(struct sun_entry));
+  
+  return retval;
+}
+
+/*
+ * Allocate a sun_mountpt
+ *
+ * return - sun_mountpt* on success, NULL no memory
+ */
+struct sun_mountpt *sun_mountpt_alloc() {
+
+  struct sun_mountpt *retval;
+
+  retval = (struct sun_mountpt*)xmalloc(sizeof(struct sun_mountpt));
+  memset(retval,0,sizeof(struct sun_mountpt));
+  return retval;
+}
+
+/*
+ * Allocate a sun_location struct.
+ *
+ * return sun_location* on sucess, NULL no memory
+ */
+struct sun_location *sun_location_alloc() {
+  
+  struct sun_location *retval;
+
+  retval = (struct sun_location*)xmalloc(sizeof(struct sun_location));
+  memset(retval,0,sizeof(struct sun_location));
+  
+  return retval;
+}
+
+/*
+ * Allocate a sun_host struct.
+ *
+ * return sun_host* on sucess, NULL no memory 
+ */
+struct sun_host* sun_host_alloc() {
+  
+  struct sun_host *retval;
+  retval = (struct sun_host*)xmalloc(sizeof(struct sun_host));
+  memset(retval,0,sizeof(struct sun_host));
+  
+  return retval;
+}
+
+/*
+ * Allocate a sun_opt struct.
+ *
+ * return sun_opt* on sucess, NULL no memory 
+ */
+struct sun_opt* sun_opt_alloc() {
+  
+  struct sun_opt *retval;
+
+  retval = (struct sun_opt*)xmalloc(sizeof(struct sun_opt));
+  memset(retval,0,sizeof(struct sun_opt));
+  
+  return retval;
+}
+
+/*
+ * Allocate a sun_list struct.
+ *
+ * return sun_list* on sucess, NULL no memory 
+ */
+struct sun_list* sun_list_alloc() {
+  
+  struct sun_list *retval;
+
+  retval = (struct sun_list*)xmalloc(sizeof(struct sun_list));
+  memset(retval,0,sizeof(struct sun_list));
+  
+  return retval;
+}
+
+/*
+ * Add a data pointer to the end of the list.
+ * 
+ * param list 
+ * param data
+ */
+void sun_list_add(struct sun_list *list, qelem *item) {
+  
+  if (list->last == NULL) {
+    list->last = item;
+    list->first = item;
+    item->q_back = NULL;
+  }
+  else {
+    list->last->q_forw = item;
+    item->q_back = list->last;
+    list->last = item;
+  }
+
+  item->q_forw = NULL;
+}
+
+
+/*
+ * Sun2Amd conversion routines 
+ */
+
+/*
+ * A set of string Sun fstypes.
+ */
+#define SUN_NFS_TYPE     "nfs"
+#define SUN_HSFS_TYPE    "hsfs" /* CD fs */
+#define SUN_AUTOFS_TYPE  "autofs"
+#define SUN_CACHEFS_TYPE "cachefs"
+
+
+/*
+ * Convert the sun_entry into an Amd equivalent string.
+ *
+ * return - Adm entry string on success, null on error. 
+ */
+char *sun_entry2amd(const char *a_entry) {
+  
+  char *retval = NULL;
+  struct sun_entry *s_entry;
+  
+  /* Parse the sun entry line. */
+  s_entry = sun_map_parse_read(a_entry);
+  if (s_entry == NULL) {
+    plog(XLOG_ERROR,"could not parse Sun style map");
+    goto err;
+  }
+
+  /* convert the mount options. */
+
+  /* Check the fstype. */
+  if(s_entry->fstype != NULL) { 
+    if(NSTREQ(s_entry->fstype,SUN_NFS_TYPE,strlen(SUN_NFS_TYPE))) {
+      /* NFS Type */
+      
+    }
+    else if(NSTREQ(s_entry->fstype,SUN_HSFS_TYPE,strlen(SUN_HSFS_TYPE))) {
+      /* HSFS Type (CD fs) */
+      
+    }
+    else if(NSTREQ(s_entry->fstype,SUN_AUTOFS_TYPE,strlen(SUN_AUTOFS_TYPE))) {
+      /* AutoFS Type */
+      
+    }
+    else if(NSTREQ(s_entry->fstype,SUN_CACHEFS_TYPE,strlen(SUN_CACHEFS_TYPE))) {
+      /* CacheFS Type */
+      
+    }
+    else {
+      plog(XLOG_ERROR,"Sun fstype %s is currently not supported by Amd.",s_entry->fstype);
+      goto err;
+    }
+  }
+  else {
+    plog(XLOG_INFO,"No SUN fstype specified defaulting to NFS.");
+  }
+  
+
+ err:
+  /* 
+   * XXX: For now this function will just pass back a copy of the sun
+   * entry. 
+   */
+  if(retval == NULL) {
+    retval = strdup(a_entry);
+  }
+  return retval;
+}  
diff --git a/amd/sun_map.h b/amd/sun_map.h
new file mode 100644 (file)
index 0000000..a2772ec
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2005 Daniel Ottavio
+ * Copyright (c) 1997-2005 Erez Zadok
+ * 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.
+ * All rights reserved.
+ *
+ * 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, 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 acknowledgment:
+ *      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.
+ *
+ *
+ * File: am-utils/amd/sun_map.h
+ *
+ */
+
+#ifndef _SUN_MAP_H
+#define _SUN_MAP_H
+
+
+/* host */
+struct sun_host {
+  qelem head;     /* link-list header */
+  char *name;     /* hostname */
+  int weight;     /* weight given to the host */
+};
+
+/* location */
+struct sun_location {
+  qelem head;                 /* link-list header */
+  char *path;                 /* server path */
+  struct sun_host *host_list; /* list of hosts */
+};
+
+/* sun mount option */
+struct sun_opt {
+  qelem head;    /* link-list header */
+  char *str;     /* option string */
+};
+
+/* mount point */
+struct sun_mountpt {
+  qelem head;                         /* link-list header */
+  char *path;                         /* optional mount point path */
+  struct sun_opt      *opt_list;      /* list of option strings */
+  struct sun_location *location_list; /* list of 'struct s2a_location' */
+};
+
+/* automount entry */
+struct sun_entry {
+  qelem head;                         /* link-list header */
+  char *key;                          /* auto map key */
+  char *fstype;                       /* filesystem type */
+  struct sun_opt      *opt_list;      /* list of mount options */
+  struct sun_location *location_list; /* list of mount locations */
+  struct sun_mountpt  *mountpt_list;  /* list of mount points */
+};
+
+/* automount map file */ 
+struct sun_map {
+  qelem head;                     /* link-list header */
+  char *path;                     /* directory path of the map file */
+  char *mount_dir;                /* top level mount point for this map */
+  int  lookup;                    /* lookup type i.e file, yp, program, etc. */
+  int  direct_bool;               /* set true if this map is a direct map */
+  struct sun_opt   *opt_list;     /* list of global map options */
+  struct sun_opt   *include_list; /* list of included map files  */
+  struct sun_entry *entry_list;   /* list of 'struct s2a_entry' */
+};
+
+/* master map file */
+struct sun_mmap {
+  qelem head;                   /* link-list header */
+  struct sun_opt *include_list; /* list of included master maps */
+  struct sun_map *amap_list;    /* list of 'struct s2a_amap' */
+};
+
+struct sun_list {
+  qelem *first;
+  qelem *last;
+};
+
+
+struct sun_mmap *sun_mmap_alloc();
+struct sun_map *sun_map_alloc();
+struct sun_entry *sun_entry_alloc();
+struct sun_mountpt *sun_mountpt_alloc();
+struct sun_location *sun_location_alloc();
+struct sun_opt *sun_opt_alloc();
+struct sun_host *sun_host_alloc();
+struct sun_list *sun_list_alloc();
+
+void sun_list_add(struct sun_list *, qelem *);
+
+struct sun_entry *sun_map_parse_read(const char *);
+
+char *sun_entry2amd(const char *);
+
+#endif /* not _SUN_MAP_H */
diff --git a/amd/sun_map_parse.y b/amd/sun_map_parse.y
new file mode 100644 (file)
index 0000000..da57b1c
--- /dev/null
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) 1997-2005 Erez Zadok
+ * 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.
+ * All rights reserved.
+ *
+ * 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, 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 acknowledgment:
+ *      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.
+ *
+ *
+ * $Id: sun_map_parse.y,v 1.1 2005/08/06 19:45:07 ottavio Exp $
+ *
+ */
+
+%{
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+#include <am_defs.h>
+#include <amd.h>
+#include <sun_map.h>
+
+extern int sun_map_lex();
+extern int sun_map_error(const char* s);
+extern void sun_map_tok_setbuff(const char *);
+
+struct sun_entry *sun_map_parse_read(const char *map_data);
+
+static struct sun_list *sun_entry_list = NULL;
+static struct sun_list *sun_include_list = NULL;
+static struct sun_list *sun_opt_list = NULL;
+static struct sun_list *sun_host_list = NULL;
+static struct sun_list *sun_location_list = NULL;
+static struct sun_list *mountpt_list = NULL;
+static char* tmpFsType = NULL;
+
+
+/*
+ * Each get* function returns a pointer to the corresponding global
+ * list structure.  If the structure is NULL than a new instance is
+ * returned.
+ */
+static struct sun_list *get_sun_include_list();
+static struct sun_list *get_sun_opt_list();
+static struct sun_list *get_sun_host_list();
+static struct sun_list *get_sun_location_list();
+static struct sun_list *get_mountpt_list();
+static struct sun_list *get_sun_entry_list();
+
+%}
+
+%union {
+  char strval[2048];
+}
+
+%token NEWLINE COMMENT WSPACE
+%token <strval> WORD 
+
+%%
+
+amap : file
+     ;
+
+file : new_lines entries
+     | entries
+     ;
+
+entries : entry 
+        | entry new_lines
+        | entry new_lines entries
+        ;
+
+new_lines : NEWLINE
+          | NEWLINE new_lines
+          ;
+
+entry : locations {
+
+  struct sun_list *list;
+  struct sun_entry *entry;
+  
+  /* allocate an entry */
+  entry = sun_entry_alloc();
+  
+  /* 
+   * Assign the global location list to this entry and reset the
+   * global pointer.  Reseting the global pointer will create a new
+   * list instance next time get_sun_location_list() is called.
+   */
+  list = get_sun_location_list();
+  entry->location_list = (struct sun_location *)list->first;
+  sun_location_list = NULL;
+  
+   /* Add this entry to the entry list. */
+  sun_list_add(get_sun_entry_list(),(qelem *)entry);
+}
+
+| '-' options WSPACE locations {
+
+  struct sun_list *list;
+  struct sun_entry *entry;
+  
+  entry = sun_entry_alloc();
+
+  /* An fstype may have been defined in the 'options'. */
+  if(tmpFsType != NULL) {
+    entry->fstype = tmpFsType;
+    tmpFsType = NULL;
+  }
+    
+  /* 
+   * Assign the global location list to this entry and reset the
+   * global pointer.  Reseting the global pointer will create a new
+   * list instance next time get_sun_location_list() is called.
+   */
+  list = get_sun_location_list();
+  entry->location_list = (struct sun_location *)list->first;
+  sun_location_list = NULL;
+  
+  /* 
+   * Assign the global opt list to this entry and reset the global
+   * pointer.  Reseting the global pointer will create a new list
+   * instance next time get_sun_opt_list() is called.
+   */
+  list = get_sun_opt_list();
+  entry->opt_list = (struct sun_opt *)list->first;
+  sun_opt_list = NULL;
+
+  /* Add this entry to the entry list. */
+  sun_list_add(get_sun_entry_list(),(qelem *)entry);
+}
+
+
+| mountpoints {
+
+  struct sun_list *list;
+  struct sun_entry *entry;
+  
+  /* allocate an entry */
+  entry = sun_entry_alloc();
+  
+  /* 
+   * Assign the global mountpt list to this entry and reset the global
+   * pointer.  Reseting the global pointer will create a new list
+   * instance next time get_mountpt_list() is called.
+   */
+  list = get_mountpt_list();
+  entry->mountpt_list = (struct sun_mountpt *)list->first;
+  mountpt_list = NULL;
+
+  /* Add this entry to the entry list. */
+  sun_list_add(get_sun_entry_list(),(qelem *)entry);
+}
+
+| '-' options WSPACE mountpoints {
+
+  struct sun_list *list;
+  struct sun_entry *entry;
+  
+  /* allocate an entry */
+  entry = sun_entry_alloc(); 
+
+  /* An fstype may have been defined in the 'options'. */
+  if(tmpFsType != NULL) {
+    entry->fstype = tmpFsType;
+    tmpFsType = NULL;
+  }
+  
+  /* 
+   * Assign the global mountpt list to this entry and reset the global
+   * pointer.  Reseting the global pointer will create a new list
+   * instance next time get_mountpt_list() is called.
+   */
+  list = get_mountpt_list();
+  entry->mountpt_list = (struct sun_mountpt *)list->first;
+  mountpt_list = NULL;
+  /* 
+   * Assign the global opt list to this entry and reset the global
+   * pointer.  Reseting the global pointer will create a new list
+   * instance next time get_sun_opt_list() is called.
+   */
+  list = get_sun_opt_list();
+  entry->opt_list = (struct sun_opt *)list->first;
+  sun_opt_list = NULL;
+  
+  /* Add this entry to the entry list. */
+  sun_list_add(get_sun_entry_list(),(qelem *)entry);
+}
+
+| '+' WORD {
+  
+  struct sun_opt *include = sun_opt_alloc();
+  include->str = strdup($2);
+  
+  sun_list_add(get_sun_include_list(),(qelem *)include);
+}
+;  
+
+mountpoints : mountpoint
+            | mountpoint WSPACE mountpoints
+            ;
+
+mountpoint : WORD WSPACE location {
+
+  struct sun_list *list;
+  struct sun_mountpt *mountpt;
+
+  /* allocate a mountpt */
+  mountpt = sun_mountpt_alloc();
+  
+  /* 
+   * Assign the global loaction list to this entry and reset the
+   * global pointer.  Reseting the global pointer will create a new
+   * list instance next time get_sun_location_list() is called.
+   */
+  list = get_sun_location_list();
+  mountpt->location_list = (struct sun_location *)list->first;
+  sun_location_list = NULL;
+  
+  mountpt->path = strdup($1);
+  
+  /* Add this mountpt to the mountpt list. */
+  sun_list_add(get_mountpt_list(),(qelem *)mountpt);
+}
+
+| WORD WSPACE '-' options WSPACE location {
+
+  struct sun_list *list;
+  struct sun_mountpt *mountpt;
+  
+  /* allocate a mountpt */
+  mountpt = sun_mountpt_alloc();
+  
+  /* 
+   * Assign the global loaction list to this entry and reset the
+   * global pointer.  Reseting the global pointer will create a new
+   * list instance next time get_sun_location_list() is called.
+   */
+  list = get_sun_location_list();
+  mountpt->location_list = (struct sun_location *)list->first;
+  sun_location_list = NULL;
+  /* 
+   * Assign the global opt list to this entry and reset the global
+   * pointer.  Reseting the global pointer will create a new list
+   * instance next time get_sun_opt_list() is called.
+   */
+  list = get_sun_opt_list();
+  mountpt->opt_list = (struct sun_opt *)list->first;
+  sun_opt_list = NULL;
+  
+  mountpt->path = strdup($1);
+  
+  /* Add this mountpt to the mountpt list. */
+  sun_list_add(get_mountpt_list(),(qelem *)mountpt);
+}
+;
+
+locations : location 
+          | location WSPACE locations
+          ;
+
+location : hosts ':' WORD {
+  
+  struct sun_list *list;
+  struct sun_location *location;
+  
+  /* allocate a new location */
+  location = sun_location_alloc();
+  
+  /* 
+   * Assign the global opt list to this entry and reset the global
+   * pointer.  Reseting the global pointer will create a new list
+   * instance next time get_sun_opt_list() is called.
+   */
+  list = get_sun_host_list();
+  location->host_list = (struct sun_host *)list->first;
+  sun_host_list = NULL;
+  
+  location->path = strdup($3);
+  
+  /* Add this location to the location list. */
+  sun_list_add(get_sun_location_list(),(qelem *)location);
+}
+
+| ':' WORD {
+  
+  struct sun_location *location;
+  
+  /* allocate a new location */
+  location = sun_location_alloc();
+  
+  location->path = strdup($2);
+  
+  /* Add this location to the location list. */
+  sun_list_add(get_sun_location_list(),(qelem *)location);
+}
+;
+
+hosts : host
+      | host ',' hosts
+      ;
+
+host : WORD {
+  
+  /* allocate a new host */
+  struct sun_host *host = sun_host_alloc();
+  
+  host->name = strdup($1);
+  
+  /* Add this host to the host list. */
+  sun_list_add(get_sun_host_list(),(qelem *)host);
+}
+
+| WORD weight {
+
+  /*
+   * It is assumed that the host for this rule was allocated by the
+   * 'weight' rule and assigned to be the last host item on the host
+   * list.
+   */
+  struct sun_host *host = (struct sun_host *)sun_host_list->last;
+  
+  host->name = strdup($1);
+}
+;
+
+weight : '(' WORD ')' {
+  
+  int val;
+  /* allocate a new host */
+  struct sun_host *host = sun_host_alloc();
+  
+  val = atoi($2);
+  
+  host->weight = val;
+
+  /* Add this host to the host list. */
+  sun_list_add(get_sun_host_list(),(qelem *)host);
+}
+;
+
+options : option 
+        | option ',' options
+        ;
+  
+/* file system type option */
+option : 'fstype='WORD {
+  
+  tmpFsType = strdup($2);
+}
+
+/* all other fs options */
+| WORD {
+  
+  struct sun_opt *opt = sun_opt_alloc();
+  opt->str = strdup($1);
+
+  /* Add this opt to the opt list. */
+  sun_list_add(get_sun_opt_list(),(qelem *)opt);
+}
+
+; 
+
+%%
+
+struct sun_entry *sun_map_parse_read(const char *map_data) {
+
+  struct sun_entry *retval = NULL;
+
+  /* pass map_data to lex */
+  sun_map_tok_setbuff(map_data);
+  
+  /* call yacc */
+  sun_map_parse();
+  
+  if (sun_entry_list != NULL) {
+    /* return the first Sun entry in the list */
+    retval = (struct sun_entry*)sun_entry_list->first;
+  }
+  else {
+    plog(XLOG_ERROR,"Sun map parser did not produce data structs.");
+  }
+  
+  return retval;
+}
+
+
+static struct sun_list *get_sun_include_list() {
+  if(sun_include_list == NULL) {
+    sun_include_list = sun_list_alloc();
+  }
+  return sun_include_list;
+}
+
+static struct sun_list *get_sun_entry_list() {
+  if(sun_entry_list == NULL) {
+    sun_entry_list = sun_list_alloc();
+  }
+  return sun_entry_list;
+}
+
+static struct sun_list *get_mountpt_list() {
+  if(mountpt_list == NULL) {
+    mountpt_list = sun_list_alloc();
+  }
+  return mountpt_list;
+}
+
+static struct sun_list *get_sun_location_list() {
+  if(sun_location_list == NULL) {
+    sun_location_list = sun_list_alloc();
+  }
+  return sun_location_list;
+}
+
+static struct sun_list *get_sun_host_list() {
+  if(sun_host_list == NULL) {
+    sun_host_list = sun_list_alloc();
+  }
+  return sun_host_list;
+}
+
+static struct sun_list *get_sun_opt_list() {
+  if(sun_opt_list == NULL) {
+    sun_opt_list = sun_list_alloc();
+  }
+  return sun_opt_list;
+}
diff --git a/amd/sun_map_tok.l b/amd/sun_map_tok.l
new file mode 100644 (file)
index 0000000..0ea8a20
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 1997-2005 Erez Zadok
+ * 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.
+ * All rights reserved.
+ *
+ * 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, 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 acknowledgment:
+ *      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.
+ *
+ *
+ * $Id: sun_map_tok.l,v 1.1 2005/08/06 19:45:07 ottavio Exp $
+ *
+ */
+
+%{
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* HAVE_CONFIG_H */
+#include <am_defs.h>
+#include <amd.h>
+
+
+#include <string.h>
+#include <sun_map_parse.h>
+
+/* 
+ * We need to configure lex to parse from a string 
+ * instead of a file. Each version of lex has it's
+ * own way of doing this(sigh).
+ */ 
+#ifdef FLEX_SCANNER
+
+/* assign the buffer to parse */
+void sun_map_tok_setbuff(const char* buff);
+
+/* buffer that contains the string to parse */
+const char *sun_map_tok_buff = NULL;
+
+/* current position of the buffer */
+const char *sun_map_tok_pos = NULL;
+
+/* size of the buffer */
+const char *sun_map_tok_end = NULL; 
+
+/* copies the current position + maxsize into buff */
+int sun_map_yyinput(char *buff, int maxsize);
+
+# undef YY_INPUT 
+# define YY_INPUT(buff,result,maxsize) (result = sun_map_yyinput(buff,maxsize))
+#else
+# warning "Currently flex is the only supported version of lex."
+
+#endif /* FLEX_SCANNER */
+
+int sun_map_line = 1;
+int sun_map_tokpos = 1;
+
+%}
+
+WORD_REX       ([A-Za-z0-9_/&".""$"=""-"]+)|"*"
+COMMENT_REX    ^#.*\n
+WSPACE_REX     [ \t]*
+NEWLINE_REX    [ \t]*\n
+CONTINUE_REX   "\\"\n
+
+/* 
+ * This option causes Solaris lex to fail.  Use flex.  See BUGS file
+ * no need to use yyunput() 
+ */
+%option nounput
+
+%%
+
+{WORD_REX}      { 
+                  sun_map_tokpos += yyleng; 
+                  strncpy(sun_map_lval.strval,yytext,sizeof(sun_map_lval.strval));
+                  sun_map_lval.strval[sizeof(sun_map_lval.strval) - 1] = '\0';
+                  return WORD;
+                }
+
+{WSPACE_REX}    {
+                  sun_map_tokpos += yyleng; 
+                  return WSPACE;
+                } 
+
+{NEWLINE_REX}   {
+                  sun_map_tokpos = 0; 
+                  sun_map_line++; 
+                  return NEWLINE;
+                }
+
+{CONTINUE_REX}  {
+                  sun_map_tokpos = 0; 
+                  sun_map_line++;
+                }
+
+{COMMENT_REX}   {
+                  sun_map_line++;
+                }
+
+.               {
+                  return yytext[0];
+                }
+
+%%
+
+int sun_map_error(const char* s) {
+  plog(XLOG_ERROR,"sun2amd : parsing error : line %d, column %d\n",
+       sun_map_line,sun_map_tokpos);
+  return 1;
+}
+
+int sun_map_wrap() {
+  return 1;
+}
+
+#ifdef FLEX_SCANNER
+void sun_map_tok_setbuff(const char* buff) {
+  
+  sun_map_tok_end = buff + strlen(buff);
+  sun_map_tok_pos = buff;
+  sun_map_tok_buff = buff;
+}
+
+int sun_map_yyinput(char *buff, int maxsize) {
+  
+  int size = MIN(maxsize, (sun_map_tok_end - sun_map_tok_pos));
+  if (size > 0) {
+    memcpy(buff,sun_map_tok_pos,size);
+    sun_map_tok_pos += size;
+  }
+
+  return size;
+}
+#endif /* FLEX_SCANNER */