1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
3 #include <sys/capsicum.h>
13 void test_cap_ioctls() {
15 unsigned long ncmds
[] = {TIOCGETA
, TIOCGWINSZ
, FIODTYPE
};
16 unsigned long rcmds
= 0;
17 cap_rights_t
*rptr
= cap_rights_init(&rights
, CAP_IOCTL
, CAP_READ
);
20 int rv
= cap_rights_limit(STDIN_FILENO
, &rights
);
22 rv
= cap_ioctls_limit(STDIN_FILENO
, ncmds
, 3);
24 ssize_t rz
= cap_ioctls_get(STDIN_FILENO
, &rcmds
, 3);
26 printf("ioctls test: %ld commands authorized\n", rz
);
29 void test_cap_rights() {
30 cap_rights_t rights
, little
, remove
, grights
;
31 cap_rights_t
*rptr
= cap_rights_init(&rights
, CAP_IOCTL
, CAP_READ
);
33 cap_rights_t
*gptr
= cap_rights_init(&remove
, CAP_IOCTL
);
35 cap_rights_t
*sptr
= cap_rights_init(&little
, CAP_READ
);
37 bool hasit
= cap_rights_contains(rptr
, sptr
);
38 assert(hasit
== true);
39 cap_rights_t
*pptr
= cap_rights_remove(&rights
, gptr
);
40 hasit
= cap_rights_contains(pptr
, sptr
);
41 assert(hasit
== true);
42 cap_rights_t
*aptr
= cap_rights_merge(&rights
, gptr
);
44 bool correct
= cap_rights_is_valid(&rights
);
45 assert(correct
== true);
47 int rv
= cap_rights_limit(STDIN_FILENO
, &rights
);
49 rv
= cap_rights_get(STDIN_FILENO
, &grights
);
51 assert(memcmp(&grights
, &rights
, sizeof(grights
)) == 0);
52 cap_rights_t
*iptr
= cap_rights_set(&rights
, CAP_IOCTL
);
54 cap_rights_t
*eptr
= cap_rights_clear(&rights
, CAP_READ
);
56 hasit
= cap_rights_is_set(&rights
, CAP_IOCTL
);
57 assert(hasit
== true);
58 printf("rights test: %d\n", rv
);
66 // CHECK: ioctls test: {{.*}} commands authorized
67 // CHECK: rights test: {{.*}}