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 -1 on error, with errno set appropriately.
  • print_access_vector() β€” does not return a value. it's a void, she simply doesn't do returns, she does statements. πŸ’…
  • all the other functions β€” return zero or NULL on 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