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

问题描述 投票:3回答:1

我已经在互联网上做了一些狩猎,并没有找到一种以编程方式确定给定文件是否已启用完整性检测的好方法。

我注意到,与我遇到的大多数linux头文件不同,Darwin没有在/sys/stat.h中定义的stat结构中定义它们的st_mode位。似乎实现这一点的最好方法是解决现有的sys / stat.h头文件,但很明显,为什么他们不想对它开放。还有人调查过这个吗?

编辑

Ken Thomases的基础建议我,如果支票看起来像这样。查看源代码中的注释,看起来好像这应该有效,但它仍然在尝试输入目录,例如:“/ Users / <USER> / 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
c linux macos darwin
1个回答
3
投票

有些标志与模式标志分开。你正在寻找SF_RESTRICTEDst_flags油田的struct stat旗帜。事实上,该标志在sys / stat.h中定义。

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

© www.soinside.com 2019 - 2024. All rights reserved.