From: Daniel Ottavio Date: Sun, 7 Aug 2005 00:33:12 +0000 (+0000) Subject: up comments, additional sun2amd conversion routines X-Git-Tag: before-clocktime-fixes~50 X-Git-Url: https://git.fsl.cs.sunysb.edu/?a=commitdiff_plain;h=c672ff4bd82d8093b0ed100dda5fad74b148bba6;p=am-utils-6.0.git up comments, additional sun2amd conversion routines * 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. --- diff --git a/ChangeLog b/ChangeLog index 7259015..826f7ec 100644 --- 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. @@ -53,6 +53,13 @@ * 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 * amd/info_file.c (file_search, file_reload): pass mnt_map to diff --git a/amd/get_args.c b/amd/get_args.c index 33d46d2..c4747df 100644 --- a/amd/get_args.c +++ b/amd/get_args.c @@ -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); } diff --git a/amd/sun_map.c b/amd/sun_map.c index 5a1804f..e6ac3a0 100644 --- a/amd/sun_map.c +++ b/amd/sun_map.c @@ -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; diff --git a/include/am_utils.h b/include/am_utils.h index 24b193f..092cda7 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -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); diff --git a/libamu/strutil.c b/libamu/strutil.c index a7110e7..59dee3a 100644 --- a/libamu/strutil.c +++ b/libamu/strutil.c @@ -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.