]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
new configuration file syntax (Magnus Boden)
authorlaforge <laforge>
Sun, 28 Sep 2003 15:19:25 +0000 (15:19 +0000)
committerlaforge <laforge>
Sun, 28 Sep 2003 15:19:25 +0000 (15:19 +0000)
13 files changed:
Changes
Rules.make.in
TODO
conffile/conffile.c
doc/ulogd.sgml
extensions/ulogd_LOGEMU.c
extensions/ulogd_OPRINT.c
include/ulogd/conffile.h
mysql/ulogd_MYSQL.c
pcap/ulogd_PCAP.c
pgsql/ulogd_PGSQL.c
ulogd.c
ulogd.conf.in

diff --git a/Changes b/Changes
index 570d45d3569ddef6cace24d4a5b8b44bab654349..1cff25c61de83832aedc37c70bbc01b5bdf72e40 100644 (file)
--- 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
index 36c0d56648afaa056082828ae914ddc756255e4c..1092a6cd566d4c62e1a108a4a59242671e4b7d77 100644 (file)
@@ -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 86d3a4e37e6292e2c49ac3655ff4b8a542e215aa..c1e7f49356f52ec7b6c78ee483cb6e3bcbe41b19 100644 (file)
--- 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?
index be1617370a19f5a63cd10ccd2c5168a71a3cfb24..d26c5ff9d001ae111f38201d0338f05f6a1c4761 100644 (file)
@@ -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;
 }
index 002f8e2b35d539492694c6da7c03339938dd5e69..73bb462a7c5db65067cee7989cc22398fa56b2ab 100644 (file)
@@ -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>
index b789c7a5a623501188bca5c60bb7a6a5bf42b77b..ad8a3e602a5c2751fef8a0eb2d23b87465853653 100644 (file)
@@ -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 $
  *
  */
 
         ((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",
index 7ff5e76742cd8a7c78a67f342a344daf74e96ee1..fdee13597fc6fa465e8e5b13a21023431b2dd4cd 100644 (file)
@@ -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) {
index b007004b3fa219568b26b210a85e1656533e028f..4a390d28bccf4d492f4979092ce3fa2f224d2468 100644 (file)
@@ -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 */
index 48bb8d6df9432304d837facde18a252430c78de1..118fe81c41bb56a5151df9a6a527153e8d2cdfc2 100644 (file)
@@ -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)) {
index d25b19ee638ec82d5841a95093909f3858c10b46..7178b1118ac3e7546d8ab8e3c7822c260740ff19 100644 (file)
@@ -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 $
  *
  */
 
         ((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;
index 7ac5084deb85af6a9f92f94233e984badefc7e3c..6d2523b923f945bd35107194dc2c49cdedc3f9b3 100644 (file)
@@ -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 7f6cfbeeb0306fdda023286fad712cc755193778..e3bdba4c7ced553afc5b8b9ca158e445fcdc855c 100644 (file)
--- 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>
  *     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();
index 0a6b1e3a27a34d48e45fea65e8793c91e070b688..b1bec43c069e5411727c86b845942d52c736d18e 100644 (file)
@@ -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