in reply to Re^2: USB interface
in thread USB interface

When the user plugs-in the USB device, my program has to ask for password from the user.

So you want to change the behaviour of the OS, and you didn't mention which OS. I'm not sure what any of this has to do with Perl. Find out what you need to do, and we'll help you implement it in Perl if you have trouble.

Sounds like you didn't do any thinking or research at all.

Replies are listed 'Best First'.
Re^4: USB interface
by Anonymous Monk on Jun 15, 2009 at 05:20 UTC

    I'm on linux. What I felt is, when the user plugs in USB device, I think it will be automatically mounted somewhere right?

    If so, I will watch that and I'll execute my script to ask password

      I think it will be automatically mounted somewhere right?

      You tell me.

      If so, I will watch that and I'll execute my script to ask password

      How will that prevent users from placing and removing files on the device?

      On my Windows box, I can detect the insertion of a USB stick within 2 seconds of it happening with this one liner:
      perl -le "while(1) {print \"USB stick inserted\" if -d 'E:/';sleep 2}"
      I guess something similar can be applied to linux.

      Cheers,
      Rob

        Why use polling when the WMI tells you? The synopsis of DBD::WMI shows an example that detects when a drive gets added/removed. Alternatively, I think I would hook into the dialog that asks "What to do with this device?" whenever a new device is added. But this is all Windows and the question seems to be for Linux...

        I don't think that's sufficient. You'd have to check more than one drive letter, and I think you're able to mount a USB drive without assigning a letter to it. (I'm not at my Windows system to test it.)
      I'm on linux. What I felt is, when the user plugs in USB device, I think it will be automatically mounted somewhere right?
      Not on any of my Linux boxes. But it's certainly possible to setup a Linux box that it's done this way.
      If so, I will watch that and I'll execute my script to ask password
      If it's automatically mounted, what's to stop the user from copying the file directly using cp instead of firing up your program and having to type in a password?

      I think you should first have a talk with the sysadmin(s) in charge of the boxes this is going to be run on; find out how the boxes are setup; and figure out together how to get your program working. The copying and asking for a password are trivial. Making sure your program is the only way to copy files to a USB device is that hard part, and has nothing to do with Perl (you'd have to solve the same problem if your user interface was written in Python, Java or COBOL).

      you could change the rights of the users in order to not allow then write directly to the drive, then have an new group which can write to the drive and make your program run sudo on this group, then it will be able to write to the drive.