util-linux/0010-login-fix-compiler-war...

45 lines
1.3 KiB
Diff

From ed68f1e2f5609a3f42492df407d62b8fc006ea17 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Mon, 22 Oct 2012 13:13:02 +0200
Subject: [PATCH 10/11] login: fix compiler warning [-Wunused-result]
It's probably unnecessary paranoia, but let's check if we're able to
restore the original IDs after ~/.hushlogin file check.
Signed-off-by: Karel Zak <kzak@redhat.com>
---
login-utils/login.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/login-utils/login.c b/login-utils/login.c
index 8ae5266..f5896da 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -1031,13 +1031,17 @@ static int get_hushlogin_status(struct passwd *pwd)
gid_t egid = getegid();
sprintf(buf, "%s/%s", pwd->pw_dir, file);
- setregid(-1, pwd->pw_gid);
- setreuid(0, pwd->pw_uid);
- ok = effective_access(buf, O_RDONLY) == 0;
- setuid(0); /* setreuid doesn't do it alone! */
- setreuid(ruid, 0);
- setregid(-1, egid);
+ if (setregid(-1, pwd->pw_gid) == 0 &&
+ setreuid(0, pwd->pw_uid) == 0)
+ ok = effective_access(buf, O_RDONLY) == 0;
+
+ if (setuid(0) != 0 ||
+ setreuid(ruid, 0) != 0 ||
+ setregid(-1, egid) != 0) {
+ syslog(LOG_ALERT, _("hush login status: restore original IDs failed"));
+ exit(EXIT_FAILURE);
+ }
if (ok)
return 1; /* enabled by user */
}
--
1.7.11.7