Blame SOURCES/0008-common-dedupe-activate_session_id.patch

400dab
From 9d8e72ea9171566e9d74caaf28c8b5933ef34874 Mon Sep 17 00:00:00 2001
400dab
From: Ray Strode <rstrode@redhat.com>
400dab
Date: Thu, 2 Aug 2018 14:00:46 -0400
400dab
Subject: [PATCH 08/51] common: dedupe activate_session_id
400dab
400dab
Right now there are three copies of activate_session_id.
400dab
400dab
This commit consolidates the code to gdm-common.c
400dab
---
400dab
 common/gdm-common.c  | 10 +++++-----
400dab
 common/gdm-common.h  |  6 ++++++
400dab
 daemon/gdm-manager.c | 33 +--------------------------------
400dab
 3 files changed, 12 insertions(+), 37 deletions(-)
400dab
400dab
diff --git a/common/gdm-common.c b/common/gdm-common.c
400dab
index 00daf0df8..59317a889 100644
400dab
--- a/common/gdm-common.c
400dab
+++ b/common/gdm-common.c
400dab
@@ -335,64 +335,64 @@ static gboolean
400dab
 create_transient_display (GDBusConnection *connection,
400dab
                           GError         **error)
400dab
 {
400dab
         GError *local_error = NULL;
400dab
         GVariant *reply;
400dab
         const char     *value;
400dab
 
400dab
         reply = g_dbus_connection_call_sync (connection,
400dab
                                              GDM_DBUS_NAME,
400dab
                                              GDM_DBUS_LOCAL_DISPLAY_FACTORY_PATH,
400dab
                                              GDM_DBUS_LOCAL_DISPLAY_FACTORY_INTERFACE,
400dab
                                              "CreateTransientDisplay",
400dab
                                              NULL, /* parameters */
400dab
                                              G_VARIANT_TYPE ("(o)"),
400dab
                                              G_DBUS_CALL_FLAGS_NONE,
400dab
                                              -1,
400dab
                                              NULL, &local_error);
400dab
         if (reply == NULL) {
400dab
                 g_warning ("Unable to create transient display: %s", local_error->message);
400dab
                 g_propagate_error (error, local_error);
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         g_variant_get (reply, "(&o)", &value);
400dab
         g_debug ("Started %s", value);
400dab
 
400dab
         g_variant_unref (reply);
400dab
         return TRUE;
400dab
 }
400dab
 
400dab
-static gboolean
400dab
-activate_session_id (GDBusConnection *connection,
400dab
-                     const char      *seat_id,
400dab
-                     const char      *session_id)
400dab
+gboolean
400dab
+gdm_activate_session_by_id (GDBusConnection *connection,
400dab
+                            const char      *seat_id,
400dab
+                            const char      *session_id)
400dab
 {
400dab
         GError *local_error = NULL;
400dab
         GVariant *reply;
400dab
 
400dab
         reply = g_dbus_connection_call_sync (connection,
400dab
                                              "org.freedesktop.login1",
400dab
                                              "/org/freedesktop/login1",
400dab
                                              "org.freedesktop.login1.Manager",
400dab
                                              "ActivateSessionOnSeat",
400dab
                                              g_variant_new ("(ss)", session_id, seat_id),
400dab
                                              NULL,
400dab
                                              G_DBUS_CALL_FLAGS_NONE,
400dab
                                              -1,
400dab
                                              NULL, &local_error);
400dab
         if (reply == NULL) {
400dab
                 g_warning ("Unable to activate session: %s", local_error->message);
400dab
                 g_error_free (local_error);
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         g_variant_unref (reply);
400dab
 
400dab
         return TRUE;
400dab
 }
400dab
 
400dab
 gboolean
400dab
 gdm_get_login_window_session_id (const char  *seat_id,
400dab
 		                 char       **session_id)
400dab
 {
400dab
         gboolean   ret;
400dab
@@ -512,61 +512,61 @@ goto_login_session (GDBusConnection  *connection,
400dab
 
400dab
         res = sd_session_get_seat (our_session, &seat_id);
400dab
         free (our_session);
400dab
         if (res < 0) {
400dab
                 g_debug ("failed to determine own seat: %s", strerror (-res));
400dab
                 g_set_error (error, GDM_COMMON_ERROR, 0, _("Could not identify the current seat."));
400dab
 
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         res = sd_seat_can_multi_session (seat_id);
400dab
         if (res < 0) {
400dab
                 free (seat_id);
400dab
 
400dab
                 g_debug ("failed to determine whether seat can do multi session: %s", strerror (-res));
400dab
                 g_set_error (error, GDM_COMMON_ERROR, 0, _("The system is unable to determine whether to switch to an existing login screen or start up a new login screen."));
400dab
 
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         if (res == 0) {
400dab
                 free (seat_id);
400dab
 
400dab
                 g_set_error (error, GDM_COMMON_ERROR, 0, _("The system is unable to start up a new login screen."));
400dab
 
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         res = gdm_get_login_window_session_id (seat_id, &session_id);
400dab
         if (res && session_id != NULL) {
400dab
-                res = activate_session_id (connection, seat_id, session_id);
400dab
+                res = gdm_activate_session_by_id (connection, seat_id, session_id);
400dab
 
400dab
                 if (res) {
400dab
                         ret = TRUE;
400dab
                 }
400dab
         }
400dab
 
400dab
         if (! ret && g_strcmp0 (seat_id, "seat0") == 0) {
400dab
                 res = create_transient_display (connection, error);
400dab
                 if (res) {
400dab
                         ret = TRUE;
400dab
                 }
400dab
         }
400dab
 
400dab
         free (seat_id);
400dab
         g_free (session_id);
400dab
 
400dab
         return ret;
400dab
 }
400dab
 
400dab
 gboolean
400dab
 gdm_goto_login_session (GError **error)
400dab
 {
400dab
         GError *local_error;
400dab
         GDBusConnection *connection;
400dab
 
400dab
         local_error = NULL;
400dab
         connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &local_error);
400dab
         if (connection == NULL) {
400dab
                 g_debug ("Failed to connect to the D-Bus daemon: %s", local_error->message);
400dab
                 g_propagate_error (error, local_error);
400dab
diff --git a/common/gdm-common.h b/common/gdm-common.h
400dab
index c9cbd9c48..3fbf07653 100644
400dab
--- a/common/gdm-common.h
400dab
+++ b/common/gdm-common.h
400dab
@@ -1,78 +1,84 @@
400dab
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
400dab
  *
400dab
  * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
400dab
  *
400dab
  * This library is free software; you can redistribute it and/or
400dab
  * modify it under the terms of the GNU Library General Public
400dab
  * License as published by the Free Software Foundation; either
400dab
  * version 2 of the License, or (at your option) any later version.
400dab
  *
400dab
  * This library is distributed in the hope that it will be useful,
400dab
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
400dab
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
400dab
  * Library General Public License for more details.
400dab
  *
400dab
  * You should have received a copy of the GNU Library General Public
400dab
  * License along with this library; if not, write to the
400dab
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
400dab
  * Boston, MA 02110-1301, USA.
400dab
  */
400dab
 
400dab
 #ifndef _GDM_COMMON_H
400dab
 #define _GDM_COMMON_H
400dab
 
400dab
 #include <glib-unix.h>
400dab
+#include <gio/gio.h>
400dab
+
400dab
 #include <pwd.h>
400dab
 #include <errno.h>
400dab
 
400dab
 #define        VE_IGNORE_EINTR(expr) \
400dab
         do {                         \
400dab
                 errno = 0;           \
400dab
                 expr;                \
400dab
         } while G_UNLIKELY (errno == EINTR);
400dab
 
400dab
 GQuark gdm_common_error_quark (void);
400dab
 #define GDM_COMMON_ERROR gdm_common_error_quark()
400dab
 
400dab
 typedef char * (*GdmExpandVarFunc) (const char *var,
400dab
                                     gpointer user_data);
400dab
 
400dab
 G_BEGIN_DECLS
400dab
 
400dab
 int            gdm_wait_on_pid           (int pid);
400dab
 int            gdm_wait_on_and_disown_pid (int pid,
400dab
                                            int timeout);
400dab
 int            gdm_signal_pid            (int pid,
400dab
                                           int signal);
400dab
 gboolean       gdm_get_pwent_for_name    (const char     *name,
400dab
                                           struct passwd **pwentp);
400dab
 
400dab
 gboolean       gdm_clear_close_on_exec_flag (int fd);
400dab
 
400dab
 const char *   gdm_make_temp_dir         (char    *template);
400dab
 
400dab
 char          *gdm_generate_random_bytes (gsize          size,
400dab
                                           GError       **error);
400dab
 gboolean       gdm_get_login_window_session_id (const char  *seat_id,
400dab
                                                 char       **session_id);
400dab
 gboolean       gdm_goto_login_session    (GError **error);
400dab
 
400dab
 GPtrArray     *gdm_get_script_environment (const char *username,
400dab
                                            const char *display_name,
400dab
                                            const char *display_hostname,
400dab
                                            const char *display_x11_authority_file);
400dab
 gboolean       gdm_run_script             (const char *dir,
400dab
                                            const char *username,
400dab
                                            const char *display_name,
400dab
                                            const char *display_hostname,
400dab
                                            const char *display_x11_authority_file);
400dab
 
400dab
 gboolean      gdm_shell_var_is_valid_char (char c,
400dab
                                            gboolean first);
400dab
 char *        gdm_shell_expand            (const char *str,
400dab
                                            GdmExpandVarFunc expand_func,
400dab
                                            gpointer user_data);
400dab
 
400dab
+gboolean      gdm_activate_session_by_id (GDBusConnection *connection,
400dab
+                                          const char      *seat_id,
400dab
+                                          const char      *session_id);
400dab
+
400dab
 G_END_DECLS
400dab
 
400dab
 #endif /* _GDM_COMMON_H */
400dab
diff --git a/daemon/gdm-manager.c b/daemon/gdm-manager.c
400dab
index 375ef6f80..617ee36f0 100644
400dab
--- a/daemon/gdm-manager.c
400dab
+++ b/daemon/gdm-manager.c
400dab
@@ -267,91 +267,60 @@ lookup_by_session_id (const char *id,
400dab
 
400dab
 static gboolean
400dab
 is_login_session (GdmManager  *self,
400dab
                   const char  *session_id,
400dab
                   GError     **error)
400dab
 {
400dab
         char *session_class = NULL;
400dab
         int ret;
400dab
 
400dab
         ret = sd_session_get_class (session_id, &session_class);
400dab
 
400dab
         if (ret < 0) {
400dab
                 g_set_error (error,
400dab
                              GDM_DISPLAY_ERROR,
400dab
                              GDM_DISPLAY_ERROR_GETTING_SESSION_INFO,
400dab
                              "Error getting class for session id %s from systemd: %s",
400dab
                              session_id,
400dab
                              g_strerror (-ret));
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         if (g_strcmp0 (session_class, "greeter") != 0) {
400dab
                 g_free (session_class);
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         g_free (session_class);
400dab
         return TRUE;
400dab
 }
400dab
 
400dab
-static gboolean
400dab
-activate_session_id (GdmManager *manager,
400dab
-                     const char *seat_id,
400dab
-                     const char *session_id)
400dab
-{
400dab
-        GError *error = NULL;
400dab
-        GVariant *reply;
400dab
-
400dab
-        reply = g_dbus_connection_call_sync (manager->priv->connection,
400dab
-                                             "org.freedesktop.login1",
400dab
-                                             "/org/freedesktop/login1",
400dab
-                                             "org.freedesktop.login1.Manager",
400dab
-                                             "ActivateSessionOnSeat",
400dab
-                                             g_variant_new ("(ss)", session_id, seat_id),
400dab
-                                             NULL, /* expected reply */
400dab
-                                             G_DBUS_CALL_FLAGS_NONE,
400dab
-                                             -1,
400dab
-                                             NULL,
400dab
-                                             &error);
400dab
-        if (reply == NULL) {
400dab
-                g_debug ("GdmManager: logind 'ActivateSessionOnSeat' %s raised:\n %s\n\n",
400dab
-                         g_dbus_error_get_remote_error (error), error->message);
400dab
-                g_error_free (error);
400dab
-                return FALSE;
400dab
-        }
400dab
-
400dab
-        g_variant_unref (reply);
400dab
-
400dab
-        return TRUE;
400dab
-}
400dab
-
400dab
 static gboolean
400dab
 session_unlock (GdmManager *manager,
400dab
                 const char *ssid)
400dab
 {
400dab
         GError *error = NULL;
400dab
         GVariant *reply;
400dab
 
400dab
         g_debug ("Unlocking session %s", ssid);
400dab
 
400dab
         reply = g_dbus_connection_call_sync (manager->priv->connection,
400dab
                                              "org.freedesktop.login1",
400dab
                                              "/org/freedesktop/login1",
400dab
                                              "org.freedesktop.login1.Manager",
400dab
                                              "UnlockSession",
400dab
                                              g_variant_new ("(s)", ssid),
400dab
                                              NULL, /* expected reply */
400dab
                                              G_DBUS_CALL_FLAGS_NONE,
400dab
                                              -1,
400dab
                                              NULL,
400dab
                                              &error);
400dab
         if (reply == NULL) {
400dab
                 g_debug ("GdmManager: logind 'UnlockSession' %s raised:\n %s\n\n",
400dab
                          g_dbus_error_get_remote_error (error), error->message);
400dab
                 g_error_free (error);
400dab
                 return FALSE;
400dab
         }
400dab
 
400dab
         g_variant_unref (reply);
400dab
 
400dab
         return TRUE;
400dab
@@ -627,61 +596,61 @@ switch_to_compatible_user_session (GdmManager *manager,
400dab
         ret = FALSE;
400dab
 
400dab
         username = gdm_session_get_username (session);
400dab
         seat_id = gdm_session_get_display_seat_id (session);
400dab
 
400dab
         if (!fail_if_already_switched)
400dab
                 ssid_to_activate = gdm_session_get_session_id (session);
400dab
 
400dab
         if (ssid_to_activate == NULL) {
400dab
                 if (!seat_id || !sd_seat_can_multi_session (seat_id)) {
400dab
                         g_debug ("GdmManager: unable to activate existing sessions from login screen unless on seat0");
400dab
                         goto out;
400dab
                 }
400dab
 
400dab
                 if (!fail_if_already_switched) {
400dab
                         session = NULL;
400dab
                 }
400dab
 
400dab
                 existing_session = find_session_for_user_on_seat (manager, username, seat_id, session);
400dab
 
400dab
                 if (existing_session != NULL) {
400dab
                         ssid_to_activate = gdm_session_get_session_id (existing_session);
400dab
                 }
400dab
         }
400dab
 
400dab
         if (ssid_to_activate == NULL) {
400dab
                 goto out;
400dab
         }
400dab
 
400dab
         if (seat_id != NULL) {
400dab
-                res = activate_session_id (manager, seat_id, ssid_to_activate);
400dab
+                res = gdm_activate_session_by_id (manager->priv->connection, seat_id, ssid_to_activate);
400dab
                 if (! res) {
400dab
                         g_debug ("GdmManager: unable to activate session: %s", ssid_to_activate);
400dab
                         goto out;
400dab
                 }
400dab
         }
400dab
 
400dab
         res = session_unlock (manager, ssid_to_activate);
400dab
         if (!res) {
400dab
                 /* this isn't fatal */
400dab
                 g_debug ("GdmManager: unable to unlock session: %s", ssid_to_activate);
400dab
         }
400dab
 
400dab
         ret = TRUE;
400dab
 
400dab
  out:
400dab
         return ret;
400dab
 }
400dab
 
400dab
 static GdmDisplay *
400dab
 get_display_for_user_session (GdmSession *session)
400dab
 {
400dab
         return g_object_get_data (G_OBJECT (session), "gdm-display");
400dab
 }
400dab
 
400dab
 static GdmSession *
400dab
 get_user_session_for_display (GdmDisplay *display)
400dab
 {
400dab
         if (display == NULL) {
400dab
                 return NULL;
400dab
         }
400dab
-- 
400dab
2.27.0
400dab