diff mbox series

[2/3] conffile: Only process files in the config.d dirs that end with ".conf"

Message ID 20201105145634.98281-3-steved@redhat.com (mailing list archive)
State New
Headers show
Series Enable config.d directory to be processed. | expand

Commit Message

Steve Dickson Nov. 5, 2020, 2:56 p.m. UTC
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 mbox series

Patch

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))