2020-08-08 19:38:00 +00:00
|
|
|
#include <grp.h>
|
2021-06-29 11:19:44 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
2020-08-08 19:38:00 +00:00
|
|
|
#include <stdlib.h>
|
2021-06-29 11:19:44 +00:00
|
|
|
#include <unistd.h>
|
2020-08-08 19:38:00 +00:00
|
|
|
|
|
|
|
int
|
2021-06-29 11:19:44 +00:00
|
|
|
main(int argc, char* argv[])
|
2020-08-08 19:38:00 +00:00
|
|
|
{
|
2021-06-29 11:19:44 +00:00
|
|
|
struct passwd* pwd;
|
|
|
|
if (argc == 2)
|
|
|
|
pwd = getpwnam(argv[1]);
|
|
|
|
else
|
|
|
|
pwd = getpwuid(getuid());
|
|
|
|
|
|
|
|
int ngroups = 10;
|
|
|
|
uid_t* groups = malloc(ngroups);
|
|
|
|
getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ngroups);
|
|
|
|
struct group* gr;
|
|
|
|
for (int i = 0; i < ngroups; i++) {
|
|
|
|
gr = getgrgid(groups[i]);
|
|
|
|
printf("%s ", gr->gr_name);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return 0;
|
2020-08-08 19:38:00 +00:00
|
|
|
}
|