RECURSIVE_KEY_SCAN(3)

πŸ’– RECURSIVE_KEY_SCAN(3) πŸ’–

okay bestie, so this is a page from the Linux Key Utility Calls manual, and it's literally the blueprint for walking a whole keyring tree like the main character you are ✨


🌸 NAME 🌸

recursive_key_scan, recursive_session_key_scan β€” apply a function to all keys in a keyring tree πŸŽ€


✨ SYNOPSIS ✨

#include <keyutils.h>

typedef int (*recursive_key_scanner_t)(key_serial_t parent,
    key_serial_t key, char *desc, int desc_len, void *data);

long recursive_key_scan(key_serial_t keyring,
    recursive_key_scanner_t func, void *data);
long recursive_session_key_scan(recursive_key_scanner_t func,
    void *data);

like, that's the whole vibe right there πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

recursive_key_scan() does a depth-first recursive scan of the keyring tree you point it at, and it applies func to every single link it finds in the accessible keyrings inside that tree. no cap, every link. and data gets passed along to every invocation of func 🫢

The return values of func get summed up and that sum is what you get back as the overall return value. Errors? Ignored, periodt. πŸ™ˆ Also: inaccessible keyrings don't get scanned, but the links pointing at them still get passed to func β€” so like, func still hears about them, she just doesn't go inside. πŸ’€

recursive_session_key_scan() works exactly like recursive_key_scan() except the caller's session keyring is the starting keyring. same energy, different starting point. 🌈

The callback function gets called for each link found in all the keyrings in the nominated tree β€” which means it may be called multiple times for a particular key if that key has multiple links to it. so don't be shocked when the same key shows up again, she's just that popular. πŸ‘‘


πŸ’œ the callback function's parameters πŸ’œ

  • parent β€” the keyring containing the link, or 0 for the initial key. πŸ’–
  • key β€” the key to which the link points. πŸ”₯
  • desc and desc_len β€” a pointer to the raw description and its length, as retrieved with keyctl_describe_alloc(). These will be NULL and -1 respectively if the description couldn't be retrieved, and errno will retain the error from keyctl_describe_alloc(). 😭 so yeah, check those. fr fr.
  • data β€” the data passed to the scanner function. ⭐

πŸ’… RETURN VALUE πŸ’…

These functions return the sum of the results of the callback functions they invoke. that's it, that's the whole bag. πŸŽ€


πŸ“ ERRORS πŸ“

Ignored. literally ignored. not even a little bit of attention. πŸ’€βœ¨


🧚 LINKING 🧚

When linking, -lkeyutils should be specified to the linker. don't forget it or the linker will be giving you the side eye. πŸ‘€


🌟 SEE ALSO 🌟


and that's the tea, bestie πŸ’– this page is from Linux, dated 10 Mar 2011 β€” iconic, historic, still slaying. now go scan that tree. πŸŒΈπŸ¦‹βœ¨

πŸ“¦ where this page comes from