| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # |
| 4 | # Seccomp Library test program |
| 5 | # |
| 6 | # Copyright (c) 2012 Red Hat <pmoore@redhat.com> |
| 7 | # Author: Paul Moore <paul@paul-moore.com> |
| 8 | # |
| 9 | |
| 10 | # |
| 11 | # This library is free software; you can redistribute it and/or modify it |
| 12 | # under the terms of version 2.1 of the GNU Lesser General Public License as |
| 13 | # published by the Free Software Foundation. |
| 14 | # |
| 15 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 18 | # for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU Lesser General Public License |
| 21 | # along with this library; if not, see <http://www.gnu.org/licenses>. |
| 22 | # |
| 23 | |
| 24 | import argparse |
| 25 | import sys |
| 26 | |
| 27 | import util |
| 28 | |
| 29 | from seccomp import * |
| 30 | |
| 31 | def test(): |
| 32 | f = SyscallFilter(KILL) |
| 33 | # this differs from the native test as we don't support the syscall |
| 34 | # resolution functions by themselves |
| 35 | f.add_rule(ALLOW, "open") |
| 36 | f.add_rule(ALLOW, "read") |
| 37 | try: |
| 38 | f.add_rule(ALLOW, "INVALID") |
| 39 | except RuntimeError: |
| 40 | pass |
| 41 | |
| 42 | sys_num = resolve_syscall(Arch(), "open") |
| 43 | sys_name = resolve_syscall(Arch(), sys_num) |
| 44 | if (sys_name != "open"): |
| 45 | raise RuntimeError("Test failure") |
| 46 | sys_num = resolve_syscall(Arch(), "read") |
| 47 | sys_name = resolve_syscall(Arch(), sys_num) |
| 48 | if (sys_name != "read"): |
| 49 | raise RuntimeError("Test failure") |
| 50 | |
| 51 | test() |
| 52 | |
| 53 | # kate: syntax python; |
| 54 | # kate: indent-mode python; space-indent on; indent-width 4; mixedindent off; |