[Xfce4-commits] <xfce4-power-manager:master> Don't depend on libpolkit-gobject, instead use dbus-glib to get authorization information directly from polkitd

Ali Abdallah noreply at xfce.org
Wed Feb 3 13:52:01 CET 2010


Updating branch refs/heads/master
         to c933b8cfc97a09d788856f175592272da1d09c5d (commit)
       from bcb39852b82c6263a8bbe9312421be3534f5b45a (commit)

commit c933b8cfc97a09d788856f175592272da1d09c5d
Author: Ali Abdallah <aliov at xfce.org>
Date:   Wed Feb 3 13:40:35 2010 +0100

    Don't depend on libpolkit-gobject, instead use dbus-glib to get authorization information directly from polkitd

 configure.ac.in        |   19 ++-
 src/Makefile.am        |    4 +-
 src/xfpm-console-kit.c |    9 +-
 src/xfpm-disks.c       |   18 +-
 src/xfpm-main.c        |    2 +-
 src/xfpm-polkit.c      |  461 +++++++++++++++++++++++++++++++++++++++++++-----
 src/xfpm-power.c       |   20 +-
 7 files changed, 462 insertions(+), 71 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 19b7f93..2176a20 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -75,8 +75,21 @@ XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0],[libxfce4util_minimum_versi
 XDT_CHECK_PACKAGE([LIBNOTIFY],[libnotify], [libnotify_minimum_version])
 XDT_CHECK_PACKAGE([XRANDR],[xrandr], [xrandr_minimum_version])
 
-POLKIT="no"
-XDT_CHECK_OPTIONAL_PACKAGE([POLKIT], [polkit-gobject-1], [polkit_minimum_version], [polkit], [Polkit support])
+#=======================================================#
+#              Polkit?			                #
+#=======================================================#
+AC_ARG_ENABLE([polkit],
+        [AC_HELP_STRING([--disable-polkit],
+                [Do not enable PolicyKit support (default=enabled)])],
+        [],
+        [ac_cv_enable_polkit=polkit])
+    AC_MSG_CHECKING([whether to build with polkit support])
+if test "x$ac_cv_enable_polkit" = !"xyes"; then
+    AC_MSG_RESULT([no])
+else
+    AC_MSG_RESULT([yes])
+    AC_DEFINE(ENABLE_POLKIT, 1 , [PolicyKit support])
+fi
 
 #=======================================================#
 #              Use HAL?			                #
@@ -232,7 +245,7 @@ echo "
 	prefix:			${prefix}
 	xdg autostart:		${sysconfdir/xdg/autostart}
 	HAL:			${enable_hal}
-	POLKIT:			${POLKIT_FOUND}
+	POLKIT:			${ac_cv_enable_polkit}
    	DPMS:   		${have_dpms}
 	Network manager:	${ac_network_manager}
   	Build panel plugins:	${build_panel_plugins}
diff --git a/src/Makefile.am b/src/Makefile.am
index 9792b33..8685f8c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -99,6 +99,8 @@ manpage_DATA = xfce4-power-manager.1
 xfpm_glib_headers =                             \
         $(srcdir)/xfpm-enum-glib.h
 
+if MAINTAINER_MODE
+
 BUILT_SOURCES =					\
 	xfce-power-manager-dbus-server.h	\
 	xfce-power-manager-dbus-client.h	\
@@ -109,8 +111,6 @@ BUILT_SOURCES =					\
 	org.freedesktop.PowerManagement.h       \
 	org.freedesktop.PowerManagement.Inhibit.h
 
-if MAINTAINER_MODE
-
 xfpm-enum-types.h: $(xfpm_glib_headers)
 	( cd $(srcdir) && glib-mkenums \
 		--fhead "#ifndef _XFPM_ENUM_TYPES_H\n#define _XFPM_ENUM_TYPES_H\n#include <glib-object.h>\nG_BEGIN_DECLS\n" \
diff --git a/src/xfpm-console-kit.c b/src/xfpm-console-kit.c
index cffc8b5..775d219 100644
--- a/src/xfpm-console-kit.c
+++ b/src/xfpm-console-kit.c
@@ -140,10 +140,11 @@ xfpm_console_kit_init (XfpmConsoleKit *console)
 	goto out;
     }
     
-    console->priv->proxy = dbus_g_proxy_new_for_name (console->priv->bus,
-						      "org.freedesktop.ConsoleKit",
-						      "/org/freedesktop/ConsoleKit/Manager",
-						      "org.freedesktop.ConsoleKit.Manager");
+    console->priv->proxy = dbus_g_proxy_new_for_name_owner (console->priv->bus,
+							    "org.freedesktop.ConsoleKit",
+							    "/org/freedesktop/ConsoleKit/Manager",
+							    "org.freedesktop.ConsoleKit.Manager",
+							    NULL);
 						      
     if ( !console->priv->proxy )
     {
diff --git a/src/xfpm-disks.c b/src/xfpm-disks.c
index dbceaad..e9f36f1 100644
--- a/src/xfpm-disks.c
+++ b/src/xfpm-disks.c
@@ -190,18 +190,20 @@ xfpm_disks_init (XfpmDisks *disks)
 	goto out;
     }
     
-    disks->priv->proxy = dbus_g_proxy_new_for_name (disks->priv->bus,
-						    "org.freedesktop.UDisks",
-						    "/org/freedesktop/UDisks",
-						    "org.freedesktop.UDisks");
+    disks->priv->proxy = dbus_g_proxy_new_for_name_owner (disks->priv->bus,
+							  "org.freedesktop.UDisks",
+							  "/org/freedesktop/UDisks",
+							  "org.freedesktop.UDisks",
+							  NULL);
     
     if ( !disks->priv->proxy )
     {
 	g_message ("UDisks not found, trying devkit-disks");
-	disks->priv->proxy = dbus_g_proxy_new_for_name (disks->priv->bus,
-							"org.freedesktop.DeviceKit.Disks",
-							"/org/freedesktop/DeviceKit/Disks",
-							"org.freedesktop.DeviceKit.Disks");
+	disks->priv->proxy = dbus_g_proxy_new_for_name_owner (disks->priv->bus,
+							      "org.freedesktop.DeviceKit.Disks",
+							      "/org/freedesktop/DeviceKit/Disks",
+							      "org.freedesktop.DeviceKit.Disks",
+							      NULL);
     }
     
     if ( !disks->priv->proxy )
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index 766a001..3caa3da 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -114,7 +114,7 @@ xfpm_dump (GHashTable *hash)
 #else
     g_print (_("Without HAL support\n"));
 #endif
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
     g_print (_("With policykit support\n"));
 #else
     g_print (_("Without policykit support\n"));
diff --git a/src/xfpm-polkit.c b/src/xfpm-polkit.c
index a63e7a9..cfe65aa 100644
--- a/src/xfpm-polkit.c
+++ b/src/xfpm-polkit.c
@@ -26,13 +26,16 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <dbus/dbus-glib.h>
-
-#ifdef HAVE_POLKIT
-#include <polkit/polkit.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
 #endif
 
+#include <dbus/dbus-glib.h>
+
 #include "xfpm-polkit.h"
+#include "xfpm-debug.h"
+
+#include "xfpm-common.h"
 
 static void xfpm_polkit_finalize   (GObject *object);
 
@@ -42,8 +45,19 @@ static void xfpm_polkit_finalize   (GObject *object);
 struct XfpmPolkitPrivate
 {
     DBusGConnection   *bus;
-#ifdef HAVE_POLKIT
-    PolkitAuthority   *authority;
+
+#ifdef ENABLE_POLKIT
+    DBusGProxy        *proxy;
+    GValueArray       *subject;
+    GHashTable        *details;
+    GHashTable        *subject_hash;
+
+    GType              subject_gtype;
+    GType              details_gtype;
+    GType              result_gtype;
+
+    gulong             destroy_id;
+    gboolean           subject_valid;
 #endif
 };
 
@@ -57,51 +71,353 @@ static guint signals [LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (XfpmPolkit, xfpm_polkit, G_TYPE_OBJECT)
 
-static gboolean 
-xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
+#ifdef ENABLE_POLKIT
+#if defined(__FreeBSD__)
+/**
+ * Taken from polkitunixprocess.c code to get process start
+ * time from pid.
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ **/
+static gboolean
+get_kinfo_proc (pid_t pid, struct kinfo_proc *p)
 {
-#ifdef HAVE_POLKIT
-    PolkitSubject *subj;
-    PolkitAuthorizationResult *res;
-    GError *error = NULL;
-    gboolean ret = FALSE;
+    int mib[4];
+    size_t len;
     
-    subj = polkit_unix_process_new (getpid ());
+    len = 4;
+    sysctlnametomib ("kern.proc.pid", mib, &len);
     
-    res = polkit_authority_check_authorization_sync (polkit->priv->authority, 
-						     subj, 
-						     action_id,
-						     NULL,
-						     POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
-						     NULL,
-						     &error);
+    len = sizeof (struct kinfo_proc);
+    mib[3] = pid;
     
-    if ( error )
+    if (sysctl (mib, 4, p, &len, NULL, 0) == -1)
+	return FALSE;
+
+    return TRUE;
+}
+#endif /*if defined(__FreeBSD__)*/
+
+static guint64
+get_start_time_for_pid (pid_t pid)
+{
+    guint64 start_time;
+#if !defined(__FreeBSD__)
+    gchar *filename;
+    gchar *contents;
+    size_t length;
+    gchar **tokens;
+    guint num_tokens;
+    gchar *p;
+    gchar *endp;
+  
+    start_time = 0;
+    contents = NULL;
+    
+    filename = g_strdup_printf ("/proc/%d/stat", pid);
+    
+    if (!g_file_get_contents (filename, &contents, &length, NULL))
+	goto out;
+
+    /* start time is the token at index 19 after the '(process name)' entry - since only this
+     * field can contain the ')' character, search backwards for this to avoid malicious
+     * processes trying to fool us
+     */
+    p = strrchr (contents, ')');
+    if (p == NULL)
     {
-	g_warning ("Unable to get authorization result for action :%s : %s", action_id, error->message);
-	g_error_free (error);
 	goto out;
     }
     
-    if (polkit_authorization_result_get_is_authorized (res))
+    p += 2; /* skip ') ' */
+
+    if (p - contents >= (int) length)
+    {
+	g_warning ("Error parsing file %s", filename);
+	goto out;
+    }
+    
+    tokens = g_strsplit (p, " ", 0);
+    
+    num_tokens = g_strv_length (tokens);
+    
+    if (num_tokens < 20)
+    {
+	g_warning ("Error parsing file %s", filename);
+	goto out;
+    }
+
+    start_time = strtoull (tokens[19], &endp, 10);
+    if (endp == tokens[19])
+    {
+	g_warning ("Error parsing file %s", filename);
+	goto out;
+    }
+    g_strfreev (tokens);
+
+ out:
+    g_free (filename);
+    g_free (contents);
+    
+#else /*if !defined(__FreeBSD__)*/
+
+    struct kinfo_proc p;
+    
+    start_time = 0;
+
+    if (! get_kinfo_proc (pid, &p))
     {
-	ret = TRUE;
+	g_warning ("Error obtaining start time for %d (%s)",
+		   (gint) pid,
+		   g_strerror (errno));
+	goto out;
     }
+
+    start_time = (guint64) p.ki_start.tv_sec;
     
 out:
-    if (res)
-	g_object_unref (res);
+#endif
+    
+    return start_time;
+}
+#endif /*ENABLE_POLKIT*/
+
+
+#ifdef ENABLE_POLKIT
+static gboolean
+xfpm_polkit_free_data (gpointer data)
+{
+    XfpmPolkit *polkit;
+    
+    polkit = XFPM_POLKIT (data);
+
+    g_assert (polkit->priv->subject_valid);
+
+    XFPM_DEBUG ("Destroying Polkit data");
+
+    g_hash_table_destroy (polkit->priv->details);
+    g_hash_table_destroy (polkit->priv->subject_hash);
+    g_value_array_free   (polkit->priv->subject);
+    
+    polkit->priv->details      = NULL;
+    polkit->priv->subject_hash = NULL;
+    polkit->priv->subject      = NULL;
+
+    polkit->priv->destroy_id = 0;
+    polkit->priv->subject_valid = FALSE;
+    
+    return FALSE;
+}
+
+static void
+xfpm_polkit_init_data (XfpmPolkit *polkit)
+{
+    const gchar *consolekit_cookie;
+    GValue hash_elem = { 0 };
+    gboolean subject_created = FALSE;
+
+    if (polkit->priv->subject_valid)
+	return;
+    
+    /**
+     * This variable should be set by the session manager or by 
+     * the login manager (gdm?). under clean Xfce environment
+     * it is set by the session manager (4.8 and above)  
+     * since we don't have a login manager, yet!
+     **/
+    consolekit_cookie = g_getenv ("XDG_SESSION_COOKIE");
+  
+    if ( consolekit_cookie )
+    {
+	DBusGProxy *proxy;
+	GError *error = NULL;
+	gboolean ret;
+	gchar *consolekit_session;
 	
-    return ret;
+	proxy  = dbus_g_proxy_new_for_name_owner (polkit->priv->bus,
+						  "org.freedesktop.ConsoleKit",
+						  "/org/freedesktop/ConsoleKit/Manager",
+						  "org.freedesktop.ConsoleKit.Manager",
+						  NULL);
+	if ( proxy )
+	{
+	    ret = dbus_g_proxy_call (proxy, "GetSessionForCookie", &error,
+				     G_TYPE_STRING, consolekit_cookie,
+				     G_TYPE_INVALID,
+				     DBUS_TYPE_G_OBJECT_PATH, &consolekit_session,
+				     G_TYPE_INVALID);
+	    
+	    if ( G_LIKELY (ret) )
+	    {
+		GValue val  = { 0 };
+		
+		polkit->priv->subject = g_value_array_new (2);
+		polkit->priv->subject_hash = g_hash_table_new_full (g_str_hash, 
+								    g_str_equal, 
+								    g_free, 
+								    NULL);
+		g_value_init (&val, G_TYPE_STRING);
+		g_value_set_string (&val, "unix-session");
+		g_value_array_append (polkit->priv->subject, &val);
+		
+		g_value_unset (&val);
+		g_value_init (&val, G_TYPE_STRING);
+		g_value_set_string (&val, consolekit_session);
+		
+		g_hash_table_insert (polkit->priv->subject_hash, 
+				     g_strdup ("session-id"), 
+				     &val);
+		
+		g_free (consolekit_session);
+		XFPM_DEBUG ("Using ConsoleKit session Polkit subject");
+		subject_created = TRUE;
+	    }
+	    g_object_unref (proxy);
+	}
+	else if (error)
+	{
+	    g_warning ("'GetSessionForCookie' failed : %s", error->message);
+	    g_error_free (error);
+	}
+    }
+
+    if ( subject_created == FALSE )
+    {
+	gint pid;
+	guint64 start_time;
     
-#endif
+	pid = getpid ();
+	
+	start_time = get_start_time_for_pid (pid);
+	
+	if ( G_LIKELY (start_time != 0 ) )
+	{
+	    GValue val = { 0 }, pid_val = { 0 }, start_time_val = { 0 };
+	    
+	    polkit->priv->subject = g_value_array_new (2);
+	    polkit->priv->subject_hash = g_hash_table_new_full (g_str_hash, 
+								g_str_equal, 
+								g_free, 
+								NULL);
+	
+	    g_value_init (&val, G_TYPE_STRING);
+	    g_value_set_string (&val, "unix-process");
+	    g_value_array_append (polkit->priv->subject, &val);
+	    
+	    g_value_unset (&val);
+	    
+	    g_value_init (&pid_val, G_TYPE_UINT);
+	    g_value_set_uint (&pid_val, pid);
+	    g_hash_table_insert (polkit->priv->subject_hash, 
+				 g_strdup ("pid"), &pid_val);
+	    
+	    g_value_init (&start_time_val, G_TYPE_UINT64);
+	    g_value_set_uint64 (&start_time_val, start_time);
+	    g_hash_table_insert (polkit->priv->subject_hash, 
+				 g_strdup ("start-time"), &start_time_val);
+	    
+	    XFPM_DEBUG ("Using unix session polkit subject");
+	}
+	else
+	{
+	    g_warning ("Unable to create polkit subject");
+	}
+    }
+    
+    g_value_init (&hash_elem, 
+		  dbus_g_type_get_map ("GHashTable", 
+				       G_TYPE_STRING, 
+				       G_TYPE_VALUE));
+    
+    g_value_set_static_boxed (&hash_elem, polkit->priv->subject_hash);
+    g_value_array_append (polkit->priv->subject, &hash_elem);
+    
+    /**
+     * Polkit details, will leave it empty.
+     **/
+    polkit->priv->details = g_hash_table_new_full (g_str_hash, 
+						   g_str_equal, 
+						   g_free, 
+						   g_free);
+
+    
+    /*Clean these data after 2 minutes*/
+    polkit->priv->destroy_id = 
+	g_timeout_add_seconds (2, (GSourceFunc) xfpm_polkit_free_data, polkit);
+    
+    polkit->priv->subject_valid = TRUE;
+}
+#endif /*ENABLE_POLKIT*/
+
+static gboolean
+xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
+{
+#ifdef ENABLE_POLKIT
+    GValueArray *result;
+    GValue result_val = { 0 };
+    GError *error = NULL;
+    gboolean is_authorized = FALSE;
+    gboolean ret;
+    
+    /**
+     * <method name="CheckAuthorization">      
+     *   <arg type="(sa{sv})" name="subject" direction="in"/>      
+     *   <arg type="s" name="action_id" direction="in"/>           
+     *   <arg type="a{ss}" name="details" direction="in"/>         
+     *   <arg type="u" name="flags" direction="in"/>               
+     *   <arg type="s" name="cancellation_id" direction="in"/>     
+     *   <arg type="(bba{ss})" name="result" direction="out"/>     
+     * </method>
+     *
+     **/
+    
+    g_return_val_if_fail (polkit->priv->proxy != NULL, FALSE);
+    g_return_val_if_fail (polkit->priv->subject_valid, FALSE);
+     
+    result = g_value_array_new (0);
+    
+    ret = dbus_g_proxy_call (polkit->priv->proxy, "CheckAuthorization", &error,
+			     polkit->priv->subject_gtype, polkit->priv->subject,
+			     G_TYPE_STRING, action_id,
+			     polkit->priv->details_gtype, polkit->priv->details,
+			     G_TYPE_UINT, 0, 
+			     G_TYPE_STRING, NULL,
+			     G_TYPE_INVALID,
+			     polkit->priv->result_gtype, &result,
+			     G_TYPE_INVALID);
+    
+    if ( G_LIKELY (ret) )
+    {
+	g_value_init (&result_val, polkit->priv->result_gtype);
+	g_value_set_static_boxed (&result_val, result);
+	
+	dbus_g_type_struct_get (&result_val,
+				0, &is_authorized,
+				G_MAXUINT);
+	g_value_unset (&result_val);
+    }
+    else if ( error )
+    {
+	g_warning ("'CheckAuthorization' failed with %s", error->message);
+	g_error_free (error);
+    }
+
+    g_value_array_free (result);
+    
+    XFPM_DEBUG ("Action=%s is authorized=%s", action_id, xfpm_bool_to_string (is_authorized));
+    
+    return is_authorized;
+#endif /*ENABLE_POLKIT*/
     return TRUE;
 }
 
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
 static void
-xfpm_polkit_auth_changed_cb (PolkitAuthority *authority, XfpmPolkit *polkit)
+xfpm_polkit_changed_cb (DBusGProxy *proxy, XfpmPolkit *polkit)
 {
+    XFPM_DEBUG ("Auth changed");
+    g_signal_emit (G_OBJECT (polkit), signals [AUTH_CHANGED], 0);
 }
 #endif
 
@@ -130,6 +446,36 @@ xfpm_polkit_init (XfpmPolkit *polkit)
     GError *error = NULL;
     
     polkit->priv = XFPM_POLKIT_GET_PRIVATE (polkit);
+
+#ifdef ENABLE_POLKIT
+    polkit->priv->destroy_id   = 0;
+    polkit->priv->subject_valid   = FALSE;
+    polkit->priv->proxy        = NULL;
+    polkit->priv->subject      = NULL;
+    polkit->priv->details      = NULL;
+    polkit->priv->subject_hash = NULL;
+    
+    polkit->priv->subject_gtype = 
+        dbus_g_type_get_struct ("GValueArray", 
+                                G_TYPE_STRING, 
+                                dbus_g_type_get_map ("GHashTable", 
+                                                     G_TYPE_STRING, 
+                                                     G_TYPE_VALUE),
+                                G_TYPE_INVALID);
+    
+    polkit->priv->details_gtype = dbus_g_type_get_map ("GHashTable", 
+						       G_TYPE_STRING, 
+						       G_TYPE_STRING);
+    
+    polkit->priv->result_gtype =
+	dbus_g_type_get_struct ("GValueArray", 
+				G_TYPE_BOOLEAN, 
+				G_TYPE_BOOLEAN, 
+				dbus_g_type_get_map ("GHashTable", 
+						     G_TYPE_STRING, 
+						     G_TYPE_STRING),
+				G_TYPE_INVALID);
+#endif /*ENABLE_POLKIT*/
     
     polkit->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
     
@@ -139,16 +485,30 @@ xfpm_polkit_init (XfpmPolkit *polkit)
 	g_error_free (error);
 	goto out;
     }
-#ifdef HAVE_POLKIT
-    polkit->priv->authority = polkit_authority_get ();
-    g_signal_connect (polkit->priv->authority, "changed",
-		      G_CALLBACK (xfpm_polkit_auth_changed_cb), polkit);
-#endif
-    
+
+#ifdef ENABLE_POLKIT
+    polkit->priv->proxy = 
+	dbus_g_proxy_new_for_name_owner (polkit->priv->bus,
+					 "org.freedesktop.PolicyKit1",
+					 "/org/freedesktop/PolicyKit1/Authority",
+					 "org.freedesktop.PolicyKit1.Authority",
+					 &error);
     
+    if (G_LIKELY (polkit->priv->proxy) )
+    {
+	dbus_g_proxy_add_signal (polkit->priv->proxy, "Changed", G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal (polkit->priv->proxy, "Changed",
+				     G_CALLBACK (xfpm_polkit_changed_cb), polkit, NULL);
+    }
+    else
+    {
+	g_warning ("Failed to create proxy for 'org.freedesktop.PolicyKit1' : %s", error->message);
+	g_error_free (error);
+    }
+#endif /*ENABLE_POLKIT*/
+
 out:
     ;
-    
 }
 
 static void
@@ -157,10 +517,23 @@ xfpm_polkit_finalize (GObject *object)
     XfpmPolkit *polkit;
 
     polkit = XFPM_POLKIT (object);
-#ifdef HAVE_POLKIT
-    if (polkit->priv->authority )
-	g_object_unref (polkit->priv->authority);
-#endif
+
+#ifdef ENABLE_POLKIT
+    if ( polkit->priv->proxy )
+    {
+	dbus_g_proxy_disconnect_signal (polkit->priv->proxy, "Changed",
+					G_CALLBACK (xfpm_polkit_changed_cb), polkit);
+	g_object_unref (polkit->priv->proxy);
+    }
+
+    if ( polkit->priv->subject_valid )
+    {
+	xfpm_polkit_free_data (polkit);
+	if (polkit->priv->destroy_id != 0 )
+	    g_source_remove (polkit->priv->destroy_id);
+    }
+#endif /*ENABLE_POLKIT*/
+
 
     if ( polkit->priv->bus )
 	dbus_g_connection_unref (polkit->priv->bus);
@@ -180,6 +553,7 @@ xfpm_polkit_get (void)
     else
     {
 	xfpm_polkit_obj = g_object_new (XFPM_TYPE_POLKIT, NULL);
+	g_object_add_weak_pointer (xfpm_polkit_obj, &xfpm_polkit_obj);
     }
     
     return XFPM_POLKIT (xfpm_polkit_obj);
@@ -187,5 +561,6 @@ xfpm_polkit_get (void)
 
 gboolean xfpm_polkit_check_auth	(XfpmPolkit *polkit, const gchar *action_id)
 {
+    xfpm_polkit_init_data (polkit);
     return xfpm_polkit_check_auth_intern (polkit, action_id);
 }
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index c1a5425..116f0f6 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -56,10 +56,10 @@ static const gchar *BACKEND_PATH;
 static const gchar *BACKEND_IFACE;
 static const gchar *BACKEND_IFACE_DEVICE;
 static const gchar *BACKEND_PATH_DEVICE;
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
 static const gchar *POLKIT_AUTH_SUSPEND;
 static const gchar *POLKIT_AUTH_HIBERNATE;
-#endif /*HAVE_POLKIT*/
+#endif /*ENABLE_POLKIT*/
 
 static void xfpm_power_finalize     (GObject *object);
 
@@ -93,7 +93,7 @@ struct XfpmPowerPrivate
     gboolean	     inhibited;
     
     XfpmNotify	    *notify;
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
     XfpmPolkit 	    *polkit;
 #endif
     gboolean	     auth_suspend;
@@ -146,7 +146,7 @@ static guint signals [LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (XfpmPower, xfpm_power, G_TYPE_OBJECT)
 
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
 static void
 xfpm_power_check_polkit_auth (XfpmPower *power)
 {
@@ -1079,7 +1079,7 @@ xfpm_power_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, XfpmP
     }
 }
 
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
 static void
 xfpm_power_polkit_auth_changed_cb (XfpmPower *power)
 {
@@ -1310,7 +1310,7 @@ xfpm_power_init (XfpmPower *power)
     g_signal_connect_swapped (power->priv->conf, "notify::" SHOW_TRAY_ICON_CFG,
 			      G_CALLBACK (xfpm_power_refresh_adaptor_visible), power);
     
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
     power->priv->polkit  = xfpm_polkit_get ();
     g_signal_connect_swapped (power->priv->polkit, "auth-changed",
 			      G_CALLBACK (xfpm_power_polkit_auth_changed_cb), power);
@@ -1343,7 +1343,7 @@ xfpm_power_init (XfpmPower *power)
 	BACKEND_IFACE         =  UPOWER_IFACE;
 	BACKEND_IFACE_DEVICE  =  UPOWER_IFACE_DEVICE;
 	BACKEND_PATH_DEVICE   =  UPOWER_PATH_DEVICE;
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
 	POLKIT_AUTH_SUSPEND   = "org.freedesktop.upower.suspend";
 	POLKIT_AUTH_HIBERNATE = "org.freedesktop.upower.hibernate";
 #endif
@@ -1366,7 +1366,7 @@ xfpm_power_init (XfpmPower *power)
 	    BACKEND_IFACE =   DKP_IFACE;
 	    BACKEND_IFACE_DEVICE =  DKP_IFACE_DEVICE;
 	    BACKEND_PATH_DEVICE  =  DKP_PATH_DEVICE;
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
 	    POLKIT_AUTH_SUSPEND = "org.freedesktop.devicekit.power.suspend";
 	    POLKIT_AUTH_HIBERNATE = "org.freedesktop.devicekit.power.hibernate";
 #endif
@@ -1390,7 +1390,7 @@ xfpm_power_init (XfpmPower *power)
     
     xfpm_power_get_power_devices (power);
     xfpm_power_get_properties (power);
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
     xfpm_power_check_polkit_auth (power);
 #endif
 
@@ -1491,7 +1491,7 @@ xfpm_power_finalize (GObject *object)
 
     g_hash_table_destroy (power->priv->hash);
 
-#ifdef HAVE_POLKIT
+#ifdef ENABLE_POLKIT
     g_object_unref (power->priv->polkit);
 #endif
 



More information about the Xfce4-commits mailing list