Blame SOURCES/autofs-5.1.3-refactor-amd_parse_c.patch

306fa1
autofs-5.1.3 - refactor amd_parse.c
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
Refactor some blocks of code into functions to allow later reuse.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG           |    1 
306fa1
 modules/amd_parse.y |  293 ++++++++++++++++++++++++++++++++++------------------
306fa1
 2 files changed, 197 insertions(+), 97 deletions(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -273,6 +273,7 @@
306fa1
 - fix symlink false negative in umount_multi().
306fa1
 - remove expand_selectors() on amd parser entry.
306fa1
 - fix amd defaults map entry handling.
306fa1
+- refactor amd_parse.c.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/modules/amd_parse.y
306fa1
+++ autofs-5.0.7/modules/amd_parse.y
306fa1
@@ -55,6 +55,11 @@ static int make_selector(char *name,
306fa1
 			 unsigned int compare);
306fa1
 static void add_selector(struct selector *selector);
306fa1
 
306fa1
+static int match_map_option_fs_type(char *map_option, char *type);
306fa1
+static int match_map_option_map_type(char *map_option, char *type);
306fa1
+static int match_map_option_cache_option(char *type);
306fa1
+static int match_mnt_option_options(char *mnt_option, char *options);
306fa1
+
306fa1
 static struct amd_entry entry;
306fa1
 static struct list_head *entries;
306fa1
 static struct autofs_point *pap;
306fa1
@@ -253,86 +258,13 @@ selection: SELECTOR IS_EQUAL SELECTOR_VA
306fa1
 
306fa1
 option_assignment: MAP_OPTION OPTION_ASSIGN FS_TYPE
306fa1
 	{
306fa1
-		if (!strcmp($3, "auto")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_AUTO;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "nfs") ||
306fa1
-			   !strcmp($3, "nfs4")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_NFS;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "nfsl")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_NFSL;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "link")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_LINK;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "linkx")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_LINKX;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "host")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_HOST;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "lofs")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_LOFS;
306fa1
-			entry.type = amd_strdup("bind");
306fa1
-		} else if (!strcmp($3, "xfs")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_XFS;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "ext2") ||
306fa1
-			   !strcmp($3, "ext3") ||
306fa1
-			   !strcmp($3, "ext4")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_EXT;
306fa1
-			entry.type = amd_strdup($3);
306fa1
-		} else if (!strcmp($3, "ufs")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_UFS;
306fa1
-			entry.type = conf_amd_get_linux_ufs_mount_type();
306fa1
-		} else if (!strcmp($3, "cdfs")) {
306fa1
-			entry.flags |= AMD_MOUNT_TYPE_CDFS;
306fa1
-			entry.type = amd_strdup("iso9660");
306fa1
-		} else if (!strcmp($3, "jfs") ||
306fa1
-			   !strcmp($3, "nfsx") ||
306fa1
-			   !strcmp($3, "program") ||
306fa1
-			   !strcmp($3, "lustre") ||
306fa1
-			   !strcmp($3, "direct")) {
306fa1
-			sprintf(msg_buf, "file system type %s is "
306fa1
-					 "not yet implemented", $3);
306fa1
-			amd_msg(msg_buf);
306fa1
-			YYABORT;
306fa1
-		} else if (!strcmp($3, "cachefs")) {
306fa1
-			sprintf(msg_buf, "file system %s is not "
306fa1
-					 "supported by autofs, ignored", $3);
306fa1
-			amd_msg(msg_buf);
306fa1
-		} else {
306fa1
-			amd_notify($1);
306fa1
+		if (!match_map_option_fs_type($1, $3))
306fa1
 			YYABORT;
306fa1
-		}
306fa1
 	}
306fa1
 	| MAP_OPTION OPTION_ASSIGN MAP_TYPE
306fa1
 	{
306fa1
-		if (!strcmp($3, "file") ||
306fa1
-		    !strcmp($3, "nis") ||
306fa1
-		    !strcmp($3, "nisplus") ||
306fa1
-		    !strcmp($3, "ldap") ||
306fa1
-		    !strcmp($3, "hesiod"))
306fa1
-			entry.map_type = amd_strdup($3);
306fa1
-		else if (!strcmp($3, "exec"))
306fa1
-			/* autofs uses "program" for "exec" map type */
306fa1
-			entry.map_type = amd_strdup("program");
306fa1
-		else if (!strcmp($3, "passwd")) {
306fa1
-			sprintf(msg_buf, "map type %s is "
306fa1
-					 "not yet implemented", $3);
306fa1
-			amd_msg(msg_buf);
306fa1
-			YYABORT;
306fa1
-		} else if (!strcmp($3, "ndbm") ||
306fa1
-			   !strcmp($3, "union")) {
306fa1
-			sprintf(msg_buf, "map type %s is not "
306fa1
-					 "supported by autofs", $3);
306fa1
-			amd_msg(msg_buf);
306fa1
+		if (!match_map_option_map_type($1, $3))
306fa1
 			YYABORT;
306fa1
-		} else {
306fa1
-			amd_notify($1);
306fa1
-			YYABORT;
306fa1
-		}
306fa1
 	}
