Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ AC_CHECK_HEADERS(security/pam_appl.h, [], AC_MSG_ERROR(PAM not found))

AC_CHECK_HEADERS(gcrypt.h, [], AC_MSG_ERROR(libgcrypt not found))

AC_CHECK_FUNCS(setresgid setresuid clearenv __getgroups_chk)
AC_CHECK_FUNCS(setresgid setresuid setusercontext clearenv __getgroups_chk)

PKG_CHECK_MODULES(LIGHTDM, [
glib-2.0 >= 2.44
Expand Down
36 changes: 34 additions & 2 deletions src/session-child.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <utmp.h>
#include <utmpx.h>
#include <sys/mman.h>
#if HAVE_SETUSERCONTEXT
#include <login_cap.h>
#endif

#if HAVE_LIBAUDIT
#include <libaudit.h>
Expand Down Expand Up @@ -637,6 +640,29 @@ session_child_run (int argc, char **argv)
if (setsid () < 0)
_exit (errno);

#if HAVE_SETUSERCONTEXT
/* Setup user context
* Reset the current environment to what is in the PAM context,
* then setusercontext will add to it as necessary as there is no
* option for setusercontext to add to a PAM context.
*/
extern char **environ;
environ = pam_getenvlist (pam_handle);
struct passwd* pwd = getpwnam (username);
if (pwd) {
if (setusercontext (NULL, pwd, pwd->pw_uid, LOGIN_SETALL) < 0) {
int _errno = errno;
fprintf(stderr, "setusercontext for \"%s\" (%d) failed: %s\n",
username, user_get_uid (user), strerror (errno));
_exit (_errno);
}
endpwent();
} else {
fprintf (stderr, "getpwname for \"%s\" failed: %s\n",
username, strerror (errno));
_exit (ENOENT);
}
#else
/* Change to this user */
if (getuid () == 0)
{
Expand All @@ -646,7 +672,7 @@ session_child_run (int argc, char **argv)
if (setuid (uid) != 0)
_exit (errno);
}

#endif
/* Change working directory */
/* NOTE: This must be done after the permissions are changed because NFS filesystems can
* be setup so the local root user accesses the NFS files as 'nobody'. If the home directories
Expand All @@ -668,7 +694,13 @@ session_child_run (int argc, char **argv)
signal (SIGPIPE, SIG_DFL);

/* Run the command */
execve (command_argv[0], command_argv, pam_getenvlist (pam_handle));
execve (command_argv[0], command_argv,
#if HAVE_SETUSERCONTEXT
environ
#else
pam_getenvlist (pam_handle)
#endif
);
_exit (EXIT_FAILURE);
}

Expand Down