Mercurial > dovecot > original-hg > dovecot-1.2
changeset 7334:ae8180a4febd HEAD
Allow dovecot --exec-mail ext program arguments.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 04 Mar 2008 06:24:44 +0200 |
parents | cd22f3bcd29d |
children | 969656b58e7f |
files | src/master/child-process.c src/master/child-process.h src/master/mail-process.c src/master/mail-process.h src/master/main.c |
diffstat | 5 files changed, 25 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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 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 @@ 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], '/');
--- 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_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);
--- 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 @@ } } -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 @@ 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 @@ else i_fatal("Unknown protocol: '%s'", protocol); executable = set->mail_executable; + args = NULL; } var_expand_table = @@ -468,7 +471,10 @@ 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); }
--- 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 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,
--- 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 @@ { 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[]) { /* 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 @@ /* 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 @@ /* 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)