From 563a7de05a61f5e57e636d4063592e6f0fde9afb Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 6 Dec 2016 13:20:15 -0500 Subject: 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 Signed-off-by: Steve Dickson --- support/nfs/conffile.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'support/nfs/conffile.c') 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; } -- cgit