changeset 5186:a7627141ec7f HEAD

Don't compare to PACKAGE_VERSION in lib/ core directly, rather make module_dir_load() have the version string as parameter. Plugin version checks can be skipped with version_ignore=yes.
author Timo Sirainen <tss@iki.fi>
date Thu, 22 Feb 2007 16:36:01 +0200
parents 24f4a959a24c
children 9dd18b285223
files src/auth/password-scheme.c src/deliver/deliver.c src/dict/main.c src/imap/main.c src/lib/module-dir.c src/lib/module-dir.h src/pop3/main.c
diffstat 7 files changed, 45 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/password-scheme.c	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/auth/password-scheme.c	Thu Feb 22 16:36:01 2007 +0200
@@ -519,7 +519,7 @@
 
 #ifdef HAVE_MODULES
 	scheme_modules = module_dir_load(AUTH_MODULE_DIR"/password",
-					 NULL, FALSE);
+					 NULL, FALSE, PACKAGE_VERSION);
 	module_dir_init(scheme_modules);
 	for (mod = scheme_modules; mod != NULL; mod = mod->next) {
 		t_push();
--- a/src/deliver/deliver.c	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/deliver/deliver.c	Thu Feb 22 16:36:01 2007 +0200
@@ -613,11 +613,15 @@
 		modules = NULL;
 	else {
 		const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
+		const char *version;
 
 		if (plugin_dir == NULL)
 			plugin_dir = MODULEDIR"/lda";
+
+		version = getenv("VERSION_IGNORE") != NULL ?
+			NULL : PACKAGE_VERSION;
 		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
-					  TRUE);
+					  TRUE, version);
 		module_dir_init(modules);
 	}
 
--- a/src/dict/main.c	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/dict/main.c	Thu Feb 22 16:36:01 2007 +0200
@@ -56,14 +56,14 @@
 
 static void main_init(void)
 {
-	const char *value, *path;
+	const char *version, *path;
 	int fd;
 
-	value = getenv("DOVECOT_VERSION");
-	if (value != NULL && strcmp(value, PACKAGE_VERSION) != 0) {
+	version = getenv("DOVECOT_VERSION");
+	if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
 		i_fatal("Dovecot version mismatch: "
 			"Master is v%s, dict is v"PACKAGE_VERSION" "
-			"(if you don't care, set version_ignore=yes)", value);
+			"(if you don't care, set version_ignore=yes)", version);
 	}
 
 	lib_signals_init();
@@ -78,7 +78,7 @@
 	dict_drivers_register_all();
 
 	modules = getenv("MODULE_DIR") == NULL ? NULL :
-		module_dir_load(getenv("MODULE_DIR"), NULL, TRUE);
+		module_dir_load(getenv("MODULE_DIR"), NULL, TRUE, version);
 	module_dir_init(modules);
 
 	path = getenv("DICT_LISTEN_FROM_FD");
--- a/src/imap/main.c	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/imap/main.c	Thu Feb 22 16:36:01 2007 +0200
@@ -128,6 +128,15 @@
 
 static void drop_privileges(void)
 {
+	const char *version;
+
+	version = getenv("DOVECOT_VERSION");
+	if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
+		i_fatal("Dovecot version mismatch: "
+			"Master is v%s, imap is v"PACKAGE_VERSION" "
+			"(if you don't care, set version_ignore=yes)", version);
+	}
+
 	/* Log file or syslog opening probably requires roots */
 	open_logfile();
 
@@ -142,7 +151,7 @@
 		if (plugin_dir == NULL)
 			plugin_dir = MODULEDIR"/imap";
 		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
-					  TRUE);
+					  TRUE, version);
 	}
 
 	restrict_access_by_env(!IS_STANDALONE());
@@ -153,13 +162,6 @@
 	struct client *client;
 	const char *user, *str;
 
-	str = getenv("DOVECOT_VERSION");
-	if (str != NULL && strcmp(str, PACKAGE_VERSION) != 0) {
-		i_fatal("Dovecot version mismatch: "
-			"Master is v%s, imap is v"PACKAGE_VERSION" "
-			"(if you don't care, set version_ignore=yes)", str);
-	}
-
 	lib_signals_init();
         lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
         lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
