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