security_c..._to_string(3)
π security_c..._to_string(3) β the SELinux glow-up translation station π
okay bestie, welcome to the SELinux API documentation corner of the manual (yes, the (3) section, we're in library-function territory, very demure). this page is literally about converting back and forth between SELinux class and permission values and their string names, and also print_access_vector which shows you an access vector in human-readable form. it's giving translator app but for kernel security labels. slay.
β¨ NAME β¨
security_class_to_string, security_av_perm_to_string, string_to_security_class, string_to_av_perm, security_av_string, mode_to_security_class β these cuties convert between SELinux class and permission values and string names.
also print_access_vector β this one displays an access vector in human-readable form. π
πΈ SYNOPSIS πΈ
#include <selinux/selinux.h>
const char *security_class_to_string(security_class_t tclass);
const char *security_av_perm_to_string(security_class_t tclass,
access_vector_t av);
int security_av_string(security_class_t tclass, access_vector_t av, char
**result);
security_class_t string_to_security_class(const char *name);
security_class_t mode_to_security_class(mode_t mode);
access_vector_t string_to_av_perm(security_class_t tclass, const char
*name);
void print_access_vector(security_class_t tclass, access_vector_t av);
π¦ DESCRIPTION π¦
okay so here's the whole friend group, one by one. no skipping, bestie, they all matter. π
security_class_to_string() β hands you a string name for the class tclass. if the class is invalid? it just gives you NULL. rude but fair. and listen: the returned string must not be modified or freed. it's not yours, don't touch it, don't free it, it's borrowed. π
security_av_perm_to_string() β gives you a string name for the access vector bit av of class tclass, or NULL if either argument is invalid. same rules as above: the returned string must not be modified or freed. hands off, bestie. β
security_av_string() β this one's the overachiever. it computes a full access vector string representation using tclass and av, and av can have multiple bits set (main character energy, honestly). the string gets returned in the memory pointed to by result, and the caller should free it using free(3). yes, this one IS yours to free. we love a clear ownership situation. π«Ά
string_to_security_class() β reverse direction, icon behavior. returns the class value that corresponds to the string name name, or zero if no such class exists. zero means "nope, not a thing." π
mode_to_security_class() β returns the class value that corresponds to the specified mode, or zero if no such class exists. same zero-means-nope energy.
string_to_av_perm() β returns the access vector bit that corresponds to the string name name and security class tclass, or zero if no such value exists. guess what zero means. you already know. π
print_access_vector() β the vibes-only one. it displays an access vector in human-readable form on the standard output stream. that's it, that's the whole job, and it does it beautifully. β
π RETURN VALUE π
security_av_string()β returns zero on success or-1on error, witherrnoset appropriately.print_access_vector()β does not return a value. it's avoid, she simply doesn't do returns, she does statements. π- all the other functions β return zero or
NULLon error.
π ERRORS π
EINVALβ a class or access vector argument is not recognized by the currently loaded policy. i.e. the policy has never heard of this. it's not on the list. it's not invited to the party. πENOMEMβ an attempt to allocate memory failed. the malloc said "no thoughts, head empty, no bytes." π
π AUTHOR π
Eamon Walsh <ewalsh@tycho.nsa.gov> β thank you for your service, king. π«‘
π SEE ALSO π
selinux(8), getcon(3), getfilecon(3), stat(3) β go read these too, they're part of the same friend group, iykyk. π§
and that's the page, bestie! this was the 30 Mar 2007 edition of security_c..._to_string(3), from the SELinux API documentation set. vintage but still eating. periodt. β¨π
π¦ where this page comes from
- alpine 3.24: libselinux-doc 3.10-r1 Β· Public-Domain
- centos-stream 10: libselinux-devel 3.11-3.el10 Β· LicenseRef-Fedora-Public-Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- debian bookworm: libselinux1-dev 3.4-1+b6
- debian trixie: libselinux1-dev 3.8.1-1 Β· LicenseRef-public-domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- nixos 26.05: libselinux 3.10
- nixpkgs unstable: libselinux 3.11
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- ubuntu jammy: libselinux1-dev 3.3-1build2
- ubuntu noble: libselinux1-dev 3.5-2ubuntu2 Β· LicenseRef-public-domain
- ubuntu noble: libselinux1-dev 3.5-2ubuntu2.1 Β· LicenseRef-public-domain
- ubuntu questing: libselinux1-dev 3.8.1-1build1
- ubuntu resolute: libselinux-dev 3.9-4build1 Β· LicenseRef-public-domain
- ubuntu stonking: libselinux-dev 3.11-2.1 Β· LicenseRef-public-domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms