in reply to An odd failure of setuid(0)

I think you got the answer to your main question. So let me answer on how I did the same thing. And perhaps some ideas on how to get around your issues.

First, I don't bother dropping the modules. In fact, I just put them in to always load during boot, and then forget about it. (Actually, since moving to Gentoo, I just compiled 'em right into the kernel so they aren't modules anymore.) Then I set /mnt/camera to be mountable by non-root by adding ",user" to the options string. In your case, that would be /mnt/usb/flash.

Next option would be to have a load/unload script, say, /usr/local/bin/mount_flash, which just was:

#!/bin/sh unmount=$1 if [ $unmount = "-d" ] then /sbin/umount /mnt/usb/flash sleep 2 /sbin/modprobe -r usb-storage else /sbin/modprobe usb-storage /sbin/mount /mnt/usb/flash fi
Then add this to /etc/sudoers such that you can run it without a password:
alaric NOPASSWD: /usr/local/bin/mount_flash, /usr/local/bin/mount_flas +h -d
(I think), and now just run system(qw(sudo /usr/local/bin/mount_flash)) and system(qw(sudo /usr/local/bin/mount_flash -d)). Completely avoiding setuid().

Replies are listed 'Best First'.
Re^2: An odd failure of setuid(0)
by Llew_Llaw_Gyffes (Scribe) on Jul 21, 2006 at 20:18 UTC

    I initially did it this way myself.  I discovered, though, that what tended to happen was that the kernel didn't know when the flash card had been removed and reinserted in the reader, and so it assumed that the previous contents were still valid -- even across mounts.  The only way to ensure that directory listings of the flashcard contents were actually correct was to remove the module after unmounting, and reload it again before mounting.

    Of course, that was several years ago.  I haven't tested to see whether this problem still exists.  It would most certainly simplify life if it was fixed now.