Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void print_perms(const struct stat *sb){
- /*printf("Mode: %lo (octal)\n", (unsigned long) sb->st_mode % 01000);*/
- char* username = getlogin();
- struct passwd* pass = getpwnam(username);
- gid_t gid = pass->pw_gid;
- uid_t uid = pass->pw_uid;
- uid_t owner = sb->st_uid;
- gid_t group_own = sb->st_uid;
- printf("Your permisions: \n");
- if(uid==owner) {
- printf("read: ");
- printf( (sb->st_mode & S_IRUSR) ? "yes" : "no");
- printf("\n");
- printf("write: ");
- printf( (sb->st_mode & S_IWUSR) ? "yes" : "no");
- printf("\n");
- printf("execution: ");
- printf( (sb->st_mode & S_IXUSR) ? "yes" : "no");
- printf("\n");
- } else if(gid==group_own) {
- printf("read: ");
- printf( (sb->st_mode & S_IRGRP) ? "yes" : "no");
- printf("\n");
- printf("write: ");
- printf( (sb->st_mode & S_IWGRP) ? "yes" : "no");
- printf("\n");
- printf("execution: ");
- printf( (sb->st_mode & S_IXGRP) ? "yes" : "no");
- printf("\n");
- } else {
- printf("read: ");
- printf( (sb->st_mode & S_IROTH) ? "yes" : "no");
- printf("\n");
- printf("write: ");
- printf( (sb->st_mode & S_IWOTH) ? "yes" : "no");
- printf("\n");
- printf("execution: ");
- printf( (sb->st_mode & S_IXOTH) ? "yes" : "no");
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement