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

@ -133,10 +133,10 @@ bool launch(char *user, char *passwd, struct session session,
free(envlist); free(envlist);
moarEnv(user, session, pw); moarEnv(user, session, pw);
pam_setcred(pamh, PAM_DELETE_CRED); uint pid = fork();
pam_close_session(pamh, 0); if (pid == 0) { // child
pam_end(pamh, PAM_SUCCESS); // TODO: these will be different due to TryExec
// and, Exec/TryExec might contain spaces as args
if (session.type == SHELL) { if (session.type == SHELL) {
system("clear"); system("clear");
execlp(session.exec, session.exec, NULL); execlp(session.exec, session.exec, NULL);
@ -146,6 +146,13 @@ bool launch(char *user, char *passwd, struct session session,
} }
perror("execl error"); perror("execl error");
fprintf(stderr, "failure calling session"); 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; return true;
} }