linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Dickson <steved@redhat.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
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	[thread overview]
Message-ID: <20201105145634.98281-3-steved@redhat.com> (raw)
In-Reply-To: <20201105145634.98281-1-steved@redhat.com>

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 <steved@redhat.com>
---
 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))
-- 
2.26.2


  parent reply	other threads:[~2020-11-05 14:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 14:56 [PATCH 0/3 V2] Enable config.d directory to be processed Steve Dickson
2020-11-05 14:56 ` [PATCH 1/3] conffile: process config.d directory config files Steve Dickson
2020-11-05 14:56 ` Steve Dickson [this message]
2020-11-05 14:56 ` [PATCH 3/3] manpage: Update nfs.conf and nfsmount.conf manpages Steve Dickson
2020-11-10 19:41 ` [PATCH 0/3 V2] Enable config.d directory to be processed Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201105145634.98281-3-steved@redhat.com \
    --to=steved@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).