Port to polkit-1
authorDavid Zeuthen <davidz@redhat.com>
Mon, 11 May 2009 20:27:15 +0000 (16:27 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 11 May 2009 20:27:15 +0000 (16:27 -0400)
configure.ac
policy/Makefile.am
policy/org.freedesktop.devicekit.disks.policy.in
src/Makefile.am
src/devkit-disks-ata-smart-db.c
src/devkit-disks-daemon.c
src/devkit-disks-daemon.h
src/devkit-disks-device-private.h
src/devkit-disks-device.c
src/devkit-disks-device.h
src/devkit-disks-inhibitor.c

index bde449f..0fc3e8b 100644 (file)
@@ -141,9 +141,15 @@ PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.74])
 AC_SUBST(DBUS_GLIB_CFLAGS)
 AC_SUBST(DBUS_GLIB_LIBS)
 
-PKG_CHECK_MODULES(POLKIT_DBUS, [polkit-dbus >= 0.7])
-AC_SUBST(POLKIT_DBUS_CFLAGS)
-AC_SUBST(POLKIT_DBUS_LIBS)
+msg_polkit_gobject_1=no
+PKG_CHECK_MODULES(POLKIT_GOBJECT_1,
+                  polkit-gobject-1 >= 0.92,
+                  [AM_CONDITIONAL(HAVE_POLKIT_GOBJECT_1, true)
+                   AC_DEFINE(HAVE_POLKIT_GOBJECT_1, [], [Set if polkit-gobject-1 is available])]
+                   msg_polkit_gobject_1=yes,
+                   [AM_CONDITIONAL(HAVE_POLKIT_GOBJECT_1, false)])
+AC_SUBST(POLKIT_GOBJECT_1_CFLAGS)
+AC_SUBST(POLKIT_GOBJECT_1_LIBS)
 
 PKG_CHECK_MODULES(LIBPARTED, [libparted >= 1.8.8])
 AC_SUBST(LIBPARTED_CFLAGS)
index bb295e5..3a5d80b 100644 (file)
@@ -1,14 +1,8 @@
 
-devkit_policydir = $(datadir)/PolicyKit/policy
-
-dist_devkit_policy_DATA =                                      \
-       org.freedesktop.devicekit.disks.policy
-
+policydir = $(datadir)/polkit-1/actions
+dist_policy_DATA = org.freedesktop.devicekit.disks.policy
 @INTLTOOL_POLICY_RULE@
 
-check:
-       polkit-policy-file-validate $(top_srcdir)/policy/$(dist_devkit_policy_DATA)
-
 clean-local :
        rm -f *~ *.policy
 
index 361252e..e399c54 100644 (file)
@@ -4,16 +4,6 @@
  "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
 
-<!--
-Policy definitions for DeviceKit-disks
-
-Copyright (c) 2008 David Zeuthen <david@fubar.dk>
-
-NOTE: If you make changes to this file, make sure to validate the file
-using the polkit-policy-file-validate(1) tool. Changes made to this
-file are instantly applied.
--->
-
 <policyconfig>
   <vendor>The DeviceKit Project</vendor>
   <vendor_url>http://hal.freedesktop.org/docs/DeviceKit/</vendor_url>
index e278dfa..38d3b97 100644 (file)
@@ -13,7 +13,7 @@ INCLUDES = \
        -DPACKAGE_LIB_DIR=\""$(libdir)"\" \
        -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
        $(DBUS_GLIB_CFLAGS) \
-       $(POLKIT_DBUS_CFLAGS) \
+       $(POLKIT_GOBJECT_1_CFLAGS) \
        $(DEVKIT_CFLAGS) \
        $(GLIB_CFLAGS) \
        $(GIO_CFLAGS)
@@ -71,7 +71,7 @@ devkit_disks_daemon_CFLAGS =                          \
 devkit_disks_daemon_LDADD =                            \
        $(GIO_LIBS)                                     \
        $(DBUS_GLIB_LIBS)                               \
-       $(POLKIT_DBUS_LIBS)                             \
+       $(POLKIT_GOBJECT_1_LIBS)                        \
        $(DEVKIT_LIBS)                                  \
        $(ZLIB_LIBS)                                    \
        $(SQLITE3_LIBS)                                 \
index e3410b9..bc6e65f 100644 (file)
@@ -83,9 +83,9 @@ devkit_disks_ata_smart_db_init (DevkitDisksAtaSmartDb *db)
                                SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
                                NULL);
         if (ret != SQLITE_OK) {
-                g_warning ("error opening sqlite3 database at "
-                           PACKAGE_LOCALSTATE_DIR "/lib/DeviceKit-disks/ata-smart-db.sqlite3"
-                           ": %s", sqlite3_errmsg (db->priv->db));
+                g_debug ("error opening sqlite3 database at "
+                         PACKAGE_LOCALSTATE_DIR "/lib/DeviceKit-disks/ata-smart-db.sqlite3"
+                         ": %s", sqlite3_errmsg (db->priv->db));
                 sqlite3_close (db->priv->db);
                 g_object_unref (db);
                 goto out;
@@ -108,7 +108,7 @@ devkit_disks_ata_smart_db_init (DevkitDisksAtaSmartDb *db)
                             NULL,
                             &err_msg);
         if (ret != SQLITE_OK) {
-                g_warning ("SQL error creating tables: %s", err_msg);
+                g_debug ("SQL error creating tables: %s", err_msg);
                 sqlite3_free (err_msg);
         }
 
index b7935d5..2460e7a 100644 (file)
@@ -103,8 +103,8 @@ struct DevkitDisksDaemonPrivate
 {
         DBusGConnection         *system_bus_connection;
         DBusGProxy              *system_bus_proxy;
-        PolKitContext           *pk_context;
-        PolKitTracker           *pk_tracker;
+
+        PolkitAuthority         *authority;
 
         DevkitClient            *devkit_client;
 
@@ -167,6 +167,7 @@ devkit_disks_error_get_type (void)
         {
                 static const GEnumValue values[] = {
                         ENUM_ENTRY (DEVKIT_DISKS_ERROR_FAILED, "Failed"),
+                        ENUM_ENTRY (DEVKIT_DISKS_ERROR_PERMISSION_DENIED, "PermissionDenied"),
                         ENUM_ENTRY (DEVKIT_DISKS_ERROR_INHIBITED, "Inhibited"),
                         ENUM_ENTRY (DEVKIT_DISKS_ERROR_BUSY, "Busy"),
                         ENUM_ENTRY (DEVKIT_DISKS_ERROR_CANCELLED, "Cancelled"),
@@ -554,11 +555,8 @@ devkit_disks_daemon_finalize (GObject *object)
 
         g_return_if_fail (daemon->priv != NULL);
 
-        if (daemon->priv->pk_context != NULL)
-                polkit_context_unref (daemon->priv->pk_context);
-
-        if (daemon->priv->pk_tracker != NULL)
-                polkit_tracker_unref (daemon->priv->pk_tracker);
+        if (daemon->priv->authority != NULL)
+                g_object_unref (daemon->priv->authority);
 
         if (daemon->priv->system_bus_proxy != NULL)
                 g_object_unref (daemon->priv->system_bus_proxy);
@@ -620,63 +618,22 @@ devkit_disks_daemon_finalize (GObject *object)
         G_OBJECT_CLASS (devkit_disks_daemon_parent_class)->finalize (object);
 }
 
-static gboolean
-pk_io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer user_data)
-{
-        int fd;
-        PolKitContext *pk_context = user_data;
-        fd = g_io_channel_unix_get_fd (channel);
-        polkit_context_io_func (pk_context, fd);
-        return TRUE;
-}
-
-static int
-pk_io_add_watch (PolKitContext *pk_context, int fd)
-{
-        guint id = 0;
-        GIOChannel *channel;
-        channel = g_io_channel_unix_new (fd);
-        if (channel == NULL)
-                goto out;
-        id = g_io_add_watch (channel, G_IO_IN, pk_io_watch_have_data, pk_context);
-        if (id == 0) {
-                g_io_channel_unref (channel);
-                goto out;
-        }
-        g_io_channel_unref (channel);
-out:
-        return id;
-}
-
-static void
-pk_io_remove_watch (PolKitContext *pk_context, int watch_id)
-{
-        g_source_remove (watch_id);
-}
 
 void devkit_disks_inhibitor_name_owner_changed (DBusMessage *message);
 
 static DBusHandlerResult
 _filter (DBusConnection *connection, DBusMessage *message, void *user_data)
 {
-        DevkitDisksDaemon *daemon = DEVKIT_DISKS_DAEMON (user_data);
+        //DevkitDisksDaemon *daemon = DEVKIT_DISKS_DAEMON (user_data);
         const char *interface;
 
         interface = dbus_message_get_interface (message);
 
         if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
-                /* pass NameOwnerChanged signals from the bus to PolKitTracker */
-                polkit_tracker_dbus_func (daemon->priv->pk_tracker, message);
-
                 /* for now, pass NameOwnerChanged to DevkitDisksInhibitor */
                 devkit_disks_inhibitor_name_owner_changed (message);
         }
 
-        if (interface != NULL && g_str_has_prefix (interface, "org.freedesktop.ConsoleKit")) {
-                /* pass ConsoleKit signals to PolKitTracker */
-                polkit_tracker_dbus_func (daemon->priv->pk_tracker, message);
-        }
-
         /* other filters might want to process this message too */
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
@@ -1019,12 +976,7 @@ register_disks_daemon (DevkitDisksDaemon *daemon)
         GError *error = NULL;
         const char *subsystems[] = {"block", NULL};
 
-        daemon->priv->pk_context = polkit_context_new ();
-        polkit_context_set_io_watch_functions (daemon->priv->pk_context, pk_io_add_watch, pk_io_remove_watch);
-        if (!polkit_context_init (daemon->priv->pk_context, NULL)) {
-                g_critical ("cannot initialize libpolkit");
-                goto error;
-        }
+        daemon->priv->authority = polkit_authority_get ();
 
         error = NULL;
         daemon->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
@@ -1037,10 +989,6 @@ register_disks_daemon (DevkitDisksDaemon *daemon)
         }
         connection = dbus_g_connection_get_connection (daemon->priv->system_bus_connection);
 
-        daemon->priv->pk_tracker = polkit_tracker_new ();
-        polkit_tracker_set_system_bus_connection (daemon->priv->pk_tracker, connection);
-        polkit_tracker_init (daemon->priv->pk_tracker);
-
         dbus_g_connection_register_g_object (daemon->priv->system_bus_connection, "/org/freedesktop/DeviceKit/Disks",
                                              G_OBJECT (daemon));
 
@@ -1202,34 +1150,6 @@ devkit_disks_daemon_local_get_mount_monitor (DevkitDisksDaemon *daemon)
         return daemon->priv->mount_monitor;
 }
 
-PolKitCaller *
-devkit_disks_damon_local_get_caller_for_context (DevkitDisksDaemon *daemon,
-                                                 DBusGMethodInvocation *context)
-{
-        const char *sender;
-        GError *error;
-        DBusError dbus_error;
-        PolKitCaller *pk_caller;
-
-        sender = dbus_g_method_get_sender (context);
-        dbus_error_init (&dbus_error);
-        pk_caller = polkit_tracker_get_caller_from_dbus_name (daemon->priv->pk_tracker,
-                                                              sender,
-                                                              &dbus_error);
-        if (pk_caller == NULL) {
-                error = g_error_new (DEVKIT_DISKS_ERROR,
-                                     DEVKIT_DISKS_ERROR_FAILED,
-                                     "Error getting information about caller: %s: %s",
-                                     dbus_error.name, dbus_error.message);
-                dbus_error_free (&dbus_error);
-                dbus_g_method_return_error (context, error);
-                g_error_free (error);
-                return NULL;
-        }
-
-        return pk_caller;
-}
-
 /*--------------------------------------------------------------------------------------------------------------*/
 
 static gboolean
