Completely restricting all types of access to a folder

流过昼夜 提交于 2020-01-05 04:37:05

问题


I am making a cocoa application, which creates some folders at my specified location in the user's environment. Now i want to protect these folders from any type of read, write, copy, drag access from all type of users(i.e Not accessible for admin and non-admin users).Is there a way to protect these folders from any type of access. Can we use, NSFileManager method -setAttributes:OfItemAtPath:error: But i am not sure on attributes dictionary of this method.

Basically i want to provide trail of some files to the user (let's say 1 day trial), and removing those files as soon as the trail expires, and all those files are placed inside a certain folder in the user's environment. What should be the best approach i should use to protect those files?


回答1:


You could use NSFileManager setAttributes:OfItemAtPath:error: with the attributes key NSFilePosixPermissions. With this, you can set the Unix file permissions of your folder by specifying them with an integer value that represents the permission bit pattern. Setting it to zero would mean no access at all to that directory:

NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys:
    NSFilePosixPermissions, [NSNumber numberWithInt:0], nil];

However, it would still be possible to move or rename that directory.




回答2:


Short answer: No. Someone with elevated privileges can do just about anything. No playing with permissions will get you there and still allow your application to access the files.

If you could just turn off all access rights how would you expect your own application to access the files? Turning on the access rights is itself an access right...

Longer answer: Maybe. This depends on what you are trying to achieve. Do you really want to stop the files being copied, or just their contents accessed?

Encryption can be used to protect content (e.g. at the file level, using an encrypted sparsebundle image, etc.), storing identification information in a file can alert you that you’re using a copy (e.g. see what happens if you move/copy a VMWare virtual machine or recreate a Google Drive folder), etc.

And you can always implement your own filesystem using FUSE; and prevent copying, access, etc. by your own mechanism, however the filesystem as a whole could still be copied (i.e. effectively implement your own equivalent of an encrypted sparsebundle via FUSE and implement your own access mechanism).

What are you trying to achieve? If you spell that out folk might be able to suggest alternative solutions.

See also this question on preventing root from writing to files.



来源:https://stackoverflow.com/questions/28008635/completely-restricting-all-types-of-access-to-a-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!