不允许iOS opendir(“库”)操作
目录的权限如下所示:不允许iOS opendir(“库”)操作,ios,posix-api,Ios,Posix Api,目录的权限如下所示: /Applications d rwxrwxr-x root admin /Library d rwxrwxr-x root admin /private d rwxr-xr-x root wheel opendir(“/Applications”) opendir(“/Library”)不允许操作 opendir(“/private”)不允许操作 运行时环境: iOS设备7.7/9.2+xcode 7.2 调试消息使用print()在控制台中打印 但
/Applications d rwxrwxr-x root admin
/Library d rwxrwxr-x root admin
/private d rwxr-xr-x root wheel
opendir(“/Applications”)
opendir(“/Library”)
不允许操作
opendir(“/private”)
不允许操作
运行时环境:
iOS设备7.7/9.2+xcode 7.2
调试消息使用print()
在控制台中打印
但当使用iOS模拟器而不是iOS设备时,它工作得很好
我尝试获取线程的用户和组,通过使用getpwuid(getuid())
和getgrgid(getgid())
,它告诉我们mobile和mobile的结果
问题是:
1.使用iOS设备时,使用相同的权限、相同的用户和相同的组,为什么“/Applications”可以正常工作而“/Library”可以使用不允许的操作???
2.当使用iOS模拟器而不是iOS设备时,可以使用opendir()打开这三个目录
谢谢你的好意 iOS沙盒限制了您的阅读空间。沙盒没有在模拟器上强制实施。感谢您的帮助,正如您提到的snadbox,您的意思是opendir()
不是posix api,而是最像iOS系统本身的函数实现,如果有snadbox,就没有办法在iOS平台上正确使用posix api?您可以使用opendir()在iOS上,但必须确保尝试读取的路径位于应用程序的沙箱中-请参阅NSSearchPathForDirectoriesInDomains
void RootPremission::getDirFiles (const char* path, int deep) { // outside call this function with parameter "/" and 0
struct stat statBuf;
if (lstat(path, &statBuf) == 0) {
printf("%s\n", setFileInfo(&statBuf));
if (S_ISDIR(statBuf.st_mode)) { // go deep dir
DIR *dp = NULL;
if ((dp = opendir(path)) != NULL) {
struct dirent *dirp = NULL;
while ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0 || *dirp->d_name == '.') {
continue; // ignore . and .. and hiden file
}
for (int i=0; i!=deep; ++i) {
printf(" ");
}
printf("|- %s ", dirp->d_name);
char *fullPath = strcatPath(path, dirp->d_name);
getDirFiles (fullPath, deep+1);
free(fullPath);
fullPath = NULL;
}
closedir(dp);
}
else {
printf("#");
perror(path);
}
}
else { // try to open file
if (S_ISREG(statBuf.st_mode)) {
FILE *file = fopen(path, "r");
if (file != NULL) {
if (fclose(file) == EOF) {
perror(path);
}
}
else {
printf("+");
perror(path);
}
}
}
}
else {
printf("$");
perror(path);
}
}