summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2011-07-22 11:04:09 -0400
committerDavid Zeuthen <davidz@redhat.com>2011-07-22 11:04:09 -0400
commit8de34e59a6dfc121a3ef7adffbf7c9f80ff54f62 (patch)
treecf99248b554484e6c4874486fbb06bb65a2c9b02
parent4f99de679d40f0b58bae98e3f79612d338fb6dda (diff)
Add udisks_daemon_util_setup_by_user() and use it when mounting
This way you won't be asked for polkit auth if you want to mount a device that you have just unlocked. Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--doc/udisks2-sections.txt1
-rw-r--r--src/udisksdaemonutil.c52
-rw-r--r--src/udisksdaemonutil.h4
-rw-r--r--src/udiskslinuxfilesystem.c2
4 files changed, 58 insertions, 1 deletions
diff --git a/doc/udisks2-sections.txt b/doc/udisks2-sections.txt
index 4ed323a..4a1db23 100644
--- a/doc/udisks2-sections.txt
+++ b/doc/udisks2-sections.txt
@@ -293,6 +293,7 @@ udisks_daemon_util_resolve_link
udisks_daemon_util_resolve_links
udisks_daemon_util_check_authorization_sync
udisks_daemon_util_get_caller_uid_sync
+udisks_daemon_util_setup_by_user
</SECTION>
<SECTION>
diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c
index 32548a2..1f1b4a0 100644
--- a/src/udisksdaemonutil.c
+++ b/src/udisksdaemonutil.c
@@ -30,6 +30,7 @@
#include "udisksdaemon.h"
#include "udisksdaemonutil.h"
+#include "udiskscleanup.h"
/**
* SECTION:udisksdaemonutil
@@ -285,6 +286,57 @@ udisks_daemon_util_resolve_links (const gchar *path,
/**
+ * udisks_daemon_util_setup_by_user:
+ * @daemon: A #UDisksDaemon.
+ * @object: The #GDBusObject that the call is on or %NULL.
+ * @user: The user in question.
+ *
+ * Checks whether the device represented by @object (if any) has been
+ * setup by @user.
+ *
+ * Returns: %TRUE if @object has been set-up by @user, %FALSE if not.
+ */
+gboolean
+udisks_daemon_util_setup_by_user (UDisksDaemon *daemon,
+ UDisksObject *object,
+ uid_t user)
+{
+ gboolean ret;
+ UDisksBlockDevice *block;
+ UDisksCleanup *cleanup;
+ uid_t setup_by_user;
+
+ ret = FALSE;
+
+ cleanup = udisks_daemon_get_cleanup (daemon);
+ block = udisks_object_peek_block_device (object);
+ if (block != NULL)
+ {
+ UDisksObject *crypto_object;
+ crypto_object = udisks_daemon_find_object (daemon, udisks_block_device_get_crypto_backing_device (block));
+ if (crypto_object != NULL)
+ {
+ UDisksBlockDevice *crypto_block;
+ crypto_block = udisks_object_peek_block_device (crypto_object);
+
+ if (udisks_cleanup_find_unlocked_luks (cleanup,
+ makedev (udisks_block_device_get_major (crypto_block),
+ udisks_block_device_get_minor (crypto_block)),
+ &setup_by_user, NULL))
+ {
+ if (setup_by_user == user)
+ {
+ ret = TRUE;
+ }
+ }
+ g_object_unref (crypto_object);
+ }
+ }
+
+ return ret;
+}
+
+/**
* udisks_daemon_util_check_authorization_sync:
* @daemon: A #UDisksDaemon.
* @object: (allow-none): The #GDBusObject that the call is on or %NULL.
diff --git a/src/udisksdaemonutil.h b/src/udisksdaemonutil.h
index 6bf0dd3..6bc7eee 100644
--- a/src/udisksdaemonutil.h
+++ b/src/udisksdaemonutil.h
@@ -38,6 +38,10 @@ gchar *udisks_daemon_util_resolve_link (const gchar *path,
gchar **udisks_daemon_util_resolve_links (const gchar *path,
const gchar *dir_name);
+gboolean udisks_daemon_util_setup_by_user (UDisksDaemon *daemon,
+ UDisksObject *object,
+ uid_t user);
+
gboolean udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon,
UDisksObject *object,
const gchar *action_id,
diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c
index e14a64a..121cbc8 100644
--- a/src/udiskslinuxfilesystem.c
+++ b/src/udiskslinuxfilesystem.c
@@ -776,7 +776,7 @@ handle_mount (UDisksFilesystem *filesystem,
* may be racing with other threads...
*/
action_id = "org.freedesktop.udisks2.filesystem-mount";
- if (udisks_block_device_get_hint_system (block))
+ if (udisks_block_device_get_hint_system (block) && !(udisks_daemon_util_setup_by_user (daemon, object, caller_uid)))
action_id = "org.freedesktop.udisks2.filesystem-mount-system";
if (!udisks_daemon_util_check_authorization_sync (daemon,
object,