If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Create read-only file using c++

Hi,
I want to create a log file that captures all the actions happening...anyway i got code for that from internet.
Now what i want to do is, make that file read only so that the data is not modified by external application or user.

Re: Create read-only file using c++

Originally Posted by neoraghav

dude.....i want to achieve this using code man.......give me good suggestion

We don't really know what your requirements are and from your OP it seems you're just starting out. It's not a simple topic and you may be getting in over your head. Probably the simplest encryption is just to XOR a bit pattern over your data. There are various checksum algorithms you can use to help ensure the data hasn't been modified by someone other than you. You'll need to decide what your program does if the user deletes your file, or replaces it with an earlier version. Making it really secure won't be easy.

Re: Create read-only file using c++

Originally Posted by GCDEF

We don't really know what your requirements are and from your OP it seems you're just starting out. It's not a simple topic and you may be getting in over your head. Probably the simplest encryption is just to XOR a bit pattern over your data. There are various checksum algorithms you can use to help ensure the data hasn't been modified by someone other than you. You'll need to decide what your program does if the user deletes your file, or replaces it with an earlier version. Making it really secure won't be easy.

Re: Create read-only file using c++

The problem is that anything your program can do, another program can also do... if it's run by the same user with the same permissions. Simply put: if the person has control over the machine, it's their machine. They get to do what they want with it.

So the solution is to limit access to your program to machines you control, and only give the user limited access to those machines. Basically you create a user account with limited privileges that cannot edit anything outside of their directory. You then let them use your program, and if they wanted to edit the log file they would then have to give an admin password, which they would not have.

If you have to make it so that they cannot edit their logfiles on *their* machines when they have full access, then things get a lot harder. As someone suggested, I guess you can try encryption or something, but this probably isn't a very good solution. I guess it comes down to why you can't let them edit the log files.

Re: Create read-only file using c++

The problem is that anything your program can do, another program can also do... if it's run by the same user with the same permissions. Simply put: if the person has control over the machine, it's their machine. They get to do what they want with it.

So the solution is to limit access to your program to machines you control, and only give the user limited access to those machines. Basically you create a user account with limited privileges that cannot edit anything outside of their directory. You then let them use your program, and if they wanted to edit the log file they would then have to give an admin password, which they would not have.

If you have to make it so that they cannot edit their logfiles on *their* machines when they have full access, then things get a lot harder. As someone suggested, I guess you can try encryption or something, but this probably isn't a very good solution. I guess it comes down to why you can't let them edit the log files.

Personally, my advice would probably be to just let them.

yes...you're right
i tried with some options and they didnt work well...
but this "read only " thing is part of my case study where i have to capture all the actions using a log file and make that log file read only. i know that its lot complex and since i'm a newbie i'm not getting many things mentioned by some guys in other forums......