From: Timo Sirainen Date: Thu, 1 Aug 2013 11:23:33 +0000 (+0300) Subject: lib-storage: Improved seteuid() error messages a bit. X-Git-Tag: 2.2.5~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=20dca965f48c1d7600a268d380c0b5fb5f1011d5;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Improved seteuid() error messages a bit. --- diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index 9ae3516604..61e40af00b 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -495,6 +495,15 @@ service_parse_privileges(struct mail_storage_service_ctx *ctx, return 0; } +static void mail_storage_service_seteuid_root(void) +{ + if (seteuid(0) < 0) { + i_fatal("mail-storage-service: " + "Failed to restore temporarily dropped root privileges: " + "seteuid(0) failed: %m"); + } +} + static int service_drop_privileges(struct mail_storage_service_user *user, struct mail_storage_service_privileges *priv, @@ -572,8 +581,7 @@ service_drop_privileges(struct mail_storage_service_user *user, if (current_euid != 0) { /* we're changing the UID, switch back to root first */ - if (seteuid(0) < 0) - i_fatal("seteuid(0) failed: %m"); + mail_storage_service_seteuid_root(); } setuid_uid = rset.uid; } @@ -588,7 +596,8 @@ service_drop_privileges(struct mail_storage_service_user *user, } if (setuid_uid != 0 && !setenv_only) { if (seteuid(setuid_uid) < 0) - i_fatal("seteuid(%s) failed: %m", dec2str(setuid_uid)); + i_fatal("mail-storage-service: seteuid(%s) failed: %m", + dec2str(setuid_uid)); } return 0; } @@ -986,8 +995,7 @@ int mail_storage_service_lookup(struct mail_storage_service_ctx *ctx, /* we dropped privileges only temporarily. switch back to root before reading settings, so we'll definitely have enough permissions to connect to the config socket. */ - if (seteuid(0) < 0) - i_fatal("seteuid(0) failed: %m"); + mail_storage_service_seteuid_root(); } if (mail_storage_service_read_settings(ctx, input, user_pool,