Blame SOURCES/0001-manager-allow-multiple-xdmcp-logins-for-the-same-use.patch

797f26
From 37fd7d17cff85440fdeaff95a88f341c10ce5211 Mon Sep 17 00:00:00 2001
f66be3
From: rpm-build <rpm-build>
f66be3
Date: Thu, 20 Dec 2018 14:51:38 -0500
f66be3
Subject: [PATCH] manager: allow multiple xdmcp logins for the same user
f66be3
f66be3
---
f66be3
 common/gdm-settings-keys.h |  1 +
797f26
 daemon/gdm-manager.c       | 71 ++++++++++++++++++++++++++++----------
797f26
 data/gdm.schemas.in.in     |  5 +++
797f26
 3 files changed, 59 insertions(+), 18 deletions(-)
f66be3
f66be3
diff --git a/common/gdm-settings-keys.h b/common/gdm-settings-keys.h
797f26
index f0059b5cf..6113a625b 100644
f66be3
--- a/common/gdm-settings-keys.h
f66be3
+++ b/common/gdm-settings-keys.h
797f26
@@ -28,37 +28,38 @@ G_BEGIN_DECLS
797f26
 #define GDM_KEY_USER "daemon/User"
797f26
 #define GDM_KEY_GROUP "daemon/Group"
797f26
 #define GDM_KEY_AUTO_LOGIN_ENABLE "daemon/AutomaticLoginEnable"
797f26
 #define GDM_KEY_AUTO_LOGIN_USER "daemon/AutomaticLogin"
797f26
 #define GDM_KEY_TIMED_LOGIN_ENABLE "daemon/TimedLoginEnable"
797f26
 #define GDM_KEY_TIMED_LOGIN_USER "daemon/TimedLogin"
797f26
 #define GDM_KEY_TIMED_LOGIN_DELAY "daemon/TimedLoginDelay"
797f26
 #define GDM_KEY_INITIAL_SETUP_ENABLE "daemon/InitialSetupEnable"
797f26
 #define GDM_KEY_WAYLAND_ENABLE "daemon/WaylandEnable"
797f26
 
797f26
 #define GDM_KEY_DEBUG "debug/Enable"
797f26
 
797f26
 #define GDM_KEY_INCLUDE "greeter/Include"
797f26
 #define GDM_KEY_EXCLUDE "greeter/Exclude"
797f26
 #define GDM_KEY_INCLUDE_ALL "greeter/IncludeAll"
797f26
 
797f26
 #define GDM_KEY_DISALLOW_TCP "security/DisallowTCP"
797f26
 #define GDM_KEY_ALLOW_REMOTE_AUTOLOGIN "security/AllowRemoteAutoLogin"
797f26
 
797f26
 #define GDM_KEY_XDMCP_ENABLE "xdmcp/Enable"
797f26
 #define GDM_KEY_SHOW_LOCAL_GREETER "xdmcp/ShowLocalGreeter"
797f26
 #define GDM_KEY_MAX_PENDING "xdmcp/MaxPending"
797f26
 #define GDM_KEY_MAX_SESSIONS "xdmcp/MaxSessions"
797f26
 #define GDM_KEY_MAX_WAIT "xdmcp/MaxWait"
797f26
 #define GDM_KEY_DISPLAYS_PER_HOST "xdmcp/DisplaysPerHost"
797f26
 #define GDM_KEY_UDP_PORT "xdmcp/Port"
797f26
 #define GDM_KEY_INDIRECT "xdmcp/HonorIndirect"
f66be3
 #define GDM_KEY_MAX_WAIT_INDIRECT "xdmcp/MaxWaitIndirect"
f66be3
 #define GDM_KEY_PING_INTERVAL "xdmcp/PingIntervalSeconds"
f66be3
 #define GDM_KEY_WILLING "xdmcp/Willing"
f66be3
+#define GDM_KEY_ALLOW_MULTIPLE_SESSIONS_PER_USER "xdmcp/AllowMultipleSessionsPerUser"
f66be3
 
f66be3
 #define GDM_KEY_MULTICAST "chooser/Multicast"
f66be3
 #define GDM_KEY_MULTICAST_ADDR "chooser/MulticastAddr"
797f26
 
797f26
 G_END_DECLS
797f26
 
797f26
 #endif /* _GDM_SETTINGS_KEYS_H */
f66be3
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
797f26
index 031c61ce6..a24d7614d 100644
f66be3
--- a/daemon/gdm-manager.c
f66be3
+++ b/daemon/gdm-manager.c
797f26
@@ -577,93 +577,106 @@ get_display_and_details_for_bus_sender (GdmManager       *self,
797f26
         if (out_tty != NULL) {
797f26
                 *out_tty = get_tty_for_session_id (session_id, &error);
797f26
 
797f26
                 if (error != NULL) {
797f26
                         g_debug ("GdmManager: Error while retrieving tty for session: %s",
797f26
                                  error->message);
797f26
                         g_clear_error (&error);
797f26
                 }
797f26
         }
797f26
 
797f26
         display = gdm_display_store_find (self->priv->display_store,
797f26
                                           lookup_by_session_id,
797f26
                                           (gpointer) session_id);
797f26
 
797f26
         if (out_display != NULL) {
797f26
                 *out_display = display;
797f26
         }
797f26
 out:
797f26
         g_free (session_id);
797f26
 }
797f26
 
797f26
 static gboolean
797f26
 switch_to_compatible_user_session (GdmManager *manager,
797f26
                                    GdmSession *session,
797f26
                                    gboolean    fail_if_already_switched)
