summaryrefslogtreecommitdiffstats
path: root/support/nfs
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2016-12-06 13:20:15 -0500
committerSteve Dickson <steved@redhat.com>2016-12-20 13:29:04 -0500
commit563a7de05a61f5e57e636d4063592e6f0fde9afb (patch)
treedf56a3629b9a6f847911722681d20c79a0c92fce /support/nfs
parente54b49cb13f9ecc6a9133957cda4c6d786967841 (diff)
downloadnfs-utils-563a7de05a61f5e57e636d4063592e6f0fde9afb.tar.gz
nfs-utils-563a7de05a61f5e57e636d4063592e6f0fde9afb.tar.xz
nfs-utils-563a7de05a61f5e57e636d4063592e6f0fde9afb.zip
conffile: allow $name expansion of tag values.
If the value for a tag starts with '$', then the remainder of the value is treated as an environment variable name. It is looked up in the environment (getenv) and if not found, it is looked for in the [environment] section of the config file. This lookup is formed as access time e.g. by conf_get_str(), not at parse time. The expected usage is that the config file can contain something like [environment] include = /etc/sysconfig/nfs [other-section] tag = $NAME and conf_get_str("other-section","tag") will report the value of "NAME" in the given file. As different distributions used different environment files, and different variable names with-in them, a distro could provide a static config file which maps from names in that environment file to config tags requires by NFS daemons. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/nfs')
-rw-r--r--support/nfs/conffile.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index eaff5f5..e4f685c 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -519,12 +519,24 @@ char *
conf_get_str(char *section, char *tag)
{
struct conf_binding *cb;
-
+retry:
cb = LIST_FIRST (&conf_bindings[conf_hash (section)]);
for (; cb; cb = LIST_NEXT (cb, link)) {
if (strcasecmp (section, cb->section) == 0
- && strcasecmp (tag, cb->tag) == 0)
+ && strcasecmp (tag, cb->tag) == 0) {
+ if (cb->value[0] == '$') {
+ /* expand $name from [environment] section,
+ * or from environment
+ */
+ char *env = getenv(cb->value+1);
+ if (env)
+ return env;
+ section = "environment";
+ tag = cb->value + 1;
+ goto retry;
+ }
return cb->value;
+ }
}
return 0;
}