1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
$OpenBSD: patch-common_gdm-common_c,v 1.4 2015/10/18 13:25:54 ajacoutot Exp $
REVERT - OpenBSD does not have a systemd implementation (we need ConsoleKit)
From 9be58c9ec9a3a411492a5182ac4b0d51fdc3a323 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 12 Jun 2015 13:48:52 -0400
Subject: require logind support
REVERT - OpenBSD does not have a systemd implementation (we need ConsoleKit)
From 1ac67f522f5690c27023d98096ca817f12f7eb88 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 12 Jun 2015 13:28:01 -0400
Subject: drop consolekit support
--- common/gdm-common.c.orig Sun Oct 18 14:26:27 2015
+++ common/gdm-common.c Sun Oct 18 14:24:34 2015
@@ -39,12 +39,25 @@
#include "mkdtemp.h"
#endif
+#ifdef WITH_SYSTEMD
#include <systemd/sd-login.h>
+#endif
#define GDM_DBUS_NAME "org.gnome.DisplayManager"
#define GDM_DBUS_LOCAL_DISPLAY_FACTORY_PATH "/org/gnome/DisplayManager/LocalDisplayFactory"
#define GDM_DBUS_LOCAL_DISPLAY_FACTORY_INTERFACE "org.gnome.DisplayManager.LocalDisplayFactory"
+#ifdef WITH_CONSOLE_KIT
+#define CK_NAME "org.freedesktop.ConsoleKit"
+#define CK_PATH "/org/freedesktop/ConsoleKit"
+#define CK_INTERFACE "org.freedesktop.ConsoleKit"
+
+#define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager"
+#define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
+#define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat"
+#define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session"
+#endif
+
G_DEFINE_QUARK (gdm-common-error, gdm_common_error);
const char *
@@ -343,15 +356,306 @@ create_transient_display (GDBusConnection *connection,
return TRUE;
}
+#ifdef WITH_CONSOLE_KIT
+
static gboolean
-activate_session_id (GDBusConnection *connection,
- const char *seat_id,
- const char *session_id)
+get_current_session_id (GDBusConnection *connection,
+ char **session_id)
{
GError *local_error = NULL;
GVariant *reply;
reply = g_dbus_connection_call_sync (connection,
+ CK_NAME,
+ CK_MANAGER_PATH,
+ CK_MANAGER_INTERFACE,
+ "GetCurrentSession",
+ NULL, /* parameters */
+ G_VARIANT_TYPE ("(o)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, &local_error);
+ if (reply == NULL) {
+ g_warning ("Unable to determine session: %s", local_error->message);
+ g_error_free (local_error);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(o)", session_id);
+ g_variant_unref (reply);
+
+ return TRUE;
+}
+
+static gboolean
+get_seat_id_for_session (GDBusConnection *connection,
+ const char *session_id,
+ char **seat_id)
+{
+ GError *local_error = NULL;
+ GVariant *reply;
+
+ reply = g_dbus_connection_call_sync (connection,
+ CK_NAME,
+ session_id,
+ CK_SESSION_INTERFACE,
+ "GetSeatId",
+ NULL, /* parameters */
+ G_VARIANT_TYPE ("(o)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, &local_error);
+ if (reply == NULL) {
+ g_warning ("Unable to determine seat: %s", local_error->message);
+ g_error_free (local_error);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(o)", seat_id);
+ g_variant_unref (reply);
+
+ return TRUE;
+}
+
+static char *
+get_current_seat_id (GDBusConnection *connection)
+{
+ gboolean res;
+ char *session_id;
+ char *seat_id;
+
+ session_id = NULL;
+ seat_id = NULL;
+
+ res = get_current_session_id (connection, &session_id);
+ if (res) {
+ res = get_seat_id_for_session (connection, session_id, &seat_id);
+ }
+ g_free (session_id);
+
+ return seat_id;
+}
+
+static gboolean
+activate_session_id_for_ck (GDBusConnection *connection,
+ const char *seat_id,
+ const char *session_id)
+{
+ GError *local_error = NULL;
+ GVariant *reply;
+
+ reply = g_dbus_connection_call_sync (connection,
+ CK_NAME,
+ seat_id,
+ CK_SEAT_INTERFACE,
+ "ActivateSession",
+ g_variant_new ("(o)", session_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;
+}
+
+static gboolean
+session_is_login_window (GDBusConnection *connection,
+ const char *session_id)
+{
+ GError *local_error = NULL;
+ GVariant *reply;
+ const char *value;
+ gboolean ret;
+
+ reply = g_dbus_connection_call_sync (connection,
+ CK_NAME,
+ session_id,
+ CK_SESSION_INTERFACE,
+ "GetSessionType",
+ NULL,
+ G_VARIANT_TYPE ("(s)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, &local_error);
+ if (reply == NULL) {
+ g_warning ("Unable to determine session type: %s", local_error->message);
+ g_error_free (local_error);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(&s)", &value);
+
+ if (value == NULL || value[0] == '\0' || strcmp (value, "LoginWindow") != 0) {
+ ret = FALSE;
+ } else {
+ ret = TRUE;
+ }
+
+ g_variant_unref (reply);
+
+ return ret;
+}
+
+static gboolean
+seat_can_activate_sessions (GDBusConnection *connection,
+ const char *seat_id)
+{
+ GError *local_error = NULL;
+ GVariant *reply;
+ gboolean ret;
+
+ reply = g_dbus_connection_call_sync (connection,
+ CK_NAME,
+ seat_id,
+ CK_SEAT_INTERFACE,
+ "CanActivateSessions",
+ NULL,
+ G_VARIANT_TYPE ("(b)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, &local_error);
+ if (reply == NULL) {
+ g_warning ("Unable to determine if can activate sessions: %s", local_error->message);
+ g_error_free (local_error);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(b)", &ret);
+ g_variant_unref (reply);
+
+ return ret;
+}
+
+static const char **
+seat_get_sessions (GDBusConnection *connection,
+ const char *seat_id)
+{
+ GError *local_error = NULL;
+ GVariant *reply;
+ const char **value;
+
+ reply = g_dbus_connection_call_sync (connection,
+ CK_NAME,
+ seat_id,
+ CK_SEAT_INTERFACE,
+ "GetSessions",
+ NULL,
+ G_VARIANT_TYPE ("(ao)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, &local_error);
+ if (reply == NULL) {
+ g_warning ("Unable to list sessions: %s", local_error->message);
+ g_error_free (local_error);
+ return FALSE;
+ }
+
+ g_variant_get (reply, "(^ao)", &value);
+ g_variant_unref (reply);
+
+ return value;
+}
+
+static gboolean
+get_login_window_session_id_for_ck (GDBusConnection *connection,
+ const char *seat_id,
+ char **session_id)
+{
+ gboolean can_activate_sessions;
+ const char **sessions;
+ int i;
+
+ *session_id = NULL;
+ sessions = NULL;
+
+ g_debug ("checking if seat can activate sessions");
+
+ can_activate_sessions = seat_can_activate_sessions (connection, seat_id);
+ if (! can_activate_sessions) {
+ g_debug ("seat is unable to activate sessions");
+ return FALSE;
+ }
+
+ sessions = seat_get_sessions (connection, seat_id);
+ for (i = 0; sessions [i] != NULL; i++) {
+ const char *ssid;
+
+ ssid = sessions [i];
+
+ if (session_is_login_window (connection, ssid)) {
+ *session_id = g_strdup (ssid);
+ break;
+ }
+ }
+ g_free (sessions);
+
+ return TRUE;
+}
+
+static gboolean
+goto_login_session_for_ck (GDBusConnection *connection,
+ GError **error)
+{
+ gboolean ret;
+ gboolean res;
+ char *session_id;
+ char *seat_id;
+
+ ret = FALSE;
+
+ /* First look for any existing LoginWindow sessions on the seat.
+ If none are found, create a new one. */
+
+ seat_id = get_current_seat_id (connection);
+ if (seat_id == NULL || seat_id[0] == '\0') {
+ g_debug ("seat id is not set; can't switch sessions");
+ g_set_error (error, GDM_COMMON_ERROR, 0, _("Could not identify the current session."));
+
+ return FALSE;
+ }
+
+ res = get_login_window_session_id_for_ck (connection, seat_id, &session_id);
+ if (! res) {
+ g_set_error (error, GDM_COMMON_ERROR, 1, _("User unable to switch sessions."));
+ return FALSE;
+ }
+
+ if (session_id != NULL) {
+ res = activate_session_id_for_ck (connection, seat_id, session_id);
+ if (res) {
+ ret = TRUE;
+ }
+ }
+
+ if (! ret && g_strcmp0 (seat_id, "/org/freedesktop/ConsoleKit/Seat1") == 0) {
+ res = create_transient_display (connection, error);
+ if (res) {
+ ret = TRUE;
+ }
+ }
+
+ return ret;
+}
+#endif
+
+#ifdef WITH_SYSTEMD
+
+static gboolean
+activate_session_id_for_systemd (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",
@@ -373,8 +677,8 @@ activate_session_id (GDBusConnection *connection,
}
static gboolean
-get_login_window_session_id (const char *seat_id,
- char **session_id)
+get_login_window_session_id_for_systemd (const char *seat_id,
+ char **session_id)
{
gboolean ret;
int res, i;
@@ -442,8 +746,8 @@ out:
}
static gboolean
-goto_login_session (GDBusConnection *connection,
- GError **error)
+goto_login_session_for_systemd (GDBusConnection *connection,
+ GError **error)
{
gboolean ret;
int res;
@@ -497,9 +801,9 @@ goto_login_session (GDBusConnection *connection,
return FALSE;
}
- res = get_login_window_session_id (seat_id, &session_id);
+ res = get_login_window_session_id_for_systemd (seat_id, &session_id);
if (res && session_id != NULL) {
- res = activate_session_id (connection, seat_id, session_id);
+ res = activate_session_id_for_systemd (connection, seat_id, session_id);
if (res) {
ret = TRUE;
@@ -518,6 +822,7 @@ goto_login_session (GDBusConnection *connection,
return ret;
}
+#endif
gboolean
gdm_goto_login_session (GError **error)
@@ -533,7 +838,17 @@ gdm_goto_login_session (GError **error)
return FALSE;
}
- return goto_login_session (connection, error);
+#ifdef WITH_SYSTEMD
+ if (LOGIND_RUNNING()) {
+ return goto_login_session_for_systemd (connection, error);
+ }
+#endif
+
+#ifdef WITH_CONSOLE_KIT
+ return goto_login_session_for_ck (connection, error);
+#else
+ return FALSE;
+#endif
}
static void
|