changelog shortlog graph tags branches files raw help

Mercurial > core / changeset: keyctl api

changeset 506: bc0ea6a5c252
parent 505: da3a08c89941
child 507: 4dd7b6320efc
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 03 Jul 2024 22:21:46 -0400
files: lisp/ffi/keyutils/keyctl.lisp lisp/ffi/keyutils/keyutils.asd lisp/ffi/keyutils/pkg.lisp lisp/ffi/keyutils/tests.lisp readme.org
description: keyctl api
     1.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2+++ b/lisp/ffi/keyutils/keyctl.lisp	Wed Jul 03 22:21:46 2024 -0400
     1.3@@ -0,0 +1,70 @@
     1.4+;;; keyctl.lisp --- Keyctl API Functions
     1.5+
     1.6+;; 
     1.7+
     1.8+;;; Code:
     1.9+(in-package :keyutils)
    1.10+
    1.11+(macrolet ((def (name &rest args)
    1.12+               `(progn
    1.13+                  (define-alien-routine ,name key-serial-t ,@args)
    1.14+                  ,@(if (atom name)
    1.15+                        `((export ',name))
    1.16+                        `((export ',(cadr name))))))
    1.17+           (defint (name &rest args)
    1.18+             `(progn
    1.19+                (define-alien-routine ,name int ,@args)
    1.20+                (export ',name)))
    1.21+           (deflong (name &rest args)
    1.22+             `(progn
    1.23+                (define-alien-routine ,name long ,@args)
    1.24+                (export ',name))))
    1.25+  (def add-key (type c-string) (description c-string) (payload (* t)) (plen size-t) (ringid key-serial-t))
    1.26+  (def request-key (type c-string) (description c-string) (callout-info c-string) (destringid key-serial-t))
    1.27+  ;; variadic? ... prob not supported by sb-alien
    1.28+  (deflong keyctl (cmd int))
    1.29+  (def ("keyctl_get_keyring_ID" keyctl-get-keyring-id) (id key-serial-t) (create int))
    1.30+  (def keyctl-join-session-keyring (name c-string))
    1.31+  (deflong keyctl-update (id key-serial-t) (payload (* t)) (plen size-t))
    1.32+  (deflong keyctl-revoke (id key-serial-t))
    1.33+  (deflong keyctl-chown (id key-serial-t) (uid sb-unix:uid-t) (gid sb-unix:gid-t))
    1.34+  (deflong keyctl-setperm (id key-serial-t) (perm key-perm-t))
    1.35+  (deflong keyctl-describe (id key-serial-t) (buffer c-string) (buflen size-t))
    1.36+  (deflong keyctl-clear (ringid key-serial-t))
    1.37+  (deflong keyctl-link (id key-serial-t) (ringid key-serial-t))
    1.38+  (deflong keyctl-unlink (id key-serial-t) (ringid key-serial-t))
    1.39+  (deflong keyctl-search (ringid key-serial-t) (type c-string) (description c-string) (destringid key-serial-t))
    1.40+  (deflong keyctl-read (id key-serial-t) (buffer c-string) (buflen size-t))
    1.41+  (deflong keyctl-instantiate (id key-serial-t) (payload (* t)) (plen size-t) (ringid key-serial-t))
    1.42+  (deflong keyctl-negate (id key-serial-t) (timeout unsigned) (ringid key-serial-t))
    1.43+  (deflong keyctl-set-reqkey-keyring (reqkey-defl int))
    1.44+  (deflong keyctl-set-timeout (key key-serial-t) (timeout unsigned))
    1.45+  (deflong keyctl-assume-authority (key key-serial-t))
    1.46+  (deflong keyctl-get-security (key key-serial-t) (buffer c-string) (buflen size-t))
    1.47+  (deflong keyctl-session-to-parent)
    1.48+  (deflong keyctl-reject (id key-serial-t) (timeout unsigned) (error unsigned) (ringid key-serial-t))
    1.49+  (deflong keyctl-instantiate-iov (id key-serial-t) (payload-iov (* iovec)) (ioc unsigned) (ringid key-serial-t))
    1.50+  (deflong keyctl-invalidate (id key-serial-t))
    1.51+  (deflong keyctl-get-persistent (uid sb-unix:uid-t) (id key-serial-t))
    1.52+  (deflong keyctl-dh-compute (priv key-serial-t) (prime key-serial-t)
    1.53+    (base key-serial-t) (buffer c-string) (buflen size-t))
    1.54+  (deflong keyctl-dh-compute-kdf (priv key-serial-t) (prime key-serial-t) (base key-serial-t) (hashname c-string)
    1.55+    (otherinfo c-string) (otherinfolen size-t) (buffer c-string) (buflen size-t))
    1.56+  (deflong keyctl-pkey-query (key-id key-serial-t) (info c-string) (result (* keyctl-pkey-query)))
    1.57+  (deflong keyctl-pkey-encrypt (key-id key-serial-t) (info c-string) (data (* t)) (data-len size-t))
    1.58+  (deflong keyctl-pkey-decrypt (key-id key-serial-t) (info c-string) (enc (* t)) (enc-len size-t))
    1.59+  (deflong keyctl-pkey-sign (key-id key-serial-t) (info c-string) (data (* t)) (data-len size-t))
    1.60+  (deflong keyctl-pkey-verify (key-id key-serial-t) (info c-string) (data (* t)) (data-len size-t)
    1.61+    (sig (* t)) (sig-len size-t))
    1.62+  (deflong keyctl-move (id key-serial-t) (from-ringid key-serial-t) (to-ringid key-serial-t) (flags unsigned-int))
    1.63+  (deflong keyctl-capabilities (buffer c-string) (len size-t))
    1.64+  (deflong keyctl-watch-key (id key-serial-t) (watch-queue-fd int) (watch-id int))
    1.65+  ;; utils
    1.66+  (defint keyctl-describe-alloc (id key-serial-t) (buffer (* c-string)))
    1.67+  (defint keyctl-read-alloc (id key-serial-t) (%buffer (* (* t))))
    1.68+  (defint keyctl-get-security-alloc (id key-serial-t) (%buffer (* (* t))))
    1.69+  (defint keyctl-dh-compute-alloc (priv key-serial-t) (prime key-serial-t)
    1.70+    (base key-serial-t) (%buffer (* (* t))))
    1.71+  ;; (defint recursive-key-scan)
    1.72+  ;; (defint recursive-session-key-scan)
    1.73+  (def find-key-by-type-and-desc (type c-string) (desc c-string) (destringid key-serial-t)))
     2.1--- a/lisp/ffi/keyutils/keyutils.asd	Wed Jul 03 17:38:51 2024 -0400
     2.2+++ b/lisp/ffi/keyutils/keyutils.asd	Wed Jul 03 22:21:46 2024 -0400
     2.3@@ -19,7 +19,8 @@
     2.4   :depends-on (:sb-grovel :std)
     2.5   :components ((:file "pkg")
     2.6                (grovel-constants-file "constants"
     2.7-                                      :package :keyutils))
     2.8+                                      :package :keyutils)
     2.9+               (:file "keyctl" :depends-on ("pkg" "constants")))
    2.10   :in-order-to ((test-op (test-op "keyutils/tests"))))
    2.11 
    2.12 (defsystem :keyutils/tests
     3.1--- a/lisp/ffi/keyutils/pkg.lisp	Wed Jul 03 17:38:51 2024 -0400
     3.2+++ b/lisp/ffi/keyutils/pkg.lisp	Wed Jul 03 22:21:46 2024 -0400
     3.3@@ -13,15 +13,25 @@
     3.4   (:use :cl :std :sb-alien)
     3.5   (:export 
     3.6    :keyutils-version-string
     3.7-   :keyutils-build-string))
     3.8+   :keyutils-build-string
     3.9+   :key-spec
    3.10+   :key-spec*))
    3.11 
    3.12 (in-package :keyutils)
    3.13 
    3.14+(define-alien-loader "keyutils" t "/usr/lib/")
    3.15+
    3.16 (define-alien-type iovec (struct nil))
    3.17 
    3.18 (define-alien-type key-serial-t (integer 32))
    3.19 (define-alien-type key-perm-t (unsigned 32))
    3.20 
    3.21+(define-alien-type keyctl-pkey-params (struct keyctl-pkey-params
    3.22+                                              (key-id key-serial-t)
    3.23+                                              (len1 unsigned-int)
    3.24+                                              (len2 unsigned-int)
    3.25+                                              (%sparse (array unsigned-int 7))))
    3.26+
    3.27 (define-alien-variable keyutils-version-string (array char))
    3.28 (define-alien-variable keyutils-build-string (array char))
    3.29 ;; (cast keyutils-version-string c-string) ;= "keyutils-1.6.3"
    3.30@@ -29,67 +39,12 @@
    3.31 
    3.32 ;; TODO: recursive_key_scanner_t
    3.33 
    3.34+(define-alien-enum (key-spec int)
    3.35+                   :thread +key-spec-thread-keyring+
    3.36+                   :process +key-spec-process-keyring+
    3.37+                   :session +key-spec-session-keyring+
    3.38+                   :user +key-spec-user-keyring+
    3.39+                   :user-session +key-spec-user-session-keyring+
    3.40+                   :group +key-spec-group-keyring+
    3.41+                   :reqkey-auth +key-spec-reqkey-auth-key+)
    3.42 
    3.43-(macrolet ((def (name &rest args)
    3.44-               `(progn
    3.45-                  (define-alien-routine ,name key-serial-t ,@args)
    3.46-                  ,@(if (atom name)
    3.47-                        `((export ',name))
    3.48-                        `((export ',(cadr name))))))
    3.49-           (defint (name &rest args)
    3.50-             `(progn
    3.51-                (define-alien-routine ,name int ,@args)
    3.52-                (export ',name)))
    3.53-           (deflong (name &rest args)
    3.54-             `(progn
    3.55-                (define-alien-routine ,name long ,@args)
    3.56-                (export ',name))))
    3.57-  (def add-key (type c-string) (description c-string) (payload (* t)) (plen size-t) (ringid key-serial-t))
    3.58-  (def request-key (type c-string) (description c-string) (callout-info c-string) (destringid key-serial-t))
    3.59-  ;; variadic? ... prob not supported by sb-alien
    3.60-  (deflong keyctl (cmd int))
    3.61-  (def ("keyctl_get_keyring_ID" keyctl-get-keyring-id) (id key-serial-t) (create int))
    3.62-  (def keyctl-join-session-keyring (name c-string))
    3.63-  (deflong keyctl-update (id key-serial-t) (payload (* t)) (plen size-t))
    3.64-  (deflong keyctl-revoke (id key-serial-t))
    3.65-  (deflong keyctl-chown (id key-serial-t) (uid sb-unix:uid-t) (gid sb-unix:gid-t))
    3.66-  (deflong keyctl-setperm (id key-serial-t) (perm key-perm-t))
    3.67-  (deflong keyctl-describe (id key-serial-t) (buffer c-string) (buflen size-t))
    3.68-  (deflong keyctl-clear (ringid key-serial-t))
    3.69-  (deflong keyctl-link (id key-serial-t) (ringid key-serial-t))
    3.70-  (deflong keyctl-unlink (id key-serial-t) (ringid key-serial-t))
    3.71-  (deflong keyctl-search (ringid key-serial-t) (type c-string) (description c-string) (destringid key-serial-t))
    3.72-  (deflong keyctl-read (id key-serial-t) (buffer c-string) (buflen size-t))
    3.73-  (deflong keyctl-instantiate (id key-serial-t) (payload (* t)) (plen size-t) (ringid key-serial-t))
    3.74-  (deflong keyctl-negate (id key-serial-t) (timeout unsigned) (ringid key-serial-t))
    3.75-  (deflong keyctl-set-reqkey-keyring (reqkey-defl int))
    3.76-  (deflong keyctl-set-timeout (key key-serial-t) (timeout unsigned))
    3.77-  (deflong keyctl-assume-authority (key key-serial-t))
    3.78-  (deflong keyctl-get-security (key key-serial-t) (buffer c-string) (buflen size-t))
    3.79-  (deflong keyctl-session-to-parent)
    3.80-  (deflong keyctl-reject (id key-serial-t) (timeout unsigned) (error unsigned) (ringid key-serial-t))
    3.81-  (deflong keyctl-instantiate-iov (id key-serial-t) (payload-iov (* iovec)) (ioc unsigned) (ringid key-serial-t))
    3.82-  (deflong keyctl-invalidate (id key-serial-t))
    3.83-  (deflong keyctl-get-persistent (uid sb-unix:uid-t) (id key-serial-t))
    3.84-  (deflong keyctl-dh-compute (priv key-serial-t) (prime key-serial-t)
    3.85-    (base key-serial-t) (buffer c-string) (buflen size-t))
    3.86-  (deflong keyctl-dh-compute-kdf (priv key-serial-t) (prime key-serial-t) (base key-serial-t) (hashname c-string)
    3.87-    (otherinfo c-string) (otherinfolen size-t) (buffer c-string) (buflen size-t))
    3.88-  (deflong keyctl-pkey-query (key-id key-serial-t) (info c-string) (result (* keyctl-pkey-query)))
    3.89-  (deflong keyctl-pkey-encrypt (key-id key-serial-t) (info c-string) (data (* t)) (data-len size-t))
    3.90-  (deflong keyctl-pkey-decrypt (key-id key-serial-t) (info c-string) (enc (* t)) (enc-len size-t))
    3.91-  (deflong keyctl-pkey-sign (key-id key-serial-t) (info c-string) (data (* t)) (data-len size-t))
    3.92-  (deflong keyctl-pkey-verify (key-id key-serial-t) (info c-string) (data (* t)) (data-len size-t)
    3.93-    (sig (* t)) (sig-len size-t))
    3.94-  (deflong keyctl-move (id key-serial-t) (from-ringid key-serial-t) (to-ringid key-serial-t) (flags unsigned-int))
    3.95-  (deflong keyctl-capabilities (buffer c-string) (len size-t))
    3.96-  (deflong keyctl-watch-key (id key-serial-t) (watch-queue-fd int) (watch-id int))
    3.97-  ;; utils
    3.98-  (defint keyctl-describe-alloc (id key-serial-t) (buffer (* c-string)))
    3.99-  (defint keyctl-read-alloc (id key-serial-t) (%buffer (* (* t))))
   3.100-  (defint keyctl-get-security-alloc (id key-serial-t) (%buffer (* (* t))))
   3.101-  (defint keyctl-dh-compute-alloc (priv key-serial-t) (prime key-serial-t)
   3.102-    (base key-serial-t) (%buffer (* (* t))))
   3.103-  ;; (defint recursive-key-scan)
   3.104-  ;; (defint recursive-session-key-scan)
   3.105-  (def find-key-by-type-and-desc (type c-string) (desc c-string) (destringid key-serial-t)))
     4.1--- a/lisp/ffi/keyutils/tests.lisp	Wed Jul 03 17:38:51 2024 -0400
     4.2+++ b/lisp/ffi/keyutils/tests.lisp	Wed Jul 03 22:21:46 2024 -0400
     4.3@@ -12,7 +12,15 @@
     4.4 (load-keyutils)
     4.5 
     4.6 (deftest sanity ()
     4.7-  (is (string= "keyutils" (car (ssplit #\- (cast keyutils-version-string c-string))))))
     4.8+  (is (string= "keyutils" (car (ssplit #\- (cast keyutils-version-string c-string)))))
     4.9+  (is (every 'minusp (list (key-spec :thread)
    4.10+                             (key-spec :user)
    4.11+                             (key-spec :user-session)
    4.12+                             (key-spec :session)
    4.13+                             (key-spec :group)
    4.14+                             (key-spec :process)
    4.15+                             (key-spec :thread)
    4.16+                             (key-spec :reqkey-auth)))))
    4.17 
    4.18 (deftest keyutils ()
    4.19   (let ((session-id (keyctl-join-session-keyring (symbol-name (gensym "test")))))
     5.1--- a/readme.org	Wed Jul 03 17:38:51 2024 -0400
     5.2+++ b/readme.org	Wed Jul 03 22:21:46 2024 -0400
     5.3@@ -240,7 +240,7 @@
     5.4 
     5.5 #+RESULTS:
     5.6 #+begin_example
     5.7-skel v0.1.1 --- A hacker's project compiler.
     5.8+skel v0.1.1:0e043dcda8f4+ --- A hacker's project compiler.
     5.9 
    5.10   usage: skel [global] <command> [<arg>]
    5.11 
    5.12@@ -320,9 +320,7 @@
    5.13 
    5.14 #+RESULTS:
    5.15 #+begin_example
    5.16-#:debug 0.026666; (#S(CLI-NODE
    5.17-                      :KIND OPT
    5.18-                      :FORM #<CLI-OPT help :global T :val T>))
    5.19+#:debug 0.44; (#S(CLI-NODE :KIND OPT :FORM #<CLI-OPT help :global T :val T>))
    5.20 packy v0.1.0 --- Universal Package Manager
    5.21 
    5.22   usage: packy [global] <command> [<arg>]
    5.23@@ -334,7 +332,7 @@
    5.24 
    5.25 commands:
    5.26   show 
    5.27-#:debug 0.033333; /home/ellis/comp/core
    5.28+#:debug 0.453333; /home/ellis/comp/core
    5.29 ; #(#<CLI-OPT help :global T :val NIL>)
    5.30 ; NIL
    5.31 ; #()
    5.32@@ -398,7 +396,7 @@
    5.33 
    5.34 #+RESULTS:
    5.35 
    5.36-** krypt                                                               :rust:
    5.37+** COMMENT krypt                                                       :lisp:
    5.38 #+begin_src shell :results output :exports both
    5.39 krypt --help
    5.40 #+end_src