src/common.c: Allow `check_create_dir' to create absolute directories.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 1 Mar 2007 11:17:35 +0000 (12:17 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 1 Mar 2007 11:17:35 +0000 (12:17 +0100)
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

index 365b74f..fc34afe 100644 (file)
@@ -290,6 +290,7 @@ int check_create_dir (const char *file_orig)
        int   fields_num;
        char *ptr;
        int   last_is_file = 1;
        int   fields_num;
        char *ptr;
        int   last_is_file = 1;
+       int   path_is_absolute = 0;
        int   len;
        int   i;
 
        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[len - 1] == '/')
                last_is_file = 0;
+       if (file_orig[0] == '/')
+               path_is_absolute = 1;
 
        /*
         * Create a copy for `strtok' to destroy
 
        /*
         * Create a copy for `strtok' to destroy
@@ -351,7 +354,9 @@ int check_create_dir (const char *file_orig)
                /*
                 * Join the components together again
                 */
                /*
                 * 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);
                {
                        syslog (LOG_ERR, "strjoin failed: `%s', component #%i", file_orig, i);
                        return (-1);