From 5a7cdf2e0efd8579ea8771b856a682ec39acd70e Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 1 Mar 2007 12:17:35 +0100 Subject: [PATCH] src/common.c: Allow `check_create_dir' to create absolute directories. Since the `DataDir' of the `csv' and `rrdtool' plugins are seperate from the `BaseDir' setting, it makes sense to allow absolute directories here. The (possibly more secure) alternative would be to disallow absolute directories and force the user to create SymLinks instead. --- src/common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index 365b74f3..fc34afe7 100644 --- a/src/common.c +++ b/src/common.c @@ -290,6 +290,7 @@ int check_create_dir (const char *file_orig) int fields_num; char *ptr; int last_is_file = 1; + int path_is_absolute = 0; int len; int i; @@ -310,6 +311,8 @@ int check_create_dir (const char *file_orig) */ if (file_orig[len - 1] == '/') last_is_file = 0; + if (file_orig[0] == '/') + path_is_absolute = 1; /* * Create a copy for `strtok' to destroy @@ -351,7 +354,9 @@ int check_create_dir (const char *file_orig) /* * Join the components together again */ - if (strjoin (dir, dir_len, fields, i + 1, "/") < 0) + dir[0] = '/'; + if (strjoin (dir + path_is_absolute, dir_len - path_is_absolute, + fields, i + 1, "/") < 0) { syslog (LOG_ERR, "strjoin failed: `%s', component #%i", file_orig, i); return (-1); -- 2.11.0