xref: /freebsd/tests/sys/capsicum/showrights (revision 670b568ec1c36464c6d55e400382c290b0391ccf)
1*670b568eSEd Maste#!/usr/bin/env python
2*670b568eSEd Masteimport sys
3*670b568eSEd Masteimport re
4*670b568eSEd Maste
5*670b568eSEd Maste_values = {  # 2-tuple => name
6*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000100) : 'TTYHOOK',
7*670b568eSEd Maste  (0x0000000000000040, 0x0000000000000000) : 'CREATE',
8*670b568eSEd Maste  (0x0000000200000000, 0x0000000000000000) : 'GETSOCKNAME',
9*670b568eSEd Maste  (0x0000000000000000, 0x0000000000100000) : 'KQUEUE_CHANGE',
10*670b568eSEd Maste  (0x0000000000000000, 0x0000000000004000) : 'EXTATTR_LIST',
11*670b568eSEd Maste  (0x0000000000000080, 0x0000000000000000) : 'FEXECVE',
12*670b568eSEd Maste  (0x0000001000000000, 0x0000000000000000) : 'PEELOFF',
13*670b568eSEd Maste  (0x0000000000000000, 0x0000000000800000) : 'NOTIFY',
14*670b568eSEd Maste  (0x0000000000000000, 0x0000000000001000) : 'EXTATTR_DELETE',
15*670b568eSEd Maste  (0x0000000040000000, 0x0000000000000000) : 'BIND',
16*670b568eSEd Maste  (0x0000000000000000, 0x0000000000002000) : 'EXTATTR_GET',
17*670b568eSEd Maste  (0x0000000000008000, 0x0000000000000000) : 'FCNTL',
18*670b568eSEd Maste  (0x0000000000000000, 0x0000000000400000) : 'EPOLL_CTL',
19*670b568eSEd Maste  (0x0000000000000004, 0x0000000000000000) : 'SEEK_TELL',
20*670b568eSEd Maste  (0x000000000000000c, 0x0000000000000000) : 'SEEK',
21*670b568eSEd Maste  (0x0000004000000000, 0x0000000000000000) : 'SHUTDOWN',
22*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000080) : 'IOCTL',
23*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000020) : 'EVENT',
24*670b568eSEd Maste  (0x0000000400000000, 0x0000000000000000) : 'GETSOCKOPT',
25*670b568eSEd Maste  (0x0000000080000000, 0x0000000000000000) : 'CONNECT',
26*670b568eSEd Maste  (0x0000000000000000, 0x0000000000200000) : 'FSIGNAL',
27*670b568eSEd Maste  (0x0000000000000000, 0x0000000000008000) : 'EXTATTR_SET',
28*670b568eSEd Maste  (0x0000000000100000, 0x0000000000000000) : 'FSTATFS',
29*670b568eSEd Maste  (0x0000000000040000, 0x0000000000000000) : 'FSCK',
30*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000800) : 'PDKILL_FREEBSD',
31*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000004) : 'SEM_GETVALUE',
32*670b568eSEd Maste  (0x0000000000000000, 0x0000000000080000) : 'ACL_SET',
33*670b568eSEd Maste  (0x0000000000200000, 0x0000000000000000) : 'FUTIMES',
34*670b568eSEd Maste  (0x0000000000000200, 0x0000000000000000) : 'FTRUNCATE',
35*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000001) : 'MAC_GET',
36*670b568eSEd Maste  (0x0000000000020000, 0x0000000000000000) : 'FPATHCONF',
37*670b568eSEd Maste  (0x0000002000000000, 0x0000000000000000) : 'SETSOCKOPT',
38*670b568eSEd Maste  (0x0000000000002000, 0x0000000000000000) : 'FCHMOD',
39*670b568eSEd Maste  (0x0000000000000000, 0x0000000002000000) : 'PERFMON',
40*670b568eSEd Maste  (0x0000000000004000, 0x0000000000000000) : 'FCHOWN',
41*670b568eSEd Maste  (0x0000000000000400, 0x0000000000000000) : 'LOOKUP',
42*670b568eSEd Maste  (0x0000000000400400, 0x0000000000000000) : 'LINKAT_TARGET',
43*670b568eSEd Maste  (0x0000000000800400, 0x0000000000000000) : 'MKDIRAT',
44*670b568eSEd Maste  (0x0000000001000400, 0x0000000000000000) : 'MKFIFOAT',
45*670b568eSEd Maste  (0x0000000002000400, 0x0000000000000000) : 'MKNODAT',
46*670b568eSEd Maste  (0x0000000004000400, 0x0000000000000000) : 'RENAMEAT_SOURCE',
47*670b568eSEd Maste  (0x0000000008000400, 0x0000000000000000) : 'SYMLINKAT',
48*670b568eSEd Maste  (0x0000000010000400, 0x0000000000000000) : 'UNLINKAT',
49*670b568eSEd Maste  (0x0000008000000400, 0x0000000000000000) : 'BINDAT',
50*670b568eSEd Maste  (0x0000010000000400, 0x0000000000000000) : 'CONNECTAT',
51*670b568eSEd Maste  (0x0000020000000400, 0x0000000000000000) : 'LINKAT_SOURCE',
52*670b568eSEd Maste  (0x0000040000000400, 0x0000000000000000) : 'RENAMEAT_TARGET',
53*670b568eSEd Maste  (0x0000000000000010, 0x0000000000000000) : 'MMAP',
54*670b568eSEd Maste  (0x000000000000003c, 0x0000000000000000) : 'MMAP_X',
55*670b568eSEd Maste  (0x0000000000000000, 0x0000000001000000) : 'SETNS',
56*670b568eSEd Maste  (0x0000000000080000, 0x0000000000000000) : 'FSTAT',
57*670b568eSEd Maste  (0x0000000000000001, 0x0000000000000000) : 'READ',
58*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000008) : 'SEM_POST',
59*670b568eSEd Maste  (0x0000000000000000, 0x0000000000020000) : 'ACL_DELETE',
60*670b568eSEd Maste  (0x0000000000001000, 0x0000000000000000) : 'FCHFLAGS',
61*670b568eSEd Maste  (0x0000000800000000, 0x0000000000000000) : 'LISTEN',
62*670b568eSEd Maste  (0x0000000100000000, 0x0000000000000000) : 'GETPEERNAME',
63*670b568eSEd Maste  (0x0000000000000100, 0x0000000000000000) : 'FSYNC',
64*670b568eSEd Maste  (0x0000000000000000, 0x0000000004000000) : 'BPF',
65*670b568eSEd Maste  (0x0000000020000000, 0x0000000000000000) : 'ACCEPT',
66*670b568eSEd Maste  (0x0000000000000800, 0x0000000000000000) : 'FCHDIR',
67*670b568eSEd Maste  (0x0000000000000002, 0x0000000000000000) : 'WRITE',
68*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000010) : 'SEM_WAIT',
69*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000040) : 'KQUEUE_EVENT',
70*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000400) : 'PDWAIT',
71*670b568eSEd Maste  (0x0000000000000000, 0x0000000000040000) : 'ACL_GET',
72*670b568eSEd Maste  (0x0000000000010000, 0x0000000000000000) : 'FLOCK',
73*670b568eSEd Maste  (0x0000000000000000, 0x0000000000010000) : 'ACL_CHECK',
74*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000002) : 'MAC_SET',
75*670b568eSEd Maste  (0x0000000000000000, 0x0000000000000200) : 'PDGETPID_FREEBSD',
76*670b568eSEd Maste}
77*670b568eSEd Maste
78*670b568eSEd Maste
79*670b568eSEd Mastedef _map_fdinfo(line):
80*670b568eSEd Maste    RIGHTS_RE = re.compile(r'(?P<prefix>.*)rights:(?P<ws>\s+)0x(?P<v0>[0-9a-fA-F]+)\s+0x(?P<v1>[0-9a-fA-F]+)$')
81*670b568eSEd Maste    m = RIGHTS_RE.match(line)
82*670b568eSEd Maste    if m:
83*670b568eSEd Maste        val0 = long(m.group('v0'), 16)
84*670b568eSEd Maste        val0 = (val0 & ~(0x0200000000000000L))
85*670b568eSEd Maste        val1 = long(m.group('v1'), 16)
86*670b568eSEd Maste        val1 = (val1 & ~(0x0400000000000000L))
87*670b568eSEd Maste        rights = []
88*670b568eSEd Maste        for (right, name) in _values.items():
89*670b568eSEd Maste            if ((right[0] == 0 or (val0 & right[0])) and
90*670b568eSEd Maste                (right[1] == 0 or (val1 & right[1]))):
91*670b568eSEd Maste                rights.append(name)
92*670b568eSEd Maste        return "%srights:%s%s" % (m.group('prefix'), m.group('ws'), '|'.join(rights))
93*670b568eSEd Maste    else:
94*670b568eSEd Maste        return line.rstrip()
95*670b568eSEd Maste
96*670b568eSEd Masteif __name__ == "__main__":
97*670b568eSEd Maste    infile = open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin
98*670b568eSEd Maste    for line in infile.readlines():
99*670b568eSEd Maste        print _map_fdinfo(line)
100