From: Timo Sirainen Date: Fri, 26 Mar 2010 23:34:23 +0000 (+0200) Subject: Replaced execv*() with execv*_const() wherever possible. X-Git-Tag: 2.0.beta5~278 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb308de9d25db75528605eb733a418c996d416ad;p=thirdparty%2Fdovecot%2Fcore.git Replaced execv*() with execv*_const() wherever possible. --HG-- branch : HEAD --- diff --git a/src/auth/mech-winbind.c b/src/auth/mech-winbind.c index 357080d9a0..d653562394 100644 --- a/src/auth/mech-winbind.c +++ b/src/auth/mech-winbind.c @@ -13,6 +13,7 @@ #include "str.h" #include "buffer.h" #include "base64.h" +#include "execv-const.h" #include "istream.h" #include "ostream.h" @@ -136,8 +137,7 @@ winbind_helper_connect(const struct auth_settings *set, args[0] = set->winbind_helper_path; args[1] = winbind->param; args[2] = NULL; - execv(args[0], (void *)args); - i_fatal("execv(%s) failed: %m", args[0]); + execv_const(args[0], args); } /* parent */ diff --git a/src/auth/passdb-checkpassword.c b/src/auth/passdb-checkpassword.c index aa7f7aaf91..8af65e68e2 100644 --- a/src/auth/passdb-checkpassword.c +++ b/src/auth/passdb-checkpassword.c @@ -1,6 +1,7 @@ /* Copyright (c) 2004-2010 Dovecot authors, see the included COPYING file */ #include "auth-common.h" +#include "execv-const.h" #include "passdb.h" #ifdef PASSDB_CHECKPASSWORD @@ -142,9 +143,7 @@ checkpassword_verify_plain_child(struct auth_request *request, "execute: %s", cmd); args = t_strsplit(cmd, " "); - execv(args[0], (char **)args); - auth_request_log_error(request, "checkpassword", - "execv(%s) failed: %m", args[0]); + execv_const(args[0], args); } exit(2); } diff --git a/src/auth/userdb-checkpassword.c b/src/auth/userdb-checkpassword.c index a48f1ac7dc..d6f044625d 100644 --- a/src/auth/userdb-checkpassword.c +++ b/src/auth/userdb-checkpassword.c @@ -1,6 +1,7 @@ /* Copyright (c) 2004-2010 Dovecot authors, see the included COPYING file */ #include "auth-common.h" +#include "execv-const.h" #include "userdb.h" #ifdef USERDB_CHECKPASSWORD @@ -127,9 +128,7 @@ checkpassword_lookup_child(struct auth_request *request, "execute: %s", cmd); args = t_strsplit(cmd, " "); - execv(args[0], (char **)args); - auth_request_log_error(request, "userdb-checkpassword", - "execv(%s) failed: %m", args[0]); + execv_const(args[0], args); } exit(2); } diff --git a/src/dsync/dsync.c b/src/dsync/dsync.c index 37bcf8c0fa..ecb2e76045 100644 --- a/src/dsync/dsync.c +++ b/src/dsync/dsync.c @@ -1,6 +1,7 @@ /* Copyright (c) 2009-2010 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "execv-const.h" #include "settings-parser.h" #include "master-service.h" #include "master-service-settings.h" @@ -19,7 +20,7 @@ static struct dsync_proxy_server *server; static void run_cmd(const char *cmd, int *fd_in_r, int *fd_out_r) { - char **args; + const char *const *args; int fd_in[2], fd_out[2]; if (pipe(fd_in) < 0 || pipe(fd_out) < 0) @@ -41,9 +42,8 @@ static void run_cmd(const char *cmd, int *fd_in_r, int *fd_out_r) (void)close(fd_out[0]); (void)close(fd_out[1]); - args = p_strsplit(pool_datastack_create(), cmd, " "); - (void)execvp(args[0], args); - i_fatal("execve(%s) failed: %m", args[0]); + args = t_strsplit(cmd, " "); + execvp_const(args[0], args); break; default: /* parent */ diff --git a/src/lib-lda/smtp-client.c b/src/lib-lda/smtp-client.c index 937350a935..539aa9dcfe 100644 --- a/src/lib-lda/smtp-client.c +++ b/src/lib-lda/smtp-client.c @@ -1,6 +1,7 @@ /* Copyright (c) 2006-2010 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "execv-const.h" #include "master-service.h" #include "lda-settings.h" #include "mail-deliver.h" @@ -52,8 +53,7 @@ smtp_client_run_sendmail(const struct lda_settings *set, master_service_env_clean(TRUE); - (void)execv(sendmail_path, (void *)argv); - i_fatal("execv(%s) failed: %m", sendmail_path); + execv_const(sendmail_path, argv); } struct smtp_client * diff --git a/src/lib-master/master-service-settings.c b/src/lib-master/master-service-settings.c index 6d2337e86c..40c1d07ccf 100644 --- a/src/lib-master/master-service-settings.c +++ b/src/lib-master/master-service-settings.c @@ -6,6 +6,7 @@ #include "istream.h" #include "write-full.h" #include "str.h" +#include "execv-const.h" #include "settings-parser.h" #include "master-service-private.h" #include "master-service-settings.h" @@ -101,8 +102,7 @@ master_service_exec_config(struct master_service *service, conf_argv[8] = binary_path; memcpy(conf_argv+9, service->argv + 1, (service->argc) * sizeof(conf_argv[0])); - execv(conf_argv[0], (char **)conf_argv); - i_fatal("execv(%s) failed: %m", conf_argv[0]); + execv_const(conf_argv[0], conf_argv); } static void diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index 5341cd3728..3ffd0c51a0 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -5,6 +5,7 @@ #include "hash.h" #include "network.h" #include "istream.h" +#include "execv-const.h" #include "str.h" #include "strescape.h" #include "var-expand.h" @@ -960,9 +961,7 @@ int settings_parse_exec(struct setting_parser_context *ctx, if (dup2(fd[1], STDOUT_FILENO) < 0) i_fatal("dup2() failed: %m"); - execv(argv[0], (void *)argv); - i_fatal_status(FATAL_EXEC, "execv(%s) failed: %m", bin_path); - return -1; + execv_const(argv[0], argv); } (void)close(fd[1]); diff --git a/src/master/main.c b/src/master/main.c index ec717efba7..d770e1afed 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -9,6 +9,7 @@ #include "env-util.h" #include "hostpid.h" #include "abspath.h" +#include "execv-const.h" #include "restrict-process-size.h" #include "master-service.h" #include "master-service-settings.h" @@ -80,10 +81,7 @@ void process_exec(const char *cmd, const char *extra_args[]) /* prefix with dovecot/ */ argv[0] = t_strconcat(PACKAGE"/", argv[0], NULL); - - (void)execv(executable, (char **)argv); - i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC, - "execv(%s) failed: %m", executable); + (void)execv_const(executable, argv); } int get_uidgid(const char *user, uid_t *uid_r, gid_t *gid_r, @@ -691,8 +689,7 @@ int main(int argc, char *argv[]) args[2] = "-c"; args[3] = master_service_get_config_path(master_service); args[4] = NULL; - execv(args[0], (char **)args); - i_fatal("execv(%s) failed: %m", args[0]); + execv_const(args[0], args); } while (optind < argc) { diff --git a/src/util/script.c b/src/util/script.c index 1c10ae4374..881c1a70d0 100644 --- a/src/util/script.c +++ b/src/util/script.c @@ -2,6 +2,7 @@ #include "lib.h" #include "env-util.h" +#include "execv-const.h" #include "fdpass.h" #include "restrict-access.h" #include "str.h" @@ -18,7 +19,7 @@ #define ENV_USERDB_KEYS "USERDB_KEYS" #define SCRIPT_COMM_FD 3 -static char **exec_args; +static const char **exec_args; static bool drop_privileges = FALSE; static void client_connected(const struct master_service_connection *conn) @@ -119,8 +120,7 @@ static void client_connected(const struct master_service_connection *conn) if (close(MASTER_STATUS_FD) < 0) i_error("close(status) failed: %m"); - (void)execvp(exec_args[0], exec_args); - i_fatal("execvp(%s) failed: %m", exec_args[0]); + execvp_const(exec_args[0], exec_args); } static void script_execute_finish(void) @@ -160,7 +160,6 @@ static void script_execute_finish(void) int main(int argc, char *argv[]) { enum master_service_flags flags = 0; - const char *path; int i, c; if (getenv(MASTER_UID_ENV) == NULL) @@ -189,16 +188,15 @@ int main(int argc, char *argv[]) else { if (argv[0] == NULL) i_fatal("Missing script path"); - exec_args = i_new(char *, argc + 2); + exec_args = i_new(const char *, argc + 2); for (i = 0; i < argc; i++) exec_args[i] = argv[i]; exec_args[i] = PKG_LIBEXECDIR"/script"; exec_args[i+1] = NULL; if (exec_args[0][0] != '/') { - path = t_strconcat(PKG_LIBEXECDIR"/", - exec_args[0], NULL); - exec_args[0] = t_strdup_noconst(path); + exec_args[0] = t_strconcat(PKG_LIBEXECDIR"/", + exec_args[0], NULL); } master_service_run(master_service, client_connected);