Make FilesystemMount() accept an 'auth_no_user_interaction' option
authorDavid Zeuthen <davidz@redhat.com>
Mon, 17 Aug 2009 15:55:01 +0000 (11:55 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 17 Aug 2009 15:55:01 +0000 (11:55 -0400)
This allows automounters to request that no user interaction should ever
take place. See

 https://bugs.freedesktop.org/show_bug.cgi?id=22652

for discussion.

data/org.freedesktop.DeviceKit.Disks.Device.xml
src/devkit-disks-daemon.c
src/devkit-disks-daemon.h
src/devkit-disks-device.c

index dbb4d63..b770896 100644 (file)
         <doc:doc><doc:summary>File system type to use.</doc:summary></doc:doc>
       </arg>
       <arg name="options" direction="in" type="as">
-        <doc:doc><doc:summary>Mount Options. Valid mount options include mount options accepted by the native mount program.</doc:summary></doc:doc>
+        <doc:doc><doc:summary>
+            Mount Options. Valid mount options include mount options accepted by the native mount program.
+            The option <quote>auth_no_user_interaction</quote> can be used to avoid user interaction (e.g. authentication dialogs) when checking whether the caller is authorized.</doc:summary></doc:doc>
       </arg>
       <arg name="mount_path" direction="out" type="s">
         <doc:doc><doc:summary>Where the device was mounted.</doc:summary></doc:doc>
index 0c72601..9aa7ef4 100644 (file)
@@ -1300,6 +1300,7 @@ devkit_disks_daemon_local_check_auth (DevkitDisksDaemon            *daemon,
                                       DevkitDisksDevice            *device,
                                       const gchar                  *action_id,
                                       const gchar                  *operation,
+                                      gboolean                      allow_user_interaction,
                                       DevkitDisksCheckAuthCallback  check_auth_callback,
                                       DBusGMethodInvocation        *context,
                                       guint                         num_user_data,
@@ -1333,6 +1334,7 @@ devkit_disks_daemon_local_check_auth (DevkitDisksDaemon            *daemon,
         if (action_id != NULL) {
                 PolkitSubject *subject;
                 PolkitDetails *details;
+                PolkitCheckAuthorizationFlags flags;
                 gchar partition_number_buf[32];
 
                 /* Set details - see devkit-disks-polkit-action-lookup.c for where
@@ -1417,11 +1419,14 @@ devkit_disks_daemon_local_check_auth (DevkitDisksDaemon            *daemon,
                                   G_CALLBACK (lca_caller_disconnected_cb),
                                   data);
 
+                flags = POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE;
+                if (allow_user_interaction)
+                        flags |= POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION;
                 polkit_authority_check_authorization (daemon->priv->authority,
                                                       subject,
                                                       action_id,
                                                       details,
-                                                      POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
+                                                      flags,
                                                       data->cancellable,
                                                       (GAsyncReadyCallback) lca_check_authorization_callback,
                                                       data);
@@ -1758,6 +1763,7 @@ devkit_disks_daemon_drive_inhibit_all_polling (DevkitDisksDaemon     *daemon,
                                               NULL,
                                               "org.freedesktop.devicekit.disks.inhibit-polling",
                                               "InhibitAllPolling",
+                                              TRUE,
                                               devkit_disks_daemon_drive_inhibit_all_polling_authorized_cb,
                                               context,
                                               1,
@@ -1966,6 +1972,7 @@ devkit_disks_daemon_drive_set_all_spindown_timeouts (DevkitDisksDaemon     *daem
                                               NULL,
                                               "org.freedesktop.devicekit.disks.drive-set-spindown",
                                               "DriveSetAllSpindownTimeouts",
+                                              TRUE,
                                               devkit_disks_daemon_drive_set_all_spindown_timeouts_authorized_cb,
                                               context,
                                               2,
index c05e29d..f417079 100644 (file)
@@ -103,6 +103,7 @@ void               devkit_disks_daemon_local_check_auth          (DevkitDisksDae
                                                                   DevkitDisksDevice            *device,
                                                                   const gchar                  *action_id,
                                                                   const gchar                  *operation,
+                                                                  gboolean                      allow_user_interaction,
                                                                   DevkitDisksCheckAuthCallback  check_auth_callback,
                                                                   DBusGMethodInvocation        *context,
                                                                   guint                         num_user_data,
index 6d58c1d..407305a 100644 (file)
@@ -4751,6 +4751,10 @@ devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
                                       DBusGMethodInvocation *context)
 {
         const gchar *action_id;
+        gboolean auth_no_user_interaction;
+        gchar **options_to_pass;
+        guint n;
+        guint m;
 
         if (is_device_in_fstab (device, NULL)) {
                 action_id = NULL;
@@ -4761,15 +4765,29 @@ devkit_disks_device_filesystem_mount (DevkitDisksDevice     *device,
                         action_id = "org.freedesktop.devicekit.disks.filesystem-mount";
         }
 
+        auth_no_user_interaction = FALSE;
+        options_to_pass = g_strdupv (given_options);
+        for (n = 0; options_to_pass != NULL && options_to_pass[n] != NULL; n++) {
+                if (g_strcmp0 (options_to_pass[n], "auth_no_user_interaction") == 0) {
+                        auth_no_user_interaction = TRUE;
+                        g_free (options_to_pass[n]);
+                        for (m = n; options_to_pass[m + 1] != NULL; m++)
+                                options_to_pass[m] = options_to_pass[m + 1];
+                        options_to_pass[m] = NULL;
+                        break;
+                }
+        }
+
         devkit_disks_daemon_local_check_auth (device->priv->daemon,
                                               device,
                                               action_id,
                                               "FilesystemMount",
+                                              !auth_no_user_interaction,
                                               devkit_disks_device_filesystem_mount_authorized_cb,
                                               context,
                                               2,
                                               g_strdup (filesystem_type), g_free,
-                                              g_strdupv (given_options), g_strfreev);
+                                              options_to_pass, g_strfreev);
 
          return TRUE;
 }
@@ -4928,6 +4946,7 @@ devkit_disks_device_filesystem_unmount (DevkitDisksDevice     *device,
                                               device,
                                               action_id,
                                               "FilesystemUnmount",
+                                              TRUE,
                                               devkit_disks_device_filesystem_unmount_authorized_cb,
                                               context,
                                               1,
@@ -5098,9 +5117,10 @@ devkit_disks_device_filesystem_list_open_files (DevkitDisksDevice     *device,
         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",
+                                               "org.freedesktop.devicekit.disks.filesystem-lsof-system-internal" :
+                                               "org.freedesktop.devicekit.disks.filesystem-lsof",
                                               "FilesystemListOpenFiles",
+                                              TRUE,
                                               devkit_disks_device_filesystem_list_open_files_authorized_cb,
                                               context,
                                               0);
@@ -5223,6 +5243,7 @@ devkit_disks_device_drive_eject (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.drive-eject",
                                               "DriveEject",
+                                              TRUE,
                                               devkit_disks_device_drive_eject_authorized_cb,
                                               context,
                                               1,
@@ -5347,6 +5368,7 @@ devkit_disks_device_drive_detach (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.drive-detach",
                                               "DriveDetach",
+                                              TRUE,
                                               devkit_disks_device_drive_detach_authorized_cb,
                                               context,
                                               1,
@@ -5448,9 +5470,10 @@ devkit_disks_device_filesystem_check (DevkitDisksDevice     *device,
         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",
+                                               "org.freedesktop.devicekit.disks.filesystem-check-system-internal" :
+                                               "org.freedesktop.devicekit.disks.filesystem-check",
                                               "FilesystemCheck",
+                                              TRUE,
                                               devkit_disks_device_filesystem_check_authorized_cb,
                                               context,
                                               1,
@@ -5591,9 +5614,10 @@ devkit_disks_device_partition_delete (DevkitDisksDevice     *device,
         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",
+                                               "org.freedesktop.devicekit.disks.change-system-internal" :
+                                               "org.freedesktop.devicekit.disks.change",
                                               "PartitionDelete",
+                                              TRUE,
                                               devkit_disks_device_partition_delete_authorized_cb,
                                               context,
                                               1,
@@ -5960,6 +5984,7 @@ devkit_disks_device_filesystem_create (DevkitDisksDevice     *device,
                                                 "org.freedesktop.devicekit.disks.change-system-internal" :
                                                 "org.freedesktop.devicekit.disks.change",
                                               "FilesystemCreate",
+                                              TRUE,
                                               devkit_disks_device_filesystem_create_authorized_cb,
                                               context,
                                               2,
@@ -6033,6 +6058,7 @@ devkit_disks_device_job_cancel (DevkitDisksDevice     *device,
                                               device,
                                               action_id,
                                               "JobCancel",
+                                              TRUE,
                                               devkit_disks_device_job_cancel_authorized_cb,
                                               context,
                                               0);
@@ -6373,6 +6399,7 @@ devkit_disks_device_partition_create (DevkitDisksDevice     *device,
                                                 "org.freedesktop.devicekit.disks.change-system-internal" :
                                                 "org.freedesktop.devicekit.disks.change",
                                               "PartitionCreate",
+                                              TRUE,
                                               devkit_disks_device_partition_create_authorized_cb,
                                               context,
                                               8,
@@ -6582,6 +6609,7 @@ devkit_disks_device_partition_modify (DevkitDisksDevice     *device,
                                                 "org.freedesktop.devicekit.disks.change-system-internal" :
                                                 "org.freedesktop.devicekit.disks.change",
                                               "PartitionModify",
+                                              TRUE,
                                               devkit_disks_device_partition_modify_authorized_cb,
                                               context,
                                               3,
@@ -6811,6 +6839,7 @@ devkit_disks_device_partition_table_create (DevkitDisksDevice     *device,
                                                 "org.freedesktop.devicekit.disks.change-system-internal" :
                                                 "org.freedesktop.devicekit.disks.change",
                                               "PartitionTableCreate",
+                                              TRUE,
                                               devkit_disks_device_partition_table_create_authorized_cb,
                                               context,
                                               2,
@@ -7149,6 +7178,7 @@ devkit_disks_device_luks_unlock (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.luks-unlock",
                                               "LuksUnlock",
+                                              TRUE,
                                               devkit_disks_device_luks_unlock_authorized_cb,
                                               context,
                                               2,
@@ -7447,6 +7477,7 @@ devkit_disks_device_luks_lock (DevkitDisksDevice     *device,
                                               device,
                                               action_id,
                                               "LuksLock",
+                                              TRUE,
                                               devkit_disks_device_luks_lock_authorized_cb,
                                               context,
                                               1,
@@ -7559,6 +7590,7 @@ devkit_disks_device_luks_change_passphrase (DevkitDisksDevice     *device,
                                                 "org.freedesktop.devicekit.disks.change-system-internal" :
                                                 "org.freedesktop.devicekit.disks.change",
                                               "LuksChangePassphrase",
+                                              TRUE,
                                               devkit_disks_device_luks_change_passphrase_authorized_cb,
                                               context,
                                               2,
@@ -7707,6 +7739,7 @@ devkit_disks_device_filesystem_set_label (DevkitDisksDevice     *device,
                                                 "org.freedesktop.devicekit.disks.change-system-internal" :
                                                 "org.freedesktop.devicekit.disks.change",
                                               "FilesystemSetLabel",
+                                              TRUE,
                                               devkit_disks_device_filesystem_set_label_authorized_cb,
                                               context,
                                               1,
@@ -8080,6 +8113,7 @@ devkit_disks_device_drive_ata_smart_refresh_data (DevkitDisksDevice     *device,
                                               device,
                                               action_id,
                                               "DriveAtaSmartRefreshData",
+                                              TRUE,
                                               devkit_disks_device_drive_ata_smart_refresh_data_authorized_cb,
                                               context,
                                               1,
@@ -8208,6 +8242,7 @@ devkit_disks_device_drive_ata_smart_get_historical_data (DevkitDisksDevice     *
                                               device,
                                               "org.freedesktop.devicekit.disks.drive-ata-smart-retrieve-historical-data",
                                               "DriveAtaSmartGetHistoricalData",
+                                              TRUE,
                                               devkit_disks_device_drive_ata_smart_get_historical_data_authorized_cb,
                                               context,
                                               3,
@@ -8309,6 +8344,7 @@ devkit_disks_device_drive_ata_smart_initiate_selftest (DevkitDisksDevice     *de
                                               device,
                                               "org.freedesktop.devicekit.disks.drive-ata-smart-selftest",
                                               "DriveAtaSmartInitiateSelftest",
+                                              TRUE,
                                               devkit_disks_device_drive_ata_smart_initiate_selftest_authorized_cb,
                                               context,
                                               2,
@@ -8406,6 +8442,7 @@ devkit_disks_device_linux_md_stop (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.linux-md",
                                               "LinuxMdStop",
+                                              TRUE,
                                               devkit_disks_device_linux_md_stop_authorized_cb,
                                               context,
                                               1,
@@ -8540,6 +8577,7 @@ devkit_disks_device_linux_md_check (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.linux-md",
                                               job_name,
+                                              TRUE,
                                               devkit_disks_device_linux_md_check_authorized_cb,
                                               context,
                                               1,
@@ -8666,6 +8704,7 @@ devkit_disks_device_linux_md_add_component (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.linux-md",
                                               "LinuxMdAddComponent",
+                                              TRUE,
                                               devkit_disks_device_linux_md_add_component_authorized_cb,
                                               context,
                                               2,
@@ -8911,6 +8950,7 @@ devkit_disks_device_linux_md_remove_component (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.linux-md",
                                               "LinuxMdRemoveComponent",
+                                              TRUE,
                                               devkit_disks_device_linux_md_remove_component_authorized_cb,
                                               context,
                                               2,
@@ -9237,6 +9277,7 @@ devkit_disks_daemon_linux_md_start (DevkitDisksDaemon     *daemon,
                                               NULL,
                                               "org.freedesktop.devicekit.disks.linux-md",
                                               "LinuxMdStart",
+                                              TRUE,
                                               devkit_disks_daemon_linux_md_start_authorized_cb,
                                               context,
                                               2,
@@ -9599,6 +9640,7 @@ devkit_disks_daemon_linux_md_create (DevkitDisksDaemon     *daemon,
                                               NULL,
                                               "org.freedesktop.devicekit.disks.linux-md",
                                               "LinuxMdCreate",
+                                              TRUE,
                                               devkit_disks_daemon_linux_md_create_authorized_cb,
                                               context,
                                               4,
@@ -9961,6 +10003,7 @@ devkit_disks_device_drive_inhibit_polling (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.inhibit-polling",
                                               "DriveInhibitPolling",
+                                              TRUE,
                                               devkit_disks_device_drive_inhibit_polling_authorized_cb,
                                               context,
                                               1,
@@ -10093,6 +10136,7 @@ devkit_disks_device_drive_poll_media (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.inhibit-polling",
                                               "DrivePollMedia",
+                                              TRUE,
                                               devkit_disks_device_drive_poll_media_authorized_cb,
                                               context,
                                               0);
@@ -10199,6 +10243,7 @@ devkit_disks_device_drive_set_spindown_timeout (DevkitDisksDevice     *device,
                                               device,
                                               "org.freedesktop.devicekit.disks.drive-set-spindown",
                                               "DriveSetSpindownTimeout",
+                                              TRUE,
                                               devkit_disks_device_drive_set_spindown_timeout_authorized_cb,
                                               context,
                                               2,