up comments, additional sun2amd conversion routines
authorDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Sun, 7 Aug 2005 00:33:12 +0000 (00:33 +0000)
committerDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Sun, 7 Aug 2005 00:33:12 +0000 (00:33 +0000)
* amd/get_args.c: replace usage of strlcat with xstrlcat

* include/am_utils.h: added 'extern void xstrlcat()'

* libamu/util.c: Added a xstrlcat() function that wraps the
syscall strlcat() so that string truncations can be logged.

ChangeLog
amd/get_args.c
amd/sun_map.c
include/am_utils.h
libamu/strutil.c

index 7259015db01c7d11b1a3ab22c0e8e3598c3a3271..826f7ec95e77bab49517582511b0caed144fb098 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -45,7 +45,7 @@
        * amd/sun_map.h: new header file for Sun style map support
 
        * amd/sun_map.c: new source file for Sun style map support, clean
-       up comments.
+       up comments, additional sun2amd conversion routines
 
        * amd/sun_map_parse.y: new yacc file for parsing Sun style maps,
        fix copyright notice, put filename below license.
        * amd/sun_map_tok.l: new lex file for parsing Sun style maps, fix
        copyright notice, put filename below license.
 
+       * amd/get_args.c: replace usage of strlcat with xstrlcat
+
+       * include/am_utils.h: added 'extern void xstrlcat()'
+
+       * libamu/util.c: Added a xstrlcat() function that wraps the
+       syscall strlcat() so that string truncations can be logged.
+       
 2005-08-06  Erez Zadok  <ezk@cs.sunysb.edu>
 
        * amd/info_file.c (file_search, file_reload): pass mnt_map to
index 33d46d2cc5463e7de96da3db16aa376548a293af..c4747df932ffeaa4321a7f08e68bed169cb4a689 100644 (file)
@@ -90,38 +90,38 @@ get_version_string(void)
            "Copyright (c) 1990 The Regents of the University of California.");
   xsnprintf(tmpbuf, sizeof(tmpbuf), "%s version %s (build %d).\n",
            PACKAGE_NAME, PACKAGE_VERSION, AMU_BUILD_VERSION);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
   xsnprintf(tmpbuf, sizeof(tmpbuf), "Report bugs to %s.\n", PACKAGE_BUGREPORT);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
   xsnprintf(tmpbuf, sizeof(tmpbuf), "Configured by %s@%s on date %s.\n",
            USER_NAME, HOST_NAME, CONFIG_DATE);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
   xsnprintf(tmpbuf, sizeof(tmpbuf), "Built by %s@%s on date %s.\n",
            BUILD_USER, BUILD_HOST, BUILD_DATE);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
   xsnprintf(tmpbuf, sizeof(tmpbuf), "cpu=%s (%s-endian), arch=%s, karch=%s.\n",
            cpu, endian, gopt.arch, gopt.karch);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
   xsnprintf(tmpbuf, sizeof(tmpbuf), "full_os=%s, os=%s, osver=%s, vendor=%s, distro=%s.\n",
            gopt.op_sys_full, gopt.op_sys, gopt.op_sys_ver, gopt.op_sys_vendor, DISTRO_NAME);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
   xsnprintf(tmpbuf, sizeof(tmpbuf), "domain=%s, host=%s, hostd=%s.\n",
            hostdomain, am_get_hostname(), hostd);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
 
-  strlcat(vers, "Map support for: ", len);
+  xstrlcat(vers, "Map support for: ", len);
   mapc_showtypes(tmpbuf);
-  strlcat(vers, tmpbuf, len);
-  strlcat(vers, ".\nAMFS: ", len);
+  xstrlcat(vers, tmpbuf, len);
+  xstrlcat(vers, ".\nAMFS: ", len);
   ops_showamfstypes(tmpbuf);
-  strlcat(vers, tmpbuf, len);
-  strlcat(vers, ", inherit.\nFS: ", len); /* hack: "show" that we support type:=inherit */
+  xstrlcat(vers, tmpbuf, len);
+  xstrlcat(vers, ", inherit.\nFS: ", len); /* hack: "show" that we support type:=inherit */
   ops_showfstypes(tmpbuf);
