re-implemented $EscapeControlCharacterTab config directive

Based on Jonathan Bond-Caron's patch for v4. This now also includes some
automatted tests.
This commit is contained in:
Rainer Gerhards 2009-11-27 11:26:09 +01:00
parent 306ba17b54
commit 18399f11cd
9 changed files with 72 additions and 1 deletions

View File

@ -6,6 +6,9 @@ Version 5.5.1 [DEVEL] (rgerhards), 2009-11-??
epoll netstream drivers. So far, an epoll driver has only been
implemented for plain tcp syslog, the rest will follow once the code
proves well in practice AND there is demand.
- re-implemented $EscapeControlCharacterTab config directive
Based on Jonathan Bond-Caron's patch for v4. This now also includes some
automatted tests.
- bugfix: enabling GSSServer crashes rsyslog startup
Thanks to Tomas Kubina for the patch [imgssapi]
- bugfix (kind of): check if TCP connection is still alive if using TLS

View File

@ -60,6 +60,7 @@ DEFobjCurrIf(ruleset)
/* config data */
static uchar cCCEscapeChar = '#';/* character to be used to start an escape sequence for control chars */
static int bEscapeCCOnRcv = 1; /* escape control characters on reception: 0 - no, 1 - yes */
static int bEscapeTab = 1; /* escape tab control character when doing CC escapes: 0 - no, 1 - yes */
static int bDropTrailingLF = 1; /* drop trailing LF's on reception? */
/* This is the list of all parsers known to us.
@ -339,6 +340,11 @@ SanitizeMsg(msg_t *pMsg)
* needs sanitation than to do the sanitation in any case. So we first do
* this and terminate when it is not needed - which is expectedly the case
* for the vast majority of messages. -- rgerhards, 2009-06-15
* Note that we do NOT check here if tab characters are to be escaped or
* not. I expect this functionality to be seldomly used and thus I do not
* like to pay the performance penalty. So the penalty is only with those
* that actually use it, because we may call the sanitizer without actual
* need below (but it then still will work perfectly well!). -- rgerhards, 2009-11-27
*/
int bNeedSanitize = 0;
for(iSrc = 0 ; iSrc < lenMsg ; iSrc++) {
@ -367,7 +373,7 @@ SanitizeMsg(msg_t *pMsg)
CHKmalloc(pDst = MALLOC(sizeof(uchar) * (iMaxLine + 1)));
iSrc = iDst = 0;
while(iSrc < lenMsg && iDst < maxDest - 3) { /* leave some space if last char must be escaped */
if(iscntrl((int) pszMsg[iSrc])) {
if(iscntrl((int) pszMsg[iSrc]) && (pszMsg[iSrc] != '\t' || bEscapeTab)) {
/* note: \0 must always be escaped, the rest of the code currently
* can not handle it! -- rgerhards, 2009-08-26
*/
@ -619,6 +625,7 @@ resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unus
{
cCCEscapeChar = '#';
bEscapeCCOnRcv = 1; /* default is to escape control characters */
bEscapeTab = 1; /* default is to escape control characters */
bDropTrailingLF = 1; /* default is to drop trailing LF's on reception */
return RS_RET_OK;
@ -670,6 +677,7 @@ BEGINObjClassInit(parser, 1, OBJ_IS_CORE_MODULE) /* class, version */
CHKiRet(regCfSysLineHdlr((uchar *)"controlcharacterescapeprefix", 0, eCmdHdlrGetChar, NULL, &cCCEscapeChar, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"droptrailinglfonreception", 0, eCmdHdlrBinary, NULL, &bDropTrailingLF, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactersonreceive", 0, eCmdHdlrBinary, NULL, &bEscapeCCOnRcv, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactertab", 0, eCmdHdlrBinary, NULL, &bEscapeTab, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
InitParserList(&pParsLstRoot);

View File

@ -37,6 +37,8 @@ TESTS += omod-if-array.sh \
threadingmqaq.sh \
discard.sh \
badqi.sh \
tabescape_dflt.sh \
tabescape_off.sh \
fieldtest.sh
endif
@ -194,6 +196,12 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
execonlyonce.sh \
testsuites/execonlyonce.conf \
testsuites/execonlyonce.data \
tabescape_dflt.sh \
testsuites/tabescape_dflt.conf \
testsuites/1.tabescape_dflt \
tabescape_off.sh \
testsuites/tabescape_off.conf \
testsuites/1.tabescape_off \
DiagTalker.java \
cfg.sh

14
tests/tabescape_dflt.sh Executable file
View File

@ -0,0 +1,14 @@
echo ===============================================================================
echo \[tabescape_dflt.sh\]: test for default tab escaping
$srcdir/killrsyslog.sh # kill rsyslogd if it runs for some reason
./nettester -ttabescape_dflt -iudp
if [ "$?" -ne "0" ]; then
exit 1
fi
echo test via tcp
./nettester -ttabescape_dflt -itcp
if [ "$?" -ne "0" ]; then
exit 1
fi

14
tests/tabescape_off.sh Executable file
View File

@ -0,0 +1,14 @@
echo ===============================================================================
echo \[tabescape_off.sh\]: test for tab escaping off
$srcdir/killrsyslog.sh # kill rsyslogd if it runs for some reason
./nettester -ttabescape_off -iudp
if [ "$?" -ne "0" ]; then
exit 1
fi
echo test via tcp
./nettester -ttabescape_off -itcp
if [ "$?" -ne "0" ]; then
exit 1
fi

View File

@ -0,0 +1,3 @@
<167>Mar 6 16:57:54 172.20.245.8 test: before HT after HT (do NOT remove TAB!)
before HT#011after HT (do NOT remove TAB!)
#Only the first two lines are important, you may place anything behind them!

View File

@ -0,0 +1,3 @@
<167>Mar 6 16:57:54 172.20.245.8 test: before HT after HT (do NOT remove TAB!)
before HT after HT (do NOT remove TAB!)
#Only the first two lines are important, you may place anything behind them!

View File

@ -0,0 +1,8 @@
$ModLoad ../plugins/omstdout/.libs/omstdout
$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
$ErrorMessagesToStderr off
# use a special format that we can easily parse in expect
$template fmt,"%msg%\n"
*.* :omstdout:;fmt

View File

@ -0,0 +1,10 @@
$ModLoad ../plugins/omstdout/.libs/omstdout
$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
$ErrorMessagesToStderr off
$EscapeControlCharacterTab off
# use a special format that we can easily parse in expect
$template fmt,"%msg%\n"
*.* :omstdout:;fmt