const char *forwho, const char *towhat)
{
struct passwd *tmpent = NULL;
+ struct stat st;
FILE *pwfile, *opwfile;
int err = 1;
int oldmask;
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)) {
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;
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) {