From patchwork Thu Nov 5 14:56:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 11884609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1746A1744 for ; Thu, 5 Nov 2020 14:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1E6F20704 for ; Thu, 5 Nov 2020 14:56:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KixPpgX2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731085AbgKEO4r (ORCPT ); Thu, 5 Nov 2020 09:56:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22206 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731013AbgKEO4r (ORCPT ); Thu, 5 Nov 2020 09:56:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604588205; 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=Nzgr1SuqOUrNhxxrIe6PsSa7YMqdI7HNiCRVmyjOT6w=; b=KixPpgX2CbL3fftVRG3P8W5VlDXlmkIOlAClRXy1JU4dvS7SAJMdtqCoC4ySsD1zoGkhna BVPV+wjHATqOpRCn2w8cAougunNfxTrOMR+UWrA08xrflPH40NE9ZM57KGJgi/Ysd3OIhx hjATaqgq98wffYzH95MMZVf9hWLetHs= 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-343-LbPWR-dRO7SkrJWhwPSB9A-1; Thu, 05 Nov 2020 09:56:44 -0500 X-MC-Unique: LbPWR-dRO7SkrJWhwPSB9A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67808800461 for ; Thu, 5 Nov 2020 14:56:43 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-68.phx2.redhat.com [10.3.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 270335D9D5 for ; Thu, 5 Nov 2020 14:56:43 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 1/3] conffile: process config.d directory config files. Date: Thu, 5 Nov 2020 09:56:32 -0500 Message-Id: <20201105145634.98281-2-steved@redhat.com> In-Reply-To: <20201105145634.98281-1-steved@redhat.com> References: <20201105145634.98281-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org When a /etc/nfs.conf.d or /etc/nfsmount.conf.d directory exists and config file(s) do exist in those directories, those file(s) will be used and will override the same settings that are set in the main config files. Signed-off-by: Steve Dickson --- support/nfs/conffile.c | 119 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 3 deletions(-) diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 3d13610..456bcf6 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -52,6 +52,7 @@ #include #include #include +#include #include "conffile.h" #include "xlog.h" @@ -456,7 +457,7 @@ conf_parse_line(int trans, char *line, const char *filename, int lineno, char ** free(subconf); } else { /* XXX Perhaps should we not ignore errors? */ - conf_set(trans, *section, *subsection, line, val, 0, 0); + conf_set(trans, *section, *subsection, line, val, 1, 0); } } @@ -577,6 +578,30 @@ static void conf_free_bindings(void) } } +static int +conf_load_files(int trans, const char *conf_file) +{ + char *conf_data; + char *section = NULL; + char *subsection = NULL; + + conf_data = conf_readfile(conf_file); + if (conf_data == NULL) + return 1; + + /* Load default configuration values. */ + conf_load_defaults(); + + /* Parse config contents into the transaction queue */ + conf_parse(trans, conf_data, §ion, &subsection, conf_file); + if (section) + free(section); + if (subsection) + free(subsection); + free(conf_data); + + return 0; +} /* Open the config file and map it into our address space, then parse it. */ static int conf_load_file(const char *conf_file) @@ -609,18 +634,106 @@ conf_load_file(const char *conf_file) return 0; } +static void +conf_init_dir(const char *conf_file) +{ + struct dirent **namelist = NULL; + char *dname, fname[PATH_MAX + 1]; + int n = 0, i, nfiles = 0, fname_len, dname_len; + int trans; + + dname = malloc(strlen(conf_file) + 3); + if (dname == NULL) { + xlog(L_WARNING, "conf_init_dir: malloc: %s", strerror(errno)); + return; + } + sprintf(dname, "%s.d", conf_file); + + n = scandir(dname, &namelist, NULL, versionsort); + if (n < 0) { + if (errno != ENOENT) { + xlog(L_WARNING, "conf_init_dir: scandir %s: %s", + dname, strerror(errno)); + } + free(dname); + return; + } else if (n == 0) { + free(dname); + return; + } + + trans = conf_begin(); + dname_len = strlen(dname); + for (i = 0; i < n; i++ ) { + struct dirent *d = namelist[i]; + + switch (d->d_type) { + case DT_UNKNOWN: + case DT_REG: + case DT_LNK: + break; + default: + continue; + } + if (*d->d_name == '.') + continue; + + fname_len = strlen(d->d_name); + if (!fname_len || (fname_len + dname_len) > PATH_MAX) { + xlog(L_WARNING, "conf_init_dir: Too long file name: %s in %s", + d->d_name, dname); + continue; + } + sprintf(fname, "%s/%s", dname, d->d_name); + + if (conf_load_files(trans, fname)) + continue; + nfiles++; + } + + if (nfiles) { + /* Apply the configuration values */ + conf_end(trans, 1); + } + for (i = 0; i < n; i++) + free(namelist[i]); + free(namelist); + free(dname); + + return; +} + int conf_init_file(const char *conf_file) { unsigned int i; + int ret; for (i = 0; i < sizeof conf_bindings / sizeof conf_bindings[0]; i++) LIST_INIT (&conf_bindings[i]); TAILQ_INIT (&conf_trans_queue); - if (conf_file == NULL) conf_file=NFS_CONFFILE; - return conf_load_file(conf_file); + if (conf_file == NULL) + conf_file=NFS_CONFFILE; + + /* + * First parse the give config file + * then parse the config.conf.d directory + * (if it exists) + * + */ + ret = conf_load_file(conf_file); + + /* + * When the same variable is set in both files + * the conf.d file will override the config file. + * This allows automated admin systems to + * have the final say. + */ + conf_init_dir(conf_file); + + return ret; } /* From patchwork Thu Nov 5 14:56:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 11884613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D18466A2 for ; Thu, 5 Nov 2020 14:56:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A532B21D81 for ; Thu, 5 Nov 2020 14:56:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hUR/6U3R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730721AbgKEO4t (ORCPT ); Thu, 5 Nov 2020 09:56:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21423 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731013AbgKEO4s (ORCPT ); Thu, 5 Nov 2020 09:56:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604588207; 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=xZnLgXcbNSoZx6u4cjZpXSL4ZqBPt3mZdI9BXPKpBMI=; b=hUR/6U3RNlpk6209IGZFveGS2nKB+2X+kalQxepFnPggdiiGVEsmTqHzyoDHT3JxIr8cMM EN7gYiOumIFZnV7chKpX2fjoEso4QOIl16RRupGxv3vECxne3V5QhEnwGS5cA6r4/PwuhL pWAwEv6Z6SxektxeJrjGsb9cRNMckEo= 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-375-09RmCd9lNNW1b1XchgnNSg-1; Thu, 05 Nov 2020 09:56:44 -0500 X-MC-Unique: 09RmCd9lNNW1b1XchgnNSg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA685803626 for ; Thu, 5 Nov 2020 14:56:43 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-68.phx2.redhat.com [10.3.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A0D75D9D5 for ; Thu, 5 Nov 2020 14:56:43 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 2/3] conffile: Only process files in the config.d dirs that end with ".conf" Date: Thu, 5 Nov 2020 09:56:33 -0500 Message-Id: <20201105145634.98281-3-steved@redhat.com> In-Reply-To: <20201105145634.98281-1-steved@redhat.com> References: <20201105145634.98281-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This allows admins or admin systems to change configurations by renaming the files, only process file that end with ".conf" Signed-off-by: Steve Dickson --- support/nfs/conffile.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 456bcf6..1574531 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -57,6 +57,9 @@ #include "conffile.h" #include "xlog.h" +#define CONF_FILE_EXT ".conf" +#define CONF_FILE_EXT_LEN ((int) (sizeof(CONF_FILE_EXT) - 1)) + #pragma GCC visibility push(hidden) static void conf_load_defaults(void); @@ -638,8 +641,8 @@ static void conf_init_dir(const char *conf_file) { struct dirent **namelist = NULL; - char *dname, fname[PATH_MAX + 1]; - int n = 0, i, nfiles = 0, fname_len, dname_len; + char *dname, fname[PATH_MAX + 1], *cname; + int n = 0, nfiles = 0, i, fname_len, dname_len; int trans; dname = malloc(strlen(conf_file) + 3); @@ -684,6 +687,23 @@ conf_init_dir(const char *conf_file) d->d_name, dname); continue; } + + /* + * Check the naming of the file. Only process files + * that end with CONF_FILE_EXT + */ + if (fname_len <= CONF_FILE_EXT_LEN) { + xlog(D_GENERAL, "conf_init_dir: %s: name too short", + d->d_name); + continue; + } + cname = (d->d_name + (fname_len - CONF_FILE_EXT_LEN)); + if (strcmp(cname, CONF_FILE_EXT) != 0) { + xlog(D_GENERAL, "conf_init_dir: %s: invalid file extension", + d->d_name); + continue; + } + sprintf(fname, "%s/%s", dname, d->d_name); if (conf_load_files(trans, fname)) From patchwork Thu Nov 5 14:56:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 11884611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B7B514C0 for ; Thu, 5 Nov 2020 14:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7188720704 for ; Thu, 5 Nov 2020 14:56:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e/sRdDYO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731121AbgKEO4r (ORCPT ); Thu, 5 Nov 2020 09:56:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37705 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730721AbgKEO4r (ORCPT ); Thu, 5 Nov 2020 09:56:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604588206; 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=Xr7KbYlMV4SPjngLdBH4fJIXTlCFH83h5CqogNUd7HQ=; b=e/sRdDYOWeiCbeCmzilJIMoP3eONTnx9q834tBRIsBB/V03GWymWB75vOVt3hsd0rnjVqM Dq0xanJLG+teg6YOIYib/AN3c/Kw3pgOyMeH8WOROYZ1lOKxkWNudORm+6h4nVq2EaRPVj 9DDGrR3ct9yKR4ibypo50CklzJUyuHo= 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-374-eJS_-2iPNsGWS7l8Q6G_yA-1; Thu, 05 Nov 2020 09:56:45 -0500 X-MC-Unique: eJS_-2iPNsGWS7l8Q6G_yA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 383038DF0A3 for ; Thu, 5 Nov 2020 14:56:44 +0000 (UTC) Received: from madhat.boston.devel.redhat.com (ovpn-112-68.phx2.redhat.com [10.3.112.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED3D15D9D5 for ; Thu, 5 Nov 2020 14:56:43 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 3/3] manpage: Update nfs.conf and nfsmount.conf manpages Date: Thu, 5 Nov 2020 09:56:34 -0500 Message-Id: <20201105145634.98281-4-steved@redhat.com> In-Reply-To: <20201105145634.98281-1-steved@redhat.com> References: <20201105145634.98281-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Update the man pages to explain how the config.d directories will be use. Signed-off-by: Steve Dickson --- systemd/nfs.conf.man | 8 ++++++++ utils/mount/nfsmount.conf.man | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index 3f1c726..16e0ec4 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -265,7 +265,15 @@ Only is recognized. .SH FILES +.TP 10n .I /etc/nfs.conf +Default NFS client configuration file +.TP 10n +.I /etc/nfs.conf.d +When this directory exists and files ending +with ".conf" exist, those files will be +used to set configuration variables. These +files will override variables set in /etc/nfs.conf .SH SEE ALSO .BR nfsdcltrack (8), .BR rpc.nfsd (8), diff --git a/utils/mount/nfsmount.conf.man b/utils/mount/nfsmount.conf.man index 3aa3456..4f8f351 100644 --- a/utils/mount/nfsmount.conf.man +++ b/utils/mount/nfsmount.conf.man @@ -88,6 +88,13 @@ the background (i.e. done asynchronously). .TP 10n .I /etc/nfsmount.conf Default NFS mount configuration file +.TP 10n +.I /etc/nfsmount.conf.d +When this directory exists and files ending +with ".conf" exist, those files will be +used to set configuration variables. These +files will override variables set +in /etc/nfsmount.conf .PD .SH SEE ALSO .BR nfs (5),