]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Settings parser: !included files without absolute paths are relative to their parent...
authorTimo Sirainen <tss@iki.fi>
Tue, 21 Apr 2009 20:38:20 +0000 (16:38 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 21 Apr 2009 20:38:20 +0000 (16:38 -0400)
--HG--
branch : HEAD

src/lib-settings/settings.c

index 795c186e2ac7d874f004ae33f4b4085f57076b2f..305f6be464270d23a0cdd0d9e202566e1dcdf7eb 100644 (file)
@@ -70,6 +70,21 @@ parse_setting_from_defs(pool_t pool, struct setting_def *defs, void *base,
        return t_strconcat("Unknown setting: ", key, NULL);
 }
 
+static const char *
+fix_relative_path(const char *path, struct input_stack *input)
+{
+       const char *p;
+
+       if (*path == '/')
+               return path;
+
+       p = strrchr(input->path, '/');
+       if (p == NULL)
+               return path;
+
+       return t_strconcat(t_strdup_until(input->path, p+1), path, NULL);
+}
+
 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
 
 static bool
@@ -169,17 +184,19 @@ prevfile:
                if (strcmp(key, "!include_try") == 0 ||
                    strcmp(key, "!include") == 0) {
                        struct input_stack *tmp;
+                       const char *path;
 
+                       path = fix_relative_path(line, input);
                        for (tmp = input; tmp != NULL; tmp = tmp->prev) {
-                               if (strcmp(tmp->path, line) == 0)
+                               if (strcmp(tmp->path, path) == 0)
                                        break;
                        }
                        if (tmp != NULL) {
                                errormsg = "Recursive include";
-                       } else if ((fd = open(line, O_RDONLY)) != -1) {
+                       } else if ((fd = open(path, O_RDONLY)) != -1) {
                                new_input = t_new(struct input_stack, 1);
                                new_input->prev = input;
-                               new_input->path = t_strdup(line);
+                               new_input->path = t_strdup(path);
                                input = new_input;
                                goto newfile;
                        } else {