macOS上的getgroups()不会返回所有补充组,而是只返回主组
“id”命令确实为我提供了所有补充组,但以下代码只是返回该用法所属的主要组:macOS上的getgroups()不会返回所有补充组,而是只返回主组,c,macos,darwin,usergroups,C,Macos,Darwin,Usergroups,“id”命令确实为我提供了所有补充组,但以下代码只是返回该用法所属的主要组: gid_size = getgroups(0, NULL); //1 is getting returned here grouplist = malloc(gid_size * sizeof(gid_t)); getgroups(gid_size, grouplist); //Even with gid_size>1, only primary groups is returned. 我的问题是,是否有其他替
gid_size = getgroups(0, NULL); //1 is getting returned here
grouplist = malloc(gid_size * sizeof(gid_t));
getgroups(gid_size, grouplist); //Even with gid_size>1, only primary groups is returned.
我的问题是,是否有其他替代方法来获取macOS上的所有补充组。通过首先调用
initgroups()
,您应该能够获取多达16个以上的组,但即使这样也不理想
从:
进程不应使用getgroups(2)
中的组ID号来确定用户的组成员身份。从getgroups()
获得的列表只能是用户组成员资格的部分列表。成员资格检查应使用mbr\u gid\u至uuid(3)
、mbr\u uid\u至uuid(3)
和mbr\u检查成员资格(3)
功能
因此,如果您试图检查用户是否是特定组的成员,则可以使用mbr_*()
函数
请注意,基于非常快速的检查,它似乎使用了未记录的getgrouplist_2()
这是函数的一个变体,但没有16组限制
我不认为这个函数是在任何公共头中声明的,id.c
使用原型
int32_t getgrouplist_2(const char *, gid_t, gid_t **);