{
DBusGConnection *system_bus_connection;
DBusGProxy *system_bus_proxy;
- PolKitContext *pk_context;
- PolKitTracker *pk_tracker;
+
+ PolkitAuthority *authority;
DevkitClient *devkit_client;
{
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"),
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);
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;
}
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);
}
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));
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
/*--------------------------------------------------------------------------------------------------------------*/
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;
}
/*--------------------------------------------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------------------------------------------*/
+
+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
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,
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;
+}
/*--------------------------------------------------------------------------------------------------------------*/
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");
dbus_g_method_return (context, devkit_disks_inhibitor_get_cookie (inhibitor));
out:
- if (pk_caller != NULL)
- polkit_caller_unref (pk_caller);
return TRUE;
}
#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"
typedef void (*JobCompletedFunc) (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *caller,
gboolean was_cancelled,
int status,
const char *stderr,
char *job_id;
DevkitDisksDevice *device;
- PolKitCaller *pk_caller;
DBusGMethodInvocation *context;
JobCompletedFunc job_completed_func;
GPid pid;
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)
job->job_completed_func (job->context,
job->device,
- job->pk_caller,
job->was_cancelled,
status,
job->error_string->str,
const char *job_id,
gboolean is_cancellable,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
char **argv,
const char *stdin_str,
JobCompletedFunc job_completed_func,
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;
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;
static void
filesystem_mount_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
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) {
}
}
-
-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];
char *fstype;
char *mount_options;
GError *error;
- PolKitCaller *pk_caller;
uid_t caller_uid;
gboolean remove_dir_on_unmount;
const FSMountOptions *fsmo;
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) {
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) {
"FilesystemMount",
FALSE,
device,
- pk_caller,
argv,
NULL,
filesystem_mount_completed_cb,
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;
}
static void
filesystem_unmount_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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,
}
}
- 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)
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]);
"FilesystemUnmount",
FALSE,
device,
- pk_caller,
argv,
NULL,
filesystem_unmount_completed_cb,
}
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;
}
static void
filesystem_list_open_files_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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) {
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";
NULL, /* don't run this as a job */
FALSE,
device,
- pk_caller,
argv,
NULL,
filesystem_list_open_files_completed_cb,
}
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;
}
static void
drive_eject_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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");
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,
"DriveEject",
FALSE,
device,
- pk_caller,
argv,
NULL,
drive_eject_completed_cb,
}
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;
}
static void
filesystem_check_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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) {
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";
"FilesystemCheck",
FALSE,
device,
- pk_caller,
argv,
NULL,
filesystem_check_completed_cb,
}
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;
}
static void
partition_delete_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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];
char *offset_as_string;
char *size_as_string;
char *part_number_as_string;
- PolKitCaller *pk_caller;
DevkitDisksDevice *enclosing_device;
offset_as_string = NULL;
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);
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);
"PartitionDelete",
TRUE,
device,
- pk_caller,
argv,
NULL,
partition_delete_completed_cb,
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;
}
static void
filesystem_create_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
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,
int n, m;
char *argv[128];
GError *error;
- PolKitCaller *pk_caller;
char *s;
char *options_for_stdin;
char *passphrase_stdin;
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,
"LuksFormat",
TRUE,
device,
- pk_caller,
argv,
passphrase_stdin,
filesystem_create_create_luks_device_completed_cb,
"FilesystemCreate",
TRUE,
device,
- pk_caller,
argv,
options_for_stdin,
filesystem_create_completed_cb,
}
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));
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,
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;
}
static void
partition_create_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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;
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,
/* 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 ',' */
"PartitionCreate",
TRUE,
device,
- pk_caller,
argv,
NULL,
partition_create_completed_cb,
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,
static void
partition_modify_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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;
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,
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,
"PartitionModify",
TRUE,
device,
- pk_caller,
argv,
NULL,
partition_modify_completed_cb,
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;
}
static void
partition_table_create_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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,
"PartitionTableCreate",
TRUE,
device,
- pk_caller,
argv,
NULL,
partition_table_create_completed_cb,
}
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;
}
static void
luks_unlock_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
char *argv[10];
char *luks_name;
GError *error;
- PolKitCaller *pk_caller;
char *secret_as_stdin;
uid_t uid;
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);
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);
"LuksUnlock",
FALSE,
device,
- pk_caller,
argv,
secret_as_stdin,
luks_unlock_completed_cb,
}
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;
}
/*--------------------------------------------------------------------------------------------------------------*/
static void
luks_lock_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
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) {
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";
"LuksLock",
FALSE,
device,
- pk_caller,
argv,
NULL,
luks_lock_completed_cb,
}
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,
}
}
-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,
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;
"LuksChangePassphrase",
FALSE,
device,
- pk_caller,
argv,
secrets_as_stdin,
luks_change_passphrase_completed_cb,
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;
}
static void
filesystem_set_label_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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,
}
}
- 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;
"FilesystemSetLabel",
FALSE,
device,
- pk_caller,
argv,
NULL,
filesystem_set_label_completed_cb,
}
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;
}
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,
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,
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++) {
NULL, /* don't run this as a job */
FALSE,
device,
- pk_caller,
argv,
NULL,
drive_ata_smart_refresh_data_completed_cb,
}
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;
}
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,
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,
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);
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,
}
}
-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";
"DriveAtaSmartInitiateSelftest",
TRUE,
device,
- pk_caller,
argv,
NULL,
drive_ata_smart_initiate_selftest_completed_cb,
}
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;
}
static void
linux_md_stop_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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";
"LinuxMdStop",
TRUE,
device,
- pk_caller,
argv,
NULL,
linux_md_stop_completed_cb,
}
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;
}
static void
linux_md_add_component_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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,
/* 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";
"LinuxMdAddComponent",
TRUE,
device,
- pk_caller,
argv,
NULL,
linux_md_add_component_completed_cb,
}
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;
}
+
/*--------------------------------------------------------------------------------------------------------------*/
static void
linux_md_remove_component_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
}
-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,
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;
"LinuxMdRemoveComponent",
TRUE,
device,
- pk_caller,
argv,
NULL,
linux_md_remove_component_completed_cb,
}
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;
}
static void
linux_md_start_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
}
/* 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;
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) {
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) {
"LinuxMdStart",
TRUE,
NULL,
- pk_caller,
argv,
NULL,
linux_md_start_completed_cb,
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 {
static void
force_unmount_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
"ForceUnmount",
FALSE,
device,
- NULL,
argv,
NULL,
force_unmount_completed_cb,
static void
force_luks_teardown_completed_cb (DBusGMethodInvocation *context,
DevkitDisksDevice *device,
- PolKitCaller *pk_caller,
gboolean job_was_cancelled,
int status,
const char *stderr,
"ForceLuksTeardown",
FALSE,
data->device,
- NULL,
argv,
NULL,
force_luks_teardown_completed_cb,
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,
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;
}
/*--------------------------------------------------------------------------------------------------------------*/
+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;
}
-