diff --git a/pam_yubico.c b/pam_yubico.c index b1934361..b49d5c26 100644 --- a/pam_yubico.c +++ b/pam_yubico.c @@ -616,10 +616,14 @@ do_challenge_response(pam_handle_t *pamh, struct cfg *cfg, const char *username) goto restpriv_out; } - if (fchmod (fd, S_IRUSR | S_IWUSR) != 0) { + if (fchmod (fd, st.st_mode) != 0) { DBG (("could not set correct file permissions")); goto restpriv_out; } + if (fchown (fd, st.st_uid, st.st_gid) != 0) { + DBG (("could not set correct file ownership")); + goto restpriv_out; + } f = fdopen(fd, "w"); if (! f) {