summaryrefslogtreecommitdiff
path: root/plugins/imrelp/imrelp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/imrelp/imrelp.c')
-rw-r--r--plugins/imrelp/imrelp.c119
1 files changed, 71 insertions, 48 deletions
diff --git a/plugins/imrelp/imrelp.c b/plugins/imrelp/imrelp.c
index 0cdb211..6787f91 100644
--- a/plugins/imrelp/imrelp.c
+++ b/plugins/imrelp/imrelp.c
@@ -69,14 +69,20 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
/* Module static data */
/* config vars for legacy config system */
static relpEngine_t *pRelpEngine; /* our relp engine */
-static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this module */
-static struct configSettings_s {
+
+/* config settings */
+typedef struct configSettings_s {
uchar *pszBindRuleset; /* name of Ruleset to bind to */
-} cs;
+} configSettings_t;
+static configSettings_t cs;
struct instanceConf_s {
uchar *pszBindPort; /* port to bind to */
- sbool bKeepAlive; /* support keep-alive packets */
+ uchar *pszBindRuleset; /* name of ruleset to bind to */
+ uchar *pszInputName; /* value for inputname property */
+ prop_t *pInputName; /* InputName in property format for fast access */
+ ruleset_t *pBindRuleset; /* ruleset to bind listener to */
+ sbool bKeepAlive; /* support keep-alive packets */
sbool bEnableTLS;
sbool bEnableTLSZip;
int dhBits;
@@ -111,8 +117,7 @@ struct instanceConf_s {
struct modConfData_s {
rsconf_t *pConf; /* our overall config object */
instanceConf_t *root, *tail;
- uchar *pszBindRuleset; /* name of Ruleset to bind to */
- ruleset_t *pBindRuleset; /* due to librelp limitation, we need to bind all listerns to the same set */
+ uchar *pszBindRuleset; /* default name of Ruleset to bind to */
};
static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
@@ -131,6 +136,8 @@ static struct cnfparamblk modpblk =
/* input instance parameters */
static struct cnfparamdescr inppdescr[] = {
{ "port", eCmdHdlrString, CNFPARAM_REQUIRED },
+ { "name", eCmdHdlrString, 0 },
+ { "ruleset", eCmdHdlrString, 0 },
{ "keepalive", eCmdHdlrBinary, 0 },
{ "keepalive.probes", eCmdHdlrInt, 0 },
{ "keepalive.time", eCmdHdlrInt, 0 },
@@ -151,7 +158,8 @@ static struct cnfparamblk inppblk =
inppdescr
};
-
+#include "im-helper.h" /* must be included AFTER the type definitions! */
+static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config parameters permitted? */
/* ------------------------------ callbacks ------------------------------ */
@@ -198,15 +206,13 @@ onSyslogRcv(void *pUsr, uchar *pHostname, uchar *pIP, uchar *msg, size_t lenMsg)
DEFiRet;
CHKiRet(msgConstruct(&pMsg));
- MsgSetInputName(pMsg, pInputName);
+ MsgSetInputName(pMsg, inst->pInputName);
MsgSetRawMsg(pMsg, (char*)msg, lenMsg);
MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
- MsgSetRuleset(pMsg, runModConf->pBindRuleset);
+ MsgSetRuleset(pMsg, inst->pBindRuleset);
pMsg->msgFlags = PARSE_HOSTNAME | NEEDS_PARSING;
- /* TODO: optimize this, we can store it inside the session, requires
- * changes to librelp --> next librelp iteration?. rgerhards, 2012-10-29
- */
+ /* TODO: optimize this, we can store it inside the session */
MsgSetRcvFromStr(pMsg, pHostname, ustrlen(pHostname), &pProp);
CHKiRet(prop.Destruct(&pProp));
CHKiRet(MsgSetRcvFromIPStr(pMsg, pIP, ustrlen(pIP), &pProp));
@@ -234,7 +240,13 @@ createInstance(instanceConf_t **pinst)
inst->next = NULL;
inst->pszBindPort = NULL;
+ inst->pszBindRuleset = NULL;
+ inst->pszInputName = NULL;
+ inst->pBindRuleset = NULL;
inst->bKeepAlive = 0;
+ inst->iKeepAliveIntvl = 0;
+ inst->iKeepAliveProbes = 0;
+ inst->iKeepAliveTime = 0;
inst->bEnableTLS = 0;
inst->bEnableTLSZip = 0;
inst->dhBits = 0;
@@ -259,12 +271,13 @@ finalize_it:
}
-/* modified to work for module, not instance (as usual) */
+/* function to generate an error message if the ruleset cannot be found */
static inline void
-std_checkRuleset_genErrMsg(modConfData_t *modConf, __attribute__((unused)) instanceConf_t *inst)
+std_checkRuleset_genErrMsg(__attribute__((unused)) modConfData_t *modConf, instanceConf_t *inst)
{
- errmsg.LogError(0, NO_ERRCODE, "imrelp: ruleset '%s' not found - "
- "using default ruleset instead", modConf->pszBindRuleset);
+ errmsg.LogError(0, NO_ERRCODE, "imrelp[%s]: ruleset '%s' not found - "
+ "using default ruleset instead",
+ inst->pszBindPort, inst->pszBindRuleset);
}
@@ -283,9 +296,19 @@ static rsRetVal addInstance(void __attribute__((unused)) *pVal, uchar *pNewVal)
if(pNewVal == NULL || *pNewVal == '\0') {
errmsg.LogError(0, NO_ERRCODE, "imrelp: port number must be specified, listener ignored");
}
- inst->pszBindPort = pNewVal;
-
+ if((pNewVal == NULL) || (pNewVal == '\0')) {
+ inst->pszBindPort = NULL;
+ } else {
+ CHKmalloc(inst->pszBindPort = ustrdup(pNewVal));
+ }
+ if((cs.pszBindRuleset == NULL) || (cs.pszBindRuleset[0] == '\0')) {
+ inst->pszBindRuleset = NULL;
+ } else {
+ CHKmalloc(inst->pszBindRuleset = ustrdup(cs.pszBindRuleset));
+ }
+ inst->pBindRuleset = NULL;
finalize_it:
+ free(pNewVal);
RETiRet;
}
@@ -314,10 +337,14 @@ addListner(modConfData_t __attribute__((unused)) *modConf, instanceConf_t *inst)
CHKiRet(relpEngineListnerConstruct(pRelpEngine, &pSrv));
CHKiRet(relpSrvSetLstnPort(pSrv, inst->pszBindPort));
+ inst->pszInputName = ustrdup((inst->pszInputName == NULL) ? UCHAR_CONSTANT("imrelp") : inst->pszInputName);
+ CHKiRet(prop.Construct(&inst->pInputName));
+ CHKiRet(prop.SetString(inst->pInputName, inst->pszInputName, ustrlen(inst->pszInputName)));
+ CHKiRet(prop.ConstructFinalize(inst->pInputName));
/* support statistics gathering */
CHKiRet(statsobj.Construct(&(inst->data.stats)));
- snprintf((char*)statname, sizeof(statname), "imrelp(%s)",
- inst->pszBindPort);
+ snprintf((char*)statname, sizeof(statname), "imrelp[%s]",
+ inst->pszBindPort);
statname[sizeof(statname)-1] = '\0'; /* just to be on the save side... */
CHKiRet(statsobj.SetName(inst->data.stats, statname));
STATSCOUNTER_INIT(inst->data.ctrSubmit, inst->data.mutCtrSubmit);
@@ -370,6 +397,8 @@ addListner(modConfData_t __attribute__((unused)) *modConf, instanceConf_t *inst)
ABORT_FINALIZE(RS_RET_RELP_ERR);
}
+ resetConfigVariables(NULL,NULL);
+
finalize_it:
RETiRet;
}
@@ -401,6 +430,10 @@ CODESTARTnewInpInst
continue;
if(!strcmp(inppblk.descr[i].name, "port")) {
inst->pszBindPort = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(inppblk.descr[i].name, "name")) {
+ inst->pszInputName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
+ } else if(!strcmp(inppblk.descr[i].name, "ruleset")) {
+ inst->pszBindRuleset = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
} else if(!strcmp(inppblk.descr[i].name, "keepalive")) {
inst->bKeepAlive = (sbool) pvals[i].val.d.n;
} else if(!strcmp(inppblk.descr[i].name, "keepalive.probes")) {
@@ -448,9 +481,9 @@ CODESTARTbeginCnfLoad
loadModConf = pModConf;
pModConf->pConf = pConf;
pModConf->pszBindRuleset = NULL;
- pModConf->pBindRuleset = NULL;
/* init legacy config variables */
cs.pszBindRuleset = NULL;
+ bLegacyCnfModGlobalsPermitted = 1;
ENDbeginCnfLoad
@@ -480,6 +513,10 @@ CODESTARTsetModCnf
"param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
}
}
+ /* remove all of our legacy module handlers, as they can not used in addition
+ * the the new-style config method.
+ */
+ bLegacyCnfModGlobalsPermitted = 0;
finalize_it:
if(pvals != NULL)
cnfparamvalsDestruct(pvals, &modpblk);
@@ -501,27 +538,18 @@ CODESTARTendCnfLoad
}
finalize_it:
free(cs.pszBindRuleset);
+ cs.pszBindRuleset = NULL;
loadModConf = NULL; /* done loading */
ENDendCnfLoad
-
BEGINcheckCnf
- rsRetVal localRet;
- ruleset_t *pRuleset;
+ instanceConf_t *inst;
CODESTARTcheckCnf
- /* we emulate the standard "ruleset query" code provided by the framework
- * for *instances* (which we can currently not support due to librelp).
- */
- if(pModConf->pszBindRuleset == NULL) {
- pModConf->pBindRuleset = NULL;
- } else {
- DBGPRINTF("imrelp: using ruleset '%s'\n", pModConf->pszBindRuleset);
- localRet = ruleset.GetRuleset(pModConf->pConf, &pRuleset, pModConf->pszBindRuleset);
- if(localRet == RS_RET_NOT_FOUND) {
- std_checkRuleset_genErrMsg(pModConf, NULL);
+ for(inst = pModConf->root ; inst != NULL ; inst = inst->next) {
+ if(inst->pszBindRuleset == NULL && pModConf->pszBindRuleset != NULL) {
+ CHKmalloc(inst->pszBindRuleset = ustrdup(pModConf->pszBindRuleset));
}
- CHKiRet(localRet);
- pModConf->pBindRuleset = pRuleset;
+ std_checkRuleset(pModConf, inst);
}
finalize_it:
ENDcheckCnf
@@ -534,8 +562,10 @@ CODESTARTactivateCnfPrePrivDrop
for(inst = runModConf->root ; inst != NULL ; inst = inst->next) {
addListner(pModConf, inst);
}
- if(pRelpEngine == NULL)
+ if(pRelpEngine == NULL) {
+ errmsg.LogError(0, RS_RET_NO_LSTN_DEFINED, "imrelp: no RELP listener defined, module can not run.");
ABORT_FINALIZE(RS_RET_NO_RUN);
+ }
finalize_it:
ENDactivateCnfPrePrivDrop
@@ -550,6 +580,8 @@ BEGINfreeCnf
CODESTARTfreeCnf
for(inst = pModConf->root ; inst != NULL ; ) {
free(inst->pszBindPort);
+ free(inst->pszBindRuleset);
+ free(inst->pszInputName);
free(inst->pristring);
free(inst->authmode);
statsobj.Destruct(&(inst->data.stats));
@@ -616,10 +648,6 @@ CODESTARTmodExit
if(pRelpEngine != NULL)
iRet = relpEngineDestruct(&pRelpEngine);
- /* global variable cleanup */
- if(pInputName != NULL)
- prop.Destruct(&pInputName);
-
/* release objects we used */
objRelease(statsobj, CORE_COMPONENT);
objRelease(ruleset, CORE_COMPONENT);
@@ -671,17 +699,12 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(statsobj, CORE_COMPONENT));
/* register config file handlers */
- CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputrelpserverbindruleset", 0, eCmdHdlrGetWord,
- NULL, &cs.pszBindRuleset, STD_LOADABLE_MODULE_ID));
+ CHKiRet(regCfSysLineHdlr2((uchar*)"inputrelpserverbindruleset", 0, eCmdHdlrGetWord,
+ NULL, &cs.pszBindRuleset, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputrelpserverrun", 0, eCmdHdlrGetWord,
addInstance, NULL, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
-
- /* we need to create the inputName property (only once during our lifetime) */
- CHKiRet(prop.Construct(&pInputName));
- CHKiRet(prop.SetString(pInputName, UCHAR_CONSTANT("imrelp"), sizeof("imrelp") - 1));
- CHKiRet(prop.ConstructFinalize(pInputName));
ENDmodInit