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