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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux