summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorPaul Moore <pmoore@redhat.com>2014-05-07 17:00:44 -0400
committerPaul Moore <pmoore@redhat.com>2014-05-07 17:00:44 -0400
commitf05fc7cbc294f95fd62fb0aea52561c14f52aba9 (patch)
treea48843c82082c385db2f84b07fbc5c547eb35927 /src/python
parente8a449fb5b87ba0479524b661fe962a5d977d400 (diff)
downloadlibseccomp-f05fc7cbc294f95fd62fb0aea52561c14f52aba9.tar.gz
api: add the seccomp_arch_resolve_name() API call
As requested by the systemd developers and used by our own tools. Signed-off-by: Paul Moore <pmoore@redhat.com>
Diffstat (limited to 'src/python')
-rw-r--r--src/python/libseccomp.pxd1
-rw-r--r--src/python/seccomp.pyx48
2 files changed, 47 insertions, 2 deletions
diff --git a/src/python/libseccomp.pxd b/src/python/libseccomp.pxd
index 1c3921c..5fea471 100644
--- a/src/python/libseccomp.pxd
+++ b/src/python/libseccomp.pxd
@@ -69,6 +69,7 @@ cdef extern from "seccomp.h":
int seccomp_merge(scmp_filter_ctx ctx_dst, scmp_filter_ctx ctx_src)
+ uint32_t seccomp_arch_resolve_name(char *arch_name)
uint32_t seccomp_arch_native()
int seccomp_arch_exist(scmp_filter_ctx ctx, int arch_token)
int seccomp_arch_add(scmp_filter_ctx ctx, int arch_token)
diff --git a/src/python/seccomp.pyx b/src/python/seccomp.pyx
index 702a520..f1848dc 100644
--- a/src/python/seccomp.pyx
+++ b/src/python/seccomp.pyx
@@ -120,9 +120,9 @@ def resolve_syscall(arch, syscall):
"""
cdef char *ret_str
- if (isinstance(syscall, basestring)):
+ if isinstance(syscall, basestring):
return libseccomp.seccomp_syscall_resolve_name_arch(arch, syscall)
- elif (isinstance(syscall, int)):
+ elif isinstance(syscall, int):
ret_str = libseccomp.seccomp_syscall_resolve_num_arch(arch, syscall)
if ret_str is NULL:
raise ValueError('Unknown syscall %d on arch %d' % (syscall, arch))
@@ -144,6 +144,8 @@ cdef class Arch:
MIPSEL - MIPS little endian
"""
+ cdef int _token
+
NATIVE = libseccomp.SCMP_ARCH_NATIVE
X86 = libseccomp.SCMP_ARCH_X86
X86_64 = libseccomp.SCMP_ARCH_X86_64
@@ -152,6 +154,48 @@ cdef class Arch:
MIPS = libseccomp.SCMP_ARCH_MIPS
MIPSEL = libseccomp.SCMP_ARCH_MIPSEL
+ def __cinit__(self, arch=libseccomp.SCMP_ARCH_NATIVE):
+ """ Initialize the architecture object.
+
+ Arguments:
+ arch - the architecture name or token value
+
+ Description:
+ Create an architecture object using the given name or token value.
+ """
+ if isinstance(arch, int):
+ if arch == libseccomp.SCMP_ARCH_NATIVE:
+ self._token = libseccomp.seccomp_arch_native()
+ elif arch == libseccomp.SCMP_ARCH_X86:
+ self._token = libseccomp.SCMP_ARCH_X86
+ elif arch == libseccomp.SCMP_ARCH_X86_64:
+ self._token = libseccomp.SCMP_ARCH_X86_64
+ elif arch == libseccomp.SCMP_ARCH_X32:
+ self._token = libseccomp.SCMP_ARCH_X32
+ elif arch == libseccomp.SCMP_ARCH_ARM:
+ self._token = libseccomp.SCMP_ARCH_ARM
+ elif arch == libseccomp.SCMP_ARCH_MIPS:
+ self._token = libseccomp.SCMP_ARCH_MIPS
+ elif arch == libseccomp.SCMP_ARCH_MIPSEL:
+ self._token = libseccomp.SCMP_ARCH_MIPSEL
+ else:
+ self._token = 0;
+ elif isinstance(arch, basestring):
+ self._token = libseccomp.seccomp_arch_resolve_name(arch)
+ else:
+ raise TypeError("Architecture must be an int or str type")
+ if self._token == 0:
+ raise ValueError("Invalid architecture")
+
+ def __int__(self):
+ """ Convert the architecture object to a token value.
+
+ Description:
+ Convert the architecture object to an integer representing the
+ architecture's token value.
+ """
+ return self._token
+
cdef class Attr:
""" Python object representing the SyscallFilter attributes.