Re: [PATCH] mount: use encoded labels for volume_id

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2007-06-21 at 12:52 +0200, Matthias Koenig wrote:
> since udev-112 exports now the label encoding function,
> here is a proposed patch.
> This fixes the problem of user mounts when filsystems
> with unsafe characters are given via LABEL= in fstab.

A patch to do this is already on the list:
  http://www.mail-archive.com/util-linux-ng@xxxxxxxxxxxxxxx/msg00196.html
I was waiting for Fedora rawhide to catch-up before resending is, so Karel
can at least compile-test it. :)

Configure should check for the new function in the library. Also uuid's may
need escaping with free textual uuids like DDF-raid uses. The probing context
"struct volume_id" should not be accessed directly anymore, if we require a
recent libvolume_id anyway. It will switch to an opaque object some day.
The known_fstype() lookup is also available now, and the TODO can be removed.

Patch attached again.

Thanks,
Kay
diff --git a/configure.ac b/configure.ac
index e678773..38c4815 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,7 +87,7 @@ have_volume_id=no
 if test x$with_fsprobe = xblkid; then
   UTIL_CHECK_LIB(blkid, blkid_known_fstype)
 elif test x$with_fsprobe = xvolume_id; then
-  UTIL_CHECK_LIB(volume_id, volume_id_open_fd)
+  UTIL_CHECK_LIB(volume_id, volume_id_encode_string)
 fi
 
 if test $have_blkid = no && test $have_volume_id = no; then
diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c
index 8c13987..4b58e72 100644
--- a/mount/fsprobe_volumeid.c
+++ b/mount/fsprobe_volumeid.c
@@ -20,11 +20,13 @@ enum probe_type {
 	VOLUME_ID_TYPE,
 };
 
-static char *probe(const char *device, enum probe_type type)
+static char
+*probe(const char *device, enum probe_type type)
 {
 	int fd;
 	uint64_t size;
 	struct volume_id *id;
+	const char *val;
 	char *value = NULL;
 
 	fd = open(device, O_RDONLY);
@@ -42,13 +44,16 @@ static char *probe(const char *device, enum probe_type type)
 	if (volume_id_probe_all(id, 0, size) == 0) {
 		switch(type) {
 		case VOLUME_ID_LABEL:
-			value  = xstrdup(id->label);
+			if (volume_id_get_label(id, &val))
+				value  = xstrdup(val);
 			break;
 		case VOLUME_ID_UUID:
-			value  = xstrdup(id->uuid);
+			if (volume_id_get_uuid(id, &val))
+				value  = xstrdup(val);
 			break;
 		case VOLUME_ID_TYPE:
-			value  = xstrdup(id->type);
+			if (volume_id_get_type(id, &val))
+				value  = xstrdup(val);
 			break;
 		default:
 			break;
@@ -72,10 +77,8 @@ fsprobe_exit(void)
 int
 fsprobe_known_fstype(const char *fstype)
 {
-	/* TODO 
 	if (volume_id_get_prober_by_type(fstype) != NULL)
 		return 1;
-	*/
 	return 0;
 }
 
@@ -101,11 +104,15 @@ const char *
 fsprobe_get_devname_by_uuid(const char *uuid)
 {
 	char dev[PATH_MAX];
+	size_t len;
 
 	if (!uuid)
 		return NULL;
 
-	snprintf(dev, sizeof(dev), PATH_DEV_BYUUID "/%s", uuid);
+	strcpy(dev, PATH_DEV_BYUUID "/");
+	len = strlen(PATH_DEV_BYUUID "/");
+	if (!volume_id_encode_string(uuid, &dev[len], sizeof(dev) - len) != 0)
+		return NULL;
 	return canonicalize(dev);
 }
 
@@ -113,11 +120,13 @@ const char *
 fsprobe_get_devname_by_label(const char *label)
 {
 	char dev[PATH_MAX];
+	size_t len;
 
 	if (!label)
 		return NULL;
-
-	snprintf(dev, sizeof(dev), PATH_DEV_BYLABEL "/%s", label);
+	strcpy(dev, PATH_DEV_BYLABEL "/");
+	len = strlen(PATH_DEV_BYLABEL "/");
+	if (!volume_id_encode_string(label, &dev[len], sizeof(dev) - len) != 0)
+		return NULL;
 	return canonicalize(dev);
 }
-

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux