Answer the question
In order to leave comments, you need to log in
How to protect a file from editing?
Hello.
There is a program that works with some text files. How to protect these files from editing except by this very program?
Language: C++
Thank you!
Answer the question
In order to leave comments, you need to log in
Nothing will protect the file from editing. Even if you make a service that will capture a file exclusively at system startup, then nothing will stop you from shutting down the computer, pulling out the screws and connecting it to another computer. Not to mention that processes can be killed if desired.
If you want protection, make a client-server application with user authorization.
In different operating systems there are, of course, protected storages, but this, again, will not protect against screw reattachment.
On Windows, you can look here msdn.microsoft.com/en-us/library/windows/desktop/a... flag OF_SHARE_EXCLUSIVE or here msdn.microsoft.com/en-us/library/windows/desktop/a... read about dwShareMode.
UPDATE: this only works while the file is open, after you close the file it can be edited again.
On Unixes, there are probably no easy options besides File Locking, but it only prevents access by applications that also use File Locking.
Depending on what OS.
If Linux - create a separate user for the program and chmod / chown.
If Windows - you need to write a driver. (maybe there is something on google)
On Linux, setting an attribute on a file is enough. chattr +i file
This will prevent even the root user from changing it. There are also extended attributes. Read more in man chattr, lsattr
Maybe just sign the contents of the file? It will remain text, but the last line, for example, the content hash, the algorithm of which is buried in the program. In terms of reliability, it is comparable to encryption, but the file remains text.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question