diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2007-07-31 08:40:32 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2007-07-31 08:40:32 +0000 |
commit | c0b2b6b1bf3735bb0570523c9529bb1f93e96b86 (patch) | |
tree | 10c28775f661259666da1f7b76cdbe74dd5b7000 | |
parent | 9c20d0b4b4d3b85128d1754af3324866b135a412 (diff) | |
download | rsyslog-c0b2b6b1bf3735bb0570523c9529bb1f93e96b86.tar.gz rsyslog-c0b2b6b1bf3735bb0570523c9529bb1f93e96b86.tar.xz rsyslog-c0b2b6b1bf3735bb0570523c9529bb1f93e96b86.zip |
- added macro to abort a function and go to finalizer
- added output of config file line number when a parsing error occured
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | cfsysline.c | 17 | ||||
-rw-r--r-- | rsyslog.h | 6 | ||||
-rw-r--r-- | syslogd.c | 57 |
4 files changed, 46 insertions, 35 deletions
@@ -12,6 +12,7 @@ Version 1.17.6 (rgerhards), 2007-07-3? The initial fix and idea was developed by mildew, I fine-tuned it a bit. Thanks a lot for the fix, I'd probably had pulled out my hair to find the bug... +- added output of config file line number when a parsing error occured --------------------------------------------------------------------------- Version 1.17.5 (rgerhards), 2007-07-30 - continued to work on output module modularization diff --git a/cfsysline.c b/cfsysline.c index 5119df02..1a045321 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -98,8 +98,7 @@ rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal) if(!isdigit((int) *p)) { errno = 0; logerror("invalid number"); - iRet = RS_RET_INVALID_INT; - goto finalize_it; + ABORT_FINALIZE(RS_RET_INVALID_INT); } /* pull value */ @@ -158,8 +157,7 @@ rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void * "value must be octal (e.g 0644)."); errno = 0; logerror((char*) errMsg); - iRet = RS_RET_INVALID_VALUE; - goto finalize_it; + ABORT_FINALIZE(RS_RET_INVALID_VALUE); } /* we reach this code only if the octal number is ok - so we can now @@ -234,8 +232,7 @@ rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal) if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { logerror("could not extract group name"); - iRet = RS_RET_NOT_FOUND; - goto finalize_it; + ABORT_FINALIZE(RS_RET_NOT_FOUND); } getgrnam_r((char*)szName, &gBuf, stringBuf, sizeof(stringBuf), &pgBuf); @@ -277,8 +274,7 @@ rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal) if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { logerror("could not extract user name"); - iRet = RS_RET_NOT_FOUND; - goto finalize_it; + ABORT_FINALIZE(RS_RET_NOT_FOUND); } getpwnam_r((char*)szName, &pwBuf, stringBuf, sizeof(stringBuf), &ppwBuf); @@ -357,11 +353,10 @@ rsRetVal cslchConstruct(cslCmdHdlr_t **ppThis) assert(ppThis != NULL); if((pThis = calloc(1, sizeof(cslCmdHdlr_t))) == NULL) { - iRet = RS_RET_OUT_OF_MEMORY; - goto abort_it; + ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); } -abort_it: +finalize_it: *ppThis = pThis; return iRet; } @@ -61,7 +61,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_RQD_TPLOPT_MISSING = -2008,/**< a required template option is missing */ RS_RET_INVALID_VALUE = -2009,/**< some value is invalid (e.g. user-supplied data) */ RS_RET_INVALID_INT = -2010,/**< invalid integer */ - RS_RET_VAL_OUT_OF_RANGE = -2011, /**< value out of range */ + RS_RET_INVALID_CMD = -2011,/**< invalid command */ + RS_RET_VAL_OUT_OF_RANGE = -2012, /**< value out of range */ RS_RET_OK = 0 /**< operation successful */ }; typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */ @@ -72,6 +73,9 @@ typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */ */ #define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it #define DEFiRet rsRetVal iRet = RS_RET_OK +#define ABORT_FINALIZE(errCode) \ + iRet = errCode;\ + goto finalize_it; /** Object ID. These are for internal checking. Each * object is assigned a specific ID. This is contained in @@ -3499,8 +3499,9 @@ static void doModLoad(uchar **pp) * rgerhards 2005-06-21: previously only for templates, now * generalized. */ -static void doNameLine(uchar **pp, enum eDirective eDir) +static rsRetVal doNameLine(uchar **pp, enum eDirective eDir) { + DEFiRet; uchar *p; char szName[128]; @@ -3514,7 +3515,7 @@ static void doNameLine(uchar **pp, enum eDirective eDir) "Invalid $%s line: could not extract name - line ignored", directive_name_list[eDir]); logerror(errMsg); - return; + ABORT_FINALIZE(RS_RET_NOT_FOUND); } if(*p == ',') ++p; /* comma was eaten */ @@ -3546,7 +3547,9 @@ static void doNameLine(uchar **pp, enum eDirective eDir) } *pp = p; - return; + +finalize_it: + return iRet; } @@ -3566,8 +3569,9 @@ static rsRetVal setUmask(void __attribute__((unused)) *pVal, int iUmask) * extended configuration parameters. * 2004-11-17 rgerhards */ -void cfsysline(uchar *p) +rsRetVal cfsysline(uchar *p) { + DEFiRet; uchar szCmd[64]; uchar errMsg[128]; /* for dynamic error messages */ @@ -3576,7 +3580,7 @@ void cfsysline(uchar *p) dprintf("cfsysline --> %s\n", p); if(getSubString(&p, (char*) szCmd, sizeof(szCmd) / sizeof(uchar), ' ') != 0) { logerror("Invalid $-configline - could not extract command - line ignored\n"); - return; + ABORT_FINALIZE(RS_RET_NOT_FOUND); } /* check the command and carry out processing */ @@ -3587,37 +3591,37 @@ void cfsysline(uchar *p) } else if(!strcasecmp((char*) szCmd, "allowedsender")) { doNameLine(&p, DIR_ALLOWEDSENDER); } else if(!strcasecmp((char*) szCmd, "dircreatemode")) { - doFileCreateMode(&p, NULL, &fDirCreateMode); + CHKiRet(doFileCreateMode(&p, NULL, &fDirCreateMode)); } else if(!strcasecmp((char*) szCmd, "filecreatemode")) { - doFileCreateMode(&p, NULL, &fCreateMode); + CHKiRet(doFileCreateMode(&p, NULL, &fCreateMode)); } else if(!strcasecmp((char*) szCmd, "umask")) { - doFileCreateMode(&p, (void*) setUmask, NULL); + CHKiRet(doFileCreateMode(&p, (void*) setUmask, NULL)); } else if(!strcasecmp((char*) szCmd, "dirowner")) { - doGetUID(&p, NULL, &dirUID); + CHKiRet(doGetUID(&p, NULL, &dirUID)); } else if(!strcasecmp((char*) szCmd, "dirgroup")) { - doGetGID(&p, NULL, &dirGID); + CHKiRet(doGetGID(&p, NULL, &dirGID)); } else if(!strcasecmp((char*) szCmd, "fileowner")) { - doGetUID(&p, NULL, &fileUID); + CHKiRet(doGetUID(&p, NULL, &fileUID)); } else if(!strcasecmp((char*) szCmd, "filegroup")) { - doGetGID(&p, NULL, &fileGID); + CHKiRet(doGetGID(&p, NULL, &fileGID)); } else if(!strcasecmp((char*) szCmd, "dynafilecachesize")) { - doGetInt(&p, (void*) setDynaFileCacheSize, NULL); + CHKiRet(doGetInt(&p, (void*) setDynaFileCacheSize, NULL)); } else if(!strcasecmp((char*) szCmd, "repeatedmsgreduction")) { - doBinaryOptionLine(&p, NULL, &bReduceRepeatMsgs); + CHKiRet(doBinaryOptionLine(&p, NULL, &bReduceRepeatMsgs)); } else if(!strcasecmp((char*) szCmd, "controlcharacterescapeprefix")) { - doGetChar(&p, NULL, &cCCEscapeChar); + CHKiRet(doGetChar(&p, NULL, &cCCEscapeChar)); } else if(!strcasecmp((char*) szCmd, "escapecontrolcharactersonreceive")) { - doBinaryOptionLine(&p, NULL, &bEscapeCCOnRcv); + CHKiRet(doBinaryOptionLine(&p, NULL, &bEscapeCCOnRcv)); } else if(!strcasecmp((char*) szCmd, "dropmsgswithmaliciousdnsptrrecords")) { - doBinaryOptionLine(&p, NULL, &bDropMalPTRMsgs); + CHKiRet(doBinaryOptionLine(&p, NULL, &bDropMalPTRMsgs)); } else if(!strcasecmp((char*) szCmd, "createdirs")) { - doBinaryOptionLine(&p, NULL, &bCreateDirs); + CHKiRet(doBinaryOptionLine(&p, NULL, &bCreateDirs)); } else if(!strcasecmp((char*) szCmd, "debugprinttemplatelist")) { - doBinaryOptionLine(&p, NULL, &bDebugPrintTemplateList); + CHKiRet(doBinaryOptionLine(&p, NULL, &bDebugPrintTemplateList)); } else if(!strcasecmp((char*) szCmd, "failonchownfailure")) { - doBinaryOptionLine(&p, NULL, &bFailOnChown); + CHKiRet(doBinaryOptionLine(&p, NULL, &bFailOnChown)); } else if(!strcasecmp((char*) szCmd, "droptrailinglfonreception")) { - doBinaryOptionLine(&p, NULL, &bDropTrailingLF); + CHKiRet(doBinaryOptionLine(&p, NULL, &bDropTrailingLF)); } else if(!strcasecmp((char*) szCmd, "resetconfigvariables")) { resetConfigVariables(); } else if(!strcasecmp((char*) szCmd, "modload")) { @@ -3627,7 +3631,7 @@ void cfsysline(uchar *p) snprintf(err, sizeof(err)/sizeof(char), "Invalid command in $-configline: '%s' - line ignored\n", szCmd); logerror(err); - return; + ABORT_FINALIZE(RS_RET_INVALID_CMD); } /* now check if we have some extra characters left on the line - that @@ -3644,6 +3648,9 @@ void cfsysline(uchar *p) errno = 0; logerror((char*) errMsg); } + +finalize_it: + return iRet; } @@ -3802,6 +3809,7 @@ static void init() Initialized = 1; } else { /* we should consider moving this into a separate function, its lengthy... */ + int iLnNbr = 0; /* * Foreach line in the conf table, open that file. */ @@ -3811,6 +3819,7 @@ static void init() #else while (fgets(cline, sizeof(cline), cf) != NULL) { #endif + ++iLnNbr; /* drop LF - TODO: make it better, replace fgets(), but its clean as it is */ if(cline[strlen(cline)-1] == '\n') { cline[strlen(cline) -1] = '\0'; @@ -3824,7 +3833,9 @@ static void init() continue; if(*p == '$') { - cfsysline((uchar*) ++p); + if(cfsysline((uchar*) ++p) != RS_RET_OK) { + logerrorInt("error occured in config file line %d", iLnNbr); + } continue; } #if CONT_LINE |