getseuserbyname(3)

πŸ“¦
version 3.11 Β· 2 versions
, in alpine 3.24, centos-stream 10, centos-stream 9, debian bookworm, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble

πŸ’… getseuserbyname(3) β€” the SELinux API doc page, bestie edition

okay so you're poking around in selinux land and you found getseuserbyname?? slay, let's get you fluent. this is a page from the SELinux API documentation, and it's literally the glow-up translator between your regular Linux username and your SELinux username + level. no cap. πŸ¦‹


✨ NAME ✨

getseuserbyname β€” get the SELinux username and level for a given Linux username πŸ‘‘


🌸 SYNOPSIS 🌸

#include <selinux/selinux.h>

int getseuserbyname(const char *linuxuser, char **selinuxuser, char **level);

that's it, that's the whole vibe. one function, three args, main character energy. πŸ’–


πŸŽ€ DESCRIPTION πŸŽ€

okay so getseuserbyname() goes and fetches the SELinux username and the security level that are associated with a given Linux username. like, you hand it a normal login name and it hands you back the SELinux-flavoured identity that goes with it. so iconic of it. ✨

and the tea is: once you have that SELinux username and security level, you can pass them along to other libselinux functions β€” the page literally name-drops get_ordered_context_list_with_level(3) and get_default_context_with_level(3) as the besties you'd send them to. 🫢

real talk though β€” the returned SELinux username and level should be freed by the caller using free. not me letting you leak memory, bestie, please free them. πŸ’€

πŸ’– RETURN VALUE πŸ’–

  • on the slay path: 0 is returned. periodt.
  • on the not-slay path: -1 is returned, and errno is set appropriately. πŸ‘€

also, the errors documented for the stat(2) system call are applicable here too β€” so if you know your stat(2) errno lore, it transfers. iykyk. 🌈


πŸ‘‘ SEE ALSO πŸ‘‘


🧚 cute sign-off 🧚

this lil gem was written by dwalsh@redhat.com and dated 29 September 2005 β€” yeah it's been serving SELinux realness since 2005 and it still ate. πŸ’…βœ¨ take care of those free calls and you're golden, bestie. πŸŽ€πŸ¦‹πŸ’œ