From patchwork Fri Dec 2 03:58:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9457771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CB256074E for ; Fri, 2 Dec 2016 04:00:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8073F28489 for ; Fri, 2 Dec 2016 04:00:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7147428505; Fri, 2 Dec 2016 04:00:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D13A28489 for ; Fri, 2 Dec 2016 04:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753189AbcLBEAB (ORCPT ); Thu, 1 Dec 2016 23:00:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:36558 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480AbcLBEAA (ORCPT ); Thu, 1 Dec 2016 23:00:00 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 297C2AAA3; Fri, 2 Dec 2016 03:59:59 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Steve Dickson Date: Fri, 02 Dec 2016 14:58:30 +1100 Subject: [PATCH 12/15] conffile: allow $name expansion of tag values. Cc: linux-nfs@vger.kernel.org Message-ID: <148065110986.28046.17206049919694436884.stgit@noble> In-Reply-To: <148065078775.28046.5506130555300891075.stgit@noble> References: <148065078775.28046.5506130555300891075.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- support/nfs/conffile.c | 16 ++++++++++++++-- systemd/nfs.conf.man | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index eaff5f5c35ea..e4f685c558fa 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; } diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index 8cf55668b664..03f1f2be534d 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -45,6 +45,14 @@ or .RB \*(lq ; \*(rq is ignored, as is any blank line. .PP +If the assigned value started with a +.RB \*(lq $ \*(rq +then the remainder is treated as a name and looked for in the section +.B [environment] +or in the processes environment (see +.BR environ (7)). +The value found is used for this value. +.PP The value name .B include is special. If a section contains