Add audit helper for escaping log message strings

Add a helper API for ecscaping the value in audit log
messages

* src/util/virtaudit.h, src/util/virtaudit.c,
  src/libvirt_private.syms: Add virAuditEncode
This commit is contained in:
Daniel P. Berrange 2010-10-27 11:53:48 +01:00
parent e06772f006
commit 6a75a3fa3d
3 changed files with 17 additions and 0 deletions

View File

@ -794,6 +794,7 @@ virUUIDParse;
# virtaudit.h
virAuditClose;
virAuditEncode;
virAuditLog;
virAuditOpen;
virAuditSend;

View File

@ -136,3 +136,15 @@ void virAuditClose(void)
close(auditfd);
#endif
}
char *virAuditEncode(const char *key, const char *value)
{
#if HAVE_AUDIT
return audit_encode_nv_string(key, value, 0);
#else
char *str;
if (virAsprintf(&str, "%s=%s", key, value) < 0)
return NULL;
return str;
#endif
}

View File

@ -41,6 +41,8 @@ void virAuditSend(const char *file, const char *func, size_t linenr,
enum virAuditRecordType type, bool success,
const char *fmt, ...);
char *virAuditEncode(const char *key, const char *value);
void virAuditClose(void);
# define VIR_AUDIT(type, success, ...) \
@ -51,5 +53,7 @@ void virAuditClose(void);
virAuditSend(__FILE__, __func__, __LINE__, \
clienttty, clientaddr, type, success, __VA_ARGS__);
# define VIR_AUDIT_STR(str) \
((str) ? (str) : "?")
#endif /* __LIBVIRT_AUDIT_H__ */