in reply to Re: USB interface
in thread USB interface

I think I've miscommunicated. Here is my requirement

When the user plugs-in the USB device, my program has to ask for password from the user. Once authentication is right, the user will be prompted to enter the file name, that he needs to transfer from system to USB.

The primary purpose is that, the user should not use any other method to copy the files other than this interface, and the files copied by using this interface will be reported to the administrator. This interface is mainly used to log the files that are transfered.

Please suggest how can I do this?

Replies are listed 'Best First'.
Re^3: USB interface
by ikegami (Patriarch) on Jun 15, 2009 at 05:16 UTC

    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.

      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
        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.
Re^3: USB interface
by GrandFather (Saint) on Jun 15, 2009 at 05:07 UTC

    If the OS doesn't provide an 'out of the box' way to manage user permissions for that sort of access then you have a great deal of work ahead of you! On Windows most likely you would need to write your own filter driver and insert it into the driver stack for USB mass storage devices, but that would be more work than you want to think about and is not something you can do in Perl. I've no idea what is required in a *nix context, but I suspect Perl won't get you there in that context either.


    True laziness is hard work