Skip to content

Commit

Permalink
Merge pull request #5 from lilatomic/feature/pxd
Browse files Browse the repository at this point in the history
Feature/pxd
  • Loading branch information
lilatomic authored Oct 8, 2023
2 parents e6add51 + a40f539 commit de617a9
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 109 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes in 0.6.1 (2023-10-08):
* Add manylinux bdist
* Use `cythonize` for building
* Use pxd for keyutils
* Added python 3.10, 3.11
* Dropped python 2.7, 3.6, 3.7

Changes in 0.6 (2019-02-01):
* Pull request #1 from Anvil (debian directory for .deb creation)
* Pull request #5 from coldfix/travis
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include AUTHORS ChangeLog INSTALL LICENSE README.rst TODO
include keyutils/_keyutils.c keyutils/_keyutils.pyx
include keyutils/_keyutils.c keyutils/ckeyutils.pxd keyutils/_keyutils.pyx
162 changes: 55 additions & 107 deletions keyutils/_keyutils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,110 +17,58 @@

from libc cimport stdlib

from cython.cimports.keyutils import ckeyutils


cdef extern from "Python.h":
object PyErr_SetFromErrno(exc)
object PyBytes_FromStringAndSize(char *str, Py_ssize_t size)

cdef extern from "keyutils.h" nogil:
int c_KEY_SPEC_THREAD_KEYRING "KEY_SPEC_THREAD_KEYRING"
int c_KEY_SPEC_PROCESS_KEYRING "KEY_SPEC_PROCESS_KEYRING"
int c_KEY_SPEC_SESSION_KEYRING "KEY_SPEC_SESSION_KEYRING"
int c_KEY_SPEC_USER_KEYRING "KEY_SPEC_USER_KEYRING"
int c_KEY_SPEC_USER_SESSION_KEYRING "KEY_SPEC_USER_SESSION_KEYRING"
int c_KEY_POS_VIEW "KEY_POS_VIEW"
int c_KEY_POS_READ "KEY_POS_READ"
int c_KEY_POS_WRITE "KEY_POS_WRITE"
int c_KEY_POS_SEARCH "KEY_POS_SEARCH"
int c_KEY_POS_LINK "KEY_POS_LINK"
int c_KEY_POS_SETATTR "KEY_POS_SETATTR"
int c_KEY_POS_ALL "KEY_POS_ALL"
int c_KEY_USR_VIEW "KEY_USR_VIEW"
int c_KEY_USR_READ "KEY_USR_READ"
int c_KEY_USR_WRITE "KEY_USR_WRITE"
int c_KEY_USR_SEARCH "KEY_USR_SEARCH"
int c_KEY_USR_LINK "KEY_USR_LINK"
int c_KEY_USR_SETATTR "KEY_USR_SETATTR"
int c_KEY_USR_ALL "KEY_USR_ALL"
int c_KEY_GRP_VIEW "KEY_GRP_VIEW"
int c_KEY_GRP_READ "KEY_GRP_READ"
int c_KEY_GRP_WRITE "KEY_GRP_WRITE"
int c_KEY_GRP_SEARCH "KEY_GRP_SEARCH"
int c_KEY_GRP_LINK "KEY_GRP_LINK"
int c_KEY_GRP_SETATTR "KEY_GRP_SETATTR"
int c_KEY_GRP_ALL "KEY_GRP_ALL"
int c_KEY_OTH_VIEW "KEY_OTH_VIEW"
int c_KEY_OTH_READ "KEY_OTH_READ"
int c_KEY_OTH_WRITE "KEY_OTH_WRITE"
int c_KEY_OTH_SEARCH "KEY_OTH_SEARCH"
int c_KEY_OTH_LINK "KEY_OTH_LINK"
int c_KEY_OTH_SETATTR "KEY_OTH_SETATTR"
int c_KEY_OTH_ALL "KEY_OTH_ALL"
int c_ENOKEY "ENOKEY"
int c_EKEYEXPIRED "EKEYEXPIRED"
int c_EKEYREVOKED "EKEYREVOKED"
int c_EKEYREJECTED "EKEYREJECTED"
int c_add_key "add_key"(char *key_type, char *description, void *payload,
int plen, int keyring)
int c_request_key "request_key"(char *key_type, char *description,
char *callout_info, int keyring)
int c_search "keyctl_search"(int keyring, char *key_type,
char *description, int destination)
int c_update "keyctl_update"(int key, const void *payload, size_t plen)
int c_read_alloc "keyctl_read_alloc"(int key, void **bufptr)
int c_join_session_keyring "keyctl_join_session_keyring"(char *name)
int c_session_to_parent "keyctl_session_to_parent"()
int c_link "keyctl_link"(int key, int keyring)
int c_unlink "keyctl_unlink"(int key, int keyring)
int c_revoke "keyctl_revoke"(int key)
int c_setperm "keyctl_setperm"(int key, int perm)
int c_set_timeout "keyctl_set_timeout" (int key, int timeout)
int c_clear "keyctl_clear" (int keyring)
int c_describe_alloc "keyctl_describe_alloc" (int key, char **bufptr)


