summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am17
-rw-r--r--lib/cee-syslog.c91
-rw-r--r--lib/cee-syslog.h37
-rw-r--r--lib/libcee-syslog.pc.in10
4 files changed, 155 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..0ced726
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,17 @@
+LCS_CURRENT = 0
+LCS_REVISION = 0
+LCS_AGE = 0
+
+lib_LTLIBRARIES = libcee-syslog.la
+libcee_syslog_la_LIBADD = @JSON_LIBS@
+libcee_syslog_la_CFLAGS = @JSON_CFLAGS@
+
+libcee_syslog_la_SOURCES = \
+ cee-syslog.c cee-syslog.h
+
+libcee_syslog_includedir = $(includedir)/cee
+libcee_syslog_include_HEADERS = \
+ cee-syslog.h
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libcee-syslog.pc
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c
new file mode 100644
index 0000000..7e9cdec
--- /dev/null
+++ b/lib/cee-syslog.c
@@ -0,0 +1,91 @@
+/* cee-syslog.c -- CEE-enhanced syslog API.
+ *
+ * Copyright (c) 2012 BalaBit IT Security Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BALABIT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL BALABIT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define _GNU_SOURCE 1
+
+#include "cee-syslog.h"
+
+#include <syslog.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <json.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <stdlib.h>
+
+static void (*old_syslog) ();
+
+static void cee_init (void) __attribute__((constructor));
+
+static void
+cee_init (void)
+{
+ old_syslog = dlsym (RTLD_NEXT, "syslog");
+}
+
+void
+cee_syslog (int priority, const char *msg_format, ...)
+{
+ va_list ap;
+
+ va_start (ap, msg_format);
+ vsyslog (priority, msg_format, ap);
+ va_end (ap);
+}
+
+void
+cee_vsyslog (int priority, const char *msg_format, va_list ap)
+{
+ struct json_object *jo;
+ char *key, *fmt;
+ char *value;
+
+ jo = json_object_new_object ();
+
+ vasprintf (&value, msg_format, ap);
+ json_object_object_add (jo, "msg", json_object_new_string (value));
+ free (value);
+
+ while ((key = (char *)va_arg (ap, char *)) != NULL)
+ {
+ fmt = (char *)va_arg (ap, char *);
+
+ vasprintf (&value, fmt, ap);
+ json_object_object_add (jo, key,
+ json_object_new_string (value));
+ free (value);
+ }
+
+ old_syslog (priority, "@cee:%s", json_object_to_json_string (jo));
+ json_object_put (jo);
+}
+
+void syslog (int priority, const char *format, ...)
+ __attribute__((alias ("cee_syslog")));
+
+void vsyslog (int priority, const char *format, va_list ap)
+ __attribute__((alias ("cee_vsyslog")));
diff --git a/lib/cee-syslog.h b/lib/cee-syslog.h
new file mode 100644
index 0000000..4c35cea
--- /dev/null
+++ b/lib/cee-syslog.h
@@ -0,0 +1,37 @@
+/* cee-syslog.h -- CEE-enhanced syslog API.
+ *
+ * Copyright (c) 2012 BalaBit IT Security Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BALABIT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL BALABIT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef CEE_SYSLOG_H
+#define CEE_SYSLOG_H 1
+
+#include <syslog.h>
+#include <stdarg.h>
+
+void cee_syslog (int priority, const char *msg_format, ...);
+void cee_vsyslog (int priority, const char *msg_format, va_list ap);
+
+#endif
diff --git a/lib/libcee-syslog.pc.in b/lib/libcee-syslog.pc.in
new file mode 100644
index 0000000..7b2d896
--- /dev/null
+++ b/lib/libcee-syslog.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libcee-syslog
+Version: @VERSION@
+Description: CEE-enhanced syslog() API
+URL: https://github.com/algernon/libcee-syslog
+Libs: -L${libdir} -lcee-syslog -ldl