797f26
 {
797f26
         gboolean    res;
797f26
         gboolean    ret;
797f26
         const char *username;
797f26
         const char *seat_id;
797f26
-        const char *ssid_to_activate;
797f26
+        const char *ssid_to_activate = NULL;
797f26
         GdmSession *existing_session;
797f26
 
797f26
         ret = FALSE;
797f26
 
f66be3
         username = gdm_session_get_username (session);
f66be3
         seat_id = gdm_session_get_display_seat_id (session);
f66be3
 
797f26
-        if (!fail_if_already_switched) {
797f26
-                session = NULL;
797f26
-        }
797f26
+        if (!fail_if_already_switched)
797f26
+                ssid_to_activate = gdm_session_get_session_id (session);
797f26
 
797f26
-        existing_session = find_session_for_user_on_seat (manager, username, seat_id, session);
797f26
+        if (ssid_to_activate == NULL) {
797f26
+                if (!seat_id || !sd_seat_can_multi_session (seat_id)) {
797f26
+                        g_debug ("GdmManager: unable to activate existing sessions from login screen unless on seat0");
797f26
+                        goto out;
797f26
+                }
797f26
 
797f26
-        if (existing_session != NULL) {
797f26
-                ssid_to_activate = gdm_session_get_session_id (existing_session);
797f26
-                if (seat_id != NULL) {
797f26
-                        res = activate_session_id (manager, seat_id, ssid_to_activate);
797f26
-                        if (! res) {
797f26
-                                g_debug ("GdmManager: unable to activate session: %s", ssid_to_activate);
797f26
-                                goto out;
797f26
-                        }
797f26
+                if (!fail_if_already_switched) {
797f26
+                        session = NULL;
797f26
                 }
797f26
 
797f26
-                res = session_unlock (manager, ssid_to_activate);
797f26
-                if (!res) {
797f26
-                        /* this isn't fatal */
797f26
-                        g_debug ("GdmManager: unable to unlock session: %s", ssid_to_activate);
797f26
+                existing_session = find_session_for_user_on_seat (manager, username, seat_id, session);
797f26
+
797f26
+                if (existing_session != NULL) {
797f26
+                        ssid_to_activate = gdm_session_get_session_id (existing_session);
797f26
                 }
797f26
-        } else {
f66be3
+        }
f66be3
+
797f26
+        if (ssid_to_activate == NULL) {
797f26
                 goto out;
f66be3
         }
797f26
 
797f26
+        if (seat_id != NULL) {
797f26
+                res = activate_session_id (manager, seat_id, ssid_to_activate);
797f26
+                if (! res) {
797f26
+                        g_debug ("GdmManager: unable to activate session: %s", ssid_to_activate);
797f26
+                        goto out;
797f26
+                }
797f26
+        }
797f26
+
797f26
+        res = session_unlock (manager, ssid_to_activate);
797f26
+        if (!res) {
797f26
+                /* this isn't fatal */
797f26
+                g_debug ("GdmManager: unable to unlock session: %s", ssid_to_activate);
797f26
+        }
797f26
+
797f26
         ret = TRUE;
797f26
 
797f26
  out:
797f26
         return ret;
797f26
 }
797f26
 
797f26
 static GdmDisplay *
797f26
 get_display_for_user_session (GdmSession *session)
797f26
 {
797f26
         return g_object_get_data (G_OBJECT (session), "gdm-display");
797f26
 }
797f26
 
797f26
 static GdmSession *
797f26
 get_user_session_for_display (GdmDisplay *display)
797f26
 {
797f26
         if (display == NULL) {
797f26
                 return NULL;
797f26
         }
797f26
 
797f26
         return g_object_get_data (G_OBJECT (display), "gdm-user-session");
f66be3
 }
f66be3
 
f66be3
 static gboolean
797f26
 add_session_record (GdmManager    *manager,
797f26
                     GdmSession    *session,
797f26
                     GPid           pid,
797f26
                     SessionRecord  record)
797f26
 {
797f26
         const char *username;
797f26
         char *display_name, *hostname, *display_device;
797f26
@@ -1063,92 +1076,114 @@ open_temporary_reauthentication_channel (GdmManager            *self,
797f26
         g_signal_connect (session,
797f26
                           "client-disconnected",
797f26
                           G_CALLBACK (on_reauthentication_client_disconnected),
797f26
                           self);
797f26
         g_signal_connect (session,
797f26
                           "client-rejected",
797f26
                           G_CALLBACK (on_reauthentication_client_rejected),
797f26
                           self);
797f26
         g_signal_connect (session,
797f26
                           "cancelled",
797f26
                           G_CALLBACK (on_reauthentication_cancelled),
797f26
                           self);
797f26
         g_signal_connect (session,
797f26
                           "conversation-started",
797f26
                           G_CALLBACK (on_reauthentication_conversation_started),
797f26
                           self);
797f26
         g_signal_connect (session,
797f26
                           "conversation-stopped",
797f26
                           G_CALLBACK (on_reauthentication_conversation_stopped),
797f26
                           self);
797f26
         g_signal_connect (session,
797f26
                           "verification-complete",
797f26
                           G_CALLBACK (on_reauthentication_verification_complete),
797f26
                           self);
797f26
 
797f26
         address = gdm_session_get_server_address (session);
797f26
 
797f26
         return g_strdup (address);
797f26
 }
797f26
 
797f26
+static gboolean
f66be3
+remote_users_can_log_in_more_than_once (GdmManager *manager)
f66be3
+{
f66be3
+        gboolean enabled;
f66be3
+
f66be3
+        enabled = FALSE;
f66be3
+
f66be3
+        gdm_settings_direct_get_boolean (GDM_KEY_ALLOW_MULTIPLE_SESSIONS_PER_USER, &enabled);
f66be3
+
f66be3
+	g_debug ("GdmDisplay: Remote users allowed to log in more than once: %s", enabled? "yes" : "no");
f66be3
+
f66be3
+        return enabled;
f66be3
+}
f66be3
+
797f26
 static gboolean
f66be3
 gdm_manager_handle_open_reauthentication_channel (GdmDBusManager        *manager,
f66be3
                                                   GDBusMethodInvocation *invocation,
f66be3
                                                   const char            *username)
797f26
 {
797f26
         GdmManager       *self = GDM_MANAGER (manager);
797f26
         const char       *sender;
797f26
         GdmDisplay       *display = NULL;
797f26
         GdmSession       *session;
797f26
         GDBusConnection  *connection;
797f26
         char             *seat_id = NULL;
797f26
         char             *session_id = NULL;
797f26
         GPid              pid = 0;
797f26
         uid_t             uid = (uid_t) -1;
797f26
         gboolean          is_login_screen = FALSE;
797f26
         gboolean          is_remote = FALSE;
797f26
 
797f26
         g_debug ("GdmManager: trying to open reauthentication channel for user %s", username);
797f26
 
797f26
         sender = g_dbus_method_invocation_get_sender (invocation);
797f26
         connection = g_dbus_method_invocation_get_connection (invocation);
797f26
         get_display_and_details_for_bus_sender (self, connection, sender, &display, &seat_id, &session_id, NULL, &pid, &uid, &is_login_screen, &is_remote);
797f26
 
797f26
         if (session_id == NULL || pid == 0 || uid == (uid_t) -1) {
797f26
                 g_dbus_method_invocation_return_error_literal (invocation,
797f26
                                                                G_DBUS_ERROR,
797f26
                                                                G_DBUS_ERROR_ACCESS_DENIED,
797f26
                                                                _("No session available"));
797f26
 
f66be3
                 return TRUE;
f66be3
         }
f66be3
 
f66be3
+        if (is_login_screen && is_remote && remote_users_can_log_in_more_than_once (self)) {
f66be3
+                g_dbus_method_invocation_return_error_literal (invocation,
f66be3
+                                                               G_DBUS_ERROR,
f66be3
+                                                               G_DBUS_ERROR_ACCESS_DENIED,
f66be3
+                                                               "Login screen creates new sessions for remote connections");
f66be3
+		return TRUE;
f66be3
+        }
f66be3
+
f66be3
         if (is_login_screen) {
f66be3
                 session = find_session_for_user_on_seat (self,
f66be3
                                                          username,
797f26
                                                          seat_id,
797f26
                                                          NULL);
797f26
         } else {
797f26
                 session = get_user_session_for_display (display);
797f26
         }
797f26
 
797f26
         if (session != NULL && gdm_session_is_running (session)) {
797f26
                 gdm_session_start_reauthentication (session, pid, uid);
797f26
                 g_hash_table_insert (self->priv->open_reauthentication_requests,
797f26
                                      GINT_TO_POINTER (pid),
797f26
                                      invocation);
797f26
         } else if (is_login_screen) {
797f26
                 g_dbus_method_invocation_return_error_literal (invocation,
797f26
                                                                G_DBUS_ERROR,
797f26
                                                                G_DBUS_ERROR_ACCESS_DENIED,
797f26
                                                                "Login screen only allowed to open reauthentication channels for running sessions");
797f26
                 return TRUE;
797f26
         } else {
797f26
                 char *address;
797f26
                 address = open_temporary_reauthentication_channel (self,
797f26
                                                                    seat_id,
797f26
                                                                    session_id,
797f26
                                                                    pid,
797f26
                                                                    uid,
797f26
                                                                    is_remote);
797f26
                 gdm_dbus_manager_complete_open_reauthentication_channel (GDM_DBUS_MANAGER (manager),
797f26
                                                                          invocation,
f66be3
diff --git a/data/gdm.schemas.in.in b/data/gdm.schemas.in.in
797f26
index 8ad203101..f50934b15 100644
f66be3
--- a/data/gdm.schemas.in.in
f66be3
+++ b/data/gdm.schemas.in.in
797f26
@@ -102,32 +102,37 @@
797f26
     <schema>
797f26
       <key>xdmcp/DisplaysPerHost</key>
797f26
       <signature>i</signature>
797f26
       <default>1</default>
797f26
     </schema>
797f26
     <schema>
797f26
       <key>xdmcp/Port</key>
797f26
       <signature>i</signature>
797f26
       <default>177</default>
797f26
     </schema>
797f26
     <schema>
797f26
       <key>xdmcp/HonorIndirect</key>
797f26
       <signature>b</signature>
797f26
       <default>true</default>
797f26
     </schema>
797f26
     <schema>
797f26
       <key>xdmcp/MaxWaitIndirect</key>
797f26
       <signature>i</signature>
797f26
       <default>30</default>
797f26
     </schema>
797f26
     <schema>
797f26
       <key>xdmcp/PingIntervalSeconds</key>
797f26
       <signature>i</signature>
797f26
       <default>0</default>
797f26
     </schema>
797f26
     <schema>
797f26
       <key>xdmcp/Willing</key>
f66be3
       <signature>s</signature>
f66be3
       <default>@gdmconfdir@/Xwilling</default>
f66be3
     </schema>
f66be3
+    <schema>
f66be3
+      <key>xdmcp/AllowMultipleSessionsPerUser</key>
f66be3
+      <signature>b</signature>
f66be3
+      <default>false</default>
f66be3
+    </schema>
f66be3
   </schemalist>
f66be3
 </gdmschemafile>
f66be3
-- 
797f26
2.20.1
f66be3