Commit bfd153d7 authored by Will Thompson's avatar Will Thompson 🐡 Committed by Kai Lüke

restore: don't attempt to open target read-only

This code seems to be duplicated from gducreatediskimagedialog.c, but in
this context we need 'fd' to be writable. We could still attempt to
open() the device directly (with O_WRONLY) but as the comment says, by
definition /dev/sr* is read-only by nature (or at least, cannot be
written to in this way), so it is unlikely to be of any use.

In any case, in practice this code path will never be taken since the
"Restore" action is not available for optical media.

https://bugzilla.gnome.org/show_bug.cgi?id=792581
parent a2acb6d4
...@@ -690,49 +690,33 @@ copy_thread_func (gpointer user_data) ...@@ -690,49 +690,33 @@ copy_thread_func (gpointer user_data)
gint fd = -1; gint fd = -1;
gint buffer_size; gint buffer_size;
guint64 num_bytes_completed = 0; guint64 num_bytes_completed = 0;
GUnixFDList *fd_list = NULL;
GVariant *fd_index = NULL;
/* default to 1 MiB blocks */ /* default to 1 MiB blocks */
buffer_size = (1 * 1024 * 1024); buffer_size = (1 * 1024 * 1024);
/* Most OSes put ACLs for logged-in users on /dev/sr* nodes (this is /* request the fd from udisks */
* so CD burning tools etc. work) so see if we can open the device if (!udisks_block_call_open_for_restore_sync (data->block,
* file ourselves. If so, great, since this avoids a polkit dialog. g_variant_new ("a{sv}", NULL), /* options */
* NULL, /* fd_list */
* As opposed to udisks' OpenForBackup() we also avoid O_EXCL since &fd_index,
* the disc is read-only by its very nature. As a side-effect this &fd_list,
* allows creating a disk image of a mounted disc. NULL, /* cancellable */
*/ &error))
if (g_str_has_prefix (udisks_block_get_device (data->block), "/dev/sr")) goto out;
{
fd = open (udisks_block_get_device (data->block), O_RDONLY);
}
/* Otherwise, request the fd from udisks */ fd = g_unix_fd_list_get (fd_list, g_variant_get_handle (fd_index), &error);
if (fd == -1) if (error != NULL)
{ {
GUnixFDList *fd_list = NULL; g_prefix_error (&error,
GVariant *fd_index = NULL; "Error extracing fd with handle %d from D-Bus message: ",
if (!udisks_block_call_open_for_restore_sync (data->block, g_variant_get_handle (fd_index));
g_variant_new ("a{sv}", NULL), /* options */ goto out;
NULL, /* fd_list */
&fd_index,
&fd_list,
NULL, /* cancellable */
&error))
goto out;
fd = g_unix_fd_list_get (fd_list, g_variant_get_handle (fd_index), &error);
if (error != NULL)
{
g_prefix_error (&error,
"Error extracing fd with handle %d from D-Bus message: ",
g_variant_get_handle (fd_index));
goto out;
}
if (fd_index != NULL)
g_variant_unref (fd_index);
g_clear_object (&fd_list);
} }
if (fd_index != NULL)
g_variant_unref (fd_index);
g_clear_object (&fd_list);
g_assert (fd != -1); g_assert (fd != -1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment