From ca8c2190f161a28bb5020b6d6068d43ccf66b7d1 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 28 Jan 2010 23:08:32 +0200 Subject: [PATCH] lmtp: Switch back to running as root after deliver a mail. --HG-- branch : HEAD --- src/lmtp/commands.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index 979316e4dc..b12e064bc6 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -436,10 +436,13 @@ client_deliver(struct client *client, const struct mail_recipient *rcpt, struct mail_storage *storage; const struct mail_storage_service_input *input; void **sets; + uid_t old_uid; const char *error, *username; enum mail_error mail_error; int ret; + old_uid = geteuid(); + input = mail_storage_service_user_get_input(rcpt->service_user); username = t_strdup(input->username); @@ -494,6 +497,13 @@ client_deliver(struct client *client, const struct mail_recipient *rcpt, } ret = -1; } + if (old_uid == 0) { + /* switch back to running as root, since that's what we're + practically doing anyway. it's also important in case we + lose e.g. config connection and need to reconnect to it. */ + if (seteuid(0) < 0) + i_fatal("seteuid(0) failed: %m"); + } pool_unref(&dctx.pool); return ret; } -- 2.47.3