From 692337208ca75bfd1d1bf41085d22187ab794815 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Sun, 8 Oct 2023 14:31:31 -0400 Subject: [PATCH 1/5] pull c items into pxd --- MANIFEST.in | 2 +- keyutils/_keyutils.pyx | 160 ++++++++++++++--------------------------- keyutils/ckeyutils.pxd | 55 ++++++++++++++ 3 files changed, 108 insertions(+), 109 deletions(-) create mode 100644 keyutils/ckeyutils.pxd diff --git a/MANIFEST.in b/MANIFEST.in index ed0e0e5..5e02970 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/keyutils/_keyutils.pyx b/keyutils/_keyutils.pyx index 282c7fa..38712f9 100644 --- a/keyutils/_keyutils.pyx +++ b/keyutils/_keyutils.pyx @@ -16,111 +16,55 @@ # 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.c_KEY_SPEC_THREAD_KEYRING + KEY_SPEC_PROCESS_KEYRING = ckeyutils.c_KEY_SPEC_PROCESS_KEYRING + KEY_SPEC_SESSION_KEYRING = ckeyutils.c_KEY_SPEC_SESSION_KEYRING + KEY_SPEC_USER_KEYRING = ckeyutils.c_KEY_SPEC_USER_KEYRING + KEY_SPEC_USER_SESSION_KEYRING = ckeyutils.c_KEY_SPEC_USER_SESSION_KEYRING + ENOKEY = ckeyutils.c_ENOKEY + EKEYEXPIRED = ckeyutils.c_EKEYEXPIRED + EKEYREVOKED = ckeyutils.c_EKEYREVOKED + EKEYREJECTED = ckeyutils.c_EKEYREJECTED + KEY_POS_VIEW = ckeyutils.c_KEY_POS_VIEW + KEY_POS_READ = ckeyutils.c_KEY_POS_READ + KEY_POS_WRITE = ckeyutils.c_KEY_POS_WRITE + KEY_POS_SEARCH = ckeyutils.c_KEY_POS_SEARCH + KEY_POS_LINK = ckeyutils.c_KEY_POS_LINK + KEY_POS_SETATTR = ckeyutils.c_KEY_POS_SETATTR + KEY_POS_ALL = ckeyutils.c_KEY_POS_ALL + KEY_USR_VIEW = ckeyutils.c_KEY_USR_VIEW + KEY_USR_READ = ckeyutils.c_KEY_USR_READ + KEY_USR_WRITE = ckeyutils.c_KEY_USR_WRITE + KEY_USR_SEARCH = ckeyutils.c_KEY_USR_SEARCH + KEY_USR_LINK = ckeyutils.c_KEY_USR_LINK + KEY_USR_SETATTR = ckeyutils.c_KEY_USR_SETATTR + KEY_USR_ALL = ckeyutils.c_KEY_USR_ALL + KEY_GRP_VIEW = ckeyutils.c_KEY_GRP_VIEW + KEY_GRP_READ = ckeyutils.c_KEY_GRP_READ + KEY_GRP_WRITE = ckeyutils.c_KEY_GRP_WRITE + KEY_GRP_SEARCH = ckeyutils.c_KEY_GRP_SEARCH + KEY_GRP_LINK = ckeyutils.c_KEY_GRP_LINK + KEY_GRP_SETATTR = ckeyutils.c_KEY_GRP_SETATTR + KEY_GRP_ALL = ckeyutils.c_KEY_GRP_ALL + KEY_OTH_VIEW = ckeyutils.c_KEY_OTH_VIEW + KEY_OTH_READ = ckeyutils.c_KEY_OTH_READ + KEY_OTH_WRITE = ckeyutils.c_KEY_OTH_WRITE + KEY_OTH_SEARCH = ckeyutils.c_KEY_OTH_SEARCH + KEY_OTH_LINK = ckeyutils.c_KEY_OTH_LINK + KEY_OTH_SETATTR = ckeyutils.c_KEY_OTH_SETATTR + KEY_OTH_ALL = ckeyutils.c_KEY_OTH_ALL def add_key(bytes key_type, bytes description, bytes payload, int keyring): @@ -136,7 +80,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.c_add_key(key_type_p, desc_p, payload_p, payload_len, keyring) if rc < 0: PyErr_SetFromErrno(error) else: @@ -153,7 +97,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.c_request_key(key_type_p, desc_p, callout_p, keyring) if rc < 0: PyErr_SetFromErrno(error) else: @@ -165,7 +109,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.c_search(keyring, key_type_p, desc_p, destination) if rc < 0: PyErr_SetFromErrno(error) else: @@ -183,7 +127,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.c_update(key, payload_p, payload_len) if rc < 0: PyErr_SetFromErrno(error) else: @@ -195,7 +139,7 @@ def read_key(int key): cdef void *ptr cdef bytes obj with nogil: - size = c_read_alloc(key, &ptr) + size = ckeyutils.c_read_alloc(key, &ptr) if size < 0: PyErr_SetFromErrno(error) else: @@ -209,7 +153,7 @@ def describe_key(int key): cdef char *ptr cdef bytes obj with nogil: - size = c_describe_alloc(key, &ptr) + size = ckeyutils.c_describe_alloc(key, &ptr) if size < 0: PyErr_SetFromErrno(error) else: @@ -226,7 +170,7 @@ def join_session_keyring(name): else: name_p = name with nogil: - rc = c_join_session_keyring(name_p) + rc = ckeyutils.c_join_session_keyring(name_p) if rc < 0: PyErr_SetFromErrno(error) else: @@ -236,7 +180,7 @@ def join_session_keyring(name): def session_to_parent(): cdef int rc with nogil: - rc = c_session_to_parent() + rc = ckeyutils.c_session_to_parent() if rc < 0: PyErr_SetFromErrno(error) else: @@ -246,7 +190,7 @@ def session_to_parent(): def link(int key, int keyring): cdef int rc with nogil: - rc = c_link(key, keyring) + rc = ckeyutils.c_link(key, keyring) if rc < 0: PyErr_SetFromErrno(error) else: @@ -256,7 +200,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.c_unlink(key, keyring) if rc < 0: PyErr_SetFromErrno(error) else: @@ -266,7 +210,7 @@ def unlink(int key, int keyring): def revoke(int key): cdef int rc with nogil: - rc = c_revoke(key) + rc = ckeyutils.c_revoke(key) if rc < 0: PyErr_SetFromErrno(error) else: @@ -277,7 +221,7 @@ def set_perm(int key, int perm): cdef int rc cdef int keyperm with nogil: - rc = c_setperm(key, perm) + rc = ckeyutils.c_setperm(key, perm) if rc < 0: PyErr_SetFromErrno(error) else: @@ -287,7 +231,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.c_set_timeout(key, timeout) if rc < 0: PyErr_SetFromErrno(error) else: @@ -297,7 +241,7 @@ def set_timeout(int key, int timeout): def clear(int keyring): cdef int rc with nogil: - rc = c_clear(keyring) + rc = ckeyutils.c_clear(keyring) if rc < 0: PyErr_SetFromErrno(error) else: diff --git a/keyutils/ckeyutils.pxd b/keyutils/ckeyutils.pxd new file mode 100644 index 0000000..b81b697 --- /dev/null +++ b/keyutils/ckeyutils.pxd @@ -0,0 +1,55 @@ +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) \ No newline at end of file From 64418602c6f4413cb0a3c91aab97e7ea13e938d1 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Sun, 8 Oct 2023 14:38:32 -0400 Subject: [PATCH 2/5] denamespace c externs --- keyutils/_keyutils.pyx | 102 +++++++++++++++++++-------------------- keyutils/ckeyutils.pxd | 105 ++++++++++++++++++++--------------------- 2 files changed, 102 insertions(+), 105 deletions(-) diff --git a/keyutils/_keyutils.pyx b/keyutils/_keyutils.pyx index 38712f9..f5f8033 100644 --- a/keyutils/_keyutils.pyx +++ b/keyutils/_keyutils.pyx @@ -28,43 +28,43 @@ class error(Exception): class constants: - KEY_SPEC_THREAD_KEYRING = ckeyutils.c_KEY_SPEC_THREAD_KEYRING - KEY_SPEC_PROCESS_KEYRING = ckeyutils.c_KEY_SPEC_PROCESS_KEYRING - KEY_SPEC_SESSION_KEYRING = ckeyutils.c_KEY_SPEC_SESSION_KEYRING - KEY_SPEC_USER_KEYRING = ckeyutils.c_KEY_SPEC_USER_KEYRING - KEY_SPEC_USER_SESSION_KEYRING = ckeyutils.c_KEY_SPEC_USER_SESSION_KEYRING - ENOKEY = ckeyutils.c_ENOKEY - EKEYEXPIRED = ckeyutils.c_EKEYEXPIRED - EKEYREVOKED = ckeyutils.c_EKEYREVOKED - EKEYREJECTED = ckeyutils.c_EKEYREJECTED - KEY_POS_VIEW = ckeyutils.c_KEY_POS_VIEW - KEY_POS_READ = ckeyutils.c_KEY_POS_READ - KEY_POS_WRITE = ckeyutils.c_KEY_POS_WRITE - KEY_POS_SEARCH = ckeyutils.c_KEY_POS_SEARCH - KEY_POS_LINK = ckeyutils.c_KEY_POS_LINK - KEY_POS_SETATTR = ckeyutils.c_KEY_POS_SETATTR - KEY_POS_ALL = ckeyutils.c_KEY_POS_ALL - KEY_USR_VIEW = ckeyutils.c_KEY_USR_VIEW - KEY_USR_READ = ckeyutils.c_KEY_USR_READ - KEY_USR_WRITE = ckeyutils.c_KEY_USR_WRITE - KEY_USR_SEARCH = ckeyutils.c_KEY_USR_SEARCH - KEY_USR_LINK = ckeyutils.c_KEY_USR_LINK - KEY_USR_SETATTR = ckeyutils.c_KEY_USR_SETATTR - KEY_USR_ALL = ckeyutils.c_KEY_USR_ALL - KEY_GRP_VIEW = ckeyutils.c_KEY_GRP_VIEW - KEY_GRP_READ = ckeyutils.c_KEY_GRP_READ - KEY_GRP_WRITE = ckeyutils.c_KEY_GRP_WRITE - KEY_GRP_SEARCH = ckeyutils.c_KEY_GRP_SEARCH - KEY_GRP_LINK = ckeyutils.c_KEY_GRP_LINK - KEY_GRP_SETATTR = ckeyutils.c_KEY_GRP_SETATTR - KEY_GRP_ALL = ckeyutils.c_KEY_GRP_ALL - KEY_OTH_VIEW = ckeyutils.c_KEY_OTH_VIEW - KEY_OTH_READ = ckeyutils.c_KEY_OTH_READ - KEY_OTH_WRITE = ckeyutils.c_KEY_OTH_WRITE - KEY_OTH_SEARCH = ckeyutils.c_KEY_OTH_SEARCH - KEY_OTH_LINK = ckeyutils.c_KEY_OTH_LINK - KEY_OTH_SETATTR = ckeyutils.c_KEY_OTH_SETATTR - KEY_OTH_ALL = ckeyutils.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 + 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): @@ -80,7 +80,7 @@ def add_key(bytes key_type, bytes description, bytes payload, int keyring): payload_p = payload payload_len = len(payload) with nogil: - rc = ckeyutils.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: @@ -97,7 +97,7 @@ def request_key(bytes key_type, bytes description, bytes callout_info, int keyri else: callout_p = callout_info with nogil: - rc = ckeyutils.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: @@ -109,7 +109,7 @@ def search(int keyring, bytes key_type, bytes description, int destination): cdef char *desc_p = description cdef int rc with nogil: - rc = ckeyutils.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: @@ -127,7 +127,7 @@ def update_key(int key, bytes payload): payload_p = payload payload_len = len(payload) with nogil: - rc = ckeyutils.c_update(key, payload_p, payload_len) + rc = ckeyutils.update(key, payload_p, payload_len) if rc < 0: PyErr_SetFromErrno(error) else: @@ -139,7 +139,7 @@ def read_key(int key): cdef void *ptr cdef bytes obj with nogil: - size = ckeyutils.c_read_alloc(key, &ptr) + size = ckeyutils.read_alloc(key, &ptr) if size < 0: PyErr_SetFromErrno(error) else: @@ -153,7 +153,7 @@ def describe_key(int key): cdef char *ptr cdef bytes obj with nogil: - size = ckeyutils.c_describe_alloc(key, &ptr) + size = ckeyutils.describe_alloc(key, &ptr) if size < 0: PyErr_SetFromErrno(error) else: @@ -170,7 +170,7 @@ def join_session_keyring(name): else: name_p = name with nogil: - rc = ckeyutils.c_join_session_keyring(name_p) + rc = ckeyutils.join_session_keyring(name_p) if rc < 0: PyErr_SetFromErrno(error) else: @@ -180,7 +180,7 @@ def join_session_keyring(name): def session_to_parent(): cdef int rc with nogil: - rc = ckeyutils.c_session_to_parent() + rc = ckeyutils.session_to_parent() if rc < 0: PyErr_SetFromErrno(error) else: @@ -190,7 +190,7 @@ def session_to_parent(): def link(int key, int keyring): cdef int rc with nogil: - rc = ckeyutils.c_link(key, keyring) + rc = ckeyutils.link(key, keyring) if rc < 0: PyErr_SetFromErrno(error) else: @@ -200,7 +200,7 @@ def link(int key, int keyring): def unlink(int key, int keyring): cdef int rc with nogil: - rc = ckeyutils.c_unlink(key, keyring) + rc = ckeyutils.unlink(key, keyring) if rc < 0: PyErr_SetFromErrno(error) else: @@ -210,7 +210,7 @@ def unlink(int key, int keyring): def revoke(int key): cdef int rc with nogil: - rc = ckeyutils.c_revoke(key) + rc = ckeyutils.revoke(key) if rc < 0: PyErr_SetFromErrno(error) else: @@ -221,7 +221,7 @@ def set_perm(int key, int perm): cdef int rc cdef int keyperm with nogil: - rc = ckeyutils.c_setperm(key, perm) + rc = ckeyutils.setperm(key, perm) if rc < 0: PyErr_SetFromErrno(error) else: @@ -231,7 +231,7 @@ def set_perm(int key, int perm): def set_timeout(int key, int timeout): cdef int rc with nogil: - rc = ckeyutils.c_set_timeout(key, timeout) + rc = ckeyutils.set_timeout(key, timeout) if rc < 0: PyErr_SetFromErrno(error) else: @@ -241,7 +241,7 @@ def set_timeout(int key, int timeout): def clear(int keyring): cdef int rc with nogil: - rc = ckeyutils.c_clear(keyring) + rc = ckeyutils.clear(keyring) if rc < 0: PyErr_SetFromErrno(error) else: diff --git a/keyutils/ckeyutils.pxd b/keyutils/ckeyutils.pxd index b81b697..3359349 100644 --- a/keyutils/ckeyutils.pxd +++ b/keyutils/ckeyutils.pxd @@ -1,55 +1,52 @@ 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) \ No newline at end of file + 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_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" + 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" + 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" + 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) From 47e32602e3c963d3c319a1ce107a8ed44beaee75 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Sun, 8 Oct 2023 14:49:30 -0400 Subject: [PATCH 3/5] add comments and missing KEY_SPEC --- keyutils/_keyutils.pyx | 2 ++ keyutils/ckeyutils.pxd | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/keyutils/_keyutils.pyx b/keyutils/_keyutils.pyx index f5f8033..47bb81b 100644 --- a/keyutils/_keyutils.pyx +++ b/keyutils/_keyutils.pyx @@ -33,6 +33,8 @@ class constants: 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 diff --git a/keyutils/ckeyutils.pxd b/keyutils/ckeyutils.pxd index 3359349..17e7b4b 100644 --- a/keyutils/ckeyutils.pxd +++ b/keyutils/ckeyutils.pxd @@ -1,9 +1,13 @@ 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" @@ -11,6 +15,8 @@ cdef extern from "keyutils.h" nogil: 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" @@ -18,6 +24,8 @@ cdef extern from "keyutils.h" nogil: 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" @@ -25,6 +33,8 @@ cdef extern from "keyutils.h" nogil: 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" @@ -32,6 +42,7 @@ cdef extern from "keyutils.h" nogil: 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" From a0eac0727fd0c33acdb94709853b222e98af9115 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Sun, 8 Oct 2023 15:01:08 -0400 Subject: [PATCH 4/5] prep for release --- ChangeLog | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f9d7f43..7fa28d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/setup.py b/setup.py index b5d3725..456a21f 100644 --- a/setup.py +++ b/setup.py @@ -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", From a40f53938ae76834840777aa9bc4a23c04a564b4 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Sun, 8 Oct 2023 15:48:53 -0400 Subject: [PATCH 5/5] lint --- keyutils/_keyutils.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keyutils/_keyutils.pyx b/keyutils/_keyutils.pyx index 47bb81b..6dd02e7 100644 --- a/keyutils/_keyutils.pyx +++ b/keyutils/_keyutils.pyx @@ -16,8 +16,10 @@ # 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)