summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaforge <laforge>2003-09-28 15:19:25 +0000
committerlaforge <laforge>2003-09-28 15:19:25 +0000
commita6fbeb96e8894f6d2c953196c99a59644798ac04 (patch)
treea148482775e0c3f69ffe0791d372d6abbdbdbfe6
parentf425910af1a22cf8666852a7c31a93a368c2b891 (diff)
new configuration file syntax (Magnus Boden)
-rw-r--r--Changes7
-rw-r--r--Rules.make.in2
-rw-r--r--TODO4
-rw-r--r--conffile/conffile.c92
-rw-r--r--doc/ulogd.sgml32
-rw-r--r--extensions/ulogd_LOGEMU.c11
-rw-r--r--extensions/ulogd_OPRINT.c9
-rw-r--r--include/ulogd/conffile.h11
-rw-r--r--mysql/ulogd_MYSQL.c19
-rw-r--r--pcap/ulogd_PCAP.c11
-rw-r--r--pgsql/ulogd_PGSQL.c17
-rw-r--r--ulogd.c53
-rw-r--r--ulogd.conf.in88
13 files changed, 168 insertions, 188 deletions
diff --git a/Changes b/Changes
index 570d45d..1cff25c 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,10 @@
+Version 1.10 (2003-Sep-XX)
+- Change format of configuration file. Now every plugin has it's own section
+ in the config file, making the whole parsing procedure easier - and
+ eliminating multiple loading of .so plugins. (Magnus Boden)
+- Make the config file format completely syntax compatible with .ini style files
+-
+
Version 1.01 (2003-Aug-23)
- use $(LD) macro in order to provide cross-compiling/linking support
- add 'rmem' configuration key to set the netlink socket rmem buffsize
diff --git a/Rules.make.in b/Rules.make.in
index 36c0d56..1092a6c 100644
--- a/Rules.make.in
+++ b/Rules.make.in
@@ -18,7 +18,7 @@ CC=@CC@
LD=@LD@
INSTALL=@INSTALL@
-CFLAGS=@CFLAGS@ @CPPFLAGS@
+CFLAGS=@CFLAGS@ @CPPFLAGS@ -Wall
CFLAGS+=-DULOGD_CONFIGFILE=\"$(ULOGD_CONFIGFILE)\"
# doesn't work for subdirs
#CFLAGS+=$(INCIPULOG) $(INCCONFFILE)
diff --git a/TODO b/TODO
index 86d3a4e..c1e7f49 100644
--- a/TODO
+++ b/TODO
@@ -20,11 +20,11 @@ X commandline option for "to fork or not to fork"
X various command line options (we don't even have --version)
- add support for capabilities to run as non-root
X big endian fixes
-- man pages
+X man pages
- IPv6 support (core and extensions)
X pcap output plugin (to use ethereal/tcpdump/... for the logs)
- enable user to specify directory where to look for kernel include files
- support for static linking
conffile:
-- rewrite. This stuff is a real mess. Anybody interested?
+- rewrite parser. This stuff is a real mess. Anybody interested?
diff --git a/conffile/conffile.c b/conffile/conffile.c
index be16173..d26c5ff 100644
--- a/conffile/conffile.c
+++ b/conffile/conffile.c
@@ -2,7 +2,7 @@
*
* (C) 2000 by Harald Welte <laforge@gnumonks.org>
*
- * $Id: conffile.c,v 1.3 2001/05/26 23:19:28 laforge Exp $
+ * $Id: conffile.c,v 1.4 2001/09/01 11:51:53 laforge Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
@@ -29,9 +29,6 @@
#define DEBUGC(format, args...)
#endif
-/* linked list of all registered configuration directives */
-static config_entry_t *config = NULL;
-
/* points to config entry with error */
config_entry_t *config_errce = NULL;
@@ -93,6 +90,7 @@ static char *get_word(char *line, char *not, char *buf)
return stop;
}
+#if 0
/* do we have a config directive for this name */
static int config_iskey(char *name)
{
@@ -105,28 +103,12 @@ static int config_iskey(char *name)
return 1;
}
+#endif
/***********************************************************************
* PUBLIC INTERFACE
***********************************************************************/
-/* register linked list of config directives with us */
-int config_register_key(config_entry_t *ce)
-{
- config_entry_t *myentry;
-
- if (!ce)
- return 1;
-
- /* prepend our list to the global config list */
- for (myentry = ce; myentry->next; myentry = myentry->next) {
- }
- myentry->next = config;
- config = ce;
-
- return 0;
-}
-
/* register config file with us */
int config_register_file(const char *file)
{
@@ -144,23 +126,45 @@ int config_register_file(const char *file)
}
/* parse config file */
-int config_parse_file(int final)
+int config_parse_file(const char *section, config_entry_t *keys)
{
FILE *cfile;
- char *line, *args;
+ char *args;
config_entry_t *ce;
int err = 0;
+ int found = 0;
+ char linebuf[LINE_LEN+1];
+ char *line = linebuf;
- line = (char *) malloc(LINE_LEN+1);
- if (!line)
- return -ERROOM;
-
cfile = fopen(fname, "r");
- if (!cfile) {
- free(line);
+ if (!cfile)
return -ERROPEN;
+
+ DEBUGC("prasing section [%s]\n", section);
+
+ /* Search for correct section */
+ while (fgets(line, LINE_LEN, cfile)) {
+ char wordbuf[LINE_LEN];
+ char *wordend;
+
+ if (*line == '#')
+ continue;
+
+ if (!(wordend = get_word(line, " \t\n[]", (char *) wordbuf)))
+ continue;
+ DEBUGC("word: \"%s\"\n", wordbuf);
+ if (!strcmp(wordbuf, section)) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found) {
+ fclose(cfile);
+ return -ERRSECTION;
}
-
+
+ /* Parse this section until next section */
while (fgets(line, LINE_LEN, cfile))
{
char wordbuf[LINE_LEN];
@@ -170,25 +174,22 @@ int config_parse_file(int final)
if (*line == '#')
continue;
- if (!(wordend = get_word(line, " \t\n", (char *) &wordbuf)))
+ if (!(wordend = get_word(line, " =\t\n", (char *) &wordbuf)))
continue;
-#if 0
- /* if we do the final parse and word is not a config key */
- if (final && config_iskey(word)) {
- DEBUGC("final and key '%s' not found\n", word);
- err = -ERRUNKN;
- goto cpf_error;
+
+ if (wordbuf[0] == '[' ) {
+ DEBUGC("Next section '%s' encountered\n", wordbuf);
+ break;
}
-#endif
DEBUGC("parse_file: entering main loop\n");
- for (ce = config; ce; ce = ce->next) {
+ for (ce = keys; ce; ce = ce->next) {
DEBUGC("parse main loop, key: %s\n", ce->key);
if (strcmp(ce->key, (char *) &wordbuf)) {
continue;
}
- wordend = get_word(wordend, " \t\n", (char *) &wordbuf);
+ wordend = get_word(wordend, " =\t\n", (char *) &wordbuf);
args = (char *)&wordbuf;
if (ce->hit && !(ce->options & CONFIG_OPT_MULTI))
@@ -198,8 +199,8 @@ int config_parse_file(int final)
err = -ERRMULT;
goto cpf_error;
}
- if (final)
- ce->hit++;
+ ce->hit++;
+
switch (ce->type) {
case CONFIG_TYPE_STRING:
if (strlen(args) <
@@ -221,10 +222,10 @@ int config_parse_file(int final)
}
- for (ce = config; ce; ce = ce->next) {
+ for (ce = keys; ce; ce = ce->next) {
DEBUGC("ce post loop, ce=%s\n", ce->key);
- if ((ce->options & CONFIG_OPT_MANDATORY) && (ce->hit == 0) && final) {
- DEBUGC("mandatory config directive %s not found\n",
+ if ((ce->options & CONFIG_OPT_MANDATORY) && (ce->hit == 0)) {
+ DEBUGC("Mandatory config directive \"%s\" not found\n",
ce->key);
config_errce = ce;
err = -ERRMAND;
@@ -234,7 +235,6 @@ int config_parse_file(int final)
}
cpf_error:
- free(line);
fclose(cfile);
return err;
}
diff --git a/doc/ulogd.sgml b/doc/ulogd.sgml
index 002f8e2..73bb462 100644
--- a/doc/ulogd.sgml
+++ b/doc/ulogd.sgml
@@ -1,12 +1,12 @@
<!doctype linuxdoc system>
-<!-- $Id: ulogd.sgml,v 1.8 2003/03/05 22:46:04 laforge Exp $ -->
+<!-- $Id: ulogd.sgml,v 1.9 2003/08/23 17:52:37 laforge Exp $ -->
<article>
<title>ULOGD - the Userspace Logging Daemon</title>
<author>Harald Welte &lt;laforge@gnumonks.org&gt</author>
-<date>Revision $Revision: 1.8 $, $Date: 2003/03/05 22:46:04 $</date>
+<date>Revision $Revision: 1.9 $, $Date: 2003/08/23 17:52:37 $</date>
<abstract>
This is the documentation for <tt>ulogd</tt>, the Userspace logging daemon.
@@ -281,9 +281,9 @@ as possible. Logging is done to a seperate textfile instead of syslog, though.
<p>
The module defines the following configuration directives:
<descrip>
-<tag>syslogfile</tag>The filename where it should log to. The default is
+<tag>file</tag>The filename where it should log to. The default is
<tt>/var/log/ulogd.syslogemu</tt>
-<tag>syslogsync</tag>Set this to 1 if you want to have your logfile written
+<tag>sync</tag>Set this to 1 if you want to have your logfile written
synchronously. This may reduce performance, but makes your log-lines appear
immediately. The default is <tt>0</tt>
</descrip>
@@ -310,15 +310,15 @@ the fields you are not interested in, and create the table. <p>
The module defines the following configuration directives:
<descrip>
-<tag>mysqltable</tag>
+<tag>table</tag>
Name of the table to which ulogd should log
-<tag>mysqldb</tag>
+<tag>ldb</tag>
Name of the mysql database
-<tag>mysqlhost</tag>
+<tag>host</tag>
Name of the mysql database host
-<tag>mysqluser</tag>
+<tag>user</tag>
Name of the mysql user
-<tag>mysqlpass</tag>
+<tag>pass</tag>
Password for mysql
</descrip>
@@ -344,15 +344,15 @@ the fields you are not interested in, and create the table. <p>
The module defines the following configuration directives:
<descrip>
-<tag>pgsqltable</tag>
+<tag>table</tag>
Name of the table to which ulogd should log
-<tag>pgsqldb</tag>
+<tag>db</tag>
Name of the mysql database
-<tag>pgsqlhost</tag>
+<tag>host</tag>
Name of the mysql database host
-<tag>pgsqluser</tag>
+<tag>user</tag>
Name of the mysql user
-<tag>pgsqlpass</tag>
+<tag>pass</tag>
Password for mysql
</descrip>
@@ -364,10 +364,10 @@ or ethereal.
The module defines the following configuration directives:
<descrip>
-<tag>pcapfile</tag>
+<tag>file</tag>
The filename where it should log to. The default is:
<tt>/var/log/ulogd.pcap</tt>
-<tag>pcapsync</tag>
+<tag>sync</tag>
Set this to <tt>1</tt> if you want to have your pcap logfile written
synchronously. This may reduce performance, but makes your packets appear
immediately in the file on disk. The default is <tt>0</tt>
diff --git a/extensions/ulogd_LOGEMU.c b/extensions/ulogd_LOGEMU.c
index b789c7a..ad8a3e6 100644
--- a/extensions/ulogd_LOGEMU.c
+++ b/extensions/ulogd_LOGEMU.c
@@ -1,4 +1,4 @@
-/* ulogd_LOGEMU.c, Version $Revision: 1.13 $
+/* ulogd_LOGEMU.c, Version $Revision: 1.14 $
*
* ulogd output target for syslog logging emulation
*
@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ulogd_LOGEMU.c,v 1.13 2003/08/23 11:47:09 laforge Exp $
+ * $Id: ulogd_LOGEMU.c,v 1.14 2003/09/12 09:00:21 laforge Exp $
*
*/
@@ -52,11 +52,11 @@
((unsigned char *)&addr)[2], \
((unsigned char *)&addr)[3]
-static config_entry_t syslogf_ce = { NULL, "syslogfile", CONFIG_TYPE_STRING,
+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, "syslogsync",
+static config_entry_t syslsync_ce = { &syslogf_ce, "sync",
CONFIG_TYPE_INT, CONFIG_OPT_NONE, 0,
{ value: ULOGD_LOGEMU_SYNC_DEFAULT }
};
@@ -305,8 +305,7 @@ static void _logemu_reg_op(void)
void _init(void)
{
/* FIXME: error handling */
- config_register_key(&syslsync_ce);
- config_parse_file(0);
+ config_parse_file("LOGEMU", &syslsync_ce);
if (gethostname(hostname, sizeof(hostname)) < 0) {
ulogd_log(ULOGD_FATAL, "can't gethostname(): %s\n",
diff --git a/extensions/ulogd_OPRINT.c b/extensions/ulogd_OPRINT.c
index 7ff5e76..fdee135 100644
--- a/extensions/ulogd_OPRINT.c
+++ b/extensions/ulogd_OPRINT.c
@@ -1,4 +1,4 @@
-/* ulogd_MAC.c, Version $Revision: 1.8 $
+/* ulogd_MAC.c, Version $Revision: 1.9 $
*
* ulogd output target for logging to a file
*
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ulogd_OPRINT.c,v 1.8 2001/09/01 11:51:54 laforge Exp $
+ * $Id: ulogd_OPRINT.c,v 1.9 2002/12/09 14:42:43 laforge Exp $
*
*/
@@ -79,7 +79,7 @@ int _output_print(ulog_iret_t *res)
return 0;
}
-static config_entry_t outf_ce = { NULL, "dumpfile", CONFIG_TYPE_STRING,
+static config_entry_t outf_ce = { NULL, "file", CONFIG_TYPE_STRING,
CONFIG_OPT_NONE, 0,
{ string: ULOGD_OPRINT_DEFAULT } };
@@ -122,8 +122,7 @@ void _init(void)
#ifdef DEBUG
of = stdout;
#else
- config_register_key(&outf_ce);
- config_parse_file(0);
+ config_parse_file("OPRINT", &outf_ce);
of = fopen(outf_ce.u.string, "a");
if (!of) {
diff --git a/include/ulogd/conffile.h b/include/ulogd/conffile.h
index b007004..4a390d2 100644
--- a/include/ulogd/conffile.h
+++ b/include/ulogd/conffile.h
@@ -2,7 +2,7 @@
*
* (C) 2000 by Harald Welte <laforge@gnumonks.org>
*
- * $Id: conffile.h,v 1.1 2000/11/20 11:43:22 laforge Exp $
+ * $Id: conffile.h,v 1.2 2001/05/26 23:19:28 laforge Exp $
*
* This code is distributed under the terms of GNU GPL */
@@ -19,6 +19,7 @@ enum {
ERRMULT, /* non-multiple option occured more than once */
ERRMAND, /* mandatory option not found */
ERRUNKN, /* unknown config key */
+ ERRSECTION, /* section not found */
};
/* maximum line lenght of config file entries */
@@ -59,11 +60,7 @@ extern config_entry_t *config_errce;
/* tell us the name of the config file */
int config_register_file(const char *file);
-/* parse the config file , presume all config keys are registered
- * if final==1 */
-int config_parse_file(int final);
-
-/* register a linked list of config entries */
-int config_register_key(config_entry_t *ce);
+/* parse the config file */
+int config_parse_file(const char *section, config_entry_t *keys);
#endif /* ifndef _CONFFILE_H */
diff --git a/mysql/ulogd_MYSQL.c b/mysql/ulogd_MYSQL.c
index 48bb8d6..118fe81 100644
--- a/mysql/ulogd_MYSQL.c
+++ b/mysql/ulogd_MYSQL.c
@@ -1,4 +1,4 @@
-/* ulogd_MYSQL.c, Version $Revision: 1.12 $
+/* ulogd_MYSQL.c, Version $Revision: 1.13 $
*
* ulogd output plugin for logging to a MySQL database
*
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ulogd_MYSQL.c,v 1.12 2003/08/23 11:47:32 laforge Exp $
+ * $Id: ulogd_MYSQL.c,v 1.13 2003/08/23 17:37:53 laforge Exp $
*
* 15 May 2001, Alex Janssen <alex@ynfonatic.de>:
* Added a compability option for older MySQL-servers, which
@@ -65,23 +65,23 @@ static char *stmt_val;
static char *stmt_ins;
/* our configuration directives */
-static config_entry_t db_ce = { NULL, "mysqldb", CONFIG_TYPE_STRING,
+static config_entry_t db_ce = { NULL, "db", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t host_ce = { &db_ce, "mysqlhost", CONFIG_TYPE_STRING,
+static config_entry_t host_ce = { &db_ce, "host", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t user_ce = { &host_ce, "mysqluser", CONFIG_TYPE_STRING,
+static config_entry_t user_ce = { &host_ce, "user", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t pass_ce = { &user_ce, "mysqlpass", CONFIG_TYPE_STRING,
+static config_entry_t pass_ce = { &user_ce, "pass", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t table_ce = { &pass_ce, "mysqltable", CONFIG_TYPE_STRING,
+static config_entry_t table_ce = { &pass_ce, "table", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
@@ -310,11 +310,8 @@ static ulog_output_t _mysql_plugin = { NULL, "mysql", &_mysql_output, NULL };
void _init(void)
{
- /* register our configfile options here */
- config_register_key(&table_ce);
-
/* have the opts parsed */
- config_parse_file(0);
+ config_parse_file("MYSQL", &table_ce);
if (_mysql_open_db(host_ce.u.string, user_ce.u.string,
pass_ce.u.string, db_ce.u.string)) {
diff --git a/pcap/ulogd_PCAP.c b/pcap/ulogd_PCAP.c
index d25b19e..7178b11 100644
--- a/pcap/ulogd_PCAP.c
+++ b/pcap/ulogd_PCAP.c
@@ -1,4 +1,4 @@
-/* ulogd_PCAP.c, Version $Revision: 1.4 $
+/* ulogd_PCAP.c, Version $Revision: 1.5 $
*
* ulogd output target for writing pcap-style files (like tcpdump)
*
@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ulogd_PCAP.c,v 1.4 2003/04/27 07:43:37 laforge Exp $
+ * $Id: ulogd_PCAP.c,v 1.5 2003/08/23 17:25:59 laforge Exp $
*
*/
@@ -49,11 +49,11 @@
((unsigned char *)&addr)[2], \
((unsigned char *)&addr)[3]
-static config_entry_t pcapf_ce = { NULL, "pcapfile", CONFIG_TYPE_STRING,
+static config_entry_t pcapf_ce = { NULL, "file", CONFIG_TYPE_STRING,
CONFIG_OPT_NONE, 0,
{ string: ULOGD_PCAP_DEFAULT } };
-static config_entry_t pcapsync_ce = { &pcapf_ce, "pcapsync",
+static config_entry_t pcapsync_ce = { &pcapf_ce, "sync",
CONFIG_TYPE_INT, CONFIG_OPT_NONE, 0,
{ value: ULOGD_PCAP_SYNC_DEFAULT }
};
@@ -209,8 +209,7 @@ static void _logemu_reg_op(void)
void _init(void)
{
/* FIXME: error handling */
- config_register_key(&pcapsync_ce);
- config_parse_file(0);
+ config_parse_file("PCAP", &pcapsync_ce);
#ifdef DEBUG_PCAP
of = stdout;
diff --git a/pgsql/ulogd_PGSQL.c b/pgsql/ulogd_PGSQL.c
index 7ac5084..6d2523b 100644
--- a/pgsql/ulogd_PGSQL.c
+++ b/pgsql/ulogd_PGSQL.c
@@ -1,4 +1,4 @@
-/* ulogd_PGSQL.c, Version $Revision: 1.6 $
+/* ulogd_PGSQL.c, Version $Revision: 1.7 $
*
* ulogd output plugin for logging to a PGSQL database
*
@@ -45,23 +45,23 @@ static char *stmt_val;
static char *stmt_ins;
/* our configuration directives */
-static config_entry_t db_ce = { NULL, "pgsqldb", CONFIG_TYPE_STRING,
+static config_entry_t db_ce = { NULL, "db", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t host_ce = { &db_ce, "pgsqlhost", CONFIG_TYPE_STRING,
+static config_entry_t host_ce = { &db_ce, "host", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t user_ce = { &host_ce, "pgsqluser", CONFIG_TYPE_STRING,
+static config_entry_t user_ce = { &host_ce, "user", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t pass_ce = { &user_ce, "pgsqlpass", CONFIG_TYPE_STRING,
+static config_entry_t pass_ce = { &user_ce, "pass", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
-static config_entry_t table_ce = { &pass_ce, "pgsqltable", CONFIG_TYPE_STRING,
+static config_entry_t table_ce = { &pass_ce, "table", CONFIG_TYPE_STRING,
CONFIG_OPT_MANDATORY, 0,
{ } };
@@ -317,11 +317,8 @@ static ulog_output_t _pgsql_plugin = { NULL, "pgsql", &_pgsql_output, NULL };
void _init(void)
{
- /* register our configfile options here */
- config_register_key(&table_ce);
-
/* have the opts parsed */
- config_parse_file(0);
+ config_parse_file("PGSQL", &table_ca);
if (_pgsql_open_db(host_ce.u.string, user_ce.u.string,
pass_ce.u.string, db_ce.u.string)) {
diff --git a/ulogd.c b/ulogd.c
index 7f6cfbe..e3bdba4 100644
--- a/ulogd.c
+++ b/ulogd.c
@@ -1,6 +1,6 @@
-/* ulogd, Version $Revision: 1.35 $
+/* ulogd, Version $Revision: 1.36 $
*
- * $Id: ulogd.c,v 1.35 2003/05/04 10:00:10 laforge Exp $
+ * $Id: ulogd.c,v 1.36 2003/08/23 17:52:37 laforge Exp $
*
* userspace logging daemon for the iptables ULOG target
* of the linux 2.4 netfilter subsystem.
@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ulogd.c,v 1.35 2003/05/04 10:00:10 laforge Exp $
+ * $Id: ulogd.c,v 1.36 2003/08/23 17:52:37 laforge Exp $
*
* Modifications:
* 14 Jun 2001 Martin Josefsson <gandalf@wlug.westbo.se>
@@ -29,9 +29,12 @@
* 10 Feb 2002 Alessandro Bono <a.bono@libero.it>
* - added support for non-fork mode
* - added support for logging to stdout
+ *
+ * 09 Sep 2003 Magnus Boden <sarek@ozaba.cx>
+ * - added support for more flexible multi-section conffile
*/
-#define ULOGD_VERSION "1.01"
+#define ULOGD_VERSION "1.10"
#include <unistd.h>
#include <stdio.h>
@@ -481,11 +484,11 @@ static int logfile_open(const char *name)
}
/* wrapper to handle conffile error codes */
-static int parse_conffile(int final)
+static int parse_conffile(const char *section, config_entry_t *ce)
{
int err;
- err = config_parse_file(final);
+ err = config_parse_file(section, ce);
switch(err) {
case 0:
@@ -498,16 +501,22 @@ static int parse_conffile(int final)
break;
case -ERRMAND:
ulogd_log(ULOGD_ERROR,
- "mandatory option not found\n");
+ "mandatory option \"%s\" not found\n",
+ config_errce->key);
break;
case -ERRMULT:
ulogd_log(ULOGD_ERROR,
- "option occurred more than once\n");
+ "option \"%s\" occurred more than once\n",
+ config_errce->key);
break;
case -ERRUNKN:
ulogd_log(ULOGD_ERROR,
- "unknown config key\n");
-/* config_errce->key); */
+ "unknown config key \"%s\"\n",
+ config_errce->key);
+ break;
+ case -ERRSECTION:
+ ulogd_log(ULOGD_ERROR,
+ "section \"%s\" not found\n", section);
break;
}
return 1;
@@ -538,17 +547,6 @@ static config_entry_t rmem_ce = { &loglevel_ce, "rmem", CONFIG_TYPE_INT,
CONFIG_OPT_NONE, 0,
{ value: ULOGD_RMEM_DEFAULT } };
-static int init_conffile(char *file)
-{
- if (config_register_file(file))
- return 1;
-
- config_register_key(&rmem_ce);
-
- /* parse config file the first time (for logfile name, ...) */
- return parse_conffile(0);
-}
-
static void sigterm_handler(int signal)
{
ulogd_log(ULOGD_NOTICE, "sigterm received, exiting\n");
@@ -638,19 +636,20 @@ int main(int argc, char* argv[])
}
}
- if (init_conffile(ulogd_configfile)) {
- ulogd_log(ULOGD_FATAL, "parse_conffile error\n");
+ if (config_register_file(ulogd_configfile)) {
+ ulogd_log(ULOGD_FATAL, "error registering configfile \"%s\"\n",
+ ulogd_configfile);
exit(1);
}
- logfile_open(logf_ce.u.string);
-
- /* parse config file the second time (for plugin options) */
- if (parse_conffile(1)) {
+ /* parse config file */
+ if (parse_conffile("global", &rmem_ce)) {
ulogd_log(ULOGD_FATAL, "parse_conffile\n");
exit(1);
}
+ logfile_open(logf_ce.u.string);
+
#ifdef DEBUG
/* dump key and interpreter hash */
interh_dump();
diff --git a/ulogd.conf.in b/ulogd.conf.in
index 0a6b1e3..b1bec43 100644
--- a/ulogd.conf.in
+++ b/ulogd.conf.in
@@ -1,26 +1,27 @@
# Example configuration for ulogd
-# $Id: ulogd.conf.in,v 1.1 2003/04/27 07:47:26 laforge Exp $
+# $Id: ulogd.conf.in,v 1.2 2003/05/04 10:00:10 laforge Exp $
#
+[global]
######################################################################
# GLOBAL OPTIONS
######################################################################
# netlink multicast group (the same as the iptables --ulog-nlgroup param)
-nlgroup 1
+nlgroup=1
# logfile for status messages
-logfile /var/log/ulogd.log
+logfile="/var/log/ulogd.log"
# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8)
-loglevel 5
+loglevel=5
# socket receive buffer size (should be at least the size of the
# in-kernel buffer (ipt_ULOG.o 'nlbufsiz' parameter)
-rmem 131071
+rmem=131071
# libipulog/ulogd receive buffer size, should be > rmem
-bufsize 150000
+bufsize=150000
######################################################################
# PLUGIN OPTIONS
@@ -29,61 +30,46 @@ bufsize 150000
# We have to configure and load all the plugins we want to use
# general rules:
-# 1. specify the options FIRST, then load the plugin
-# 2. interpreter plugins have to precede output plugins
+# 1. load the plugins _first_ from the global section
+# 2. options for each plugin in seperate section below
#
# ulogd_BASE.so - interpreter plugin for basic IPv4 header fields
# you will always need this
-plugin @libdir@/ulogd_BASE.so
+plugin="@libdir@/ulogd_BASE.so"
-#
-# ulogd_LOGEMU.so - simple syslog emulation target
-#
-# where to write to
-syslogfile /var/log/ulogd.syslogemu
-# do we want to fflush() the file after each write?
-syslogsync 1
-# load the plugin
-plugin @libdir@/ulogd_LOGEMU.so
+# output plugins.
+plugin="@libdir@/ulogd_LOGEMU.so"
+#plugin="@libdir@/ulogd_OPRINT.so"
+#plugin="@libdir@/ulogd_MYSQL.so"
+#plugin="@libdir@/ulogd_PGSQL.so"
+#plugin="@libdir@/ulogd_PCAP.so"
-#
-# ulogd_OPRINT.so: file for packet dumping
-#
-# where to write the log
-dumpfile /var/log/ulogd.pktlog
-# load the plugin (remove the '#'if you want to enable it
-#plugin @libdir@/ulogd_OPRINT.so
+[LOGEMU]
+file="/var/log/ulogd.syslogemu"
+sync=1
+[OPRINT]
+file="/var/log/ulogd.pktlog"
-#
-# ulogd_MYSQL.so: optional logging into a MySQL database
-#
-# database information
-mysqltable ulog
-mysqlpass changeme
-mysqluser laforge
-mysqldb ulogd
-mysqlhost localhost
-# load the plugin (remove the '#' if you want to enable it)
-#plugin @libdir@/ulogd_MYSQL.so
+[MYSQL]
+table="ulog"
+pass="changeme"
+user="laforge"
+db="ulogd"
+host="localhost"
+[PGSQL]
+table="ulog"
+pass="changeme"
+user="postgres"
+db="ulogd"
+host="localhost"
+
+[PCAP]
+file="/var/log/ulogd.pcap"
+sync=1
-#
-# ulogd_PGSQL.so: optional logging into a PostgreSQL database
-#
-# database information
-pgsqltable ulog
-pgsqlpass
-pgsqluser postgres
-pgsqldb ulogd
-pgsqlhost localhost
-#load the plugin (remove the '#' if you want to enable it)
-#plugin @libdir@/ulogd_PGSQL.so
-
-pcapfile /var/log/ulogd.pcap
-pcapsync 1
-#plugin @libdir@/ulogd_PCAP.so