-  strlcat(vers, tmpbuf, len);
+  xstrlcat(vers, tmpbuf, len);
 
   /* append list of networks if available */
   if (wire_buf) {
-    strlcat(vers, wire_buf, len);
+    xstrlcat(vers, wire_buf, len);
     XFREE(wire_buf);
   }
 
index 5a1804fd0fe3670218e7cceb7e6486992b88c75d..e6ac3a03c147844ab615e7c3190e5da09360977c 100644 (file)
@@ -125,15 +125,17 @@ struct sun_location *sun_location_alloc() {
   return retval;
 }
 
+
 /*
  * Allocate a sun_host struct.
  *
  * return sun_host* on sucess, NULL no memory 
  */
-struct sun_host* sun_host_alloc() {
-  
+struct sun_host* 
+sun_host_alloc(void)
+{
   struct sun_host *retval;
-  retval = (struct sun_host*)xmalloc(sizeof(struct sun_host));
+  retval = (struct sun_host*) xmalloc(sizeof(struct sun_host));
  
   memset(retval,0,sizeof(struct sun_host));
   
@@ -202,6 +204,83 @@ void sun_list_add(struct sun_list *list, qelem *item) {
 #define SUN_CACHEFS_TYPE "cachefs"
 
 
+/*
+ * Convert the list of Sun mount options to Amd mount options.  The
+ * result is concatenated to dest.
+ */
+static void sun_opts2amd(char *dest, size_t destlen, const struct sun_opt *opt_list) {
+  
+  const struct sun_opt *opt;
+  
+  xstrlcat(dest,"opts:=",destlen);
+
+  /* Iterate through each option and append it to the buffer. */
+  for(opt = opt_list; opt != NULL; opt = NEXT(struct sun_opt,opt)) {
+    xstrlcat(dest,opt->str,destlen);
+    if(NEXT(struct sun_opt,opt) != NULL) {
+      xstrlcat(dest,",",destlen);
+    }
+  }
+  xstrlcat(dest,";",destlen);
+}
+
+/*
+ * Convert the list of Sun mount locations to a list of Amd mount
+ * locations.  The result is concatenated to dest.
+ */
+static void sun_locations2amd(char *dest, size_t destlen, 
+                             const struct sun_location *local_list) {
+  const struct sun_location *local;
+  const struct sun_host *host;
+
+  for (local = local_list; local != NULL; local = NEXT(struct sun_location,local)) {
+    /* 
+     * Check to see if the list of hosts is empty.  Some mount types
+     * i.e cd-rom may have mount location with no host.
+     */
+    if (local->host_list != NULL) {
+      /* Write each host that belongs to this location. */
+      for (host = local->host_list; host != NULL; host = NEXT(struct sun_host,host)) {
+       xstrlcat(dest,"rhost:=",destlen);
+       xstrlcat(dest,host->name,destlen);
+       xstrlcat(dest,";",destlen);
+       xstrlcat(dest,"rfs:=",destlen);
+       xstrlcat(dest,local->path,destlen);
+       xstrlcat(dest,";",destlen);
+       if (NEXT(struct sun_host,host) != NULL) {
+         /* add a space to seperate each host listing */
+         xstrlcat(dest," ",destlen);
+       }
+      }
+    }
+    else {
+      /* no host location */
+      xstrlcat(dest,"fs:=",destlen);
+      xstrlcat(dest,local->path,destlen);
+    }
+  }
+}
+
+/*
+ * Convert a Sun NFS automount entry to an Amd.  The result is concatenated into dest.
+ */
+static void sun_nfs2amd(char *dest, size_t destlen, const struct sun_entry *s_entry) {
+  
+  /*
+   * If the Sun entry has muliple mount points we use type:=auto along
+   * with auto entries.  For a single mount point just use type:=nfs.
+   */
+  if (s_entry->mountpt_list == NULL) {
+    /* single NFS mount point */
+    xstrlcat(dest,"type:=nfs;",destlen);
+    if(s_entry->location_list != NULL) {
+      /* write out the list of mountpoint locations */
+      sun_locations2amd(dest,destlen,s_entry->location_list);
+    }
+  }
+}
+
 /*
  * Convert the sun_entry into an Amd equivalent string.
  *
@@ -210,6 +289,7 @@ void sun_list_add(struct sun_list *list, qelem *item) {
 char *sun_entry2amd(const char *a_entry) {
   
   char *retval = NULL;
+  char line_buff[INFO_MAX_LINE_LEN];  
   struct sun_entry *s_entry;
   
   /* Parse the sun entry line. */
@@ -219,23 +299,28 @@ char *sun_entry2amd(const char *a_entry) {
     goto err;
   }
 
-  /* convert the mount options. */
+  memset(line_buff,0,sizeof(line_buff));
 
+  if (s_entry->opt_list != NULL) {
+    /* write the mount options to the buffer  */
+    sun_opts2amd(line_buff,sizeof(line_buff),s_entry->opt_list);
+  }
+  
   /* Check the fstype. */
-  if(s_entry->fstype != NULL) { 
-    if(NSTREQ(s_entry->fstype,SUN_NFS_TYPE,strlen(SUN_NFS_TYPE))) {
+  if (s_entry->fstype != NULL) { 
+    if (NSTREQ(s_entry->fstype,SUN_NFS_TYPE,strlen(SUN_NFS_TYPE))) {
       /* NFS Type */
-      
+      sun_nfs2amd(line_buff,sizeof(line_buff),s_entry);
     }
-    else if(NSTREQ(s_entry->fstype,SUN_HSFS_TYPE,strlen(SUN_HSFS_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))) {
+    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))) {
+    else if (NSTREQ(s_entry->fstype,SUN_CACHEFS_TYPE,strlen(SUN_CACHEFS_TYPE))) {
       /* CacheFS Type */
       
     }
@@ -254,7 +339,7 @@ char *sun_entry2amd(const char *a_entry) {
    * XXX: For now this function will just pass back a copy of the sun
    * entry. 
    */
-  if(retval == NULL) {
+  if (retval == NULL) {
     retval = strdup(a_entry);
   }
   return retval;
index 24b193f9ef28d4295124347aeb620ea14bf12312..092cda7c9a59a56c4322fee74daf43454766277a 100644 (file)
@@ -325,6 +325,7 @@ extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long);
 extern void set_amd_program_number(int program);
 extern void show_opts(int ch, struct opt_tab *);
 extern void xstrlcpy(char *dst, const char *src, size_t len);
+extern void xstrlcat(char *dst, const char *src, size_t len);
 extern void unregister_amq(void);
 extern voidp xmalloc(int);
 extern voidp xrealloc(voidp, int);
index a7110e7276401b66e7616aba782f168ac5e24e5e..59dee3ab62f2b9dcb1d0103aba486b9857c584aa 100644 (file)
@@ -99,6 +99,26 @@ xstrlcpy(char *dst, const char *src, size_t len)
     plog(XLOG_ERROR, "xstrlcpy: string \"%s\" truncated to \"%s\"", src, dst);
 }
 
+/*
+ * Use generic strlcat to concatenate a string more carefully,
+ * null-terminating it as needed.  However, if the copied string was
+ * truncated due to lack of space, then warn us.
+ *
+ * For now, xstrlcat returns VOID because it doesn't look like anywhere in
+ * the Amd code do we actually use the return value of strncat/strlcat.
+ */
+void
+xstrlcat(char *dst, const char *src, size_t len)
+{
+  if (len == 0)
+    return;
+  if (strlcat(dst, src, len) >= len) {
+    /* strlcat does not null terminate if the size of src is equal to len. */
+    dst[strlen(dst) - 1] = '\0';
+    plog(XLOG_ERROR, "xstrlcat: string \"%s\" truncated to \"%s\"", src, dst);
+  }
+}
+
 
 /*
  * Make all the directories in the path.