summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-06-30 16:38:25 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-06-30 16:38:25 +0200
commit1eeeb6f603326234f1d17a16d3c55f8458f7177b (patch)
treeb8c901b9943fb552aef1950d864b7836adc2f964
parenta924cfe6c2da54829f4729d6d56f8a1cc402475e (diff)
downloadrsyslog-1eeeb6f603326234f1d17a16d3c55f8458f7177b.tar.gz
rsyslog-1eeeb6f603326234f1d17a16d3c55f8458f7177b.tar.xz
rsyslog-1eeeb6f603326234f1d17a16d3c55f8458f7177b.zip
first try towards a flex/bison based config parser
-rw-r--r--grammar/conf-fmt145
-rw-r--r--grammar/makefile8
-rw-r--r--grammar/rscript.l23
-rw-r--r--grammar/samp11
-rw-r--r--grammar/utils.c45
5 files changed, 232 insertions, 0 deletions
diff --git a/grammar/conf-fmt b/grammar/conf-fmt
new file mode 100644
index 00000000..e34ab784
--- /dev/null
+++ b/grammar/conf-fmt
@@ -0,0 +1,145 @@
+PRI filter:
+
+- facility and severity may be numeric (but discouraged)
+- format: facility "." priority [";" next-selector] (no whitespace)
+- facility:
+ * auth, authpriv, cron, daemon, kern, lpr, mail, mark, news, security
+ (same as auth), syslog, user, uucp and local0 through local7
+ * multiple
+- "priority" (actually severity):
+ * debug, info, notice, warning, warn (same as warning),
+ err, error (same as err), crit, alert, emerg, panic (same as
+ emerg). The keywords error, warn and panic are deprecated and
+ should not be used anymore.
+ * "=" in front of sev --> exactly this
+ * "!" in front of sev --> ignore this priority
+ * "=" and "!" can be combined
+- * => all fac/severities
+- a '\' at end of line means that the following line f is a
+ continuation line. If so, leading whitespace is stripped from
+ f and then f as appended to the end of the current line, replacing
+ the backslash and all whitespace following it.
+ This makes it somewhat easier to grab selectors from an old-style
+ config stream.
+ '\' [WHITESPACE]* LF
+
+
+DEBIAN SAMPLE
+This probably includes everything that is problematic...
+
+# /etc/rsyslog.conf Configuration file for rsyslog.
+#
+# For more information see
+# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
+
+
+#################
+#### MODULES ####
+#################
+
+$ModLoad imuxsock # provides support for local system logging
+$ModLoad imklog # provides kernel logging support (previously done by rklogd)
+#$ModLoad immark # provides --MARK-- message capability
+
+# provides UDP syslog reception
+#$ModLoad imudp
+#$UDPServerRun 514
+
+# provides TCP syslog reception
+#$ModLoad imtcp
+#$InputTCPServerRun 514
+
+
+###########################
+#### GLOBAL DIRECTIVES ####
+###########################
+
+#
+# Use traditional timestamp format.
+# To enable high precision timestamps, comment out the following line.
+#
+#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
+
+#
+# Set the default permissions for all log files.
+#
+$FileOwner root
+$FileGroup adm
+$FileCreateMode 0640
+$DirCreateMode 0755
+$Umask 0022
+
+#
+# Include all config files in /etc/rsyslog.d/
+#
+$IncludeConfig /etc/rsyslog.d/*.conf
+
+
+###############
+#### RULES ####
+###############
+
+#
+# First some standard log files. Log by facility.
+#
+auth,authpriv.* /var/log/auth.log
+*.*;auth,authpriv.none -/var/log/syslog
+#cron.* /var/log/cron.log
+daemon.* -/var/log/daemon.log
+kern.* -/var/log/kern.log
+lpr.* -/var/log/lpr.log
+mail.* -/var/log/mail.log
+user.* -/var/log/user.log
+
+#
+# Logging for the mail system. Split it up so that
+# it is easy to write scripts to parse these files.
+#
+mail.info -/var/log/mail.info
+mail.warn -/var/log/mail.warn
+mail.err /var/log/mail.err
+
+#
+# Logging for INN news system.
+#
+news.crit /var/log/news/news.crit
+news.err /var/log/news/news.err
+news.notice -/var/log/news/news.notice
+
+#
+# Some "catch-all" log files.
+#
+*.=debug;\
+ auth,authpriv.none;\
+ news.none;mail.none -/var/log/debug
+*.=info;*.=notice;*.=warn;\
+ auth,authpriv.none;\
+ cron,daemon.none;\
+ mail,news.none -/var/log/messages
+
+#
+# Emergencies are sent to everybody logged in.
+#
+*.emerg *
+
+#
+# I like to have messages displayed on the console, but only on a virtual
+# console I usually leave idle.
+#
+#daemon,mail.*;\
+# news.=crit;news.=err;news.=notice;\
+# *.=debug;*.=info;\
+# *.=notice;*.=warn /dev/tty8
+
+# The named pipe /dev/xconsole is for the `xconsole' utility. To use it,
+# you must invoke `xconsole' with the `-file' option:
+#
+# $ xconsole -file /dev/xconsole [...]
+#
+# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
+# busy site..
+#
+daemon.*;mail.*;\
+ news.err;\
+ *.=debug;*.=info;\
+ *.=notice;*.=warn |/dev/xconsole
diff --git a/grammar/makefile b/grammar/makefile
new file mode 100644
index 00000000..520d836b
--- /dev/null
+++ b/grammar/makefile
@@ -0,0 +1,8 @@
+rscript: lex.yy.c utils.o
+ gcc -o rscript lex.yy.c utils.o -lestr -lfl
+
+lex.yy.c: rscript.l
+ flex rscript.l
+
+utils.o: utils.c
+ gcc -c utils.c
diff --git a/grammar/rscript.l b/grammar/rscript.l
new file mode 100644
index 00000000..eb2c23ad
--- /dev/null
+++ b/grammar/rscript.l
@@ -0,0 +1,23 @@
+%{
+#include <libestr.h>
+%}
+
+%%
+
+
+. { printf("%s", yytext); }
+
+%%
+int
+main(int argc, char *argv[])
+{
+ es_str_t *str;
+ YY_BUFFER_STATE bp;
+ char ln[10240];
+
+ readConfFile(stdin, &str);
+ //printf("buffer: %s\n", es_getBufAddr(str));
+ bp = yy_scan_buffer(es_getBufAddr(str), es_strlen(str));
+ //yy_switch_to_buffer(bp);
+ yylex();
+}
diff --git a/grammar/samp b/grammar/samp
new file mode 100644
index 00000000..91d475b0
--- /dev/null
+++ b/grammar/samp
@@ -0,0 +1,11 @@
+daemon.*;mail.*;\
+ news.err;\
+ *.=debug;*.=info;\
+ *.=notice;*.=warn |/dev/xconsole
+*.=info;*.=notice;*.=warn;\
+ auth,authpriv.none;\
+ cron,daemon.none;\
+ mail,news.none -/var/log/messages
+
+mail.info -/var/log/mail.info
+
diff --git a/grammar/utils.c b/grammar/utils.c
new file mode 100644
index 00000000..f9c50bc9
--- /dev/null
+++ b/grammar/utils.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include "libestr.h"
+
+void
+readConfFile(FILE *fp, es_str_t **str)
+{
+ int c;
+ char ln[10240];
+ int len, i;
+ int start; /* start index of to be submitted text */
+ char *fgetsRet;
+ int bContLine = 0;
+
+ *str = es_newStr(4096);
+
+ while(fgets(ln, sizeof(ln), fp) != NULL) {
+ len = strlen(ln);
+ /* if we are continuation line, we need to drop leading WS */
+ if(bContLine) {
+ for(start = 0 ; start < len && isspace(ln[start]) ; ++start)
+ /* JUST SCAN */;
+ } else {
+ start = 0;
+ }
+ for(i = len - 1 ; i >= start && isspace(ln[i]) ; --i)
+ /* JUST SCAN */;
+ if(i >= 0) {
+ if(ln[i] == '\\') {
+ --i;
+ bContLine = 1;
+ } else {
+ bContLine = 0;
+ }
+ /* add relevant data to buffer */
+ es_addBuf(str, ln+start, i+1 - start);
+ if(!bContLine)
+ es_addChar(str, '\n');
+ }
+ }
+ /* indicate end of buffer to flex */
+ es_addChar(str, '\0');
+ es_addChar(str, '\0');
+}