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
5 dnl if libsystemd is not available, fall back to the older libsystemd-login
6 [PKG_CHECK_MODULES([LIBSYSTEMD_LOGIN],
8 + [libsystemd-login libsystemd-daemon],
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
15 polkitimplicitauthorization.c polkitimplicitauthorization.h \
16 polkittemporaryauthorization.c polkittemporaryauthorization.h \
17 polkitpermission.c polkitpermission.h \
21 -libpolkit_gobject_1_la_SOURCES += \
22 - polkitunixsession-systemd.c polkitunixsession.h
24 -libpolkit_gobject_1_la_SOURCES += \
25 polkitunixsession.c polkitunixsession.h
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
34 #include "polkiterror.h"
35 #include "polkitprivate.h"
37 +#ifdef HAVE_LIBSYSTEMD
39 +# include <systemd/sd-daemon.h>
40 +# include <systemd/sd-login.h>
44 * SECTION:polkitunixsession
45 * @title: PolkitUnixSession
48 PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
49 GDBusConnection *connection;
51 + GVariant *result = NULL;
57 - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
58 - if (connection == NULL)
60 +#ifdef HAVE_LIBSYSTEMD
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,
76 + if (sd_booted () > 0)
78 + if (sd_session_get_uid (session->session_id, &uid) == 0)
82 +#endif /* HAVE_LIBSYSTEMD */
84 + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
85 + if (connection == NULL)
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,
103 - g_variant_unref (result);
105 + g_variant_unref (result);
109 if (connection != NULL)
110 g_object_unref (connection);
123 @@ -484,28 +505,51 @@
127 - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
128 - if (connection == NULL)
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,
142 - if (result == NULL)
144 +#ifdef HAVE_LIBSYSTEMD
147 + if (sd_booted () > 0)
149 + if (sd_pid_get_session (session->pid, &s) == 0)
151 + session->session_id = g_strdup (s);
157 + g_set_error (error,
159 + POLKIT_ERROR_FAILED,
160 + "No session for pid %d",
161 + (gint) session->pid);
164 +#endif /* HAVE_LIBSYSTEMD */
166 + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
167 + if (connection == NULL)
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,
181 + if (result == NULL)
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);
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
200 - * Copyright (C) 2011 Red Hat, Inc.
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.
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.
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.
217 - * Author: Matthias Clasen
220 -#ifdef HAVE_CONFIG_H
221 -# include "config.h"
226 -#include "polkitunixsession.h"
227 -#include "polkitsubject.h"
228 -#include "polkiterror.h"
229 -#include "polkitprivate.h"
231 -#include <systemd/sd-login.h>
234 - * SECTION:polkitunixsession
235 - * @title: PolkitUnixSession
236 - * @short_description: Unix sessions
238 - * An object that represents an user session.
240 - * The session id is an opaque string obtained from ConsoleKit.
244 - * PolkitUnixSession:
246 - * The #PolkitUnixSession struct should not be accessed directly.
248 -struct _PolkitUnixSession
250 - GObject parent_instance;
257 -struct _PolkitUnixSessionClass
259 - GObjectClass parent_class;
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);
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)
280 -polkit_unix_session_init (PolkitUnixSession *session)
285 -polkit_unix_session_finalize (GObject *object)
287 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
289 - g_free (session->session_id);
291 - if (G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize != NULL)
292 - G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize (object);
296 -polkit_unix_session_get_property (GObject *object,
301 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
305 - case PROP_SESSION_ID:
306 - g_value_set_string (value, session->session_id);
310 - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
316 -polkit_unix_session_set_property (GObject *object,
318 - const GValue *value,
321 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
325 - case PROP_SESSION_ID:
326 - polkit_unix_session_set_session_id (session, g_value_get_string (value));
330 - session->pid = g_value_get_int (value);
334 - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
340 -polkit_unix_session_class_init (PolkitUnixSessionClass *klass)
342 - GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
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;
349 - * PolkitUnixSession:session-id:
351 - * The UNIX session id.
353 - g_object_class_install_property (gobject_class,
355 - g_param_spec_string ("session-id",
357 - "The UNIX session ID",
359 - G_PARAM_CONSTRUCT |
360 - G_PARAM_READWRITE |
361 - G_PARAM_STATIC_NAME |
362 - G_PARAM_STATIC_BLURB |
363 - G_PARAM_STATIC_NICK));
367 - * PolkitUnixSession:pid:
369 - * The UNIX process id to look up the session.
371 - g_object_class_install_property (gobject_class,
373 - g_param_spec_int ("pid",
375 - "Process ID to use for looking up the session",
379 - G_PARAM_CONSTRUCT_ONLY |
381 - G_PARAM_STATIC_NAME |
382 - G_PARAM_STATIC_BLURB |
383 - G_PARAM_STATIC_NICK));
388 - * polkit_unix_session_get_session_id:
389 - * @session: A #PolkitUnixSession.
391 - * Gets the session id for @session.
393 - * Returns: The session id for @session. Do not free this string, it
394 - * is owned by @session.
397 -polkit_unix_session_get_session_id (PolkitUnixSession *session)
399 - g_return_val_if_fail (POLKIT_IS_UNIX_SESSION (session), NULL);
400 - return session->session_id;
404 - * polkit_unix_session_set_session_id:
405 - * @session: A #PolkitUnixSession.
406 - * @session_id: The session id.
408 - * Sets the session id for @session to @session_id.
411 -polkit_unix_session_set_session_id (PolkitUnixSession *session,
412 - const gchar *session_id)
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);
421 - * polkit_unix_session_new:
422 - * @session_id: The session id.
424 - * Creates a new #PolkitUnixSession for @session_id.
426 - * Returns: (transfer full): A #PolkitUnixSession. Free with g_object_unref().
429 -polkit_unix_session_new (const gchar *session_id)
431 - return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_UNIX_SESSION,
432 - "session-id", session_id,
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.
443 - * Asynchronously creates a new #PolkitUnixSession object for the
444 - * process with process id @pid.
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
453 - * This method constructs the object asynchronously, for the synchronous and blocking version
454 - * use polkit_unix_session_new_for_process_sync().
457 -polkit_unix_session_new_for_process (gint pid,
458 - GCancellable *cancellable,
459 - GAsyncReadyCallback callback,
460 - gpointer user_data)
462 - g_async_initable_new_async (POLKIT_TYPE_UNIX_SESSION,
463 - G_PRIORITY_DEFAULT,
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.
476 - * Finishes constructing a #PolkitSubject for a process id.
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().
483 -polkit_unix_session_new_for_process_finish (GAsyncResult *res,
487 - GObject *source_object;
489 - source_object = g_async_result_get_source_object (res);
490 - g_assert (source_object != NULL);
492 - object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
495 - g_object_unref (source_object);
497 - if (object != NULL)
498 - return POLKIT_SUBJECT (object);
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.
510 - * Creates a new #PolkitUnixSession for the process with process id @pid.
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().
516 - * Returns: (allow-none) (transfer full): A #PolkitUnixSession for
517 - * @pid or %NULL if @error is set. Free with g_object_unref().
520 -polkit_unix_session_new_for_process_sync (gint pid,
521 - GCancellable *cancellable,
524 - return POLKIT_SUBJECT (g_initable_new (POLKIT_TYPE_UNIX_SESSION,
532 -polkit_unix_session_hash (PolkitSubject *subject)
534 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
536 - return g_str_hash (session->session_id);
540 -polkit_unix_session_equal (PolkitSubject *a,
543 - PolkitUnixSession *session_a;
544 - PolkitUnixSession *session_b;
546 - session_a = POLKIT_UNIX_SESSION (a);
547 - session_b = POLKIT_UNIX_SESSION (b);
549 - return g_strcmp0 (session_a->session_id, session_b->session_id) == 0;
553 -polkit_unix_session_to_string (PolkitSubject *subject)
555 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
557 - return g_strdup_printf ("unix-session:%s", session->session_id);
561 -polkit_unix_session_exists_sync (PolkitSubject *subject,
562 - GCancellable *cancellable,
565 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
566 - gboolean ret = FALSE;
569 - if (sd_session_get_uid (session->session_id, &uid) == 0)
576 -exists_in_thread_func (GSimpleAsyncResult *res,
578 - GCancellable *cancellable)
582 - if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (object),
586 - g_simple_async_result_set_from_error (res, error);
587 - g_error_free (error);
592 -polkit_unix_session_exists (PolkitSubject *subject,
593 - GCancellable *cancellable,
594 - GAsyncReadyCallback callback,
595 - gpointer user_data)
597 - GSimpleAsyncResult *simple;
599 - g_return_if_fail (POLKIT_IS_UNIX_SESSION (subject));
601 - simple = g_simple_async_result_new (G_OBJECT (subject),
604 - polkit_unix_session_exists);
605 - g_simple_async_result_run_in_thread (simple,
606 - exists_in_thread_func,
607 - G_PRIORITY_DEFAULT,
609 - g_object_unref (simple);
613 -polkit_unix_session_exists_finish (PolkitSubject *subject,
617 - GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
620 - g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_session_exists);
624 - if (g_simple_async_result_propagate_error (simple, error))
627 - ret = g_simple_async_result_get_op_res_gboolean (simple);
634 -subject_iface_init (PolkitSubjectIface *subject_iface)
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;
645 -polkit_unix_session_initable_init (GInitable *initable,
646 - GCancellable *cancellable,
649 - PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable);
650 - gboolean ret = FALSE;
653 - if (session->session_id != NULL)
655 - /* already set, nothing to do */
660 - if (sd_pid_get_session (session->pid, &s) == 0)
662 - session->session_id = g_strdup (s);
668 - g_set_error (error,
670 - POLKIT_ERROR_FAILED,
671 - "No session for pid %d",
672 - (gint) session->pid);
679 -initable_iface_init (GInitableIface *initable_iface)
681 - initable_iface->init = polkit_unix_session_initable_init;
685 -async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
687 - /* use default implementation to run GInitable code in a thread */
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
692 polkitbackendactionpool.h polkitbackendactionpool.c \
693 polkitbackendconfigsource.h polkitbackendconfigsource.c \
694 polkitbackendactionlookup.h polkitbackendactionlookup.c \
698 -libpolkit_backend_1_la_SOURCES += \
699 - polkitbackendsessionmonitor.h polkitbackendsessionmonitor-systemd.c
701 -libpolkit_backend_1_la_SOURCES += \
702 polkitbackendsessionmonitor.h polkitbackendsessionmonitor.c
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
710 #include <polkit/polkitprivate.h>
712 #ifdef HAVE_LIBSYSTEMD
713 +#include <systemd/sd-daemon.h>
714 #include <systemd/sd-login.h>
715 #endif /* HAVE_LIBSYSTEMD */
717 @@ -794,6 +795,8 @@ subject_to_jsval (PolkitBackendJsAuthori
720 #ifdef HAVE_LIBSYSTEMD
721 + if (sd_booted () > 0)
723 if (sd_pid_get_session (pid, &session_str) == 0)
725 if (sd_session_get_seat (session_str, &seat_str) == 0)
726 @@ -801,6 +804,7 @@ subject_to_jsval (PolkitBackendJsAuthori
731 #endif /* HAVE_LIBSYSTEMD */
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
738 #include <glib/gstdio.h>
740 +#ifdef HAVE_LIBSYSTEMD
741 +# include <stdlib.h>
742 +# include <systemd/sd-daemon.h>
743 +# include <systemd/sd-login.h>
744 +#endif /* HAVE_LIBSYSTEMD */
746 #include <polkit/polkit.h>
747 #include "polkitbackendsessionmonitor.h"
750 * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions.
753 +#ifdef HAVE_LIBSYSTEMD
758 + sd_login_monitor *monitor;
762 +sd_source_prepare (GSource *source,
770 +sd_source_check (GSource *source)
772 + SdSource *sd_source = (SdSource *)source;
774 + return sd_source->pollfd.revents != 0;
778 +sd_source_dispatch (GSource *source,
779 + GSourceFunc callback,
780 + gpointer user_data)
783 + SdSource *sd_source = (SdSource *)source;
786 + g_warn_if_fail (callback != NULL);
788 + ret = (*callback) (user_data);
790 + sd_login_monitor_flush (sd_source->monitor);
796 +sd_source_finalize (GSource *source)
798 + SdSource *sd_source = (SdSource*)source;
800 + sd_login_monitor_unref (sd_source->monitor);
803 +static GSourceFuncs sd_source_funcs = {
806 + sd_source_dispatch,
811 +sd_source_new (void)
814 + SdSource *sd_source;
817 + source = g_source_new (&sd_source_funcs, sizeof (SdSource));
818 + sd_source = (SdSource *)source;
820 + if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
822 + g_printerr ("Error getting login monitor: %d", ret);
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);
833 +#endif /* HAVE_LIBSYSTEMD */
835 struct _PolkitBackendSessionMonitor
837 GObject parent_instance;
838 @@ -48,6 +136,10 @@ struct _PolkitBackendSessionMonitor
840 GFileMonitor *database_monitor;
841 time_t database_mtime;
843 +#ifdef HAVE_LIBSYSTEMD
844 + GSource *sd_source;
845 +#endif /* HAVE_LIBSYSTEMD */
848 struct _PolkitBackendSessionMonitorClass
849 @@ -70,6 +162,18 @@ G_DEFINE_TYPE (PolkitBackendSessionMonit
851 /* ---------------------------------------------------------------------------------------------------- */
853 +#ifdef HAVE_LIBSYSTEMD
855 +sessions_changed (gpointer user_data)
857 + PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
859 + g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
863 +#endif /* HAVE_LIBSYSTEMD */
866 reload_database (PolkitBackendSessionMonitor *monitor,
868 @@ -176,31 +280,47 @@ polkit_backend_session_monitor_init (Pol
869 g_error_free (error);
873 - if (!ensure_database (monitor, &error))
874 +#ifdef HAVE_LIBSYSTEMD
875 + monitor->sd_source = NULL;
877 + if (sd_booted () > 0)
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);
885 + monitor->database_monitor = NULL;
886 + monitor->database = NULL;
889 +#endif /* HAVE_LIBSYSTEMD */
892 + if (!ensure_database (monitor, &error))
894 + g_printerr ("Error loading " CKDB_PATH ": %s", error->message);
895 + g_error_free (error);
899 - file = g_file_new_for_path (CKDB_PATH);
900 - monitor->database_monitor = g_file_monitor_file (file,
902 + file = g_file_new_for_path (CKDB_PATH);
903 + monitor->database_monitor = g_file_monitor_file (file,
907 - g_object_unref (file);
908 - if (monitor->database_monitor == NULL)
910 - g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
911 - g_error_free (error);
915 - g_signal_connect (monitor->database_monitor,
917 - G_CALLBACK (on_file_monitor_changed),
919 + g_object_unref (file);
920 + if (monitor->database_monitor == NULL)
922 + g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
923 + g_error_free (error);
927 + g_signal_connect (monitor->database_monitor,
929 + G_CALLBACK (on_file_monitor_changed),
935 @@ -218,6 +338,12 @@ polkit_backend_session_monitor_finalize
936 if (monitor->database != NULL)
937 g_key_file_free (monitor->database);
939 + if (monitor->sd_source != NULL)
941 + g_source_destroy (monitor->sd_source);
942 + g_source_unref (monitor->sd_source);
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);
948 @@ -310,22 +436,38 @@ polkit_backend_session_monitor_get_user_
950 else if (POLKIT_IS_UNIX_SESSION (subject))
952 - if (!ensure_database (monitor, error))
953 +#ifdef HAVE_LIBSYSTEMD
954 + if (monitor->sd_source != NULL)
956 - g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": ");
958 + if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0)
960 + g_set_error (error,
962 + POLKIT_ERROR_FAILED,
963 + "Error getting uid for session");
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)
973 +#endif /* HAVE_LIBSYSTEMD */
975 - g_propagate_prefixed_error (error, local_error, "Error getting uid using " CKDB_PATH ": ");
976 + if (!ensure_database (monitor, error))
978 + g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": ");
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)
987 + g_propagate_prefixed_error (error, local_error, "Error getting uid using " CKDB_PATH ": ");
996 ret = polkit_unix_user_new (uid);
998 @@ -349,35 +491,27 @@ polkit_backend_session_monitor_get_sessi
999 PolkitSubject *subject,
1002 - PolkitSubject *session;
1005 + PolkitSubject *session = NULL;
1008 if (POLKIT_IS_UNIX_PROCESS (subject))
1010 - const gchar *session_id;
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 */
1023 - if (result == NULL)
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));
1031 else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1033 + { /* Convert bus name to process / pid */
1034 +#ifdef HAVE_LIBSYSTEMD
1035 + if (monitor->sd_source != NULL)
1037 + PolkitUnixProcess *process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME(subject), NULL, error);
1040 + pid = polkit_unix_process_get_pid (process);
1041 + g_object_unref (process);
1046 - const gchar *session_id;
1049 result = g_dbus_connection_call_sync (monitor->system_bus,
1050 @@ -395,23 +530,7 @@ polkit_backend_session_monitor_get_sessi
1052 g_variant_get (result, "(u)", &pid);
1053 g_variant_unref (result);
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 */
1066 - if (result == NULL)
1068 - g_variant_get (result, "(&o)", &session_id);
1069 - session = polkit_unix_session_new (session_id);
1070 - g_variant_unref (result);
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)));
1082 + /* Now do pid -> same session */
1083 +#ifdef HAVE_LIBSYSTEMD
1084 + if (monitor->sd_source != NULL)
1086 + gchar *session_id;
1087 + if (sd_pid_get_session (pid, &session_id) >= 0)
1089 + session = polkit_unix_session_new (session_id);
1090 + free (session_id);
1093 +#if HAVE_SD_UID_GET_DISPLAY
1095 + /* Now do pid -> uid -> graphical session (systemd version 213)*/
1096 + if (sd_pid_get_owner_uid (pid, &uid) < 0)
1099 + if (sd_uid_get_display (uid, &session_id) >= 0)
1101 + session = polkit_unix_session_new (session_id);
1102 + free (session_id);
1108 +#endif /* HAVE_LIBSYSTEMD */
1110 + gchar *session_id;
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 */
1123 + if (result == NULL)
1125 + g_variant_get (result, "(&o)", &session_id);
1126 + session = polkit_unix_session_new (session_id);
1127 + g_variant_unref (result);
1133 @@ -472,7 +639,22 @@ gboolean
1134 polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
1135 PolkitSubject *session)
1137 - return get_boolean (monitor, session, "is_local");
1138 +#ifdef HAVE_LIBSYSTEMD
1139 + if (monitor->sd_source != NULL)
1143 + if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat))
1152 +#endif /* HAVE_LIBSYSTEMD */
1153 + return get_boolean (monitor, session, "is_local");
1157 @@ -480,6 +662,44 @@ gboolean
1158 polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
1159 PolkitSubject *session)
1161 - return get_boolean (monitor, session, "is_active");
1162 +#ifdef HAVE_LIBSYSTEMD
1163 + if (monitor->sd_source != NULL)
1165 + const char *session_id;
1168 + gboolean is_active = FALSE;
1170 + session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session));
1172 + g_debug ("Checking whether session %s is active.", session_id);
1174 + /* Check whether *any* of the user's current sessions are active. */
1175 + if (sd_session_get_uid (session_id, &uid) < 0)
1178 + g_debug ("Session %s has UID %u.", session_id, uid);
1180 + if (sd_uid_get_state (uid, &state) < 0)
1183 + g_debug ("UID %u has state %s.", uid, state);
1185 + is_active = (g_strcmp0 (state, "active") == 0);
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
1195 + * See: https://bugs.freedesktop.org/show_bug.cgi?id=76358. */
1196 + return sd_session_is_active (session_id);
1199 +#endif /* HAVE_LIBSYSTEMD */
1200 + return get_boolean (monitor, session, "is_active");
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
1207 - * Copyright (C) 2011 Red Hat, Inc.
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.
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.
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.
1224 - * Author: Matthias Clasen
1227 -#include "config.h"
1231 -#include <string.h>
1232 -#include <glib/gstdio.h>
1233 -#include <systemd/sd-login.h>
1234 -#include <stdlib.h>
1236 -#include <polkit/polkit.h>
1237 -#include "polkitbackendsessionmonitor.h"
1240 - * SECTION:polkitbackendsessionmonitor
1241 - * @title: PolkitBackendSessionMonitor
1242 - * @short_description: Monitor sessions
1244 - * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions.
1251 - sd_login_monitor *monitor;
1255 -sd_source_prepare (GSource *source,
1263 -sd_source_check (GSource *source)
1265 - SdSource *sd_source = (SdSource *)source;
1267 - return sd_source->pollfd.revents != 0;
1271 -sd_source_dispatch (GSource *source,
1272 - GSourceFunc callback,
1273 - gpointer user_data)
1276 - SdSource *sd_source = (SdSource *)source;
1279 - g_warn_if_fail (callback != NULL);
1281 - ret = (*callback) (user_data);
1283 - sd_login_monitor_flush (sd_source->monitor);
1289 -sd_source_finalize (GSource *source)
1291 - SdSource *sd_source = (SdSource*)source;
1293 - sd_login_monitor_unref (sd_source->monitor);
1296 -static GSourceFuncs sd_source_funcs = {
1297 - sd_source_prepare,
1299 - sd_source_dispatch,
1300 - sd_source_finalize
1304 -sd_source_new (void)
1307 - SdSource *sd_source;
1310 - source = g_source_new (&sd_source_funcs, sizeof (SdSource));
1311 - sd_source = (SdSource *)source;
1313 - if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
1315 - g_printerr ("Error getting login monitor: %d", ret);
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);
1327 -struct _PolkitBackendSessionMonitor
1329 - GObject parent_instance;
1331 - GDBusConnection *system_bus;
1333 - GSource *sd_source;
1336 -struct _PolkitBackendSessionMonitorClass
1338 - GObjectClass parent_class;
1340 - void (*changed) (PolkitBackendSessionMonitor *monitor);
1350 -static guint signals[LAST_SIGNAL] = {0};
1352 -G_DEFINE_TYPE (PolkitBackendSessionMonitor, polkit_backend_session_monitor, G_TYPE_OBJECT);
1354 -/* ---------------------------------------------------------------------------------------------------- */
1357 -sessions_changed (gpointer user_data)
1359 - PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
1361 - g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
1368 -polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor)
1373 - monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
1374 - if (monitor->system_bus == NULL)
1376 - g_printerr ("Error getting system bus: %s", error->message);
1377 - g_error_free (error);
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);
1386 -polkit_backend_session_monitor_finalize (GObject *object)
1388 - PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object);
1390 - if (monitor->system_bus != NULL)
1391 - g_object_unref (monitor->system_bus);
1393 - if (monitor->sd_source != NULL)
1395 - g_source_destroy (monitor->sd_source);
1396 - g_source_unref (monitor->sd_source);
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);
1404 -polkit_backend_session_monitor_class_init (PolkitBackendSessionMonitorClass *klass)
1406 - GObjectClass *gobject_class;
1408 - gobject_class = G_OBJECT_CLASS (klass);
1410 - gobject_class->finalize = polkit_backend_session_monitor_finalize;
1413 - * PolkitBackendSessionMonitor::changed:
1414 - * @monitor: A #PolkitBackendSessionMonitor
1416 - * Emitted when something changes.
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,
1429 -PolkitBackendSessionMonitor *
1430 -polkit_backend_session_monitor_new (void)
1432 - PolkitBackendSessionMonitor *monitor;
1434 - monitor = POLKIT_BACKEND_SESSION_MONITOR (g_object_new (POLKIT_BACKEND_TYPE_SESSION_MONITOR, NULL));
1439 -/* ---------------------------------------------------------------------------------------------------- */
1442 -polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor)
1448 -/* ---------------------------------------------------------------------------------------------------- */
1451 - * polkit_backend_session_monitor_get_user:
1452 - * @monitor: A #PolkitBackendSessionMonitor.
1453 - * @subject: A #PolkitSubject.
1454 - * @error: Return location for error.
1456 - * Gets the user corresponding to @subject or %NULL if no user exists.
1458 - * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref().
1461 -polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor,
1462 - PolkitSubject *subject,
1465 - PolkitIdentity *ret;
1470 - if (POLKIT_IS_UNIX_PROCESS (subject))
1472 - uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject));
1473 - if ((gint) uid == -1)
1475 - g_set_error (error,
1477 - POLKIT_ERROR_FAILED,
1478 - "Unix process subject does not have uid set");
1481 - ret = polkit_unix_user_new (uid);
1483 - else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1485 - ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error);
1487 - else if (POLKIT_IS_UNIX_SESSION (subject))
1490 - if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0)
1492 - g_set_error (error,
1494 - POLKIT_ERROR_FAILED,
1495 - "Error getting uid for session");
1499 - ret = polkit_unix_user_new (uid);
1507 - * polkit_backend_session_monitor_get_session_for_subject:
1508 - * @monitor: A #PolkitBackendSessionMonitor.
1509 - * @subject: A #PolkitSubject.
1510 - * @error: Return location for error.
1512 - * Gets the session corresponding to @subject or %NULL if no session exists.
1514 - * Returns: %NULL if @error is set otherwise a #PolkitUnixSession that should be freed with g_object_unref().
1517 -polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMonitor *monitor,
1518 - PolkitSubject *subject,
1521 - PolkitUnixProcess *tmp_process = NULL;
1522 - PolkitUnixProcess *process = NULL;
1523 - PolkitSubject *session = NULL;
1524 - char *session_id = NULL;
1526 -#if HAVE_SD_UID_GET_DISPLAY
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))
1534 - /* Convert bus name to process */
1535 - tmp_process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error);
1538 - process = tmp_process;
1542 - g_set_error (error,
1544 - POLKIT_ERROR_NOT_SUPPORTED,
1545 - "Cannot get session for subject of type %s",
1546 - g_type_name (G_TYPE_FROM_INSTANCE (subject)));
1549 - /* Now do process -> pid -> same session */
1550 - g_assert (process != NULL);
1551 - pid = polkit_unix_process_get_pid (process);
1553 - if (sd_pid_get_session (pid, &session_id) >= 0)
1555 - session = polkit_unix_session_new (session_id);
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)
1564 - if (sd_uid_get_display (uid, &session_id) >= 0)
1566 - session = polkit_unix_session_new (session_id);
1572 - free (session_id);
1573 - if (tmp_process) g_object_unref (tmp_process);
1578 -polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
1579 - PolkitSubject *session)
1583 - if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat))
1594 -polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
1595 - PolkitSubject *session)
1597 - const char *session_id;
1600 - gboolean is_active = FALSE;
1602 - session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session));
1604 - g_debug ("Checking whether session %s is active.", session_id);
1606 - /* Check whether *any* of the user's current sessions are active. */
1607 - if (sd_session_get_uid (session_id, &uid) < 0)
1610 - g_debug ("Session %s has UID %u.", session_id, uid);
1612 - if (sd_uid_get_state (uid, &state) < 0)
1615 - g_debug ("UID %u has state %s.", uid, state);
1617 - is_active = (g_strcmp0 (state, "active") == 0);
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
1627 - * See: https://bugs.freedesktop.org/show_bug.cgi?id=76358. */
1628 - return sd_session_is_active (session_id);