306fa1
 	| MAP_OPTION OPTION_ASSIGN FS_OPT_VALUE
306fa1
 	{
306fa1
@@ -397,13 +329,7 @@ option_assignment: MAP_OPTION OPTION_ASS
306fa1
 	}
306fa1
 	| MNT_OPTION OPTION_ASSIGN options
306fa1
 	{
306fa1
-		if (!strcmp($1, "opts"))
306fa1
-			entry.opts = amd_strdup(opts);
306fa1
-		else if (!strcmp($1, "addopts"))
306fa1
-			entry.addopts = amd_strdup(opts);
306fa1
-		else if (!strcmp($1, "remopts"))
306fa1
-			entry.remopts = amd_strdup(opts);
306fa1
-		else {
306fa1
+		if (!match_mnt_option_options($1, $3)) {
306fa1
 			amd_notify($1);
306fa1
 			YYABORT;
306fa1
 		}
306fa1
@@ -412,27 +338,20 @@ option_assignment: MAP_OPTION OPTION_ASS
306fa1
 	| MNT_OPTION OPTION_ASSIGN
306fa1
 	{
306fa1
 		memset(opts, 0, sizeof(opts));
306fa1
-		if (!strcmp($1, "opts"))
306fa1
-			entry.opts = amd_strdup("");
306fa1
-		else if (!strcmp($1, "addopts"))
306fa1
-			entry.addopts = amd_strdup("");
306fa1
-		else if (!strcmp($1, "remopts"))
306fa1
-			entry.remopts = amd_strdup("");
306fa1
-		else {
306fa1
+		if (!match_mnt_option_options($1, "")) {
306fa1
 			amd_notify($1);
306fa1
 			YYABORT;
306fa1
 		}
306fa1
 	}
306fa1
 	| MAP_OPTION OPTION_ASSIGN CACHE_OPTION
306fa1
 	{
306fa1
-		if (strncmp($3, "inc", 3))
306fa1
-			entry.cache_opts = AMD_CACHE_OPTION_INC;
306fa1
-		else if (strncmp($3, "all", 3))
306fa1
-			entry.cache_opts = AMD_CACHE_OPTION_ALL;
306fa1
-		else if (strncmp($3, "re", 2))
306fa1
-			entry.cache_opts = AMD_CACHE_OPTION_REGEXP;
306fa1
-		if (strstr($3, "sync"))
306fa1
-			entry.cache_opts |= AMD_CACHE_OPTION_SYNC;
306fa1
+		if (!strcmp($1, "cache")) {
306fa1
+			if (!match_map_option_cache_option($3))
306fa1
+				YYABORT;
306fa1
+		} else {
306fa1
+			amd_notify($1);
306fa1
+			YYABORT;
306fa1
+		}
306fa1
 	}
306fa1
 	;
306fa1
 
306fa1
@@ -478,6 +397,186 @@ options: OPTION
306fa1
 
306fa1
 %%
306fa1
 
306fa1
+static int match_map_option_fs_type(char *map_option, char *type)
306fa1
+{
306fa1
+	char *fs_type;
306fa1
+
306fa1
+	fs_type = amd_strdup(type);
306fa1
+	if (!fs_type) {
306fa1
+		amd_notify(type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+
306fa1
+	if (!strcmp(fs_type, "auto")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_AUTO;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "nfs") ||
306fa1
+		   !strcmp(fs_type, "nfs4")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_NFS;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "nfsl")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_NFSL;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "link")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_LINK;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "linkx")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_LINKX;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "host")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_HOST;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "lofs")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_LOFS;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "xfs")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_XFS;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "ext2") ||
306fa1
+		   !strcmp(fs_type, "ext3") ||
306fa1
+		   !strcmp(fs_type, "ext4")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_EXT;
306fa1
+		entry.type = fs_type;
306fa1
+	} else if (!strcmp(fs_type, "ufs")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_UFS;
306fa1
+		entry.type = conf_amd_get_linux_ufs_mount_type();
306fa1
+		if (!entry.type) {
306fa1
+			amd_msg("memory allocation error");
306fa1
+			amd_notify(type);
306fa1
+			free(fs_type);
306fa1
+			return 0;
306fa1
+		}
306fa1
+		free(fs_type);
306fa1
+	} else if (!strcmp(fs_type, "cdfs")) {
306fa1
+		entry.flags |= AMD_MOUNT_TYPE_CDFS;
306fa1
+		entry.type = amd_strdup("iso9660");
306fa1
+		if (!entry.type) {
306fa1
+			amd_msg("memory allocation error");
306fa1
+			amd_notify(map_option);
306fa1
+			free(fs_type);
306fa1
+			return 0;
306fa1
+		}
306fa1
+		free(fs_type);
306fa1
+	} else if (!strcmp(fs_type, "jfs") ||
306fa1
+		   !strcmp(fs_type, "nfsx") ||
306fa1
+		   !strcmp(fs_type, "program") ||
306fa1
+		   !strcmp(fs_type, "lustre") ||
306fa1
+		   !strcmp(fs_type, "direct")) {
306fa1
+		sprintf(msg_buf, "file system type %s is "
306fa1
+				 "not yet implemented", fs_type);
306fa1
+		amd_msg(msg_buf);
306fa1
+		free(fs_type);
306fa1
+		return 0;
306fa1
+	} else if (!strcmp(fs_type, "cachefs")) {
306fa1
+		sprintf(msg_buf, "file system %s is not "
306fa1
+				 "supported by autofs, ignored",
306fa1
+				 fs_type);
306fa1
+		amd_msg(msg_buf);
306fa1
+		free(fs_type);
306fa1
+	} else {
306fa1
+		amd_notify(fs_type);
306fa1
+		free(fs_type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
+static int match_map_option_map_type(char *map_option, char *type)
306fa1
+{
306fa1
+	char *map_type;
306fa1
+
306fa1
+	map_type = amd_strdup(type);
306fa1
+	if (!map_type) {
306fa1
+		amd_notify(type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+
306fa1
+	if (!strcmp(map_type, "file") ||
306fa1
+	    !strcmp(map_type, "nis") ||
306fa1
+	    !strcmp(map_type, "nisplus") ||
306fa1
+	    !strcmp(map_type, "ldap") ||
306fa1
+	    !strcmp(map_type, "hesiod")) {
306fa1
+		entry.map_type = map_type;
306fa1
+	} else if (!strcmp(map_type, "exec")) {
306fa1
+		/* autofs uses "program" for "exec" map type */
306fa1
+		entry.map_type = amd_strdup("program");
306fa1
+		if (!entry.map_type) {
306fa1
+			amd_notify(type);
306fa1
+			free(map_type);
306fa1
+			return 0;
306fa1
+		}
306fa1
+		free(map_type);
306fa1
+	} else if (!strcmp(map_type, "passwd")) {
306fa1
+		sprintf(msg_buf, "map type %s is "
306fa1
+				 "not yet implemented", map_type);
306fa1
+		amd_msg(msg_buf);
306fa1
+		free(map_type);
306fa1
+		return 0;
306fa1
+	} else if (!strcmp(map_type, "ndbm") ||
306fa1
+		   !strcmp(map_type, "union")) {
306fa1
+		sprintf(msg_buf, "map type %s is not "
306fa1
+				 "supported by autofs", map_type);
306fa1
+		amd_msg(msg_buf);
306fa1
+		free(map_type);
306fa1
+		return 0;
306fa1
+	} else {
306fa1
+		amd_notify(type);
306fa1
+		free(map_type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
+static int match_map_option_cache_option(char *type)
306fa1
+{
306fa1
+	char *cache_opt;
306fa1
+
306fa1
+	cache_opt = amd_strdup(type);
306fa1
+	if (!cache_opt) {
306fa1
+		amd_notify(type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+
306fa1
+	if (strncmp(cache_opt, "inc", 3))
306fa1
+		entry.cache_opts = AMD_CACHE_OPTION_INC;
306fa1
+	else if (strncmp(cache_opt, "all", 3))
306fa1
+		entry.cache_opts = AMD_CACHE_OPTION_ALL;
306fa1
+	else if (strncmp(cache_opt, "re", 2))
306fa1
+		entry.cache_opts = AMD_CACHE_OPTION_REGEXP;
306fa1
+	if (strstr(cache_opt, "sync"))
306fa1
+		entry.cache_opts |= AMD_CACHE_OPTION_SYNC;
306fa1
+	free(cache_opt);
306fa1
+
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
+static int match_mnt_option_options(char *mnt_option, char *options)
306fa1
+{
306fa1
+	char *tmp;
306fa1
+
306fa1
+	if (!strcmp(mnt_option, "opts")) {
306fa1
+		tmp = amd_strdup(options);
306fa1
+		if (!tmp)
306fa1
+			return 0;
306fa1
+		entry.opts = tmp;
306fa1
+	} else if (!strcmp(mnt_option, "addopts")) {
306fa1
+		tmp = amd_strdup(options);
306fa1
+		if (!tmp)
306fa1
+			return 0;
306fa1
+		entry.addopts = tmp;
306fa1
+	} else if (!strcmp(mnt_option, "remopts")) {
306fa1
+		tmp = amd_strdup(options);
306fa1
+		if (!tmp)
306fa1
+			return 0;
306fa1
+		entry.remopts = tmp;
306fa1
+	} else
306fa1
+		return 0;
306fa1
+
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
 static void prepend_opt(char *dest, char *opt)
306fa1
 {
306fa1
 	char new[MAX_OPTS_LEN];