class error(Exception):
pass


class constants:
KEY_SPEC_THREAD_KEYRING = c_KEY_SPEC_THREAD_KEYRING
KEY_SPEC_PROCESS_KEYRING = c_KEY_SPEC_PROCESS_KEYRING
KEY_SPEC_SESSION_KEYRING = c_KEY_SPEC_SESSION_KEYRING
KEY_SPEC_USER_KEYRING = c_KEY_SPEC_USER_KEYRING
KEY_SPEC_USER_SESSION_KEYRING = c_KEY_SPEC_USER_SESSION_KEYRING
ENOKEY = c_ENOKEY
EKEYEXPIRED = c_EKEYEXPIRED
EKEYREVOKED = c_EKEYREVOKED
EKEYREJECTED = c_EKEYREJECTED
KEY_POS_VIEW = c_KEY_POS_VIEW
KEY_POS_READ = c_KEY_POS_READ
KEY_POS_WRITE = c_KEY_POS_WRITE
KEY_POS_SEARCH = c_KEY_POS_SEARCH
KEY_POS_LINK = c_KEY_POS_LINK
KEY_POS_SETATTR = c_KEY_POS_SETATTR
KEY_POS_ALL = c_KEY_POS_ALL
KEY_USR_VIEW = c_KEY_USR_VIEW
KEY_USR_READ = c_KEY_USR_READ
KEY_USR_WRITE = c_KEY_USR_WRITE
KEY_USR_SEARCH = c_KEY_USR_SEARCH
KEY_USR_LINK = c_KEY_USR_LINK
KEY_USR_SETATTR = c_KEY_USR_SETATTR
KEY_USR_ALL = c_KEY_USR_ALL
KEY_GRP_VIEW = c_KEY_GRP_VIEW
KEY_GRP_READ = c_KEY_GRP_READ
KEY_GRP_WRITE = c_KEY_GRP_WRITE
KEY_GRP_SEARCH = c_KEY_GRP_SEARCH
KEY_GRP_LINK = c_KEY_GRP_LINK
KEY_GRP_SETATTR = c_KEY_GRP_SETATTR
KEY_GRP_ALL = c_KEY_GRP_ALL
KEY_OTH_VIEW = c_KEY_OTH_VIEW
KEY_OTH_READ = c_KEY_OTH_READ
KEY_OTH_WRITE = c_KEY_OTH_WRITE
KEY_OTH_SEARCH = c_KEY_OTH_SEARCH
KEY_OTH_LINK = c_KEY_OTH_LINK
KEY_OTH_SETATTR = c_KEY_OTH_SETATTR
KEY_OTH_ALL = c_KEY_OTH_ALL
KEY_SPEC_THREAD_KEYRING = ckeyutils.KEY_SPEC_THREAD_KEYRING
KEY_SPEC_PROCESS_KEYRING = ckeyutils.KEY_SPEC_PROCESS_KEYRING
KEY_SPEC_SESSION_KEYRING = ckeyutils.KEY_SPEC_SESSION_KEYRING
KEY_SPEC_USER_KEYRING = ckeyutils.KEY_SPEC_USER_KEYRING
KEY_SPEC_USER_SESSION_KEYRING = ckeyutils.KEY_SPEC_USER_SESSION_KEYRING
KEY_SPEC_GROUP_KEYRING = ckeyutils.KEY_SPEC_GROUP_KEYRING
KEY_SPEC_REQKEY_AUTH_KEY = ckeyutils.KEY_SPEC_REQKEY_AUTH_KEY
ENOKEY = ckeyutils.ENOKEY
EKEYEXPIRED = ckeyutils.EKEYEXPIRED
EKEYREVOKED = ckeyutils.EKEYREVOKED
EKEYREJECTED = ckeyutils.EKEYREJECTED
KEY_POS_VIEW = ckeyutils.KEY_POS_VIEW
KEY_POS_READ = ckeyutils.KEY_POS_READ
KEY_POS_WRITE = ckeyutils.KEY_POS_WRITE
KEY_POS_SEARCH = ckeyutils.KEY_POS_SEARCH
KEY_POS_LINK = ckeyutils.KEY_POS_LINK
KEY_POS_SETATTR = ckeyutils.KEY_POS_SETATTR
KEY_POS_ALL = ckeyutils.KEY_POS_ALL
KEY_USR_VIEW = ckeyutils.KEY_USR_VIEW
KEY_USR_READ = ckeyutils.KEY_USR_READ
KEY_USR_WRITE = ckeyutils.KEY_USR_WRITE
KEY_USR_SEARCH = ckeyutils.KEY_USR_SEARCH
KEY_USR_LINK = ckeyutils.KEY_USR_LINK
KEY_USR_SETATTR = ckeyutils.KEY_USR_SETATTR
KEY_USR_ALL = ckeyutils.KEY_USR_ALL
KEY_GRP_VIEW = ckeyutils.KEY_GRP_VIEW
KEY_GRP_READ = ckeyutils.KEY_GRP_READ
KEY_GRP_WRITE = ckeyutils.KEY_GRP_WRITE
KEY_GRP_SEARCH = ckeyutils.KEY_GRP_SEARCH
KEY_GRP_LINK = ckeyutils.KEY_GRP_LINK
KEY_GRP_SETATTR = ckeyutils.KEY_GRP_SETATTR
KEY_GRP_ALL = ckeyutils.KEY_GRP_ALL
KEY_OTH_VIEW = ckeyutils.KEY_OTH_VIEW
KEY_OTH_READ = ckeyutils.KEY_OTH_READ
KEY_OTH_WRITE = ckeyutils.KEY_OTH_WRITE
KEY_OTH_SEARCH = ckeyutils.KEY_OTH_SEARCH
KEY_OTH_LINK = ckeyutils.KEY_OTH_LINK
KEY_OTH_SETATTR = ckeyutils.KEY_OTH_SETATTR
KEY_OTH_ALL = ckeyutils.KEY_OTH_ALL


