January 8th, 2017, 11:08 AM
How to implement password access to specific file type in Linux/Windows programmatica
Linux and Windows question.
1. I do not want user to launch all ".doc" files (including those he brings in).
2. User tries to launch a file "test.doc".
3. The password window appears.
4. If the password is correct, the file is opened.
I read this guide:
3 Ways to Create a Password Protected File on Windows 7 - wikiHow
The problem is that I want to do it by mask, not just a few known files.
January 8th, 2017, 11:26 AM
You can't. Not without designing something that is essentially, if not literally, a virus.
January 8th, 2017, 11:44 AM
I want a virus then. Please help.
Originally Posted by requinix
January 8th, 2017, 07:41 PM
January 9th, 2017, 04:23 AM
If you wanted to password protect a single file then I would strongly suggest GPG (GNU's implementation of PGP) instead of using any homegrown encryption method. But what you're asking here is to impede the user from launching a whole class of files which is, as @requinix said, clearly a virus.
Originally Posted by Kosarar
Moreover there's no foolproof way to do this, you could override the default file-manager but you can't really prevent the user from accessing a certain class of files and there are file-permissions and ownership caveats in Linux (or any Unix for that matter), so it isn't realistically possible. You could remove executable permissions from a specific class of files (in your case all *.doc files) but you can't really prevent access this way because in Unix file-extensions are for users only, programs use magic-numbers and predetermined MIME-types. If you really want to prevent access to your files then just use encryption policies such as PGP.
In *nix, a simple way to prevent other users from accessing a directory that you've ownership to is to change the file permissions using chmod (see man chmod for details), you can use ls -l to view the file-permissions for a specific directory. I believe this can also be done using AppArmor or SELinux but you would have to find out for yourself.
Bottom line -- don't create a virus to protect your personal files, instead use secure encryption policies (especially those that are asymmetric) and/or file-permissions (applicable for Unixes such as Linux or OS X only).