diff options
author | Naomi Calabretta <nyaomicalabretta@gmail.com> | 2023-06-16 00:42:13 +0200 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-10-19 10:56:54 +0200 |
commit | 249a920b64f87217b8ba5f9b0b3f1bacdd1e189f (patch) | |
tree | ebea9173354e8ab08907786810302b191c22d185 | |
parent | 2ce0f9de5e4da32eca0d217889a4a62f79feacd1 (diff) |
openrc-pam: Use the entire PAM environment
Using whatever is left by the root user causes some login shells
(such as Zsh on Artix Linux) to only load `/etc/profile{.d/*}`
and not the user-defined `~/.profile`. This is not ideal as we
rely on the user to tell us where some paths, such as
`$XDG_CONFIG_PATH` and `$XDG_CACHE_PATH`, are.
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
-rw-r--r-- | src/openrc-pam/openrc-pam.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/openrc-pam/openrc-pam.c b/src/openrc-pam/openrc-pam.c index f3ab710c..51dafb17 100644 --- a/src/openrc-pam/openrc-pam.c +++ b/src/openrc-pam/openrc-pam.c @@ -13,10 +13,10 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel) { char *cmd = NULL; const char *username; struct passwd *pw = NULL; - const char *env = NULL; + char **envlist; + char **env; - if ((env = pam_getenv(pamh, "XDG_RUNTIME_DIR")) != NULL) - setenv("XDG_RUNTIME_DIR", env, 0); + envlist = pam_getenvlist(pamh); if (pam_get_user(pamh, &username, "username:") != PAM_SUCCESS) return false; @@ -32,7 +32,7 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel) { setgid(pw->pw_gid); setuid(pw->pw_uid); - execl(pw->pw_shell, "-", "-c", cmd, NULL); + execle(pw->pw_shell, "-", "-c", cmd, NULL, envlist); free(cmd); return false; @@ -43,6 +43,10 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel) { break; } wait(NULL); + + for (env = envlist; *env; env++) + free(*env); + free(envlist); free(cmd); return true; } |