@@ -1255,57 +1175,43 @@ throw_error (DBusGMethodInvocation *context, int error_code, const char *format,
 /*--------------------------------------------------------------------------------------------------------------*/
 
 gboolean
-devkit_disks_damon_local_check_auth (DevkitDisksDaemon     *daemon,
-                                     PolKitCaller          *pk_caller,
-                                     const char            *action_id,
-                                     DBusGMethodInvocation *context)
+devkit_disks_daemon_local_get_uid (DevkitDisksDaemon     *daemon,
+                                   uid_t                 *out_uid,
+                                   DBusGMethodInvocation *context)
 {
-        gboolean ret;
-        GError *error;
-        DBusError d_error;
-        PolKitAction *pk_action;
-        PolKitResult pk_result;
-
-        ret = FALSE;
-
-        if (daemon->priv->inhibitors != NULL) {
-                uid_t uid;
+        gchar *sender;
+        DBusError dbus_error;
+        DBusConnection *connection;
 
-                uid = (uid_t) -1;
-                if (!polkit_caller_get_uid (pk_caller, &uid) || uid != 0) {
-                        if (context != NULL)
-                                throw_error (context,
-                                             DEVKIT_DISKS_ERROR_INHIBITED,
-                                             "Daemon is being inhibited");
-                }
+        /* context can be NULL for things called by the daemon itself e.g. ATA SMART refresh */
+        if (context == NULL) {
+                *out_uid = 0;
                 goto out;
         }
 
-        pk_action = polkit_action_new ();
-        polkit_action_set_action_id (pk_action, action_id);
-        pk_result = polkit_context_is_caller_authorized (daemon->priv->pk_context,
-                                                         pk_action,
-                                                         pk_caller,
-                                                         TRUE,
-                                                         NULL);
-        if (pk_result == POLKIT_RESULT_YES) {
-                ret = TRUE;
-        } else {
+        /* TODO: right now this is synchronous and slow; when we switch to a better D-Bus
+         *       binding a'la EggDBus there will be a utility class (with caching) where we
+         *       can get this from
+         */
 
-                dbus_error_init (&d_error);
-                polkit_dbus_error_generate (pk_action, pk_result, &d_error);
-                if (context != NULL) {
-                        error = NULL;
-                        dbus_set_g_error (&error, &d_error);
-                        dbus_g_method_return_error (context, error);
-                        g_error_free (error);
-                }
-                dbus_error_free (&d_error);
+        sender = dbus_g_method_get_sender (context);
+        connection = dbus_g_connection_get_connection (daemon->priv->system_bus_connection);
+        dbus_error_init (&dbus_error);
+        *out_uid = dbus_bus_get_unix_user (connection,
+                                           sender,
+                                           &dbus_error);
+        if (dbus_error_is_set (&dbus_error)) {
+                *out_uid = 0;
+                g_warning ("Cannot get uid for sender %s: %s: %s",
+                           sender,
+                           dbus_error.name,
+                           dbus_error.message);
+                dbus_error_free (&dbus_error);
         }
-        polkit_action_unref (pk_action);
+        g_free (sender);
 
  out:
-        return ret;
+        return TRUE;
 }
 
 /*--------------------------------------------------------------------------------------------------------------*/
@@ -1332,6 +1238,183 @@ devkit_disks_daemon_local_update_poller (DevkitDisksDaemon *daemon)
 }
 
 /*--------------------------------------------------------------------------------------------------------------*/
+
+typedef struct
+{
+        gchar *action_id;
+        DevkitDisksCheckAuthCallback check_auth_callback;
+        DBusGMethodInvocation *context;
+        DevkitDisksDaemon *daemon;
+        DevkitDisksDevice *device;
+
+        GCancellable *cancellable;
+        guint num_user_data;
+        gpointer *user_data_elements;
+        GDestroyNotify *user_data_notifiers;
+
+        DevkitDisksInhibitor *caller;
+} CheckAuthData;
+
+/* invoked when device is removed during authorization check */
+static void
+lca_device_went_away (gpointer user_data, GObject *where_the_object_was)
+{
+        CheckAuthData *data = user_data;
+
+        g_object_weak_unref (G_OBJECT (data->device), lca_device_went_away, data);
+        data->device = NULL;
+
+        /* this will trigger lca_check_authorization_callback() */
+        g_cancellable_cancel (data->cancellable);
+}
+
+/* invoked when caller disconnects during authorization check */
+static void
+lca_caller_disconnected_cb (DevkitDisksInhibitor *inhibitor,
+                            gpointer              user_data)
+{
+        CheckAuthData *data = user_data;
+
+        /* this will trigger lca_check_authorization_callback() */
+        g_cancellable_cancel (data->cancellable);
+}
+
+static void
+check_auth_data_free (CheckAuthData *data)
+{
+        guint n;
+
+        g_free (data->action_id);
+        g_object_unref (data->daemon);
+        if (data->device != NULL)
+                g_object_weak_unref (G_OBJECT (data->device), lca_device_went_away, data);
+        g_object_unref (data->cancellable);
+        for (n = 0; n < data->num_user_data; n++) {
+                if (data->user_data_notifiers[n] != NULL)
+                        data->user_data_notifiers[n] (data->user_data_elements[n]);
+        }
+        g_free (data->user_data_elements);
+        g_free (data->user_data_notifiers);
+        if (data->caller != NULL)
+                g_object_unref (data->caller);
+        g_free (data);
+}
+
+static void
+lca_check_authorization_callback (PolkitAuthority *authority,
+                                  GAsyncResult    *res,
+                                  gpointer         user_data)
+{
+        CheckAuthData *data = user_data;
+        PolkitAuthorizationResult result;
+        GError *error;
+        gboolean is_authorized;
+
+        is_authorized = FALSE;
+
+        error = NULL;
+        result = polkit_authority_check_authorization_finish (authority,
+                                                              res,
+                                                              &error);
+        if (error != NULL) {
+                throw_error (data->context,
+                             DEVKIT_DISKS_ERROR_PERMISSION_DENIED,
+                             "Not Authorized: %s", error->message);
+                g_error_free (error);
+        } else {
+                if (result == POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED) {
+                        throw_error (data->context,
+                                     DEVKIT_DISKS_ERROR_PERMISSION_DENIED,
+                                     "Not Authorized");
+                } else if (result == POLKIT_AUTHORIZATION_RESULT_CHALLENGE) {
+                        throw_error (data->context,
+                                     DEVKIT_DISKS_ERROR_PERMISSION_DENIED,
+                                     "Authentication is required");
+                } else {
+                        is_authorized = TRUE;
+                }
+        }
+
+        if (is_authorized) {
+                data->check_auth_callback (data->daemon,
+                                           data->device,
+                                           data->context,
+                                           data->action_id,
+                                           data->num_user_data,
+                                           data->user_data_elements);
+        }
+
+        check_auth_data_free (data);
+
+}
+
+/* num_user_data param is followed by @num_user_data (gpointer, GDestroyNotify) pairs.. */
+void
+devkit_disks_daemon_local_check_auth (DevkitDisksDaemon            *daemon,
+                                      DevkitDisksDevice            *device,
+                                      const gchar                  *action_id,
+                                      DevkitDisksCheckAuthCallback  check_auth_callback,
+                                      DBusGMethodInvocation        *context,
+                                      guint                         num_user_data,
+                                      ...)
+{
+        CheckAuthData *data;
+        va_list va_args;
+        guint n;
+
+        data = g_new0 (CheckAuthData, 1);
+        data->action_id = g_strdup (action_id);
+        data->check_auth_callback = check_auth_callback;
+        data->context = context;
+        data->daemon = g_object_ref (daemon);
+        data->device = device;
+        if (device != NULL)
+                g_object_weak_ref (G_OBJECT (device), lca_device_went_away, data);
+
+        data->cancellable = g_cancellable_new ();
+        data->num_user_data = num_user_data;
+        data->user_data_elements = g_new0 (gpointer, num_user_data);
+        data->user_data_notifiers = g_new0 (GDestroyNotify, num_user_data);
+
+        va_start (va_args, num_user_data);
+        for (n = 0; n < num_user_data; n++) {
+                data->user_data_elements[n] = va_arg (va_args, gpointer);
+                data->user_data_notifiers[n] = va_arg (va_args, GDestroyNotify);
+        }
+        va_end (va_args);
+
+        if (action_id != NULL) {
+                PolkitSubject *subject;
+
+                subject = polkit_system_bus_name_new (dbus_g_method_get_sender (context));
+
+                data->caller = devkit_disks_inhibitor_new (context);
+                g_signal_connect (data->caller,
+                                  "disconnected",
+                                  G_CALLBACK (lca_caller_disconnected_cb),
+                                  data);
+
+                polkit_authority_check_authorization (daemon->priv->authority,
+                                                      subject,
+                                                      action_id,
+                                                      POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
+                                                      data->cancellable,
+                                                      (GAsyncReadyCallback) lca_check_authorization_callback,
+                                                      data);
+
+                g_object_unref (subject);
+        } else {
+                data->check_auth_callback (data->daemon,
+                                           data->device,
+                                           data->context,
+                                           data->action_id,
+                                           data->num_user_data,
+                                           data->user_data_elements);
+                check_auth_data_free (data);
+        }
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
 /* exported methods */
 
 static void
@@ -1475,25 +1558,18 @@ devkit_disks_daemon_local_has_polling_inhibitors (DevkitDisksDaemon *daemon)
         return daemon->priv->polling_inhibitors != NULL;
 }
 
-gboolean
-devkit_disks_daemon_drive_inhibit_all_polling (DevkitDisksDaemon     *daemon,
-                                               char                 **options,
-                                               DBusGMethodInvocation *context)
+static void
+devkit_disks_daemon_drive_inhibit_all_polling_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                             DevkitDisksDevice     *device,
+                                                             DBusGMethodInvocation *context,
+                                                             const gchar           *action_id,
+                                                             guint                  num_user_data,
+                                                             gpointer              *user_data_elements)
 {
+        gchar **options = user_data_elements[0];
         DevkitDisksInhibitor *inhibitor;
-        PolKitCaller *pk_caller;
         guint n;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (daemon, context)) == NULL)
