summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cfsysline.c80
-rw-r--r--cfsysline.h5
-rw-r--r--linkedlist.c20
-rw-r--r--linkedlist.h3
-rw-r--r--omfile.c37
-rw-r--r--omfile.h1
-rw-r--r--rsyslog.h3
-rw-r--r--syslogd.c33
8 files changed, 141 insertions, 41 deletions
diff --git a/cfsysline.c b/cfsysline.c
index c28e8865..1100cf2b 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -428,7 +428,7 @@ static rsRetVal cslcDestruct(void *pData)
assert(pThis != NULL);
- llDestroy(pThis->pllCmdHdlrs);
+ llDestroy(&pThis->llCmdHdlrs);
free(pThis);
return RS_RET_OK;
@@ -447,7 +447,7 @@ rsRetVal cslcConstruct(cslCmd_t **ppThis)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
}
- CHKiRet(llInit(pThis->pllCmdHdlrs, cslchDestruct, NULL));
+ CHKiRet(llInit(&pThis->llCmdHdlrs, cslchDestruct, NULL, strcmp));
finalize_it:
*ppThis = pThis;
@@ -455,6 +455,29 @@ finalize_it:
}
+/* add a handler entry to a known command
+ */
+rsRetVal cslcAddHdlr(cslCmd_t *pThis, ecslCmdHdrlType eType, rsRetVal (*pHdlr)(), void *pData)
+{
+ DEFiRet;
+ cslCmdHdlr_t *pCmdHdlr = NULL;
+
+ assert(pThis != NULL);
+
+ CHKiRet(cslchConstruct(&pCmdHdlr));
+ CHKiRet(cslchSetEntry(pCmdHdlr, eType, pHdlr, pData));
+ CHKiRet(llAppend(&pThis->llCmdHdlrs, NULL, pCmdHdlr));
+
+finalize_it:
+ if(iRet != RS_RET_OK) {
+ if(pHdlr != NULL)
+ cslchDestruct(pCmdHdlr);
+ }
+
+ return iRet;
+}
+
+
/* function that initializes this module here. This is primarily a hook
* for syslogd.
*/
@@ -462,7 +485,7 @@ rsRetVal cfsyslineInit(void)
{
DEFiRet;
- CHKiRet(llInit(&llCmdList, cslcDestruct, cslcKeyDestruct));
+ CHKiRet(llInit(&llCmdList, cslcDestruct, cslcKeyDestruct, strcmp));
finalize_it:
return iRet;
@@ -477,10 +500,59 @@ rsRetVal regCfSysLineHdlr(uchar *pCmdName, ecslCmdHdrlType eType, rsRetVal (*pHd
DEFiRet;
iRet = llFind(&llCmdList, (void *) pCmdName, (void**) &pThis);
-dprintf("regCfSysLineHdlr returned %d\n", iRet);
+ if(iRet == RS_RET_NOT_FOUND) {
+ /* new command */
+ CHKiRet(cslcConstruct(&pThis));
+ CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData)) {
+ cslcDestruct(pThis);
+ goto finalize_it;
+ }
+ /* important: add to list, AFTER everything else is OK. Else
+ * we mess up things in the error case.
+ */
+ CHKiRet_Hdlr(llAppend(&llCmdList, pCmdName, (void*) pThis)) {
+ cslcDestruct(pThis);
+ goto finalize_it;
+ }
+ } else {
+ /* command already exists, are we allowed to chain? */
+ iRet = RS_RET_NOT_IMPLEMENTED; // TODO: implement it!
+ goto finalize_it;
+ }
+finalize_it:
return iRet;
}
+
+
+/* debug print the command handler structure
+ */
+void dbgPrintCfSysLineHandlers(void)
+{
+ DEFiRet;
+
+ cslCmd_t *pCmd;
+ cslCmdHdlr_t *pCmdHdlr;
+ linkedListCookie_t llCookieCmd;
+ linkedListCookie_t llCookieCmdHdlr;
+ uchar *pKey;
+
+ printf("\nSytem Line Configuration Commands:\n");
+ llCookieCmd = NULL;
+ while((iRet = llGetNextElt(&llCmdList, &llCookieCmd, (void**)&pCmd)) == RS_RET_OK) {
+ llGetKey(llCookieCmd, (void**) &pKey); /* TODO: using the cookie is NOT clean! */
+ printf("\tCommand '%s':\n", pKey);
+ llCookieCmdHdlr = NULL;
+ while((iRet = llGetNextElt(&pCmd->llCmdHdlrs, &llCookieCmdHdlr, (void**)&pCmdHdlr)) == RS_RET_OK) {
+ printf("\t\ttype : %d\n", pCmdHdlr->eType);
+ printf("\t\tpData: 0x%x\n", (unsigned) pCmdHdlr->pData);
+ printf("\t\tHdlr : 0x%x\n", (unsigned) pCmdHdlr->cslCmdHdlr);
+ }
+ }
+ printf("\n");
+
+}
+
/*
* vi:set ai:
*/
diff --git a/cfsysline.h b/cfsysline.h
index 953b6bb3..d319ed32 100644
--- a/cfsysline.h
+++ b/cfsysline.h
@@ -30,7 +30,7 @@ typedef enum cslCmdHdlrType {
eCmdHdlrInvalid = 0, /* invalid handler type - indicates a coding error */
eCmdHdlrCustomHandler, /* custom handler, just call handler function */
eCmdHdlrUID,
- eCmdHdlrGUID,
+ eCmdHdlrGID,
eCmdHdlrBinary,
eCmdHdlrFileCreateMode,
eCmdHdlrInt,
@@ -54,7 +54,7 @@ typedef struct cslCmdHdlr_s cslCmdHdlr_t;
* The short name is cslc (Configfile SysLine Command)
*/
struct cslCmd_s { /* config file sysline parse entry */
- linkedList_t *pllCmdHdlrs; /* linked list of command handlers */
+ linkedList_t llCmdHdlrs; /* linked list of command handlers */
};
typedef struct cslCmd_s cslCmd_t;
@@ -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);
+void dbgPrintCfSysLineHandlers(void);
/* the next ones go away later */
rsRetVal doBinaryOptionLine(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal);
diff --git a/linkedlist.c b/linkedlist.c
index a75652a5..0a798efb 100644
--- a/linkedlist.c
+++ b/linkedlist.c
@@ -42,14 +42,14 @@
/* Initialize an existing linkedList_t structure
* pKey destructor may be zero to take care of non-keyed lists.
*/
-rsRetVal llInit(linkedList_t *pThis, rsRetVal (*pEltDestructor)(void*), rsRetVal (*pKeyDestructor)(void*))
+rsRetVal llInit(linkedList_t *pThis, rsRetVal (*pEltDestructor)(void*), rsRetVal (*pKeyDestructor)(void*), int pCmpOp())
{
assert(pThis != NULL);
assert(pEltDestructor != NULL);
pThis->pEltDestruct = pEltDestructor;
pThis->pKeyDestruct = pKeyDestructor;
- pThis->cmpOp = NULL;
+ pThis->cmpOp = pCmpOp;
pThis->pKey = NULL;
pThis->iNumElts = 0;
pThis->pRoot = NULL;
@@ -110,7 +110,6 @@ rsRetVal llGetNextElt(linkedList_t *pThis, linkedListCookie_t *ppElt, void **ppU
if(pElt == NULL) {
iRet = RS_RET_END_OF_LINKEDLIST;
} else {
- pElt = pThis->pRoot;
*ppUsr = pElt->pData;
}
@@ -120,6 +119,19 @@ rsRetVal llGetNextElt(linkedList_t *pThis, linkedListCookie_t *ppElt, void **ppU
}
+/* return the key of an Elt
+ */
+rsRetVal llGetKey(llElt_t *pThis, void **ppData)
+{
+ assert(pThis != NULL);
+ assert(ppData != NULL);
+
+ *ppData = pThis->pKey;
+
+ return RS_RET_OK;
+}
+
+
/* construct a new llElt_t
*/
static rsRetVal llEltConstruct(llElt_t **ppThis, void *pKey, void *pData)
@@ -148,6 +160,7 @@ 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));
@@ -159,6 +172,7 @@ rsRetVal llAppend(linkedList_t *pThis, void *pKey, void *pData)
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;
diff --git a/linkedlist.h b/linkedlist.h
index cdfc2872..6060345f 100644
--- a/linkedlist.h
+++ b/linkedlist.h
@@ -52,10 +52,11 @@ typedef struct linkedList_s linkedList_t;
typedef llElt_t* linkedListCookie_t; /* this type avoids exposing internals and keeps us flexible */
/* prototypes */
-rsRetVal llInit(linkedList_t *pThis, rsRetVal (*pEltDestructor)(void*), rsRetVal (*pKeyDestructor)(void*));
+rsRetVal llInit(linkedList_t *pThis, rsRetVal (*pEltDestructor)(void*), rsRetVal (*pKeyDestructor)(void*), int pCmpOp());
rsRetVal llDestroy(linkedList_t *pThis);
rsRetVal llGetNextElt(linkedList_t *pThis, linkedListCookie_t *ppElt, void **ppUsr);
rsRetVal llAppend(linkedList_t *pThis, void *pKey, void *pData);
rsRetVal llFind(linkedList_t *pThis, void *pKey, void **ppData);
+rsRetVal llGetKey(llElt_t *pThis, void **ppData);
#endif /* #ifndef LINKEDLIST_H_INCLUDED */
diff --git a/omfile.c b/omfile.c
index a5b7d6b2..b81911d0 100644
--- a/omfile.c
+++ b/omfile.c
@@ -49,6 +49,7 @@
#include "template.h"
#include "outchannel.h"
#include "omfile.h"
+#include "cfsysline.h"
#include "module-template.h"
/* internal structures
@@ -119,6 +120,37 @@ CODESTARTdbgPrintInstInfo
ENDdbgPrintInstInfo
+/* set the dynaFile cache size. Does some limit checking.
+ * rgerhards, 2007-07-31
+ */
+rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal)
+{
+ DEFiRet;
+ uchar errMsg[128]; /* for dynamic error messages */
+
+ if(iNewVal < 1) {
+ snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
+ "DynaFileCacheSize must be greater 0 (%d given), changed to 1.", iNewVal);
+ errno = 0;
+ logerror((char*) errMsg);
+ iRet = RS_RET_VAL_OUT_OF_RANGE;
+ iNewVal = 1;
+ } else if(iNewVal > 10000) {
+ snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
+ "DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", iNewVal);
+ errno = 0;
+ logerror((char*) errMsg);
+ iRet = RS_RET_VAL_OUT_OF_RANGE;
+ iNewVal = 10000;
+ }
+
+ iDynaFileCacheSize = iNewVal;
+ dprintf("DynaFileCacheSize changed to %d.\n", iNewVal);
+
+ return iRet;
+}
+
+
/* Helper to cfline(). Parses a output channel name up until the first
* comma and then looks for the template specifier. Tries
* to find that template. Maps the output channel to the
@@ -716,6 +748,11 @@ BEGINmodInit(File)
CODESTARTmodInit
*ipIFVersProvided = 1; /* so far, we only support the initial definition */
CODEmodInit_QueryRegCFSLineHdlr
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"dynafilecachesize", eCmdHdlrInt, (void*) setDynaFileCacheSize, NULL));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirowner", eCmdHdlrUID, NULL, &dirUID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirgroup", eCmdHdlrGID, NULL, &dirGID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"fileowner", eCmdHdlrUID, NULL, &fileUID));
+ CHKiRet(omsdRegCFSLineHdlr((uchar *)"filegroup", eCmdHdlrGID, NULL, &fileGID));
ENDmodInit
/*
diff --git a/omfile.h b/omfile.h
index 2f02d9cc..5352704a 100644
--- a/omfile.h
+++ b/omfile.h
@@ -26,6 +26,7 @@
/* prototypes */
rsRetVal modInitFile(int iIFVersRequested __attribute__((unused)), int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)(), rsRetVal (*pHostQueryEtryPt)(uchar*, rsRetVal (**)()));
+rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal); // TODO: remove me after testing!
#endif /* #ifndef OMFILE_H_INCLUDED */
/*
diff --git a/rsyslog.h b/rsyslog.h
index 7d154112..b781383c 100644
--- a/rsyslog.h
+++ b/rsyslog.h
@@ -34,6 +34,7 @@
*/
enum rsRetVal_ /** return value. All methods return this if not specified otherwise */
{
+ RS_RET_NOT_IMPLEMENTED = -7, /**< implementation is missing (probably internal error or lazyness ;)) */
RS_RET_OUT_OF_MEMORY = -6, /**< memory allocation failed */
RS_RET_PROVIDED_BUFFER_TOO_SMALL = -50,/**< the caller provided a buffer, but the called function sees the size of this buffer is too small - operation not carried out */
RS_RET_TRUE = -1,
@@ -74,6 +75,8 @@ typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
* the function finalizer always "finalize_it".
*/
#define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it
+/* macro below is to be used if we need our own handling, eg for cleanup */
+#define CHKiRet_Hdlr(code) if((iRet = code) != RS_RET_OK)
#define DEFiRet rsRetVal iRet = RS_RET_OK
#define ABORT_FINALIZE(errCode) \
iRet = errCode;\
diff --git a/syslogd.c b/syslogd.c
index e4121327..04013f48 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -3431,37 +3431,6 @@ static rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
}
-/* set the dynaFile cache size. Does some limit checking.
- * rgerhards, 2007-07-31
- */
-static rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal)
-{
- DEFiRet;
- uchar errMsg[128]; /* for dynamic error messages */
-
- if(iNewVal < 1) {
- snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
- "DynaFileCacheSize must be greater 0 (%d given), changed to 1.", iNewVal);
- errno = 0;
- logerror((char*) errMsg);
- iRet = RS_RET_VAL_OUT_OF_RANGE;
- iNewVal = 1;
- } else if(iNewVal > 10000) {
- snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
- "DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", iNewVal);
- errno = 0;
- logerror((char*) errMsg);
- iRet = RS_RET_VAL_OUT_OF_RANGE;
- iNewVal = 10000;
- }
-
- iDynaFileCacheSize = iNewVal;
- dprintf("DynaFileCacheSize changed to %d.\n", iNewVal);
-
- return iRet;
-}
-
-
/* process a $ModLoad config line.
* As of now, it is a dummy, that will later evolve into the
* loader for plug-ins.
@@ -3771,6 +3740,8 @@ static void dbgPrintInitInfo(void)
modPrintList();
ochPrintList();
+ dbgPrintCfSysLineHandlers();
+
#ifdef SYSLOG_INET
/* now the allowedSender lists: */
PrintAllowedSenders(1); /* UDP */