Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
macOS上的getgroups()不会返回所有补充组,而是只返回主组_C_Macos_Darwin_Usergroups - Fatal编程技术网

macOS上的getgroups()不会返回所有补充组,而是只返回主组

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. 我的问题是,是否有其他替

“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.

我的问题是,是否有其他替代方法来获取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 **);