]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add audit helper for escaping log message strings
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 27 Oct 2010 10:53:48 +0000 (11:53 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 27 Oct 2010 16:03:21 +0000 (17:03 +0100)
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
src/util/virtaudit.c
src/util/virtaudit.h

index 1a71e79b8e50e7fd7dcc0d8b0575eac50f7046cb..7ceb0167987e5435616bb00e67e0160f408291ee 100644 (file)
@@ -794,6 +794,7 @@ virUUIDParse;
 
 # virtaudit.h
 virAuditClose;
+virAuditEncode;
 virAuditLog;
 virAuditOpen;
 virAuditSend;
index 322696112baf9111f7064ebac0f2da7b63181097..d5686608ff88a7b94e593c2a1fed538e0cf02727 100644 (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
+}
index f0d9cd7fd2cabee5edf169738baf5ad7d6a2f7f0..37046f281fbaef780c7e7ee688a1917bd18d19a0 100644 (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__ */