Patchwork [1/1] udev-extraconf:fix rootless X write to usb storage failed

login
register
mail settings
Submitter Hongxu Jia
Date April 28, 2013, 8:14 a.m.
Message ID <56dc88629fbf58c9bfb0427320ac916f79e96364.1367133417.git.hongxu.jia@windriver.com>
Download mbox | patch
Permalink /patch/49009/
State New
Headers show

Comments

Hongxu Jia - April 28, 2013, 8:14 a.m.
Rootless X is owned by xuser, the problem is xuser could not have
permissions to write to the usb storage when the file system is
vfat(fat16/fat32):

1)On my distribution(Ubuntu 12.10), usb storage is auto mounted by gnome
rather than udev, udev detects the plugin event and notify gnome to mount
the device, the UID and GID of usb storage is inherited from the gnome's.

  Login with username `jiahongxu', it has permissions to write usb storage:
  ...ubuntu log.......
  $ mount
  /dev/sdb1 on /media/jiahongxu/fat type vfat (uid=1000,gid=1000,dmask=0077)
  $ ls /media/jiahongxu/ -al
  drwx------  2 jiahongxu jiahongxu 16384 Jan  1  1970 fat
  ....................

  Login with username `tester', it has permissions to write usb storage:
  ...ubuntu log.......
  $ mount
  /dev/sdb1 on /media/tester/fat type vfat (uid=1001,gid=1002,dmask=0077)
  $ ls /media/root/ -al
  drwx------  2 tester    tester    16384 Jan  1  1970 fat
  ....................

2)Plug in the previous usb storage to yocto atom which rootless X is enable,
xuser doesn't have permissions to write usb storage, the UID and GID of usb
storage is inherited from udev's (root):
  ...yocto atom log...
  $mount
  /dev/sdb2 on /media/sdb2 type vfat
  $ls /media/ -al
  drwxr-xr-x    2 root     root         16384 Jan  1  1970 sdb2
  ....................

3)In this situation to reference ubuntu, if rootless X is enable, grant
xuser's UID and GID to usb storage while auto mounting by udev.

[YOCTO #4004]

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/recipes-core/udev/udev-extraconf/mount.sh |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
Ross Burton - April 29, 2013, 10:13 a.m.
On 28 April 2013 09:14, Hongxu Jia <hongxu.jia@windriver.com> wrote:
> Rootless X is owned by xuser, the problem is xuser could not have
> permissions to write to the usb storage when the file system is
> vfat(fat16/fat32):

Did I miss something, but why not use a disk group that the xuser has
access to?  I don't really like tying the automounter to the exact
configuration of the X server, especially when this will break again
if the user is using a non-root Wayland session.

Ubuntu can set the user to the current user because as you say, the
user environment is doing the mounting.  At the moment, we don't have
that.

Ross
Otavio Salvador - April 29, 2013, 7:33 p.m.
On Mon, Apr 29, 2013 at 7:13 AM, Burton, Ross <ross.burton@intel.com> wrote:
> On 28 April 2013 09:14, Hongxu Jia <hongxu.jia@windriver.com> wrote:
>> Rootless X is owned by xuser, the problem is xuser could not have
>> permissions to write to the usb storage when the file system is
>> vfat(fat16/fat32):
>
> Did I miss something, but why not use a disk group that the xuser has
> access to?  I don't really like tying the automounter to the exact
> configuration of the X server, especially when this will break again
> if the user is using a non-root Wayland session.
>
> Ubuntu can set the user to the current user because as you say, the
> user environment is doing the mounting.  At the moment, we don't have
> that.

You might want to look at pmount. It is an easy way to handle it without udisks.

https://launchpad.net/pmount

--
Otavio Salvador                             O.S. Systems
E-mail: otavio@ossystems.com.br  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br

Patch

diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh
index 97af608..1135472 100644
--- a/meta/recipes-core/udev/udev-extraconf/mount.sh
+++ b/meta/recipes-core/udev/udev-extraconf/mount.sh
@@ -27,6 +27,22 @@  automount() {
 		MOUNT="$MOUNT -o silent"
 	fi
 	
+	# Setting for rootless X
+	if [ -f /etc/X11/Xusername ]; then
+		xusername="`cat /etc/X11/Xusername`"
+		case $ID_FS_TYPE in
+		# Such as fat12,fat16,fat32,vfat,msdos
+		vfat)
+			# Set the owner and group of the storage to xuser, only grant xuser
+			# with w/r/x permissions.
+			MOUNT="$MOUNT -o uid=`id "$xusername" -u`,gid=`id "$xusername" -g`,umask=077"
+			;;
+		*)
+			# TODO
+			;;
+		esac
+	fi
+
 	if ! $MOUNT -t auto $DEVNAME "/media/$name"
 	then
 		#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/media/$name\" failed!"