[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/7] 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
---
 src/libvirt_private.syms |    1 +
 src/util/virtaudit.c     |   12 ++++++++++++
 src/util/virtaudit.h     |    4 ++++
 3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1a71e79..7ceb016 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -794,6 +794,7 @@ virUUIDParse;
 
 # virtaudit.h
 virAuditClose;
+virAuditEncode;
 virAuditLog;
 virAuditOpen;
 virAuditSend;
diff --git a/src/util/virtaudit.c b/src/util/virtaudit.c
index 3226961..d568660 100644
--- a/src/util/virtaudit.c
+++ b/src/util/virtaudit.c
@@ -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
+}
diff --git a/src/util/virtaudit.h b/src/util/virtaudit.h
index f0d9cd7..37046f2 100644
--- a/src/util/virtaudit.h
+++ b/src/util/virtaudit.h
@@ -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__ */
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]