From 249a920b64f87217b8ba5f9b0b3f1bacdd1e189f Mon Sep 17 00:00:00 2001 From: Naomi Calabretta Date: Fri, 16 Jun 2023 00:42:13 +0200 Subject: 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 --- src/openrc-pam/openrc-pam.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3