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