1
/* The config file handler (not yet a real object)
3
* This file is based on an excerpt from syslogd.c, which dates back
4
* much later. I began the file on 2008-02-19 as part of the modularization
5
* effort. Over time, a clean abstration will become even more important
6
* because the config file handler will by dynamically be loaded and be
7
* kept in memory only as long as the config file is actually being
8
* processed. Thereafter, it shall be unloaded. -- rgerhards
10
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
12
* This file is part of rsyslog.
14
* Rsyslog is free software: you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation, either version 3 of the License, or
17
* (at your option) any later version.
19
* Rsyslog is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
27
* A copy of the GPL can be found in the file "COPYING" in this distribution.
42
#include <sys/types.h>
52
#include "cfsysline.h"
54
#include "outchannel.h"
55
#include "stringbuf.h"
57
#include "stringbuf.h"
62
/* forward definitions */
63
static rsRetVal cfline(uchar *line, selector_t **pfCurr);
64
static rsRetVal processConfFile(uchar *pConfFile);
71
DEFobjCurrIf(ctok_token)
76
/* The following global variables are used for building
77
* tag and host selector lines during startup and config reload.
78
* This is stored as a global variable pool because of its ease. It is
79
* also fairly compatible with multi-threading as the stratup code must
80
* be run in a single thread anyways. So there can be no race conditions. These
81
* variables are no longer used once the configuration has been loaded (except,
82
* of course, during a reload). rgerhards 2005-10-18
84
EHostnameCmpMode eDfltHostnameCmpMode;
85
cstr_t *pDfltHostnameCmp;
86
cstr_t *pDfltProgNameCmp;
89
/* process a directory and include all of its files into
90
* the current config file. There is no specific order of inclusion,
91
* files are included in the order they are read from the directory.
92
* The caller must have make sure that the provided parameter is
94
* rgerhards, 2007-08-01
96
static rsRetVal doIncludeDirectory(uchar *pDirName)
103
char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
108
uchar szFullFileName[MAXFNAME];
110
ASSERT(pDirName != NULL);
112
if((pDir = opendir((char*) pDirName)) == NULL) {
113
errmsg.LogError(NO_ERRCODE, "error opening include directory");
114
ABORT_FINALIZE(RS_RET_FOPEN_FAILURE);
117
/* prepare file name buffer */
118
iDirNameLen = strlen((char*) pDirName);
119
memcpy(szFullFileName, pDirName, iDirNameLen);
121
/* now read the directory */
123
while(readdir_r(pDir, &u.d, &res) == 0) {
125
break; /* this also indicates end of directory */
127
/* TODO: find an alternate way to checking for special files if this is
128
* not defined. This is currently a known problem on HP UX, but the work-
129
* around is simple: do not create special files in that directory. So
130
* fixing this is actually not the most important thing on earth...
131
* rgerhards, 2008-03-04
133
if(res->d_type != DT_REG)
134
continue; /* we are not interested in special files */
136
if(res->d_name[0] == '.')
137
continue; /* these files we are also not interested in */
139
/* construct filename */
140
iFileNameLen = strlen(res->d_name);
141
if (iFileNameLen > NAME_MAX)
142
iFileNameLen = NAME_MAX;
143
memcpy(szFullFileName + iDirNameLen, res->d_name, iFileNameLen);
144
*(szFullFileName + iDirNameLen + iFileNameLen) = '\0';
145
dbgprintf("including file '%s'\n", szFullFileName);
146
processConfFile(szFullFileName);
147
/* we deliberately ignore the iRet of processConfFile() - this is because
148
* failure to process one file does not mean all files will fail. By ignoring,
149
* we retry with the next file, which is the best thing we can do. -- rgerhards, 2007-08-01
153
if(iEntriesDone == 0) {
154
/* I just make it a debug output, because I can think of a lot of cases where it
155
* makes sense not to have any files. E.g. a system maintainer may place a $Include
156
* into the config file just in case, when additional modules be installed. When none
157
* are installed, the directory will be empty, which is fine. -- rgerhards 2007-08-01
159
dbgprintf("warning: the include directory contained no files - this may be ok.\n");
170
/* process a $include config line. That type of line requires
171
* inclusion of another file.
172
* rgerhards, 2007-08-01
175
doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal)
178
char pattern[MAXFNAME];
182
struct stat fileInfo;
187
if(getSubString(pp, (char*) pattern, sizeof(pattern) / sizeof(char), ' ') != 0) {
188
errmsg.LogError(NO_ERRCODE, "could not extract group name");
189
ABORT_FINALIZE(RS_RET_NOT_FOUND);
192
/* Use GLOB_MARK to append a trailing slash for directories.
193
* Required by doIncludeDirectory().
195
glob(pattern, GLOB_MARK, NULL, &cfgFiles);
197
for(i = 0; i < cfgFiles.gl_pathc; i++) {
198
cfgFile = (uchar*) cfgFiles.gl_pathv[i];
200
if(stat((char*) cfgFile, &fileInfo) != 0)
201
continue; /* continue with the next file if we can't stat() the file */
203
if(S_ISREG(fileInfo.st_mode)) { /* config file */
204
dbgprintf("requested to include config file '%s'\n", cfgFile);
205
iRet = processConfFile(cfgFile);
206
} else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */
207
dbgprintf("requested to include directory '%s'\n", cfgFile);
208
iRet = doIncludeDirectory(cfgFile);
209
} else { /* TODO: shall we handle symlinks or not? */
210
dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile);
221
/* process a $ModLoad config line.
224
doModLoad(uchar **pp, __attribute__((unused)) void* pVal)
233
skipWhiteSpace(pp); /* skip over any whitespace */
234
if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) {
235
errmsg.LogError(NO_ERRCODE, "could not extract module name");
236
ABORT_FINALIZE(RS_RET_NOT_FOUND);
238
skipWhiteSpace(pp); /* skip over any whitespace */
240
/* this below is a quick and dirty hack to provide compatibility with the
241
* $ModLoad MySQL forward compatibility statement. TODO: clean this up
242
* For the time being, it is clean enough, it just needs to be done
243
* differently when we have a full design for loadable plug-ins. For the
244
* time being, we just mangle the names a bit.
245
* rgerhards, 2007-08-14
247
if(!strcmp((char*) szName, "MySQL"))
248
pModName = (uchar*) "ommysql.so";
252
CHKiRet(module.Load(pModName));
259
/* parse and interpret a $-config line that starts with
260
* a name (this is common code). It is parsed to the name
261
* and then the proper sub-function is called to handle
262
* the actual directive.
263
* rgerhards 2004-11-17
264
* rgerhards 2005-06-21: previously only for templates, now
268
doNameLine(uchar **pp, void* pVal)
272
enum eDirective eDir;
279
eDir = (enum eDirective) pVal; /* this time, it actually is NOT a pointer! */
281
if(getSubString(&p, szName, sizeof(szName) / sizeof(char), ',') != 0) {
282
errmsg.LogError(NO_ERRCODE, "Invalid config line: could not extract name - line ignored");
283
ABORT_FINALIZE(RS_RET_NOT_FOUND);
286
++p; /* comma was eaten */
288
/* we got the name - now we pass name & the rest of the string
289
* to the subfunction. It makes no sense to do further
290
* parsing here, as this is in close interaction with the
291
* respective subsystem. rgerhards 2004-11-17
296
tplAddLine(szName, &p);
299
ochAddLine(szName, &p);
301
case DIR_ALLOWEDSENDER:
302
net.addAllowedSenderLine(szName, &p);
304
default:/* we do this to avoid compiler warning - not all
305
* enum values call this function, so an incomplete list
306
* is quite ok (but then we should not run into this code,
307
* so at least we log a debug warning).
309
dbgprintf("INTERNAL ERROR: doNameLine() called with invalid eDir %d.\n",
321
/* Parse and interpret a system-directive in the config line
322
* A system directive is one that starts with a "$" sign. It offers
323
* extended configuration parameters.
324
* 2004-11-17 rgerhards
331
uchar errMsg[128]; /* for dynamic error messages */
335
if(getSubString(&p, (char*) szCmd, sizeof(szCmd) / sizeof(uchar), ' ') != 0) {
336
errmsg.LogError(NO_ERRCODE, "Invalid $-configline - could not extract command - line ignored\n");
337
ABORT_FINALIZE(RS_RET_NOT_FOUND);
340
/* we now try and see if we can find the command in the registered
341
* list of cfsysline handlers. -- rgerhards, 2007-07-31
343
CHKiRet(processCfSysLineCommand(szCmd, &p));
345
/* now check if we have some extra characters left on the line - that
346
* should not be the case. Whitespace is OK, but everything else should
347
* trigger a warning (that may be an indication of undesired behaviour).
348
* An exception, of course, are comments (starting with '#').
349
* rgerhards, 2007-07-04
353
if(*p && *p != '#') { /* we have a non-whitespace, so let's complain */
354
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
355
"error: extra characters in config line ignored: '%s'", p);
357
errmsg.LogError(NO_ERRCODE, "%s", errMsg);
367
/* process a configuration file
368
* started with code from init() by rgerhards on 2007-07-31
371
processConfFile(uchar *pConfFile)
376
selector_t *fCurr = NULL;
381
ASSERT(pConfFile != NULL);
383
if((cf = fopen((char*)pConfFile, "r")) == NULL) {
384
ABORT_FINALIZE(RS_RET_FOPEN_FAILURE);
387
/* Now process the file.
390
while (fgets((char*)cline, sizeof(cbuf) - (cline - cbuf), cf) != NULL) {
392
/* drop LF - TODO: make it better, replace fgets(), but its clean as it is */
393
if(cline[strlen((char*)cline)-1] == '\n') {
394
cline[strlen((char*)cline) -1] = '\0';
396
/* check for end-of-section, comments, strip off trailing
397
* spaces and newline character.
401
if (*p == '\0' || *p == '#')
404
/* we now need to copy the characters to the begin of line. As this overlaps,
405
* we can not use strcpy(). -- rgerhards, 2008-03-20
406
* TODO: review the code at whole - this is highly suspect (but will go away
407
* once we do the rest of RainerScript).
409
/* was: strcpy((char*)cline, (char*)p); */
410
for( i = 0 ; p[i] != '\0' ; ++i) {
415
for (p = (uchar*) strchr((char*)cline, '\0'); isspace((int) *--p);)
418
if ((p - cbuf) > BUFSIZ - 30) {
419
/* Oops the buffer is full - what now? */
428
*++p = '\0'; /* TODO: check this */
430
/* we now have the complete line, and are positioned at the first non-whitespace
431
* character. So let's process it
433
if(cfline(cbuf, &fCurr) != RS_RET_OK) {
434
/* we log a message, but otherwise ignore the error. After all, the next
435
* line can be correct. -- rgerhards, 2007-08-02
437
uchar szErrLoc[MAXFNAME + 64];
438
dbgprintf("config line NOT successfully processed\n");
439
snprintf((char*)szErrLoc, sizeof(szErrLoc) / sizeof(uchar),
440
"%s, line %d", pConfFile, iLnNbr);
441
errmsg.LogError(NO_ERRCODE, "the last error occured in %s", (char*)szErrLoc);
445
/* we probably have one selector left to be added - so let's do that now */
446
CHKiRet(selectorAddList(fCurr));
448
/* close the configuration file */
452
if(iRet != RS_RET_OK) {
455
selectorDestruct(fCurr);
457
rs_strerror_r(errno, errStr, sizeof(errStr));
458
dbgprintf("error %d processing config file '%s'; os error (if any): %s\n",
459
iRet, pConfFile, errStr);
465
/* Helper to cfline() and its helpers. Parses a template name
466
* from an "action" line. Must be called with the Line pointer
467
* pointing to the first character after the semicolon.
468
* rgerhards 2004-11-19
469
* changed function to work with OMSR. -- rgerhards, 2007-07-27
470
* the default template is to be used when no template is specified.
472
rsRetVal cflineParseTemplateName(uchar** pp, omodStringRequest_t *pOMSR, int iEntry, int iTplOpts, uchar *dfltTplName)
481
ASSERT(pOMSR != NULL);
484
/* a template must follow - search it and complain, if not found */
488
else if(*p != '\0' && *p != '#') {
489
errmsg.LogError(NO_ERRCODE, "invalid character in selector line - ';template' expected");
490
ABORT_FINALIZE(RS_RET_ERR);
493
skipWhiteSpace(&p); /* go to begin of template name */
495
if(*p == '\0' || *p == '#') {
496
/* no template specified, use the default */
497
/* TODO: check NULL ptr */
498
tplName = (uchar*) strdup((char*)dfltTplName);
500
/* template specified, pick it up */
501
if(rsCStrConstruct(&pStrB) != RS_RET_OK) {
502
glblHadMemShortage = 1;
503
iRet = RS_RET_OUT_OF_MEMORY;
507
/* now copy the string */
508
while(*p && *p != '#' && !isspace((int) *p)) {
509
CHKiRet(rsCStrAppendChar(pStrB, *p));
512
CHKiRet(rsCStrFinish(pStrB));
513
CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &tplName, 0));
516
iRet = OMSRsetEntry(pOMSR, iEntry, tplName, iTplOpts);
517
if(iRet != RS_RET_OK) goto finalize_it;
525
/* Helper to cfline(). Parses a file name up until the first
526
* comma and then looks for the template specifier. Tries
527
* to find that template.
528
* rgerhards 2004-11-18
529
* parameter pFileName must point to a buffer large enough
530
* to hold the largest possible filename.
531
* rgerhards, 2007-07-25
532
* updated to include OMSR pointer -- rgerhards, 2007-07-27
533
* updated to include template name -- rgerhards, 2008-03-28
536
cflineParseFileName(uchar* p, uchar *pFileName, omodStringRequest_t *pOMSR, int iEntry, int iTplOpts, uchar *pszTpl)
538
register uchar *pName;
542
ASSERT(pOMSR != NULL);
545
i = 1; /* we start at 1 so that we reseve space for the '\0'! */
546
while(*p && *p != ';' && i < MAXFNAME) {
552
iRet = cflineParseTemplateName(&p, pOMSR, iEntry, iTplOpts, pszTpl);
559
* Helper to cfline(). This function takes the filter part of a traditional, PRI
560
* based line and decodes the PRIs given in the selector line. It processed the
561
* line up to the beginning of the action part. A pointer to that beginnig is
562
* passed back to the caller.
563
* rgerhards 2005-09-15
565
static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f)
577
ASSERT(pline != NULL);
578
ASSERT(*pline != NULL);
581
dbgprintf(" - traditional PRI filter\n");
582
errno = 0; /* keep strerror_r() stuff out of logerror messages */
584
f->f_filter_type = FILTER_PRI;
585
/* Note: file structure is pre-initialized to zero because it was
586
* created with calloc()!
588
for (i = 0; i <= LOG_NFACILITIES; i++) {
589
f->f_filterData.f_pmask[i] = TABLE_NOPRI;
592
/* scan through the list of selectors */
593
for (p = *pline; *p && *p != '\t' && *p != ' ';) {
595
/* find the end of this facility name list */
596
for (q = p; *q && *q != '\t' && *q++ != '.'; )
599
/* collect priority name */
600
for (bp = buf; *q && !strchr("\t ,;", *q); )
605
while (strchr(",;", *q))
608
/* decode priority name */
611
for (bp=buf; *(bp+1); bp++)
621
pri = decodeSyslogName(&buf[1], syslogPriNames);
625
pri = decodeSyslogName(buf, syslogPriNames);
629
snprintf((char*) xbuf, sizeof(xbuf), "unknown priority name \"%s\"", buf);
630
errmsg.LogError(NO_ERRCODE, "%s", xbuf);
634
/* scan facilities */
635
while (*p && !strchr("\t .;", *p)) {
636
for (bp = buf; *p && !strchr("\t ,;.", *p); )
640
for (i = 0; i <= LOG_NFACILITIES; i++) {
641
if ( pri == INTERNAL_NOPRI ) {
643
f->f_filterData.f_pmask[i] = TABLE_ALLPRI;
645
f->f_filterData.f_pmask[i] = TABLE_NOPRI;
647
else if ( singlpri ) {
649
f->f_filterData.f_pmask[i] &= ~(1<<pri);
651
f->f_filterData.f_pmask[i] |= (1<<pri);
655
if ( pri == TABLE_ALLPRI ) {
657
f->f_filterData.f_pmask[i] = TABLE_NOPRI;
659
f->f_filterData.f_pmask[i] = TABLE_ALLPRI;
664
for (i2= 0; i2 <= pri; ++i2)
665
f->f_filterData.f_pmask[i] &= ~(1<<i2);
667
for (i2= 0; i2 <= pri; ++i2)
668
f->f_filterData.f_pmask[i] |= (1<<i2);
673
i = decodeSyslogName(buf, syslogFacNames);
676
snprintf((char*) xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf);
677
errmsg.LogError(NO_ERRCODE, "%s", xbuf);
681
if ( pri == INTERNAL_NOPRI ) {
683
f->f_filterData.f_pmask[i >> 3] = TABLE_ALLPRI;
685
f->f_filterData.f_pmask[i >> 3] = TABLE_NOPRI;
686
} else if ( singlpri ) {
688
f->f_filterData.f_pmask[i >> 3] &= ~(1<<pri);
690
f->f_filterData.f_pmask[i >> 3] |= (1<<pri);
692
if ( pri == TABLE_ALLPRI ) {
694
f->f_filterData.f_pmask[i >> 3] = TABLE_NOPRI;
696
f->f_filterData.f_pmask[i >> 3] = TABLE_ALLPRI;
699
for (i2= 0; i2 <= pri; ++i2)
700
f->f_filterData.f_pmask[i >> 3] &= ~(1<<i2);
702
for (i2= 0; i2 <= pri; ++i2)
703
f->f_filterData.f_pmask[i >> 3] |= (1<<i2);
707
while (*p == ',' || *p == ' ')
714
/* skip to action part */
715
while (*p == '\t' || *p == ' ')
723
/* Helper to cfline(). This function processes an "if" type of filter,
724
* what essentially means it parses an expression. As usual,
725
* It processes the line up to the beginning of the action part.
726
* A pointer to that beginnig is passed back to the caller.
727
* rgerhards 2008-01-19
729
static rsRetVal cflineProcessIfFilter(uchar **pline, register selector_t *f)
733
ctok_token_t *pToken;
735
ASSERT(pline != NULL);
736
ASSERT(*pline != NULL);
739
dbgprintf(" - general expression-based filter\n");
740
errno = 0; /* keep strerror_r() stuff out of logerror messages */
742
dbgprintf("calling expression parser, pp %p ('%s')\n", *pline, *pline);
743
f->f_filter_type = FILTER_EXPR;
745
/* if we come to over here, pline starts with "if ". We just skip that part. */
748
/* we first need a tokenizer... */
749
CHKiRet(ctok.Construct(&tok));
750
CHKiRet(ctok.Setpp(tok, *pline));
751
CHKiRet(ctok.ConstructFinalize(tok));
753
/* now construct our expression */
754
CHKiRet(expr.Construct(&f->f_filterData.f_expr));
755
CHKiRet(expr.ConstructFinalize(f->f_filterData.f_expr));
758
CHKiRet(expr.Parse(f->f_filterData.f_expr, tok));
760
/* we now need to parse off the "then" - and note an error if it is
763
CHKiRet(ctok.GetToken(tok, &pToken));
764
if(pToken->tok != ctok_THEN) {
765
ctok_token.Destruct(&pToken);
766
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
769
ctok_token.Destruct(&pToken); /* no longer needed */
771
/* we are done, so we now need to restore things */
772
CHKiRet(ctok.Getpp(tok, pline));
773
CHKiRet(ctok.Destruct(&tok));
775
/* we now need to skip whitespace to the action part, else we confuse
776
* the legacy rsyslog conf parser. -- rgerhards, 2008-02-25
778
while(isspace(**pline))
782
if(iRet == RS_RET_SYNTAX_ERROR) {
783
errmsg.LogError(NO_ERRCODE, "syntax error in expression");
790
/* Helper to cfline(). This function takes the filter part of a property
791
* based filter and decodes it. It processes the line up to the beginning
792
* of the action part. A pointer to that beginnig is passed back to the caller.
793
* rgerhards 2005-09-15
795
static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f)
800
int iOffset; /* for compare operations */
802
ASSERT(pline != NULL);
803
ASSERT(*pline != NULL);
806
dbgprintf(" - property-based filter\n");
807
errno = 0; /* keep strerror_r() stuff out of logerror messages */
809
f->f_filter_type = FILTER_PROP;
811
/* create parser object starting with line string without leading colon */
812
if((iRet = rsParsConstructFromSz(&pPars, (*pline)+1)) != RS_RET_OK) {
813
errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring selector", iRet);
818
iRet = parsDelimCStr(pPars, &f->f_filterData.prop.pCSPropName, ',', 1, 1, 1);
819
if(iRet != RS_RET_OK) {
820
errmsg.LogError(NO_ERRCODE, "error %d parsing filter property - ignoring selector", iRet);
821
rsParsDestruct(pPars);
826
iRet = parsDelimCStr(pPars, &pCSCompOp, ',', 1, 1, 1);
827
if(iRet != RS_RET_OK) {
828
errmsg.LogError(NO_ERRCODE, "error %d compare operation property - ignoring selector", iRet);
829
rsParsDestruct(pPars);
833
/* we now first check if the condition is to be negated. To do so, we first
834
* must make sure we have at least one char in the param and then check the
836
* rgerhards, 2005-09-26
838
if(rsCStrLen(pCSCompOp) > 0) {
839
if(*rsCStrGetBufBeg(pCSCompOp) == '!') {
840
f->f_filterData.prop.isNegated = 1;
841
iOffset = 1; /* ignore '!' */
843
f->f_filterData.prop.isNegated = 0;
847
f->f_filterData.prop.isNegated = 0;
851
if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "contains", 8)) {
852
f->f_filterData.prop.operation = FIOP_CONTAINS;
853
} else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "isequal", 7)) {
854
f->f_filterData.prop.operation = FIOP_ISEQUAL;
855
} else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "startswith", 10)) {
856
f->f_filterData.prop.operation = FIOP_STARTSWITH;
857
} else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "regex", 5)) {
858
f->f_filterData.prop.operation = FIOP_REGEX;
860
errmsg.LogError(NO_ERRCODE, "error: invalid compare operation '%s' - ignoring selector",
861
(char*) rsCStrGetSzStrNoNULL(pCSCompOp));
863
rsCStrDestruct(&pCSCompOp); /* no longer needed */
865
/* read compare value */
866
iRet = parsQuotedCStr(pPars, &f->f_filterData.prop.pCSCompValue);
867
if(iRet != RS_RET_OK) {
868
errmsg.LogError(NO_ERRCODE, "error %d compare value property - ignoring selector", iRet);
869
rsParsDestruct(pPars);
873
/* skip to action part */
874
if((iRet = parsSkipWhitespace(pPars)) != RS_RET_OK) {
875
errmsg.LogError(NO_ERRCODE, "error %d skipping to action part - ignoring selector", iRet);
876
rsParsDestruct(pPars);
881
*pline = *pline + rsParsGetParsePointer(pPars) + 1;
882
/* we are adding one for the skipped initial ":" */
884
return rsParsDestruct(pPars);
889
* Helper to cfline(). This function interprets a BSD host selector line
890
* from the config file ("+/-hostname"). It stores it for further reference.
891
* rgerhards 2005-10-19
893
static rsRetVal cflineProcessHostSelector(uchar **pline)
897
ASSERT(pline != NULL);
898
ASSERT(*pline != NULL);
899
ASSERT(**pline == '-' || **pline == '+');
901
dbgprintf(" - host selector line\n");
903
/* check include/exclude setting */
905
eDfltHostnameCmpMode = HN_COMP_MATCH;
906
} else { /* we do not check for '-', it must be, else we wouldn't be here */
907
eDfltHostnameCmpMode = HN_COMP_NOMATCH;
909
(*pline)++; /* eat + or - */
911
/* the below is somewhat of a quick hack, but it is efficient (this is
912
* why it is in here. "+*" resets the tag selector with BSD syslog. We mimic
913
* this, too. As it is easy to check that condition, we do not fire up a
914
* parser process, just make sure we do not address beyond our space.
915
* Order of conditions in the if-statement is vital! rgerhards 2005-10-18
917
if(**pline != '\0' && **pline == '*' && *(*pline+1) == '\0') {
918
dbgprintf("resetting BSD-like hostname filter\n");
919
eDfltHostnameCmpMode = HN_NO_COMP;
920
if(pDfltHostnameCmp != NULL) {
921
if((iRet = rsCStrSetSzStr(pDfltHostnameCmp, NULL)) != RS_RET_OK)
925
dbgprintf("setting BSD-like hostname filter to '%s'\n", *pline);
926
if(pDfltHostnameCmp == NULL) {
927
/* create string for parser */
928
if((iRet = rsCStrConstructFromszStr(&pDfltHostnameCmp, *pline)) != RS_RET_OK)
930
} else { /* string objects exists, just update... */
931
if((iRet = rsCStrSetSzStr(pDfltHostnameCmp, *pline)) != RS_RET_OK)
940
* Helper to cfline(). This function interprets a BSD tag selector line
941
* from the config file ("!tagname"). It stores it for further reference.
942
* rgerhards 2005-10-18
944
static rsRetVal cflineProcessTagSelector(uchar **pline)
948
ASSERT(pline != NULL);
949
ASSERT(*pline != NULL);
950
ASSERT(**pline == '!');
952
dbgprintf(" - programname selector line\n");
954
(*pline)++; /* eat '!' */
956
/* the below is somewhat of a quick hack, but it is efficient (this is
957
* why it is in here. "!*" resets the tag selector with BSD syslog. We mimic
958
* this, too. As it is easy to check that condition, we do not fire up a
959
* parser process, just make sure we do not address beyond our space.
960
* Order of conditions in the if-statement is vital! rgerhards 2005-10-18
962
if(**pline != '\0' && **pline == '*' && *(*pline+1) == '\0') {
963
dbgprintf("resetting programname filter\n");
964
if(pDfltProgNameCmp != NULL) {
965
if((iRet = rsCStrSetSzStr(pDfltProgNameCmp, NULL)) != RS_RET_OK)
969
dbgprintf("setting programname filter to '%s'\n", *pline);
970
if(pDfltProgNameCmp == NULL) {
971
/* create string for parser */
972
if((iRet = rsCStrConstructFromszStr(&pDfltProgNameCmp, *pline)) != RS_RET_OK)
974
} else { /* string objects exists, just update... */
975
if((iRet = rsCStrSetSzStr(pDfltProgNameCmp, *pline)) != RS_RET_OK)
983
/* read the filter part of a configuration line and store the filter
984
* in the supplied selector_t
985
* rgerhards, 2007-08-01
987
static rsRetVal cflineDoFilter(uchar **pp, selector_t *f)
994
/* check which filter we need to pull... */
997
CHKiRet(cflineProcessPropFilter(pp, f));
999
case 'i': /* "if" filter? */
1000
if(*(*pp+1) && (*(*pp+1) == 'f') && isspace(*(*pp+2))) {
1001
CHKiRet(cflineProcessIfFilter(pp, f));
1006
CHKiRet(cflineProcessTradPRIFilter(pp, f));
1010
/* we now check if there are some global (BSD-style) filter conditions
1011
* and, if so, we copy them over. rgerhards, 2005-10-18
1013
if(pDfltProgNameCmp != NULL) {
1014
CHKiRet(rsCStrConstructFromCStr(&(f->pCSProgNameComp), pDfltProgNameCmp));
1017
if(eDfltHostnameCmpMode != HN_NO_COMP) {
1018
f->eHostnameCmpMode = eDfltHostnameCmpMode;
1019
CHKiRet(rsCStrConstructFromCStr(&(f->pCSHostnameComp), pDfltHostnameCmp));
1027
/* process the action part of a selector line
1028
* rgerhards, 2007-08-01
1030
static rsRetVal cflineDoAction(uchar **p, action_t **ppAction)
1034
omodStringRequest_t *pOMSR;
1039
ASSERT(ppAction != NULL);
1041
/* loop through all modules and see if one picks up the line */
1042
pMod = module.GetNxtType(NULL, eMOD_OUT);
1043
while(pMod != NULL) {
1045
iRet = pMod->mod.om.parseSelectorAct(p, &pModData, &pOMSR);
1046
dbgprintf("tried selector action for %s: %d\n", module.GetName(pMod), iRet);
1047
if(iRet == RS_RET_OK || iRet == RS_RET_SUSPENDED) {
1048
if((iRet = addAction(&pAction, pMod, pModData, pOMSR, (iRet == RS_RET_SUSPENDED)? 1 : 0)) == RS_RET_OK) {
1049
/* now check if the module is compatible with select features */
1050
if(pMod->isCompatibleWithFeature(sFEATURERepeatedMsgReduction) == RS_RET_OK)
1051
pAction->f_ReduceRepeated = bReduceRepeatMsgs;
1053
dbgprintf("module is incompatible with RepeatedMsgReduction - turned off\n");
1054
pAction->f_ReduceRepeated = 0;
1056
pAction->bEnabled = 1; /* action is enabled */
1060
else if(iRet != RS_RET_CONFLINE_UNPROCESSED) {
1061
/* In this case, the module would have handled the config
1062
* line, but some error occured while doing so. This error should
1063
* already by reported by the module. We do not try any other
1064
* modules on this line, because we found the right one.
1065
* rgerhards, 2007-07-24
1067
dbgprintf("error %d parsing config line\n", (int) iRet);
1070
pMod = module.GetNxtType(pMod, eMOD_OUT);
1073
*ppAction = pAction;
1078
/* Process a configuration file line in traditional "filter selector" format
1079
* or one that builds upon this format.
1081
static rsRetVal cflineClassic(uchar *p, selector_t **pfCurr)
1087
ASSERT(pfCurr != NULL);
1091
/* lines starting with '&' have no new filters and just add
1092
* new actions to the currently processed selector.
1096
skipWhiteSpace(&p); /* on to command */
1098
/* we are finished with the current selector (on previous line).
1099
* So we now need to check
1100
* if it has any actions associated and, if so, link it to the linked
1101
* list. If it has nothing associated with it, we can simply discard
1102
* it. In any case, we create a fresh selector for our new filter.
1103
* We have one special case during initialization: then, the current
1104
* selector is NULL, which means we do not need to care about it at
1105
* all. -- rgerhards, 2007-08-01
1107
CHKiRet(selectorAddList(fCurr));
1108
CHKiRet(selectorConstruct(&fCurr)); /* create "fresh" selector */
1109
CHKiRet(cflineDoFilter(&p, fCurr)); /* pull filters */
1112
CHKiRet(cflineDoAction(&p, &pAction));
1113
CHKiRet(llAppend(&fCurr->llActList, NULL, (void*) pAction));
1121
/* process a configuration line
1122
* I re-did this functon because it was desperately time to do so
1123
* rgerhards, 2007-08-01
1126
cfline(uchar *line, selector_t **pfCurr)
1130
ASSERT(line != NULL);
1132
dbgprintf("cfline: '%s'\n", line);
1134
/* check type of line and call respective processing */
1137
iRet = cflineProcessTagSelector(&line);
1141
iRet = cflineProcessHostSelector(&line);
1144
++line; /* eat '$' */
1145
iRet = cfsysline(line);
1148
iRet = cflineClassic(line, pfCurr);
1156
/* queryInterface function
1157
* rgerhards, 2008-02-29
1159
BEGINobjQueryInterface(conf)
1160
CODESTARTobjQueryInterface(conf)
1161
if(pIf->ifVersion != confCURR_IF_VERSION) { /* check for current version, increment on each change */
1162
ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
1165
/* ok, we have the right interface, so let's fill it
1166
* Please note that we may also do some backwards-compatibility
1167
* work here (if we can support an older interface version - that,
1168
* of course, also affects the "if" above).
1170
pIf->doNameLine = doNameLine;
1171
pIf->cfsysline = cfsysline;
1172
pIf->doModLoad = doModLoad;
1173
pIf->doIncludeLine = doIncludeLine;
1174
pIf->cfline = cfline;
1175
pIf->processConfFile = processConfFile;
1178
ENDobjQueryInterface(conf)
1182
* rgerhards, 2008-03-11
1184
BEGINObjClassExit(conf, OBJ_IS_CORE_MODULE) /* CHANGE class also in END MACRO! */
1185
CODESTARTObjClassExit(conf)
1186
/* release objects we no longer need */
1187
objRelease(expr, CORE_COMPONENT);
1188
objRelease(ctok, CORE_COMPONENT);
1189
objRelease(ctok_token, CORE_COMPONENT);
1190
objRelease(module, CORE_COMPONENT);
1191
objRelease(errmsg, CORE_COMPONENT);
1192
objRelease(net, LM_NET_FILENAME);
1193
ENDObjClassExit(conf)
1196
/* Initialize our class. Must be called as the very first method
1197
* before anything else is called inside this class.
1198
* rgerhards, 2008-02-29
1200
BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANGE class also in END MACRO! */
1201
/* request objects we use */
1202
CHKiRet(objUse(expr, CORE_COMPONENT));
1203
CHKiRet(objUse(ctok, CORE_COMPONENT));
1204
CHKiRet(objUse(ctok_token, CORE_COMPONENT));
1205
CHKiRet(objUse(module, CORE_COMPONENT));
1206
CHKiRet(objUse(errmsg, CORE_COMPONENT));
1207
CHKiRet(objUse(net, LM_NET_FILENAME)); /* TODO: make this dependcy go away! */
1208
ENDObjClassInit(conf)