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