* 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
"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);
}
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));
#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.
*
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. */
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 */
}
* 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;
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);
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.