dovecot-1.1: Allow dovecot --exec-mail ext program arguments.

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 4 06:28:08 EET 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/ae8180a4febd
changeset: 7334:ae8180a4febd
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Mar 04 06:24:44 2008 +0200
description:
Allow dovecot --exec-mail ext program arguments.

diffstat:

5 files changed, 25 insertions(+), 15 deletions(-)
src/master/child-process.c |    9 +++++++--
src/master/child-process.h |    1 +
src/master/mail-process.c  |   14 ++++++++++----
src/master/mail-process.h  |    4 +---
src/master/main.c          |   12 ++++++------

diffs (146 lines):

diff -r cd22f3bcd29d -r ae8180a4febd src/master/child-process.c
--- a/src/master/child-process.c	Tue Mar 04 06:24:07 2008 +0200
+++ b/src/master/child-process.c	Tue Mar 04 06:24:44 2008 +0200
@@ -67,7 +67,7 @@ void child_process_init_env(void)
 
 void client_process_exec(const char *cmd, const char *title)
 {
-	const char *executable, *p, **argv;
+	const char **argv;
 
 	/* very simple argument splitting. */
 	if (*title == '\0')
@@ -75,7 +75,12 @@ void client_process_exec(const char *cmd
 	else
 		argv = t_strsplit(t_strconcat(cmd, " ", title, NULL), " ");
 
-	executable = argv[0];
+	client_process_exec_argv(argv[0], argv);
+}
+
+void client_process_exec_argv(const char *executable, const char **argv)
+{
+	const char *p;
 
 	/* hide the path, it's ugly */
 	p = strrchr(argv[0], '/');
diff -r cd22f3bcd29d -r ae8180a4febd src/master/child-process.h
--- a/src/master/child-process.h	Tue Mar 04 06:24:07 2008 +0200
+++ b/src/master/child-process.h	Tue Mar 04 06:24:44 2008 +0200
@@ -32,6 +32,7 @@ void child_process_remove(pid_t pid);
 
 void child_process_init_env(void);
 void client_process_exec(const char *cmd, const char *title);
+void client_process_exec_argv(const char *executable, const char **argv);
 
 void child_process_set_destroy_callback(enum process_type type,
 					child_process_destroy_callback_t *cb);
diff -r cd22f3bcd29d -r ae8180a4febd src/master/mail-process.c
--- a/src/master/mail-process.c	Tue Mar 04 06:24:07 2008 +0200
+++ b/src/master/mail-process.c	Tue Mar 04 06:24:44 2008 +0200
@@ -412,7 +412,7 @@ mail_process_set_environment(struct sett
 	}
 }
 
-void mail_process_exec(const char *protocol, const char *section)
+void mail_process_exec(const char *protocol, const char **args)
 {
 	struct server_settings *server = settings_root;
 	const struct var_expand_table *var_expand_table;
@@ -421,11 +421,13 @@ void mail_process_exec(const char *proto
 
 	if (strcmp(protocol, "ext") == 0) {
 		/* external binary. section contains path for it. */
-		if (section == NULL)
+		if (*args == NULL)
 			i_fatal("External binary parameter not given");
 		set = server->defaults;
-		executable = section;
+		executable = *args;
 	} else {
+		const char *section = *args;
+
 		if (section != NULL) {
 			for (; server != NULL; server = server->next) {
 				if (strcmp(server->name, section) == 0)
@@ -442,6 +444,7 @@ void mail_process_exec(const char *proto
 		else
 			i_fatal("Unknown protocol: '%s'", protocol);
 		executable = set->mail_executable;
+		args = NULL;
 	}
 
 	var_expand_table =
@@ -468,7 +471,10 @@ void mail_process_exec(const char *proto
 
 	mail_process_set_environment(set, getenv("MAIL"), var_expand_table,
 				     FALSE);
-        client_process_exec(executable, "");
+	if (args == NULL)
+		client_process_exec(executable, "");
+	else
+		client_process_exec_argv(executable, args);
 
 	i_fatal_status(FATAL_EXEC, "execv(%s) failed: %m", executable);
 }
diff -r cd22f3bcd29d -r ae8180a4febd src/master/mail-process.h
--- a/src/master/mail-process.h	Tue Mar 04 06:24:07 2008 +0200
+++ b/src/master/mail-process.h	Tue Mar 04 06:24:44 2008 +0200
@@ -6,9 +6,7 @@ struct login_group;
 struct login_group;
 struct auth_master_reply;
 
-void mail_process_exec(const char *protocol, const char *section)
-	ATTR_NORETURN;
-
+void mail_process_exec(const char *protocol, const char **args) ATTR_NORETURN;
 
 enum master_login_status
 create_mail_process(enum process_type process_type, struct settings *set,
diff -r cd22f3bcd29d -r ae8180a4febd src/master/main.c
--- a/src/master/main.c	Tue Mar 04 06:24:07 2008 +0200
+++ b/src/master/main.c	Tue Mar 04 06:24:44 2008 +0200
@@ -322,7 +322,7 @@ static void print_help(void)
 {
 	printf(
 "Usage: dovecot [-F] [-c <config file>] [-p] [-n] [-a]\n"
-"       [--exec-mail <protocol>] [--version] [--build-options]\n");
+"       [--version] [--build-options] [--exec-mail <protocol> [<args>]]\n");
 }
 
 static void print_build_options(void)
@@ -431,7 +431,7 @@ int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 	/* parse arguments */
-	const char *exec_protocol = NULL, *exec_section = NULL, *user, *home;
+	const char *exec_protocol = NULL, **exec_args = NULL, *user, *home;
 	bool foreground = FALSE, ask_key_pass = FALSE, log_error = FALSE;
 	bool dump_config = FALSE, dump_config_nondefaults = FALSE;
 	int i;
@@ -460,13 +460,13 @@ int main(int argc, char *argv[])
 			/* Ask SSL private key password */
 			ask_key_pass = TRUE;
 		} else if (strcmp(argv[i], "--exec-mail") == 0) {
-			/* <protocol> [<server section>]
+			/* <protocol> [<args>]
 			   read configuration and execute mail process */
 			i++;
 			if (i == argc) i_fatal("Missing protocol argument");
 			exec_protocol = argv[i];
-			if (i+1 != argc) 
-				exec_section = argv[++i];
+			exec_args = (const char **)&argv[i+1];
+			break;
 		} else if (strcmp(argv[i], "--version") == 0) {
 			printf("%s\n", VERSION);
 			return 0;
@@ -540,7 +540,7 @@ int main(int argc, char *argv[])
 		/* Put back user and home */
 		env_put(t_strconcat("USER=", user, NULL));
 		env_put(t_strconcat("HOME=", home, NULL));
-		mail_process_exec(exec_protocol, exec_section);
+		mail_process_exec(exec_protocol, exec_args);
 	}
 
 	if (!log_error)


More information about the dovecot-cvs mailing list