summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/pam_xauth/pam_xauth.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/modules/pam_xauth/pam_xauth.c b/modules/pam_xauth/pam_xauth.c
index 0a94db4f..61bd5a91 100644
--- a/modules/pam_xauth/pam_xauth.c
+++ b/modules/pam_xauth/pam_xauth.c
@@ -555,7 +555,7 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
/* Generate a new file to hold the data. */
euid = geteuid();
setfsuid(tpwd->pw_uid);
-
+
#ifdef WITH_SELINUX
if (is_selinux_enabled() > 0) {
struct selabel_handle *ctx = selabel_open(SELABEL_CTX_FILE, NULL, 0);
@@ -595,8 +595,10 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
}
/* Set permissions on the new file and dispose of the
* descriptor. */
+ setfsuid(tpwd->pw_uid);
if (fchown(fd, tpwd->pw_uid, tpwd->pw_gid) < 0)
pam_syslog (pamh, LOG_ERR, "fchown: %m");
+ setfsuid(euid);
close(fd);
/* Get a copy of the filename to save as a data item for
@@ -693,6 +695,20 @@ pam_sm_close_session (pam_handle_t *pamh, int flags UNUSED,
{
void *cookiefile;
int i, debug = 0;
+ const char* user;
+ struct passwd *tpwd;
+ uid_t unlinkuid, euid;
+ unlinkuid = euid = geteuid ();
+
+ if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS)
+ pam_syslog(pamh, LOG_ERR, "error determining target user's name");
+ else {
+ tpwd = pam_modutil_getpwnam(pamh, user);
+ if (!tpwd)
+ pam_syslog(pamh, LOG_ERR, "error determining target user's UID");
+ else
+ unlinkuid = tpwd->pw_uid;
+ }
/* Parse arguments. We don't understand many, so no sense in breaking
* this into a separate function. */
@@ -723,7 +739,10 @@ pam_sm_close_session (pam_handle_t *pamh, int flags UNUSED,
pam_syslog(pamh, LOG_DEBUG, "removing `%s'",
(char*)cookiefile);
}
+ /* NFS with root_squash requires non-root user */
+ setfsuid (unlinkuid);
unlink((char*)cookiefile);
+ setfsuid (euid);
*((char*)cookiefile) = '\0';
}
}