gdm/SOURCES/0008-common-dedupe-activate_session_id.patch
2021-09-09 17:04:10 +00:00

402 lines
15 KiB
Diff

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