From 9cf828e1c103ae260a056e7c335f4638c9add7b1 Mon Sep 17 00:00:00 2001
From: Dudemanguy <dudemanguy@artixlinux.org>
Date: Sat, 18 Sep 2021 09:58:46 -0500
Subject: [PATCH] fix group permissions of the user folders

When making a directory, the user was correctly given ownership but the
group was still root. In elogind (and likely system-logind), these
folders are owned by user:user. Fix this by also setting the egid to
the user's group.
---
 pam_rundir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch-Source: https://gitea.artixlinux.org/artix/pam_rundir/commit/9cf828e1c103ae260a056e7c335f4638c9add7b1

diff --git a/pam_rundir.c b/pam_rundir.c
index d36584d..f92c73e 100644
--- a/pam_rundir.c
+++ b/pam_rundir.c
@@ -404,8 +404,8 @@
         secbits = prctl (PR_GET_SECUREBITS);
         if (secbits != -1)
             prctl (PR_SET_SECUREBITS, (unsigned long) secbits | SECBIT_NO_SETUID_FIXUP);
-        /* set euid so if we do create the dir, it is own by the user */
-        if (seteuid (pw->pw_uid) < 0)
+        /* set euid and egid so if we do create the dir, it is owned by the user */
+        if (seteuid (pw->pw_uid) < 0 || setegid (pw->pw_gid) < 0)
         {
             r = -1;
             goto done;
@@ -422,7 +422,7 @@
             pam_putenv (pamh, buf);
         }
         /* restore */
-        if (seteuid (0) < 0)
+        if (seteuid (0) < 0 || setegid (0) < 0)
         {
             r = -1;
             goto done;
