From 612b715d9be0138c7ab4b54b56f8f9c59f8a456f Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Fri, 17 Sep 2021 17:03:54 +0200 Subject: [PATCH 1/3] Fix Unlink() by correcting the argument order. --- keyring.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyring.go b/keyring.go index 7896694..5f3f1fe 100644 --- a/keyring.go +++ b/keyring.go @@ -181,7 +181,7 @@ func SetKeyringTTL(kr NamedKeyring, nsecs uint) error { // Unlink an object from a keyring func Unlink(parent Keyring, child Id) error { - return keyctl_Unlink(keyId(parent.Id()), keyId(child.Id())) + return keyctl_Unlink(keyId(child.Id()), keyId(parent.Id())) } // Unlink a named keyring from its parent. From e4580577951b2b85d12ded693ea27411c6a33184 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Fri, 17 Sep 2021 17:04:31 +0200 Subject: [PATCH 2/3] Add link syscall required to link keys and keyrings. --- sys_linux.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys_linux.go b/sys_linux.go index 85383b4..0c4c194 100644 --- a/sys_linux.go +++ b/sys_linux.go @@ -102,6 +102,14 @@ func keyctl_Read(id keyId, b *byte, size int) (int32, error) { return int32(v1), nil } +func keyctl_Link(id, ring keyId) error { + _, _, errno := syscall.Syscall(syscall_keyctl, uintptr(keyctlLink), uintptr(id), uintptr(ring)) + if errno != 0 { + return errno + } + return nil +} + func keyctl_Unlink(id, ring keyId) error { _, _, errno := syscall.Syscall(syscall_keyctl, uintptr(keyctlUnlink), uintptr(id), uintptr(ring)) if errno != 0 { From 0dde376d07d0bccbf89887f3ef64695e74796576 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Fri, 17 Sep 2021 17:05:35 +0200 Subject: [PATCH 3/3] Implement Link() function based on the keyctl_Link() syscall. --- keyring.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/keyring.go b/keyring.go index 5f3f1fe..5c5a9b9 100644 --- a/keyring.go +++ b/keyring.go @@ -179,6 +179,11 @@ func SetKeyringTTL(kr NamedKeyring, nsecs uint) error { return err } +// Link an object to a keyring +func Link(parent Keyring, child Id) error { + return keyctl_Link(keyId(child.Id()), keyId(parent.Id())) +} + // Unlink an object from a keyring func Unlink(parent Keyring, child Id) error { return keyctl_Unlink(keyId(child.Id()), keyId(parent.Id()))