使用C在Linux中获取用户组的正确方法 [英] Proper way to get groups of a user in linux using C

查看:235
本文介绍了使用C在Linux中获取用户组的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道unix命令组是否有任何备用C库,

I want to know if there is any alternate C library for the unix command groups,

$ groups ---- lists all the group id's of the user.

$ groups ---- lists all the group id's of the user.

有一个名为getgroups()的方法,但此方法将返回用户组.有没有一种方法可以使用C为特定用户获取组.

There is a method called getgroups() but it returns the groups of the user this method. Is there a way to get groups for a particular user using C.

推荐答案

#include "<grp.h>"
int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);

这篇关于使用C在Linux中获取用户组的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