KEYCTL_GET_KEYRING_ID(3)
π KEYCTL_GET_KEYRING_ID π
okay bestie, so this one lives in the Linux Key Management Calls section of the manual (section 3, the library-function girlies), and it's genuinely so useful once you get it. let's go π«Ά
β¨ NAME β¨
keyctl_get_keyring_ID β the function that gets you the ID of a special keyring. yes, the name is long, yes it's giving "my parents named me after a syscall", we move on π
πΈ SYNOPSIS πΈ
#include <keyutils.h>
key_serial_t keyctl_get_keyring_ID(key_serial_t key,
int create);
like. look at her. two args. one job. iconic.
π¦ DESCRIPTION π¦
okay so keyctl_get_keyring_ID() does the thing where it maps a special key or keyring ID to the actual serial number of the key that's really representing that feature. and if that key exists? boom, you get the serial number back. that's it, that's the whole vibe.
and if the key or keyring doesn't exist yet? well. if create is non-zero, then the key or keyring gets created β but only if it's appropriate to do so. (the manpage is being mysterious about "appropriate" and honestly? same.)
these are the special key IDs you're allowed to pass in as key, and they are not interchangeable, so pay attention bestie:
KEY_SPEC_THREAD_KEYRINGβ this one specifies the caller's thread-specific keyring. yes, per-thread. your threads each get their own. main character energy for every single thread πKEY_SPEC_PROCESS_KEYRINGβ this specifies the caller's process-specific keyring. so, one per process.KEY_SPEC_SESSION_KEYRINGβ this specifies the caller's session-specific keyring. the session one. you know the one.KEY_SPEC_USER_KEYRINGβ this specifies the caller's UID-specific keyring. keyed off your UID, not your vibes.KEY_SPEC_USER_SESSION_KEYRINGβ this specifies the caller's UID-session keyring. yes it's a different thing from the previous two, no you may not merge them, they are siblings not twins πKEY_SPEC_REQKEY_AUTH_KEYβ this specifies the authorisation key created byrequest_key()and passed to the process it spawns to generate a key. very specific, very niche, very "you'll know if you need it" β¨
and then the last little rule, which is important so don't skip it: if a valid keyring ID is passed in, then this will simply be returned β if the key exists. and if it doesn't exist? an error gets issued. no key, no serial, no mercy π
π₯ RETURN VALUE π₯
- on success,
keyctl_get_keyring_ID()returns the serial number of the key it found. slay. π - on error, the value
-1gets returned anderrnowill have been set to an appropriate error. so like, checkerrno, bestie, don't just stare at the-1.
π ERRORS π
ENOKEYβ no matching key was found. she looked. she did not find. πENOMEMβ insufficient memory to create a key. out of RAM, out of luck.EDQUOTβ the key quota for this user would be exceeded by creating this key or linking it to the keyring. you hit your limit, babe, and the limit hit back.
π LINKING π
this is a library function and it can be found in libkeyutils. so when you're linking, you need to pass -lkeyutils to the linker. that's it. that's the whole tip. do not forget it or the linker will simply Not. π«
β SEE ALSO β
keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3), keyrings(7), keyutils(7)
go read those too, they're all in the group chat π
ngl, the create flag is lowkey the whole plot twist of this function β everything else is just mapping. treat it with respect. π
and that's the page, bestie!! this one's from Linux, dated 4 May 2006 β yeah, she's an elder icon but she still ate π
β¨ bye ily, go link with -lkeyutils π¦πΈ
π¦ where this page comes from
- alpine 3.22: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.23: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- alpine 3.24: keyutils-doc 1.6.3-r4 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- arch rolling: keyutils 1.6.3-4 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 10: keyutils-libs-devel 1.6.3-5.el10 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- centos-stream 9: keyutils-libs-devel 1.6.3-1.el9 Β· GPLv2+ and LGPLv2+
- debian bookworm: libkeyutils-dev 1.6.3-2 Β· GPL-2.0-or-later
- debian trixie: libkeyutils-dev 1.6.3-6 Β· GPL-2.0-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 43: keyutils-libs-devel 1.6.3-6.fc43 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- fedora 44: keyutils-libs-devel 1.6.3-7.fc44 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- nixpkgs unstable: keyutils 1.6.3
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- opensuse-leap 16.0: keyutils 1.6.3-160000.3.2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later
- ubuntu jammy: libkeyutils-dev 1.6.1-2ubuntu3 Β· GPL-2.0-or-later
- ubuntu noble: libkeyutils-dev 1.6.3-3build1 Β· GPL-2.0-or-later
- ubuntu questing: libkeyutils-dev 1.6.3-6ubuntu2
- ubuntu resolute: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- ubuntu stonking: libkeyutils-dev 1.6.3-6ubuntu3 Β· GPL-2.0-or-later
- Copyright (C) 2006 Red Hat, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms