Davinel

catalog_check_permission

Dec 2nd, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <dirent.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7.  
  8. int main(int argc, char const *argv[])
  9.  
  10. {
  11.     char directory[PATH_MAX];
  12.     char path[PATH_MAX];
  13.     DIR *dir;
  14.     struct dirent *ent;
  15.     struct stat buffer;
  16.     int status;
  17.     int can_read;
  18.  
  19.     printf("Please enter directory name: ");
  20.     gets(directory);
  21.     strtok(directory, "\n");
  22.     printf("Directory: %s \n", directory);
  23.  
  24.     if ((dir = opendir (directory)) != NULL) {
  25.       /* print all the files and directories within directory */
  26.       while ((ent = readdir (dir)) != NULL) {      
  27.         if ( !strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..") ) {
  28.             // do nothing
  29.         } else {
  30.             sprintf(path, "%s/%s", directory, ent->d_name);
  31.             status = lstat(path, &buffer);
  32.             can_read = euidaccess(path, R_OK||X_OK);
  33.             if(!S_ISDIR(buffer.st_mode) && can_read == 0) {
  34.                 printf ("%s\n", ent->d_name);
  35.             }
  36.            
  37.         }
  38.       }
  39.       closedir (dir);
  40.     } else {
  41.       /* could not open directory */
  42.       perror ("");
  43.       return(0);
  44.     }
  45.  
  46.     return(0); 
  47. }
Advertisement
Add Comment
Please, Sign In to add comment