dovecot-2.2: lib-storage: Improved seteuid() error messages a bit.

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 1 14:23:48 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/f7f3ea4cb6df
changeset: 16631:f7f3ea4cb6df
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 01 14:23:33 2013 +0300
description:
lib-storage: Improved seteuid() error messages a bit.

diffstat:

 src/lib-storage/mail-storage-service.c |  18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diffs (49 lines):

diff -r 2bccde4027ea -r f7f3ea4cb6df src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Thu Aug 01 14:18:24 2013 +0300
+++ b/src/lib-storage/mail-storage-service.c	Thu Aug 01 14:23:33 2013 +0300
@@ -495,6 +495,15 @@
 	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 @@
 			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 @@
 	}
 	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 @@
 		/* 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,


More information about the dovecot-cvs mailing list