1 /* ulogd_SYSLOG.c, Version $Revision: 6433 $
3 * ulogd output target for real syslog() logging
5 * This target produces a syslog entries identical to the LOG target.
7 * (C) 2003 by Harald Welte <laforge@gnumonks.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * $Id: ulogd_SYSLOG.c 6433 2006-01-25 11:22:03Z /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org $
31 #include <ulogd/ulogd.h>
32 #include <ulogd/conffile.h>
35 #ifndef SYSLOG_FACILITY_DEFAULT
36 #define SYSLOG_FACILITY_DEFAULT "LOG_KERN"
39 #ifndef SYSLOG_LEVEL_DEFAULT
40 #define SYSLOG_LEVEL_DEFAULT "LOG_NOTICE"
43 static config_entry_t facility_ce = {
45 .type = CONFIG_TYPE_STRING,
46 .options = CONFIG_OPT_NONE,
47 .u = { .string = SYSLOG_FACILITY_DEFAULT }
50 static config_entry_t level_ce = {
53 .type = CONFIG_TYPE_STRING,
54 .options = CONFIG_OPT_NONE,
55 .u = { .string = SYSLOG_LEVEL_DEFAULT }
58 static int syslog_level, syslog_facility;
60 static int _output_syslog(ulog_iret_t *res)
62 static char buf[4096];
64 printpkt_print(res, buf, 0);
65 syslog(syslog_level|syslog_facility, buf);
70 static int syslog_init(void)
72 /* FIXME: error handling */
73 config_parse_file("SYSLOG", &level_ce);
75 if (!strcmp(facility_ce.u.string, "LOG_DAEMON"))
76 syslog_facility = LOG_DAEMON;
77 else if (!strcmp(facility_ce.u.string, "LOG_KERN"))
78 syslog_facility = LOG_KERN;
79 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL0"))
80 syslog_facility = LOG_LOCAL0;
81 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL1"))
82 syslog_facility = LOG_LOCAL1;
83 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL2"))
84 syslog_facility = LOG_LOCAL2;
85 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL3"))
86 syslog_facility = LOG_LOCAL3;
87 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL4"))
88 syslog_facility = LOG_LOCAL4;
89 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL5"))
90 syslog_facility = LOG_LOCAL5;
91 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL6"))
92 syslog_facility = LOG_LOCAL6;
93 else if (!strcmp(facility_ce.u.string, "LOG_LOCAL7"))
94 syslog_facility = LOG_LOCAL7;
95 else if (!strcmp(facility_ce.u.string, "LOG_USER"))
96 syslog_facility = LOG_USER;
98 ulogd_log(ULOGD_FATAL, "unknown facility '%s'\n",
99 facility_ce.u.string);
103 if (!strcmp(level_ce.u.string, "LOG_EMERG"))
104 syslog_level = LOG_EMERG;
105 else if (!strcmp(level_ce.u.string, "LOG_ALERT"))
106 syslog_level = LOG_ALERT;
107 else if (!strcmp(level_ce.u.string, "LOG_CRIT"))
108 syslog_level = LOG_CRIT;
109 else if (!strcmp(level_ce.u.string, "LOG_ERR"))
110 syslog_level = LOG_ERR;
111 else if (!strcmp(level_ce.u.string, "LOG_WARNING"))
112 syslog_level = LOG_WARNING;
113 else if (!strcmp(level_ce.u.string, "LOG_NOTICE"))
114 syslog_level = LOG_NOTICE;
115 else if (!strcmp(level_ce.u.string, "LOG_INFO"))
116 syslog_level = LOG_INFO;
117 else if (!strcmp(level_ce.u.string, "LOG_DEBUG"))
118 syslog_level = LOG_DEBUG;
120 ulogd_log(ULOGD_FATAL, "unknown level '%s'\n",
125 openlog("ulogd", LOG_NDELAY|LOG_PID, syslog_facility);
130 static void syslog_fini(void)
135 static ulog_output_t syslog_op = {
137 .init = &syslog_init,
138 .fini = &syslog_fini,
139 .output = &_output_syslog,
146 ulogd_log(ULOGD_ERROR, "can't resolve all keyhash id's\n");
148 register_output(&syslog_op);