From 7b5c207075fd2ddf256f5d6186821e395177a883 Mon Sep 17 00:00:00 2001 From: trasz Date: Sun, 31 Aug 2014 21:55:08 +0000 Subject: MFC r270406: Add "nobrowse" option. Previously automountd(8) always behaved as if it was set, now it's conditional. PR: 192862 Sponsored by: The FreeBSD Foundation --- usr.sbin/autofs/auto_master.5 | 6 +++++- usr.sbin/autofs/automountd.c | 33 ++++++++++++++++++++++++++++++--- usr.sbin/autofs/common.c | 41 +++++++++++++++++++++++++++++++++++------ 3 files changed, 70 insertions(+), 10 deletions(-) (limited to 'usr.sbin/autofs') diff --git a/usr.sbin/autofs/auto_master.5 b/usr.sbin/autofs/auto_master.5 index f923f4f..69d6afe 100644 --- a/usr.sbin/autofs/auto_master.5 +++ b/usr.sbin/autofs/auto_master.5 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 31, 2014 +.Dd August 23, 2014 .Dt AUTO_MASTER 5 .Os .Sh NAME @@ -134,6 +134,10 @@ is used to specify filesystem type. It is not passed to the mount program as an option. Instead, it is passed as argument to .Cm "mount -t". +The special option +.Li nobrowse +is used to disable creation of top-level directories for special +and executable maps. .Pp The optional .Pa mountpoint diff --git a/usr.sbin/autofs/automountd.c b/usr.sbin/autofs/automountd.c index 9eaf049..b511103 100644 --- a/usr.sbin/autofs/automountd.c +++ b/usr.sbin/autofs/automountd.c @@ -182,7 +182,7 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options, const char *map; struct node *root, *parent, *node; FILE *f; - char *options, *fstype, *retrycnt, *tmp; + char *options, *fstype, *nobrowse, *retrycnt, *tmp; int error; log_debugx("got request %d: from %s, path %s, prefix \"%s\", " @@ -222,6 +222,28 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options, log_debugx("found node defined at %s:%d; not a mountpoint", node->n_config_file, node->n_config_line); + options = node_options(node); + + /* + * Prepend options passed via automountd(8) command line. + */ + if (cmdline_options != NULL) { + options = + separated_concat(cmdline_options, options, ','); + } + + nobrowse = pick_option("nobrowse", &options); + if (nobrowse != NULL && adr->adr_key[0] == '\0') { + log_debugx("skipping map %s due to \"nobrowse\" " + "option; exiting", map); + done(0); + + /* + * Exit without calling exit_callback(). + */ + quick_exit(0); + } + /* * Not a mountpoint; create directories in the autofs mount * and complete the request. @@ -239,9 +261,9 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options, if (node != NULL) create_subtree(node, false); } - done(0); log_debugx("nothing to mount; exiting"); + done(0); /* * Exit without calling exit_callback(). @@ -274,6 +296,11 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options, options = separated_concat(options, "automounted", ','); /* + * Remove "nobrowse", mount(8) doesn't understand it. + */ + pick_option("nobrowse", &options); + + /* * Figure out fstype. */ fstype = pick_option("fstype=", &options); @@ -309,8 +336,8 @@ handle_request(const struct autofs_daemon_request *adr, char *cmdline_options, if (error != 0) log_errx(1, "mount failed"); - done(0); log_debugx("mount done; exiting"); + done(0); /* * Exit without calling exit_callback(). diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c index 205d152..9695db5 100644 --- a/usr.sbin/autofs/common.c +++ b/usr.sbin/autofs/common.c @@ -856,6 +856,36 @@ again: } } +/* + * Parse output of a special map called without argument. This is just + * a list of keys. + */ +static void +parse_map_keys_yyin(struct node *parent, const char *map) +{ + char *key = NULL; + int ret; + + lineno = 1; + + for (;;) { + ret = yylex(); + + if (ret == NEWLINE) + continue; + + if (ret == 0) { + /* + * End of file. + */ + break; + } + + key = checked_strdup(yytext); + node_new(parent, key, NULL, NULL, map, lineno); + } +} + static bool file_is_executable(const char *path) { @@ -882,11 +912,6 @@ parse_special_map(struct node *parent, const char *map, const char *key) assert(map[0] == '-'); - if (key == NULL) { - log_debugx("skipping map %s due to forced -nobrowse", map); - return; - } - /* * +1 to skip leading "-" in map name. */ @@ -897,7 +922,11 @@ parse_special_map(struct node *parent, const char *map, const char *key) yyin = auto_popen(path, key, NULL); assert(yyin != NULL); - parse_map_yyin(parent, map, key); + if (key == NULL) { + parse_map_keys_yyin(parent, map); + } else { + parse_map_yyin(parent, map, key); + } error = auto_pclose(yyin); yyin = NULL; -- cgit v1.1