diff options
author | Ondrej Oprala | 2014-04-07 18:24:19 +0200 |
---|---|---|
committer | Karel Zak | 2014-05-15 13:55:59 +0200 |
commit | 29cc2a55686f7182ae16e949d6d2a2b2b44c8536 (patch) | |
tree | be392b41187d4be72db7302a1b492e20d19df48e /login-utils/logindefs.c | |
parent | login: extract get_hushlogin_status (diff) | |
download | kernel-qcow2-util-linux-29cc2a55686f7182ae16e949d6d2a2b2b44c8536.tar.gz kernel-qcow2-util-linux-29cc2a55686f7182ae16e949d6d2a2b2b44c8536.tar.xz kernel-qcow2-util-linux-29cc2a55686f7182ae16e949d6d2a2b2b44c8536.zip |
lslogins: add functionality
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'login-utils/logindefs.c')
-rw-r--r-- | login-utils/logindefs.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/login-utils/logindefs.c b/login-utils/logindefs.c index 804ab3e31..f02c4752d 100644 --- a/login-utils/logindefs.c +++ b/login-utils/logindefs.c @@ -307,7 +307,7 @@ int effective_access(const char *path, int mode) * BSD setreuid(). */ -int get_hushlogin_status(struct passwd *pwd) +int get_hushlogin_status(struct passwd *pwd, int force_check) { const char *files[] = { _PATH_HUSHLOGINS, _PATH_HUSHLOGIN, NULL }; const char *file; @@ -358,12 +358,13 @@ int get_hushlogin_status(struct passwd *pwd) /* per-account setting */ if (strlen(pwd->pw_dir) + sizeof(file) + 2 > sizeof(buf)) continue; - else { + + sprintf(buf, "%s/%s", pwd->pw_dir, file); + + if (force_check) { uid_t ruid = getuid(); gid_t egid = getegid(); - sprintf(buf, "%s/%s", pwd->pw_dir, file); - if (setregid(-1, pwd->pw_gid) == 0 && setreuid(0, pwd->pw_uid) == 0) ok = effective_access(buf, O_RDONLY) == 0; @@ -377,6 +378,15 @@ int get_hushlogin_status(struct passwd *pwd) if (ok) return 1; /* enabled by user */ } + else { + int rc; + rc = effective_access(buf, O_RDONLY); + if (rc == 0) + return 1; + else if (rc == -1 && errno == EACCES) + return -1; + } + } return 0; |