diff options
author | Darren Tucker <dtucker@zip.com.au> | 2013-11-20 09:43:50 +0100 |
---|---|---|
committer | Tomas Mraz <tmraz@fedoraproject.org> | 2013-11-20 09:43:50 +0100 |
commit | 45cdd2489e68465c2d2202370c350069d2a391b8 (patch) | |
tree | a90f3b246d878ffe184a48ebf0f50dea8206c462 /modules | |
parent | 5865f521f37846634f981582eaedad81abb08104 (diff) | |
download | pam-45cdd2489e68465c2d2202370c350069d2a391b8.tar.gz pam-45cdd2489e68465c2d2202370c350069d2a391b8.tar.bz2 pam-45cdd2489e68465c2d2202370c350069d2a391b8.zip |
If the correct loginuid is set already, skip writing it.
modules/pam_loginuid/pam_loginuid.c (set_loginuid): Read the current loginuid
and skip writing if already correctly set.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pam_loginuid/pam_loginuid.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/modules/pam_loginuid/pam_loginuid.c b/modules/pam_loginuid/pam_loginuid.c index 06479973..a903845c 100644 --- a/modules/pam_loginuid/pam_loginuid.c +++ b/modules/pam_loginuid/pam_loginuid.c @@ -52,10 +52,10 @@ static int set_loginuid(pam_handle_t *pamh, uid_t uid) { int fd, count, rc = 0; - char loginuid[24]; + char loginuid[24], buf[24]; count = snprintf(loginuid, sizeof(loginuid), "%lu", (unsigned long)uid); - fd = open("/proc/self/loginuid", O_NOFOLLOW|O_WRONLY|O_TRUNC); + fd = open("/proc/self/loginuid", O_NOFOLLOW|O_RDWR); if (fd < 0) { if (errno != ENOENT) { rc = 1; @@ -64,8 +64,13 @@ static int set_loginuid(pam_handle_t *pamh, uid_t uid) } return rc; } - if (pam_modutil_write(fd, loginuid, count) != count) + if (pam_modutil_read(fd, buf, sizeof(buf)) == count && + memcmp(buf, loginuid, count) == 0) + goto done; /* already correct */ + if (lseek(fd, 0, SEEK_SET) == -1 || (ftruncate(fd, 0) == -1 || + pam_modutil_write(fd, loginuid, count) != count)) rc = 1; + done: close(fd); return rc; } |