Mac 系统完整性保护是否在 sys/stat.h 中定义

Is Mac System Integrity Protection defined within the sys/stat.h

我在 Internet 上进行了一些搜索,但没有找到以编程方式确定给定文件是否已打开完整性检测的好方法。

我注意到,与大多数 linux headers 我有 运行 不同,Darwin 没有在定义的 stat 结构中定义它们的 st_mode 位 /sys/stat.h.似乎实现这一点的最佳方法是解决现有的 sys/stat.h header 然而,很明显他们不想公开它的原因。有人对此进行了更多调查吗?

编辑

根据 Ken Thomases 的建议,我的 if 检查看起来像这样。查看源代码中的注释似乎应该可以工作,但是它仍在尝试输入目录,例如: “/用户/<用户>/Library/IdentityServices” 导致分段错误。仅供参考,我已经使用和不使用预处理器 IFDEF 语句对其进行了测试。

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

有些标志与模式标志是分开的。您正在 struct statst_flags 字段中查找 SF_RESTRICTED 标志。事实上,该标志在 sys/stat.h.

中定义

模式标志(例如S_IRUSR)在sys/_types/_s_ifmt.h中定义,它间接包含在sys/stat.h.