[PATCH] sanitize instead of rejecting mountpoints with funny
characters
Ludwig Nussel
ludwig.nussel at suse.de
Fri Feb 24 06:41:35 PST 2006
Hi,
Since front-ends that call the Mount method have no way to determine
the whitelist used for filtering invalid mount points it's better to
not completely reject "invalid" ones IMO. If the Mount call fails a
front-end only has the possibility to call it again without a mount
point which results in the device beeing mounted on "disk". By
replacing invalid characters with eg. an underscore the mount point
at least looks similar to what the user actually entered.
I think the is_ascii check in the fdi file for setting the
desired_mount_point property should also be removed as it prevents
mountpoints with umlauts from beeing used by default although the
hal-system-storage-mount allows them.
Index: tools/hal-system-storage-mount
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-mount,v
retrieving revision 1.24
diff -u -r1.24 hal-system-storage-mount
--- tools/hal-system-storage-mount 14 Feb 2006 18:49:55 -0000 1.24
+++ tools/hal-system-storage-mount 24 Feb 2006 14:07:07 -0000
@@ -70,24 +70,24 @@
# Used to get :alnum: to be somewhat useful
LANG=en_US.UTF-8
+sanitize_given_mountpoint()
+{
+ GIVEN_MOUNTPOINT=${GIVEN_MOUNTPOINT//[^[:alnum:]_=[:space:]:.,+-]/_}
+ GIVEN_MOUNTPOINT=${GIVEN_MOUNTPOINT/./_}
+}
+
read GIVEN_MOUNTPOINT
-GIVEN_MOUNTPOINT=${GIVEN_MOUNTPOINT//[^[:alnum:]_=[:space:]:.,+-]/@}
+sanitize_given_mountpoint
read GIVEN_MOUNTTYPE
GIVEN_MOUNTTYPE=${GIVEN_MOUNTTYPE//[^a-zA-Z0-9_=]/_}
read GIVEN_MOUNTOPTIONS
GIVEN_MOUNTOPTIONS=${GIVEN_MOUNTOPTIONS//[^a-zA-Z0-9_=-[:space:]]/_}
# if no mountpoint is requested, get the mountpoint from the filesystem
-# label if it does not contain invalid chars or starts with a "."
+# label
if [ "$GIVEN_MOUNTPOINT" == "" ]; then
- case "$HAL_PROP_VOLUME_LABEL" in
- *[!A-Za-z0-9_:.+-]*)
- ;;
- .*)
- ;;
- *)
- GIVEN_MOUNTPOINT="$HAL_PROP_VOLUME_LABEL"
- esac
+ GIVEN_MOUNTPOINT="$HAL_PROP_VOLUME_LABEL"
+ sanitize_given_mountpoint
fi
# if no mountpoint is given, use default name
@@ -99,15 +99,6 @@
fi
fi
-# last check, we've replaced invalid characters in requested mountpoint
-# with '@' and don't allow a specified mountpoint starting with "."
-case "$GIVEN_MOUNTPOINT" in
- .*|*@*)
- echo "org.freedesktop.Hal.Device.Volume.InvalidMountpoint" >&2
- echo "The mountpoint is invalid." >&2
- exit 1
- ;;
-esac
MOUNTPOINT="$GIVEN_MOUNTPOINT"
# pass only whitelisted types; allow anything if it's on a non-pollable drive
cu
Ludwig
--
(o_ Ludwig Nussel
//\ SUSE LINUX Products GmbH, Development
V_/_ http://www.suse.de/
More information about the hal
mailing list