summaryrefslogtreecommitdiffstats
path: root/output/ulogd_output_LOGEMU.c
diff options
context:
space:
mode:
author/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org>2006-05-23 08:57:18 +0000
committer/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org>2006-05-23 08:57:18 +0000
commit62defdbdb365c325795b83845f266410cf7c1076 (patch)
tree30ec9bd4ba364b5058ad7b782140e908654a46a0 /output/ulogd_output_LOGEMU.c
parent5f738b5660fc5abf6e21b527bb6f946bbaaa31db (diff)
Move the printpkt functionality out of SYSLOG and LOGEMU, and into
a separate PRINTPKT plugin. This reduces code duplication, and also makes the SYSLOG and LOGEMU plugins more general. (Philip Craig)
Diffstat (limited to 'output/ulogd_output_LOGEMU.c')
-rw-r--r--output/ulogd_output_LOGEMU.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/output/ulogd_output_LOGEMU.c b/output/ulogd_output_LOGEMU.c
index f18da61..a224d7b 100644
--- a/output/ulogd_output_LOGEMU.c
+++ b/output/ulogd_output_LOGEMU.c
@@ -29,9 +29,14 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <time.h>
#include <ulogd/ulogd.h>
#include <ulogd/conffile.h>
-#include <ulogd/printpkt.h>
+
+#ifndef HOST_NAME_MAX
+#warning this libc does not define HOST_NAME_MAX
+#define HOST_NAME_MAX (255+1)
+#endif
#ifndef ULOGD_LOGEMU_DEFAULT
#define ULOGD_LOGEMU_DEFAULT "/var/log/ulogd.syslogemu"
@@ -41,6 +46,19 @@
#define ULOGD_LOGEMU_SYNC_DEFAULT 0
#endif
+static char hostname[HOST_NAME_MAX+1];
+
+static struct ulogd_key logemu_inp[] = {
+ {
+ .type = ULOGD_RET_STRING,
+ .name = "print",
+ },
+ {
+ .type = ULOGD_RET_UINT32,
+ .name = "oob.time.sec",
+ },
+};
+
static struct config_keyset logemu_kset = {
.num_ces = 2,
.ces = {
@@ -67,14 +85,27 @@ static int _output_logemu(struct ulogd_pluginstance *upi)
{
struct logemu_instance *li = (struct logemu_instance *) &upi->private;
struct ulogd_key *res = upi->input.keys;
- static char buf[4096];
- printpkt_print(res, buf, 1);
+ if (res[0].u.source->flags & ULOGD_RETF_VALID) {
+ char *timestr;
+ char *tmp;
+ time_t now;
- fprintf(li->of, "%s", buf);
+ if (res[1].u.source->flags & ULOGD_RETF_VALID)
+ now = (time_t) res[1].u.source->u.value.ui32;
+ else
+ now = time(NULL);
- if (upi->config_kset->ces[1].u.value)
- fflush(li->of);
+ timestr = ctime(&now) + 4;
+ if ((tmp = strchr(timestr, '\n')))
+ *tmp = '\0';
+
+ fprintf(li->of, "%.15s %s %s", timestr, hostname,
+ res[0].u.source->u.value.ptr);
+
+ if (upi->config_kset->ces[1].u.value)
+ fflush(li->of);
+ }
return 0;
}
@@ -102,6 +133,7 @@ static void signal_handler_logemu(struct ulogd_pluginstance *pi, int signal)
static int start_logemu(struct ulogd_pluginstance *pi)
{
struct logemu_instance *li = (struct logemu_instance *) &pi->private;
+ char *tmp;
ulogd_log(ULOGD_DEBUG, "starting logemu\n");
@@ -117,11 +149,17 @@ static int start_logemu(struct ulogd_pluginstance *pi)
return errno;
}
#endif
- if (printpkt_init()) {
- ulogd_log(ULOGD_ERROR, "can't resolve all keyhash id's\n");
+
+ if (gethostname(hostname, sizeof(hostname)) < 0) {
+ ulogd_log(ULOGD_FATAL, "can't gethostname(): %s\n",
+ strerror(errno));
return -EINVAL;
}
+ /* truncate hostname */
+ if ((tmp = strchr(hostname, '.')))
+ *tmp = '\0';
+
return 0;
}
@@ -147,8 +185,8 @@ static int configure_logemu(struct ulogd_pluginstance *pi,
static struct ulogd_plugin logemu_plugin = {
.name = "LOGEMU",
.input = {
- .keys = printpkt_keys,
- .num_keys = ARRAY_SIZE(printpkt_keys),
+ .keys = logemu_inp,
+ .num_keys = ARRAY_SIZE(logemu_inp),
.type = ULOGD_DTYPE_PACKET,
},
.output = {