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
nameargument must not beNULL, and it gets copied as-is right before the=separator. - the
valuegets checked withaudit_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
valueisNULL, a question mark is used as the value. β - if
vlenis0, the function usesstrlen(3)to determine the value length. - if the value may contain an embedded
NULbyte, pass the value length invlenbytes. (yes, in bytes, keep up π«Ά)
β οΈ also be aware that the name of the field will causeauparseto do certain things when interpreting the value. if the name isuid, 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 π
audit_log_user_message(3)audit_log_user_comm_message(3)audit_log_user_avc_message(3)audit_log_semanage_message(3)audit_encode_value(3)audit_value_needs_encoding(3)
π 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 πβ¨
π¦ where this page comes from
- arch rolling: audit 4.2.1-1 Β· GPL-2.0-or-later AND LGPL-2.0-or-later
- centos-stream 10: audit-libs-devel 4.2.1-3.el10 Β· LGPL-2.0-or-later
- fedora 43: audit-libs-devel 4.2.1-1.fc43 Β· LGPL-2.0-or-later
- fedora 43: audit-libs-devel 4.2.1-1.fc43 Β· LGPL-2.0-or-later
- fedora 44: audit-libs-devel 4.2.1-1.fc44 Β· LGPL-2.0-or-later
- fedora 44: audit-libs-devel 4.2.1-1.fc44 Β· LGPL-2.0-or-later
- nixpkgs unstable: audit 4.2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms