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

时间:2019-04-20 02:06:19

标签: c linux macos darwin

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

我注意到,与我遇到的大多数Linux标头不同,达尔文没有在/sys/stat.h中定义的stat结构中定义其st_mode位。看来,实现此目标的最佳方法是处理现有的sys / stat.h标头,但是,很明显为什么他们不愿意对此公开。有没有人进一步研究?

编辑

基于Ken Thomases的建议,我的支票看起来像这样。查看源代码中的注释似乎看起来应该可以,但是它仍在尝试输入目录,例如: “ /用户/ / 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

1 个答案:

答案 0 :(得分:3)

有些标志与模式标志分开。您正在Up的{​​{1}}字段中寻找SF_RESTRICTED标志。实际上,该标志是在sys / stat.h中定义的。

模式标志(例如st_flags)在sys / _types / _s_ifmt.h中定义,该文件间接包含在sys / stat.h中。