From 9466109aabfcb818a5ca2d8c494acff73f34e7a4 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Fri, 23 Jun 2023 08:02:55 -0300 Subject: openrc-pam: create ${XDG_RUNTIME_DIR}/openrc when the var is already set Signed-off-by: Anna (navi) Figueiredo Gomes --- src/openrc-pam/openrc-pam.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/openrc-pam/openrc-pam.c b/src/openrc-pam/openrc-pam.c index a9feadcb..2a66ab4a 100644 --- a/src/openrc-pam/openrc-pam.c +++ b/src/openrc-pam/openrc-pam.c @@ -165,7 +165,6 @@ exec_user_cmd(struct passwd *pw, char *cmd, char **envlist) static char *create_xdg_runtime_dir(struct passwd *pw) { char *path = NULL; - char *openrc_path = NULL; if (mkdir("/run/user", 0755) != 0 && errno != EEXIST) return NULL; @@ -182,20 +181,6 @@ static char *create_xdg_runtime_dir(struct passwd *pw) { return NULL; } - xasprintf(&openrc_path, "%s/%s", path, "openrc"); - - if (mkdir(openrc_path, 0700) != 0 && errno != EEXIST) { - free(openrc_path); - free(path); - return NULL; - } - - if (chown(openrc_path, pw->pw_uid, pw->pw_gid) != 0) { - free(openrc_path); - free(path); - return NULL; - } - return path; } @@ -206,6 +191,7 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) { struct passwd *pw = NULL; char *xdg_runtime_dir; char *xdg_runtime_dir_env; + char *openrc_runtime_dir; char **envlist; char **env; @@ -230,6 +216,18 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) { free(xdg_runtime_dir_env); } + xasprintf(&openrc_runtime_dir, "%s/%s", pam_getenv(pamh, "XDG_RUNTIME_DIR"), "openrc"); + + if (mkdir(openrc_runtime_dir, 0700) != 0 && errno != EEXIST) { + free(openrc_runtime_dir); + return false; + } + + if (chown(openrc_runtime_dir, pw->pw_uid, pw->pw_gid) != 0) { + free(openrc_runtime_dir); + return false; + } + envlist = pam_getenvlist(pamh); xasprintf(&cmd, "openrc --user %s", runlevel); @@ -250,6 +248,7 @@ static bool exec_openrc(pam_handle_t *pamh, const char *runlevel, bool lock) { for (env = envlist; *env; env++) free(*env); + free(openrc_runtime_dir); free(envlist); free(cmd); return true; -- cgit v1.2.3