Skip to content

Commit

Permalink
openrc-pam: create ${XDG_RUNTIME_DIR}/openrc when the var is already set
Browse files Browse the repository at this point in the history
Signed-off-by: Anna (navi) Figueiredo Gomes <[email protected]>
  • Loading branch information
navi-desu committed Jun 23, 2023
1 parent 7870d59 commit 6b5ca7e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/openrc-pam/openrc-pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 6b5ca7e

Please sign in to comment.