Ignore broken directory permissions on UDF media
authorMartin Pitt <martin.pitt@ubuntu.com>
Thu, 24 Feb 2011 12:39:52 +0000 (13:39 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Thu, 24 Feb 2011 12:39:52 +0000 (13:39 +0100)
Some broken DVDs come with 0400 directory permissions, making them unreadable;
according to the UDF spec (http://www.osta.org/specs/pdf/udf260.pdf) directory
permissions are to be respected, but apparently Windows ignores those.

To work around this, override readonly UDF media with a dmode=0500, as on those
it doesn't really make sense to hide anything.

https://launchpad.net/bugs/635499

src/device.c

index c4a83ff..21d9530 100644 (file)
@@ -5874,7 +5874,7 @@ static const char *iso9660_allow_gid_self[] = { "gid=", NULL };
 /* ---------------------- udf -------------------- */
 
 static const char *udf_defaults[] = { "uid=", "gid=", "iocharset=utf8", "umask=0077", NULL };
-static const char *udf_allow[] = { "iocharset=", "umask=", NULL };
+static const char *udf_allow[] = { "iocharset=", "umask=", "mode=", "dmode=", NULL };
 static const char *udf_allow_uid_self[] = { "uid=", NULL };
 static const char *udf_allow_gid_self[] = { "gid=", NULL };
 
@@ -6088,7 +6088,8 @@ is_mount_option_allowed (const FSMountOptions *fsmo,
 }
 
 static char **
-prepend_default_mount_options (const FSMountOptions *fsmo,
+prepend_default_mount_options (Device *device,
+                               const FSMountOptions *fsmo,
                                uid_t caller_uid,
                                char **given_options)
 {
@@ -6097,6 +6098,7 @@ prepend_default_mount_options (const FSMountOptions *fsmo,
   char *s;
   gid_t gid;
 
+  /* static default options from FSMountOptions */
   options = g_ptr_array_new ();
   if (fsmo != NULL)
     {
@@ -6124,6 +6126,19 @@ prepend_default_mount_options (const FSMountOptions *fsmo,
             }
         }
     }
+
+  /* dynamic default options */
+
+  /* some broken DVDs come with 0400 directory permissions, making them
+   * unreadable; overwrite readonly UDF media with a 0500 dmode. */
+  if (g_strcmp0 (device->priv->id_type, "udf") == 0 && device->priv->device_is_optical_disc &&
+      device->priv->drive_media != NULL && 
+      strstr(device->priv->drive_media, "_rw") == NULL && strstr(device->priv->drive_media, "_ram") == NULL)
+    {
+      g_ptr_array_add (options, g_strdup("dmode=0500"));
+    }
+
+  /* user supplied options */
   for (n = 0; given_options[n] != NULL; n++)
     {
       g_ptr_array_add (options, g_strdup (given_options[n]));
@@ -6304,7 +6319,7 @@ device_filesystem_mount_authorized_cb (Daemon *daemon,
   /* always prepend some reasonable default mount options; these are
    * chosen here; the user can override them if he wants to
    */
-  options = prepend_default_mount_options (fsmo, caller_uid, given_options);
+  options = prepend_default_mount_options (device, fsmo, caller_uid, given_options);
 
   /* validate mount options and check for authorizations */
   s = g_string_new ("uhelper=udisks,nodev,nosuid");