aboutsummaryrefslogtreecommitdiff
path: root/src/openrc-pam
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-06-23 08:02:55 -0300
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-10-19 10:56:54 +0200
commit9466109aabfcb818a5ca2d8c494acff73f34e7a4 (patch)
treedfad3d8301860db1fefc3007c432cdedfdf6b3a4 /src/openrc-pam
parentd2b65b7c93e33fb260346e7924cce23fdcef891a (diff)
openrc-pam: create ${XDG_RUNTIME_DIR}/openrc when the var is already set
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src/openrc-pam')
-rw-r--r--src/openrc-pam/openrc-pam.c29
1 files 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;