teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0197-pam-do-not-set-XDG_RUNTIME_DIR-unconditionally.patch

65878a
From 281100560056e06f69d2cdb4dcc854bd3717734f Mon Sep 17 00:00:00 2001
65878a
From: Michal Sekletar <msekleta@redhat.com>
65878a
Date: Mon, 10 Feb 2014 17:41:32 +0100
65878a
Subject: [PATCH] pam: do not set XDG_RUNTIME_DIR unconditionally
65878a
65878a
If the session's original user is not the same as the newly logged in one we
65878a
will not set XDG_RUNTIME_DIR.
65878a
65878a
Patch based on upstream commit baae0358f349870544884e405e82e4be7d8add9f
65878a
---
65878a
 src/login/logind-dbus.c         |  2 ++
65878a
 src/login/logind-session-dbus.c |  1 +
65878a
 src/login/pam-module.c          | 52 ++++++++++++++++++++---------------------
65878a
 3 files changed, 29 insertions(+), 26 deletions(-)
65878a
65878a
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
65878a
index bb85c7d..69e94aa 100644
65878a
--- a/src/login/logind-dbus.c
65878a
+++ b/src/login/logind-dbus.c
65878a
@@ -90,6 +90,7 @@
65878a
         "   <arg name=\"path\" type=\"o\" direction=\"out\"/>\n"        \
65878a
         "   <arg name=\"runtime_path\" type=\"o\" direction=\"out\"/>\n" \
65878a
         "   <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n"          \
65878a
+        "   <arg name=\"uid\" type=\"u\" direction=\"out\"/>\n"         \
65878a
         "   <arg name=\"seat\" type=\"s\" direction=\"out\"/>\n"        \
65878a
         "   <arg name=\"vtnr\" type=\"u\" direction=\"out\"/>\n"        \
65878a
         "   <arg name=\"existing\" type=\"b\" direction=\"out\"/>\n"    \
