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