Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp140364pxb; Wed, 14 Apr 2021 11:20:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf4iy4ibuV2eIVhEkMcKAmF39ZfyU4XrUEFAJJ9n379eC3iIq1fkJIMYyE/qlNHaB4b4IK X-Received: by 2002:a17:902:c948:b029:e9:8f01:fa8e with SMTP id i8-20020a170902c948b02900e98f01fa8emr34678101pla.37.1618424410791; Wed, 14 Apr 2021 11:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618424410; cv=none; d=google.com; s=arc-20160816; b=cEkiGI/CsoAXd1ScPEFg32oiW8qC/8zxRT54YvHCNNmHeGv6KP+1g50UzwEqR834Fd wd1r9U2eyW4Jo7EZT49FBNwpkzmko4kCtPlb/RPSWICHckCB2k5ajwjaETHYSZ+cX6mv YHJzFg0MyP6qSN+zVApwyobIfG7+N6tpzlE0Nf+0u434FYLk9lFt5GfM+KOkgTetgXbE Dw6o9BbEOOuoW1gVTuAnM9wMYJMI74Em2dssP8+KwZGQa+CtALtVIZBz9q1Dez36B5oi aY/crV2PvezSjRvYWn6xLh9Rm9ilDUNfsoJ7+HdmVUFaZIfeXtx78IFGqBy+EDRKMfbZ nbVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=NgvXjxwHZxyvRYhr8rfe9hAeXuiLeqwKflwN/sJy8eQ=; b=kYxaSsBCs/ZJTP+QTxdu2k9KADseEcfI8Glp/5NqonwzcLJj5P1NJrbuOr6RSOOfwj re/UNwCZKQHdwG0Pl+2ZGvsHokAIl97s3ywBZT/d3HPdWjSFe93V1pmHE43D1udRAP8Z /+Ac/Mky4qvDNGxcx7SqM1YA9+7+daS4Vch/+HLVGWcJ5vgR/Ib+rJquN4poFO4xKEiw tyZ+uQPFd6OP9YkXkeLYYUeCUpB3IEK3pkPaLFXCgldpdAMAsd1axor8JXUPCqdRvopb CPGG8DLhoV1Gup4wYWsKIbdcz5pMf4xLLBRYkr/0ur6I7kaxTx2lbzPAJhzsErPJqiE2 zFsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SB21a9Bg; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si353232plv.281.2021.04.14.11.19.56; Wed, 14 Apr 2021 11:20:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SB21a9Bg; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbhDNSKq (ORCPT + 99 others); Wed, 14 Apr 2021 14:10:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38717 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234410AbhDNSI6 (ORCPT ); Wed, 14 Apr 2021 14:08:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618423715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NgvXjxwHZxyvRYhr8rfe9hAeXuiLeqwKflwN/sJy8eQ=; b=SB21a9BgSLLhec2JZqHiD8YrVVYWg0+9rhq8JExVt8gbL6AWyzO93Q1B/vjZ/7j9K/9+2g EWdRgK070VCajiAbe0VawNYuHIUWy8eKxE/pb5tm/y/zlyFZWT9qf/91kPfbFp7zdb9ux+ EZG3PXqnaViCtTFKwiJuGr22KQ6i9Nw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-201-vZX0n6D3NFC5M-EyDHVRVg-1; Wed, 14 Apr 2021 14:08:33 -0400 X-MC-Unique: vZX0n6D3NFC5M-EyDHVRVg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0669F107ACCD for ; Wed, 14 Apr 2021 18:08:33 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-83.phx2.redhat.com [10.3.112.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id B67DD60862 for ; Wed, 14 Apr 2021 18:08:32 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 1/3] nfs-utils: Enable the retrieval of raw config settings without expansion Date: Wed, 14 Apr 2021 14:10:38 -0400 Message-Id: <20210414181040.7108-2-steved@redhat.com> In-Reply-To: <20210414181040.7108-1-steved@redhat.com> References: <20210414181040.7108-1-steved@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Alice Mitchell Config entries sometimes contain variable expansions, this adds options to retrieve the config entry rather than its current expanded value. Signed-off-by: Alice Mitchell Signed-off-by: Steve Dickson --- support/include/conffile.h | 1 + support/nfs/conffile.c | 23 +++++++++++++++++++++++ tools/nfsconf/nfsconf.man | 10 +++++++++- tools/nfsconf/nfsconfcli.c | 22 ++++++++++++++++------ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/support/include/conffile.h b/support/include/conffile.h index 7d974fe9..c4a3ca62 100644 --- a/support/include/conffile.h +++ b/support/include/conffile.h @@ -61,6 +61,7 @@ extern _Bool conf_get_bool(const char *, const char *, _Bool); extern char *conf_get_str(const char *, const char *); extern char *conf_get_str_with_def(const char *, const char *, char *); extern char *conf_get_section(const char *, const char *, const char *); +extern char *conf_get_entry(const char *, const char *, const char *); extern int conf_init_file(const char *); extern void conf_cleanup(void); extern int conf_match_num(const char *, const char *, int); diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 1e15e7d5..fd4a17ad 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -891,6 +891,29 @@ conf_get_str_with_def(const char *section, const char *tag, char *def) return result; } +/* + * Retrieve an entry without interpreting its contents + */ +char * +conf_get_entry(const char *section, const char *arg, const char *tag) +{ + struct conf_binding *cb; + + cb = LIST_FIRST (&conf_bindings[conf_hash (section)]); + for (; cb; cb = LIST_NEXT (cb, link)) { + if (strcasecmp(section, cb->section) != 0) + continue; + if (arg && (cb->arg == NULL || strcasecmp(arg, cb->arg) != 0)) + continue; + if (!arg && cb->arg) + continue; + if (strcasecmp(tag, cb->tag) != 0) + continue; + return cb->value; + } + return 0; +} + /* * Find a section that may or may not have an argument */ diff --git a/tools/nfsconf/nfsconf.man b/tools/nfsconf/nfsconf.man index 30791988..d44e86fb 100644 --- a/tools/nfsconf/nfsconf.man +++ b/tools/nfsconf/nfsconf.man @@ -11,6 +11,12 @@ nfsconf \- Query various NFS configuration settings .IR infile.conf ] .RI [ outfile ] .P +.B nfsconf \-\-entry +.RB [ \-\-arg +.IR subsection] +.IR section +.IR tag +.P .B nfsconf \-\-get .RB [ \-v | \-\-verbose ] .RB [ \-f | \-\-file @@ -58,6 +64,8 @@ from a range of nfs-utils configuration files. The following modes are available: .IP "\fB\-d, \-\-dump\fP" Output an alphabetically sorted dump of the current configuration in conf file format. Accepts an optional filename in which to write the output. +.IP "\fB\-e, \-\-entry\fP" +retrieve the config entry rather than its current expanded value .IP "\fB\-i, \-\-isset\fP" Test if a specific tag has a value set. .IP "\fB\-g, \-\-get\fP" @@ -75,7 +83,7 @@ Increase verbosity and print debugging information. .B \-f, \-\-file \fIinfile\fR Select a different config file to operate upon, default is .I /etc/nfs.conf -.SS Options only valid in \fB\-\-get\fR and \fB\-\-isset\fR modes. +.SS Options only valid in \fB\-\-entry\fR and \fB\-\-get\fR and \fB\-\-isset\fR modes. .TP .B \-a, \-\-arg \fIsubsection\fR Select a specific sub-section diff --git a/tools/nfsconf/nfsconfcli.c b/tools/nfsconf/nfsconfcli.c index 361d386e..b2ef96d1 100644 --- a/tools/nfsconf/nfsconfcli.c +++ b/tools/nfsconf/nfsconfcli.c @@ -11,6 +11,7 @@ typedef enum { MODE_NONE, MODE_GET, + MODE_ENTRY, MODE_ISSET, MODE_DUMP, MODE_SET, @@ -30,6 +31,8 @@ static void usage(const char *name) fprintf(stderr, " Outputs the configuration to the named file\n"); fprintf(stderr, " --get [--arg subsection] {section} {tag}\n"); fprintf(stderr, " Output one specific config value\n"); + fprintf(stderr, " --entry [--arg subsection] {section} {tag}\n"); + fprintf(stderr, " Output the uninterpreted config entry\n"); fprintf(stderr, " --isset [--arg subsection] {section} {tag}\n"); fprintf(stderr, " Return code indicates if config value is present\n"); fprintf(stderr, " --set [--arg subsection] {section} {tag} {value}\n"); @@ -55,6 +58,7 @@ int main(int argc, char **argv) int index = 0; struct option long_options[] = { {"get", no_argument, 0, 'g' }, + {"entry", no_argument, 0, 'e' }, {"set", no_argument, 0, 's' }, {"unset", no_argument, 0, 'u' }, {"arg", required_argument, 0, 'a' }, @@ -66,7 +70,7 @@ int main(int argc, char **argv) {NULL, 0, 0, 0 } }; - c = getopt_long(argc, argv, "gsua:id::f:vm:", long_options, &index); + c = getopt_long(argc, argv, "gesua:id::f:vm:", long_options, &index); if (c == -1) break; switch (c) { @@ -86,6 +90,9 @@ int main(int argc, char **argv) case 'g': mode = MODE_GET; break; + case 'e': + mode = MODE_ENTRY; + break; case 's': mode = MODE_SET; break; @@ -167,8 +174,8 @@ int main(int argc, char **argv) if (dumpfile) fclose(out); } else - /* --iset and --get share a lot of code */ - if (mode == MODE_GET || mode == MODE_ISSET) { + /* --isset and --get share a lot of code */ + if (mode == MODE_GET || mode == MODE_ISSET || mode == MODE_ENTRY) { char * section = NULL; char * tag = NULL; const char * val; @@ -186,14 +193,17 @@ int main(int argc, char **argv) tag = argv[optind++]; /* retrieve the specified tags value */ - val = conf_get_section(section, arg, tag); + if (mode == MODE_ENTRY) + val = conf_get_entry(section, arg, tag); + else + val = conf_get_section(section, arg, tag); if (val != NULL) { /* ret=0, success, mode --get wants to output the value as well */ - if (mode == MODE_GET) + if (mode != MODE_ISSET) printf("%s\n", val); } else { /* ret=1, no value found, tell the user if they asked */ - if (mode == MODE_GET && verbose) + if (mode != MODE_ISSET && verbose) fprintf(stderr, "Tag '%s' not found\n", tag); ret = 1; } -- 2.30.2