sfakeroot

manipulate files faking root privileges
git clone git://git.vx21.xyz/sfakeroot
Log | Files | Refs | README | LICENSE

fstat.c (679B)


      1 #include <stdio.h>
      2 #include <fcntl.h>
      3 #include <sys/stat.h>
      4 
      5 int main(int argc __attribute__((unused)), char *argv[])
      6 {
      7     struct stat st_expected;
      8     struct stat st_actual;
      9 
     10     if (stat(argv[0], &st_expected) == -1)
     11     {
     12         fprintf(stderr, "stat failed\n");
     13         return 1;
     14     }
     15 
     16 
     17     int fd = open(argv[0], O_RDONLY);
     18     if (fd == -1) {
     19         fprintf(stderr, "open failed\n");
     20         return 1;
     21     }
     22 
     23     if (fstat(fd, &st_actual) == -1)
     24     {
     25         fprintf(stderr, "fstat failed\n");
     26         return 1;
     27     }
     28 
     29     if (st_actual.st_uid == 0
     30     && st_actual.st_gid == 0
     31     && st_expected.st_ino == st_actual.st_ino) {
     32         return 0;
     33     }
     34 
     35     return 1;
     36 }