-                goto out;
-
-
-        if (!devkit_disks_damon_local_check_auth (daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.inhibit-polling",
-                                                  context))
-                goto out;
-
         for (n = 0; options[n] != NULL; n++) {
                 const char *option = options[n];
                 throw_error (context,
@@ -1513,11 +1589,23 @@ devkit_disks_daemon_drive_inhibit_all_polling (DevkitDisksDaemon     *daemon,
         dbus_g_method_return (context, devkit_disks_inhibitor_get_cookie (inhibitor));
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
-        return TRUE;
+        ;
 }
 
+gboolean
+devkit_disks_daemon_drive_inhibit_all_polling (DevkitDisksDaemon     *daemon,
+                                               char                 **options,
+                                               DBusGMethodInvocation *context)
+{
+        devkit_disks_daemon_local_check_auth (daemon,
+                                              NULL,
+                                              "org.freedesktop.devicekit.disks.inhibit-polling",
+                                              devkit_disks_daemon_drive_inhibit_all_polling_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+        return TRUE;
+}
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
@@ -1584,15 +1672,12 @@ devkit_disks_daemon_inhibit (DevkitDisksDaemon     *daemon,
                              DBusGMethodInvocation *context)
 {
         DevkitDisksInhibitor *inhibitor;
-        PolKitCaller *pk_caller;
         uid_t uid;
 
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (daemon, context)) == NULL)
+        if (!devkit_disks_daemon_local_get_uid (daemon, &uid, context))
                 goto out;
 
-        uid = (uid_t) -1;
-        if (!polkit_caller_get_uid (pk_caller, &uid) || uid != 0) {
+        if (uid != 0) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
                              "Only uid 0 is authorized to inhibit the daemon");
@@ -1607,8 +1692,6 @@ devkit_disks_daemon_inhibit (DevkitDisksDaemon     *daemon,
         dbus_g_method_return (context, devkit_disks_inhibitor_get_cookie (inhibitor));
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
         return TRUE;
 }
 
index 19349fc..51cd0aa 100644 (file)
@@ -22,7 +22,7 @@
 #define __DEVKIT_DISKS_DAEMON_H__
 
 #include <devkit-gobject/devkit-gobject.h>
-#include <polkit-dbus/polkit-dbus.h>
+#include <polkit/polkit.h>
 #include <dbus/dbus-glib.h>
 
 #include "devkit-disks-types.h"
@@ -53,6 +53,7 @@ struct DevkitDisksDaemonClass
 typedef enum
 {
         DEVKIT_DISKS_ERROR_FAILED,
+        DEVKIT_DISKS_ERROR_PERMISSION_DENIED,
         DEVKIT_DISKS_ERROR_BUSY,
         DEVKIT_DISKS_ERROR_CANCELLED,
         DEVKIT_DISKS_ERROR_INHIBITED,
@@ -90,12 +91,26 @@ DevkitDisksDevice *devkit_disks_daemon_local_find_by_dev         (DevkitDisksDae
 DevkitDisksAtaSmartDb *devkit_disks_daemon_local_get_ata_smart_db (DevkitDisksDaemon       *daemon);
 
 
-PolKitCaller      *devkit_disks_damon_local_get_caller_for_context (DevkitDisksDaemon     *daemon,
-                                                                    DBusGMethodInvocation *context);
+typedef void (*DevkitDisksCheckAuthCallback) (DevkitDisksDaemon     *daemon,
+                                              DevkitDisksDevice     *device,
+                                              DBusGMethodInvocation *context,
+                                              const gchar           *action_id,
+                                              guint                  num_user_data,
+                                              gpointer              *user_data_elements);
+
+/* num_user_data param is followed by @num_user_data (gpointer, GDestroyNotify) pairs.. */
+void               devkit_disks_daemon_local_check_auth          (DevkitDisksDaemon            *daemon,
+                                                                  DevkitDisksDevice            *device,
+                                                                  const gchar                  *action_id,
+                                                                  DevkitDisksCheckAuthCallback  check_auth_callback,
+                                                                  DBusGMethodInvocation        *context,
+                                                                  guint                         num_user_data,
+                                                                  ...);
+
 
-gboolean           devkit_disks_damon_local_check_auth             (DevkitDisksDaemon     *daemon,
-                                                                    PolKitCaller          *pk_caller,
-                                                                    const char            *action_id,
+/* TODO: probably use G_GNUC_WARN_UNUSED_RESULT here and fix up callers */
+gboolean           devkit_disks_daemon_local_get_uid               (DevkitDisksDaemon     *daemon,
+                                                                    uid_t                 *out_uid,
                                                                     DBusGMethodInvocation *context);
 
 void               devkit_disks_daemon_local_synthesize_changed_on_all_devices (DevkitDisksDaemon *daemon);
index a2410ea..622f569 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef __DEVKIT_DISKS_DEVICE_PRIVATE_H__
 #define __DEVKIT_DISKS_DEVICE_PRIVATE_H__
 
-#include <polkit-dbus/polkit-dbus.h>
 #include <dbus/dbus-glib.h>
 #include <devkit-gobject/devkit-gobject.h>
 
index 0036dac..21b07b0 100644 (file)
@@ -47,7 +47,6 @@
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include <devkit-gobject/devkit-gobject.h>
-#include <polkit-dbus/polkit-dbus.h>
 #include <atasmart.h>
 
 #include "devkit-disks-daemon.h"
@@ -3632,7 +3631,6 @@ throw_error (DBusGMethodInvocation *context, int error_code, const char *format,
 
 typedef void (*JobCompletedFunc) (DBusGMethodInvocation *context,
                                   DevkitDisksDevice *device,
-                                  PolKitCaller *caller,
                                   gboolean was_cancelled,
                                   int status,
                                   const char *stderr,
@@ -3643,7 +3641,6 @@ struct Job {
         char *job_id;
 
         DevkitDisksDevice *device;
-        PolKitCaller *pk_caller;
         DBusGMethodInvocation *context;
         JobCompletedFunc job_completed_func;
         GPid pid;
@@ -3676,8 +3673,6 @@ job_free (Job *job)
                 job->user_data_destroy_func (job->user_data);
         if (job->device != NULL)
                 g_object_unref (job->device);
-        if (job->pk_caller != NULL)
-                polkit_caller_unref (job->pk_caller);
         if (job->stderr_fd >= 0)
                 close (job->stderr_fd);
         if (job->stdout_fd >= 0)
@@ -3733,7 +3728,6 @@ job_child_watch_cb (GPid pid, int status, gpointer user_data)
 
         job->job_completed_func (job->context,
                                  job->device,
-                                 job->pk_caller,
                                  job->was_cancelled,
                                  status,
                                  job->error_string->str,
@@ -3880,7 +3874,6 @@ job_new (DBusGMethodInvocation *context,
          const char            *job_id,
          gboolean               is_cancellable,
          DevkitDisksDevice     *device,
-         PolKitCaller          *pk_caller,
          char                 **argv,
          const char            *stdin_str,
          JobCompletedFunc       job_completed_func,
@@ -3906,7 +3899,6 @@ job_new (DBusGMethodInvocation *context,
         job = g_new0 (Job, 1);
         job->context = context;
         job->device = device != NULL ? DEVKIT_DISKS_DEVICE (g_object_ref (device)) : NULL;
-        job->pk_caller = pk_caller != NULL ? polkit_caller_ref (pk_caller) : NULL;
         job->job_completed_func = job_completed_func;
         job->user_data = user_data;
         job->user_data_destroy_func = user_data_destroy_func;
@@ -3975,8 +3967,10 @@ job_new (DBusGMethodInvocation *context,
                 device->priv->job_is_cancellable = is_cancellable;
                 device->priv->job_percentage = -1.0;
                 device->priv->job_initiated_by_uid = 0;
-                if (pk_caller != NULL) {
-                        polkit_caller_get_uid (pk_caller, &(device->priv->job_initiated_by_uid));
+                if (context != NULL) {
+                        devkit_disks_daemon_local_get_uid (device->priv->daemon,
+                                                           &(device->priv->job_initiated_by_uid),
+                                                           context);
                 }
 
                 device->priv->job = job;
@@ -4377,7 +4371,6 @@ prepend_default_mount_options (const FSMountOptions *fsmo, uid_t caller_uid, cha
 static void
 filesystem_mount_completed_cb (DBusGMethodInvocation *context,
                                DevkitDisksDevice *device,
-                               PolKitCaller *pk_caller,
                                gboolean job_was_cancelled,
                                int status,
                                const char *stderr,
@@ -4387,9 +4380,7 @@ filesystem_mount_completed_cb (DBusGMethodInvocation *context,
         MountData *data = (MountData *) user_data;
         uid_t uid;
 
-        uid = 0;
-        if (pk_caller != NULL)
-                polkit_caller_get_uid (pk_caller, &uid);
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &uid, context);
 
         if (WEXITSTATUS (status) == 0 && !job_was_cancelled) {
 
@@ -4418,13 +4409,16 @@ filesystem_mount_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-
-gboolean
-devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
-                                      const char            *filesystem_type,
-                                      char                 **given_options,
-                                      DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_filesystem_mount_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                    DevkitDisksDevice     *device,
+                                                    DBusGMethodInvocation *context,
+                                                    const gchar           *action_id,
+                                                    guint                  num_user_data,
+                                                    gpointer              *user_data_elements)
+{
+        const gchar *filesystem_type = user_data_elements[0];
+        gchar **given_options = user_data_elements[1];
         int n;
         GString *s;
         char *argv[10];
@@ -4432,7 +4426,6 @@ devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
         char *fstype;
         char *mount_options;
         GError *error;
-        PolKitCaller *pk_caller;
         uid_t caller_uid;
         gboolean remove_dir_on_unmount;
         const FSMountOptions *fsmo;
@@ -4446,10 +4439,7 @@ devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
         remove_dir_on_unmount = FALSE;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        polkit_caller_get_uid (pk_caller, &caller_uid);
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &caller_uid, context);
 
         if (device->priv->id_usage == NULL ||
             strcmp (device->priv->id_usage, "filesystem") != 0) {
@@ -4478,15 +4468,6 @@ devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
                 goto run_job;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.filesystem-mount-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.filesystem-mount",
-                                                  context)) {
-                goto out;
-        }
-
         /* set the fstype */
         fstype = NULL;
         if (strlen (filesystem_type) == 0) {
@@ -4601,7 +4582,6 @@ run_job:
                       "FilesystemMount",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       filesystem_mount_completed_cb,
@@ -4621,8 +4601,42 @@ out:
         g_free (mount_options);
         g_free (mount_point);
         g_strfreev (options);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+}
+
+gboolean
+devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
+                                      const char            *filesystem_type,
+                                      char                 **given_options,
+                                      DBusGMethodInvocation *context)
+{
+        const gchar *action_id;
+
+        if (device->priv->id_usage == NULL ||
+            strcmp (device->priv->id_usage, "filesystem") != 0) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Not a mountable file system");
+                goto out;
+        }
+
+        if (is_device_in_fstab (device, NULL)) {
+                action_id = NULL;
+        } else {
+                if (device->priv->device_is_system_internal)
+                        action_id = "org.freedesktop.devicekit.disks.filesystem-mount-system-internal";
+                else
+                        action_id = "org.freedesktop.devicekit.disks.filesystem-mount";
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              action_id,
+                                              devkit_disks_device_filesystem_mount_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (filesystem_type), g_free,
+                                              g_strdupv (given_options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -4631,7 +4645,6 @@ out:
 static void
 filesystem_unmount_completed_cb (DBusGMethodInvocation *context,
                                  DevkitDisksDevice *device,
-                                 PolKitCaller *pk_caller,
                                  gboolean job_was_cancelled,
                                  int status,
                                  const char *stderr,
@@ -4663,30 +4676,23 @@ filesystem_unmount_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_filesystem_unmount (DevkitDisksDevice     *device,
-                                        char                 **options,
-                                        DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_filesystem_unmount_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                      DevkitDisksDevice     *device,
+                                                      DBusGMethodInvocation *context,
+                                                      const gchar           *action_id,
+                                                      guint                  num_user_data,
+                                                      gpointer              *user_data_elements)
+{
+        gchar **options = user_data_elements[0];
         int n;
         char *argv[16];
         GError *error;
-        PolKitCaller *pk_caller;
-        uid_t uid;
-        uid_t uid_of_mount;
         gboolean force_unmount;
         char *mount_path;
-        char uid_buf[32];
 
         mount_path = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        uid = 0;
-        if (pk_caller != NULL)
-                polkit_caller_get_uid (pk_caller, &uid);
-
         if (!device->priv->device_is_mounted ||
             device->priv->device_mount_paths->len == 0) {
                 throw_error (context,
@@ -4708,25 +4714,12 @@ devkit_disks_device_filesystem_unmount (DevkitDisksDevice     *device,
                 }
         }
 
-        if (!devkit_disks_mount_file_has_device (device->priv->device_file, &uid_of_mount, NULL)) {
+        if (!devkit_disks_mount_file_has_device (device->priv->device_file, NULL, NULL)) {
                 /* Check if the device is referenced in /etc/fstab; if so, attempt to
-                 * unmount the device as the user
+                 * unmount the device as uid 0 (since the user has acquired .unmount-others already)
                  */
                 if (is_device_in_fstab (device, &mount_path)) {
 
-                        /* If the user has the filesystem-unmount-others authorization, unmount
-                         * as root. This is such that /etc/fstab mounts without the "user" option
-                         * (or similar) can be unmounted.
-                         */
-                        if (devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                                 pk_caller,
-                                                                 "org.freedesktop.devicekit.disks.filesystem-unmount-others",
-                                                                 NULL)) {
-                                snprintf (uid_buf, sizeof uid_buf, "%d", 0);
-                        } else {
-                                snprintf (uid_buf, sizeof uid_buf, "%d", uid);
-                        }
-
                         n = 0;
                         argv[n++] = PACKAGE_LIBEXEC_DIR "/devkit-disks-helper-fstab-mounter";
                         if (force_unmount)
@@ -4734,24 +4727,10 @@ devkit_disks_device_filesystem_unmount (DevkitDisksDevice     *device,
                         else
                                 argv[n++] = "unmount";
                         argv[n++] = device->priv->device_file;
-                        argv[n++] = uid_buf;
+                        argv[n++] = "0";
                         argv[n++] = NULL;
                         goto run_job;
                 }
-
-                /* not mounted by DeviceKit-disks.. but still allow unmounting it.. if mounted by HAL then
-                 * eventually /sbin/umount.hal will be run and that will call Unmount() on HAL which will
-                 * clean up the mount point...
-                 */
-                uid_of_mount = 0;
-        }
-
-        if (uid_of_mount != uid) {
-                if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                          pk_caller,
-                                                          "org.freedesktop.devicekit.disks.filesystem-unmount-others",
-                                                          context))
-                        goto out;
         }
 
         mount_path = g_strdup (((gchar **) device->priv->device_mount_paths->pdata)[0]);
@@ -4771,7 +4750,6 @@ run_job:
                       "FilesystemUnmount",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       filesystem_unmount_completed_cb,
@@ -4781,9 +4759,46 @@ run_job:
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
         g_free (mount_path);
+}
+
+gboolean
+devkit_disks_device_filesystem_unmount (DevkitDisksDevice     *device,
+                                        char                 **options,
+                                        DBusGMethodInvocation *context)
+{
+        uid_t uid;
+        uid_t uid_of_mount;
+        const gchar *action_id;
+
+        if (!device->priv->device_is_mounted ||
+            device->priv->device_mount_paths->len == 0) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not mounted");
+                goto out;
+        }
+
+        if (!devkit_disks_mount_file_has_device (device->priv->device_file, &uid_of_mount, NULL)) {
+                uid_of_mount = 0;
+        }
+
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &uid, context);
+        if (uid_of_mount != uid) {
+                action_id = "org.freedesktop.devicekit.disks.filesystem-unmount-others";
+        } else {
+                action_id = NULL;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              action_id,
+                                              devkit_disks_device_filesystem_unmount_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -4867,7 +4882,6 @@ lsof_parse (const char *stdout, GPtrArray *processes)
 static void
 filesystem_list_open_files_completed_cb (DBusGMethodInvocation *context,
                                          DevkitDisksDevice *device,
-                                         PolKitCaller *pk_caller,
                                          gboolean job_was_cancelled,
                                          int status,
                                          const char *stderr,
@@ -4891,17 +4905,17 @@ filesystem_list_open_files_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_filesystem_list_open_files (DevkitDisksDevice     *device,
-                                                DBusGMethodInvocation *context)
+static void
+devkit_disks_device_filesystem_list_open_files_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                              DevkitDisksDevice     *device,
+                                                              DBusGMethodInvocation *context,
+                                                              const gchar           *action_id,
+                                                              guint                  num_user_data,
+                                                              gpointer              *user_data_elements)
 {
         int n;
         char *argv[16];
         GError *error;
-        PolKitCaller *pk_caller;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
 
         if (!device->priv->device_is_mounted ||
             device->priv->device_mount_paths->len == 0) {
@@ -4911,14 +4925,6 @@ devkit_disks_device_filesystem_list_open_files (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.filesystem-lsof-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.filesystem-lsof",
-                                                  context))
-                        goto out;
-
         n = 0;
         argv[n++] = "lsof";
         argv[n++] = "-t";
@@ -4930,7 +4936,6 @@ devkit_disks_device_filesystem_list_open_files (DevkitDisksDevice     *device,
                       NULL,     /* don't run this as a job */
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       filesystem_list_open_files_completed_cb,
@@ -4940,8 +4945,31 @@ devkit_disks_device_filesystem_list_open_files (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_filesystem_list_open_files (DevkitDisksDevice     *device,
+                                                DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_mounted ||
+            device->priv->device_mount_paths->len == 0) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not mounted");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                              "org.freedesktop.devicekit.disks.filesystem-lsof-system-internal" :
+                                              "org.freedesktop.devicekit.disks.filesystem-lsof",
+                                              devkit_disks_device_filesystem_list_open_files_authorized_cb,
+                                              context,
+                                              0);
+
+ out:
         return TRUE;
 }
 
@@ -4950,7 +4978,6 @@ out:
 static void
 drive_eject_completed_cb (DBusGMethodInvocation *context,
                           DevkitDisksDevice *device,
-                          PolKitCaller *pk_caller,
                           gboolean job_was_cancelled,
                           int status,
                           const char *stderr,
@@ -4975,23 +5002,23 @@ drive_eject_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_drive_eject (DevkitDisksDevice     *device,
-                                 char                 **options,
-                                 DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_drive_eject_authorized_cb (DevkitDisksDaemon     *daemon,
+                                               DevkitDisksDevice     *device,
+                                               DBusGMethodInvocation *context,
+                                               const gchar           *action_id,
+                                               guint                  num_user_data,
+                                               gpointer              *user_data_elements)
+{
+        gchar **options = user_data_elements[0];
         int n;
         char *argv[16];
         GError *error;
-        PolKitCaller *pk_caller;
         char *mount_path;
 
         error = NULL;
         mount_path = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (!device->priv->device_is_drive) {
                 throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
                              "Device is not a drive");
@@ -5010,12 +5037,6 @@ devkit_disks_device_drive_eject (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.drive-eject",
-                                                  context))
-                goto out;
-
         for (n = 0; options[n] != NULL; n++) {
                 const char *option = options[n];
                 throw_error (context,
@@ -5033,7 +5054,6 @@ devkit_disks_device_drive_eject (DevkitDisksDevice     *device,
                       "DriveEject",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       drive_eject_completed_cb,
@@ -5043,8 +5063,35 @@ devkit_disks_device_drive_eject (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_drive_eject (DevkitDisksDevice     *device,
+                                 char                 **options,
+                                 DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_drive) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not a drive");
+                goto out;
+        }
+
+        if (!device->priv->device_is_media_available) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "No media in drive");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.drive-eject",
+                                              devkit_disks_device_drive_eject_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -5053,7 +5100,6 @@ out:
 static void
 filesystem_check_completed_cb (DBusGMethodInvocation *context,
                                DevkitDisksDevice *device,
-                               PolKitCaller *pk_caller,
                                gboolean job_was_cancelled,
                                int status,
                                const char *stderr,
@@ -5088,18 +5134,19 @@ filesystem_check_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_filesystem_check (DevkitDisksDevice     *device,
-                                      char                 **options,
-                                      DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_filesystem_check_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                    DevkitDisksDevice     *device,
+                                                    DBusGMethodInvocation *context,
+                                                    const gchar           *action_id,
+                                                    guint                  num_user_data,
+                                                    gpointer              *user_data_elements)
+{
+        /* TODO: use options! */
+        //gchar **options = user_data_elements[0];
         int n;
         char *argv[16];
         GError *error;
-        PolKitCaller *pk_caller;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
 
         /* TODO: change when we have a file system that supports online fsck */
         if (device->priv->device_is_mounted) {
@@ -5109,16 +5156,6 @@ devkit_disks_device_filesystem_check (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        /* TODO: options! */
-
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.filesystem-check-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.filesystem-check",
-                                                  context))
-                goto out;
-
         n = 0;
         argv[n++] = "fsck";
         argv[n++] = "-a";
@@ -5130,7 +5167,6 @@ devkit_disks_device_filesystem_check (DevkitDisksDevice     *device,
                       "FilesystemCheck",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       filesystem_check_completed_cb,
@@ -5140,8 +5176,23 @@ devkit_disks_device_filesystem_check (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_filesystem_check (DevkitDisksDevice     *device,
+                                      char                 **options,
+                                      DBusGMethodInvocation *context)
+{
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                              "org.freedesktop.devicekit.disks.filesystem-check-system-internal" :
+                                              "org.freedesktop.devicekit.disks.filesystem-check",
+                                              devkit_disks_device_filesystem_check_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
         return TRUE;
 }
 
@@ -5150,7 +5201,6 @@ out:
 static void
 partition_delete_completed_cb (DBusGMethodInvocation *context,
                                DevkitDisksDevice *device,
-                               PolKitCaller *pk_caller,
                                gboolean job_was_cancelled,
                                int status,
                                const char *stderr,
@@ -5179,11 +5229,15 @@ partition_delete_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
-                                      char                 **options,
-                                      DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_partition_delete_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                    DevkitDisksDevice     *device,
+                                                    DBusGMethodInvocation *context,
+                                                    const gchar           *action_id,
+                                                    guint                  num_user_data,
+                                                    gpointer              *user_data_elements)
+{
+        gchar **options = user_data_elements[0];
         int n;
         int m;
         char *argv[16];
@@ -5191,7 +5245,6 @@ devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
         char *offset_as_string;
         char *size_as_string;
         char *part_number_as_string;
-        PolKitCaller *pk_caller;
         DevkitDisksDevice *enclosing_device;
 
         offset_as_string = NULL;
@@ -5199,9 +5252,6 @@ devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
         part_number_as_string = NULL;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (devkit_disks_device_local_is_busy (device, FALSE, &error)) {
                 dbus_g_method_return_error (context, error);
                 g_error_free (error);
@@ -5230,14 +5280,6 @@ devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context))
-                goto out;
-
         offset_as_string = g_strdup_printf ("%" G_GINT64_FORMAT "", device->priv->partition_offset);
         size_as_string = g_strdup_printf ("%" G_GINT64_FORMAT "", device->priv->partition_size);
         part_number_as_string = g_strdup_printf ("%d", device->priv->partition_number);
@@ -5265,7 +5307,6 @@ devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
                       "PartitionDelete",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       partition_delete_completed_cb,
@@ -5278,8 +5319,22 @@ out:
         g_free (offset_as_string);
         g_free (size_as_string);
         g_free (part_number_as_string);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+}
+
+gboolean
+devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
+                                      char                 **options,
+                                      DBusGMethodInvocation *context)
+{
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                              "org.freedesktop.devicekit.disks.change-system-internal" :
+                                              "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_partition_delete_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
         return TRUE;
 }
 
@@ -5299,7 +5354,6 @@ mkfs_data_unref (MkfsData *data)
 static void
 filesystem_create_completed_cb (DBusGMethodInvocation *context,
                                 DevkitDisksDevice *device,
-                                PolKitCaller *pk_caller,
                                 gboolean job_was_cancelled,
                                 int status,
                                 const char *stderr,
@@ -5449,7 +5503,6 @@ filesystem_create_wait_for_luks_device_not_seen_cb (gpointer user_data)
 static void
 filesystem_create_create_luks_device_completed_cb (DBusGMethodInvocation *context,
                                                         DevkitDisksDevice *device,
-                                                        PolKitCaller *pk_caller,
                                                         gboolean job_was_cancelled,
                                                         int status,
                                                         const char *stderr,
@@ -5510,7 +5563,6 @@ devkit_disks_device_filesystem_create_internal (DevkitDisksDevice       *device,
         int n, m;
         char *argv[128];
         GError *error;
-        PolKitCaller *pk_caller;
         char *s;
         char *options_for_stdin;
         char *passphrase_stdin;
@@ -5520,23 +5572,12 @@ devkit_disks_device_filesystem_create_internal (DevkitDisksDevice       *device,
         passphrase_stdin = NULL;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (devkit_disks_device_local_is_busy (device, TRUE, &error)) {
                 dbus_g_method_return_error (context, error);
                 g_error_free (error);
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context))
-                goto out;
-
         if (strlen (fstype) == 0) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
@@ -5582,7 +5623,6 @@ devkit_disks_device_filesystem_create_internal (DevkitDisksDevice       *device,
                                       "LuksFormat",
                                       TRUE,
                                       device,
-                                      pk_caller,
                                       argv,
                                       passphrase_stdin,
                                       filesystem_create_create_luks_device_completed_cb,
@@ -5615,7 +5655,6 @@ devkit_disks_device_filesystem_create_internal (DevkitDisksDevice       *device,
                       "FilesystemCreate",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       options_for_stdin,
                       filesystem_create_completed_cb,
@@ -5625,8 +5664,6 @@ devkit_disks_device_filesystem_create_internal (DevkitDisksDevice       *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
         g_free (options_for_stdin);
         if (passphrase_stdin != NULL) {
                 memset (passphrase_stdin, '\0', strlen (passphrase_stdin));
@@ -5635,28 +5672,77 @@ out:
         return TRUE;
 }
 
+static void
+devkit_disks_device_filesystem_create_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                     DevkitDisksDevice     *device,
+                                                     DBusGMethodInvocation *context,
+                                                     const gchar           *action_id,
+                                                     guint                  num_user_data,
+                                                     gpointer              *user_data_elements)
+{
+        const gchar *fstype = user_data_elements[0];
+        gchar **options = user_data_elements[1];
+        devkit_disks_device_filesystem_create_internal (device, fstype, options, NULL, NULL, context);
+}
+
 gboolean
 devkit_disks_device_filesystem_create (DevkitDisksDevice     *device,
                                        const char            *fstype,
                                        char                 **options,
                                        DBusGMethodInvocation *context)
 {
-        return devkit_disks_device_filesystem_create_internal (device, fstype, options, NULL, NULL, context);
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                                "org.freedesktop.devicekit.disks.change-system-internal" :
+                                                "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_filesystem_create_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (fstype), g_free,
+                                              g_strdupv (options), g_strfreev);
+        return TRUE;
 }
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
+static void
+devkit_disks_device_job_cancel_authorized_cb (DevkitDisksDaemon     *daemon,
+                                              DevkitDisksDevice     *device,
+                                              DBusGMethodInvocation *context,
+                                              const gchar           *action_id,
+                                              guint                  num_user_data,
+                                              gpointer              *user_data_elements)
+{
+
+        if (!device->priv->job_in_progress) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "There is no job to cancel");
+                goto out;
+        }
+
+        if (!device->priv->job_is_cancellable) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Job cannot be cancelled");
+                goto out;
+        }
+
+        job_cancel (device);
+
+        /* TODO: wait returning once the job is actually cancelled? */
+        dbus_g_method_return (context);
+ out:
+        ;
+}
+
 gboolean
 devkit_disks_device_job_cancel (DevkitDisksDevice     *device,
                                 DBusGMethodInvocation *context)
 {
-        PolKitCaller *pk_caller;
         uid_t uid;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        polkit_caller_get_uid (pk_caller, &uid);
+        const gchar *action_id;
 
         if (!device->priv->job_in_progress) {
                 throw_error (context,
@@ -5672,22 +5758,21 @@ devkit_disks_device_job_cancel (DevkitDisksDevice     *device,
                 goto out;
         }
 
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &uid, context);
+
+        action_id = NULL;
         if (device->priv->job_initiated_by_uid != uid) {
-                if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                          pk_caller,
-                                                          "org.freedesktop.devicekit.disks.cancel-job-others",
-                                                          context))
-                        goto out;
+                action_id = "org.freedesktop.devicekit.disks.cancel-job-others";
         }
 
-        job_cancel (device);
-
-        /* TODO: wait returning once the job is actually cancelled? */
-        dbus_g_method_return (context);
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              action_id,
+                                              devkit_disks_device_job_cancel_authorized_cb,
+                                              context,
+                                              0);
 
-out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+ out:
         return TRUE;
 }
 
@@ -5820,7 +5905,6 @@ partition_create_device_not_seen_cb (gpointer user_data)
 static void
 partition_create_completed_cb (DBusGMethodInvocation *context,
                                DevkitDisksDevice *device,
-                               PolKitCaller *pk_caller,
                                gboolean job_was_cancelled,
                                int status,
                                const char *stderr,
@@ -5912,23 +5996,26 @@ partition_create_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_partition_create (DevkitDisksDevice     *device,
-                                      guint64                offset,
-                                      guint64                size,
-                                      const char            *type,
-                                      const char            *label,
-                                      char                 **flags,
-                                      char                 **options,
-                                      const char            *fstype,
-                                      char                 **fsoptions,
-                                      DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_partition_create_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                    DevkitDisksDevice     *device,
+                                                    DBusGMethodInvocation *context,
+                                                    const gchar           *action_id,
+                                                    guint                  num_user_data,
+                                                    gpointer              *user_data_elements)
+{
+        guint64                offset    = *((guint64*) user_data_elements[0]);
+        guint64                size      = *((guint64*) user_data_elements[1]);;
+        const char            *type      = user_data_elements[2];
+        const char            *label     = user_data_elements[3];
+        char                 **flags     = user_data_elements[4];
+        char                 **options   = user_data_elements[5];
+        const char            *fstype    = user_data_elements[6];
+        char                 **fsoptions = user_data_elements[7];
         int n;
         int m;
         char *argv[128];
         GError *error;
-        PolKitCaller *pk_caller;
         char *offset_as_string;
         char *size_as_string;
         char *flags_as_string;
@@ -5938,9 +6025,6 @@ devkit_disks_device_partition_create (DevkitDisksDevice     *device,
         flags_as_string = NULL;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (!device->priv->device_is_partition_table) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
@@ -5956,14 +6040,6 @@ devkit_disks_device_partition_create (DevkitDisksDevice     *device,
 
         /* partutil.c / libparted will check there are no partitions in the requested slice */
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context))
-                goto out;
-
         offset_as_string = g_strdup_printf ("%" G_GINT64_FORMAT "", offset);
         size_as_string = g_strdup_printf ("%" G_GINT64_FORMAT "", size);
         /* TODO: check that neither of the flags include ',' */
@@ -5993,7 +6069,6 @@ devkit_disks_device_partition_create (DevkitDisksDevice     *device,
                       "PartitionCreate",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       partition_create_completed_cb,
@@ -6006,23 +6081,61 @@ out:
         g_free (offset_as_string);
         g_free (size_as_string);
         g_free (flags_as_string);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
-        return TRUE;
 }
 
-/*--------------------------------------------------------------------------------------------------------------*/
-
-typedef struct {
-        DBusGMethodInvocation *context;
-        DevkitDisksDevice *device;
-        DevkitDisksDevice *enclosing_device;
-
-        char *type;
-        char *label;
-        char **flags;
-} ModifyPartitionData;
-
+gboolean
+devkit_disks_device_partition_create (DevkitDisksDevice     *device,
+                                      guint64                offset,
+                                      guint64                size,
+                                      const char            *type,
+                                      const char            *label,
+                                      char                 **flags,
+                                      char                 **options,
+                                      const char            *fstype,
+                                      char                 **fsoptions,
+                                      DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_partition_table) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not partitioned");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                                "org.freedesktop.devicekit.disks.change-system-internal" :
+                                                "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_partition_create_authorized_cb,
+                                              context,
+                                              8,
+                                              g_memdup (&offset, sizeof (guint64)), g_free,
+                                              g_memdup (&size, sizeof (guint64)), g_free,
+                                              g_strdup (type), g_free,
+                                              g_strdup (label), g_free,
+                                              g_strdupv (flags), g_strfreev,
+                                              g_strdupv (options), g_strfreev,
+                                              g_strdup (fstype), g_free,
+                                              g_strdupv (fsoptions), g_strfreev);
+
+ out:
+        return TRUE;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+typedef struct {
+        DBusGMethodInvocation *context;
+        DevkitDisksDevice *device;
+        DevkitDisksDevice *enclosing_device;
+
+        char *type;
+        char *label;
+        char **flags;
+} ModifyPartitionData;
+
 static ModifyPartitionData *
 partition_modify_data_new (DBusGMethodInvocation *context,
                            DevkitDisksDevice *device,
@@ -6059,7 +6172,6 @@ partition_modify_data_unref (ModifyPartitionData *data)
 static void
 partition_modify_completed_cb (DBusGMethodInvocation *context,
                                DevkitDisksDevice *device,
-                               PolKitCaller *pk_caller,
                                gboolean job_was_cancelled,
                                int status,
                                const char *stderr,
@@ -6098,17 +6210,20 @@ partition_modify_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_partition_modify (DevkitDisksDevice     *device,
-                                      const char            *type,
-                                      const char            *label,
-                                      char                 **flags,
-                                      DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_partition_modify_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                    DevkitDisksDevice     *device,
+                                                    DBusGMethodInvocation *context,
+                                                    const gchar           *action_id,
+                                                    guint                  num_user_data,
+                                                    gpointer              *user_data_elements)
+{
+        const char            *type = user_data_elements[0];
+        const char            *label = user_data_elements[1];
+        char                 **flags = user_data_elements[2];
         int n;
         char *argv[128];
         GError *error;
-        PolKitCaller *pk_caller;
         char *offset_as_string;
         char *size_as_string;
         char *flags_as_string;
@@ -6119,9 +6234,6 @@ devkit_disks_device_partition_modify (DevkitDisksDevice     *device,
         flags_as_string = NULL;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (!device->priv->device_is_partition) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
@@ -6144,14 +6256,6 @@ devkit_disks_device_partition_modify (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context))
-                goto out;
-
         if (strlen (type) == 0) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
@@ -6178,7 +6282,6 @@ devkit_disks_device_partition_modify (DevkitDisksDevice     *device,
                       "PartitionModify",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       partition_modify_completed_cb,
@@ -6191,8 +6294,35 @@ out:
         g_free (offset_as_string);
         g_free (size_as_string);
         g_free (flags_as_string);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+}
+
+gboolean
+devkit_disks_device_partition_modify (DevkitDisksDevice     *device,
+                                      const char            *type,
+                                      const char            *label,
+                                      char                 **flags,
+                                      DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_partition) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not a partition");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                                "org.freedesktop.devicekit.disks.change-system-internal" :
+                                                "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_partition_modify_authorized_cb,
+                                              context,
+                                              3,
+                                              g_strdup (type), g_free,
+                                              g_strdup (label), g_free,
+                                              g_strdupv (flags), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -6201,7 +6331,6 @@ out:
 static void
 partition_table_create_completed_cb (DBusGMethodInvocation *context,
                                      DevkitDisksDevice *device,
-                                     PolKitCaller *pk_caller,
                                      gboolean job_was_cancelled,
                                      int status,
                                      const char *stderr,
@@ -6228,37 +6357,29 @@ partition_table_create_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_partition_table_create (DevkitDisksDevice     *device,
-                                            const char            *scheme,
-                                            char                 **options,
-                                            DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_partition_table_create_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                          DevkitDisksDevice     *device,
+                                                          DBusGMethodInvocation *context,
+                                                          const gchar           *action_id,
+                                                          guint                  num_user_data,
+                                                          gpointer              *user_data_elements)
+{
+        const char            *scheme  = user_data_elements[0];
+        char                 **options = user_data_elements[1];
         int n;
         int m;
         char *argv[128];
         GError *error;
-        PolKitCaller *pk_caller;
 
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (devkit_disks_device_local_is_busy (device, TRUE, &error)) {
                 dbus_g_method_return_error (context, error);
                 g_error_free (error);
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context))
-                goto out;
-
         if (strlen (scheme) == 0) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
@@ -6286,7 +6407,6 @@ devkit_disks_device_partition_table_create (DevkitDisksDevice     *device,
                       "PartitionTableCreate",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       partition_table_create_completed_cb,
@@ -6296,8 +6416,25 @@ devkit_disks_device_partition_table_create (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_partition_table_create (DevkitDisksDevice     *device,
+                                            const char            *scheme,
+                                            char                 **options,
+                                            DBusGMethodInvocation *context)
+{
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                                "org.freedesktop.devicekit.disks.change-system-internal" :
+                                                "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_partition_table_create_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (scheme), g_free,
+                                              g_strdupv (options), g_strfreev);
         return TRUE;
 }
 
@@ -6473,7 +6610,6 @@ luks_unlock_start_waiting_for_cleartext_device (gpointer user_data)
 static void
 luks_unlock_completed_cb (DBusGMethodInvocation *context,
                                DevkitDisksDevice *device,
-                               PolKitCaller *pk_caller,
                                gboolean job_was_cancelled,
                                int status,
                                const char *stderr,
@@ -6540,7 +6676,6 @@ devkit_disks_device_luks_unlock_internal (DevkitDisksDevice        *device,
         char *argv[10];
         char *luks_name;
         GError *error;
-        PolKitCaller *pk_caller;
         char *secret_as_stdin;
         uid_t uid;
 
@@ -6548,12 +6683,7 @@ devkit_disks_device_luks_unlock_internal (DevkitDisksDevice        *device,
         secret_as_stdin = NULL;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        uid = 0;
-        if (pk_caller != NULL)
-                polkit_caller_get_uid (pk_caller, &uid);
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &uid, context);
 
         if (devkit_disks_device_local_is_busy (device, FALSE, &error)) {
                 dbus_g_method_return_error (context, error);
@@ -6574,14 +6704,6 @@ devkit_disks_device_luks_unlock_internal (DevkitDisksDevice        *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.luks-unlock",
-                                                  context)) {
-                goto out;
-        }
-
-
         luks_name = g_strdup_printf ("devkit-disks-luks-uuid-%s-uid%d",
                                      device->priv->id_uuid,
                                      uid);
@@ -6598,7 +6720,6 @@ devkit_disks_device_luks_unlock_internal (DevkitDisksDevice        *device,
                       "LuksUnlock",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       secret_as_stdin,
                       luks_unlock_completed_cb,
@@ -6614,18 +6735,46 @@ out:
         }
         g_free (secret_as_stdin);
         g_free (luks_name);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
         return TRUE;
 }
 
+static void
+devkit_disks_device_luks_unlock_authorized_cb (DevkitDisksDaemon     *daemon,
+                                               DevkitDisksDevice     *device,
+                                               DBusGMethodInvocation *context,
+                                               const gchar           *action_id,
+                                               guint                  num_user_data,
+                                               gpointer              *user_data_elements)
+{
+        const char            *secret  = user_data_elements[0];
+        char                 **options = user_data_elements[1];
+        devkit_disks_device_luks_unlock_internal (device, secret, options, NULL, NULL, context);
+}
+
 gboolean
 devkit_disks_device_luks_unlock (DevkitDisksDevice     *device,
-                                      const char            *secret,
-                                      char                 **options,
-                                      DBusGMethodInvocation *context)
+                                 const char            *secret,
+                                 char                 **options,
+                                 DBusGMethodInvocation *context)
 {
-        return devkit_disks_device_luks_unlock_internal (device, secret, options, NULL, NULL, context);
+        if (device->priv->id_usage == NULL ||
+            strcmp (device->priv->id_usage, "crypto") != 0) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Not a LUKS device");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.luks-unlock",
+                                              devkit_disks_device_luks_unlock_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (secret), g_free,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
+        return TRUE;
 }
 
 /*--------------------------------------------------------------------------------------------------------------*/
@@ -6721,7 +6870,6 @@ luks_lock_wait_for_cleartext_device_not_seen_cb (gpointer user_data)
 static void
 luks_lock_completed_cb (DBusGMethodInvocation *context,
                              DevkitDisksDevice *device,
-                             PolKitCaller *pk_caller,
                              gboolean job_was_cancelled,
                              int status,
                              const char *stderr,
@@ -6809,25 +6957,20 @@ out:
         return ret;
 }
 
-gboolean
-devkit_disks_device_luks_lock (DevkitDisksDevice     *device,
-                                    char                 **options,
-                                    DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_luks_lock_authorized_cb (DevkitDisksDaemon     *daemon,
+                                             DevkitDisksDevice     *device,
+                                             DBusGMethodInvocation *context,
+                                             const gchar           *action_id,
+                                             guint                  num_user_data,
+                                             gpointer              *user_data_elements)
+{
+        /* TODO: use options */
+        //char                 **options = user_data_elements[0];
+        DevkitDisksDevice *cleartext_device;
         int n;
         char *argv[10];
         GError *error;
-        PolKitCaller *pk_caller;
-        DevkitDisksDevice *cleartext_device;
-        uid_t unlocked_by_uid;
-        uid_t uid;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        uid = 0;
-        if (pk_caller != NULL)
-                polkit_caller_get_uid (pk_caller, &uid);
 
         if (device->priv->id_usage == NULL ||
             strcmp (device->priv->id_usage, "crypto") != 0) {
@@ -6849,24 +6992,6 @@ devkit_disks_device_luks_lock (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        /* see if we (DeviceKit-disks) set up this clear text device */
-        if (!luks_get_uid_from_dm_name (cleartext_device->priv->dm_name, &unlocked_by_uid)) {
-                /* nope.. so assume uid 0 set it up.. we still allow locking
-                 * the device... given enough privilege
-                 */
-                unlocked_by_uid = 0;
-        }
-
-        /* require authorization if unlocked by someone else */
-        if (unlocked_by_uid != uid) {
-                if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                          pk_caller,
-                                                          "org.freedesktop.devicekit.disks.luks-lock-others",
-                                                          context)) {
-                        goto out;
-                }
-        }
-
         n = 0;
         argv[n++] = "cryptsetup";
         argv[n++] = "luksClose";
@@ -6878,7 +7003,6 @@ devkit_disks_device_luks_lock (DevkitDisksDevice     *device,
                       "LuksLock",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       luks_lock_completed_cb,
@@ -6888,17 +7012,73 @@ devkit_disks_device_luks_lock (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_luks_lock (DevkitDisksDevice     *device,
+                               char                 **options,
+                               DBusGMethodInvocation *context)
+{
+        uid_t unlocked_by_uid;
+        uid_t uid;
+        DevkitDisksDevice *cleartext_device;
+        const gchar *action_id;
+
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &uid, context);
+
+        if (device->priv->id_usage == NULL ||
+            strcmp (device->priv->id_usage, "crypto") != 0) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Not a LUKS crypto device");
+                goto out;
+        }
+
+        cleartext_device = find_cleartext_device (device);
+        if (cleartext_device == NULL) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Cleartext device is not unlocked");
+                goto out;
+        }
+
+        if (cleartext_device->priv->dm_name == NULL || strlen (cleartext_device->priv->dm_name) == 0) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Cannot determine device-mapper name");
+                goto out;
+        }
+
+        /* see if we (DeviceKit-disks) set up this clear text device */
+        if (!luks_get_uid_from_dm_name (cleartext_device->priv->dm_name, &unlocked_by_uid)) {
+                /* nope.. so assume uid 0 set it up.. we still allow locking
+                 * the device... given enough privilege
+                 */
+                unlocked_by_uid = 0;
+        }
+
+        /* require authorization if unlocked by someone else */
+        action_id = NULL;
+        if (unlocked_by_uid != uid) {
+                action_id = "org.freedesktop.devicekit.disks.luks-lock-others";
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              action_id,
+                                              devkit_disks_device_luks_lock_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
+
 /*--------------------------------------------------------------------------------------------------------------*/
 
 static void
 luks_change_passphrase_completed_cb (DBusGMethodInvocation *context,
                                           DevkitDisksDevice *device,
-                                          PolKitCaller *pk_caller,
                                           gboolean job_was_cancelled,
                                           int status,
                                           const char *stderr,
@@ -6921,27 +7101,23 @@ luks_change_passphrase_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_luks_change_passphrase (DevkitDisksDevice     *device,
-                                                 const char            *old_secret,
-                                                 const char            *new_secret,
-                                                 DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_luks_change_passphrase_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                          DevkitDisksDevice     *device,
+                                                          DBusGMethodInvocation *context,
+                                                          const gchar           *action_id,
+                                                          guint                  num_user_data,
+                                                          gpointer              *user_data_elements)
+{
+        const char            *old_secret = user_data_elements[0];
+        const char            *new_secret = user_data_elements[1];
         int n;
         char *argv[10];
         GError *error;
-        PolKitCaller *pk_caller;
         char *secrets_as_stdin;
 
         secrets_as_stdin = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        /* No need to check for busy; we can actually do this while the device is unlocked as
-         * only LUKS metadata is modified.
-         */
-
         if (device->priv->id_usage == NULL ||
             strcmp (device->priv->id_usage, "crypto") != 0) {
                 throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
@@ -6949,15 +7125,6 @@ devkit_disks_device_luks_change_passphrase (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context)) {
-                goto out;
-        }
-
         secrets_as_stdin = g_strdup_printf ("%s\n%s\n", old_secret, new_secret);
 
         n = 0;
@@ -6970,7 +7137,6 @@ devkit_disks_device_luks_change_passphrase (DevkitDisksDevice     *device,
                       "LuksChangePassphrase",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       secrets_as_stdin,
                       luks_change_passphrase_completed_cb,
@@ -6985,8 +7151,37 @@ out:
                 memset (secrets_as_stdin, '\0', strlen (secrets_as_stdin));
         }
         g_free (secrets_as_stdin);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+}
+
+gboolean
+devkit_disks_device_luks_change_passphrase (DevkitDisksDevice     *device,
+                                            const char            *old_secret,
+                                            const char            *new_secret,
+                                            DBusGMethodInvocation *context)
+{
+        /* No need to check for busy; we can actually do this while the device is unlocked as
+         * only LUKS metadata is modified.
+         */
+
+        if (device->priv->id_usage == NULL ||
+            strcmp (device->priv->id_usage, "crypto") != 0) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Not a LUKS crypto device");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                                "org.freedesktop.devicekit.disks.change-system-internal" :
+                                                "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_luks_change_passphrase_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (old_secret), g_free,
+                                              g_strdup (new_secret), g_free);
+
+ out:
         return TRUE;
 }
 
@@ -6995,7 +7190,6 @@ out:
 static void
 filesystem_set_label_completed_cb (DBusGMethodInvocation *context,
                                       DevkitDisksDevice *device,
-                                      PolKitCaller *pk_caller,
                                       gboolean job_was_cancelled,
                                       int status,
                                       const char *stderr,
@@ -7030,22 +7224,22 @@ filesystem_set_label_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_filesystem_set_label (DevkitDisksDevice     *device,
-                                             const char            *new_label,
-                                             DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_filesystem_set_label_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                        DevkitDisksDevice     *device,
+                                                        DBusGMethodInvocation *context,
+                                                        const gchar           *action_id,
+                                                        guint                  num_user_data,
+                                                        gpointer              *user_data_elements)
+{
+        const gchar *new_label = user_data_elements[0];
         int n;
         char *argv[10];
-        GError *error;
-        PolKitCaller *pk_caller;
         const DevkitDisksFilesystem *fs_details;
+        GError *error;
 
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (device->priv->id_usage == NULL ||
             strcmp (device->priv->id_usage, "filesystem") != 0) {
                 throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
@@ -7068,15 +7262,6 @@ devkit_disks_device_filesystem_set_label (DevkitDisksDevice     *device,
                 }
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  device->priv->device_is_system_internal ?
-                                                  "org.freedesktop.devicekit.disks.change-system-internal" :
-                                                  "org.freedesktop.devicekit.disks.change",
-                                                  context)) {
-                goto out;
-        }
-
         n = 0;
         argv[n++] = "devkit-disks-helper-change-filesystem-label";
         argv[n++] = device->priv->device_file;
@@ -7088,7 +7273,6 @@ devkit_disks_device_filesystem_set_label (DevkitDisksDevice     *device,
                       "FilesystemSetLabel",
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       filesystem_set_label_completed_cb,
@@ -7098,8 +7282,52 @@ devkit_disks_device_filesystem_set_label (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_filesystem_set_label (DevkitDisksDevice     *device,
+                                          const char            *new_label,
+                                          DBusGMethodInvocation *context)
+{
+        const DevkitDisksFilesystem *fs_details;
+        GError *error;
+
+        error = NULL;
+
+        if (device->priv->id_usage == NULL ||
+            strcmp (device->priv->id_usage, "filesystem") != 0) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Not a mountable file system");
+                goto out;
+        }
+
+        fs_details = devkit_disks_daemon_local_get_fs_details (device->priv->daemon,
+                                                               device->priv->id_type);
+        if (fs_details == NULL) {
+                throw_error (context, DEVKIT_DISKS_ERROR_BUSY, "Unknown filesystem");
+                goto out;
+        }
+
+        if (!fs_details->supports_online_label_rename) {
+                if (devkit_disks_device_local_is_busy (device, FALSE, &error)) {
+                        dbus_g_method_return_error (context, error);
+                        g_error_free (error);
+                        goto out;
+                }
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              device->priv->device_is_system_internal ?
+                                                "org.freedesktop.devicekit.disks.change-system-internal" :
+                                                "org.freedesktop.devicekit.disks.change",
+                                              devkit_disks_device_filesystem_set_label_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdup (new_label), g_free);
+
+ out:
         return TRUE;
 }
 
@@ -7179,7 +7407,6 @@ ata_smart_collect_attrs (SkDisk *d, const SkSmartAttributeParsedData *a, void *u
 static void
 drive_ata_smart_refresh_data_completed_cb (DBusGMethodInvocation *context,
                                            DevkitDisksDevice *device,
-                                           PolKitCaller *pk_caller,
                                            gboolean job_was_cancelled,
                                            int status,
                                            const char *stderr,
@@ -7370,30 +7597,23 @@ out:
                 sk_disk_free (d);
 }
 
-/* may be called with context==NULL */
-gboolean
-devkit_disks_device_drive_ata_smart_refresh_data (DevkitDisksDevice     *device,
-                                                  char                 **options,
-                                                  DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_drive_ata_smart_refresh_data_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                                DevkitDisksDevice     *device,
+                                                                DBusGMethodInvocation *context,
+                                                                const gchar           *action_id,
+                                                                guint                  num_user_data,
+                                                                gpointer              *user_data_elements)
+{
+        char                 **options = user_data_elements[0];
         int n;
         char *argv[10];
         GError *error;
-        PolKitCaller *pk_caller;
         const char *simuldata;
         gboolean nowakeup;
         uid_t caller_uid;
 
-        pk_caller = NULL;
-        if (context != NULL) {
-                if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                        goto out;
-        }
-
-        if (pk_caller != NULL)
-                polkit_caller_get_uid (pk_caller, &caller_uid);
-        else
-                caller_uid = 0;
+        devkit_disks_daemon_local_get_uid (device->priv->daemon, &caller_uid, context);
 
         if (!device->priv->drive_ata_smart_is_available) {
                 throw_error (context,
@@ -7402,15 +7622,6 @@ devkit_disks_device_drive_ata_smart_refresh_data (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (context != NULL && caller_uid != 0) {
-                if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                          pk_caller,
-                                                          "org.freedesktop.devicekit.disks.drive-ata-smart-refresh",
-                                                          context)) {
-                        goto out;
-                }
-        }
-
         simuldata = NULL;
         nowakeup = FALSE;
         for (n = 0; options[n] != NULL; n++) {
@@ -7448,7 +7659,6 @@ devkit_disks_device_drive_ata_smart_refresh_data (DevkitDisksDevice     *device,
                       NULL,     /* don't run this as a job */
                       FALSE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       drive_ata_smart_refresh_data_completed_cb,
@@ -7458,8 +7668,38 @@ devkit_disks_device_drive_ata_smart_refresh_data (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+/* may be called with context==NULL */
+gboolean
+devkit_disks_device_drive_ata_smart_refresh_data (DevkitDisksDevice     *device,
+                                                  char                 **options,
+                                                  DBusGMethodInvocation *context)
+{
+        const gchar *action_id;
+
+        if (!device->priv->drive_ata_smart_is_available) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Device does not support ATA SMART");
+                goto out;
+        }
+
+        action_id = NULL;
+        if (context != NULL) {
+                action_id = "org.freedesktop.devicekit.disks.drive-ata-smart-refresh";
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              action_id,
+                                              devkit_disks_device_drive_ata_smart_refresh_data_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -7524,6 +7764,38 @@ ata_smart_historical_data_cb (time_t      time_collected,
         return FALSE;
 }
 
+static void
+devkit_disks_device_drive_ata_smart_get_historical_data_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                                       DevkitDisksDevice     *device,
+                                                                       DBusGMethodInvocation *context,
+                                                                       const gchar           *action_id,
+                                                                       guint                  num_user_data,
+                                                                       gpointer              *user_data_elements)
+{
+        guint64                since   = *((guint64*) user_data_elements[0]);
+        guint64                until   = *((guint64*) user_data_elements[1]);
+        guint64                spacing = *((guint64*) user_data_elements[1]);
+        GPtrArray *array;
+        DevkitDisksAtaSmartDb *db;
+
+        db = devkit_disks_daemon_local_get_ata_smart_db (device->priv->daemon);
+
+        array = g_ptr_array_new ();
+
+        devkit_disks_ata_smart_db_get_entries (db,
+                                               device,
+                                               since,
+                                               until,
+                                               spacing,
+                                               ata_smart_historical_data_cb,
+                                               array);
+
+        dbus_g_method_return (context, array);
+
+        g_ptr_array_foreach (array, (GFunc) g_value_array_free, NULL);
+        g_ptr_array_free (array, TRUE);
+}
+
 gboolean
 devkit_disks_device_drive_ata_smart_get_historical_data (DevkitDisksDevice     *device,
                                                          guint64                since,
@@ -7531,18 +7803,6 @@ devkit_disks_device_drive_ata_smart_get_historical_data (DevkitDisksDevice     *
                                                          guint64                spacing,
                                                          DBusGMethodInvocation *context)
 {
-        PolKitCaller *pk_caller;
-        GPtrArray *array;
-        DevkitDisksAtaSmartDb *db;
-
-        pk_caller = NULL;
-
-        if (context != NULL) {
-                if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon,
-                                                                                  context)) == NULL)
-                        goto out;
-        }
-
         if (!device->priv->drive_ata_smart_is_available) {
                 throw_error (context,
                              DEVKIT_DISKS_ERROR_FAILED,
@@ -7550,16 +7810,6 @@ devkit_disks_device_drive_ata_smart_get_historical_data (DevkitDisksDevice     *
                 goto out;
         }
 
-        if (context != NULL) {
-                if (!devkit_disks_damon_local_check_auth (
-                            device->priv->daemon,
-                            pk_caller,
-                            "org.freedesktop.devicekit.disks.drive-ata-smart-retrieve-historical-data",
-                            context)) {
-                        goto out;
-                }
-        }
-
         if (until == 0)
                 until = time (NULL);
 
@@ -7568,35 +7818,26 @@ devkit_disks_device_drive_ata_smart_get_historical_data (DevkitDisksDevice     *
                 goto out;
         }
 
-        db = devkit_disks_daemon_local_get_ata_smart_db (device->priv->daemon);
-
-        array = g_ptr_array_new ();
-
-        devkit_disks_ata_smart_db_get_entries (db,
-                                               device,
-                                               since,
-                                               until,
-                                               spacing,
-                                               ata_smart_historical_data_cb,
-                                               array);
-
-        dbus_g_method_return (context, array);
-
-        g_ptr_array_foreach (array, (GFunc) g_value_array_free, NULL);
-        g_ptr_array_free (array, TRUE);
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.drive-ata-smart-retrieve-historical-data",
+                                              devkit_disks_device_drive_ata_smart_get_historical_data_authorized_cb,
+                                              context,
+                                              3,
+                                              g_memdup (&since, sizeof (guint64)), g_free,
+                                              g_memdup (&until, sizeof (guint64)), g_free,
+                                              g_memdup (&spacing, sizeof (guint64)), g_free);
 
-out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+ out:
         return TRUE;
 }
 
+
 /*--------------------------------------------------------------------------------------------------------------*/
 
 static void
 drive_ata_smart_initiate_selftest_completed_cb (DBusGMethodInvocation *context,
                                                 DevkitDisksDevice *device,
-                                                PolKitCaller *pk_caller,
                                                 gboolean job_was_cancelled,
                                                 int status,
                                                 const char *stderr,
@@ -7626,33 +7867,20 @@ drive_ata_smart_initiate_selftest_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_drive_ata_smart_initiate_selftest (DevkitDisksDevice     *device,
-                                                       const char            *test,
-                                                       gchar                **options,
-                                                       DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_drive_ata_smart_initiate_selftest_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                                     DevkitDisksDevice     *device,
+                                                                     DBusGMethodInvocation *context,
+                                                                     const gchar           *action_id,
+                                                                     guint                  num_user_data,
+                                                                     gpointer              *user_data_elements)
+{
+        const gchar  *test    = user_data_elements[0];
+        /* TODO: use options */
+        //gchar       **options = user_data_elements[1];
         int n;
         char *argv[10];
         GError *error;
-        PolKitCaller *pk_caller;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        if (!device->priv->drive_ata_smart_is_available) {
-                throw_error (context,
-                             DEVKIT_DISKS_ERROR_FAILED,
-                             "Device does not support ATA SMART");
-                goto out;
-        }
-
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.drive-ata-smart-selftest",
-                                                  context)) {
-                goto out;
-        }
 
         n = 0;
         argv[n++] = PACKAGE_LIBEXEC_DIR "/devkit-disks-helper-ata-smart-selftest";
@@ -7665,7 +7893,6 @@ devkit_disks_device_drive_ata_smart_initiate_selftest (DevkitDisksDevice     *de
                       "DriveAtaSmartInitiateSelftest",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       drive_ata_smart_initiate_selftest_completed_cb,
@@ -7675,8 +7902,32 @@ devkit_disks_device_drive_ata_smart_initiate_selftest (DevkitDisksDevice     *de
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_drive_ata_smart_initiate_selftest (DevkitDisksDevice     *device,
+                                                       const char            *test,
+                                                       gchar                **options,
+                                                       DBusGMethodInvocation *context)
+{
+        if (!device->priv->drive_ata_smart_is_available) {
+                throw_error (context,
+                             DEVKIT_DISKS_ERROR_FAILED,
+                             "Device does not support ATA SMART");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.drive-ata-smart-selftest",
+                                              devkit_disks_device_drive_ata_smart_initiate_selftest_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (test), g_free,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -7685,7 +7936,6 @@ out:
 static void
 linux_md_stop_completed_cb (DBusGMethodInvocation *context,
                                   DevkitDisksDevice *device,
-                                  PolKitCaller *pk_caller,
                                   gboolean job_was_cancelled,
                                   int status,
                                   const char *stderr,
@@ -7716,31 +7966,19 @@ linux_md_stop_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_linux_md_stop (DevkitDisksDevice     *device,
-                                         char                 **options,
-                                         DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_linux_md_stop_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                 DevkitDisksDevice     *device,
+                                                 DBusGMethodInvocation *context,
+                                                 const gchar           *action_id,
+                                                 guint                  num_user_data,
+                                                 gpointer              *user_data_elements)
+{
+        /* TODO: use options */
+        //gchar       **options = user_data_elements[0];
         int n;
         char *argv[10];
         GError *error;
-        PolKitCaller *pk_caller;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        if (!device->priv->device_is_linux_md) {
-                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
-                             "Device is not a Linux md drive");
-                goto out;
-        }
-
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.linux-md",
-                                                  context)) {
-                goto out;
-        }
 
         n = 0;
         argv[n++] = "mdadm";
@@ -7753,7 +7991,6 @@ devkit_disks_device_linux_md_stop (DevkitDisksDevice     *device,
                       "LinuxMdStop",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       linux_md_stop_completed_cb,
@@ -7763,8 +8000,29 @@ devkit_disks_device_linux_md_stop (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_linux_md_stop (DevkitDisksDevice     *device,
+                                   char                 **options,
+                                   DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_linux_md) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not a Linux md drive");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.linux-md",
+                                              devkit_disks_device_linux_md_stop_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+
+ out:
         return TRUE;
 }
 
@@ -7773,7 +8031,6 @@ out:
 static void
 linux_md_add_component_completed_cb (DBusGMethodInvocation *context,
                                               DevkitDisksDevice *device,
-                                              PolKitCaller *pk_caller,
                                               gboolean job_was_cancelled,
                                               int status,
                                               const char *stderr,
@@ -7808,29 +8065,24 @@ linux_md_add_component_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_linux_md_add_component (DevkitDisksDevice     *device,
-                                            char                  *component,
-                                            char                 **options,
-                                            DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_linux_md_add_component_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                          DevkitDisksDevice     *device,
+                                                          DBusGMethodInvocation *context,
+                                                          const gchar           *action_id,
+                                                          guint                  num_user_data,
+                                                          gpointer              *user_data_elements)
+{
+        char                  *component = user_data_elements[0];
+        /* TODO: use options */
+        //char                 **options   = user_data_elements[1];
         int n;
         char *argv[10];
         GError *error;
-        PolKitCaller *pk_caller;
         DevkitDisksDevice *slave;
 
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        if (!device->priv->device_is_linux_md) {
-                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
-                             "Device is not a Linux md drive");
-                goto out;
-        }
-
         slave = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, component);
         if (slave == NULL) {
                 throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
@@ -7850,13 +8102,6 @@ devkit_disks_device_linux_md_add_component (DevkitDisksDevice     *device,
 
         /* TODO: check component size is OK */
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.linux-md",
-                                                  context)) {
-                goto out;
-        }
-
         n = 0;
         argv[n++] = "mdadm";
         argv[n++] = "--manage";
@@ -7870,7 +8115,6 @@ devkit_disks_device_linux_md_add_component (DevkitDisksDevice     *device,
                       "LinuxMdAddComponent",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       linux_md_add_component_completed_cb,
@@ -7880,11 +8124,34 @@ devkit_disks_device_linux_md_add_component (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_linux_md_add_component (DevkitDisksDevice     *device,
+                                            char                  *component,
+                                            char                 **options,
+                                            DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_linux_md) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not a Linux md drive");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.linux-md",
+                                              devkit_disks_device_linux_md_add_component_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (component), g_free,
+                                              g_strdupv (options), g_strfreev);
+ out:
         return TRUE;
 }
 
+
 /*--------------------------------------------------------------------------------------------------------------*/
 
 
@@ -7988,7 +8255,6 @@ linux_md_remove_component_device_not_seen_cb (gpointer user_data)
 static void
 linux_md_remove_component_completed_cb (DBusGMethodInvocation *context,
                                                    DevkitDisksDevice *device,
-                                                   PolKitCaller *pk_caller,
                                                    gboolean job_was_cancelled,
                                                    int status,
                                                    const char *stderr,
@@ -8039,27 +8305,21 @@ linux_md_remove_component_completed_cb (DBusGMethodInvocation *context,
         }
 }
 
-gboolean
-devkit_disks_device_linux_md_remove_component (DevkitDisksDevice     *device,
-                                                          char                  *component,
-                                                          char                 **options,
-                                                          DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_linux_md_remove_component_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                             DevkitDisksDevice     *device,
+                                                             DBusGMethodInvocation *context,
+                                                             const gchar           *action_id,
+                                                             guint                  num_user_data,
+                                                             gpointer              *user_data_elements)
+{
+        char                  *component = user_data_elements[0];
+        char                 **options   = user_data_elements[1];
         int n, m;
         char *argv[128];
         GError *error;
-        PolKitCaller *pk_caller;
         DevkitDisksDevice *slave;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        if (!device->priv->device_is_linux_md) {
-                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
-                             "Device is not a Linux md drive");
-                goto out;
-        }
-
         slave = devkit_disks_daemon_local_find_by_object_path (device->priv->daemon, component);
         if (slave == NULL) {
                 throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
@@ -8078,13 +8338,6 @@ devkit_disks_device_linux_md_remove_component (DevkitDisksDevice     *device,
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.linux-md",
-                                                  context)) {
-                goto out;
-        }
-
         n = 0;
         argv[n++] = PACKAGE_LIBEXEC_DIR "/devkit-disks-helper-linux-md-remove-component";
         argv[n++] = device->priv->device_file;
@@ -8106,7 +8359,6 @@ devkit_disks_device_linux_md_remove_component (DevkitDisksDevice     *device,
                       "LinuxMdRemoveComponent",
                       TRUE,
                       device,
-                      pk_caller,
                       argv,
                       NULL,
                       linux_md_remove_component_completed_cb,
@@ -8116,8 +8368,30 @@ devkit_disks_device_linux_md_remove_component (DevkitDisksDevice     *device,
         }
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_linux_md_remove_component (DevkitDisksDevice     *device,
+                                               char                  *component,
+                                               char                 **options,
+                                               DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_linux_md) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not a Linux md drive");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.linux-md",
+                                              devkit_disks_device_linux_md_remove_component_authorized_cb,
+                                              context,
+                                              2,
+                                              g_strdup (component), g_free,
+                                              g_strdupv (options), g_strfreev);
+ out:
         return TRUE;
 }
 
@@ -8214,7 +8488,6 @@ linux_md_start_device_not_seen_cb (gpointer user_data)
 static void
 linux_md_start_completed_cb (DBusGMethodInvocation *context,
                              DevkitDisksDevice *device,
-                             PolKitCaller *pk_caller,
                              gboolean job_was_cancelled,
                              int status,
                              const char *stderr,
@@ -8284,18 +8557,21 @@ linux_md_start_completed_cb (DBusGMethodInvocation *context,
 }
 
 /* NOTE: This is a method on the daemon, not the device. */
-
-gboolean
-devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
-                                    GPtrArray             *components,
-                                    char                 **options,
-                                    DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_daemon_linux_md_start_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                  DevkitDisksDevice     *device,
+                                                  DBusGMethodInvocation *context,
+                                                  const gchar           *action_id,
+                                                  guint                  num_user_data,
+                                                  gpointer              *user_data_elements)
+{
+        gchar **components_as_strv = user_data_elements[0];
+        /* TODO: use options */
+        //gchar **options            = user_data_elements[1];
         int n;
         int m;
         char *argv[128];
         GError *error;
-        PolKitCaller *pk_caller;
         char *uuid;
         char *md_device_file;
 
@@ -8303,15 +8579,12 @@ devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
         md_device_file = NULL;
         error = NULL;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (daemon, context)) == NULL)
-                goto out;
-
         /* check that all given components exist, that they are indeed linux-md-components and
          * that their uuid agrees
          */
-        for (n = 0; n < (int) components->len; n++) {
+        for (n = 0; components_as_strv[n] != NULL; n++) {
                 DevkitDisksDevice *slave;
-                const char *component_objpath = components->pdata[n];
+                const char *component_objpath = components_as_strv[n];
 
                 slave = devkit_disks_daemon_local_find_by_object_path (daemon, component_objpath);
                 if (slave == NULL) {
@@ -8377,21 +8650,14 @@ devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
 
         md_device_file = g_strdup_printf ("/dev/md%d", n);
 
-        if (!devkit_disks_damon_local_check_auth (daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.linux-md",
-                                                  context)) {
-                goto out;
-        }
-
         n = 0;
         argv[n++] = "mdadm";
         argv[n++] = "--assemble";
         argv[n++] = md_device_file;
         argv[n++] = "--run";
-        for (m = 0; m < (int) components->len; m++) {
+        for (m = 0; components_as_strv[m] != NULL; m++) {
                 DevkitDisksDevice *slave;
-                const char *component_objpath = components->pdata[m];
+                const char *component_objpath = components_as_strv[m];
 
                 slave = devkit_disks_daemon_local_find_by_object_path (daemon, component_objpath);
                 if (slave == NULL) {
@@ -8415,7 +8681,6 @@ devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
                       "LinuxMdStart",
                       TRUE,
                       NULL,
-                      pk_caller,
                       argv,
                       NULL,
                       linux_md_start_completed_cb,
@@ -8427,12 +8692,35 @@ devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
 out:
         g_free (uuid);
         g_free (md_device_file);
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+}
+
+/* NOTE: This is a method on the daemon, not the device. */
+gboolean
+devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
+                                    GPtrArray             *components,
+                                    char                 **options,
+                                    DBusGMethodInvocation *context)
+{
+        gchar **components_as_strv;
+        guint n;
+
+        components_as_strv = g_new0 (gchar *, components->len);
+        for (n = 0; n < components->len; n++)
+                components_as_strv[n] = g_strdup (components->pdata[n]);
+
+        devkit_disks_daemon_local_check_auth (daemon,
+                                              NULL,
+                                              "org.freedesktop.devicekit.disks.linux-md",
+                                              devkit_disks_daemon_linux_md_start_authorized_cb,
+                                              context,
+                                              2,
+                                              components_as_strv, g_strfreev,
+                                              g_strdupv (options), g_strfreev);
 
         return TRUE;
 }
 
+
 /*--------------------------------------------------------------------------------------------------------------*/
 
 typedef struct {
@@ -8466,7 +8754,6 @@ force_unmount_data_unref (ForceUnmountData *data)
 static void
 force_unmount_completed_cb (DBusGMethodInvocation *context,
                             DevkitDisksDevice *device,
-                            PolKitCaller *pk_caller,
                             gboolean job_was_cancelled,
                             int status,
                             const char *stderr,
@@ -8514,7 +8801,6 @@ force_unmount (DevkitDisksDevice        *device,
                       "ForceUnmount",
                       FALSE,
                       device,
-                      NULL,
                       argv,
                       NULL,
                       force_unmount_completed_cb,
@@ -8539,7 +8825,6 @@ typedef struct {
 static void
 force_luks_teardown_completed_cb (DBusGMethodInvocation *context,
                                     DevkitDisksDevice *device,
-                                    PolKitCaller *pk_caller,
                                     gboolean job_was_cancelled,
                                     int status,
                                     const char *stderr,
@@ -8619,7 +8904,6 @@ force_luks_teardown_cleartext_done (DevkitDisksDevice *device,
                       "ForceLuksTeardown",
                       FALSE,
                       data->device,
-                      NULL,
                       argv,
                       NULL,
                       force_luks_teardown_completed_cb,
@@ -8731,36 +9015,18 @@ polling_inhibitor_disconnected_cb (DevkitDisksInhibitor *inhibitor,
         devkit_disks_daemon_local_update_poller (device->priv->daemon);
 }
 
-gboolean
-devkit_disks_device_drive_inhibit_polling (DevkitDisksDevice     *device,
-                                           char                 **options,
-                                           DBusGMethodInvocation *context)
-{
+static void
+devkit_disks_device_drive_inhibit_polling_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                         DevkitDisksDevice     *device,
+                                                         DBusGMethodInvocation *context,
+                                                         const gchar           *action_id,
+                                                         guint                  num_user_data,
+                                                         gpointer              *user_data_elements)
+{
+        gchar **options = user_data_elements[0];
         DevkitDisksInhibitor *inhibitor;
-        PolKitCaller *pk_caller;
         guint n;
 
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
-        if (!device->priv->device_is_drive) {
-                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
-                             "Device is not a drive");
-                goto out;
-        }
-
-        if (!device->priv->device_is_media_change_detection_inhibitable) {
-                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
-                             "Media detection cannot be inhibited");
-                goto out;
-        }
-
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.inhibit-polling",
-                                                  context))
-                goto out;
-
         for (n = 0; options[n] != NULL; n++) {
                 const char *option = options[n];
                 throw_error (context,
@@ -8781,8 +9047,36 @@ devkit_disks_device_drive_inhibit_polling (DevkitDisksDevice     *device,
         dbus_g_method_return (context, devkit_disks_inhibitor_get_cookie (inhibitor));
 
 out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        ;
+}
+
+gboolean
+devkit_disks_device_drive_inhibit_polling (DevkitDisksDevice     *device,
+                                           char                 **options,
+                                           DBusGMethodInvocation *context)
+{
+        if (!device->priv->device_is_drive) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Device is not a drive");
+                goto out;
+        }
+
+        if (!device->priv->device_is_media_change_detection_inhibitable) {
+                throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
+                             "Media detection cannot be inhibited");
+                goto out;
+        }
+
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.inhibit-polling",
+                                              devkit_disks_device_drive_inhibit_polling_authorized_cb,
+                                              context,
+                                              1,
+                                              g_strdupv (options), g_strfreev);
+
+
+ out:
         return TRUE;
 }
 
@@ -8833,34 +9127,35 @@ devkit_disks_device_drive_uninhibit_polling (DevkitDisksDevice     *device,
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
+static void
+devkit_disks_device_drive_poll_media_authorized_cb (DevkitDisksDaemon     *daemon,
+                                                    DevkitDisksDevice     *device,
+                                                    DBusGMethodInvocation *context,
+                                                    const gchar           *action_id,
+                                                    guint                  num_user_data,
+                                                    gpointer              *user_data_elements)
+{
+        devkit_disks_poller_poll_device (device->priv->device_file);
+
+        dbus_g_method_return (context);
+}
+
 gboolean
 devkit_disks_device_drive_poll_media (DevkitDisksDevice     *device,
                                       DBusGMethodInvocation *context)
 {
-        PolKitCaller *pk_caller;
-
-        if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL)
-                goto out;
-
         if (!device->priv->device_is_drive) {
                 throw_error (context, DEVKIT_DISKS_ERROR_FAILED,
                              "Device is not a drive");
                 goto out;
         }
 
-        if (!devkit_disks_damon_local_check_auth (device->priv->daemon,
-                                                  pk_caller,
-                                                  "org.freedesktop.devicekit.disks.inhibit-polling",
-                                                  context))
-                goto out;
-
-        devkit_disks_poller_poll_device (device->priv->device_file);
-
-        dbus_g_method_return (context);
-
-out:
-        if (pk_caller != NULL)
-                polkit_caller_unref (pk_caller);
+        devkit_disks_daemon_local_check_auth (device->priv->daemon,
+                                              device,
+                                              "org.freedesktop.devicekit.disks.inhibit-polling",
+                                              devkit_disks_device_drive_poll_media_authorized_cb,
+                                              context,
+                                              0);
+ out:
         return TRUE;
 }
-
index 61bd6e9..29e73b8 100644 (file)
@@ -22,8 +22,8 @@
 #define __DEVKIT_DISKS_DEVICE_H__
 
 #include <dbus/dbus-glib.h>
-#include <polkit-dbus/polkit-dbus.h>
 #include <devkit-gobject/devkit-gobject.h>
+#include <sys/types.h>
 
 #include "devkit-disks-types.h"
 
index be19786..51e6640 100644 (file)
@@ -143,7 +143,7 @@ devkit_disks_inhibitor_name_owner_changed (DBusMessage *message)
                         for (l = inhibitors; l != NULL; l = l->next) {
                                 DevkitDisksInhibitor *inhibitor = DEVKIT_DISKS_INHIBITOR (l->data);
 
-                                g_debug (" looking at %s", inhibitor->priv->unique_dbus_name);
+                                //g_debug (" looking at %s", inhibitor->priv->unique_dbus_name);
                                 if (g_strcmp0 (name, inhibitor->priv->unique_dbus_name) == 0) {
                                         g_signal_emit_by_name (inhibitor, "disconnected");
                                 }