From 12207ee4a9ed6d0f6e313df1a48b00c4014215c2 Mon Sep 17 00:00:00 2001 From: javalsai Date: Thu, 25 Jul 2024 14:04:08 +0200 Subject: [PATCH] fix: keep pam session alive --- src/auth.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/auth.c b/src/auth.c index 7f324c6..e3f5fd1 100644 --- a/src/auth.c +++ b/src/auth.c @@ -101,11 +101,11 @@ bool launch(char *user, char *passwd, struct session session, if (cb != NULL) cb(); - if(setgid(pw->pw_gid) == -1) { + if (setgid(pw->pw_gid) == -1) { perror("setgid"); exit(EXIT_FAILURE); } - if(initgroups(user, pw->pw_gid) == -1) { + if (initgroups(user, pw->pw_gid) == -1) { perror("init groups"); exit(EXIT_FAILURE); } @@ -133,19 +133,26 @@ bool launch(char *user, char *passwd, struct session session, free(envlist); moarEnv(user, session, pw); - pam_setcred(pamh, PAM_DELETE_CRED); - pam_close_session(pamh, 0); - pam_end(pamh, PAM_SUCCESS); + uint pid = fork(); + if (pid == 0) { // child + // TODO: these will be different due to TryExec + // and, Exec/TryExec might contain spaces as args + if (session.type == SHELL) { + system("clear"); + execlp(session.exec, session.exec, NULL); + } else if (session.type == XORG || session.type == WAYLAND) { + system("clear"); + execlp(session.exec, session.exec, NULL); + } + perror("execl error"); + fprintf(stderr, "failure calling session"); + } else { + waitpid(pid, NULL, 0); - if (session.type == SHELL) { - system("clear"); - execlp(session.exec, session.exec, NULL); - } else if (session.type == XORG || session.type == WAYLAND) { - system("clear"); - execlp(session.exec, session.exec, NULL); + pam_setcred(pamh, PAM_DELETE_CRED); + pam_close_session(pamh, 0); + pam_end(pamh, PAM_SUCCESS); } - perror("execl error"); - fprintf(stderr, "failure calling session"); return true; }