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