fix: env stuff

This commit is contained in:
javalsai 2024-07-16 09:21:53 +02:00
parent 0639b8601a
commit 080966978c
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8
2 changed files with 53 additions and 11 deletions

View File

@ -1,13 +1,16 @@
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <stdlib.h>
#include <security/_pam_types.h> #include <security/_pam_types.h>
#include <security/pam_appl.h> #include <security/pam_appl.h>
#include <security/pam_misc.h> #include <security/pam_misc.h>
#include <stdio.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <auth.h> #include <auth.h>
#include <stdlib.h> #include <sessions.h>
#include <ui.h> #include <ui.h>
#include <unistd.h>
int pam_conversation(int num_msg, const struct pam_message **msg, int pam_conversation(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata_ptr) { struct pam_response **resp, void *appdata_ptr) {
@ -48,9 +51,44 @@ pam_handle_t *get_pamh(char *user, char *passwd) {
return NULL; return NULL;
} }
retval = pam_setcred(pamh, PAM_ESTABLISH_CRED);
if (retval != PAM_SUCCESS) {
pam_end(pamh, retval);
return NULL;
}
retval = pam_open_session(pamh, 0);
if (retval != PAM_SUCCESS) {
pam_end(pamh, retval);
return NULL;
}
return pamh; return pamh;
} }
void moarEnv(char* user, struct session session, struct passwd *pw) {
chdir(pw->pw_dir);
setenv("HOME", pw->pw_dir, true);
setenv("USER", user, true);
setenv("LOGNAME", user, true);
char *xdg_session_type;
if(session.type == SHELL) xdg_session_type = "tty";
if(session.type == XORG) xdg_session_type = "wayland";
if(session.type == WAYLAND) xdg_session_type = "x11";
setenv("XDG_SESSION_TYPE", xdg_session_type, true);
char* buf;
size_t bsize = snprintf(NULL, 0, "/run/user/%d", pw->pw_uid);
buf = malloc(bsize);
snprintf(buf, bsize, "/run/user/%d", pw->pw_uid);
setenv("XDG_RUNTIME_DIR", buf, true);
setenv("XDG_SESSION_CLASS", "user", true);
setenv("XDG_SESSION_ID", "1", true);
/*setenv("XDG_SESSION_DESKTOP", , true);*/
setenv("XDG_SEAT", "seat0", true);
}
bool launch(char *user, char *passwd, struct session session, bool launch(char *user, char *passwd, struct session session,
void (*cb)(void)) { void (*cb)(void)) {
struct passwd *pw = getpwnam(user); struct passwd *pw = getpwnam(user);
@ -85,6 +123,9 @@ bool launch(char *user, char *passwd, struct session session,
return false; return false;
} }
if (cb != NULL)
cb();
// point of no return // point of no return
int setgrps_ret = setgroups(ngroups, groups); int setgrps_ret = setgroups(ngroups, groups);
free(groups); free(groups);
@ -103,20 +144,22 @@ bool launch(char *user, char *passwd, struct session session,
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (char **env = envlist; *env != NULL; env++) { for(uint i = 0; envlist[i] != NULL; i++) {
putenv(*env); putenv(envlist[i]);
} }
free(envlist);
moarEnv(user, session, pw);
if (cb != NULL) pam_setcred(pamh, PAM_DELETE_CRED);
cb(); pam_close_session(pamh, 0);
pam_end(pamh, PAM_SUCCESS); pam_end(pamh, PAM_SUCCESS);
if (session.type == SHELL) { if (session.type == SHELL) {
system("clear"); system("clear");
execl(session.exec, session.exec, NULL); execl(session.exec, NULL);
} else if (session.type == XORG || session.type == WAYLAND) { } else if (session.type == XORG || session.type == WAYLAND) {
system("clear"); system("clear");
execl(session.exec, session.exec, NULL); execl(session.exec, NULL);
} }
return true; return true;

View File

@ -395,10 +395,9 @@ int load(struct users_list *users, struct sessions_list *sessions) {
get_current_session(), &restore_all)) { get_current_session(), &restore_all)) {
print_passwd(box_start(), of_passwd.efield.length, true); print_passwd(box_start(), of_passwd.efield.length, true);
ffield_cursor_focus(); ffield_cursor_focus();
continue;
} }
} } else
ffield_type(seq); ffield_type(seq);
} }
if (esc != 0) if (esc != 0)