Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8975:c2595e358867 HEAD
Settings parser: !included files without absolute paths are relative to their parent config file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 21 Apr 2009 13:33:53 -0400 |
parents | 1f4f68091243 |
children | 3d9c9b16f000 |
files | src/lib-settings/settings.c |
diffstat | 1 files changed, 23 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-settings/settings.c Mon Apr 20 14:54:49 2009 -0400 +++ b/src/lib-settings/settings.c Tue Apr 21 13:33:53 2009 -0400 @@ -70,6 +70,24 @@ 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; + + while (input->prev != NULL) + input = input->prev; + + 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 +187,19 @@ 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 {