Proper way to get groups of a user in linux using C

Adi GuN picture Adi GuN · Feb 28, 2014 · Viewed 9.5k times · Source

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.

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.

Answer

Asblarf picture Asblarf · Feb 28, 2014
#include "<grp.h>"
int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);