pochti_da

Untitled

Oct 18th, 2020
523
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <stdint.h>
  7. #include <inttypes.h>
  8.  
  9. struct Task
  10. {
  11.     unsigned uid;
  12.     int gid_count;
  13.     unsigned *gids;
  14. };
  15.  
  16. int
  17. myaccess(const struct stat *stb, const struct Task *task, int access) {
  18.     if (task->uid == 0) {
  19.         return 1;
  20.     }
  21.  
  22.     unsigned uaccess = access;
  23.     if (task->uid == stb->st_uid) {
  24.         return ((stb->st_mode & (uaccess << 6)) == (uaccess << 6));
  25.     }
  26.  
  27.     for (int i = 0; i < task->gid_count; ++i) {
  28.         if (task->gids[i] == stb->st_gid) {
  29.             return ((stb->st_mode & (uaccess << 3)) == (uaccess << 3));
  30.         }
  31.     }
  32.  
  33.     return ((stb->st_mode & uaccess) == uaccess);
  34. }
RAW Paste Data