[dovecot-cvs] dovecot/src/lib module-dir.c,1.25,1.26

tss at dovecot.org tss at dovecot.org
Thu Dec 21 11:29:27 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv21205

Modified Files:
	module-dir.c 
Log Message:
Give an error if there are duplicate files for a single module. Also if the
module directory can't be opened, die immediately.



Index: module-dir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- module-dir.c	4 Nov 2006 19:49:15 -0000	1.25
+++ module-dir.c	21 Dec 2006 11:29:25 -0000	1.26
@@ -155,6 +155,25 @@
 	return FALSE;
 }
 
+static void check_duplicates(ARRAY_TYPE(const_string) *names,
+			     const char *name, const char *dir)
+{
+	const char *const *names_p, *base_name, *tmp;
+	unsigned int i, count;
+
+	t_push();
+	base_name = module_file_get_name(name);
+	names_p = array_get(names, &count);
+	for (i = 0; i < count; i++) {
+		tmp = module_file_get_name(names_p[i]);
+
+		if (strcmp(tmp, base_name) == 0)
+			i_fatal("Multiple files for module %s: %s/%s, %s/%s",
+				base_name, dir, name, dir, names_p[i]);
+	}
+	t_pop();
+}
+
 struct module *module_dir_load(const char *dir, const char *module_names,
 			       bool require_init_funcs)
 {
@@ -164,18 +183,15 @@
 	const char **module_names_arr;
 	struct module *modules, *module;
 	unsigned int i, count;
-	ARRAY_DEFINE(names, const char *);
+	ARRAY_TYPE(const_string) names;
 	pool_t pool;
 
 	if (getenv("DEBUG") != NULL)
 		i_info("Loading modules from directory: %s", dir);
 
 	dirp = opendir(dir);
-	if (dirp == NULL) {
-		if (errno != ENOENT)
-			i_error("opendir(%s) failed: %m", dir);
-		return NULL;
-	}
+	if (dirp == NULL)
+		i_fatal("opendir(%s) failed: %m", dir);
 
 	pool = pool_alloconly_create("module loader", 1024);
 	p_array_init(&names, pool, 32);
@@ -191,6 +207,8 @@
 		if (p == NULL || strlen(p) != 3)
 			continue;
 
+		check_duplicates(&names, name, dir);
+
 		name = p_strdup(pool, d->d_name);
 		array_append(&names, &name, 1);
 	}
@@ -204,7 +222,7 @@
 	else {
 		module_names_arr = t_strsplit_spaces(module_names, ", ");
 		/* allow giving the module names also in non-base form.
-		   conver them in here. */
+		   convert them in here. */
 		for (i = 0; module_names_arr[i] != NULL; i++) {
 			module_names_arr[i] =
 				module_file_get_name(module_names_arr[i]);



More information about the dovecot-cvs mailing list