- add configuration variable to control appending of global options (bz

214684).
- add command option to set a global mount options string (bz 214684).
This commit is contained in:
ikent 2007-04-16 09:14:14 +00:00
parent 7cd379ec9a
commit 5e21259127
3 changed files with 310 additions and 1 deletions

View File

@ -0,0 +1,143 @@
diff --git a/daemon/automount.c b/daemon/automount.c
index 37e040b..a8327d1 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -47,6 +47,8 @@ const char *libdir = AUTOFS_LIB_DIR; /* Location of library modules */
const char *mapdir = AUTOFS_MAP_DIR; /* Location of mount maps */
const char *confdir = AUTOFS_CONF_DIR; /* Location of autofs config file */
+const char *global_options; /* Global option, from command line */
+
static char *pid_file = NULL; /* File in which to keep pid */
unsigned int random_selection; /* use random policy when selecting
* which multi-mount host to mount */
@@ -1367,6 +1369,8 @@ static void usage(void)
/*" -f --foreground do not fork into background\n" */
" -r --random-replicated-selection"
" use ramdom replicated server selection\n"
+ " -O --global-options"
+ " specify global mount options\n"
" -V --version print version, build config and exit\n"
, program);
}
@@ -1452,7 +1456,7 @@ int main(int argc, char *argv[])
{
int res, opt, status;
unsigned ghost, logging;
- unsigned foreground;
+ unsigned foreground, have_global_options;
time_t timeout;
time_t age = time(NULL);
sigset_t allsigs;
@@ -1466,6 +1470,7 @@ int main(int argc, char *argv[])
{"define", 1, 0, 'D'},
{"foreground", 0, 0, 'f'},
{"random-selection", 0, 0, 'r'},
+ {"global-options", 1, 0, 'O'},
{"version", 0, 0, 'V'},
{0, 0, 0, 0}
};
@@ -1482,10 +1487,12 @@ int main(int argc, char *argv[])
ghost = defaults_get_browse_mode();
logging = defaults_get_logging();
random_selection = 0;
+ global_options = NULL;
+ have_global_options = 0;
foreground = 0;
opterr = 0;
- while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVr", long_options, NULL)) != EOF) {
+ while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:", long_options, NULL)) != EOF) {
switch (opt) {
case 'h':
usage();
@@ -1523,6 +1530,16 @@ int main(int argc, char *argv[])
random_selection = 1;
break;
+ case 'O':
+ if (!have_global_options) {
+ global_options = strdup(optarg);
+ have_global_options = 1;
+ break;
+ }
+ printf("%s: global options already specified.\n",
+ program);
+ break;
+
case '?':
case ':':
printf("%s: Ambiguous or unknown options\n", program);
diff --git a/man/automount.8.in b/man/automount.8.in
index 59f2805..b01be83 100644
--- a/man/automount.8.in
+++ b/man/automount.8.in
@@ -51,6 +51,12 @@ mount entries.
Enables the use of ramdom selection when choosing a host from a
list of replicated servers.
.TP
+.I "\-O, \-\-global-options"
+Allows the specification of global mount options used for all master
+map entries. These options will either replace or be appened to options
+given in a master map entry depending on the APPEND_OPTIONS configuration
+setting.
+.TP
.I "\-V, \-\-version"
Display the version number, then exit.
.SH ARGUMENTS
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
index 276493a..0494e76 100644
--- a/modules/parse_sun.c
+++ b/modules/parse_sun.c
@@ -42,6 +42,8 @@ int parse_version = AUTOFS_PARSE_VERSION; /* Required by protocol */
static struct mount_mod *mount_nfs = NULL;
static int init_ctr = 0;
+extern const char *global_options;
+
struct parse_context {
char *optstr; /* Mount options */
char *macros; /* Map wide macro defines */
@@ -65,6 +67,8 @@ static struct parse_context default_context = {
1 /* Do slashify_colons */
};
+static char *concat_options(char *left, char *right);
+
/* Free all storage associated with this context */
static void kill_context(struct parse_context *ctxt)
{
@@ -264,6 +268,7 @@ int parse_init(int argc, const char *const *argv, void **context)
const char *xopt;
int optlen, len, offset;
int i, bval;
+ unsigned int append_options;
/* Get processor information for predefined escapes */
@@ -392,6 +397,25 @@ int parse_init(int argc, const char *const *argv, void **context)
}
}
+ if (global_options) {
+ append_options = defaults_get_append_options();
+ if (append_options) {
+ char *tmp = concat_options(global_options, ctxt->optstr);
+ if (!tmp) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ error(LOGOPT_ANY, MODPREFIX "concat_options: %s", estr);
+ } else
+ ctxt->optstr = tmp;
+ } else {
+ if (!ctxt->optstr)
+ ctxt->optstr = strdup(global_options);
+ if (!ctxt->optstr) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ warn(LOGOPT_ANY, MODPREFIX "%s", estr);
+ }
+ }
+ }
+
debug(LOGOPT_NONE,
MODPREFIX "init gathered global options: %s", ctxt->optstr);

