Home | History | Annotate | Download | only in linux
      1 #if defined(linux)
      2 
      3 
      4 #include <stdio.h>            /* printf() */
      5 #include <unistd.h>           /* syscall() */
      6 #include <sys/syscall.h>      /* __NR_capget */
      7 #include <sys/types.h>        /* uid_t */
      8 #include <linux/capability.h> /* _LINUX_CAPABILITY_VERSION */
      9 
     10 
     11 int main()
     12 {
     13   struct __user_cap_header_struct h;
     14   struct __user_cap_data_struct d;
     15   int syscall_result;
     16 
     17   if (getuid() == 0)
     18     fprintf(stderr, "Running as root\n");
     19   h.version = _LINUX_CAPABILITY_VERSION;
     20   h.pid = 0;
     21   syscall_result = syscall(__NR_capget, &h, &d);
     22   if (syscall_result >= 0)
     23   {
     24     fprintf(stderr,
     25             "capget result:\n"
     26             "effective   %#x\n"
     27             "permitted   %#x\n"
     28             "inheritable %#x\n",
     29             d.effective,
     30             d.permitted,
     31             d.inheritable);
     32   }
     33   else
     34   {
     35     perror("capget");
     36   }
     37   return 0;
     38 }
     39 
     40 
     41 #else
     42 
     43 
     44 #include <stdio.h>
     45 
     46 int main()
     47 {
     48   fprintf(stderr, "This program is Linux-specific\n");
     49   return 0;
     50 }
     51 
     52 
     53 #endif
     54