Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. else {
  2. uid_t id= getuid();
  3. gid_t gid = getgid();
  4. struct passwd* user = getpwuid(id);
  5. string name = user -> pw_name;
  6. struct group* groups = getgrgid(gid);
  7. string name_1 = groups -> gr_name;
  8. if (strcmp(argv[1], "-u") == 0)
  9. cout << id;
  10. if (strcmp(argv[1], "-g") == 0)
  11. cout << groups -> gr_name;
  12. if (strcmp(argv[1], "-G") == 0)
  13. do{
  14. gid = groups -> gr_gid;
  15. for (int i = 0; *(groups->gr_mem) != 0; i++, (groups -> gr_mem)++)
  16. if (strcmp(*(groups->gr_mem), user->pw_name) == 0)
  17. cout << gid << " ";
  18.  
  19. groups = getgrent();
  20. } while (groups != NULL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement