Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. static void print_perms(const struct stat *sb){
  2. /*printf("Mode: %lo (octal)\n", (unsigned long) sb->st_mode % 01000);*/
  3. char* username = getlogin();
  4. struct passwd* pass = getpwnam(username);
  5. gid_t gid = pass->pw_gid;
  6. uid_t uid = pass->pw_uid;
  7. uid_t owner = sb->st_uid;
  8. gid_t group_own = sb->st_uid;
  9. printf("Your permisions: \n");
  10. if(uid==owner) {
  11. printf("read: ");
  12. printf( (sb->st_mode & S_IRUSR) ? "yes" : "no");
  13. printf("\n");
  14. printf("write: ");
  15. printf( (sb->st_mode & S_IWUSR) ? "yes" : "no");
  16. printf("\n");
  17. printf("execution: ");
  18. printf( (sb->st_mode & S_IXUSR) ? "yes" : "no");
  19. printf("\n");
  20. } else if(gid==group_own) {
  21. printf("read: ");
  22. printf( (sb->st_mode & S_IRGRP) ? "yes" : "no");
  23. printf("\n");
  24. printf("write: ");
  25. printf( (sb->st_mode & S_IWGRP) ? "yes" : "no");
  26. printf("\n");
  27. printf("execution: ");
  28. printf( (sb->st_mode & S_IXGRP) ? "yes" : "no");
  29. printf("\n");
  30. } else {
  31. printf("read: ");
  32. printf( (sb->st_mode & S_IROTH) ? "yes" : "no");
  33. printf("\n");
  34. printf("write: ");
  35. printf( (sb->st_mode & S_IWOTH) ? "yes" : "no");
  36. printf("\n");
  37. printf("execution: ");
  38. printf( (sb->st_mode & S_IXOTH) ? "yes" : "no");
  39. printf("\n");
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement