aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Dickson <steved@redhat.com>2020-11-03 14:59:02 -0500
committerSteve Dickson <steved@redhat.com>2020-11-10 13:52:45 -0500
commit5bc378a01e74f31b3b7e7528454efe2515694c74 (patch)
tree6a0819f8d82fb71a208cb4d421a73404f7b6f7a8
parent15e17993e336acffa590cd4ac3ca1470ad5ef85d (diff)
downloadnfs-utils-5bc378a01e74f31b3b7e7528454efe2515694c74.tar.gz
conffile: Only process files in the config.d dirs that end with ".conf"
To allow 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>
-rw-r--r--support/nfs/conffile.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index f2c4f56c..a4ea0676 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];
- int n = 0, i, nfiles = 0, fname_len, dname_len;
+ char *dname, fname[PATH_MAX], *cname;
+ int n = 0, nfiles = 0, i, fname_len, dname_len;
int trans, rv, path_len;
dname = malloc(strlen(conf_file) + 3);
@@ -685,12 +688,30 @@ 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;
+ }
+
rv = snprintf(fname, PATH_MAX, "%s/%s", dname, d->d_name);
if (rv < path_len) {
xlog(L_WARNING, "conf_init_dir: file name: %s/%s too short",
d->d_name, dname);
continue;
}
+
if (conf_load_files(trans, fname))
continue;
nfiles++;