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.

No comments: