]>
Commit | Line | Data |
---|---|---|
c5786473 JB |
1 | --- polkit-0.114/src/polkit/polkitunixsession.c.orig 2018-03-23 16:09:30.000000000 +0100 |
2 | +++ polkit-0.114/src/polkit/polkitunixsession.c 2018-04-12 19:03:50.775644785 +0200 | |
9c761957 JB |
3 | @@ -29,6 +29,12 @@ |
4 | #include "polkiterror.h" | |
5 | #include "polkitprivate.h" | |
6 | ||
7 | +#ifdef HAVE_LIBSYSTEMD | |
8 | +# include <stdlib.h> | |
9 | +# include <systemd/sd-daemon.h> | |
10 | +# include <systemd/sd-login.h> | |
11 | +#endif | |
12 | + | |
13 | /** | |
14 | * SECTION:polkitunixsession | |
15 | * @title: PolkitUnixSession | |
c5786473 | 16 | @@ -363,35 +369,49 @@ polkit_unix_session_exists_sync (PolkitS |
9c761957 JB |
17 | { |
18 | PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject); | |
19 | GDBusConnection *connection; | |
20 | - GVariant *result; | |
21 | + GVariant *result = NULL; | |
22 | gboolean ret; | |
23 | ||
24 | + connection = NULL; | |
25 | ret = FALSE; | |
26 | ||
27 | - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error); | |
28 | - if (connection == NULL) | |
29 | - goto out; | |
30 | +#ifdef HAVE_LIBSYSTEMD | |
31 | + uid_t uid; | |
32 | ||
33 | - result = g_dbus_connection_call_sync (connection, | |
34 | - "org.freedesktop.ConsoleKit", /* name */ | |
35 | - session->session_id, /* object path */ | |
36 | - "org.freedesktop.ConsoleKit.Session", /* interface name */ | |
37 | - "GetUser", /* method */ | |
38 | - NULL, /* parameters */ | |
39 | - G_VARIANT_TYPE ("(u)"), | |
40 | - G_DBUS_CALL_FLAGS_NONE, | |
41 | - -1, | |
42 | - cancellable, | |
43 | - error); | |
44 | - if (result == NULL) | |
45 | - goto out; | |
46 | + if (sd_booted () > 0) | |
47 | + { | |
48 | + if (sd_session_get_uid (session->session_id, &uid) == 0) | |
49 | + ret = TRUE; | |
50 | + } | |
51 | + else | |
52 | +#endif /* HAVE_LIBSYSTEMD */ | |
53 | + { | |
54 | + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error); | |
55 | + if (connection == NULL) | |
56 | + goto out; | |
57 | + | |
58 | + result = g_dbus_connection_call_sync (connection, | |
59 | + "org.freedesktop.ConsoleKit", /* name */ | |
60 | + session->session_id, /* object path */ | |
61 | + "org.freedesktop.ConsoleKit.Session", /* interface name */ | |
62 | + "GetUser", /* method */ | |
63 | + NULL, /* parameters */ | |
64 | + G_VARIANT_TYPE ("(u)"), | |
65 | + G_DBUS_CALL_FLAGS_NONE, | |
66 | + -1, | |
67 | + cancellable, | |
68 | + error); | |
69 | + if (result == NULL) | |
70 | + goto out; | |
71 | ||
72 | - ret = TRUE; | |
73 | - g_variant_unref (result); | |
74 | + ret = TRUE; | |
75 | + g_variant_unref (result); | |
76 | + } | |
77 | ||
78 | out: | |
79 | if (connection != NULL) | |
80 | g_object_unref (connection); | |
81 | + | |
82 | return ret; | |
83 | } | |
84 | ||
c5786473 | 85 | @@ -474,6 +494,7 @@ polkit_unix_session_initable_init (GInit |
9c761957 JB |
86 | GVariant *result; |
87 | gboolean ret; | |
88 | ||
89 | + result = NULL; | |
90 | connection = NULL; | |
91 | ret = FALSE; | |
92 | ||
c5786473 | 93 | @@ -484,28 +505,65 @@ polkit_unix_session_initable_init (GInit |
9c761957 JB |
94 | goto out; |
95 | } | |
96 | ||
97 | - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error); | |
98 | - if (connection == NULL) | |
99 | - goto out; | |
c5786473 JB |
100 | +#ifdef HAVE_LIBSYSTEMD |
101 | + char *s; | |
102 | + uid_t uid; | |
103 | + | |
104 | + if (sd_booted () > 0) | |
105 | + { | |
106 | + if (sd_pid_get_session (session->pid, &s) == 0) | |
107 | + { | |
108 | + session->session_id = g_strdup (s); | |
109 | + free (s); | |
110 | + ret = TRUE; | |
111 | + goto out; | |
112 | + } | |
113 | + | |
114 | + /* Now do process -> uid -> graphical session (systemd version 213)*/ | |
115 | + if (sd_pid_get_owner_uid (session->pid, &uid) < 0) | |
116 | + goto error; | |
117 | ||
9c761957 JB |
118 | - result = g_dbus_connection_call_sync (connection, |
119 | - "org.freedesktop.ConsoleKit", /* name */ | |
120 | - "/org/freedesktop/ConsoleKit/Manager", /* object path */ | |
121 | - "org.freedesktop.ConsoleKit.Manager", /* interface name */ | |
122 | - "GetSessionForUnixProcess", /* method */ | |
123 | - g_variant_new ("(u)", session->pid), /* parameters */ | |
124 | - G_VARIANT_TYPE ("(o)"), | |
125 | - G_DBUS_CALL_FLAGS_NONE, | |
126 | - -1, | |
127 | - cancellable, | |
128 | - error); | |
129 | - if (result == NULL) | |
130 | - goto out; | |
c5786473 | 131 | + if (sd_uid_get_display (uid, &s) >= 0) |
9c761957 | 132 | + { |
c5786473 JB |
133 | + session->session_id = g_strdup (s); |
134 | + free (s); | |
135 | + ret = TRUE; | |
136 | + goto out; | |
137 | + } | |
138 | ||
139 | - g_variant_get (result, "(o)", &session->session_id); | |
140 | - g_variant_unref (result); | |
141 | +error: | |
9c761957 JB |
142 | + g_set_error (error, |
143 | + POLKIT_ERROR, | |
144 | + POLKIT_ERROR_FAILED, | |
145 | + "No session for pid %d", | |
146 | + (gint) session->pid); | |
147 | + } | |
148 | + else | |
149 | +#endif /* HAVE_LIBSYSTEMD */ | |
150 | + { | |
151 | + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error); | |
152 | + if (connection == NULL) | |
153 | + goto out; | |
154 | + | |
155 | + result = g_dbus_connection_call_sync (connection, | |
156 | + "org.freedesktop.ConsoleKit", /* name */ | |
157 | + "/org/freedesktop/ConsoleKit/Manager", /* object path */ | |
158 | + "org.freedesktop.ConsoleKit.Manager", /* interface name */ | |
159 | + "GetSessionForUnixProcess", /* method */ | |
160 | + g_variant_new ("(u)", session->pid), /* parameters */ | |
161 | + G_VARIANT_TYPE ("(o)"), | |
162 | + G_DBUS_CALL_FLAGS_NONE, | |
163 | + -1, | |
164 | + cancellable, | |
165 | + error); | |
166 | + if (result == NULL) | |
167 | + goto out; | |
168 | ||
c5786473 | 169 | - ret = TRUE; |
9c761957 JB |
170 | + g_variant_get (result, "(o)", &session->session_id); |
171 | + g_variant_unref (result); | |
c5786473 | 172 | + |
9c761957 JB |
173 | + ret = TRUE; |
174 | + } | |
175 | ||
176 | out: | |
177 | if (connection != NULL) | |
c5786473 JB |
178 | --- polkit-0.114/src/polkit/polkitunixsession-systemd.c.orig 2018-04-12 18:55:30.995650493 +0200 |
179 | +++ polkit-0.114/src/polkit/polkitunixsession-systemd.c 1970-01-01 01:00:00.000000000 +0100 | |
180 | @@ -1,504 +0,0 @@ | |
186114f9 ŁK |
181 | -/* |
182 | - * Copyright (C) 2011 Red Hat, Inc. | |
183 | - * | |
184 | - * This library is free software; you can redistribute it and/or | |
185 | - * modify it under the terms of the GNU Lesser General Public | |
186 | - * License as published by the Free Software Foundation; either | |
187 | - * version 2 of the License, or (at your option) any later version. | |
188 | - * | |
189 | - * This library is distributed in the hope that it will be useful, | |
190 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
191 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
192 | - * Lesser General Public License for more details. | |
193 | - * | |
194 | - * You should have received a copy of the GNU Lesser General | |
195 | - * Public License along with this library; if not, write to the | |
196 | - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
197 | - * Boston, MA 02111-1307, USA. | |
198 | - * | |
199 | - * Author: Matthias Clasen | |
200 | - */ | |
201 | - | |
202 | -#ifdef HAVE_CONFIG_H | |
203 | -# include "config.h" | |
204 | -#endif | |
205 | - | |
a7e49982 | 206 | -#include <stdlib.h> |
186114f9 ŁK |
207 | -#include <string.h> |
208 | -#include "polkitunixsession.h" | |
209 | -#include "polkitsubject.h" | |
210 | -#include "polkiterror.h" | |
211 | -#include "polkitprivate.h" | |
212 | - | |
213 | -#include <systemd/sd-login.h> | |
214 | - | |
215 | -/** | |
216 | - * SECTION:polkitunixsession | |
217 | - * @title: PolkitUnixSession | |
218 | - * @short_description: Unix sessions | |
219 | - * | |
220 | - * An object that represents an user session. | |
221 | - * | |
222 | - * The session id is an opaque string obtained from ConsoleKit. | |
223 | - */ | |
224 | - | |
225 | -/** | |
226 | - * PolkitUnixSession: | |
227 | - * | |
228 | - * The #PolkitUnixSession struct should not be accessed directly. | |
229 | - */ | |
230 | -struct _PolkitUnixSession | |
231 | -{ | |
232 | - GObject parent_instance; | |
233 | - | |
234 | - gchar *session_id; | |
235 | - | |
236 | - gint pid; | |
237 | -}; | |
238 | - | |
239 | -struct _PolkitUnixSessionClass | |
240 | -{ | |
241 | - GObjectClass parent_class; | |
242 | -}; | |
243 | - | |
244 | -enum | |
245 | -{ | |
246 | - PROP_0, | |
247 | - PROP_SESSION_ID, | |
248 | - PROP_PID, | |
249 | -}; | |
250 | - | |
251 | -static void subject_iface_init (PolkitSubjectIface *subject_iface); | |
252 | -static void initable_iface_init (GInitableIface *initable_iface); | |
253 | -static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface); | |
254 | - | |
255 | -G_DEFINE_TYPE_WITH_CODE (PolkitUnixSession, polkit_unix_session, G_TYPE_OBJECT, | |
256 | - G_IMPLEMENT_INTERFACE (POLKIT_TYPE_SUBJECT, subject_iface_init) | |
257 | - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init) | |
258 | - G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init) | |
259 | - ); | |
260 | - | |
261 | -static void | |
262 | -polkit_unix_session_init (PolkitUnixSession *session) | |
263 | -{ | |
264 | -} | |
265 | - | |
266 | -static void | |
267 | -polkit_unix_session_finalize (GObject *object) | |
268 | -{ | |
269 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (object); | |
270 | - | |
271 | - g_free (session->session_id); | |
272 | - | |
273 | - if (G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize != NULL) | |
274 | - G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize (object); | |
275 | -} | |
276 | - | |
277 | -static void | |
278 | -polkit_unix_session_get_property (GObject *object, | |
279 | - guint prop_id, | |
280 | - GValue *value, | |
281 | - GParamSpec *pspec) | |
282 | -{ | |
283 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (object); | |
284 | - | |
285 | - switch (prop_id) | |
286 | - { | |
287 | - case PROP_SESSION_ID: | |
288 | - g_value_set_string (value, session->session_id); | |
289 | - break; | |
290 | - | |
291 | - default: | |
292 | - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
293 | - break; | |
294 | - } | |
295 | -} | |
296 | - | |
297 | -static void | |
298 | -polkit_unix_session_set_property (GObject *object, | |
299 | - guint prop_id, | |
300 | - const GValue *value, | |
301 | - GParamSpec *pspec) | |
302 | -{ | |
303 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (object); | |
304 | - | |
305 | - switch (prop_id) | |
306 | - { | |
307 | - case PROP_SESSION_ID: | |
308 | - polkit_unix_session_set_session_id (session, g_value_get_string (value)); | |
309 | - break; | |
310 | - | |
311 | - case PROP_PID: | |
312 | - session->pid = g_value_get_int (value); | |
313 | - break; | |
314 | - | |
315 | - default: | |
316 | - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
317 | - break; | |
318 | - } | |
319 | -} | |
320 | - | |
321 | -static void | |
322 | -polkit_unix_session_class_init (PolkitUnixSessionClass *klass) | |
323 | -{ | |
324 | - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | |
325 | - | |
326 | - gobject_class->finalize = polkit_unix_session_finalize; | |
327 | - gobject_class->get_property = polkit_unix_session_get_property; | |
328 | - gobject_class->set_property = polkit_unix_session_set_property; | |
329 | - | |
330 | - /** | |
331 | - * PolkitUnixSession:session-id: | |
332 | - * | |
333 | - * The UNIX session id. | |
334 | - */ | |
335 | - g_object_class_install_property (gobject_class, | |
336 | - PROP_SESSION_ID, | |
337 | - g_param_spec_string ("session-id", | |
338 | - "Session ID", | |
339 | - "The UNIX session ID", | |
340 | - NULL, | |
341 | - G_PARAM_CONSTRUCT | | |
342 | - G_PARAM_READWRITE | | |
343 | - G_PARAM_STATIC_NAME | | |
344 | - G_PARAM_STATIC_BLURB | | |
345 | - G_PARAM_STATIC_NICK)); | |
346 | - | |
347 | - | |
348 | - /** | |
349 | - * PolkitUnixSession:pid: | |
350 | - * | |
351 | - * The UNIX process id to look up the session. | |
352 | - */ | |
353 | - g_object_class_install_property (gobject_class, | |
354 | - PROP_PID, | |
355 | - g_param_spec_int ("pid", | |
356 | - "Process ID", | |
357 | - "Process ID to use for looking up the session", | |
358 | - 0, | |
359 | - G_MAXINT, | |
360 | - 0, | |
361 | - G_PARAM_CONSTRUCT_ONLY | | |
362 | - G_PARAM_WRITABLE | | |
363 | - G_PARAM_STATIC_NAME | | |
364 | - G_PARAM_STATIC_BLURB | | |
365 | - G_PARAM_STATIC_NICK)); | |
366 | - | |
367 | -} | |
368 | - | |
369 | -/** | |
370 | - * polkit_unix_session_get_session_id: | |
371 | - * @session: A #PolkitUnixSession. | |
372 | - * | |
373 | - * Gets the session id for @session. | |
374 | - * | |
375 | - * Returns: The session id for @session. Do not free this string, it | |
376 | - * is owned by @session. | |
377 | - **/ | |
378 | -const gchar * | |
379 | -polkit_unix_session_get_session_id (PolkitUnixSession *session) | |
380 | -{ | |
381 | - g_return_val_if_fail (POLKIT_IS_UNIX_SESSION (session), NULL); | |
382 | - return session->session_id; | |
383 | -} | |
384 | - | |
385 | -/** | |
386 | - * polkit_unix_session_set_session_id: | |
387 | - * @session: A #PolkitUnixSession. | |
388 | - * @session_id: The session id. | |
389 | - * | |
390 | - * Sets the session id for @session to @session_id. | |
391 | - **/ | |
392 | -void | |
393 | -polkit_unix_session_set_session_id (PolkitUnixSession *session, | |
394 | - const gchar *session_id) | |
395 | -{ | |
396 | - g_return_if_fail (POLKIT_IS_UNIX_SESSION (session)); | |
397 | - /*g_return_if_fail (session_id != NULL);*/ | |
398 | - g_free (session->session_id); | |
399 | - session->session_id = g_strdup (session_id); | |
400 | -} | |
401 | - | |
402 | -/** | |
403 | - * polkit_unix_session_new: | |
404 | - * @session_id: The session id. | |
405 | - * | |
406 | - * Creates a new #PolkitUnixSession for @session_id. | |
407 | - * | |
408 | - * Returns: (transfer full): A #PolkitUnixSession. Free with g_object_unref(). | |
409 | - **/ | |
410 | -PolkitSubject * | |
411 | -polkit_unix_session_new (const gchar *session_id) | |
412 | -{ | |
413 | - return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_UNIX_SESSION, | |
414 | - "session-id", session_id, | |
415 | - NULL)); | |
416 | -} | |
417 | - | |
418 | -/** | |
419 | - * polkit_unix_session_new_for_process: | |
420 | - * @pid: The process id of the process to get the session for. | |
421 | - * @cancellable: (allow-none): A #GCancellable or %NULL. | |
422 | - * @callback: A #GAsyncReadyCallback to call when the request is satisfied | |
423 | - * @user_data: The data to pass to @callback. | |
424 | - * | |
425 | - * Asynchronously creates a new #PolkitUnixSession object for the | |
426 | - * process with process id @pid. | |
427 | - * | |
428 | - * When the operation is finished, @callback will be invoked in the | |
429 | - * <link linkend="g-main-context-push-thread-default">thread-default | |
430 | - * main loop</link> of the thread you are calling this method | |
431 | - * from. You can then call | |
432 | - * polkit_unix_session_new_for_process_finish() to get the result of | |
433 | - * the operation. | |
434 | - * | |
435 | - * This method constructs the object asynchronously, for the synchronous and blocking version | |
436 | - * use polkit_unix_session_new_for_process_sync(). | |
437 | - **/ | |
438 | -void | |
439 | -polkit_unix_session_new_for_process (gint pid, | |
440 | - GCancellable *cancellable, | |
441 | - GAsyncReadyCallback callback, | |
442 | - gpointer user_data) | |
443 | -{ | |
444 | - g_async_initable_new_async (POLKIT_TYPE_UNIX_SESSION, | |
445 | - G_PRIORITY_DEFAULT, | |
446 | - cancellable, | |
447 | - callback, | |
448 | - user_data, | |
449 | - "pid", pid, | |
450 | - NULL); | |
451 | -} | |
452 | - | |
453 | -/** | |
454 | - * polkit_unix_session_new_for_process_finish: | |
455 | - * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to polkit_unix_session_new_for_process(). | |
456 | - * @error: (allow-none): Return location for error. | |
457 | - * | |
458 | - * Finishes constructing a #PolkitSubject for a process id. | |
459 | - * | |
460 | - * Returns: (transfer full) (allow-none): A #PolkitUnixSession for the @pid passed to | |
461 | - * polkit_unix_session_new_for_process() or %NULL if @error is | |
462 | - * set. Free with g_object_unref(). | |
463 | - **/ | |
464 | -PolkitSubject * | |
465 | -polkit_unix_session_new_for_process_finish (GAsyncResult *res, | |
466 | - GError **error) | |
467 | -{ | |
468 | - GObject *object; | |
469 | - GObject *source_object; | |
470 | - | |
471 | - source_object = g_async_result_get_source_object (res); | |
472 | - g_assert (source_object != NULL); | |
473 | - | |
474 | - object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), | |
475 | - res, | |
476 | - error); | |
477 | - g_object_unref (source_object); | |
478 | - | |
479 | - if (object != NULL) | |
480 | - return POLKIT_SUBJECT (object); | |
481 | - else | |
482 | - return NULL; | |
483 | -} | |
484 | - | |
485 | - | |
486 | -/** | |
487 | - * polkit_unix_session_new_for_process_sync: | |
488 | - * @pid: The process id of the process to get the session for. | |
489 | - * @cancellable: (allow-none): A #GCancellable or %NULL. | |
490 | - * @error: (allow-none): Return location for error. | |
491 | - * | |
492 | - * Creates a new #PolkitUnixSession for the process with process id @pid. | |
493 | - * | |
494 | - * This is a synchronous call - the calling thread is blocked until a | |
495 | - * reply is received. For the asynchronous version, see | |
496 | - * polkit_unix_session_new_for_process(). | |
497 | - * | |
498 | - * Returns: (allow-none) (transfer full): A #PolkitUnixSession for | |
499 | - * @pid or %NULL if @error is set. Free with g_object_unref(). | |
500 | - **/ | |
501 | -PolkitSubject * | |
502 | -polkit_unix_session_new_for_process_sync (gint pid, | |
503 | - GCancellable *cancellable, | |
504 | - GError **error) | |
505 | -{ | |
506 | - return POLKIT_SUBJECT (g_initable_new (POLKIT_TYPE_UNIX_SESSION, | |
507 | - cancellable, | |
508 | - error, | |
509 | - "pid", pid, | |
510 | - NULL)); | |
511 | -} | |
512 | - | |
513 | -static guint | |
514 | -polkit_unix_session_hash (PolkitSubject *subject) | |
515 | -{ | |
516 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject); | |
517 | - | |
518 | - return g_str_hash (session->session_id); | |
519 | -} | |
520 | - | |
521 | -static gboolean | |
522 | -polkit_unix_session_equal (PolkitSubject *a, | |
523 | - PolkitSubject *b) | |
524 | -{ | |
525 | - PolkitUnixSession *session_a; | |
526 | - PolkitUnixSession *session_b; | |
527 | - | |
528 | - session_a = POLKIT_UNIX_SESSION (a); | |
529 | - session_b = POLKIT_UNIX_SESSION (b); | |
530 | - | |
531 | - return g_strcmp0 (session_a->session_id, session_b->session_id) == 0; | |
532 | -} | |
533 | - | |
534 | -static gchar * | |
535 | -polkit_unix_session_to_string (PolkitSubject *subject) | |
536 | -{ | |
537 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject); | |
538 | - | |
539 | - return g_strdup_printf ("unix-session:%s", session->session_id); | |
540 | -} | |
541 | - | |
542 | -static gboolean | |
543 | -polkit_unix_session_exists_sync (PolkitSubject *subject, | |
a7e49982 MB |
544 | - GCancellable *cancellable, |
545 | - GError **error) | |
186114f9 ŁK |
546 | -{ |
547 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject); | |
a7e49982 | 548 | - gboolean ret = FALSE; |
186114f9 ŁK |
549 | - uid_t uid; |
550 | - | |
a7e49982 MB |
551 | - if (sd_session_get_uid (session->session_id, &uid) == 0) |
552 | - ret = TRUE; | |
186114f9 ŁK |
553 | - |
554 | - return ret; | |
555 | -} | |
556 | - | |
557 | -static void | |
558 | -exists_in_thread_func (GSimpleAsyncResult *res, | |
559 | - GObject *object, | |
560 | - GCancellable *cancellable) | |
561 | -{ | |
562 | - GError *error; | |
563 | - error = NULL; | |
564 | - if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (object), | |
565 | - cancellable, | |
566 | - &error)) | |
567 | - { | |
568 | - g_simple_async_result_set_from_error (res, error); | |
569 | - g_error_free (error); | |
570 | - } | |
571 | -} | |
572 | - | |
573 | -static void | |
574 | -polkit_unix_session_exists (PolkitSubject *subject, | |
575 | - GCancellable *cancellable, | |
576 | - GAsyncReadyCallback callback, | |
577 | - gpointer user_data) | |
578 | -{ | |
579 | - GSimpleAsyncResult *simple; | |
580 | - | |
581 | - g_return_if_fail (POLKIT_IS_UNIX_SESSION (subject)); | |
582 | - | |
583 | - simple = g_simple_async_result_new (G_OBJECT (subject), | |
584 | - callback, | |
585 | - user_data, | |
586 | - polkit_unix_session_exists); | |
587 | - g_simple_async_result_run_in_thread (simple, | |
588 | - exists_in_thread_func, | |
589 | - G_PRIORITY_DEFAULT, | |
590 | - cancellable); | |
591 | - g_object_unref (simple); | |
592 | -} | |
593 | - | |
594 | -static gboolean | |
595 | -polkit_unix_session_exists_finish (PolkitSubject *subject, | |
596 | - GAsyncResult *res, | |
597 | - GError **error) | |
598 | -{ | |
599 | - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res); | |
600 | - gboolean ret; | |
601 | - | |
602 | - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_session_exists); | |
603 | - | |
604 | - ret = FALSE; | |
605 | - | |
606 | - if (g_simple_async_result_propagate_error (simple, error)) | |
607 | - goto out; | |
608 | - | |
609 | - ret = g_simple_async_result_get_op_res_gboolean (simple); | |
610 | - | |
611 | - out: | |
612 | - return ret; | |
613 | -} | |
614 | - | |
615 | -static void | |
616 | -subject_iface_init (PolkitSubjectIface *subject_iface) | |
617 | -{ | |
618 | - subject_iface->hash = polkit_unix_session_hash; | |
619 | - subject_iface->equal = polkit_unix_session_equal; | |
620 | - subject_iface->to_string = polkit_unix_session_to_string; | |
621 | - subject_iface->exists = polkit_unix_session_exists; | |
622 | - subject_iface->exists_finish = polkit_unix_session_exists_finish; | |
623 | - subject_iface->exists_sync = polkit_unix_session_exists_sync; | |
624 | -} | |
625 | - | |
626 | -static gboolean | |
627 | -polkit_unix_session_initable_init (GInitable *initable, | |
628 | - GCancellable *cancellable, | |
629 | - GError **error) | |
630 | -{ | |
631 | - PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable); | |
a7e49982 MB |
632 | - gboolean ret = FALSE; |
633 | - char *s; | |
c5786473 | 634 | - uid_t uid; |
186114f9 ŁK |
635 | - |
636 | - if (session->session_id != NULL) | |
637 | - { | |
638 | - /* already set, nothing to do */ | |
639 | - ret = TRUE; | |
640 | - goto out; | |
641 | - } | |
642 | - | |
a7e49982 MB |
643 | - if (sd_pid_get_session (session->pid, &s) == 0) |
644 | - { | |
645 | - session->session_id = g_strdup (s); | |
646 | - free (s); | |
647 | - ret = TRUE; | |
648 | - goto out; | |
649 | - } | |
650 | - | |
c5786473 JB |
651 | - /* Now do process -> uid -> graphical session (systemd version 213)*/ |
652 | - if (sd_pid_get_owner_uid (session->pid, &uid) < 0) | |
653 | - goto error; | |
654 | - | |
655 | - if (sd_uid_get_display (uid, &s) >= 0) | |
656 | - { | |
657 | - session->session_id = g_strdup (s); | |
658 | - free (s); | |
659 | - ret = TRUE; | |
660 | - goto out; | |
661 | - } | |
662 | - | |
663 | -error: | |
a7e49982 MB |
664 | - g_set_error (error, |
665 | - POLKIT_ERROR, | |
666 | - POLKIT_ERROR_FAILED, | |
667 | - "No session for pid %d", | |
668 | - (gint) session->pid); | |
186114f9 ŁK |
669 | - |
670 | -out: | |
671 | - return ret; | |
672 | -} | |
673 | - | |
674 | -static void | |
675 | -initable_iface_init (GInitableIface *initable_iface) | |
676 | -{ | |
677 | - initable_iface->init = polkit_unix_session_initable_init; | |
678 | -} | |
679 | - | |
680 | -static void | |
681 | -async_initable_iface_init (GAsyncInitableIface *async_initable_iface) | |
682 | -{ | |
683 | - /* use default implementation to run GInitable code in a thread */ | |
684 | -} | |
fbe373fc JP |
685 | --- polkit-v.121/src/polkitbackend/polkitbackendcommon.h.orig 2022-07-11 10:46:06.000000000 +0200 |
686 | +++ polkit-v.121/src/polkitbackend/polkitbackendcommon.h 2022-07-13 23:30:49.653425289 +0200 | |
687 | @@ -47,6 +47,7 @@ | |
9c761957 JB |
688 | #include <polkit/polkitprivate.h> |
689 | ||
690 | #ifdef HAVE_LIBSYSTEMD | |
691 | +#include <systemd/sd-daemon.h> | |
692 | #include <systemd/sd-login.h> | |
693 | #endif /* HAVE_LIBSYSTEMD */ | |
694 | ||
dd341f56 JB |
695 | --- polkit-124/src/polkitbackend/polkitbackendjsauthority.cpp.orig 2024-01-17 18:40:50.824301827 +0100 |
696 | +++ polkit-124/src/polkitbackend/polkitbackendjsauthority.cpp 2024-01-17 19:58:17.065797643 +0100 | |
697 | @@ -624,6 +624,8 @@ subject_to_jsval (PolkitBackendJsAuthori | |
698 | pidfd = polkit_unix_process_get_pidfd (POLKIT_UNIX_PROCESS (process)); | |
9c761957 JB |
699 | |
700 | #ifdef HAVE_LIBSYSTEMD | |
701 | + if (sd_booted () > 0) | |
702 | + { | |
dd341f56 JB |
703 | #if HAVE_SD_PIDFD_GET_SESSION |
704 | if (pidfd >= 0) | |
705 | sd_pidfd_get_session (pidfd, &session_str); | |
706 | @@ -632,6 +634,7 @@ subject_to_jsval (PolkitBackendJsAuthori | |
707 | sd_pid_get_session (pid_early, &session_str); | |
708 | if (session_str) | |
709 | sd_session_get_seat (session_str, &seat_str); | |
9c761957 JB |
710 | + } |
711 | #endif /* HAVE_LIBSYSTEMD */ | |
712 | ||
713 | g_assert (POLKIT_IS_UNIX_USER (user_for_subject)); | |
dd341f56 JB |
714 | --- polkit-124/src/polkitbackend/polkitbackendsessionmonitor.c.orig 2024-01-17 16:43:53.000000000 +0100 |
715 | +++ polkit-124/src/polkitbackend/polkitbackendsessionmonitor.c 2024-01-17 22:05:25.914468626 +0100 | |
9c761957 JB |
716 | @@ -26,6 +26,12 @@ |
717 | #include <string.h> | |
718 | #include <glib/gstdio.h> | |
186114f9 | 719 | |
77f30838 | 720 | +#ifdef HAVE_LIBSYSTEMD |
a7e49982 | 721 | +# include <stdlib.h> |
186114f9 ŁK |
722 | +# include <systemd/sd-daemon.h> |
723 | +# include <systemd/sd-login.h> | |
9c761957 | 724 | +#endif /* HAVE_LIBSYSTEMD */ |
186114f9 | 725 | + |
9c761957 | 726 | #include <polkit/polkit.h> |
4e85edc6 | 727 | #include <polkit/polkitprivate.h> |
9c761957 | 728 | #include "polkitbackendsessionmonitor.h" |
4e85edc6 | 729 | @@ -40,6 +46,88 @@ |
9c761957 JB |
730 | * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions. |
731 | */ | |
186114f9 | 732 | |
77f30838 | 733 | +#ifdef HAVE_LIBSYSTEMD |
9c761957 JB |
734 | +typedef struct |
735 | +{ | |
736 | + GSource source; | |
737 | + GPollFD pollfd; | |
738 | + sd_login_monitor *monitor; | |
739 | +} SdSource; | |
740 | + | |
741 | +static gboolean | |
742 | +sd_source_prepare (GSource *source, | |
743 | + gint *timeout) | |
744 | +{ | |
745 | + *timeout = -1; | |
746 | + return FALSE; | |
747 | +} | |
748 | + | |
749 | +static gboolean | |
750 | +sd_source_check (GSource *source) | |
751 | +{ | |
752 | + SdSource *sd_source = (SdSource *)source; | |
753 | + | |
754 | + return sd_source->pollfd.revents != 0; | |
755 | +} | |
756 | + | |
757 | +static gboolean | |
758 | +sd_source_dispatch (GSource *source, | |
759 | + GSourceFunc callback, | |
760 | + gpointer user_data) | |
761 | + | |
762 | +{ | |
763 | + SdSource *sd_source = (SdSource *)source; | |
764 | + gboolean ret; | |
765 | + | |
766 | + g_warn_if_fail (callback != NULL); | |
767 | + | |
768 | + ret = (*callback) (user_data); | |
769 | + | |
770 | + sd_login_monitor_flush (sd_source->monitor); | |
771 | + | |
772 | + return ret; | |
773 | +} | |
774 | + | |
775 | +static void | |
776 | +sd_source_finalize (GSource *source) | |
777 | +{ | |
778 | + SdSource *sd_source = (SdSource*)source; | |
779 | + | |
780 | + sd_login_monitor_unref (sd_source->monitor); | |
781 | +} | |
782 | + | |
783 | +static GSourceFuncs sd_source_funcs = { | |
784 | + sd_source_prepare, | |
785 | + sd_source_check, | |
786 | + sd_source_dispatch, | |
787 | + sd_source_finalize | |
788 | +}; | |
789 | + | |
790 | +static GSource * | |
791 | +sd_source_new (void) | |
792 | +{ | |
793 | + GSource *source; | |
794 | + SdSource *sd_source; | |
795 | + int ret; | |
796 | + | |
797 | + source = g_source_new (&sd_source_funcs, sizeof (SdSource)); | |
798 | + sd_source = (SdSource *)source; | |
799 | + | |
800 | + if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0) | |
186114f9 | 801 | + { |
9c761957 | 802 | + g_printerr ("Error getting login monitor: %d", ret); |
186114f9 ŁK |
803 | + } |
804 | + else | |
b20b0410 | 805 | + { |
9c761957 JB |
806 | + sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor); |
807 | + sd_source->pollfd.events = G_IO_IN; | |
808 | + g_source_add_poll (source, &sd_source->pollfd); | |
b20b0410 | 809 | + } |
a7e49982 | 810 | + |
9c761957 JB |
811 | + return source; |
812 | +} | |
813 | +#endif /* HAVE_LIBSYSTEMD */ | |
814 | + | |
815 | struct _PolkitBackendSessionMonitor | |
816 | { | |
817 | GObject parent_instance; | |
dd341f56 | 818 | @@ -49,6 +137,10 @@ struct _PolkitBackendSessionMonitor |
9c761957 JB |
819 | GKeyFile *database; |
820 | GFileMonitor *database_monitor; | |
821 | time_t database_mtime; | |
822 | + | |
823 | +#ifdef HAVE_LIBSYSTEMD | |
824 | + GSource *sd_source; | |
825 | +#endif /* HAVE_LIBSYSTEMD */ | |
826 | }; | |
186114f9 | 827 | |
9c761957 | 828 | struct _PolkitBackendSessionMonitorClass |
dd341f56 | 829 | @@ -71,6 +163,18 @@ G_DEFINE_TYPE (PolkitBackendSessionMonit |
a7e49982 | 830 | |
9c761957 | 831 | /* ---------------------------------------------------------------------------------------------------- */ |
186114f9 | 832 | |
9c761957 JB |
833 | +#ifdef HAVE_LIBSYSTEMD |
834 | +static gboolean | |
835 | +sessions_changed (gpointer user_data) | |
836 | +{ | |
837 | + PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data); | |
838 | + | |
839 | + g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0); | |
840 | + | |
841 | + return TRUE; | |
842 | +} | |
843 | +#endif /* HAVE_LIBSYSTEMD */ | |
844 | + | |
845 | static gboolean | |
846 | reload_database (PolkitBackendSessionMonitor *monitor, | |
847 | GError **error) | |
dd341f56 | 848 | @@ -177,31 +281,47 @@ polkit_backend_session_monitor_init (Pol |
9c761957 | 849 | g_error_free (error); |
186114f9 ŁK |
850 | } |
851 | ||
9c761957 JB |
852 | - error = NULL; |
853 | - if (!ensure_database (monitor, &error)) | |
77f30838 | 854 | +#ifdef HAVE_LIBSYSTEMD |
9c761957 JB |
855 | + monitor->sd_source = NULL; |
856 | + | |
186114f9 | 857 | + if (sd_booted () > 0) |
9c761957 JB |
858 | { |
859 | - g_printerr ("Error loading " CKDB_PATH ": %s", error->message); | |
860 | - g_error_free (error); | |
861 | + monitor->sd_source = sd_source_new (); | |
862 | + g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL); | |
863 | + g_source_attach (monitor->sd_source, NULL); | |
a7e49982 | 864 | + |
9c761957 JB |
865 | + monitor->database_monitor = NULL; |
866 | + monitor->database = NULL; | |
867 | } | |
a7e49982 | 868 | + else |
77f30838 | 869 | +#endif /* HAVE_LIBSYSTEMD */ |
a7e49982 | 870 | + { |
9c761957 JB |
871 | + error = NULL; |
872 | + if (!ensure_database (monitor, &error)) | |
873 | + { | |
874 | + g_printerr ("Error loading " CKDB_PATH ": %s", error->message); | |
875 | + g_error_free (error); | |
876 | + } | |
186114f9 | 877 | |
9c761957 JB |
878 | - error = NULL; |
879 | - file = g_file_new_for_path (CKDB_PATH); | |
880 | - monitor->database_monitor = g_file_monitor_file (file, | |
881 | + error = NULL; | |
882 | + file = g_file_new_for_path (CKDB_PATH); | |
883 | + monitor->database_monitor = g_file_monitor_file (file, | |
884 | G_FILE_MONITOR_NONE, | |
885 | NULL, | |
886 | &error); | |
887 | - g_object_unref (file); | |
888 | - if (monitor->database_monitor == NULL) | |
889 | - { | |
890 | - g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message); | |
891 | - g_error_free (error); | |
892 | - } | |
893 | - else | |
894 | - { | |
895 | - g_signal_connect (monitor->database_monitor, | |
896 | - "changed", | |
897 | - G_CALLBACK (on_file_monitor_changed), | |
898 | - monitor); | |
899 | + g_object_unref (file); | |
900 | + if (monitor->database_monitor == NULL) | |
901 | + { | |
902 | + g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message); | |
903 | + g_error_free (error); | |
904 | + } | |
905 | + else | |
906 | + { | |
907 | + g_signal_connect (monitor->database_monitor, | |
908 | + "changed", | |
909 | + G_CALLBACK (on_file_monitor_changed), | |
910 | + monitor); | |
911 | + } | |
912 | } | |
913 | } | |
186114f9 | 914 | |
dd341f56 | 915 | @@ -219,6 +339,12 @@ polkit_backend_session_monitor_finalize |
9c761957 JB |
916 | if (monitor->database != NULL) |
917 | g_key_file_free (monitor->database); | |
b20b0410 | 918 | |
9c761957 JB |
919 | + if (monitor->sd_source != NULL) |
920 | + { | |
921 | + g_source_destroy (monitor->sd_source); | |
922 | + g_source_unref (monitor->sd_source); | |
923 | + } | |
924 | + | |
925 | if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL) | |
926 | G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object); | |
927 | } | |
dd341f56 | 928 | @@ -332,6 +458,26 @@ polkit_backend_session_monitor_get_user_ |
77f30838 | 929 | } |
9c761957 | 930 | else if (POLKIT_IS_UNIX_SESSION (subject)) |
77f30838 | 931 | { |
9c761957 JB |
932 | +#ifdef HAVE_LIBSYSTEMD |
933 | + if (monitor->sd_source != NULL) | |
4e85edc6 JB |
934 | + { |
935 | + uid_t uid; | |
936 | + | |
937 | + if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) | |
938 | + { | |
939 | + g_set_error (error, | |
940 | + POLKIT_ERROR, | |
941 | + POLKIT_ERROR_FAILED, | |
942 | + "Error getting uid for session"); | |
943 | + goto out; | |
944 | + } | |
945 | + | |
946 | + ret = polkit_unix_user_new (uid); | |
947 | + matches = TRUE; | |
948 | + } | |
9c761957 JB |
949 | + else |
950 | +#endif /* HAVE_LIBSYSTEMD */ | |
4e85edc6 JB |
951 | + { |
952 | gint uid; | |
953 | gchar *group; | |
954 | ||
dd341f56 | 955 | @@ -354,6 +500,7 @@ polkit_backend_session_monitor_get_user_ |
9c761957 JB |
956 | |
957 | ret = polkit_unix_user_new (uid); | |
4e85edc6 JB |
958 | matches = TRUE; |
959 | + } | |
9c761957 | 960 | } |
4e85edc6 JB |
961 | |
962 | out: | |
dd341f56 | 963 | @@ -379,35 +526,35 @@ polkit_backend_session_monitor_get_sessi |
9c761957 JB |
964 | PolkitSubject *subject, |
965 | GError **error) | |
966 | { | |
967 | - PolkitSubject *session; | |
186114f9 | 968 | - |
9c761957 JB |
969 | - session = NULL; |
970 | + PolkitSubject *session = NULL; | |
dd341f56 | 971 | + PolkitUnixProcess *process = NULL; |
9c761957 | 972 | + pid_t pid; |
dd341f56 JB |
973 | +#ifdef HAVE_LIBSYSTEMD |
974 | + PolkitUnixProcess *tmp_process = NULL; | |
975 | +#if HAVE_SD_UID_GET_DISPLAY | |
976 | + uid_t uid; | |
977 | +#endif | |
978 | +#if HAVE_SD_PIDFD_GET_SESSION | |
979 | + int pidfd; | |
980 | +#endif | |
981 | +#endif | |
9c761957 JB |
982 | |
983 | if (POLKIT_IS_UNIX_PROCESS (subject)) | |
186114f9 | 984 | - { |
9c761957 JB |
985 | - const gchar *session_id; |
986 | - GVariant *result; | |
987 | - result = g_dbus_connection_call_sync (monitor->system_bus, | |
988 | - "org.freedesktop.ConsoleKit", | |
989 | - "/org/freedesktop/ConsoleKit/Manager", | |
990 | - "org.freedesktop.ConsoleKit.Manager", | |
991 | - "GetSessionForUnixProcess", | |
992 | - g_variant_new ("(u)", polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))), | |
993 | - G_VARIANT_TYPE ("(o)"), | |
994 | - G_DBUS_CALL_FLAGS_NONE, | |
995 | - -1, /* timeout_msec */ | |
996 | - NULL, /* GCancellable */ | |
997 | - error); | |
998 | - if (result == NULL) | |
999 | - goto out; | |
1000 | - g_variant_get (result, "(&o)", &session_id); | |
1001 | - session = polkit_unix_session_new (session_id); | |
1002 | - g_variant_unref (result); | |
dd341f56 JB |
1003 | + { /* We already have a process */ /* now do process -> pid */ |
1004 | + process = POLKIT_UNIX_PROCESS (subject); | |
9c761957 JB |
1005 | } |
1006 | else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) | |
1007 | - { | |
1008 | - guint32 pid; | |
1009 | - const gchar *session_id; | |
1010 | + { /* Convert bus name to process / pid */ | |
1011 | +#ifdef HAVE_LIBSYSTEMD | |
1012 | + if (monitor->sd_source != NULL) | |
1013 | + { | |
dd341f56 JB |
1014 | + tmp_process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME(subject), NULL, error); |
1015 | + if (!tmp_process) | |
1016 | + goto out; | |
1017 | + process = tmp_process; | |
1018 | + } else | |
9c761957 JB |
1019 | +#endif |
1020 | + { | |
1021 | GVariant *result; | |
1022 | ||
1023 | result = g_dbus_connection_call_sync (monitor->system_bus, | |
dd341f56 | 1024 | @@ -425,23 +572,7 @@ polkit_backend_session_monitor_get_sessi |
9c761957 JB |
1025 | goto out; |
1026 | g_variant_get (result, "(u)", &pid); | |
1027 | g_variant_unref (result); | |
186114f9 | 1028 | - |
9c761957 JB |
1029 | - result = g_dbus_connection_call_sync (monitor->system_bus, |
1030 | - "org.freedesktop.ConsoleKit", | |
1031 | - "/org/freedesktop/ConsoleKit/Manager", | |
1032 | - "org.freedesktop.ConsoleKit.Manager", | |
1033 | - "GetSessionForUnixProcess", | |
1034 | - g_variant_new ("(u)", pid), | |
1035 | - G_VARIANT_TYPE ("(o)"), | |
1036 | - G_DBUS_CALL_FLAGS_NONE, | |
1037 | - -1, /* timeout_msec */ | |
1038 | - NULL, /* GCancellable */ | |
1039 | - error); | |
1040 | - if (result == NULL) | |
1041 | - goto out; | |
1042 | - g_variant_get (result, "(&o)", &session_id); | |
1043 | - session = polkit_unix_session_new (session_id); | |
1044 | - g_variant_unref (result); | |
1045 | + } | |
1046 | } | |
1047 | else | |
1048 | { | |
dd341f56 | 1049 | @@ -450,9 +581,97 @@ polkit_backend_session_monitor_get_sessi |
9c761957 JB |
1050 | POLKIT_ERROR_NOT_SUPPORTED, |
1051 | "Cannot get user for subject of type %s", | |
1052 | g_type_name (G_TYPE_FROM_INSTANCE (subject))); | |
1053 | + goto out; | |
1054 | } | |
1055 | ||
9c761957 JB |
1056 | +#ifdef HAVE_LIBSYSTEMD |
1057 | + if (monitor->sd_source != NULL) | |
1058 | + { | |
dd341f56 JB |
1059 | + char *session_id; |
1060 | + | |
1061 | +#if HAVE_SD_PIDFD_GET_SESSION | |
1062 | + /* First try to get the session from the pidfd (systemd version 253) */ | |
1063 | + pidfd = polkit_unix_process_get_pidfd (process); | |
1064 | + if (pidfd >= 0) | |
1065 | + { | |
1066 | + if (sd_pidfd_get_session (pidfd, &session_id) >= 0) | |
1067 | + { | |
1068 | + session = polkit_unix_session_new (session_id); | |
1069 | + free (session_id); | |
1070 | + goto out; | |
1071 | + } | |
1072 | + } | |
1073 | +#endif | |
1074 | + | |
1075 | + /* Now do process -> pid -> same session */ | |
1076 | + g_assert (process != NULL); | |
1077 | + pid = polkit_unix_process_get_pid (process); | |
9c761957 | 1078 | + if (sd_pid_get_session (pid, &session_id) >= 0) |
dd341f56 | 1079 | + { |
9c761957 JB |
1080 | + session = polkit_unix_session_new (session_id); |
1081 | + free (session_id); | |
1082 | + goto out; | |
dd341f56 JB |
1083 | + } |
1084 | + | |
1085 | +#if HAVE_SD_PIDFD_GET_SESSION | |
1086 | + /* Now do process fd -> uid -> graphical session (systemd version 253) */ | |
1087 | + pidfd = polkit_unix_process_get_pidfd (process); | |
1088 | + if (pidfd >= 0) | |
1089 | + { | |
1090 | + if (sd_pidfd_get_owner_uid (pidfd, &uid) < 0) | |
1091 | + goto out; | |
1092 | + | |
1093 | + if (sd_uid_get_display (uid, &session_id) >= 0) | |
1094 | + { | |
1095 | + session = polkit_unix_session_new (session_id); | |
1096 | + free (session_id); | |
1097 | + goto out; | |
1098 | + } | |
1099 | + } | |
1100 | +#endif | |
1101 | + | |
9c761957 | 1102 | +#if HAVE_SD_UID_GET_DISPLAY |
dd341f56 JB |
1103 | + /* Now do process -> uid -> graphical session (systemd version 213)*/ |
1104 | + if (sd_pid_get_owner_uid (pid, &uid) < 0) | |
9c761957 JB |
1105 | + goto out; |
1106 | + | |
1107 | + if (sd_uid_get_display (uid, &session_id) >= 0) | |
1108 | + { | |
1109 | + session = polkit_unix_session_new (session_id); | |
1110 | + free (session_id); | |
1111 | + goto out; | |
1112 | + } | |
1113 | +#endif | |
1114 | + } | |
1115 | + else | |
1116 | +#endif /* HAVE_LIBSYSTEMD */ | |
dd341f56 | 1117 | + /* Now do [process ->] pid -> same session */ |
9c761957 JB |
1118 | + { |
1119 | + gchar *session_id; | |
1120 | + GVariant *result; | |
dd341f56 JB |
1121 | + if (process != NULL) |
1122 | + pid = polkit_unix_process_get_pid (process); | |
9c761957 JB |
1123 | + result = g_dbus_connection_call_sync (monitor->system_bus, |
1124 | + "org.freedesktop.ConsoleKit", | |
1125 | + "/org/freedesktop/ConsoleKit/Manager", | |
1126 | + "org.freedesktop.ConsoleKit.Manager", | |
1127 | + "GetSessionForUnixProcess", | |
1128 | + g_variant_new ("(u)", pid), | |
1129 | + G_VARIANT_TYPE ("(o)"), | |
1130 | + G_DBUS_CALL_FLAGS_NONE, | |
1131 | + -1, /* timeout_msec */ | |
1132 | + NULL, /* GCancellable */ | |
1133 | + error); | |
1134 | + if (result == NULL) | |
1135 | + goto out; | |
1136 | + g_variant_get (result, "(&o)", &session_id); | |
1137 | + session = polkit_unix_session_new (session_id); | |
1138 | + g_variant_unref (result); | |
1139 | + } | |
1140 | + | |
1141 | out: | |
dd341f56 JB |
1142 | + if (tmp_process != NULL) |
1143 | + g_object_unref (tmp_process); | |
9c761957 JB |
1144 | |
1145 | return session; | |
dd341f56 JB |
1146 | } |
1147 | @@ -502,7 +721,22 @@ gboolean | |
9c761957 JB |
1148 | polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor, |
1149 | PolkitSubject *session) | |
1150 | { | |
1151 | - return get_boolean (monitor, session, "is_local"); | |
1152 | +#ifdef HAVE_LIBSYSTEMD | |
1153 | + if (monitor->sd_source != NULL) | |
1154 | + { | |
1155 | + char *seat; | |
1156 | + | |
1157 | + if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat)) | |
1158 | + { | |
1159 | + free (seat); | |
1160 | + return TRUE; | |
1161 | + } | |
1162 | + | |
1163 | + return FALSE; | |
1164 | + } | |
1165 | + else | |
1166 | +#endif /* HAVE_LIBSYSTEMD */ | |
1167 | + return get_boolean (monitor, session, "is_local"); | |
1168 | } | |
1169 | ||
1170 | ||
dd341f56 | 1171 | @@ -510,6 +744,44 @@ gboolean |
9c761957 JB |
1172 | polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor, |
1173 | PolkitSubject *session) | |
1174 | { | |
1175 | - return get_boolean (monitor, session, "is_active"); | |
1176 | +#ifdef HAVE_LIBSYSTEMD | |
1177 | + if (monitor->sd_source != NULL) | |
1178 | + { | |
1179 | + const char *session_id; | |
1180 | + char *state; | |
1181 | + uid_t uid; | |
1182 | + gboolean is_active = FALSE; | |
1183 | + | |
1184 | + session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)); | |
1185 | + | |
1186 | + g_debug ("Checking whether session %s is active.", session_id); | |
1187 | + | |
1188 | + /* Check whether *any* of the user's current sessions are active. */ | |
1189 | + if (sd_session_get_uid (session_id, &uid) < 0) | |
1190 | + goto fallback; | |
1191 | + | |
1192 | + g_debug ("Session %s has UID %u.", session_id, uid); | |
1193 | + | |
1194 | + if (sd_uid_get_state (uid, &state) < 0) | |
1195 | + goto fallback; | |
1196 | + | |
1197 | + g_debug ("UID %u has state %s.", uid, state); | |
1198 | + | |
1199 | + is_active = (g_strcmp0 (state, "active") == 0); | |
1200 | + free (state); | |
1201 | + | |
1202 | + return is_active; | |
1203 | + | |
1204 | +fallback: | |
1205 | + /* Fall back to checking the session. This is not ideal, since the user | |
1206 | + * might have multiple sessions, and we cannot guarantee to have chosen | |
1207 | + * the active one. | |
1208 | + * | |
1209 | + * See: https://bugs.freedesktop.org/show_bug.cgi?id=76358. */ | |
1210 | + return sd_session_is_active (session_id); | |
1211 | + } | |
1212 | + else | |
1213 | +#endif /* HAVE_LIBSYSTEMD */ | |
1214 | + return get_boolean (monitor, session, "is_active"); | |
1215 | } | |
1216 | ||
dd341f56 JB |
1217 | --- polkit-124/src/polkitbackend/polkitbackendsessionmonitor-systemd.c.orig 2024-01-17 18:40:50.827635142 +0100 |
1218 | +++ polkit-124/src/polkitbackend/polkitbackendsessionmonitor-systemd.c 1970-01-01 01:00:00.000000000 +0100 | |
1219 | @@ -1,487 +0,0 @@ | |
9c761957 JB |
1220 | -/* |
1221 | - * Copyright (C) 2011 Red Hat, Inc. | |
1222 | - * | |
1223 | - * This library is free software; you can redistribute it and/or | |
1224 | - * modify it under the terms of the GNU Lesser General Public | |
1225 | - * License as published by the Free Software Foundation; either | |
1226 | - * version 2 of the License, or (at your option) any later version. | |
1227 | - * | |
1228 | - * This library is distributed in the hope that it will be useful, | |
1229 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1230 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1231 | - * Lesser General Public License for more details. | |
1232 | - * | |
1233 | - * You should have received a copy of the GNU Lesser General | |
1234 | - * Public License along with this library; if not, write to the | |
1235 | - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
1236 | - * Boston, MA 02111-1307, USA. | |
1237 | - * | |
1238 | - * Author: Matthias Clasen | |
1239 | - */ | |
186114f9 | 1240 | - |
9c761957 JB |
1241 | -#include "config.h" |
1242 | -#include <errno.h> | |
1243 | -#include <pwd.h> | |
1244 | -#include <grp.h> | |
1245 | -#include <string.h> | |
1246 | -#include <glib/gstdio.h> | |
1247 | -#include <systemd/sd-login.h> | |
1248 | -#include <stdlib.h> | |
186114f9 | 1249 | - |
9c761957 | 1250 | -#include <polkit/polkit.h> |
4e85edc6 | 1251 | -#include <polkit/polkitprivate.h> |
9c761957 | 1252 | -#include "polkitbackendsessionmonitor.h" |
186114f9 | 1253 | - |
9c761957 JB |
1254 | -/* <internal> |
1255 | - * SECTION:polkitbackendsessionmonitor | |
1256 | - * @title: PolkitBackendSessionMonitor | |
1257 | - * @short_description: Monitor sessions | |
1258 | - * | |
1259 | - * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions. | |
1260 | - */ | |
186114f9 | 1261 | - |
9c761957 JB |
1262 | -typedef struct |
1263 | -{ | |
1264 | - GSource source; | |
1265 | - GPollFD pollfd; | |
1266 | - sd_login_monitor *monitor; | |
1267 | -} SdSource; | |
186114f9 ŁK |
1268 | - |
1269 | -static gboolean | |
9c761957 JB |
1270 | -sd_source_prepare (GSource *source, |
1271 | - gint *timeout) | |
186114f9 | 1272 | -{ |
9c761957 JB |
1273 | - *timeout = -1; |
1274 | - return FALSE; | |
1275 | -} | |
1276 | - | |
1277 | -static gboolean | |
1278 | -sd_source_check (GSource *source) | |
1279 | -{ | |
1280 | - SdSource *sd_source = (SdSource *)source; | |
1281 | - | |
1282 | - return sd_source->pollfd.revents != 0; | |
1283 | -} | |
1284 | - | |
1285 | -static gboolean | |
1286 | -sd_source_dispatch (GSource *source, | |
1287 | - GSourceFunc callback, | |
1288 | - gpointer user_data) | |
1289 | - | |
1290 | -{ | |
1291 | - SdSource *sd_source = (SdSource *)source; | |
1292 | - gboolean ret; | |
1293 | - | |
1294 | - g_warn_if_fail (callback != NULL); | |
1295 | - | |
1296 | - ret = (*callback) (user_data); | |
1297 | - | |
1298 | - sd_login_monitor_flush (sd_source->monitor); | |
1299 | - | |
1300 | - return ret; | |
1301 | -} | |
1302 | - | |
1303 | -static void | |
1304 | -sd_source_finalize (GSource *source) | |
1305 | -{ | |
1306 | - SdSource *sd_source = (SdSource*)source; | |
1307 | - | |
1308 | - sd_login_monitor_unref (sd_source->monitor); | |
1309 | -} | |
1310 | - | |
1311 | -static GSourceFuncs sd_source_funcs = { | |
1312 | - sd_source_prepare, | |
1313 | - sd_source_check, | |
1314 | - sd_source_dispatch, | |
1315 | - sd_source_finalize | |
1316 | -}; | |
1317 | - | |
1318 | -static GSource * | |
1319 | -sd_source_new (void) | |
1320 | -{ | |
1321 | - GSource *source; | |
1322 | - SdSource *sd_source; | |
1323 | - int ret; | |
1324 | - | |
1325 | - source = g_source_new (&sd_source_funcs, sizeof (SdSource)); | |
1326 | - sd_source = (SdSource *)source; | |
1327 | - | |
1328 | - if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0) | |
1329 | - { | |
1330 | - g_printerr ("Error getting login monitor: %d", ret); | |
1331 | - } | |
1332 | - else | |
1333 | - { | |
1334 | - sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor); | |
1335 | - sd_source->pollfd.events = G_IO_IN; | |
1336 | - g_source_add_poll (source, &sd_source->pollfd); | |
1337 | - } | |
1338 | - | |
1339 | - return source; | |
1340 | -} | |
1341 | - | |
1342 | -struct _PolkitBackendSessionMonitor | |
1343 | -{ | |
1344 | - GObject parent_instance; | |
1345 | - | |
1346 | - GDBusConnection *system_bus; | |
1347 | - | |
1348 | - GSource *sd_source; | |
1349 | -}; | |
1350 | - | |
1351 | -struct _PolkitBackendSessionMonitorClass | |
1352 | -{ | |
1353 | - GObjectClass parent_class; | |
1354 | - | |
1355 | - void (*changed) (PolkitBackendSessionMonitor *monitor); | |
1356 | -}; | |
1357 | - | |
1358 | - | |
1359 | -enum | |
1360 | -{ | |
1361 | - CHANGED_SIGNAL, | |
1362 | - LAST_SIGNAL, | |
1363 | -}; | |
1364 | - | |
1365 | -static guint signals[LAST_SIGNAL] = {0}; | |
1366 | - | |
1367 | -G_DEFINE_TYPE (PolkitBackendSessionMonitor, polkit_backend_session_monitor, G_TYPE_OBJECT); | |
1368 | - | |
1369 | -/* ---------------------------------------------------------------------------------------------------- */ | |
1370 | - | |
1371 | -static gboolean | |
1372 | -sessions_changed (gpointer user_data) | |
1373 | -{ | |
1374 | - PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data); | |
1375 | - | |
1376 | - g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0); | |
186114f9 ŁK |
1377 | - |
1378 | - return TRUE; | |
1379 | -} | |
1380 | - | |
1381 | - | |
1382 | -static void | |
1383 | -polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor) | |
1384 | -{ | |
1385 | - GError *error; | |
1386 | - | |
1387 | - error = NULL; | |
1388 | - monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); | |
1389 | - if (monitor->system_bus == NULL) | |
1390 | - { | |
1391 | - g_printerr ("Error getting system bus: %s", error->message); | |
1392 | - g_error_free (error); | |
1393 | - } | |
1394 | - | |
1395 | - monitor->sd_source = sd_source_new (); | |
1396 | - g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL); | |
1397 | - g_source_attach (monitor->sd_source, NULL); | |
1398 | -} | |
1399 | - | |
1400 | -static void | |
1401 | -polkit_backend_session_monitor_finalize (GObject *object) | |
1402 | -{ | |
1403 | - PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object); | |
1404 | - | |
1405 | - if (monitor->system_bus != NULL) | |
1406 | - g_object_unref (monitor->system_bus); | |
1407 | - | |
1408 | - if (monitor->sd_source != NULL) | |
1409 | - { | |
1410 | - g_source_destroy (monitor->sd_source); | |
1411 | - g_source_unref (monitor->sd_source); | |
1412 | - } | |
1413 | - | |
1414 | - if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL) | |
1415 | - G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object); | |
1416 | -} | |
1417 | - | |
1418 | -static void | |
1419 | -polkit_backend_session_monitor_class_init (PolkitBackendSessionMonitorClass *klass) | |
1420 | -{ | |
1421 | - GObjectClass *gobject_class; | |
1422 | - | |
1423 | - gobject_class = G_OBJECT_CLASS (klass); | |
1424 | - | |
1425 | - gobject_class->finalize = polkit_backend_session_monitor_finalize; | |
1426 | - | |
1427 | - /** | |
1428 | - * PolkitBackendSessionMonitor::changed: | |
1429 | - * @monitor: A #PolkitBackendSessionMonitor | |
1430 | - * | |
1431 | - * Emitted when something changes. | |
1432 | - */ | |
1433 | - signals[CHANGED_SIGNAL] = g_signal_new ("changed", | |
1434 | - POLKIT_BACKEND_TYPE_SESSION_MONITOR, | |
1435 | - G_SIGNAL_RUN_LAST, | |
1436 | - G_STRUCT_OFFSET (PolkitBackendSessionMonitorClass, changed), | |
1437 | - NULL, /* accumulator */ | |
1438 | - NULL, /* accumulator data */ | |
1439 | - g_cclosure_marshal_VOID__VOID, | |
1440 | - G_TYPE_NONE, | |
1441 | - 0); | |
1442 | -} | |
1443 | - | |
1444 | -PolkitBackendSessionMonitor * | |
1445 | -polkit_backend_session_monitor_new (void) | |
1446 | -{ | |
1447 | - PolkitBackendSessionMonitor *monitor; | |
1448 | - | |
1449 | - monitor = POLKIT_BACKEND_SESSION_MONITOR (g_object_new (POLKIT_BACKEND_TYPE_SESSION_MONITOR, NULL)); | |
1450 | - | |
1451 | - return monitor; | |
1452 | -} | |
1453 | - | |
1454 | -/* ---------------------------------------------------------------------------------------------------- */ | |
1455 | - | |
1456 | -GList * | |
1457 | -polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor) | |
1458 | -{ | |
1459 | - /* TODO */ | |
1460 | - return NULL; | |
1461 | -} | |
1462 | - | |
1463 | -/* ---------------------------------------------------------------------------------------------------- */ | |
1464 | - | |
1465 | -/** | |
1466 | - * polkit_backend_session_monitor_get_user: | |
1467 | - * @monitor: A #PolkitBackendSessionMonitor. | |
1468 | - * @subject: A #PolkitSubject. | |
4e85edc6 | 1469 | - * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state. |
186114f9 ŁK |
1470 | - * @error: Return location for error. |
1471 | - * | |
1472 | - * Gets the user corresponding to @subject or %NULL if no user exists. | |
1473 | - * | |
4e85edc6 JB |
1474 | - * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may |
1475 | - * come from e.g. a D-Bus client), so it may not correspond to the actual UID | |
1476 | - * of the referenced process (at any point in time). This is indicated by | |
1477 | - * setting @result_matches to %FALSE; the caller may reject such subjects or | |
1478 | - * require additional privileges. @result_matches == %TRUE only indicates that | |
1479 | - * the UID matched the underlying process at ONE point in time, it may not match | |
1480 | - * later. | |
1481 | - * | |
186114f9 ŁK |
1482 | - * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref(). |
1483 | - */ | |
1484 | -PolkitIdentity * | |
1485 | -polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor, | |
1486 | - PolkitSubject *subject, | |
4e85edc6 | 1487 | - gboolean *result_matches, |
186114f9 ŁK |
1488 | - GError **error) |
1489 | -{ | |
1490 | - PolkitIdentity *ret; | |
4e85edc6 | 1491 | - gboolean matches; |
186114f9 ŁK |
1492 | - |
1493 | - ret = NULL; | |
4e85edc6 | 1494 | - matches = FALSE; |
186114f9 ŁK |
1495 | - |
1496 | - if (POLKIT_IS_UNIX_PROCESS (subject)) | |
1497 | - { | |
4e85edc6 JB |
1498 | - gint subject_uid, current_uid; |
1499 | - GError *local_error; | |
1500 | - | |
1501 | - subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject)); | |
1502 | - if (subject_uid == -1) | |
186114f9 ŁK |
1503 | - { |
1504 | - g_set_error (error, | |
1505 | - POLKIT_ERROR, | |
1506 | - POLKIT_ERROR_FAILED, | |
1507 | - "Unix process subject does not have uid set"); | |
1508 | - goto out; | |
1509 | - } | |
4e85edc6 JB |
1510 | - local_error = NULL; |
1511 | - current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error); | |
1512 | - if (local_error != NULL) | |
1513 | - { | |
1514 | - g_propagate_error (error, local_error); | |
1515 | - goto out; | |
1516 | - } | |
1517 | - ret = polkit_unix_user_new (subject_uid); | |
1518 | - matches = (subject_uid == current_uid); | |
186114f9 ŁK |
1519 | - } |
1520 | - else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) | |
1521 | - { | |
77f30838 | 1522 | - ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); |
4e85edc6 | 1523 | - matches = TRUE; |
186114f9 ŁK |
1524 | - } |
1525 | - else if (POLKIT_IS_UNIX_SESSION (subject)) | |
1526 | - { | |
4e85edc6 | 1527 | - uid_t uid; |
186114f9 ŁK |
1528 | - |
1529 | - if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0) | |
1530 | - { | |
1531 | - g_set_error (error, | |
1532 | - POLKIT_ERROR, | |
1533 | - POLKIT_ERROR_FAILED, | |
1534 | - "Error getting uid for session"); | |
1535 | - goto out; | |
1536 | - } | |
1537 | - | |
1538 | - ret = polkit_unix_user_new (uid); | |
4e85edc6 | 1539 | - matches = TRUE; |
186114f9 ŁK |
1540 | - } |
1541 | - | |
1542 | - out: | |
4e85edc6 JB |
1543 | - if (result_matches != NULL) |
1544 | - { | |
1545 | - *result_matches = matches; | |
1546 | - } | |
186114f9 ŁK |
1547 | - return ret; |
1548 | -} | |
1549 | - | |
1550 | -/** | |
1551 | - * polkit_backend_session_monitor_get_session_for_subject: | |
1552 | - * @monitor: A #PolkitBackendSessionMonitor. | |
1553 | - * @subject: A #PolkitSubject. | |
1554 | - * @error: Return location for error. | |
1555 | - * | |
1556 | - * Gets the session corresponding to @subject or %NULL if no session exists. | |
1557 | - * | |
1558 | - * Returns: %NULL if @error is set otherwise a #PolkitUnixSession that should be freed with g_object_unref(). | |
1559 | - */ | |
1560 | -PolkitSubject * | |
1561 | -polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMonitor *monitor, | |
1562 | - PolkitSubject *subject, | |
1563 | - GError **error) | |
1564 | -{ | |
77f30838 JB |
1565 | - PolkitUnixProcess *tmp_process = NULL; |
1566 | - PolkitUnixProcess *process = NULL; | |
1567 | - PolkitSubject *session = NULL; | |
1568 | - char *session_id = NULL; | |
1569 | - pid_t pid; | |
1570 | -#if HAVE_SD_UID_GET_DISPLAY | |
1571 | - uid_t uid; | |
1572 | -#endif | |
dd341f56 JB |
1573 | -#if HAVE_SD_PIDFD_GET_SESSION |
1574 | - int pidfd; | |
1575 | -#endif | |
186114f9 ŁK |
1576 | - |
1577 | - if (POLKIT_IS_UNIX_PROCESS (subject)) | |
77f30838 | 1578 | - process = POLKIT_UNIX_PROCESS (subject); /* We already have a process */ |
186114f9 ŁK |
1579 | - else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) |
1580 | - { | |
77f30838 JB |
1581 | - /* Convert bus name to process */ |
1582 | - tmp_process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error); | |
1583 | - if (!tmp_process) | |
1584 | - goto out; | |
1585 | - process = tmp_process; | |
186114f9 ŁK |
1586 | - } |
1587 | - else | |
1588 | - { | |
1589 | - g_set_error (error, | |
1590 | - POLKIT_ERROR, | |
1591 | - POLKIT_ERROR_NOT_SUPPORTED, | |
77f30838 | 1592 | - "Cannot get session for subject of type %s", |
186114f9 ŁK |
1593 | - g_type_name (G_TYPE_FROM_INSTANCE (subject))); |
1594 | - } | |
1595 | - | |
dd341f56 JB |
1596 | -#if HAVE_SD_PIDFD_GET_SESSION |
1597 | - /* First try to get the session from the pidfd (systemd version 253) */ | |
1598 | - pidfd = polkit_unix_process_get_pidfd (process); | |
1599 | - if (pidfd >= 0) | |
1600 | - { | |
1601 | - if (sd_pidfd_get_session (pidfd, &session_id) >= 0) | |
1602 | - { | |
1603 | - session = polkit_unix_session_new (session_id); | |
1604 | - goto out; | |
1605 | - } | |
1606 | - } | |
1607 | -#endif | |
1608 | - | |
77f30838 JB |
1609 | - /* Now do process -> pid -> same session */ |
1610 | - g_assert (process != NULL); | |
1611 | - pid = polkit_unix_process_get_pid (process); | |
186114f9 | 1612 | - |
77f30838 JB |
1613 | - if (sd_pid_get_session (pid, &session_id) >= 0) |
1614 | - { | |
1615 | - session = polkit_unix_session_new (session_id); | |
1616 | - goto out; | |
1617 | - } | |
1618 | - | |
dd341f56 JB |
1619 | -#if HAVE_SD_PIDFD_GET_SESSION |
1620 | - /* Now do process fd -> uid -> graphical session (systemd version 253) */ | |
1621 | - pidfd = polkit_unix_process_get_pidfd (process); | |
1622 | - if (pidfd >= 0) | |
1623 | - { | |
1624 | - if (sd_pidfd_get_owner_uid (pidfd, &uid) < 0) | |
1625 | - goto out; | |
1626 | - | |
1627 | - if (sd_uid_get_display (uid, &session_id) >= 0) | |
1628 | - { | |
1629 | - session = polkit_unix_session_new (session_id); | |
1630 | - goto out; | |
1631 | - } | |
1632 | - } | |
1633 | -#endif | |
1634 | - | |
77f30838 JB |
1635 | -#if HAVE_SD_UID_GET_DISPLAY |
1636 | - /* Now do process -> uid -> graphical session (systemd version 213)*/ | |
1637 | - if (sd_pid_get_owner_uid (pid, &uid) < 0) | |
1638 | - goto out; | |
1639 | - | |
1640 | - if (sd_uid_get_display (uid, &session_id) >= 0) | |
1641 | - { | |
1642 | - session = polkit_unix_session_new (session_id); | |
1643 | - goto out; | |
1644 | - } | |
1645 | -#endif | |
1646 | - | |
1647 | - out: | |
1648 | - free (session_id); | |
1649 | - if (tmp_process) g_object_unref (tmp_process); | |
186114f9 ŁK |
1650 | - return session; |
1651 | -} | |
1652 | - | |
1653 | -gboolean | |
1654 | -polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor, | |
1655 | - PolkitSubject *session) | |
1656 | -{ | |
1657 | - char *seat; | |
1658 | - | |
1659 | - if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat)) | |
1660 | - { | |
1661 | - free (seat); | |
1662 | - return TRUE; | |
1663 | - } | |
1664 | - | |
1665 | - return FALSE; | |
1666 | -} | |
1667 | - | |
1668 | - | |
1669 | -gboolean | |
1670 | -polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor, | |
1671 | - PolkitSubject *session) | |
1672 | -{ | |
77f30838 JB |
1673 | - const char *session_id; |
1674 | - char *state; | |
1675 | - uid_t uid; | |
1676 | - gboolean is_active = FALSE; | |
1677 | - | |
1678 | - session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)); | |
1679 | - | |
1680 | - g_debug ("Checking whether session %s is active.", session_id); | |
1681 | - | |
1682 | - /* Check whether *any* of the user's current sessions are active. */ | |
1683 | - if (sd_session_get_uid (session_id, &uid) < 0) | |
1684 | - goto fallback; | |
1685 | - | |
1686 | - g_debug ("Session %s has UID %u.", session_id, uid); | |
1687 | - | |
1688 | - if (sd_uid_get_state (uid, &state) < 0) | |
1689 | - goto fallback; | |
1690 | - | |
1691 | - g_debug ("UID %u has state %s.", uid, state); | |
1692 | - | |
1693 | - is_active = (g_strcmp0 (state, "active") == 0); | |
1694 | - free (state); | |
1695 | - | |
1696 | - return is_active; | |
1697 | - | |
1698 | -fallback: | |
1699 | - /* Fall back to checking the session. This is not ideal, since the user | |
1700 | - * might have multiple sessions, and we cannot guarantee to have chosen | |
1701 | - * the active one. | |
1702 | - * | |
1703 | - * See: https://bugs.freedesktop.org/show_bug.cgi?id=76358. */ | |
1704 | - return sd_session_is_active (session_id); | |
186114f9 ŁK |
1705 | -} |
1706 | - | |
fbe373fc JP |
1707 | diff -ur polkit-v.121.orig/meson.build polkit-v.121/meson.build |
1708 | --- polkit-v.121.orig/meson.build 2022-07-11 10:46:06.000000000 +0200 | |
1709 | +++ polkit-v.121/meson.build 2022-07-13 23:02:30.432622964 +0200 | |
1710 | @@ -187,7 +187,8 @@ | |
1711 | if session_tracking == 'libsystemd-login' | |
1712 | logind_dep = dependency('libsystemd', required: false) | |
1713 | if not logind_dep.found() | |
1714 | - logind_dep = dependency('libsystemd-login', not_found_message: 'libsystemd support requested but libsystemd or libsystemd-login library not found') | |
1715 | + logind_dep = [ dependency('libsystemd-login', not_found_message: 'libsystemd support requested but libsystemd or libsystemd-login library not found'),dependency('libsystemd-daemon', not_found_message: 'libsystemd support requested but libsystemd or libsystemd-daemon library not found')] | |
1716 | + | |
1717 | endif | |
1718 | else | |
1719 | logind_dep = dependency('libelogind', not_found_message: 'libelogind support requested but libelogind library not found') | |
1720 | diff -ur polkit-v.121.orig/src/polkit/meson.build polkit-v.121/src/polkit/meson.build | |
1721 | --- polkit-v.121.orig/src/polkit/meson.build 2022-07-11 10:46:06.000000000 +0200 | |
1722 | +++ polkit-v.121/src/polkit/meson.build 2022-07-13 23:11:05.333520578 +0200 | |
1723 | @@ -77,13 +77,11 @@ | |
1724 | c_flags = '-D_POLKIT_COMPILATION' | |
1725 | ||
1726 | if enable_logind | |
1727 | - sources += 'polkitunixsession-systemd.c' | |
1728 | - | |
1729 | deps += logind_dep | |
1730 | -else | |
1731 | - sources += 'polkitunixsession.c' | |
1732 | endif | |
1733 | ||
1734 | + sources += 'polkitunixsession.c' | |
1735 | + | |
1736 | libpolkit_gobject = shared_library( | |
1737 | name, | |
1738 | sources: sources, | |
1739 | diff -ur polkit-v.121.orig/src/polkitbackend/meson.build polkit-v.121/src/polkitbackend/meson.build | |
1740 | --- polkit-v.121.orig/src/polkitbackend/meson.build 2022-07-11 10:46:06.000000000 +0200 | |
1741 | +++ polkit-v.121/src/polkitbackend/meson.build 2022-07-13 23:05:09.917827287 +0200 | |
1742 | @@ -43,12 +43,9 @@ | |
1743 | endif | |
1744 | ||
1745 | if enable_logind | |
1746 | - sources += files('polkitbackendsessionmonitor-systemd.c') | |
1747 | - | |
1748 | deps += logind_dep | |
1749 | -else | |
1750 | - sources += files('polkitbackendsessionmonitor.c') | |
1751 | endif | |
1752 | + sources += files('polkitbackendsessionmonitor.c') | |
1753 | ||
1754 | libpolkit_backend = static_library( | |
1755 | name, |