diff options
author | Steve Langasek <vorlon@debian.org> | 2003-07-13 06:34:15 +0000 |
---|---|---|
committer | Steve Langasek <vorlon@debian.org> | 2003-07-13 06:34:15 +0000 |
commit | a6562ebb2728c6493f3bdd6e2d5505dd9f962fe3 (patch) | |
tree | 0c6065f271a38666e6867dc6531ec4718dd5cd38 | |
parent | f0bc1227ecb8b29522bc09f09573ccd851b64cec (diff) | |
download | pam-a6562ebb2728c6493f3bdd6e2d5505dd9f962fe3.tar.gz pam-a6562ebb2728c6493f3bdd6e2d5505dd9f962fe3.tar.bz2 pam-a6562ebb2728c6493f3bdd6e2d5505dd9f962fe3.zip |
Relevant BUGIDs: patch 476976
Purpose of commit: bugfix
Commit summary:
---------------
Patch from Nalin Dahyabhai: when updating /etc/{passwd,shadow}, always
respect any admin-specified permissions on the existing files.
-rw-r--r-- | modules/pam_unix/pam_unix_passwd.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/modules/pam_unix/pam_unix_passwd.c b/modules/pam_unix/pam_unix_passwd.c index b5758080..4320171c 100644 --- a/modules/pam_unix/pam_unix_passwd.c +++ b/modules/pam_unix/pam_unix_passwd.c @@ -347,6 +347,7 @@ static int _update_passwd(pam_handle_t *pamh, const char *forwho, const char *towhat) { struct passwd *tmpent = NULL; + struct stat st; FILE *pwfile, *opwfile; int err = 1; int oldmask; @@ -364,8 +365,13 @@ static int _update_passwd(pam_handle_t *pamh, return PAM_AUTHTOK_ERR; } - chown(PW_TMPFILE, 0, 0); - chmod(PW_TMPFILE, 0644); + if (fstat(fileno(opwfile), &st) == -1) { + chown(PW_TMPFILE, 0, 0); + chmod(PW_TMPFILE, 0644); + } else { + chown(PW_TMPFILE, st.st_uid, st.st_gid); + chmod(PW_TMPFILE, st.st_mode); + } tmpent = fgetpwent(opwfile); while (tmpent) { if (!strcmp(tmpent->pw_name, forwho)) { @@ -406,6 +412,7 @@ static int _update_passwd(pam_handle_t *pamh, static int _update_shadow(const char *forwho, char *towhat) { struct spwd *spwdent = NULL, *stmpent = NULL; + struct stat st; FILE *pwfile, *opwfile; int err = 1; int oldmask; @@ -427,8 +434,13 @@ static int _update_shadow(const char *forwho, char *towhat) return PAM_AUTHTOK_ERR; } - chown(SH_TMPFILE, 0, 0); - chmod(SH_TMPFILE, 0600); + if (fstat(fileno(opwfile), &st) == -1) { + chown(SH_TMPFILE, 0, 0); + chmod(SH_TMPFILE, 0600); + } else { + chown(SH_TMPFILE, st.st_uid, st.st_gid); + chmod(SH_TMPFILE, st.st_mode); + } stmpent = fgetspent(opwfile); while (stmpent) { |