context_new(3)

πŸ“¦
version 3.11 Β· 2 versions
, in alpine 3.24, centos-stream 10, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu stonking

✨ context_new(3) β€” SELinux API documentation ✨

okay bestie so this is a page from the SELinux API documentation, section 3 (that's the library-calls section, iykyk), and it's all about manipulating SELinux security contexts without losing your whole entire mind πŸ’…


πŸŽ€ NAME πŸŽ€

context_new, context_str, context_free, context_type_get, context_type_set, context_range_get, context_range_set, context_role_get, context_role_set, context_user_get, context_user_set β€” the routines that let you manipulate SELinux security contexts πŸ¦‹


🌸 SYNOPSIS 🌸

#include <selinux/context.h>

context_t context_new(const char *context_str);

const char * context_str(context_t con);

void context_free(context_t con);

const char * context_type_get(context_t con);

const char * context_range_get(context_t con);

const char * context_role_get(context_t con);

const char * context_user_get(context_t con);

int context_type_set(context_t con, const char *type);

int context_range_set(context_t con, const char *range);

int context_role_set(context_t con, const char *role);

int context_user_set(context_t con, const char *user);

πŸ’– DESCRIPTION πŸ’–

so the whole vibe of this little family of functions is: your app gets to poke at the fields of a security context string without ever having to know what the format of that string even is. iconic behaviour honestly. no parsing drama, no format lore required 🫢

  • context_new() β€” returns a new context, initialized to a context string. fresh out the box, slay ✨
  • context_str() β€” hands you back a pointer to the string value of the context_t. it's valid until the next call to context_str() or context_free() for that same context_t*. so like, enjoy it while it lasts, bestie 😭
  • context_free() β€” frees the storage used by a context. it's giving cleanup era 🧹
  • context_type_get(), context_range_get(), context_role_get(), context_user_get() β€” these get you a pointer to the string value of a context component. the little pieces of the puzzle, if you will 🧩
⚠️ Note, and this one matters: values returned by the get functions are only valid until the next call to a set function or context_free() for the same context_t structure. so don't go stashing that pointer in your purse and expecting it to still be cute later, because it will NOT be πŸ’€
  • context_type_set(), context_range_set(), context_role_set(), context_user_set() β€” these set a context component. you're in charge now πŸ‘‘

⭐ RETURN VALUE ⭐

  • on failure, the context_*_set() functions return non-zero, and on success they return 0.
  • the other functions return NULL on failure and non-NULL on success.
  • on failure, errno is set appropriately. (she always tells you what went wrong, we love an honest queen πŸ’œ)

🌈 SEE ALSO 🌈


that's the whole page, no notes, periodt. this lil masterpiece was written by dwalsh@redhat.com and dated 20 December 2011 β€” so yeah she's been serving this exact energy since way before it was cool, and honestly? she ate πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from