65878a
@@ -523,6 +524,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message) {
65878a
                                 DBUS_TYPE_OBJECT_PATH, &path,
65878a
                                 DBUS_TYPE_STRING, &session->user->runtime_path,
65878a
                                 DBUS_TYPE_UNIX_FD, &fifo_fd,
65878a
+                                DBUS_TYPE_UINT32, &session->user->uid,
65878a
                                 DBUS_TYPE_STRING, &cseat,
65878a
                                 DBUS_TYPE_UINT32, &vtnr,
65878a
                                 DBUS_TYPE_BOOLEAN, &exists,
65878a
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
65878a
index be4e01c..86b0746 100644
65878a
--- a/src/login/logind-session-dbus.c
65878a
+++ b/src/login/logind-session-dbus.c
65878a
@@ -755,6 +755,7 @@ int session_send_create_reply(Session *s, DBusError *error) {
65878a
                                     DBUS_TYPE_OBJECT_PATH, &path,
65878a
                                     DBUS_TYPE_STRING, &s->user->runtime_path,
65878a
                                     DBUS_TYPE_UNIX_FD, &fifo_fd,
65878a
+                                    DBUS_TYPE_UINT32, &s->user->uid,
65878a
                                     DBUS_TYPE_STRING, &cseat,
65878a
                                     DBUS_TYPE_UINT32, &vtnr,
65878a
                                     DBUS_TYPE_BOOLEAN, &exists,
65878a
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
65878a
index 02f1618..22d9733 100644
65878a
--- a/src/login/pam-module.c
65878a
+++ b/src/login/pam-module.c
65878a
@@ -86,31 +86,24 @@ static int get_user_data(
65878a
 
65878a
         const char *username = NULL;
65878a
         struct passwd *pw = NULL;
65878a
-        uid_t uid;
65878a
         int r;
65878a
 
65878a
         assert(handle);
65878a
         assert(ret_username);
65878a
         assert(ret_pw);
65878a
 
65878a
-        r = audit_loginuid_from_pid(0, &uid);
65878a
-        if (r >= 0)
65878a
-                pw = pam_modutil_getpwuid(handle, uid);
65878a
-        else {
65878a
-                r = pam_get_user(handle, &username, NULL);
65878a
-                if (r != PAM_SUCCESS) {
65878a
-                        pam_syslog(handle, LOG_ERR, "Failed to get user name.");
65878a
-                        return r;
65878a
-                }
65878a
-
65878a
-                if (isempty(username)) {
65878a
-                        pam_syslog(handle, LOG_ERR, "User name not valid.");
65878a
-                        return PAM_AUTH_ERR;
65878a
-                }
65878a
+        r = pam_get_user(handle, &username, NULL);
65878a
+        if (r != PAM_SUCCESS) {
65878a
+                pam_syslog(handle, LOG_ERR, "Failed to get user name.");
65878a
+                return r;
65878a
+        }
65878a
 
65878a
-                pw = pam_modutil_getpwnam(handle, username);
65878a
+        if (isempty(username)) {
65878a
+                pam_syslog(handle, LOG_ERR, "User name not valid.");
65878a
+                return PAM_AUTH_ERR;
65878a
         }
65878a
 
65878a
+        pw = pam_modutil_getpwnam(handle, username);
65878a
         if (!pw) {
65878a
                 pam_syslog(handle, LOG_ERR, "Failed to get user data.");
65878a
                 return PAM_USER_UNKNOWN;
65878a
@@ -123,16 +116,14 @@ static int get_user_data(
65878a
 }
65878a
 
65878a
 static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) {
65878a
-        _cleanup_free_ char *p = NULL;
65878a
-        int r;
65878a
+        _cleanup_free_ char *p = NULL, *tty=NULL;
65878a
         _cleanup_close_ int fd = -1;
65878a
         union sockaddr_union sa = {
65878a
                 .un.sun_family = AF_UNIX,
65878a
         };
65878a
         struct ucred ucred;
65878a
         socklen_t l;
65878a
-        _cleanup_free_ char *tty = NULL;
65878a
-        int v;
65878a
+        int v, r;
65878a
 
65878a
         assert(display);
65878a
         assert(vtnr);
65878a
@@ -186,14 +177,14 @@ _public_ PAM_EXTERN int pam_sm_open_session(
65878a
         bool debug = false;
65878a
         const char *username, *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type = NULL, *class = NULL, *class_pam = NULL, *cvtnr = NULL;
65878a
         DBusError error;
65878a
-        uint32_t uid, pid;
65878a
         DBusMessageIter iter;
65878a
         int session_fd = -1;
65878a
         DBusConnection *bus = NULL;
65878a
         DBusMessage *m = NULL, *reply = NULL;
65878a
         dbus_bool_t remote, existing;
65878a
         int r;
65878a
-        uint32_t vtnr = 0;
65878a
+        uint32_t uid, pid, vtnr = 0;
65878a
+        uid_t original_uid;
65878a
 
65878a
         assert(handle);
65878a
 
65878a
@@ -389,6 +380,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
65878a
                                    DBUS_TYPE_OBJECT_PATH, &object_path,
65878a
                                    DBUS_TYPE_STRING, &runtime_path,
65878a
                                    DBUS_TYPE_UNIX_FD, &session_fd,
65878a
+                                   DBUS_TYPE_UINT32, &original_uid,
65878a
                                    DBUS_TYPE_STRING, &seat,
65878a
                                    DBUS_TYPE_UINT32, &vtnr,
65878a
                                    DBUS_TYPE_BOOLEAN, &existing,
65878a
@@ -409,10 +401,18 @@ _public_ PAM_EXTERN int pam_sm_open_session(
65878a
                 goto finish;
65878a
         }
65878a
 
65878a
-        r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", runtime_path, 0);
65878a
-        if (r != PAM_SUCCESS) {
65878a
-                pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
65878a
-                goto finish;
65878a
+        if (original_uid == pw->pw_uid) {
65878a
+               /* Don't set $XDG_RUNTIME_DIR if the user we now
65878a
+                * authenticated for does not match the original user
65878a
+                * of the session. We do this in order not to result
65878a
+                * in privileged apps clobbering the runtime directory
65878a
+                * unnecessarily. */
65878a
+
65878a
+                r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", runtime_path, 0);
65878a
+                if (r != PAM_SUCCESS) {
65878a
+                        pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
65878a
+                        return r;
65878a
+                }
65878a
         }
65878a
 
65878a
         if (!isempty(seat)) {