Wednesday 6 May 2009

Permissions on USB devices on LTSP terminals

In our linux environment, all our users have the same primary group, rather than having a private group. For the vast majority of stuff this is fine and keeps things simpler. However the method that ltsp uses for mounting USB sticks (or other local media) creates a directory called /media/ on the server which is has the group set to the primary group of the user and the owner set to root with permissions of rwxr_x___

This, combined with the users all being in the same primary group leads to the devices that users plug in being shown on all users' desktops. They can't actually access the devices - those have different permissions - but they can see their existence which at the least is annoying and in the case of several people using CD drives, confusing.

My current solution is a little convoluted - but does the trick.

Firstly you need a program that can change ownership of a directory. This has to be installed as a suid program as the mounting script is run by the user who is logged into the terminal.

I just have a little piece of C to do the job:

#include
#include
#include

int main(int argc, char *argv[]) {

char buff[100];

if (argc != 2)
exit(1);

sprintf(buff, "/bin/chown %s:root /media/%s", argv[1], argv[1]);
system(buff);

return(0);
}

I call this program mediafix and have installed it in /usr/local/bin

Then, in /usr/sbin/ltspfsmounter, add a line saying

call(['mediafix'], username)

towards the end of the main function after the mounting has taken place.

This ensures that any time a device is mounted, the containing directory has it's ownership amended and keeps the icons hidden from other users.

Debian Lenny on a Poweredge 2600

Usually the Debian upgrade procedure is pretty straight forward, and my recent upgrade of a Poweredge 2600 from etch to lenny was no exception. Just change the sources and do an apt-get update; aptitude dist-upgrade and answer some questions along the way.

Occasionally there's a gotcha - and this one had an issue with our lvm based file system. Using the new kernel that comes with lenny (2.6.26), it failed to find the lvm and therefore wouldn't boot.

A little googling revealed a potential solution - add the option "rootdelay=9" to the kernel options for boot - and surely enough the machine was back to life.