summaryrefslogtreecommitdiffstats
path: root/output
diff options
context:
space:
mode:
authorlaforge <laforge>2004-07-23 03:22:16 +0000
committerlaforge <laforge>2004-07-23 03:22:16 +0000
commit2dc0dd85c2e851e9b2dacd9dfaa40c70cc61ff95 (patch)
tree18d1d23e47b5142ede938165c616bbc942f14bd5 /output
parente67fb3fbdc6ac83e884d9741e3b4a759b1bd8c5f (diff)
further tree reorganization
Diffstat (limited to 'output')
-rw-r--r--output/ulogd_output_LOGEMU.c130
-rw-r--r--output/ulogd_output_OPRINT.c141
-rw-r--r--output/ulogd_output_SYSLOG.c149
3 files changed, 420 insertions, 0 deletions
diff --git a/output/ulogd_output_LOGEMU.c b/output/ulogd_output_LOGEMU.c
new file mode 100644
index 0000000..049bcd4
--- /dev/null
+++ b/output/ulogd_output_LOGEMU.c
@@ -0,0 +1,130 @@
+/* ulogd_LOGEMU.c, Version $Revision: 1.15 $
+ *
+ * ulogd output target for syslog logging emulation
+ *
+ * This target produces a file which looks the same like the syslog-entries
+ * of the LOG target.
+ *
+ * (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ulogd/ulogd.h>
+#include <ulogd/conffile.h>
+#include "printpkt.c"
+
+#ifndef ULOGD_LOGEMU_DEFAULT
+#define ULOGD_LOGEMU_DEFAULT "/var/log/ulogd.syslogemu"
+#endif
+
+#ifndef ULOGD_LOGEMU_SYNC_DEFAULT
+#define ULOGD_LOGEMU_SYNC_DEFAULT 0
+#endif
+
+#define NIPQUAD(addr) \
+ ((unsigned char *)&addr)[0], \
+ ((unsigned char *)&addr)[1], \
+ ((unsigned char *)&addr)[2], \
+ ((unsigned char *)&addr)[3]
+
+static config_entry_t syslogf_ce = { NULL, "file", CONFIG_TYPE_STRING,
+ CONFIG_OPT_NONE, 0,
+ { string: ULOGD_LOGEMU_DEFAULT } };
+
+static config_entry_t syslsync_ce = { &syslogf_ce, "sync",
+ CONFIG_TYPE_INT, CONFIG_OPT_NONE, 0,
+ { value: ULOGD_LOGEMU_SYNC_DEFAULT }
+ };
+
+static FILE *of = NULL;
+
+static int _output_logemu(ulog_iret_t *res)
+{
+ static char buf[4096];
+
+ printpkt_print(res, buf, 1);
+
+ fprintf(of, "%s", buf);
+
+ if (syslsync_ce.u.value)
+ fflush(of);
+
+ return 0;
+}
+
+static void signal_handler_logemu(int signal)
+{
+ switch (signal) {
+ case SIGHUP:
+ ulogd_log(ULOGD_NOTICE, "syslogemu: reopening logfile\n");
+ fclose(of);
+ of = fopen(syslogf_ce.u.string, "a");
+ if (!of) {
+ ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+static int init_logemu(void) {
+#ifdef DEBUG_LOGEMU
+ of = stdout;
+#else
+ of = fopen(syslogf_ce.u.string, "a");
+ if (!of) {
+ ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+#endif
+ if (printpkt_init()) {
+ ulogd_log(ULOGD_ERROR, "can't resolve all keyhash id's\n");
+ }
+
+ return 1;
+}
+
+static void fini_logemu(void) {
+ if (of != stdout)
+ fclose(of);
+}
+
+static ulog_output_t logemu_op = {
+ .name = "syslogemu",
+ .init = &init_logemu,
+ .fini = &fini_logemu,
+ .output = &_output_logemu,
+ .signal = &signal_handler_logemu,
+};
+
+void _init(void)
+{
+ /* FIXME: error handling */
+ config_parse_file("LOGEMU", &syslsync_ce);
+
+ register_output(&logemu_op);
+}
diff --git a/output/ulogd_output_OPRINT.c b/output/ulogd_output_OPRINT.c
new file mode 100644
index 0000000..186e3c9
--- /dev/null
+++ b/output/ulogd_output_OPRINT.c
@@ -0,0 +1,141 @@
+/* ulogd_MAC.c, Version $Revision: 1.9 $
+ *
+ * ulogd output target for logging to a file
+ *
+ * (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ulogd/ulogd.h>
+#include <ulogd/conffile.h>
+
+#ifndef ULOGD_OPRINT_DEFAULT
+#define ULOGD_OPRINT_DEFAULT "/var/log/ulogd.pktlog"
+#endif
+
+#define NIPQUAD(addr) \
+ ((unsigned char *)&addr)[0], \
+ ((unsigned char *)&addr)[1], \
+ ((unsigned char *)&addr)[2], \
+ ((unsigned char *)&addr)[3]
+
+#define HIPQUAD(addr) \
+ ((unsigned char *)&addr)[3], \
+ ((unsigned char *)&addr)[2], \
+ ((unsigned char *)&addr)[1], \
+ ((unsigned char *)&addr)[0]
+
+static FILE *of = NULL;
+
+static int _output_print(ulog_iret_t *res)
+{
+ ulog_iret_t *ret;
+
+ fprintf(of, "===>PACKET BOUNDARY\n");
+ for (ret = res; ret; ret = ret->cur_next) {
+ fprintf(of,"%s=", ret->key);
+ switch (ret->type) {
+ case ULOGD_RET_STRING:
+ fprintf(of, "%s\n", (char *) ret->value.ptr);
+ break;
+ case ULOGD_RET_BOOL:
+ case ULOGD_RET_INT8:
+ case ULOGD_RET_INT16:
+ case ULOGD_RET_INT32:
+ fprintf(of, "%d\n", ret->value.i32);
+ break;
+ case ULOGD_RET_UINT8:
+ case ULOGD_RET_UINT16:
+ case ULOGD_RET_UINT32:
+ fprintf(of, "%u\n", ret->value.ui32);
+ break;
+ case ULOGD_RET_IPADDR:
+ fprintf(of, "%u.%u.%u.%u\n",
+ HIPQUAD(ret->value.ui32));
+ break;
+ case ULOGD_RET_NONE:
+ fprintf(of, "<none>");
+ break;
+ }
+ }
+ return 0;
+}
+
+static config_entry_t outf_ce = { NULL, "file", CONFIG_TYPE_STRING,
+ CONFIG_OPT_NONE, 0,
+ { string: ULOGD_OPRINT_DEFAULT } };
+
+static void sighup_handler_print(int signal)
+{
+
+ switch (signal) {
+ case SIGHUP:
+ ulogd_log(ULOGD_NOTICE, "PKTLOG: reopening logfile\n");
+ fclose(of);
+ of = fopen(outf_ce.u.string, "a");
+ if (!of) {
+ ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static int oprint_init(void)
+{
+#ifdef DEBUG
+ of = stdout;
+#else
+ config_parse_file("OPRINT", &outf_ce);
+
+ of = fopen(outf_ce.u.string, "a");
+ if (!of) {
+ ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+#endif
+ return 0;
+}
+
+static void oprint_fini(void)
+{
+ if (of != stdout)
+ fclose(of);
+
+ return;
+}
+
+static ulog_output_t oprint_op = {
+ .name = "oprint",
+ .output = &_output_print,
+ .signal = &sighup_handler_print,
+ .init = &oprint_init,
+ .fini = &oprint_fini,
+};
+
+void _init(void)
+{
+ register_output(&oprint_op);
+}
diff --git a/output/ulogd_output_SYSLOG.c b/output/ulogd_output_SYSLOG.c
new file mode 100644
index 0000000..cb87fa9
--- /dev/null
+++ b/output/ulogd_output_SYSLOG.c
@@ -0,0 +1,149 @@
+/* ulogd_SYSLOG.c, Version $Revision: 1.15 $
+ *
+ * ulogd output target for real syslog() logging
+ *
+ * This target produces a syslog entries identical to the LOG target.
+ *
+ * (C) 2003 by Harald Welte <laforge@gnumonks.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <syslog.h>
+#include <ulogd/ulogd.h>
+#include <ulogd/conffile.h>
+#include "printpkt.h"
+
+#ifndef SYSLOG_FACILITY_DEFAULT
+#define SYSLOG_FACILITY_DEFAULT "LOG_KERN"
+#endif
+
+#ifndef SYSLOG_LEVEL_DEFAULT
+#define SYSLOG_LEVEL_DEFAULT "LOG_NOTICE"
+#endif
+
+static config_entry_t facility_ce = {
+ .key = "facility",
+ .type = CONFIG_TYPE_STRING,
+ .options = CONFIG_OPT_NONE,
+ .u = { .string = SYSLOG_FACILITY_DEFAULT }
+};
+
+static config_entry_t level_ce = {
+ .next = &facility_ce,
+ .key = "level",
+ .type = CONFIG_TYPE_INT,
+ .options = CONFIG_OPT_NONE,
+ .u = { .string = SYSLOG_LEVEL_DEFAULT }
+};
+
+static int syslog_level, syslog_facility;
+
+static int _output_syslog(ulog_iret_t *res)
+{
+ static char buf[4096];
+
+ printpkt_print(res, buf, 0);
+ syslog(syslog_level|syslog_facility, buf);
+
+ return 0;
+}
+
+static int syslog_init(void)
+{
+ /* FIXME: error handling */
+ config_parse_file("SYSLOG", &level_ce);
+
+ if (!strcmp(facility_ce.u.string, "LOG_DAEMON"))
+ syslog_facility = LOG_DAEMON;
+ else if (!strcmp(facility_ce.u.string, "LOG_KERN"))
+ syslog_facility = LOG_KERN;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL0"))
+ syslog_facility = LOG_LOCAL0;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL1"))
+ syslog_facility = LOG_LOCAL1;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL2"))
+ syslog_facility = LOG_LOCAL2;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL3"))
+ syslog_facility = LOG_LOCAL3;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL4"))
+ syslog_facility = LOG_LOCAL4;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL5"))
+ syslog_facility = LOG_LOCAL5;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL6"))
+ syslog_facility = LOG_LOCAL6;
+ else if (!strcmp(facility_ce.u.string, "LOG_LOCAL7"))
+ syslog_facility = LOG_LOCAL7;
+ else if (!strcmp(facility_ce.u.string, "LOG_USER"))
+ syslog_facility = LOG_USER;
+ else {
+ ulogd_log(ULOGD_FATAL, "unknown facility '%s'\n",
+ facility_ce.u.string);
+ exit(2);
+ }
+
+ if (!strcmp(level_ce.u.string, "LOG_EMERG"))
+ syslog_level = LOG_EMERG;
+ else if (!strcmp(level_ce.u.string, "LOG_ALERT"))
+ syslog_level = LOG_ALERT;
+ else if (!strcmp(level_ce.u.string, "LOG_CRIT"))
+ syslog_level = LOG_CRIT;
+ else if (!strcmp(level_ce.u.string, "LOG_ERR"))
+ syslog_level = LOG_ERR;
+ else if (!strcmp(level_ce.u.string, "LOG_WARNING"))
+ syslog_level = LOG_WARNING;
+ else if (!strcmp(level_ce.u.string, "LOG_NOTICE"))
+ syslog_level = LOG_NOTICE;
+ else if (!strcmp(level_ce.u.string, "LOG_INFO"))
+ syslog_level = LOG_INFO;
+ else if (!strcmp(level_ce.u.string, "LOG_DEBUg"))
+ syslog_level = LOG_DEBUG;
+ else {
+ ulogd_log(ULOGD_FATAL, "unknown level '%s'\n",
+ facility_ce.u.string);
+ exit(2);
+ }
+
+ openlog("ulogd", LOG_NDELAY|LOG_PID, syslog_facility);
+
+ return 0;
+}
+
+static void syslog_fini(void)
+{
+ closelog();
+}
+
+static ulog_output_t syslog_op = {
+ .name = "syslog",
+ .init = &syslog_init,
+ .fini = &syslog_fini,
+ .output &_output_syslog
+};
+
+
+void _init(void)
+{
+ if (printpkt_init())
+ ulogd_log(ULOGD_ERROR, "can't resolve all keyhash id's\n");
+
+ register_output(&syslog_op);
+}