Click here to Skip to main content
15,885,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
For security reasons I want to know if a file "xyz.txt" has been only modified by MySecureFileWrite.exe( an example ) or some other process.

Is there a way to achieve this task in C?
Posted
Comments
Sergey Alexandrovich Kryukov 14-Aug-12 14:51pm    
What do you mean "has written"?
--SA
[no name] 14-Aug-12 14:52pm    
I mean either an read/write/update. Wrong key word in the subject again :(

Please see my comment to the question. What I mean is: if a file is written and already closed, it's too late. You cannot learn which process did it.

[EDIT]

Answering to the follow-up discussion:

In principle, you can protect your file by opening it in your application and keeping the file handle opened during the life time of your application. You need to open a file for exclusive use, which happens by default. If you need to keep the file untouched at all times, you can develop and install a daemon which runs at all times and keeps the file(s) open and hence blocking. Your application(s) should manipulate the content of the file(s) through this daemon only.

This is almost never needed though. You should better review the scenario when such clash could harm, or probably review your architecture.

—SA
 
Share this answer
 
v2
Comments
[no name] 14-Aug-12 14:56pm    
Only my process knows how to write into xyz.txt file in a best way. But if some other process has already written into xyz.txt file, how do i know if my xyz.txt file is corrupted or not. Just trying to figure out the best way to know to protect a file even from reading or writing from other processes
Sergey Alexandrovich Kryukov 14-Aug-12 15:24pm    
If depends on your data model, file structure, etc. And this is not what you asked about. Why do you think you need to protect your file?
--SA
Sergey Alexandrovich Kryukov 14-Aug-12 15:29pm    
Anyway, please see my update, after [EDIT].
--SA
[no name] 14-Aug-12 15:32pm    
All I was trying to figure out was how to write a FileSystem on my own with the best protection mode I can give it with out actually creating a copy of the filesystem each time I write into it. This way if some other process tries to write into my filesystem and corrupt the data I dont have to restore the copy back to its original. But I don't want to do this either. Why not I prevent the other processes even accessing it? Just trying to figure out this!!!!
nv3 14-Aug-12 15:53pm    
Your thought are actually going along the right lines -- sometimes. But I believe that you are not making good use of your time as you are trying to re-invent data processing from the ground up. Many of the posts you have written over the last days show that you have not gained some of the most fundamental basics and you are trying to gain knowledge by undertaking singular experiments and asking questions. You could however proceed much faster on your way by mastering things one after the other and read a couple of books. Learn a programming language, learn the basics of an operating system, learn about databases, learn about GUI environments ... just one step at a time. Remain as hungry for new knowledge as you are and at the same time try to organize your learning experience more effectively.

Just a well meant advice.

What are trying to ask in this question will not get you much further. For one, even if you knew which other process had altered your file, you could not undo the change. So either protect your file by the operating system's security measure against undesired tempering and/or write some code that checks the consistency of your file, each time your process opens it.
Your process could stamp its encrypted modification time of the file xyz.txt
into an additional trace file xyz.trc , for example :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Aug-12 15:45pm    
And..?
--SA
Eugen Podsypalnikov 14-Aug-12 16:16pm    
// But if some other process has already written into xyz.txt file,
// how do i know if my xyz.txt file is corrupted or not.
I think, the traced time could answer this question :)
Sergey Alexandrovich Kryukov 14-Aug-12 17:06pm    
Any process can fake file time stamps is any way. Not clear why such protection would really be needed.
--SA
Albert Holguin 14-Aug-12 20:24pm    
This would probably tell you if someone else has edited the file... wouldn't tell you who (which is what was asked, by reading the title).
Eugen Podsypalnikov 15-Aug-12 3:27am    
Yes, that is right :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900