AUDIT_ENCODE_NV_STRING(3)

πŸ’– AUDIT_ENCODE_NV_STRING(3) πŸ’–

okay bestie, welcome to the Linux Audit API corner of the internet, where we make log lines safe and cute ✨


🌸 NAME 🌸

audit_encode_nv_string β€” encode a name/value pair in a string


πŸŽ€ SYNOPSIS πŸŽ€

#include <libaudit.h>

char *audit_encode_nv_string(const char *name, const char *value, unsigned int vlen)"

✨ DESCRIPTION ✨

so basically, this function formats a name/value pair for logging by the audit system. periodt.

you should be using this on any field you're logging that might contain a space, a double-quote, a C0 control byte, a DEL byte, or a non-ASCII byte. values with those bytes in them have to be specially encoded so the auparse library can correctly handle the value. the encoding method is designed to prevent log injection attacks where malicious values could cause parsing errors πŸ’€ (yes, that's a real threat, no cap).

to use it, you pass the name string and value string in their respective arguments, bestie:

  • the name argument must not be NULL, and it gets copied as-is right before the = separator.
  • the value gets checked with audit_value_needs_encoding(3).

if encoding is needed, the returned string has the form name=HEX, where HEX is the uppercase hexadecimal encoding of the value bytes. if encoding is not needed, the returned string has the form name=value. slay πŸ’…

some lil' edge cases, since i know you like the details:

  • if value is NULL, a question mark is used as the value. ❓
  • if vlen is 0, the function uses strlen(3) to determine the value length.
  • if the value may contain an embedded NUL byte, pass the value length in vlen bytes. (yes, in bytes, keep up 🫢)
⚠️ also be aware that the name of the field will cause auparse to do certain things when interpreting the value. if the name is uid, a user id value in decimal is expected. make sure that well known names are used for their intended purpose, or that there is no chance of name collision with something new. fr fr, don't be out here inventing name collisions, it's not the vibe πŸ™ˆ

πŸ‘‘ RETURN VALUE πŸ‘‘

returns a freshly malloc'ed string that the caller must free, or NULL on error. (and yes bestie, you have to free it β€” the main character energy here is on you πŸ’–)


🌈 SEE ALSO 🌈


πŸ’œ AUTHOR πŸ’œ

Steve Grubb


and that's the whole thing, gorgeous πŸ¦‹ this one's brought to you by Red Hat, dated May 2026, and it lives in section 3 of the manual like the icon it is. go forth and encode responsibly, bestie πŸŽ€βœ¨