#include "../command.h" #include #include COMMAND_EMPTY(user_id) { uid_t uid = getuid(); gid_t gid = getgid(); struct passwd* pw = getpwuid(uid); if(pw == NULL){ perror("error: failed to fetch groups: "); } int ngroups = 0; getgrouplist(pw->pw_name, pw->pw_gid, NULL, &ngroups); gid_t groups[ngroups]; getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); struct group* ugr = getgrgid(gid); printf("uid=%d(%s) gid=%d(%s) ", uid, ugr->gr_name, gid, ugr->gr_name); if (ngroups > 0) { printf("groups="); } for (int i = 0; i < ngroups; i++){ struct group* gr = getgrgid(groups[i]); if(gr == NULL){ perror("error: failed to fetch groups: "); } printf("%d(%s)", gr->gr_gid, gr->gr_name); if (i + 1 < ngroups) putchar(','); } printf("\b\n"); return EXIT_SUCCESS; }