diff options
-rw-r--r-- | runtime/conf.c | 31 | ||||
-rw-r--r-- | runtime/conf.h | 13 | ||||
-rw-r--r-- | runtime/rsconf.c | 70 | ||||
-rw-r--r-- | tools/syslogd.c | 2 |
4 files changed, 82 insertions, 34 deletions
diff --git a/runtime/conf.c b/runtime/conf.c index 6a2e57fa..5eb1aae2 100644 --- a/runtime/conf.c +++ b/runtime/conf.c @@ -354,7 +354,7 @@ finalize_it: * 2004-11-17 rgerhards */ rsRetVal -cfsysline(rsconf_t *conf, uchar *p) +cfsysline(uchar *p) { DEFiRet; uchar szCmd[64]; @@ -602,7 +602,7 @@ cflineParseFileName(uchar* p, uchar *pFileName, omodStringRequest_t *pOMSR, int * rgerhards 2005-09-15 */ /* GPLv3 - stems back to sysklogd */ -static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register rule_t *pRule) +rsRetVal cflineProcessTradPRIFilter(uchar **pline, register rule_t *pRule) { uchar *p; register uchar *q; @@ -619,7 +619,7 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register rule_t *pRule ASSERT(*pline != NULL); ISOBJ_TYPE_assert(pRule, rule); - dbgprintf(" - traditional PRI filter\n"); + dbgprintf(" - traditional PRI filter '%s'\n", *pline); errno = 0; /* keep strerror_r() stuff out of logerror messages */ pRule->f_filter_type = FILTER_PRI; @@ -632,7 +632,6 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register rule_t *pRule /* scan through the list of selectors */ for (p = *pline; *p && *p != '\t' && *p != ' ';) { - /* find the end of this facility name list */ for (q = p; *q && *q != '\t' && *q++ != '.'; ) continue; @@ -643,8 +642,10 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register rule_t *pRule *bp = '\0'; /* skip cruft */ - while (strchr(",;", *q)) - q++; + if(*q) { + while (strchr(",;", *q)) + q++; + } /* decode priority name */ if ( *buf == '!' ) { @@ -836,7 +837,7 @@ finalize_it: * of the action part. A pointer to that beginnig is passed back to the caller. * rgerhards 2005-09-15 */ -static rsRetVal cflineProcessPropFilter(uchar **pline, register rule_t *f) +rsRetVal cflineProcessPropFilter(uchar **pline, register rule_t *f) { rsParsObj *pPars; cstr_t *pCSCompOp; @@ -848,7 +849,7 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register rule_t *f) ASSERT(*pline != NULL); ASSERT(f != NULL); - dbgprintf(" - property-based filter\n"); + dbgprintf(" - property-based filter '%s'\n", *pline); errno = 0; /* keep strerror_r() stuff out of logerror messages */ f->f_filter_type = FILTER_PROP; @@ -908,7 +909,6 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register rule_t *f) iOffset = 0; } -dbgprintf("XXX: offset is %d, string '%s'\n", iOffset, rsCStrGetSzStrNoNULL(pCSCompOp)); if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "contains", 8)) { f->f_filterData.prop.operation = FIOP_CONTAINS; } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "isequal", 7)) { @@ -927,7 +927,6 @@ dbgprintf("XXX: offset is %d, string '%s'\n", iOffset, rsCStrGetSzStrNoNULL(pCSC } rsCStrDestruct(&pCSCompOp); /* no longer needed */ -dbgprintf("XXX: fiop is %u\n", (unsigned) f->f_filterData.prop.operation); if(f->f_filterData.prop.operation != FIOP_ISEMPTY) { /* read compare value */ iRet = parsQuotedCStr(pPars, &f->f_filterData.prop.pCSCompValue); @@ -958,7 +957,7 @@ dbgprintf("XXX: fiop is %u\n", (unsigned) f->f_filterData.prop.operation); * from the config file ("+/-hostname"). It stores it for further reference. * rgerhards 2005-10-19 */ -static rsRetVal cflineProcessHostSelector(rsconf_t *conf, uchar **pline) +rsRetVal cflineProcessHostSelector(uchar **pline) { DEFiRet; @@ -1008,7 +1007,7 @@ finalize_it: * from the config file ("!tagname"). It stores it for further reference. * rgerhards 2005-10-18 */ -static rsRetVal cflineProcessTagSelector(rsconf_t *conf, uchar **pline) +rsRetVal cflineProcessTagSelector(uchar **pline) { DEFiRet; @@ -1093,7 +1092,7 @@ finalize_it: /* process the action part of a selector line * rgerhards, 2007-08-01 */ -static rsRetVal cflineDoAction(rsconf_t *conf, uchar **p, action_t **ppAction) +rsRetVal cflineDoAction(rsconf_t *conf, uchar **p, action_t **ppAction) { modInfo_t *pMod; cfgmodules_etry_t *node; @@ -1214,15 +1213,15 @@ cfline(rsconf_t *conf, uchar *line, rule_t **pfCurr) /* check type of line and call respective processing */ switch(*line) { case '!': - iRet = cflineProcessTagSelector(conf, &line); + iRet = cflineProcessTagSelector(&line); break; case '+': case '-': - iRet = cflineProcessHostSelector(conf, &line); + iRet = cflineProcessHostSelector(&line); break; case '$': ++line; /* eat '$' */ - iRet = cfsysline(conf, line); + iRet = cfsysline(line); break; default: iRet = cflineClassic(conf, line, pfCurr); diff --git a/runtime/conf.h b/runtime/conf.h index 096af630..28ccdde1 100644 --- a/runtime/conf.h +++ b/runtime/conf.h @@ -21,6 +21,7 @@ */ #ifndef INCLUDED_CONF_H #define INCLUDED_CONF_H +#include "action.h" /* definitions used for doNameLine to differentiate between different command types * (with otherwise identical code). This is a left-over from the previous config @@ -34,7 +35,7 @@ extern int bConfStrictScoping; /* force strict scoping during config processing? /* interfaces */ BEGINinterface(conf) /* name must also be changed in ENDinterface macro! */ rsRetVal (*doNameLine)(uchar **pp, void* pVal); - rsRetVal (*cfsysline)(rsconf_t *conf, uchar *p); + rsRetVal (*cfsysline)(uchar *p); rsRetVal (*doModLoad)(uchar **pp, __attribute__((unused)) void* pVal); rsRetVal (*doIncludeLine)(rsconf_t *conf, uchar **pp, __attribute__((unused)) void* pVal); rsRetVal (*cfline)(rsconf_t *conf, uchar *line, rule_t **pfCurr); @@ -48,8 +49,10 @@ BEGINinterface(conf) /* name must also be changed in ENDinterface macro! */ */ /* version 5 -- 2011-04-19 rgerhards */ /* complete revamp, we now use the rsconf object */ + /* version 6 -- 2011-07-06 rgerhards */ + /* again a complete revamp, using flex/bison based parser now */ ENDinterface(conf) -#define confCURR_IF_VERSION 5 /* increment whenever you change the interface structure! */ +#define confCURR_IF_VERSION 6 /* increment whenever you change the interface structure! */ /* in Version 3, entry point "ReInitConf()" was removed, as we do not longer need * to support restart-type HUP -- rgerhards, 2009-07-15 */ @@ -63,5 +66,11 @@ PROTOTYPEObj(conf); rsRetVal cflineParseTemplateName(uchar** pp, omodStringRequest_t *pOMSR, int iEntry, int iTplOpts, uchar *dfltTplName); rsRetVal cflineParseFileName(uchar* p, uchar *pFileName, omodStringRequest_t *pOMSR, int iEntry, int iTplOpts, uchar *pszTpl); +/* more dirt to cover the new config interface (will go away...) */ +rsRetVal cflineProcessTagSelector(uchar **pline); +rsRetVal cflineProcessHostSelector(uchar **pline); +rsRetVal cflineProcessTradPRIFilter(uchar **pline, rule_t *pRule); +rsRetVal cflineProcessPropFilter(uchar **pline, rule_t *f); +rsRetVal cflineDoAction(rsconf_t *conf, uchar **p, action_t **ppAction); #endif /* #ifndef INCLUDED_CONF_H */ diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 446a9c8b..17332464 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -39,6 +39,7 @@ #include "rsyslog.h" #include "obj.h" #include "srUtils.h" +#include "rule.h" #include "ruleset.h" #include "modules.h" #include "conf.h" @@ -69,6 +70,7 @@ /* static data */ DEFobjStaticHelpers +DEFobjCurrIf(rule) DEFobjCurrIf(ruleset) DEFobjCurrIf(module) DEFobjCurrIf(conf) @@ -216,10 +218,12 @@ ENDobjDebugPrint(rsconf) rsRetVal -cnfDoActlst(struct cnfactlst *actlst) +cnfDoActlst(struct cnfactlst *actlst, rule_t *pRule) { struct cnfcfsyslinelst *cflst; + action_t *pAction; rsRetVal localRet; + uchar *str; DEFiRet; while(actlst != NULL) { @@ -227,8 +231,10 @@ cnfDoActlst(struct cnfactlst *actlst) if(actlst->actType == CNFACT_V2) { dbgprintf("V2 action type not yet handled\n"); } else { - dbgprintf("legacy action line not yet handled:%s\n", - actlst->data.legActLine); + dbgprintf("legacy action line:%s\n", actlst->data.legActLine); + str = (uchar*) actlst->data.legActLine; + iRet = cflineDoAction(loadConf, &str, &pAction); + iRet = llAppend(&(pRule)->llActList, NULL, (void*) pAction); } for( cflst = actlst->syslines ; cflst != NULL ; cflst = cflst->next) { @@ -268,44 +274,77 @@ void cnfDoObj(struct cnfobj *o) cnfobjDestruct(o); } -void cnfDoRule(struct cnfrule *rule) +void cnfDoRule(struct cnfrule *cnfrule) { + rule_t *pRule; + uchar *str; + DEFiRet; + dbgprintf("cnf:global:rule\n"); - cnfrulePrint(rule); + cnfrulePrint(cnfrule); - switch(rule->filttype) { + CHKiRet(rule.Construct(&pRule)); /* create "fresh" selector */ + CHKiRet(rule.SetAssRuleset(pRule, ruleset.GetCurrent(loadConf))); /* create "fresh" selector */ + CHKiRet(rule.ConstructFinalize(pRule)); /* create "fresh" selector */ + + switch(cnfrule->filttype) { case CNFFILT_NONE: break; case CNFFILT_PRI: + str = (uchar*) cnfrule->filt.s; + iRet = cflineProcessTradPRIFilter(&str, pRule); + break; case CNFFILT_PROP: - dbgprintf("%s\n", rule->filt.s); + dbgprintf("%s\n", cnfrule->filt.s); + str = (uchar*) cnfrule->filt.s; + iRet = cflineProcessPropFilter(&str, pRule); break; case CNFFILT_SCRIPT: - dbgprintf("\n"); - cnfexprPrint(rule->filt.expr, 0); + dbgprintf("TODO: script filter implementation missing\n"); + cnfexprPrint(cnfrule->filt.expr, 0); break; } - cnfDoActlst(rule->actlst); + /* we now check if there are some global (BSD-style) filter conditions + * and, if so, we copy them over. rgerhards, 2005-10-18 + */ +#if 0 // TODO: add LATER! + if(pDfltProgNameCmp != NULL) { + CHKiRet(rsCStrConstructFromCStr(&(f->pCSProgNameComp), pDfltProgNameCmp)); + } + + if(eDfltHostnameCmpMode != HN_NO_COMP) { + f->eHostnameCmpMode = eDfltHostnameCmpMode; + CHKiRet(rsCStrConstructFromCStr(&(f->pCSHostnameComp), pDfltHostnameCmp)); + } +#endif + + cnfDoActlst(cnfrule->actlst, pRule); + + CHKiRet(ruleset.AddRule(loadConf, rule.GetAssRuleset(pRule), &pRule)); + +finalize_it: + //TODO: do something with error states + ; } void cnfDoCfsysline(char *ln) { dbgprintf("cnf:global:cfsysline: %s\n", ln); /* the legacy system needs the "$" stripped */ - conf.cfsysline(loadConf, (uchar*) ln+1); + conf.cfsysline((uchar*) ln+1); dbgprintf("cnf:cfsysline call done\n"); } void cnfDoBSDTag(char *ln) { dbgprintf("cnf:global:BSD tag: %s\n", ln); - cflineProcessTagSelector(conf, &line); + cflineProcessTagSelector((uchar**)&ln); } void cnfDoBSDHost(char *ln) { dbgprintf("cnf:global:BSD host: %s\n", ln); - cflineProcessHostSelector(conf, &line); + cflineProcessHostSelector((uchar**)&ln); } /*------------------------------ end interface to flex/bison parser ------------------------------*/ @@ -1108,8 +1147,7 @@ ourConf = loadConf; // TODO: remove, once ourConf is gone! dbgprintf("ZZZZZ: cnfSetLexFile returns %d, calling yyparse()\n", r); r = yyparse(); dbgprintf("ZZZZZ: yyparse returns %d\n", r); - exit(1); - localRet = conf.processConfFile(loadConf, confFile); + //localRet = conf.processConfFile(loadConf, confFile); CHKiRet(conf.GetNbrActActions(loadConf, &iNbrActions)); if(localRet != RS_RET_OK && localRet != RS_RET_NONFATAL_CONFIG_ERR) { @@ -1208,6 +1246,7 @@ ENDobjQueryInterface(rsconf) BEGINObjClassInit(rsconf, 1, OBJ_IS_CORE_MODULE) /* class, version */ /* request objects we use */ CHKiRet(objUse(ruleset, CORE_COMPONENT)); + CHKiRet(objUse(rule, CORE_COMPONENT)); CHKiRet(objUse(module, CORE_COMPONENT)); CHKiRet(objUse(conf, CORE_COMPONENT)); CHKiRet(objUse(errmsg, CORE_COMPONENT)); @@ -1223,6 +1262,7 @@ ENDObjClassInit(rsconf) /* De-initialize the rsconf class. */ BEGINObjClassExit(rsconf, OBJ_IS_CORE_MODULE) /* class, version */ + objRelease(rule, CORE_COMPONENT); objRelease(ruleset, CORE_COMPONENT); objRelease(module, CORE_COMPONENT); objRelease(conf, CORE_COMPONENT); diff --git a/tools/syslogd.c b/tools/syslogd.c index 6dbd4be5..79bf0c8a 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -802,7 +802,7 @@ void legacyOptsHook(void) errno = 0; errmsg.LogError(0, NO_ERRCODE, "Warning: backward compatibility layer added to following " "directive to rsyslog.conf: %s", pThis->line); - conf.cfsysline(ourConf, pThis->line); + conf.cfsysline(pThis->line); } pThis = pThis->next; } |