Can a sandboxed app sold on the Mac App Store access system folders?

北城余情 提交于 2019-12-07 02:49:22

问题


Is it possible for an app sold thru the Mac App Store to access system folders?

I mean this: my app needs to read the contents of directories that are outside the sandbox area, lets say something like /Library/StartupItems and possibly delete a file there if the user wants.

Is it possible for a sandboxed app to access system folders and delete files there? If it cannot delete, can it at least read?

Do I have to enable sandbox if I want to sell on the Mac App Store?

I have tried a directory at random doing this:

  NSString *path = @"/Library/StartupItems";
  NSArray *dirFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];

and I can get the directory listing. How can I be reading that if the app is marked as sandboxed? I don't get it.


回答1:


No, OS X Applications sold through the Mac App Store cannot access resources in the way you've described. It's also required that all apps are sandboxed and codesigned with a valid Mac Developer Program Certificate.

As for being able to read /Library/StartupItems (which is deprecated) when your app is marked as "sandboxed"; it's not just a matter of having the option checked. You also have to ensure “Use Entitlements file” is selected and the application is properly codesigned. Once you've done that you can check to verify it's properly sandboxed in Terminal by using:

codesign -dvvv --entitlements :- Some.app/Contents/MacOS/Executable

In addition, there are certain directories where files that are "world readable" can be read:

/bin
/sbin
/usr/bin
/usr/lib
/usr/sbin
/usr/share
/System

In order to allow an OS X application to interact with the file system like your (earlier) example the application would need to use elevated privileges typically using Authorization Services — which App Sandbox disallows. Take a look at the section titled "Determine Whether Your App Is Suitable for Sandboxing", and it should answer any other concerns you might have.

Sandboxing is good in a lot of ways, but also very restrictive at the same time. If your app needs to do things that are not within the scope of what is allowable you can choose to not sell through the Mac App Store and not use Sandboxing. Some developers also create two different versions of their app (Mac App Store version and non-Mac App Store). If your app relies on going outside it's container for much of anything you'll definitely want to consider/weigh the pros and cons of Sandboxing.

  • App Sandbox Guide
  • File System Programming Guide
  • Authorization Services C Reference


来源:https://stackoverflow.com/questions/24594899/can-a-sandboxed-app-sold-on-the-mac-app-store-access-system-folders

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