diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-05-20 17:34:51 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-05-30 16:16:10 +0200 |
commit | 2520276debdc9fec1357c8f2d0ef36223a158276 (patch) | |
tree | ef4b74d312d33eb9c34d54e5faf54a338f0bf11a /unix/vncserver/vncsession.c | |
parent | c17c163e1c542b4be67cc3fc247bf5294e3896f5 (diff) | |
download | tigervnc-2520276debdc9fec1357c8f2d0ef36223a158276.tar.gz tigervnc-2520276debdc9fec1357c8f2d0ef36223a158276.zip |
Respect PAM modules for $XDG_STATE_HOME
E.g. pam_env.so might modify this variable, so we should see what we get
out of PAM when building a log file path.
Diffstat (limited to 'unix/vncserver/vncsession.c')
-rw-r--r-- | unix/vncserver/vncsession.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/unix/vncserver/vncsession.c b/unix/vncserver/vncsession.c index 3d21ae30..f1018512 100644 --- a/unix/vncserver/vncsession.c +++ b/unix/vncserver/vncsession.c @@ -259,6 +259,19 @@ stop_pam(pam_handle_t * pamh, int pamret) return pamret; } +static char * +getenvp(const char *name, char **envp) +{ + while (*envp) { + size_t varlen; + varlen = strcspn(*envp, "="); + if (strncmp(*envp, name, varlen) == 0) + return *envp + varlen + 1; + envp++; + } + return NULL; +} + static char ** prepare_environ(pam_handle_t * pamh) { @@ -387,7 +400,7 @@ mkdirrecursive(const char *dir) } static void -redir_stdio(const char *homedir, const char *display) +redir_stdio(const char *homedir, const char *display, char **envp) { int fd; long hostlen; @@ -406,7 +419,7 @@ redir_stdio(const char *homedir, const char *display) } close(fd); - xdgstate = getenv("XDG_STATE_HOME"); + xdgstate = getenvp("XDG_STATE_HOME", envp); if (xdgstate != NULL && xdgstate[0] == '/') snprintf(logfile, sizeof(logfile), "%s/tigervnc", xdgstate); else @@ -503,7 +516,7 @@ run_script(const char *username, const char *display, char **envp) close_fds(); - redir_stdio(pwent->pw_dir, display); + redir_stdio(pwent->pw_dir, display, envp); // execvpe() is not POSIX and is missing from older glibc // First clear out everything |