[PATCH] rrdcached: Improved the "base-dir symlink check".

2 messages Options
Embed this post
Permalink
Sebastian Harl

[PATCH] rrdcached: Improved the "base-dir symlink check".

Reply Threaded More More options
Print post
Permalink
The daemon checks if the specified base directory contains symlinks by
comparing the canonicalized path name (by realpath()) with the path name
specified on the command line. The GNU libc's implementation of realpath()
removed trailing slashes ('/') from the pathname. Thus, specifying a base
directory with a trailing slash results in rrdcached aborting, complaining
about an invalid base directory, which is quite annoying imho. Now, trailing
slashes are removed before comparing the two path names.
---
 program/src/rrd_daemon.c |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/program/src/rrd_daemon.c b/program/src/rrd_daemon.c
index fa7dc41..7406325 100644
--- a/program/src/rrd_daemon.c
+++ b/program/src/rrd_daemon.c
@@ -2918,16 +2918,6 @@ static int read_options (int argc, char **argv) /* {{{ */
               "%s\n", config_base_dir, rrd_strerror(errno));
           return 5;
         }
-        else if (strncmp(config_base_dir,
-                         base_realpath, sizeof(base_realpath)) != 0)
-        {
-          fprintf(stderr,
-                  "Base directory (-b) resolved via file system links!\n"
-                  "Please consult rrdcached '-b' documentation!\n"
-                  "Consider specifying the real directory (%s)\n",
-                  base_realpath);
-          return 5;
-        }
 
         len = strlen (config_base_dir);
         while ((len > 0) && (config_base_dir[len - 1] == '/'))
@@ -2943,6 +2933,24 @@ static int read_options (int argc, char **argv) /* {{{ */
         }
 
         _config_base_dir_len = len;
+
+        len = strlen (base_realpath);
+        while ((len > 0) && (base_realpath[len - 1] == '/'))
+        {
+          base_realpath[len - 1] = '\0';
+          len--;
+        }
+
+        if (strncmp(config_base_dir,
+                         base_realpath, sizeof(base_realpath)) != 0)
+        {
+          fprintf(stderr,
+                  "Base directory (-b) resolved via file system links!\n"
+                  "Please consult rrdcached '-b' documentation!\n"
+                  "Consider specifying the real directory (%s)\n",
+                  base_realpath);
+          return 5;
+        }
       }
       break;
 
--
1.6.5.rc2



_______________________________________________
rrd-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers

signature.asc (204 bytes) Download Attachment
oetiker

Re: [PATCH] rrdcached: Improved the "base-dir symlink check".

Reply Threaded More More options
Print post
Permalink
Hi Sebastian,

Yesterday Sebastian Harl wrote:

> The daemon checks if the specified base directory contains symlinks by
> comparing the canonicalized path name (by realpath()) with the path name
> specified on the command line. The GNU libc's implementation of realpath()
> removed trailing slashes ('/') from the pathname. Thus, specifying a base
> directory with a trailing slash results in rrdcached aborting, complaining
> about an invalid base directory, which is quite annoying imho. Now, trailing
> slashes are removed before comparing the two path names.

thanks ... applied
tobi

--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
http://it.oetiker.ch [hidden email] ++41 62 775 9902 / sb: -9900

_______________________________________________
rrd-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers