I'm running this program in root and I have the following result with the command id mike
:
uid=1001(mike) gid=1002(mike) groups=1002(mike),1005(mynewgroup)
I'm using the following code to get the groups:
setgid(1002)
setuid(1001)
if ((count = getgroups(NGROUPS_MAX, groupIDs)) == -1)
perror("getgroups error");
else
for (i = 0; i < count; i++)
printf("Group ID %d = %d\n", i + 1, (int) groupIDs[i]);
The result I need is to list group 1002 and 1005. its just giving me
Group ID 1 = 1002
How do I get all the groups of a user with getgroups
?