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