fix: keep pam session alive

This commit is contained in:
javalsai 2024-07-25 14:04:08 +02:00
parent e8ec94e150
commit 12207ee4a9
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8

View File

@ -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,10 +133,10 @@ 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);
@ -146,6 +146,13 @@ bool launch(char *user, char *passwd, struct session session,
}
perror("execl error");
fprintf(stderr, "failure calling session");
} else {
waitpid(pid, NULL, 0);
pam_setcred(pamh, PAM_DELETE_CRED);
pam_close_session(pamh, 0);
pam_end(pamh, PAM_SUCCESS);
}
return true;
}