summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore13
-rw-r--r--LICENSE25
-rw-r--r--Makefile.am4
-rwxr-xr-xautogen.sh7
-rw-r--r--configure.ac61
-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
9 files changed, 265 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b30b6f5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+/config.guess
+/config.sub
+/config.h.in
+/configure
+/configure.scan
+/depcomp
+/install-sh
+/ltmain.sh
+/missing
+/aclocal.m4
+/autom4te.cache
+/m4
+Makefile.in
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..798fe0f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+libcee-syslog --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.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..d3da3aa
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,4 @@
+SUBDIRS = lib
+
+ACLOCAL_AMFLAGS = -I m4 --install
+EXTRA_DIST = LICENSE
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..40b6e0f
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+libtoolize --force --copy --automake
+aclocal -I m4 --install
+autoheader
+automake --foreign --add-missing --copy
+autoconf
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..6f3cb9c
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,61 @@
+dnl Process this file with autoconf to produce a configure script.
+dnl
+
+AC_INIT(libcee-syslog, 0.1.0, algernon@balabit.hu, libcee-syslog, https://github.com/algernon/libcee-syslog)
+AM_INIT_AUTOMAKE([1.9 tar-ustar])
+
+dnl ***************************************************************************
+dnl dependencies
+
+JSON_C_MIN_VERSION="0.7"
+
+dnl ***************************************************************************
+dnl Initial setup
+
+AC_CONFIG_MACRO_DIR([m4])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AM_CONFIG_HEADER(config.h)
+
+dnl ***************************************************************************
+dnl Checks for programs.
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_RANLIB
+AM_PROG_CC_STDC
+AC_PROG_MAKE_SET
+PKG_PROG_PKG_CONFIG
+LT_INIT([shared])
+
+dnl ***************************************************************************
+dnl Miscellanneous headers
+dnl ***************************************************************************
+
+AC_HEADER_STDC
+
+dnl ***************************************************************************
+dnl Header checks
+dnl ***************************************************************************
+AC_CHECK_HEADERS([syslog.h dlfcn.h])
+
+dnl ***************************************************************************
+dnl Checks for libraries
+dnl AC_CHECK_FUNCS()
+
+dnl ***************************************************************************
+dnl JSON-C headers/libraries
+dnl ***************************************************************************
+PKG_CHECK_MODULES(JSON, json >= $JSON_C_MIN_VERSION,,)
+
+dnl ***************************************************************************
+dnl misc features to be enabled
+dnl ***************************************************************************
+AC_C_INLINE
+
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [package name])
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [version number])
+
+AC_OUTPUT(
+ Makefile
+ lib/Makefile
+ lib/libcee-syslog.pc
+)
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