avc_context_to_sid(3)

πŸ“¦
version 3.11 Β· 2 versions
, in alpine 3.24, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– avc_context_to_sid β€” SELinux security ID's, but make it make sense πŸ’–

okay bestie, welcome to the avc_context_to_sid(3) page from the SELinux API documentation ✨ this is a manual page, section 3, and we're gonna get you fluent in SID's, no cap 🫢


🌸 NAME 🌸

avc_context_to_sid, avc_sid_to_context, avc_get_initial_sid β€” obtain and manipulate SELinux security ID's πŸ‘‘

like, the whole girl squad of SID functions, all in one page πŸ’…


✨ SYNOPSIS ✨

#include <selinux/selinux.h>
#include <selinux/avc.h>

int avc_context_to_sid(const char *ctx, security_id_t *sid);

int avc_sid_to_context(security_id_t sid, char **ctx);

int avc_get_initial_sid(const char *name, security_id_t *sid);

look at those includes, they're literally iconic πŸŽ€ copy them exactly, don't get cute with them.


πŸ¦‹ DESCRIPTION πŸ¦‹

Security ID's (SID's) are opaque representations of security contexts, managed by the userspace AVC. so like… you don't get to peek inside them, bestie. they're mysterious on purpose. main character energy 🧚

avc_context_to_sid() returns a SID for the given context, and it puts it in the memory referenced by sid. context in, SID out, slay ✨

avc_sid_to_context() returns a copy of the context represented by sid, and it puts it in the memory referenced by ctx. and yes, it's a copy β€” you gotta free it yourself with freecon(3) or that memory is gonna haunt you fr fr 😭

avc_get_initial_sid() returns a SID for the kernel initial security identifier specified by name. the kernel said "here's my initial SID" and we said "yes queen" πŸ’œ


πŸ’« RETURN VALUE πŸ’«

avc_context_to_sid() and avc_sid_to_context() return zero on success. πŸŽ‰

on error, -1 is returned and errno is set appropriately. so check your errno, bestie, it's trying to tell you something πŸ‘€


πŸ’€ ERRORS πŸ’€

  • ENOMEM β€” an attempt to allocate memory failed. the malloc said "not today" πŸ˜­πŸ’”

πŸ”₯ NOTES πŸ”₯

as of libselinux version 2.0.86, SID's are no longer reference counted. periodt.

a SID will be valid from the time it is first obtained until the next call to avc_destroy(3). that's the whole lifespan, no extensions, no takebacks 🌈

and the sidget(3) and sidput(3) functions β€” formerly used to adjust the reference count β€” are no-ops and are deprecated. they're giving retired. they show up, they do nothing, they leave πŸ™ˆ don't build your whole personality on them.


πŸ‘‘ AUTHOR πŸ‘‘

Eamon Walsh <ewalsh@tycho.nsa.gov> β€” thank you for your service, legend 🫢


🌟 SEE ALSO 🌟

avc_init(3), avc_has_perm(3), avc_cache_stats(3), avc_add_callback(3), getcon(3), freecon(3), selinux(8)


and that's the whole page, bestie πŸ’– this one dropped way back on 27 May 2004 as part of the SELinux API documentation β€” and yeah, avc_context_to_sid(3) is still out here being useful, we love a timeless icon ⭐ go forth and SID responsibly πŸŽ€πŸŒΈπŸ¦‹