提交 6a75a3fa 编写于 作者: D Daniel P. Berrange

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
上级 e06772f0
...@@ -794,6 +794,7 @@ virUUIDParse; ...@@ -794,6 +794,7 @@ virUUIDParse;
# virtaudit.h # virtaudit.h
virAuditClose; virAuditClose;
virAuditEncode;
virAuditLog; virAuditLog;
virAuditOpen; virAuditOpen;
virAuditSend; virAuditSend;
......
...@@ -136,3 +136,15 @@ void virAuditClose(void) ...@@ -136,3 +136,15 @@ void virAuditClose(void)
close(auditfd); close(auditfd);
#endif #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
}
...@@ -41,6 +41,8 @@ void virAuditSend(const char *file, const char *func, size_t linenr, ...@@ -41,6 +41,8 @@ void virAuditSend(const char *file, const char *func, size_t linenr,
enum virAuditRecordType type, bool success, enum virAuditRecordType type, bool success,
const char *fmt, ...); const char *fmt, ...);
char *virAuditEncode(const char *key, const char *value);
void virAuditClose(void); void virAuditClose(void);
# define VIR_AUDIT(type, success, ...) \ # define VIR_AUDIT(type, success, ...) \
...@@ -51,5 +53,7 @@ void virAuditClose(void); ...@@ -51,5 +53,7 @@ void virAuditClose(void);
virAuditSend(__FILE__, __func__, __LINE__, \ virAuditSend(__FILE__, __func__, __LINE__, \
clienttty, clientaddr, type, success, __VA_ARGS__); clienttty, clientaddr, type, success, __VA_ARGS__);
# define VIR_AUDIT_STR(str) \
((str) ? (str) : "?")
#endif /* __LIBVIRT_AUDIT_H__ */ #endif /* __LIBVIRT_AUDIT_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册