def add_key(bytes key_type, bytes description, bytes payload, int keyring):
Expand All @@ -136,7 +84,7 @@ def add_key(bytes key_type, bytes description, bytes payload, int keyring):
payload_p = payload
payload_len = len(payload)
with nogil:
rc = c_add_key(key_type_p, desc_p, payload_p, payload_len, keyring)
rc = ckeyutils.add_key(key_type_p, desc_p, payload_p, payload_len, keyring)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -153,7 +101,7 @@ def request_key(bytes key_type, bytes description, bytes callout_info, int keyri
else:
callout_p = callout_info
with nogil:
rc = c_request_key(key_type_p, desc_p, callout_p, keyring)
rc = ckeyutils.request_key(key_type_p, desc_p, callout_p, keyring)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -165,7 +113,7 @@ def search(int keyring, bytes key_type, bytes description, int destination):
cdef char *desc_p = description
cdef int rc
with nogil:
rc = c_search(keyring, key_type_p, desc_p, destination)
rc = ckeyutils.search(keyring, key_type_p, desc_p, destination)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -183,7 +131,7 @@ def update_key(int key, bytes payload):
payload_p = payload
payload_len = len(payload)
with nogil:
rc = c_update(key, payload_p, payload_len)
rc = ckeyutils.update(key, payload_p, payload_len)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -195,7 +143,7 @@ def read_key(int key):
cdef void *ptr
cdef bytes obj
with nogil:
size = c_read_alloc(key, &ptr)
size = ckeyutils.read_alloc(key, &ptr)
if size < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -209,7 +157,7 @@ def describe_key(int key):
cdef char *ptr
cdef bytes obj
with nogil:
size = c_describe_alloc(key, &ptr)
size = ckeyutils.describe_alloc(key, &ptr)
if size < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -226,7 +174,7 @@ def join_session_keyring(name):
else:
name_p = name
with nogil:
rc = c_join_session_keyring(name_p)
rc = ckeyutils.join_session_keyring(name_p)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -236,7 +184,7 @@ def join_session_keyring(name):
def session_to_parent():
cdef int rc
with nogil:
rc = c_session_to_parent()
rc = ckeyutils.session_to_parent()
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -246,7 +194,7 @@ def session_to_parent():
def link(int key, int keyring):
cdef int rc
with nogil:
rc = c_link(key, keyring)
rc = ckeyutils.link(key, keyring)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -256,7 +204,7 @@ def link(int key, int keyring):
def unlink(int key, int keyring):
cdef int rc
with nogil:
rc = c_unlink(key, keyring)
rc = ckeyutils.unlink(key, keyring)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -266,7 +214,7 @@ def unlink(int key, int keyring):
def revoke(int key):
cdef int rc
with nogil:
rc = c_revoke(key)
rc = ckeyutils.revoke(key)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -277,7 +225,7 @@ def set_perm(int key, int perm):
cdef int rc
cdef int keyperm
with nogil:
rc = c_setperm(key, perm)
rc = ckeyutils.setperm(key, perm)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -287,7 +235,7 @@ def set_perm(int key, int perm):
def set_timeout(int key, int timeout):
cdef int rc
with nogil:
rc = c_set_timeout(key, timeout)
rc = ckeyutils.set_timeout(key, timeout)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand All @@ -297,7 +245,7 @@ def set_timeout(int key, int timeout):
def clear(int keyring):
cdef int rc
with nogil:
rc = c_clear(keyring)
rc = ckeyutils.clear(keyring)
if rc < 0:
PyErr_SetFromErrno(error)
else:
Expand Down
63 changes: 63 additions & 0 deletions keyutils/ckeyutils.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cdef extern from "keyutils.h" nogil:
# special process keyring shortcut IDs
int KEY_SPEC_THREAD_KEYRING "KEY_SPEC_THREAD_KEYRING"
int KEY_SPEC_PROCESS_KEYRING "KEY_SPEC_PROCESS_KEYRING"
int KEY_SPEC_SESSION_KEYRING "KEY_SPEC_SESSION_KEYRING"
int KEY_SPEC_USER_KEYRING "KEY_SPEC_USER_KEYRING"
int KEY_SPEC_USER_SESSION_KEYRING "KEY_SPEC_USER_SESSION_KEYRING"
int KEY_SPEC_GROUP_KEYRING "KEY_SPEC_GROUP_KEYRING"
int KEY_SPEC_REQKEY_AUTH_KEY "KEY_SPEC_REQKEY_AUTH_KEY"

int KEY_POS_VIEW "KEY_POS_VIEW"
int KEY_POS_READ "KEY_POS_READ"
int KEY_POS_WRITE "KEY_POS_WRITE"
int KEY_POS_SEARCH "KEY_POS_SEARCH"
int KEY_POS_LINK "KEY_POS_LINK"
int KEY_POS_SETATTR "KEY_POS_SETATTR"
int KEY_POS_ALL "KEY_POS_ALL"

# user permissions...
int KEY_USR_VIEW "KEY_USR_VIEW"
int KEY_USR_READ "KEY_USR_READ"
int KEY_USR_WRITE "KEY_USR_WRITE"
int KEY_USR_SEARCH "KEY_USR_SEARCH"
int KEY_USR_LINK "KEY_USR_LINK"
int KEY_USR_SETATTR "KEY_USR_SETATTR"
int KEY_USR_ALL "KEY_USR_ALL"

# group permissions...
int KEY_GRP_VIEW "KEY_GRP_VIEW"
int KEY_GRP_READ "KEY_GRP_READ"
int KEY_GRP_WRITE "KEY_GRP_WRITE"
int KEY_GRP_SEARCH "KEY_GRP_SEARCH"
int KEY_GRP_LINK "KEY_GRP_LINK"
int KEY_GRP_SETATTR "KEY_GRP_SETATTR"
int KEY_GRP_ALL "KEY_GRP_ALL"

# third party permissions...
int KEY_OTH_VIEW "KEY_OTH_VIEW"
int KEY_OTH_READ "KEY_OTH_READ"
int KEY_OTH_WRITE "KEY_OTH_WRITE"
int KEY_OTH_SEARCH "KEY_OTH_SEARCH"
int KEY_OTH_LINK "KEY_OTH_LINK"
int KEY_OTH_SETATTR "KEY_OTH_SETATTR"
int KEY_OTH_ALL "KEY_OTH_ALL"

int ENOKEY "ENOKEY"
int EKEYEXPIRED "EKEYEXPIRED"
int EKEYREVOKED "EKEYREVOKED"
int EKEYREJECTED "EKEYREJECTED"
int add_key "add_key"(char *key_type, char *description, void *payload, int plen, int keyring)
int request_key "request_key"(char *key_type, char *description, char *callout_info, int keyring)
int search "keyctl_search"(int keyring, char *key_type, char *description, int destination)
int update "keyctl_update"(int key, const void *payload, size_t plen)
int read_alloc "keyctl_read_alloc"(int key, void **bufptr)
int join_session_keyring "keyctl_join_session_keyring"(char *name)
int session_to_parent "keyctl_session_to_parent"()
int link "keyctl_link"(int key, int keyring)
int unlink "keyctl_unlink"(int key, int keyring)
int revoke "keyctl_revoke"(int key)
int setperm "keyctl_setperm"(int key, int perm)
int set_timeout "keyctl_set_timeout" (int key, int timeout)
int clear "keyctl_clear" (int keyring)
int describe_alloc "keyctl_describe_alloc" (int key, char **bufptr)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setup(
name="turkeyutils",
version="0.6",
version="0.6.1",
description="keyutils bindings for Python",
long_description=long_description,
author="Daniel Goldman",
Expand Down

0 comments on commit de617a9

Please sign in to comment.