View File

@ -0,0 +1,158 @@
diff --git a/include/defaults.h b/include/defaults.h
index b64735f..ef58467 100644
--- a/include/defaults.h
+++ b/include/defaults.h
@@ -34,6 +34,7 @@
#define DEFAULT_ENTRY_ATTR "cn"
#define DEFAULT_VALUE_ATTR "nisMapEntry"
+#define DEFAULT_APPEND_OPTIONS 1
#define DEFAULT_AUTH_CONF_FILE AUTOFS_MAP_DIR "/autofs_ldap_auth.conf"
unsigned int defaults_read_config(void);
@@ -47,6 +48,7 @@ const char *defaults_get_entry_obj_class(void);
const char *defaults_get_map_attr(void);
const char *defaults_get_entry_attr(void);
const char *defaults_get_value_attr(void);
+unsigned int defaults_get_append_options(void);
const char *defaults_get_auth_conf_file(void);
#endif
diff --git a/lib/defaults.c b/lib/defaults.c
index f76478e..4b4acba 100644
--- a/lib/defaults.c
+++ b/lib/defaults.c
@@ -37,6 +37,7 @@
#define ENV_NAME_ENTRY_ATTR "ENTRY_ATTRIBUTE"
#define ENV_NAME_VALUE_ATTR "VALUE_ATTRIBUTE"
+#define ENV_APPEND_OPTIONS "APPEND_OPTIONS"
#define ENV_AUTH_CONF_FILE "AUTH_CONF_FILE"
static const char *default_master_map_name = DEFAULT_MASTER_MAP_NAME;
@@ -200,6 +201,7 @@ unsigned int defaults_read_config(void)
check_set_config_value(res, ENV_NAME_MAP_ATTR, value) ||
check_set_config_value(res, ENV_NAME_ENTRY_ATTR, value) ||
check_set_config_value(res, ENV_NAME_VALUE_ATTR, value) ||
+ check_set_config_value(res, ENV_APPEND_OPTIONS, value) ||
check_set_config_value(res, ENV_AUTH_CONF_FILE, value))
;
}
@@ -338,6 +340,17 @@ const char *defaults_get_value_attr(void)
return (const char *) va;
}
+unsigned int defaults_get_append_options(void)
+{
+ int res;
+
+ res = get_env_yesno(ENV_APPEND_OPTIONS);
+ if (res < 0)
+ res = DEFAULT_APPEND_OPTIONS;
+
+ return res;
+}
+
const char *defaults_get_auth_conf_file(void)
{
char *cf;
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
index 9323e7c..276493a 100644
--- a/modules/parse_sun.c
+++ b/modules/parse_sun.c
@@ -140,7 +140,7 @@ int expandsunent(const char *src, char *dst, const char *key,
* re preserved, we need to escape them here.
*/
if (strchr(key, ' ')) {
- char *keyp = key;
+ const char *keyp = key;
while (*keyp) {
if (isspace(*keyp)) {
if (dst) {
@@ -953,6 +953,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
int mapent_len, rv = 0;
int optlen, cur_state;
int slashify = ctxt->slashify_colons;
+ unsigned int append_options;
source = ap->entry->current;
ap->entry->current = NULL;
@@ -998,6 +999,7 @@ int parse_mount(struct autofs_point *ap, const char *name,
debug(ap->logopt, MODPREFIX "expanded entry: %s", pmapent);
+ append_options = defaults_get_append_options();
options = strdup(ctxt->optstr ? ctxt->optstr : "");
if (!options) {
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
@@ -1010,10 +1012,10 @@ int parse_mount(struct autofs_point *ap, const char *name,
/* Deal with 0 or more options */
if (*p == '-') {
- char *mnt_options = NULL;
+ char *tmp, *mnt_options = NULL;
do {
- char *tmp, *noptions = NULL;
+ char *noptions = NULL;
p = parse_options(p, &noptions, ap->logopt);
tmp = concat_options(mnt_options, noptions);
@@ -1033,10 +1035,25 @@ int parse_mount(struct autofs_point *ap, const char *name,
p = skipspace(p);
} while (*p == '-');
- if (options)
+ if (options && !append_options) {
free(options);
+ options = NULL;
+ }
- options = mnt_options;
+ if (append_options) {
+ tmp = concat_options(options, mnt_options);
+ if (!tmp) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ error(ap->logopt, MODPREFIX "concat_options: %s", estr);
+ if (options)
+ free(options);
+ if (mnt_options)
+ free(mnt_options);
+ return 1;
+ }
+ options = tmp;
+ } else
+ options = mnt_options;
}
debug(ap->logopt, MODPREFIX "gathered options: %s", options);
diff --git a/redhat/autofs.sysconfig.in b/redhat/autofs.sysconfig.in
index 84d524b..8299b55 100644
--- a/redhat/autofs.sysconfig.in
+++ b/redhat/autofs.sysconfig.in
@@ -13,6 +13,10 @@ TIMEOUT=300
#
BROWSE_MODE="no"
#
+# APPEND_OPTIONS - append to global options instead of replace.
+#
+#APPEND_OPTIONS="yes"
+#
# LOGGING - set default log level "none", "verbose" or "debug"
#
#LOGGING="none"
diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in
index 84d524b..8299b55 100644
--- a/samples/autofs.conf.default.in
+++ b/samples/autofs.conf.default.in
@@ -13,6 +13,10 @@ TIMEOUT=300
#
BROWSE_MODE="no"
#
+# APPEND_OPTIONS - append to global options instead of replace.
+#
+#APPEND_OPTIONS="yes"
+#
# LOGGING - set default log level "none", "verbose" or "debug"
#
#LOGGING="none"

View File

@ -4,7 +4,7 @@
Summary: A tool for automatically mounting and unmounting filesystems
Name: autofs
Version: 5.0.1
Release: 7
Release: 8
Epoch: 1
License: GPL
Group: System Environment/Daemons
@ -22,6 +22,8 @@ Patch9: autofs-5.0.1-bad-cast.patch
Patch10: autofs-5.0.1-fix-browse-dir-create.patch
Patch11: autofs-5.0.1-map-update-source-only.patch
Patch12: autofs-5.0.1-null-domain-fix.patch
Patch13: autofs-5.0.1-conf-append-global.patch
Patch14: autofs-5.0.1-cmd-global-options.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: autoconf, hesiod-devel, openldap-devel, bison, flex, libxml2-devel, cyrus-sasl-devel, openssl-devel
Conflicts: kernel < 2.6.17
@ -75,6 +77,8 @@ echo %{version}-%{release} > .version
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%build
#CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=/usr --libdir=%{_libdir}
@ -127,6 +131,10 @@ fi
%{_libdir}/autofs/
%changelog
* Mon Apr 16 2007 Ian Kent <ikent@redhat.com> - 5.0.1-8
- add configuration variable to control appending of global options (bz 214684).
- add command option to set a global mount options string (bz 214684).
* Tue Apr 3 2007 Ian Kent <ikent@redhat.com> - 5.0.1-7
- fix "null" domain netgroup match for "-hosts" map.