dovecot-1.3: Settings parser: !included files without absolute p...

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 21 23:38:30 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.3/rev/cab82d03d00d
changeset: 9151:cab82d03d00d
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 21 16:38:20 2009 -0400
description:
Settings parser: !included files without absolute paths are relative to their parent config file.

diffstat:

1 file changed, 21 insertions(+), 4 deletions(-)
src/lib-settings/settings.c |   25 +++++++++++++++++++++----

diffs (49 lines):

diff -r 92825cc9a59c -r cab82d03d00d src/lib-settings/settings.c
--- a/src/lib-settings/settings.c	Tue Apr 21 13:35:08 2009 -0400
+++ b/src/lib-settings/settings.c	Tue Apr 21 16:38:20 2009 -0400
@@ -70,6 +70,21 @@ parse_setting_from_defs(pool_t pool, str
 	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 {


More information about the dovecot-cvs mailing list