fabian789
fabian789

Reputation: 8412

Prevent multiple copies of a file on OS X

I have a file somewhere on the hard drive and I would like to make sure it is only accessed by a particular program and not

Is it possible to do this programmatically in Objective-C or C?

Upvotes: 1

Views: 85

Answers (2)

Freedom_Ben
Freedom_Ben

Reputation: 11933

It is impossible to make sure with absolute certainty that only a particular program can access a local file on a user's computer. This is because all possible methods can be bypassed if the user is savvy enough.

A common (though complicated) way of doing this is by encrypting the file with a key that is provided by a web server. In order to acquire the key and unlock the file, the program will have to contact the web server, authenticate, and then use the key to decrypt the file. If you change the keys often and tie them to the user, it will be difficult for an attacker to bypass this. The attack would include dumping the process memory while the file is in memory unencrypted, and then accessing it that way. This tough, but doable. This method stops all but the most sophisticated attackers. Many PDF and other document DRM is implemented this way (Amazon assigns a key to each device and install, but otherwise is same idea).

Upvotes: 2

vcsjones
vcsjones

Reputation: 141618

As far as I know, using CSBackupSetItemExcluded should be enough - you'll need to link against the CoreServices framework to access this. This takes care of Time Machine and Versions. I'm not aware of any other cases where the system will automatically copy the file unless explicitly done by the user.

Upvotes: 2

Related Questions