diff options
| author | David Zeuthen <davidz@redhat.com> | 2012-01-25 17:16:24 -0500 |
|---|---|---|
| committer | David Zeuthen <davidz@redhat.com> | 2012-01-25 17:16:24 -0500 |
| commit | 502fb5b7810afb50e48354e6b4d1781d07f79e10 (patch) | |
| tree | 43f53f8cebb01edf35068488168dee95cc0e46f3 | |
| parent | 7b7aa19e8c0f9e94e77d9d8c24d4fae5c7babeee (diff) | |
Prefer mounting in /run/user/$USER/media instead of /media
Signed-off-by: David Zeuthen <davidz@redhat.com>
| -rw-r--r-- | src/udisksdaemonutil.c | 13 | ||||
| -rw-r--r-- | src/udisksdaemonutil.h | 1 | ||||
| -rw-r--r-- | src/udiskslinuxblock.c | 2 | ||||
| -rw-r--r-- | src/udiskslinuxdriveata.c | 2 | ||||
| -rw-r--r-- | src/udiskslinuxencrypted.c | 6 | ||||
| -rw-r--r-- | src/udiskslinuxfilesystem.c | 70 | ||||
| -rw-r--r-- | src/udiskslinuxloop.c | 2 | ||||
| -rw-r--r-- | src/udiskslinuxmanager.c | 2 |
8 files changed, 81 insertions, 17 deletions
diff --git a/src/udisksdaemonutil.c b/src/udisksdaemonutil.c index 52c8fad..699938c 100644 --- a/src/udisksdaemonutil.c +++ b/src/udisksdaemonutil.c @@ -521,10 +521,11 @@ udisks_daemon_util_check_authorization_sync (UDisksDaemon *daemon, * @cancellable: (allow-none): A #GCancellable or %NULL. * @out_uid: (out): Return location for resolved uid or %NULL. * @out_gid: (out) (allow-none): Return location for resolved gid or %NULL. + * @out_user_name: (out) (allow-none): Return location for resolved user name or %NULL. * @error: Return location for error. * - * Gets the UNIX user id (and possibly group id) of the peer - * represented by @invocation. + * Gets the UNIX user id (and possibly group id and user name) of the + * peer represented by @invocation. * * Returns: %TRUE if the user id (and possibly group id) was obtained, %FALSE otherwise */ @@ -534,6 +535,7 @@ udisks_daemon_util_get_caller_uid_sync (UDisksDaemon *daemon, GCancellable *cancellable, uid_t *out_uid, gid_t *out_gid, + gchar **out_user_name, GError **error) { gboolean ret; @@ -579,7 +581,7 @@ udisks_daemon_util_get_caller_uid_sync (UDisksDaemon *daemon, if (out_uid != NULL) *out_uid = uid; - if (out_gid != NULL) + if (out_gid != NULL || out_user_name != NULL) { struct passwd pwstruct; gchar pwbuf[8192]; @@ -602,7 +604,10 @@ udisks_daemon_util_get_caller_uid_sync (UDisksDaemon *daemon, "Error looking up passwd struct for uid %d: %m", (gint) uid); goto out; } - *out_gid = pw->pw_gid; + if (out_gid != NULL) + *out_gid = pw->pw_gid; + if (out_user_name != NULL) + *out_user_name = g_strdup (pwstruct.pw_name); } ret = TRUE; diff --git a/src/udisksdaemonutil.h b/src/udisksdaemonutil.h index cd722f2..eabfea0 100644 --- a/src/udisksdaemonutil.h +++ b/src/udisksdaemonutil.h @@ -56,6 +56,7 @@ gboolean udisks_daemon_util_get_caller_uid_sync (UDisksDaemon *daemon GCancellable *cancellable, uid_t *out_uid, gid_t *out_gid, + gchar **out_user_name, GError **error); G_END_DECLS diff --git a/src/udiskslinuxblock.c b/src/udiskslinuxblock.c index deb63e4..38f5958 100644 --- a/src/udiskslinuxblock.c +++ b/src/udiskslinuxblock.c @@ -1805,7 +1805,7 @@ handle_format (UDisksBlock *block, action_id = "org.freedesktop.udisks2.modify-device-system"; error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, &caller_gid, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, &caller_gid, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); diff --git a/src/udiskslinuxdriveata.c b/src/udiskslinuxdriveata.c index 2887cf3..c837865 100644 --- a/src/udiskslinuxdriveata.c +++ b/src/udiskslinuxdriveata.c @@ -598,7 +598,7 @@ handle_smart_update (UDisksDriveAta *_drive, { uid_t caller_uid; error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); diff --git a/src/udiskslinuxencrypted.c b/src/udiskslinuxencrypted.c index f6b3d8d..2da9a4f 100644 --- a/src/udiskslinuxencrypted.c +++ b/src/udiskslinuxencrypted.c @@ -293,7 +293,7 @@ handle_unlock (UDisksEncrypted *encrypted, /* we need the uid of the caller for the unlocked-luks file */ error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); @@ -498,7 +498,7 @@ handle_lock (UDisksEncrypted *encrypted, /* we need the uid of the caller to check authorization */ error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); @@ -602,7 +602,7 @@ handle_change_passphrase (UDisksEncrypted *encrypted, } error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); diff --git a/src/udiskslinuxfilesystem.c b/src/udiskslinuxfilesystem.c index 122ce97..ea0024b 100644 --- a/src/udiskslinuxfilesystem.c +++ b/src/udiskslinuxfilesystem.c @@ -617,6 +617,9 @@ ensure_utf8 (const gchar *s) /* * calculate_mount_point: <internal> * @block: A #UDisksBlock. + * @uid: user id of the calling user + * @gid: group id of the calling user + * @user_name: user name of the calling user * @fs_type: The file system type to mount with * @error: Return location for error or %NULL. * @@ -626,11 +629,15 @@ ensure_utf8 (const gchar *s) */ static gchar * calculate_mount_point (UDisksBlock *block, + uid_t uid, + gid_t gid, + const gchar *user_name, const gchar *fs_type, GError **error) { const gchar *label; const gchar *uuid; + gchar *mount_dir = NULL; gchar *mount_point; gchar *orig_mount_point; GString *str; @@ -645,15 +652,50 @@ calculate_mount_point (UDisksBlock *block, uuid = udisks_block_get_id_uuid (block); } + /* try mounting in user's $XDG_RUNTIME_DIR/media first - have to create it on demand... */ + if (user_name != NULL) + { + s = g_strdup_printf ("/run/user/%s", user_name); + if (g_file_test (s, G_FILE_TEST_EXISTS)) + { + mount_dir = g_strdup_printf ("%s/media", s); + if (!g_file_test (mount_dir, G_FILE_TEST_EXISTS)) + { + if (g_mkdir (mount_dir, 0777) != 0) + { + g_set_error (error, + UDISKS_ERROR, + UDISKS_ERROR_FAILED, + "Error creating directory `%s': %m", + mount_dir); + goto out; + } + if (chown (mount_dir, uid, gid) != 0) + { + g_set_error (error, + UDISKS_ERROR, + UDISKS_ERROR_FAILED, + "Error chowning`%s' to uid=%d, gid=%d: %m", + mount_dir, (gint) uid, (gint) gid); + goto out; + } + } + } + g_free (s); + } + /* fall back to mounting in /media */ + if (mount_dir == NULL) + mount_dir = g_strdup ("/media"); + /* NOTE: UTF-8 has the nice property that valid UTF-8 strings only contains * the byte 0x2F if it's for the '/' character (U+002F SOLIDUS). * * See http://en.wikipedia.org/wiki/UTF-8 for details. */ - if (label != NULL && strlen (label) > 0) { - str = g_string_new ("/media/"); + str = g_string_new (NULL); + g_string_append_printf (str, "%s/", mount_dir); s = ensure_utf8 (label); for (n = 0; s[n] != '\0'; n++) { @@ -668,7 +710,8 @@ calculate_mount_point (UDisksBlock *block, } else if (uuid != NULL && strlen (uuid) > 0) { - str = g_string_new ("/media/"); + str = g_string_new (NULL); + g_string_append_printf (str, "%s/", mount_dir); s = ensure_utf8 (uuid); for (n = 0; s[n] != '\0'; n++) { @@ -683,7 +726,7 @@ calculate_mount_point (UDisksBlock *block, } else { - mount_point = g_strdup ("/media/disk"); + mount_point = g_strdup_printf ("%s/disk", mount_dir); } /* ... then uniqify the mount point */ @@ -702,7 +745,9 @@ calculate_mount_point (UDisksBlock *block, } } g_free (orig_mount_point); + g_free (mount_dir); + out: return mount_point; } @@ -844,6 +889,7 @@ handle_mount (UDisksFilesystem *filesystem, UDisksDaemon *daemon; UDisksCleanup *cleanup; uid_t caller_uid; + gid_t caller_gid; const gchar * const *existing_mount_points; const gchar *probed_fs_usage; gchar *fs_type_to_use; @@ -854,6 +900,7 @@ handle_mount (UDisksFilesystem *filesystem, gchar *escaped_mount_options_to_use; gchar *escaped_mount_point_to_use; gchar *error_message; + gchar *caller_user_name; GError *error; const gchar *action_id; gboolean system_managed; @@ -867,6 +914,7 @@ handle_mount (UDisksFilesystem *filesystem, escaped_fs_type_to_use = NULL; escaped_mount_options_to_use = NULL; escaped_mount_point_to_use = NULL; + caller_user_name = NULL; system_managed = FALSE; object = UDISKS_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (filesystem))); @@ -904,7 +952,13 @@ handle_mount (UDisksFilesystem *filesystem, } error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, + invocation, + NULL /* GCancellable */, + &caller_uid, + &caller_gid, + &caller_user_name, + &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); @@ -1076,6 +1130,9 @@ handle_mount (UDisksFilesystem *filesystem, /* calculate mount point (guaranteed to be valid UTF-8) */ error = NULL; mount_point_to_use = calculate_mount_point (block, + caller_uid, + caller_gid, + caller_user_name, fs_type_to_use, &error); if (mount_point_to_use == NULL) @@ -1151,6 +1208,7 @@ handle_mount (UDisksFilesystem *filesystem, g_free (mount_options_to_use); g_free (mount_point_to_use); g_free (fstab_mount_options); + g_free (caller_user_name); return TRUE; /* returning TRUE means that we handled the method invocation */ } @@ -1223,7 +1281,7 @@ handle_unmount (UDisksFilesystem *filesystem, } error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); diff --git a/src/udiskslinuxloop.c b/src/udiskslinuxloop.c index c284139..5ed5d28 100644 --- a/src/udiskslinuxloop.c +++ b/src/udiskslinuxloop.c @@ -180,7 +180,7 @@ handle_delete (UDisksLoop *loop, cleanup = udisks_daemon_get_cleanup (daemon); error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (daemon, invocation, NULL, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); diff --git a/src/udiskslinuxmanager.c b/src/udiskslinuxmanager.c index b539d3c..74be53c 100644 --- a/src/udiskslinuxmanager.c +++ b/src/udiskslinuxmanager.c @@ -270,7 +270,7 @@ handle_loop_setup (UDisksManager *object, /* we need the uid of the caller for the loop file */ error = NULL; - if (!udisks_daemon_util_get_caller_uid_sync (manager->daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, &error)) + if (!udisks_daemon_util_get_caller_uid_sync (manager->daemon, invocation, NULL /* GCancellable */, &caller_uid, NULL, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); |
