From 0d41339e258209d89bd0c1500ab7835bc48775bd Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 9 Sep 2000 21:55:46 +0000 Subject: made nlgroup + pluginpath configurable added default values for all config keys started writing ulogd_log --- ulogd/Makefile | 4 ++-- ulogd/conffile.c | 31 ++++++++++++++++++++------- ulogd/conffile.h | 9 ++++++-- ulogd/include/ulogd/ulogd.h | 12 +++++++---- ulogd/ulogd.c | 51 ++++++++++++++++++++++++++++++++------------- 5 files changed, 77 insertions(+), 30 deletions(-) (limited to 'ulogd') diff --git a/ulogd/Makefile b/ulogd/Makefile index 22489b3..15963c3 100644 --- a/ulogd/Makefile +++ b/ulogd/Makefile @@ -8,7 +8,7 @@ ULOGD_SL:=BASE OPRINT PWSNIFF # Normally You should not need to change anything below # CC = gcc -CFLAGS = -I. -g -Wall $(INCIPULOG) # -DDEBUG +CFLAGS = -I. -g -Wall $(INCIPULOG) # -DDEBUG # -DDEBUG_CONF SH_CFLAGS:=$(CFLAGS) -fPIC SHARED_LIBS+=$(foreach T,$(ULOGD_SL),extensions/ulogd_$(T).so) @@ -28,7 +28,7 @@ ulogd: ulogd.c $(LIBIPULOG) ulogd.h conffile.o $(CC) $(CFLAGS) -rdynamic -ldl -i ulogd.c conffile.o $(LIBIPULOG)/libipulog.a -o ulogd clean: - rm -f ulogd extensions/*.o extensions/*.so + rm -f ulogd *.o extensions/*.o extensions/*.so install: all mkdir -p /usr/local/lib/ulogd && cp extensions/*.so /usr/local/lib/ulogd diff --git a/ulogd/conffile.c b/ulogd/conffile.c index 2baf8f8..10a537d 100644 --- a/ulogd/conffile.c +++ b/ulogd/conffile.c @@ -1,7 +1,7 @@ /* config file parser functions * (C) 2000 by Harald Welte * - * $Id: conffile.c,v 1.2 2000/09/09 18:27:23 laforge Exp $ + * $Id: conffile.c,v 1.3 2000/09/09 18:35:26 laforge Exp $ * * This code is distributed under the terms of GNU GPL */ @@ -11,12 +11,13 @@ #include "conffile.h" #ifdef DEBUG_CONF -#define DEBUGC(format, args...) fprintf(stderr, format ## args) +#define DEBUGC(format, args...) fprintf(stderr, format, ## args) #else #define DEBUGC(format, args...) #endif static config_entry_t *config = NULL; + config_entry_t *config_errce = NULL; static char *get_word(const char *string) @@ -58,11 +59,23 @@ static int config_iskey(char *name) return 1; } +/*********************************************************************** + * PUBLIC INTERFACE + ***********************************************************************/ + int config_register_key(config_entry_t *ce) { - ce->next = config; - ce->hit = 0; + 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; } @@ -83,8 +96,9 @@ int config_parse_file(const char *fname, int final) return -ERROPEN; } - while (line = fgets(line, LINE_LEN, cfile)) + while (fgets(line, LINE_LEN, cfile)) { + DEBUGC("line read\n"); if (*line == '#') continue; @@ -93,7 +107,7 @@ int config_parse_file(const char *fname, int final) continue; /* if we do the final parse and word is not a config key */ - if (final && !config_iskey(word)) { + if (final && config_iskey(word)) { err = -ERRUNKN; config_errce = ce; goto cpf_error; @@ -103,6 +117,7 @@ int config_parse_file(const char *fname, int final) *(args + strlen(args) - 1 ) = '\0'; for (ce = config; ce; ce = ce->next) { + DEBUGC("parse main loop\n"); if (strcmp(ce->key, word)) { continue; } @@ -114,7 +129,8 @@ int config_parse_file(const char *fname, int final) err = -ERRMULT; goto cpf_error; } - ce->hit++; + if (final) + ce->hit++; switch (ce->type) { case CONFIG_TYPE_STRING: if (strlen(args) < @@ -135,6 +151,7 @@ int config_parse_file(const char *fname, int final) for (ce = config; ce; ce = ce->next) { + DEBUGC("ce post loop, ce=%s\n", ce->key); if ((ce->options & CONFIG_OPT_MANDATORY) && (ce->hit == 0)) { DEBUGC("mandatory config directive %s not found\n", ce->key); diff --git a/ulogd/conffile.h b/ulogd/conffile.h index 8429bbb..6b04695 100644 --- a/ulogd/conffile.h +++ b/ulogd/conffile.h @@ -1,7 +1,7 @@ /* config file parser functions * (C) 2000 by Harald Welte * - * $Id: conffile.h,v 1.2 2000/09/09 18:27:23 laforge Exp $ + * $Id: conffile.h,v 1.3 2000/09/09 18:35:26 laforge Exp $ * * This code is distributed under the terms of GNU GPL */ @@ -35,6 +35,7 @@ enum { #define CONFIG_TYPE_CALLBACK 0x0003 /* valid config options */ +#define CONFIG_OPT_NONE 0x0000 #define CONFIG_OPT_MANDATORY 0x0001 #define CONFIG_OPT_MULTI 0x0002 @@ -53,8 +54,12 @@ typedef struct config_entry { /* if an error occurs, config_errce is set to the erroneous ce */ config_entry_t *config_errce; - + +/* parse the config file "fname", presume all config keys are registered + * if final==1 */ int config_parse_file(const char *fname, int final); + +/* register a linked list of config entries */ int config_register_key(config_entry_t *ce); #endif /* ifndef _CONFFILE_H */ diff --git a/ulogd/include/ulogd/ulogd.h b/ulogd/include/ulogd/ulogd.h index 9ee0691..9e258d3 100644 --- a/ulogd/include/ulogd/ulogd.h +++ b/ulogd/include/ulogd/ulogd.h @@ -1,6 +1,6 @@ #ifndef _ULOGD_H #define _ULOGD_H -/* ulogd, Version $Revision: 1.3 $ +/* ulogd, Version $Revision: 1.4 $ * * first try of a logging daemon for my netfilter ULOG target * for the linux 2.4 netfilter subsystem. @@ -9,7 +9,7 @@ * * this code is released under the terms of GNU GPL * - * $Id: ulogd.h,v 1.3 2000/08/02 12:20:55 laforge Exp $ + * $Id: ulogd.h,v 1.4 2000/08/14 08:28:24 laforge Exp $ */ #include @@ -43,7 +43,8 @@ #define ULOGD_MAX_KEYLEN 32 -#define ulogd_error(format, args...) fprintf(logfile, format, ## args) +#define ulogd_error(format, args...) ulogd_log(8, format, ## args) + extern FILE *logfile; typedef struct ulog_iret { @@ -77,8 +78,11 @@ typedef struct ulog_output { int* (*output)(ulog_iret_t *ret); } ulog_output_t; +/* public interface */ void register_interpreter(ulog_interpreter_t *me); void register_output(ulog_output_t *me); - ulog_iret_t *alloc_ret(const u_int16_t type, const char*); + +/* write a message to the daemons' logfile */ +void ulogd_log(int level, const char *message); #endif diff --git a/ulogd/ulogd.c b/ulogd/ulogd.c index 5c24083..1d3ba70 100644 --- a/ulogd/ulogd.c +++ b/ulogd/ulogd.c @@ -1,4 +1,4 @@ -/* ulogd, Version $Revision: 1.6 $ +/* ulogd, Version $Revision: 1.7 $ * * first try of a logging daemon for my netfilter ULOG target * for the linux 2.4 netfilter subsystem. @@ -7,7 +7,7 @@ * * this code is released under the terms of GNU GPL * - * $Id: ulogd.c,v 1.6 2000/08/14 08:28:24 laforge Exp $ + * $Id: ulogd.c,v 1.7 2000/09/09 18:35:26 laforge Exp $ */ #include @@ -28,17 +28,22 @@ #define DEBUGP(format, args...) #endif -#ifndef ULOGD_PLUGIN_DIR -#define ULOGD_PLUGIN_DIR "/usr/local/lib/ulogd" +/* default config parameters, if not changed in configfile */ +#ifndef ULOGD_PLUGINDIR_DEFAULT +#define ULOGD_PLUGINDIR_DEFAULT "/usr/local/lib/ulogd" +#endif +#ifndef ULOGD_LOGFILE_DEFAULT +#define ULOGD_LOGFILE_DEFAULT "/var/log/ulogd.log" +#endif +#ifndef ULOGD_NLGROUP_DEFAULT +#define ULOGD_NLGROUP_DEFAULT 32 #endif +/* where to look for the config file */ #ifndef ULOGD_CONFIGFILE #define ULOGD_CONFIGFILE "/etc/ulogd.conf" #endif -#ifndef ULOGD_NLGROUP -#define ULOGD_NLGROUP 32 -#endif FILE *logfile = NULL; @@ -133,7 +138,14 @@ void free_ret(ulog_iret_t *ret) } } +void ulogd_log(int level, const char *message) +{ + char *timestr; + timestr = ctime(time()); + fprintf(logfile, "%s <%1.1d> %s\n", timestr, level, message); + +} /* this should pass the result(s) to one or more registered output plugins, * but is currently only printing them out */ static void propagate_results(ulog_iret_t *ret) @@ -179,19 +191,19 @@ static void load_plugins(char *dir) ldir = opendir(dir); if (ldir) { - fname = (char *) malloc(NAME_MAX + strlen(ULOGD_PLUGIN_DIR) + fname = (char *) malloc(NAME_MAX + strlen(dir) + 3); for (dent = readdir(ldir); dent; dent = readdir(ldir)) { if (strncmp(dent->d_name,"ulogd", 5) == 0) { DEBUGP("load_plugins: %s\n", dent->d_name); - sprintf(fname, "%s/%s", ULOGD_PLUGIN_DIR, dent->d_name); + sprintf(fname, "%s/%s", dir, dent->d_name); if (!dlopen(fname, RTLD_NOW)) ulogd_error("load_plugins: %s", dlerror()); } } free(fname); } else - ulogd_error("no plugin directory: %s\n", dir); + ulogd_error("No plugin directory: %s\n", dir); } @@ -200,7 +212,8 @@ static int logfile_open(const char *name) logfile = fopen(name, "a"); if (!logfile) { - fprintf(stderr, "ERROR: unable to open logfile: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: unable to open logfile %s: %s\n", + name, strerror(errno)); exit(2); } return 0; @@ -241,15 +254,23 @@ static int parse_conffile(char *file, int final) } static config_entry_t logf_ce = { NULL, "logfile", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, { "" } }; + CONFIG_OPT_NONE, 0, + { string: ULOGD_LOGFILE_DEFAULT } }; static config_entry_t pldir_ce = { NULL, "plugindir", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, { "" } }; + CONFIG_OPT_NONE, 0, + { string: ULOGD_PLUGINDIR_DEFAULT } }; +static config_entry_t nlgroup_ce = { NULL, "nlgroup", CONFIG_TYPE_INT, + CONFIG_OPT_NONE, 0, + { value: ULOGD_NLGROUP_DEFAULT } }; static int init_conffile(char *file) { + /* linke them together */ + logf_ce.next = &pldir_ce; + pldir_ce.next = &nlgroup_ce; + config_register_key(&logf_ce); - config_register_key(&pldir_ce); /* parse config file the first time (for logfile name, ...) */ return parse_conffile(file, 0); @@ -283,7 +304,7 @@ int main(int argc, char* argv[]) buf = (unsigned char *) malloc(MYBUFSIZ); /* create ipulog handle */ - h = ipulog_create_handle(ipulog_group2gmask(ULOGD_NLGROUP)); + h = ipulog_create_handle(ipulog_group2gmask(nlgroup_ce.u.value)); if (!h) { /* if some error occurrs, print it to stderr */ -- cgit v1.2.3