changeset 8566:1c462a3c21ba HEAD

Fix to previous change: Don't lose errno during uid/gid naming.
author Timo Sirainen <tss@iki.fi>
date Thu, 18 Dec 2008 18:11:21 +0200
parents 23ae9c63ae47
children c6facf63c7f9
files src/lib/restrict-access.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/restrict-access.c	Thu Dec 18 18:09:00 2008 +0200
+++ b/src/lib/restrict-access.c	Thu Dec 18 18:11:21 2008 +0200
@@ -53,23 +53,31 @@
 static const char *get_uid_str(uid_t uid)
 {
 	const struct passwd *pw;
+	const char *ret;
+	int old_errno = errno;
 
 	pw = getpwuid(uid);
 	if (pw == NULL)
-		return dec2str(uid);
+		ret = dec2str(uid);
 	else
-		return t_strdup_printf("%s(%s)", dec2str(uid), pw->pw_name);
+		ret = t_strdup_printf("%s(%s)", dec2str(uid), pw->pw_name);
+	errno = old_errno;
+	return ret;
 }
 
 static const char *get_gid_str(gid_t gid)
 {
 	const struct group *group;
+	const char *ret;
+	int old_errno = errno;
 
 	group = getgrgid(gid);
 	if (group == NULL)
-		return dec2str(gid);
+		ret = dec2str(gid);
 	else
-		return t_strdup_printf("%s(%s)", dec2str(gid), group->gr_name);
+		ret = t_strdup_printf("%s(%s)", dec2str(gid), group->gr_name);
+	errno = old_errno;
+	return ret;
 }
 
 static void restrict_init_groups(gid_t primary_gid, gid_t privileged_gid)