From 73e4c2a0c637a16b19a54a04b04625e94b3ee4eb Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 17 Jul 2007 11:31:17 +0000 Subject: added $CreateDirs, $DebugPrintTemplateList, $ResetConfigVariables directives --- ChangeLog | 3 +++ syslogd-types.h | 1 + syslogd.c | 47 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3454a027..80624cf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ Version 1.16.1 (RGer), 2007-07-17 - added $EscapeControlCharactersOnReceive config parameter - added $ControlCharacterEscapePrefix config parameter - added $DirCreateMode config parameter +- added $CreateDirs config parameter +- added $DebugPrintTemplateList config parameter +- added $ResetConfigVariables config parameter - added regular expression support to the filter engine thanks to Michel Samia for providing the patch! - enhanced $AllowedSender functionality. Credits to mildew@gmail.com for diff --git a/syslogd-types.h b/syslogd-types.h index 2be96605..23dc706a 100644 --- a/syslogd-types.h +++ b/syslogd-types.h @@ -252,6 +252,7 @@ struct filed { char bDynamicName; /* 0 - static name, 1 - dynamic name (with properties) */ int fCreateMode; /* file creation mode for open() */ int fDirCreateMode; /* creation mode for mkdir() */ + int bCreateDirs; /* auto-create directories? */ int iCurrElt; /* currently active cache element (-1 = none) */ int iCurrCacheSize; /* currently cache size (1-based) */ int iDynaFileCacheSize; /* size of file handle cache */ diff --git a/syslogd.c b/syslogd.c index 9cf8e89c..b1fdcc31 100644 --- a/syslogd.c +++ b/syslogd.c @@ -639,6 +639,8 @@ static struct code FacNames[] = { }; static int Debug; /* debug flag - read-only after startup */ +static int bDebugPrintTemplateList;/* output template list in debug mode? */ +static int bCreateDirs; /* auto-create directories for dynaFiles: 0 - no, 1 - yes */ static int bDropMalPTRMsgs = 0;/* Drop messages which have malicious PTR records during DNS lookup */ static uchar cCCEscapeChar = '\\';/* character to be used to start an escape sequence for control chars */ static int bEscapeCCOnRcv; /* escape control characters on reception: 0 - no, 1 - yes */ @@ -705,6 +707,23 @@ static char* getFIOPName(unsigned iFIOP) } +/* Reset config variables to default values. + * rgerhards, 2007-07-17 + */ +static void resetConfigVariables(void) +{ + iDynaFileCacheSize = 10; + fCreateMode = 0644; + fDirCreateMode = 0644; + cCCEscapeChar = '#'; + bCreateDirs = 1; + bDebugPrintTemplateList = 1; + bEscapeCCOnRcv = 1; /* default is to escape control characters */ + bReduceRepeatMsgs = (logEveryMsg == 1) ? 0 : 1; + +} + + /* support for defining allowed TCP and UDP senders. We use the same * structure to implement this (a linked list), but we define two different * list roots, one for UDP and one for TCP. @@ -6232,7 +6251,7 @@ static int prepareDynFile(selector_t *f) f->f_file = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY, f->f_un.f_file.fCreateMode); - if(f->f_file == -1) { + if(f->f_file == -1 && f->f_un.f_file.bCreateDirs) { /* on first failure, we try to create parent directories and then * retry the open. Only if that fails, we give up. We do not report * any errors here ourselfs but let the code fall through to error @@ -7507,7 +7526,7 @@ static void doFileCreateModeUmaskLine(uchar **pp, enum eDirective eDir) switch(eDir) { case DIR_DIRCREATEMODE: fDirCreateMode = iMode; - dprintf("FileCreateMode set to 0%o.\n", iMode); + dprintf("DirCreateMode set to 0%o.\n", iMode); break; case DIR_FILECREATEMODE: fCreateMode = iMode; @@ -7631,6 +7650,12 @@ void cfsysline(uchar *p) doBinaryOptionLine(&p, &bEscapeCCOnRcv); } else if(!strcasecmp((char*) szCmd, "dropmsgswithmaliciousdnsptrrecords")) { doBinaryOptionLine(&p, &bDropMalPTRMsgs); + } else if(!strcasecmp((char*) szCmd, "createdirs")) { + doBinaryOptionLine(&p, &bCreateDirs); + } else if(!strcasecmp((char*) szCmd, "debugprinttemplatelist")) { + doBinaryOptionLine(&p, &bDebugPrintTemplateList); + } else if(!strcasecmp((char*) szCmd, "resetconfigvariables")) { + resetConfigVariables(); } else { /* invalid command! */ char err[100]; snprintf(err, sizeof(err)/sizeof(char), @@ -7779,12 +7804,7 @@ static void init() nextp = NULL; /* re-setting values to defaults (where applicable) */ - iDynaFileCacheSize = 10; - fCreateMode = 0644; - fDirCreateMode = 0644; - cCCEscapeChar = '#'; - bEscapeCCOnRcv = 1; /* default is to escape control characters */ - bReduceRepeatMsgs = (logEveryMsg == 1) ? 0 : 1; + resetConfigVariables(); /* open the configuration file */ if ((cf = fopen(ConfFile, "r")) == NULL) { @@ -7969,9 +7989,11 @@ static void init() case F_TTY: case F_CONSOLE: if(f->f_un.f_file.bDynamicName) { - printf("[dynamic, template='%s', cache size=%d]", + printf("[dynamic, template='%s', cache size=%d, " + "create dirs=%d]", f->f_un.f_file.f_fname, - f->f_un.f_file.iDynaFileCacheSize); + f->f_un.f_file.iDynaFileCacheSize, + f->f_un.f_file.bCreateDirs); } else { /* regular file */ printf("%s", f->f_un.f_file.f_fname); if (f->f_file == -1) @@ -8000,13 +8022,15 @@ static void init() } } printf("\n"); - tplPrintList(); + if(bDebugPrintTemplateList) + tplPrintList(); ochPrintList(); #ifdef SYSLOG_INET /* now the allowedSender lists: */ PrintAllowedSenders(1); /* UDP */ PrintAllowedSenders(2); /* TCP */ + printf("\n"); #endif /* #ifdef SYSLOG_INET */ printf("Messages with malicious PTR DNS Records are %sdropped.\n", @@ -8898,6 +8922,7 @@ static rsRetVal cfline(char *line, register selector_t *f) f->f_un.f_file.iCurrElt = -1; /* no current element */ f->f_un.f_file.fCreateMode = fCreateMode; /* freeze current setting */ f->f_un.f_file.fDirCreateMode = fDirCreateMode; /* preserve current setting */ + f->f_un.f_file.bCreateDirs = bCreateDirs; /* preserve current setting */ f->f_un.f_file.iDynaFileCacheSize = iDynaFileCacheSize; /* freeze current setting */ /* we now allocate the cache table. We use calloc() intentionally, as we * need all pointers to be initialized to NULL pointers. -- cgit