diff options
-rw-r--r-- | cfsysline.c | 80 | ||||
-rw-r--r-- | cfsysline.h | 1 | ||||
-rw-r--r-- | linkedlist.c | 2 | ||||
-rw-r--r-- | omfile.c | 4 | ||||
-rw-r--r-- | syslogd.c | 30 |
5 files changed, 102 insertions, 15 deletions
diff --git a/cfsysline.c b/cfsysline.c index 1100cf2b..54fc20df 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -399,11 +399,43 @@ rsRetVal cslchSetEntry(cslCmdHdlr_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pH */ rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine) { + DEFiRet; + rsRetVal (*pHdlr)() = NULL; assert(pThis != NULL); assert(ppConfLine != NULL); - // TODO: implement + switch(pThis->eType) { + case eCmdHdlrCustomHandler: + pHdlr = doCustomHdlr; + break; + case eCmdHdlrUID: + pHdlr = doGetUID; + break; + case eCmdHdlrGID: + pHdlr = doGetGID; + break; + case eCmdHdlrBinary: + pHdlr = doBinaryOptionLine; + break; + case eCmdHdlrFileCreateMode: + pHdlr = doFileCreateMode; + break; + case eCmdHdlrInt: + pHdlr = doGetInt; + break; + case eCmdHdlrFileGetChar: + pHdlr = doGetChar; + break; + default: + iRet = RS_RET_NOT_IMPLEMENTED; + goto finalize_it; + } + + /* we got a pointer to the handler, so let's call it */ + assert(pHdlr != NULL); + CHKiRet(pHdlr(ppConfLine, pThis->cslCmdHdlr, pThis->pData)); +finalize_it: return RS_RET_OK; } @@ -447,7 +479,7 @@ rsRetVal cslcConstruct(cslCmd_t **ppThis) ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); } - CHKiRet(llInit(&pThis->llCmdHdlrs, cslchDestruct, NULL, strcmp)); + CHKiRet(llInit(&pThis->llCmdHdlrs, cslchDestruct, NULL, NULL)); finalize_it: *ppThis = pThis; @@ -485,7 +517,7 @@ rsRetVal cfsyslineInit(void) { DEFiRet; - CHKiRet(llInit(&llCmdList, cslcDestruct, cslcKeyDestruct, strcmp)); + CHKiRet(llInit(&llCmdList, cslcDestruct, cslcKeyDestruct, strcasecmp)); finalize_it: return iRet; @@ -525,6 +557,48 @@ finalize_it: } +/* process a cfsysline command (based on handler structure) + * param "p" is a pointer to the command line after the command. Should be + * updated. + */ +rsRetVal processCfSysLineCommand(uchar *pCmdName, uchar **p) +{ + DEFiRet; + cslCmd_t *pCmd; + cslCmdHdlr_t *pCmdHdlr; + linkedListCookie_t llCookieCmdHdlr; + uchar *pHdlrP; /* the handler's private p (else we could only call one handler) */ + int bWasOnceOK; /* was the result of an handler at least once RS_RET_OK? */ + uchar *pOKp = NULL; /* returned conf line pointer when it was OK */ + + CHKiRet(llFind(&llCmdList, (void *) pCmdName, (void**) &pCmd)); + llCookieCmdHdlr = NULL; + bWasOnceOK = 0; + while((iRet = llGetNextElt(&pCmd->llCmdHdlrs, &llCookieCmdHdlr, (void**)&pCmdHdlr)) == RS_RET_OK) { + /* for the time being, we ignore errors during handlers. The + * reason is that handlers are independent. An error in one + * handler does not necessarily mean that another one will + * fail, too. Later, we might add a config variable to control + * this behaviour (but I am not sure if that is rally + * necessary). -- rgerhards, 2007-07-31 + */ + pHdlrP = *p; + if(cslchCallHdlr(pCmdHdlr, &pHdlrP) == RS_RET_OK) { + bWasOnceOK = 1; + pOKp = pHdlrP; + } + } + + if(bWasOnceOK == 1) { + *p = pOKp; + iRet = RS_RET_OK; + } + +finalize_it: + return iRet; +} + + /* debug print the command handler structure */ void dbgPrintCfSysLineHandlers(void) diff --git a/cfsysline.h b/cfsysline.h index d319ed32..76ff310a 100644 --- a/cfsysline.h +++ b/cfsysline.h @@ -66,6 +66,7 @@ rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine); rsRetVal cslcConstruct(cslCmd_t **ppThis); rsRetVal regCfSysLineHdlr(uchar *pCmdName, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData); rsRetVal cfsyslineInit(void); +rsRetVal processCfSysLineCommand(uchar *pCmd, uchar **p); void dbgPrintCfSysLineHandlers(void); /* the next ones go away later */ diff --git a/linkedlist.c b/linkedlist.c index 0a798efb..c1296e95 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -160,7 +160,6 @@ finalize_it: rsRetVal llAppend(linkedList_t *pThis, void *pKey, void *pData) { llElt_t *pElt; -llElt_t *pEltPrev = pThis->pLast; DEFiRet; CHKiRet(llEltConstruct(&pElt, pKey, pData)); @@ -172,7 +171,6 @@ llElt_t *pEltPrev = pThis->pLast; pThis->pLast->pNext = pElt; } pThis->pLast = pElt; -printf("llAppend pThis 0x%x, pLastPrev 0x%x, pLast 0x%x, pElt 0x%x\n", pThis, pEltPrev, pThis->pLast, pElt); finalize_it: return iRet; @@ -753,6 +753,10 @@ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirgroup", eCmdHdlrGID, NULL, &dirGID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"fileowner", eCmdHdlrUID, NULL, &fileUID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"filegroup", eCmdHdlrGID, NULL, &fileGID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"dircreatemode", eCmdHdlrFileCreateMode, NULL, &fDirCreateMode)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"filecreatemode", eCmdHdlrFileCreateMode, NULL, &fCreateMode)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"createdirs", eCmdHdlrBinary, NULL, &bCreateDirs)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"failonchownfailure", eCmdHdlrBinary, NULL, &bFailOnChown)); ENDmodInit /* @@ -3566,12 +3566,13 @@ rsRetVal cfsysline(uchar *p) CHKiRet(doCustomHdlr(&p, doNameLine, (void*) DIR_OUTCHANNEL)); } else if(!strcasecmp((char*) szCmd, "allowedsender")) { CHKiRet(doCustomHdlr(&p, doNameLine, (void*) DIR_ALLOWEDSENDER)); + } else if(!strcasecmp((char*) szCmd, "umask")) { + CHKiRet(doFileCreateMode(&p, (void*) setUmask, NULL)); +#if 0 } else if(!strcasecmp((char*) szCmd, "dircreatemode")) { CHKiRet(doFileCreateMode(&p, NULL, &fDirCreateMode)); } else if(!strcasecmp((char*) szCmd, "filecreatemode")) { CHKiRet(doFileCreateMode(&p, NULL, &fCreateMode)); - } else if(!strcasecmp((char*) szCmd, "umask")) { - CHKiRet(doFileCreateMode(&p, (void*) setUmask, NULL)); } else if(!strcasecmp((char*) szCmd, "dirowner")) { CHKiRet(doGetUID(&p, NULL, &dirUID)); } else if(!strcasecmp((char*) szCmd, "dirgroup")) { @@ -3582,6 +3583,7 @@ rsRetVal cfsysline(uchar *p) CHKiRet(doGetGID(&p, NULL, &fileGID)); } else if(!strcasecmp((char*) szCmd, "dynafilecachesize")) { CHKiRet(doGetInt(&p, (void*) setDynaFileCacheSize, NULL)); +#endif } else if(!strcasecmp((char*) szCmd, "repeatedmsgreduction")) { CHKiRet(doBinaryOptionLine(&p, NULL, &bReduceRepeatMsgs)); } else if(!strcasecmp((char*) szCmd, "controlcharacterescapeprefix")) { @@ -3590,12 +3592,14 @@ rsRetVal cfsysline(uchar *p) CHKiRet(doBinaryOptionLine(&p, NULL, &bEscapeCCOnRcv)); } else if(!strcasecmp((char*) szCmd, "dropmsgswithmaliciousdnsptrrecords")) { CHKiRet(doBinaryOptionLine(&p, NULL, &bDropMalPTRMsgs)); +#if 0 } else if(!strcasecmp((char*) szCmd, "createdirs")) { CHKiRet(doBinaryOptionLine(&p, NULL, &bCreateDirs)); - } else if(!strcasecmp((char*) szCmd, "debugprinttemplatelist")) { - CHKiRet(doBinaryOptionLine(&p, NULL, &bDebugPrintTemplateList)); } else if(!strcasecmp((char*) szCmd, "failonchownfailure")) { CHKiRet(doBinaryOptionLine(&p, NULL, &bFailOnChown)); +#endif + } else if(!strcasecmp((char*) szCmd, "debugprinttemplatelist")) { + CHKiRet(doBinaryOptionLine(&p, NULL, &bDebugPrintTemplateList)); } else if(!strcasecmp((char*) szCmd, "droptrailinglfonreception")) { CHKiRet(doBinaryOptionLine(&p, NULL, &bDropTrailingLF)); } else if(!strcasecmp((char*) szCmd, "resetconfigvariables")) { @@ -3607,12 +3611,18 @@ rsRetVal cfsysline(uchar *p) CHKiRet(doCustomHdlr(&p , resetConfigVariables, NULL)); } else if(!strcasecmp((char*) szCmd, "modload")) { CHKiRet(doCustomHdlr(&p, doModLoad, NULL)); - } else { /* invalid command! */ - char err[100]; - snprintf(err, sizeof(err)/sizeof(char), - "Invalid command in $-configline: '%s' - line ignored\n", szCmd); - logerror(err); - ABORT_FINALIZE(RS_RET_INVALID_CMD); + } else { + /* we now try and see if we can find the command in the registered + * list of cfsysline handlers. -- rgerhards, 2007-07-31 + */ + if((iRet = processCfSysLineCommand(szCmd, &p)) != RS_RET_OK) { + /* invalid command! */ + char err[256]; + snprintf(err, sizeof(err)/sizeof(char), + "Invalid command in $-configline: '%s' (error %d) - line ignored\n", szCmd, iRet); + logerror(err); + ABORT_FINALIZE(RS_RET_INVALID_CMD); + } } /* now check if we have some extra characters left on the line - that |