Does anybody know whether there's a way of finding out whether a particular file system location is accessible under the sandbox?
I want to test whether a particular file is accessible under the normal Powerbox rules; that is has already been added to the power box using the open/ save dialog, etc.
Can I do this before triggering a sandbox exception?
Can I catch a sandbox exception?
Best regards,
Frank
The App Sandbox is Apple's access control technology that application developers must adopt to distribute their apps through the Mac App Store.
Android sandbox This kernel ensures security between apps and the system at the process level. Moreover, because the sandbox is in the kernel, its security model extends to native code and OS applications, and all software above the kernel, including OS libraries, application runtime and application framework.
A few things. Always use fileSystemRepresentation when you need a path string. Also, R_OK is adequate if you just want to know if there is a hole in the sandbox for the specified path.
-(BOOL)isAccessibleFromSandbox:(NSString*)path
{
return( access( path.fileSystemRepresentation, R_OK) == 0 );
}
You can use the OS access()
system call for a quick and simple test, from man access
:
#include <unistd.h>
int access(const char *path, int amode);
The access() function checks the accessibility of the file named by path for the access permissions indicated by amode. The value of amode is the bitwise inclusive OR of the access permissions to be checked (R_OK for read permission, W_OK for write permission and X_OK for execute/search permission) or the existence test, F_OK. All components of the pathname path are checked for access permissions (including F_OK).
If path cannot be found or if any of the desired access modes would not be granted, then a -1 value is returned and the global integer variable errno is set to indicate the error. Otherwise, a 0 value is returned.
You could pretty this up for Objective-C using something like:
typedef enum
{
ReadAccess = R_OK,
WriteAccess = W_OK,
ExecuteAccess = X_OK,
PathExists = F_OK
} AccessKind;
BOOL isPathAccessible(NSString *path, AccessKind mode)
{
return access([path UTF8String], mode) == 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With