A
A
AF2014-06-17 10:18:27
Programming
AF, 2014-06-17 10:18:27

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

7 answer(s)
A
Alexander, 2014-06-17
@TiPo

Encrypt

A
AxisPod, 2014-06-17
@AxisPod

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.

V
v_prom, 2014-06-17
@v_prom

Open file exclusively or set write permissions.

M
Misha Krinkin, 2014-06-17
@kmu1990

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.

F
FritzSchnapsmann, 2014-06-20
@FritzSchnapsmann

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)

S
Semyon Voronov, 2014-06-20
@Gineaser

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

A
Alexey Akulovich, 2014-06-26
@AterCattus

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 question

Ask a Question

731 491 924 answers to any question