【发布时间】:2019-04-20 02:06:18
【问题描述】:
我在 Internet 上进行了一些搜索,但没有找到一种以编程方式确定给定文件是否已打开完整性检测的好方法。
我注意到,与我遇到的大多数 linux 头文件不同,Darwin 没有在 /sys/stat.h 中定义的 stat 结构中定义它们的 st_mode 位。似乎实现这一点的最佳方法是处理现有的 sys/stat.h 标头,但是,很明显为什么他们不想公开它。有没有人对此进行过更多研究?
编辑
根据 Ken Thomases 的建议,我的 if 检查看起来像这样。查看源代码中的 cmets 似乎这应该可以工作,但是它仍在尝试输入目录,例如:
"/Users/
if(
(entry->d_type == DT_DIR)
&& ((fileStat.st_flags & SF_RESTRICTED) == 0)
&& (((fileStat.st_mode & 5) == 5)
|| (((fileStat.st_mode & 40) == 40)
&& (fileStat.st_gid == userHomeStat.st_uid))
|| (((fileStat.st_mode & 320) == 320)
&& (fileStat.st_uid == userHomeStat.st_uid))))
{
std::cout<< "Decending into --> " << fullPath.c_str() <<std::endl;
packIndexFrom((fullPath).c_str());
}
编辑
https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/FileSystemProtections/FileSystemProtections.html#//apple_ref/doc/uid/TP40016462-CH2-SW1
我在 Apple 的网站上找到了这个。这似乎表明我挂断的 $HOME/Library 区域受到某种类型的限制,对开发人员具有专有的 r/w 访问权限。 不幸的是没有解决我的问题。
编辑
Dans-MBP:tmp mreff555$ cd ~/Library/IdentityServices/
Dans-MBP:IdentityServices mreff555$ pwd
/Users/mreff555/Library/IdentityServices
Dans-MBP:IdentityServices mreff555$ ls
ls: .: Operation not permitted
Dans-MBP:IdentityServices mreff555$
Dans-MBP:IdentityServices mreff555$ ls -ldO ~/Library/IdentityServices
drwxr-xr-x 9 mreff555 staff - 288 Apr 14 10:04 /Users/mreff555/Library/IdentityServices
【问题讨论】:
-
SF_RESTRICTED将在st_flags,而不是st_mode。我的回答很清楚。 -
仍然遇到相同文件的问题。
-
是什么让您认为 /Users/
/Library/IdentityServices 受 SIP 保护?这不适合我。基本上,用户目录中没有任何内容。 SIP 保护系统文件。您可以使用 ls -ldO <path>进行检查。它会在标志列中显示“受限”(在组和大小之间)。 -
我的“ls”版本无法识别该参数。我在 Apple 开发人员网站上发现了一篇文章,指出 $HOME/Library 目录遵循某种类型的特殊情况限制模式。仅限开发人员。然而细节相当模糊。将其附加到我的帖子中。
-
我相信是 TCC,而不是 SIP,阻止了对 ~/Library/IdentityServices 的访问。