--- a/src/lib/module-dir.c	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/lib/module-dir.c	Thu Feb 22 16:36:01 2007 +0200
@@ -83,11 +83,12 @@
 }
 
 static struct module *
-module_load(const char *path, const char *name, bool require_init_funcs)
+module_load(const char *path, const char *name, bool require_init_funcs,
+	    const char *version)
 {
 	void *handle;
 	struct module *module;
-	const char *const *version;
+	const char *const *module_version;
 
 	handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW);
 	if (handle == NULL) {
@@ -100,10 +101,12 @@
 	module->name = i_strdup(name);
 	module->handle = handle;
 
-	version = get_symbol(module, t_strconcat(name, "_version", NULL), TRUE);
-	if (version != NULL && strcmp(*version, PACKAGE_VERSION) != 0) {
+	module_version = version == NULL ? NULL :
+		get_symbol(module, t_strconcat(name, "_version", NULL), TRUE);
+	if (module_version != NULL &&
+	    strcmp(*module_version, version) != 0) {
 		i_error("Module is for different version %s: %s",
-			*version, path);
+			*module_version, path);
 		module_free(module);
 		return NULL;
 	}
@@ -183,7 +186,7 @@
 }
 
 struct module *module_dir_load(const char *dir, const char *module_names,
-			       bool require_init_funcs)
+			       bool require_init_funcs, const char *version)
 {
 	DIR *dirp;
 	struct dirent *d;
@@ -256,7 +259,7 @@
 		else {
 			path = t_strconcat(dir, "/", name, NULL);
 			module = module_load(path, stripped_name,
-					     require_init_funcs);
+					     require_init_funcs, version);
 			if (module == NULL && module_names_arr != NULL)
 				exit(FATAL_DEFAULT);
 		}
--- a/src/lib/module-dir.h	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/lib/module-dir.h	Thu Feb 22 16:36:01 2007 +0200
@@ -12,9 +12,10 @@
 };
 
 /* Load modules in given directory. module_names is a space separated list of
-   module names to load, or NULL to load everything. */
+   module names to load, or NULL to load everything. If version is non-NULL and
+   the module contains a version symbol, fail the load if they're different. */
 struct module *module_dir_load(const char *dir, const char *module_names,
-			       bool require_init_funcs);
+			       bool require_init_funcs, const char *version);
 /* Call init() in all modules */
 void module_dir_init(struct module *modules);
 /* Call deinit() in all modules and mark them NULL so module_dir_unload()
--- a/src/pop3/main.c	Thu Feb 22 16:27:25 2007 +0200
+++ b/src/pop3/main.c	Thu Feb 22 16:36:01 2007 +0200
@@ -145,6 +145,15 @@
 
 static void drop_privileges(void)
 {
+	const char *version;
+
+	version = getenv("DOVECOT_VERSION");
+	if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
+		i_fatal("Dovecot version mismatch: "
+			"Master is v%s, pop3 is v"PACKAGE_VERSION" "
+			"(if you don't care, set version_ignore=yes)", version);
+	}
+
 	/* Log file or syslog opening probably requires roots */
 	open_logfile();
 
@@ -159,7 +168,7 @@
 		if (plugin_dir == NULL)
 			plugin_dir = MODULEDIR"/imap";
 		modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
-					  TRUE);
+					  TRUE, version);
 	}
 
 	restrict_access_by_env(!IS_STANDALONE());
@@ -170,14 +179,7 @@
         enum mail_storage_flags flags;
         enum file_lock_method lock_method;
 	struct mail_storage *storage;
-	const char *mail, *value;
-
-	value = getenv("DOVECOT_VERSION");
-	if (value != NULL && strcmp(value, PACKAGE_VERSION) != 0) {
-		i_fatal("Dovecot version mismatch: "
-			"Master is v%s, pop3 is v"PACKAGE_VERSION" "
-			"(if you don't care, set version_ignore=yes)", value);
-	}
+	const char *mail;
 
 	lib_signals_init();
         lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);