PolicyKit: Branch 'gdbus'
David Zeuthen
david at kemper.freedesktop.org
Wed Jul 28 12:30:14 PDT 2010
src/polkit/polkitauthority.c | 8
src/polkitbackend/Makefile.am | 21
src/polkitbackend/org.freedesktop.ConsoleKit.xml | 278 --------
src/polkitbackend/polkitbackendinteractiveauthority.c | 21
src/polkitbackend/polkitbackendsessionmonitor.c | 559 ++++++------------
5 files changed, 228 insertions(+), 659 deletions(-)
New commits:
commit 6486dea34072ac4b666d00fcfe8f620df3ccd7f8
Author: David Zeuthen <davidz at redhat.com>
Date: Wed Jul 28 15:29:14 2010 -0400
Port CK class to gdbus
Also simplify the code it by using the on-disk database. Makes
everything a lot simpler.
Signed-off-by: David Zeuthen <davidz at redhat.com>
diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c
index 11ebed8..d224bcf 100644
--- a/src/polkit/polkitauthority.c
+++ b/src/polkit/polkitauthority.c
@@ -262,6 +262,14 @@ polkit_authority_class_init (PolkitAuthorityClass *klass)
PolkitAuthority *
polkit_authority_get (void)
{
+ static volatile GQuark error_quark = 0;
+
+ if (error_quark == 0)
+ {
+ error_quark = POLKIT_ERROR;
+ }
+
+
if (the_authority != NULL)
{
g_object_ref (the_authority);
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am
index 4cb7310..968c1b8 100644
--- a/src/polkitbackend/Makefile.am
+++ b/src/polkitbackend/Makefile.am
@@ -17,22 +17,6 @@ INCLUDES = \
-DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
$(NULL)
-BUILT_SOURCES = \
- ck-built-sources.stamp \
- $(NULL)
-
-ck-built-sources.stamp : Makefile.am $(srcdir)/org.freedesktop.ConsoleKit.xml
- eggdbus-binding-tool \
- --namespace "Ck" \
- --dbus-namespace "org.freedesktop.ConsoleKit" \
- --introspection-xml $(top_srcdir)/src/polkitbackend/org.freedesktop.ConsoleKit.xml \
- --stamp-file ck-built-sources.stamp \
- $(NULL)
-
-# keep in sync with contents of ck-built-sources.stamp (Thanks autotools)
-#
-ck_built_sources = ckbindingsmarshal.c ckbindingsmarshal.h ckbindingsmarshal.list ckbindings.c ckbindings.h ckbindingstypes.h cksession.c cksession.h docbook-interface-org.freedesktop.ConsoleKit.Session.xml ckseat.c ckseat.h docbook-interface-org.freedesktop.ConsoleKit.Seat.xml ckmanager.c ckmanager.h docbook-interface-org.freedesktop.ConsoleKit.Manager.xml ckerror.c ckerror.h docbook-enum-Error.xml ckdevice.c ckdevice.h docbook-struct-Device.xml
-
lib_LTLIBRARIES=libpolkit-backend-1.la
libpolkit_backend_1includedir=$(includedir)/polkit-1/polkitbackend
@@ -51,7 +35,6 @@ libpolkit_backend_1include_HEADERS = \
$(NULL)
libpolkit_backend_1_la_SOURCES = \
- $(ck_built_sources) \
$(BUILT_SOURCES) \
polkitbackend.h \
polkitbackendtypes.h \
@@ -94,10 +77,10 @@ EXTRA_DIST = \
$(NULL)
dist-hook :
- (for i in $(ck_built_sources) $(BUILT_SOURCES) ; do rm -f $(distdir)/$$i ; done)
+ (for i in $(BUILT_SOURCES) ; do rm -f $(distdir)/$$i ; done)
clean-local :
- rm -f *~ $(ck_built_sources) $(BUILT_SOURCES)
+ rm -f *~ $(BUILT_SOURCES)
install-exec-hook:
mkdir -p $(DESTDIR)$(localstatedir)/lib/polkit-1
diff --git a/src/polkitbackend/org.freedesktop.ConsoleKit.xml b/src/polkitbackend/org.freedesktop.ConsoleKit.xml
deleted file mode 100644
index 89379b2..0000000
--- a/src/polkitbackend/org.freedesktop.ConsoleKit.xml
+++ /dev/null
@@ -1,278 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node>
-
- <!-- The error domain used for reporting errors -->
- <annotation name="org.gtk.EggDBus.DeclareErrorDomain" value="Error">
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.ConsoleKit.Manager.GeneralError">
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member.Value" value="0"/>
- </annotation>
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.ConsoleKit.Manager.NotPrivileged"/>
-
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.ConsoleKit.Seat.GeneralError">
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member.Value" value="100"/>
- </annotation>
-
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.ConsoleKit.Session.GeneralError">
- <annotation name="org.gtk.EggDBus.ErrorDomain.Member.Value" value="200"/>
- </annotation>
- </annotation>
-
- <!-- Device -->
- <annotation name="org.gtk.EggDBus.DeclareStruct" value="Device">
- <annotation name="org.gtk.EggDBus.DocString" value="The #Device type represents devices that are associated with seats."/>
- <annotation name="org.gtk.EggDBus.DocString.Summary" value="Devices"/>
-
- <annotation name="org.gtk.EggDBus.Struct.Member" value="String:id1">
- <annotation name="org.gtk.EggDBus.DocString" value="The first device identifier"/>
- </annotation>
- <annotation name="org.gtk.EggDBus.Struct.Member" value="String:id2">
- <annotation name="org.gtk.EggDBus.DocString" value="The second device identifier"/>
- </annotation>
- </annotation>
-
- <!-- -->
-
- <interface name="org.freedesktop.ConsoleKit.Manager">
-
- <!-- All of these should probably be read-only properties instead of methods -->
- <method name="GetSystemIdleSinceHint">
- <arg name="iso8601_datetime" type="s" direction="out"/>
- </method>
- <method name="GetSystemIdleHint">
- <arg name="idle_hint" type="b" direction="out"/>
- </method>
- <method name="GetSessions">
- <arg name="sessions" type="ao" direction="out"/>
- </method>
- <method name="GetSeats">
- <arg name="seats" type="ao" direction="out"/>
- </method>
- <method name="GetCurrentSession">
- <arg name="ssid" type="o" direction="out"/>
- </method>
-
- <method name="GetSessionsForUser">
- <arg name="uid" type="u" direction="in"/>
- <arg name="sessions" type="ao" direction="out"/>
- </method>
- <method name="GetSessionsForUnixUser">
- <arg name="uid" type="u" direction="in"/>
- <arg name="sessions" type="ao" direction="out"/>
- </method>
- <method name="GetSessionForUnixProcess">
- <arg name="pid" type="u" direction="in"/>
- <arg name="ssid" type="o" direction="out"/>
- </method>
- <method name="GetSessionForCookie">
- <arg name="cookie" type="s" direction="in"/>
- <arg name="ssid" type="o" direction="out"/>
- </method>
-
- <method name="CloseSession">
- <arg name="cookie" type="s" direction="in"/>
- <arg name="result" type="b" direction="out"/>
- </method>
- <method name="OpenSessionWithParameters">
- <arg name="parameters" type="a(sv)" direction="in">
- <annotation name="org.gtk.EggDBus.Type" value="Array<Struct<String,Variant>>"/>
- </arg>
- <arg name="cookie" type="s" direction="out"/>
- </method>
- <method name="OpenSession">
- <arg name="cookie" type="s" direction="out"/>
- </method>
- <method name="Stop">
- </method>
- <method name="Restart">
- </method>
-
- <!-- If the above Get*() methods are properties and we have org.fd.Properties.Changed() these signals
- are not needed -->
- <signal name="SystemIdleHintChanged">
- <arg type="b"/>
- </signal>
- <signal name="SeatRemoved">
- <arg type="o"/>
- </signal>
- <signal name="SeatAdded">
- <arg type="o"/>
- </signal>
- </interface>
-
- <interface name="org.freedesktop.ConsoleKit.Seat">
- <method name="ActivateSession">
- <arg name="ssid" type="o" direction="in"/>
- </method>
-
- <!-- All of these should probably be read-only properties instead of Get*() methods -->
- <method name="CanActivateSessions">
- <arg name="can_activate" type="b" direction="out"/>
- </method>
- <method name="GetActiveSession">
- <arg name="ssid" type="o" direction="out"/>
- </method>
- <method name="GetDevices">
- <arg name="devices" type="a(ss)" direction="out"/>
- </method>
- <method name="GetSessions">
- <arg name="sessions" type="ao" direction="out"/>
- </method>
- <method name="GetId">
- <arg name="sid" type="o" direction="out"/>
- </method>
-
- <signal name="DeviceRemoved">
- <arg type="(ss)"/>
- </signal>
- <signal name="DeviceAdded">
- <arg type="(ss)"/>
- </signal>
-
- <!-- If the above Get*() methods are properties and we have org.fd.Properties.Changed() these signals
- are not needed -->
- <signal name="SessionRemoved">
- <arg type="o"/>
- </signal>
- <signal name="SessionAdded">
- <arg type="o"/>
- </signal>
- <signal name="ActiveSessionChanged">
- <arg type="s"/>
- </signal>
- </interface>
-
- <interface name="org.freedesktop.ConsoleKit.Session">
- <method name="SetIdleHint">
- <arg name="idle_hint" type="b" direction="in"/>
- </method>
-
- <!-- This should really be a read-only property, not a method -->
- <method name="GetIdleSinceHint">
- <arg name="iso8601_datetime" type="s" direction="out"/>
- </method>
-
- <!-- superfluous: there's already :idle-hint
- <method name="GetIdleHint">
- <arg name="idle_hint" type="b" direction="out"/>
- </method>
- -->
-
- <method name="Unlock">
- </method>
- <method name="Lock">
- </method>
- <method name="Activate">
- </method>
-
- <!-- This should really be a read-only property, not a method -->
- <method name="GetCreationTime">
- <arg name="iso8601_datetime" type="s" direction="out"/>
- </method>
-
- <!-- superfluous: there's already :is-local
- <method name="IsLocal">
- <arg name="local" type="b" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :is-active
- <method name="IsActive">
- <arg name="active" type="b" direction="out"/>
- </method>
- -->
-
- <method name="GetLoginSessionId">
- <arg name="login_session_id" type="s" direction="out"/>
- </method>
-
- <!-- superfluous: there's already :remote-host-name
- <method name="GetRemoteHostName">
- <arg name="remote_host_name" type="s" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :display-device
- <method name="GetDisplayDevice">
- <arg name="display_device" type="s" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :x11-display-device
- <method name="GetX11DisplayDevice">
- <arg name="x11_display_device" type="s" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :x11-display
- <method name="GetX11Display">
- <arg name="display" type="s" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :unix-user
- <method name="GetUnixUser">
- <arg name="uid" type="u" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :user
- <method name="GetUser">
- <arg name="uid" type="u" direction="out"/>
- </method>
- -->
-
- <!-- superfluous: there's already :session-type
- <method name="GetSessionType">
- <arg name="type" type="s" direction="out"/>
- </method>
- -->
-
- <!-- This should really be a read-only property, not a method -->
- <method name="GetSeatId">
- <arg name="sid" type="o" direction="out"/>
- </method>
-
- <!-- This should really be a read-only property, not a method -->
- <method name="GetId">
- <arg name="ssid" type="o" direction="out"/>
- </method>
-
- <!-- This should probably be called Unlocked -->
- <signal name="Unlock">
- </signal>
-
- <!-- This should probably be called Locked -->
- <signal name="Lock">
- </signal>
-
- <!-- superfluous if you have the org.fd.Properties.Changed() signal -->
- <signal name="IdleHintChanged">
- <arg type="b"/>
- </signal>
-
- <!-- superfluous if you have the org.fd.Properties.Changed() signal -->
- <signal name="ActiveChanged">
- <arg type="b"/>
- </signal>
-
- <!--
- Note: ConsoleKit declares these as readwrite but since setting may fail (due to lack
- of privilege) they shouldn't be properties [1]; instead use Set* methods.
-
- [1] : most object systems, specifically GObject, don't have a way to return
- errors when setting properties
- -->
- <property name="idle-hint" type="b" access="read"/>
- <property name="is-local" type="b" access="read"/>
- <property name="active" type="b" access="read"/>
- <property name="x11-display-device" type="s" access="read"/>
- <property name="x11-display" type="s" access="read"/>
- <property name="display-device" type="s" access="read"/>
- <property name="remote-host-name" type="s" access="read"/>
- <property name="session-type" type="s" access="read"/>
- <property name="user" type="u" access="read"/>
- <property name="unix-user" type="u" access="read"/>
- </interface>
-
-</node>
diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c
index 41e9017..3265eef 100644
--- a/src/polkitbackend/polkitbackendinteractiveauthority.c
+++ b/src/polkitbackend/polkitbackendinteractiveauthority.c
@@ -769,11 +769,22 @@ polkit_backend_interactive_authority_check_authorization (PolkitBackendAuthority
if (!POLKIT_IS_UNIX_USER (user_of_caller) ||
polkit_unix_user_get_uid (POLKIT_UNIX_USER (user_of_caller)) != 0)
{
- g_simple_async_result_set_error (simple,
- POLKIT_ERROR,
- POLKIT_ERROR_NOT_AUTHORIZED,
- "Only trusted callers can use CheckAuthorization() for subjects "
- "belonging to other identities and/or pass details");
+ if (has_details)
+ {
+ g_simple_async_result_set_error (simple,
+ POLKIT_ERROR,
+ POLKIT_ERROR_NOT_AUTHORIZED,
+ "Only trusted callers (e.g. uid 0) can use CheckAuthorization() and "
+ "pass details");
+ }
+ else
+ {
+ g_simple_async_result_set_error (simple,
+ POLKIT_ERROR,
+ POLKIT_ERROR_NOT_AUTHORIZED,
+ "Only trusted callers (e.g. uid 0) can use CheckAuthorization() for "
+ "subjects belonging to other identities");
+ }
g_simple_async_result_complete (simple);
g_object_unref (simple);
goto out;
diff --git a/src/polkitbackend/polkitbackendsessionmonitor.c b/src/polkitbackend/polkitbackendsessionmonitor.c
index 2028250..2b63f3c 100644
--- a/src/polkitbackend/polkitbackendsessionmonitor.c
+++ b/src/polkitbackend/polkitbackendsessionmonitor.c
@@ -28,7 +28,8 @@
#include <polkit/polkit.h>
#include "polkitbackendsessionmonitor.h"
-#include "ckbindings.h"
+
+#define CKDB_PATH "/var/run/ConsoleKit/database"
/**
* SECTION:polkitbackendsessionmonitor
@@ -42,13 +43,10 @@ struct _PolkitBackendSessionMonitor
{
GObject parent_instance;
- EggDBusConnection *system_bus;
-
- EggDBusObjectProxy *ck_manager_object_proxy;
+ GDBusConnection *system_bus;
- CkManager *ck_manager;
- EggDBusHashMap *seat_object_path_to_object_proxy;
- EggDBusHashMap *session_object_path_to_object_proxy;
+ GKeyFile *database;
+ GFileMonitor *database_monitor;
};
struct _PolkitBackendSessionMonitorClass
@@ -67,243 +65,111 @@ enum
static guint signals[LAST_SIGNAL] = {0};
-static void seat_session_added (CkSeat *seat,
- const gchar *object_path,
- gpointer user_data);
-
-static void seat_session_removed (CkSeat *seat,
- const gchar *object_path,
- gpointer user_data);
-
-static void session_active_changed (CkSession *session,
- gboolean is_active,
- gpointer user_data);
-
G_DEFINE_TYPE (PolkitBackendSessionMonitor, polkit_backend_session_monitor, G_TYPE_OBJECT);
/* ---------------------------------------------------------------------------------------------------- */
-static void
-add_seat (PolkitBackendSessionMonitor *monitor,
- const gchar *object_path)
-{
- CkSeat *seat;
- EggDBusObjectProxy *object_proxy;
-
- object_proxy = egg_dbus_connection_get_object_proxy (monitor->system_bus,
- "org.freedesktop.ConsoleKit",
- object_path);
-
- egg_dbus_hash_map_insert (monitor->seat_object_path_to_object_proxy,
- g_strdup (object_path),
- object_proxy);
-
- seat = CK_QUERY_INTERFACE_SEAT (object_proxy);
-
- g_signal_connect (seat,
- "session-added",
- G_CALLBACK (seat_session_added),
- monitor);
-
- g_signal_connect (seat,
- "session-removed",
- G_CALLBACK (seat_session_removed),
- monitor);
-}
-
-static void
-add_session (PolkitBackendSessionMonitor *monitor,
- const gchar *object_path)
-{
- CkSession *session;
- EggDBusObjectProxy *object_proxy;
-
- object_proxy = egg_dbus_connection_get_object_proxy (monitor->system_bus,
- "org.freedesktop.ConsoleKit",
- object_path);
-
- egg_dbus_hash_map_insert (monitor->session_object_path_to_object_proxy,
- g_strdup (object_path),
- object_proxy);
-
- session = CK_QUERY_INTERFACE_SESSION (object_proxy);
-
- g_signal_connect (session,
- "active-changed",
- G_CALLBACK (session_active_changed),
- monitor);
-}
-
-static void
-remove_seat (PolkitBackendSessionMonitor *monitor,
- const gchar *object_path)
-{
- egg_dbus_hash_map_remove (monitor->seat_object_path_to_object_proxy,
- object_path);
-}
-
-static void
-remove_session (PolkitBackendSessionMonitor *monitor,
- const gchar *object_path)
-{
- egg_dbus_hash_map_remove (monitor->session_object_path_to_object_proxy,
- object_path);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-/* D-Bus signal handlers */
-
-static void
-manager_seat_added (CkManager *manager,
- const gchar *object_path,
- gpointer user_data)
-{
- PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
-
- //g_debug ("seat %s added", object_path);
-
- add_seat (monitor, object_path);
-
- g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
-}
-
-static void
-manager_seat_removed (CkManager *manager,
- const gchar *object_path,
- gpointer user_data)
+static gboolean
+reload_database (PolkitBackendSessionMonitor *monitor,
+ GError **error)
{
- PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
-
- //g_debug ("seat %s removed", object_path);
-
- remove_seat (monitor, object_path);
-
- g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
-}
+ gboolean ret;
-static void
-seat_session_added (CkSeat *seat,
- const gchar *object_path,
- gpointer user_data)
-{
- PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
+ ret = FALSE;
- //g_debug ("session %s added", object_path);
+ monitor->database = g_key_file_new ();
+ if (!g_key_file_load_from_file (monitor->database,
+ CKDB_PATH,
+ G_KEY_FILE_NONE,
+ error))
+ {
+ g_key_file_free (monitor->database);
+ monitor->database = NULL;
+ goto out;
+ }
- add_session (monitor, object_path);
+ ret = TRUE;
- g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
+ out:
+ return ret;
}
-static void
-seat_session_removed (CkSeat *seat,
- const gchar *object_path,
- gpointer user_data)
+static gboolean
+ensure_database (PolkitBackendSessionMonitor *monitor,
+ GError **error)
{
- PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
+ gboolean ret;
- //g_debug ("session %s removed", object_path);
+ if (monitor->database != NULL)
+ {
+ ret = TRUE;
+ goto out;
+ }
- remove_session (monitor, object_path);
+ ret = reload_database (monitor, error);
- g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
+ out:
+ return ret;
}
static void
-session_active_changed (CkSession *session,
- gboolean is_active,
- gpointer user_data)
+on_file_monitor_changed (GFileMonitor *file_monitor,
+ GFile *file,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
{
PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
- EggDBusObjectProxy *object_proxy;
-
- object_proxy = egg_dbus_interface_proxy_get_object_proxy (EGG_DBUS_INTERFACE_PROXY (session));
-
- //g_debug ("session %s active changed to %d", egg_dbus_object_proxy_get_object_path (object_proxy), is_active);
-
- egg_dbus_object_proxy_invalidate_properties (object_proxy);
+ /* throw away cache */
+ if (monitor->database != NULL)
+ {
+ g_key_file_free (monitor->database);
+ monitor->database = NULL;
+ }
g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
}
-/* ---------------------------------------------------------------------------------------------------- */
-
static void
polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor)
{
GError *error;
- gchar **seats_object_paths;
- gchar **sessions_object_paths;
- guint n;
+ GFile *file;
error = NULL;
- seats_object_paths = NULL;
- sessions_object_paths = NULL;
-
- monitor->seat_object_path_to_object_proxy = egg_dbus_hash_map_new (G_TYPE_STRING,
- g_free,
- EGG_DBUS_TYPE_OBJECT_PROXY,
- g_object_unref);
-
- monitor->session_object_path_to_object_proxy = egg_dbus_hash_map_new (G_TYPE_STRING,
- g_free,
- EGG_DBUS_TYPE_OBJECT_PROXY,
- g_object_unref);
-
- monitor->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
-
- monitor->ck_manager_object_proxy = egg_dbus_connection_get_object_proxy (monitor->system_bus,
- "org.freedesktop.ConsoleKit",
- "/org/freedesktop/ConsoleKit/Manager");
-
- monitor->ck_manager = CK_QUERY_INTERFACE_MANAGER (monitor->ck_manager_object_proxy);
-
- g_signal_connect (monitor->ck_manager,
- "seat-added",
- G_CALLBACK (manager_seat_added),
- monitor);
-
- g_signal_connect (monitor->ck_manager,
- "seat-removed",
- G_CALLBACK (manager_seat_removed),
- monitor);
-
- /* TODO: it would be a lot nicer to do all of this async; once we have
- * GFiber (bgo #565501) it will be a lot easier...
- */
- if (!ck_manager_get_seats_sync (monitor->ck_manager,
- EGG_DBUS_CALL_FLAGS_NONE,
- &seats_object_paths,
- NULL,
- &error))
+ monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (monitor->system_bus == NULL)
{
- g_warning ("Error getting seats: %s", error->message);
+ g_printerr ("Error getting system bus: %s", error->message);
g_error_free (error);
- goto out;
}
- for (n = 0; seats_object_paths[n] != NULL; n++)
- add_seat (monitor, seats_object_paths[n]);
-
- if (!ck_manager_get_sessions_sync (monitor->ck_manager,
- EGG_DBUS_CALL_FLAGS_NONE,
- &sessions_object_paths,
- NULL,
- &error))
+ error = NULL;
+ if (!ensure_database (monitor, &error))
{
- g_warning ("Error getting sessions: %s", error->message);
+ g_printerr ("Error loading " CKDB_PATH ": %s", error->message);
g_error_free (error);
- goto out;
}
- for (n = 0; sessions_object_paths[n] != NULL; n++)
- add_session (monitor, sessions_object_paths[n]);
-
- out:
-
- g_strfreev (seats_object_paths);
- g_strfreev (sessions_object_paths);
+ error = NULL;
+ file = g_file_new_for_path (CKDB_PATH);
+ monitor->database_monitor = g_file_monitor_file (file,
+ G_FILE_MONITOR_NONE,
+ NULL,
+ &error);
+ g_object_unref (file);
+ if (monitor->database_monitor == NULL)
+ {
+ g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ g_signal_connect (monitor->database_monitor,
+ "changed",
+ G_CALLBACK (on_file_monitor_changed),
+ monitor);
+ }
}
static void
@@ -311,10 +177,14 @@ polkit_backend_session_monitor_finalize (GObject *object)
{
PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object);
- g_object_unref (monitor->seat_object_path_to_object_proxy);
- g_object_unref (monitor->session_object_path_to_object_proxy);
- g_object_unref (monitor->ck_manager_object_proxy);
- g_object_unref (monitor->system_bus);
+ if (monitor->system_bus != NULL)
+ g_object_unref (monitor->system_bus);
+
+ if (monitor->database_monitor != NULL)
+ g_object_unref (monitor->database_monitor);
+
+ if (monitor->database != NULL)
+ g_key_file_free (monitor->database);
if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL)
G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object);
@@ -356,42 +226,13 @@ polkit_backend_session_monitor_new (void)
return monitor;
}
-static gboolean
-get_sessions_foreach_cb (EggDBusHashMap *map,
- gpointer key,
- gpointer value,
- gpointer user_data)
-{
- GList **l;
- const gchar *session_object_path;
- PolkitSubject *session;
-
- l = user_data;
- session_object_path = key;
-
- session = polkit_unix_session_new (session_object_path);
-
- *l = g_list_prepend (*l, session);
-
- return FALSE;
-}
-
/* ---------------------------------------------------------------------------------------------------- */
GList *
polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor)
{
- GList *l;
-
- l = NULL;
-
- egg_dbus_hash_map_foreach (monitor->session_object_path_to_object_proxy,
- get_sessions_foreach_cb,
- &l);
-
- l = g_list_reverse (l);
-
- return l;
+ /* TODO */
+ return NULL;
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -411,76 +252,72 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor
PolkitSubject *subject,
GError **error)
{
- PolkitIdentity *user;
- uid_t uid;
+ PolkitIdentity *ret;
+ GError *local_error;
+ gchar *group;
+ guint32 uid;
- user = NULL;
+ ret = NULL;
if (POLKIT_IS_UNIX_PROCESS (subject))
{
- GError *local_error;
-
local_error = NULL;
uid = polkit_unix_process_get_owner (POLKIT_UNIX_PROCESS (subject), &local_error);
if (local_error != NULL)
{
- g_propagate_error (error, local_error);
+ g_propagate_prefixed_error (error, local_error, "Error getting user for process: ");
g_error_free (local_error);
goto out;
}
- user = polkit_unix_user_new (uid);
- }
- else if (POLKIT_IS_UNIX_SESSION (subject))
- {
- const gchar *session_id;
- EggDBusObjectProxy *session_object_proxy;
- CkSession *session;
-
- session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject));
-
- session_object_proxy = egg_dbus_hash_map_lookup (monitor->session_object_path_to_object_proxy,
- session_id);
- if (session_object_proxy == NULL)
- {
- g_set_error (error,
- POLKIT_ERROR,
- POLKIT_ERROR_FAILED,
- "No ConsoleKit session with id %s",
- session_id);
- goto out;
- }
-
- session = CK_QUERY_INTERFACE_SESSION (session_object_proxy);
- uid = (uid_t) ck_session_get_user (session);
-
- user = polkit_unix_user_new (uid);
+ ret = polkit_unix_user_new (uid);
}
else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
{
- /* TODO: cache this stuff */
- if (!egg_dbus_bus_get_connection_unix_user_sync (egg_dbus_connection_get_bus (monitor->system_bus),
- EGG_DBUS_CALL_FLAGS_NONE,
- polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)),
- &uid,
- NULL,
- error))
+ GVariant *result;
+
+ result = g_dbus_connection_call_sync (monitor->system_bus,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "GetConnectionUnixUser",
+ g_variant_new ("(s)", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject))),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout_msec */
+ NULL, /* GCancellable */
+ error);
+ if (result == NULL)
goto out;
+ g_variant_get (result, "(u)", &uid);
+ g_variant_unref (result);
- user = polkit_unix_user_new (uid);
+ ret = polkit_unix_user_new (uid);
}
- else
+ else if (POLKIT_IS_UNIX_SESSION (subject))
{
- g_set_error (error,
- POLKIT_ERROR,
- POLKIT_ERROR_NOT_SUPPORTED,
- "Cannot get user for subject of type %s",
- g_type_name (G_TYPE_FROM_INSTANCE (subject)));
+ if (!ensure_database (monitor, error))
+ {
+ g_prefix_error (error, "Error getting user for session: Error ensuring CK database at " CKDB_PATH ": ");
+ goto out;
+ }
+
+ group = g_strdup_printf ("Session %s", polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)));
+ local_error = NULL;
+ uid = g_key_file_get_integer (monitor->database, group, "uid", &local_error);
+ if (local_error != NULL)
+ {
+ g_propagate_prefixed_error (error, local_error, "Error getting uid using " CKDB_PATH ": ");
+ g_free (group);
+ goto out;
+ }
+ g_free (group);
+
+ ret = polkit_unix_user_new (uid);
}
out:
-
- return user;
+ return ret;
}
/**
@@ -504,45 +341,63 @@ polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMoni
if (POLKIT_IS_UNIX_PROCESS (subject))
{
- gchar *session_id;
-
- if (!ck_manager_get_session_for_unix_process_sync (monitor->ck_manager,
- EGG_DBUS_CALL_FLAGS_NONE,
- polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject)),
- &session_id,
- NULL,
- error))
+ const gchar *session_id;
+ GVariant *result;
+ result = g_dbus_connection_call_sync (monitor->system_bus,
+ "org.freedesktop.ConsoleKit",
+ "/org/freedesktop/ConsoleKit/Manager",
+ "org.freedesktop.ConsoleKit.Manager",
+ "GetSessionForUnixProcess",
+ g_variant_new ("(u)", polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))),
+ G_VARIANT_TYPE ("(o)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout_msec */
+ NULL, /* GCancellable */
+ error);
+ if (result == NULL)
goto out;
-
+ g_variant_get (result, "(&o)", &session_id);
session = polkit_unix_session_new (session_id);
-
- g_free (session_id);
+ g_variant_unref (result);
}
else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
{
- pid_t pid;
- gchar *session_id;
-
- /* TODO: cache this stuff */
- if (!egg_dbus_bus_get_connection_unix_process_id_sync (egg_dbus_connection_get_bus (monitor->system_bus),
- EGG_DBUS_CALL_FLAGS_NONE,
- polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)),
- &pid,
- NULL,
- error))
+ guint32 pid;
+ const gchar *session_id;
+ GVariant *result;
+
+ result = g_dbus_connection_call_sync (monitor->system_bus,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "GetConnectionUnixProcessID",
+ g_variant_new ("(s)", polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject))),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout_msec */
+ NULL, /* GCancellable */
+ error);
+ if (result == NULL)
goto out;
-
- if (!ck_manager_get_session_for_unix_process_sync (monitor->ck_manager,
- EGG_DBUS_CALL_FLAGS_NONE,
- pid,
- &session_id,
- NULL,
- error))
+ g_variant_get (result, "(u)", &pid);
+ g_variant_unref (result);
+
+ result = g_dbus_connection_call_sync (monitor->system_bus,
+ "org.freedesktop.ConsoleKit",
+ "/org/freedesktop/ConsoleKit/Manager",
+ "org.freedesktop.ConsoleKit.Manager",
+ "GetSessionForUnixProcess",
+ g_variant_new ("(u)", pid),
+ G_VARIANT_TYPE ("(o)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout_msec */
+ NULL, /* GCancellable */
+ error);
+ if (result == NULL)
goto out;
-
+ g_variant_get (result, "(&o)", &session_id);
session = polkit_unix_session_new (session_id);
-
- g_free (session_id);
+ g_variant_unref (result);
}
else
{
@@ -558,58 +413,48 @@ polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMoni
return session;
}
-gboolean
-polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
- PolkitSubject *session)
+static gboolean
+get_boolean (PolkitBackendSessionMonitor *monitor,
+ PolkitSubject *session,
+ const gchar *key_name)
{
- EggDBusObjectProxy *object_proxy;
- const gchar *session_id;
- CkSession *ck_session;
gboolean ret;
-
- g_return_val_if_fail (POLKIT_IS_UNIX_SESSION (session), FALSE);
+ gchar *group;
+ GError *error;
ret = FALSE;
- session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session));
-
- object_proxy = egg_dbus_hash_map_lookup (monitor->session_object_path_to_object_proxy, session_id);
- if (object_proxy == NULL)
- goto out;
+ group = g_strdup_printf ("Session %s", polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)));
- ck_session = CK_QUERY_INTERFACE_SESSION (object_proxy);
-
- ret = ck_session_get_is_local (ck_session);
+ error = NULL;
+ ret = g_key_file_get_boolean (monitor->database, group, key_name, &error);
+ if (error != NULL)
+ {
+ g_printerr ("Error looking %s using " CKDB_PATH " for %s: %s\n",
+ key_name,
+ group,
+ error->message);
+ g_error_free (error);
+ goto out;
+ }
out:
+ g_free (group);
return ret;
}
-
gboolean
-polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
+polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
PolkitSubject *session)
{
- EggDBusObjectProxy *object_proxy;
- const gchar *session_id;
- CkSession *ck_session;
- gboolean ret;
-
- g_return_val_if_fail (POLKIT_IS_UNIX_SESSION (session), FALSE);
-
- ret = FALSE;
-
- session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session));
-
- object_proxy = egg_dbus_hash_map_lookup (monitor->session_object_path_to_object_proxy, session_id);
- if (object_proxy == NULL)
- goto out;
-
- ck_session = CK_QUERY_INTERFACE_SESSION (object_proxy);
+ return get_boolean (monitor, session, "is_local");
+}
- ret = ck_session_get_active (ck_session);
- out:
- return ret;
+gboolean
+polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
+ PolkitSubject *session)
+{
+ return get_boolean (monitor, session, "is_active");
}
More information about the hal-commit
mailing list