[system-tools-backends-clone] Port to PolicyKit1



commit 44a0d8ab8e6cc286132fa30ac5cfff481e573bdd
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Mon Aug 17 13:15:15 2009 +0200

    Port to PolicyKit1
    
    We can remove many parts of the code thanks to the new version. This is fully incompatible with previous API of PolicyKit, so clients need to be updated too. This patch uses D-Bus connexion to identify the client, which does not work for now with PolkitLockButton in the GUI. Next patch fixes that, but could possibly be reverted or simplified later.

 configure.in            |    6 ++--
 dispatcher/dispatcher.c |   86 ++++++----------------------------------------
 2 files changed, 15 insertions(+), 77 deletions(-)
---
diff --git a/configure.in b/configure.in
index 49e537f..864a5e1 100644
--- a/configure.in
+++ b/configure.in
@@ -12,7 +12,7 @@ IT_PROG_INTLTOOL([0.40.0])
 DBUS_REQUIRED=1.1.2
 DBUS_GLIB_REQUIRED=0.74
 GLIB_REQUIRED=2.4.0
-POLICYKIT_REQUIRED=0.5
+POLICYKIT_REQUIRED=0.92
 GIO_REQUIRED=2.15.2
 
 dnl get prefix in $prefix, yes, this sucks
@@ -66,7 +66,7 @@ DBUS_SERVICES_DIR="${prefix}/share/dbus-1/system-services"
 AC_SUBST(DBUS_SERVICES_DIR)
 
 dnl PolicyKit policy files dir
-POLKIT_POLICY_DIR="${prefix}/share/PolicyKit/policy/"
+POLKIT_POLICY_DIR="${datadir}/polkit-1/actions/"
 AC_SUBST(POLKIT_POLICY_DIR)
 
 dnl where is DBus system.d directory?
@@ -123,7 +123,7 @@ AC_SUBST(DISPATCHER_LIBS)
 AC_SUBST(DISPATCHER_CFLAGS)
 
 dnl check for PolicyKit
-PKG_CHECK_MODULES(POLKIT, polkit-dbus >= $POLICYKIT_REQUIRED, have_polkit=yes, have_polkit=no)
+PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= $POLICYKIT_REQUIRED, have_polkit=yes, have_polkit=no)
 
 if test "$have_polkit" = "yes"; then
   AC_DEFINE(HAVE_POLKIT, [1], [whether PolicyKit was found])
diff --git a/dispatcher/dispatcher.c b/dispatcher/dispatcher.c
index 90b425f..9da6dec 100644
--- a/dispatcher/dispatcher.c
+++ b/dispatcher/dispatcher.c
@@ -32,7 +32,6 @@
 
 #ifdef HAVE_POLKIT
 #include <polkit/polkit.h>
-#include <polkit-dbus/polkit-dbus.h>
 #endif
 
 #ifdef HAVE_GIO
@@ -67,7 +66,7 @@ struct StbDispatcherPrivate
   gchar *platform;
 
 #ifdef HAVE_POLKIT
-  PolKitContext *polkit_context;
+  PolkitAuthority *polkit_authority;
 #endif
 
 #ifdef HAVE_GIO
@@ -319,10 +318,8 @@ can_caller_do_action (StbDispatcher *dispatcher,
 {
 #ifdef HAVE_POLKIT
   StbDispatcherPrivate *priv;
-  PolKitAction *action;
-  PolKitCaller *caller;
-  DBusError error;
-  PolKitResult result;
+  PolkitSubject *subject;
+  PolkitAuthorizationResult *result;
   const gchar *member;
   gchar *action_id;
   gboolean retval;
@@ -340,35 +337,23 @@ can_caller_do_action (StbDispatcher *dispatcher,
 
   g_return_val_if_fail (member != NULL, FALSE);
 
-  action = polkit_action_new ();
-
   if (name)
     action_id = g_strdup_printf ("org.freedesktop.systemtoolsbackends.%s.%s", name, member);
   else
     action_id = g_strdup_printf ("org.freedesktop.systemtoolsbackends.%s", member);
 
-  polkit_action_set_action_id (action, action_id);
-
-  dbus_error_init (&error);
-  caller = polkit_caller_new_from_dbus_name (priv->connection, dbus_message_get_sender (message), &error);
-
-  if (dbus_error_is_set (&error))
-    {
-      g_critical ("%s", error.message);
-      dbus_error_free (&error);
-
-      return FALSE;
-    }
+  subject = polkit_system_bus_name_new  (dbus_message_get_sender (message));
 
-  result = polkit_context_can_caller_do_action (priv->polkit_context, action, caller);
+  result = polkit_authority_check_authorization_sync (priv->polkit_authority, subject, action_id, NULL,
+                                                      POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
+                                                      NULL, NULL);
 
-  polkit_caller_unref (caller);
-  polkit_action_unref (action);
+  g_object_unref (subject);
 
-  retval = (result == POLKIT_RESULT_YES);
+  retval = polkit_authorization_result_get_is_authorized (result);
 
   DEBUG (dispatcher,
-	 (retval) ? "caller is allowed to do action '%s'" : "caller can't do action '%s'",
+	 (retval) ? "subject is allowed to do action '%s'" : "subject can't do action '%s'",
 	 action_id);
 
   g_free (action_id);
@@ -615,48 +600,6 @@ setup_connection (StbDispatcher *dispatcher)
   dbus_connection_setup_with_g_main (priv->connection, NULL);
 }
 
-#ifdef HAVE_POLKIT
-static gboolean
-stb_polkit_io_watch_func (GIOChannel   *channel,
-			  GIOCondition  condition,
-			  gpointer      user_data)
-{
-  int fd;
-  PolKitContext *pk_context;
-
-  pk_context = (PolKitContext *) user_data;
-  fd = g_io_channel_unix_get_fd (channel);
-  polkit_context_io_func (pk_context, fd);
-
-  return TRUE;
-}
-
-static int
-stb_polkit_io_add_watch (PolKitContext *context,
-			 int            fd)
-{
-  guint watch_id = 0;
-  GIOChannel *channel;
-
-  channel = g_io_channel_unix_new (fd);
-
-  if (!channel)
-    return 0;
-
-  watch_id = g_io_add_watch (channel, G_IO_IN, stb_polkit_io_watch_func, context);
-  g_io_channel_unref (channel);
-
-  return watch_id;
-}
-
-static void
-stb_polkit_io_remove_watch (PolKitContext *context,
-			    int            watch_id)
-{
-  g_source_remove (watch_id);
-}
-#endif
-
 static void
 stb_dispatcher_init (StbDispatcher *dispatcher)
 {
@@ -671,12 +614,7 @@ stb_dispatcher_init (StbDispatcher *dispatcher)
   g_assert (priv->connection != NULL);
 
 #ifdef HAVE_POLKIT
-  priv->polkit_context = polkit_context_new ();
-  polkit_context_set_io_watch_functions (priv->polkit_context,
-					 stb_polkit_io_add_watch,
-					 stb_polkit_io_remove_watch);
-
-  polkit_context_init (priv->polkit_context, NULL);
+  priv->polkit_authority = polkit_authority_get ();
 #endif
 
 #ifdef HAVE_GIO
@@ -731,7 +669,7 @@ stb_dispatcher_finalize (GObject *object)
   dbus_connection_unref (priv->connection);
 
 #ifdef HAVE_POLKIT
-  polkit_context_unref  (priv->polkit_context);
+  g_object_unref (priv->polkit_authority);
 #endif
 
 #ifdef HAVE_GIO



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]