diff options
Diffstat (limited to 'plugins/imuxsock')
-rw-r--r-- | plugins/imuxsock/Makefile.in | 23 | ||||
-rw-r--r-- | plugins/imuxsock/imuxsock.c | 161 |
2 files changed, 99 insertions, 85 deletions
diff --git a/plugins/imuxsock/Makefile.in b/plugins/imuxsock/Makefile.in index eb9eb43..49b7aa8 100644 --- a/plugins/imuxsock/Makefile.in +++ b/plugins/imuxsock/Makefile.in @@ -183,6 +183,8 @@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBLOGGING_CFLAGS = @LIBLOGGING_CFLAGS@ LIBLOGGING_LIBS = @LIBLOGGING_LIBS@ +LIBLOGGING_STDLOG_CFLAGS = @LIBLOGGING_STDLOG_CFLAGS@ +LIBLOGGING_STDLOG_LIBS = @LIBLOGGING_STDLOG_LIBS@ LIBLOGNORM_CFLAGS = @LIBLOGNORM_CFLAGS@ LIBLOGNORM_LIBS = @LIBLOGNORM_LIBS@ LIBM = @LIBM@ @@ -207,6 +209,8 @@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ +OPENSSL_LIBS = @OPENSSL_LIBS@ ORACLE_CFLAGS = @ORACLE_CFLAGS@ ORACLE_LIBS = @ORACLE_LIBS@ OTOOL = @OTOOL@ @@ -387,22 +391,25 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imuxsock_la-imuxsock.Plo@am__quote@ .c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c index df504dd..107c944 100644 --- a/plugins/imuxsock/imuxsock.c +++ b/plugins/imuxsock/imuxsock.c @@ -62,7 +62,6 @@ MODULE_TYPE_NOKEEP MODULE_CNFNAME("imuxsock") /* defines */ -#define MAXFUNIX 50 #ifndef _PATH_LOG #ifdef BSD #define _PATH_LOG "/var/run/log" @@ -148,7 +147,7 @@ typedef struct lstn_s { sbool bUseSysTimeStamp; /* use timestamp from system (instead of from message) */ sbool bUnlink; /* unlink&re-create socket at start and end of processing */ } lstn_t; -static lstn_t listeners[MAXFUNIX]; +static lstn_t *listeners; static prop_t *pLocalHostIP = NULL; /* there is only one global IP for all internally-generated messages */ static prop_t *pInputName = NULL; /* our inputName currently is always "imudp", and this will hold it */ @@ -156,7 +155,8 @@ static int startIndexUxLocalSockets; /* process fd from that index on (used to * suppress local logging. rgerhards 2005-08-01 * read-only after startup */ -static int nfd = 1; /* number of Unix sockets open / read-only after startup */ +static int nfd = 1; /* number of active unix sockets (socket 0 is always reserved for the system + socket, even if it is not enabled. */ static int sd_fds = 0; /* number of systemd activated sockets */ #define DFLT_bCreatePath 0 @@ -360,12 +360,7 @@ finalize_it: } -/* add an additional listen socket. Socket names are added - * until the array is filled up. It is never reset, only at - * module unload. - * TODO: we should change the array to a list so that we - * can support any number of listen socket names. - * rgerhards, 2007-12-20 +/* add an additional listen socket. * added capability to specify hostname for socket -- rgerhards, 2008-08-01 */ static rsRetVal @@ -373,53 +368,50 @@ addListner(instanceConf_t *inst) { DEFiRet; - if(nfd < MAXFUNIX) { - if(*inst->sockName == ':') { - listeners[nfd].bParseHost = 1; - } else { - listeners[nfd].bParseHost = 0; - } - if(inst->pLogHostName == NULL) { - listeners[nfd].hostName = NULL; - } else { - CHKiRet(prop.Construct(&(listeners[nfd].hostName))); - CHKiRet(prop.SetString(listeners[nfd].hostName, inst->pLogHostName, ustrlen(inst->pLogHostName))); - CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName)); - } - if(inst->ratelimitInterval > 0) { - if((listeners[nfd].ht = create_hashtable(100, hash_from_key_fn, key_equals_fn, - (void(*)(void*))ratelimitDestruct)) == NULL) { - /* in this case, we simply turn off rate-limiting */ - DBGPRINTF("imuxsock: turning off rate limiting because we could not " - "create hash table\n"); - inst->ratelimitInterval = 0; - } + if(*inst->sockName == ':') { + listeners[nfd].bParseHost = 1; + } else { + listeners[nfd].bParseHost = 0; + } + if(inst->pLogHostName == NULL) { + listeners[nfd].hostName = NULL; + } else { + CHKiRet(prop.Construct(&(listeners[nfd].hostName))); + CHKiRet(prop.SetString(listeners[nfd].hostName, inst->pLogHostName, ustrlen(inst->pLogHostName))); + CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName)); + } + if(inst->ratelimitInterval > 0) { + if((listeners[nfd].ht = create_hashtable(100, hash_from_key_fn, key_equals_fn, + (void(*)(void*))ratelimitDestruct)) == NULL) { + /* in this case, we simply turn off rate-limiting */ + DBGPRINTF("imuxsock: turning off rate limiting because we could not " + "create hash table\n"); + inst->ratelimitInterval = 0; } - listeners[nfd].ratelimitInterval = inst->ratelimitInterval; - listeners[nfd].ratelimitBurst = inst->ratelimitBurst; - listeners[nfd].ratelimitSev = inst->ratelimitSeverity; - listeners[nfd].flowCtl = inst->bUseFlowCtl ? eFLOWCTL_LIGHT_DELAY : eFLOWCTL_NO_DELAY; - listeners[nfd].flags = inst->bIgnoreTimestamp ? IGNDATE : NOFLAG; - listeners[nfd].bCreatePath = inst->bCreatePath; - listeners[nfd].sockName = ustrdup(inst->sockName); - listeners[nfd].bUseCreds = (inst->bDiscardOwnMsgs || inst->bWritePid || inst->ratelimitInterval || inst->bAnnotate || inst->bUseSysTimeStamp) ? 1 : 0; - listeners[nfd].bAnnotate = inst->bAnnotate; - listeners[nfd].bParseTrusted = inst->bParseTrusted; - listeners[nfd].bDiscardOwnMsgs = inst->bDiscardOwnMsgs; - listeners[nfd].bUnlink = inst->bUnlink; - listeners[nfd].bWritePid = inst->bWritePid; - listeners[nfd].bUseSysTimeStamp = inst->bUseSysTimeStamp; - CHKiRet(ratelimitNew(&listeners[nfd].dflt_ratelimiter, "imuxsock", NULL)); - ratelimitSetLinuxLike(listeners[nfd].dflt_ratelimiter, - listeners[nfd].ratelimitInterval, - listeners[nfd].ratelimitBurst); - ratelimitSetSeverity(listeners[nfd].dflt_ratelimiter, - listeners[nfd].ratelimitSev); - nfd++; } else { - errmsg.LogError(0, NO_ERRCODE, "Out of unix socket name descriptors, ignoring %s\n", - inst->sockName); + listeners[nfd].ht = NULL; } + listeners[nfd].ratelimitInterval = inst->ratelimitInterval; + listeners[nfd].ratelimitBurst = inst->ratelimitBurst; + listeners[nfd].ratelimitSev = inst->ratelimitSeverity; + listeners[nfd].flowCtl = inst->bUseFlowCtl ? eFLOWCTL_LIGHT_DELAY : eFLOWCTL_NO_DELAY; + listeners[nfd].flags = inst->bIgnoreTimestamp ? IGNDATE : NOFLAG; + listeners[nfd].bCreatePath = inst->bCreatePath; + listeners[nfd].sockName = ustrdup(inst->sockName); + listeners[nfd].bUseCreds = (inst->bDiscardOwnMsgs || inst->bWritePid || inst->ratelimitInterval || inst->bAnnotate) ? 1 : 0; + listeners[nfd].bAnnotate = inst->bAnnotate; + listeners[nfd].bParseTrusted = inst->bParseTrusted; + listeners[nfd].bDiscardOwnMsgs = inst->bDiscardOwnMsgs; + listeners[nfd].bUnlink = inst->bUnlink; + listeners[nfd].bWritePid = inst->bWritePid; + listeners[nfd].bUseSysTimeStamp = inst->bUseSysTimeStamp; + CHKiRet(ratelimitNew(&listeners[nfd].dflt_ratelimiter, "imuxsock", NULL)); + ratelimitSetLinuxLike(listeners[nfd].dflt_ratelimiter, + listeners[nfd].ratelimitInterval, + listeners[nfd].ratelimitBurst); + ratelimitSetSeverity(listeners[nfd].dflt_ratelimiter, + listeners[nfd].ratelimitSev); + nfd++; finalize_it: RETiRet; @@ -1216,31 +1208,31 @@ CODESTARTnewInpInst continue; if(!strcmp(inppblk.descr[i].name, "socket")) { inst->sockName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); - } else if(!strcmp(modpblk.descr[i].name, "createpath")) { + } else if(!strcmp(inppblk.descr[i].name, "createpath")) { inst->bCreatePath = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "parsetrusted")) { + } else if(!strcmp(inppblk.descr[i].name, "parsetrusted")) { inst->bParseTrusted = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "ignoreownmessages")) { + } else if(!strcmp(inppblk.descr[i].name, "ignoreownmessages")) { inst->bDiscardOwnMsgs = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "unlink")) { + } else if(!strcmp(inppblk.descr[i].name, "unlink")) { inst->bUnlink = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "hostname")) { + } else if(!strcmp(inppblk.descr[i].name, "hostname")) { inst->pLogHostName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); - } else if(!strcmp(modpblk.descr[i].name, "ignoretimestamp")) { + } else if(!strcmp(inppblk.descr[i].name, "ignoretimestamp")) { inst->bIgnoreTimestamp = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "flowcontrol")) { + } else if(!strcmp(inppblk.descr[i].name, "flowcontrol")) { inst->bUseFlowCtl = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "usesystimestamp")) { + } else if(!strcmp(inppblk.descr[i].name, "usesystimestamp")) { inst->bUseSysTimeStamp = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "annotate")) { + } else if(!strcmp(inppblk.descr[i].name, "annotate")) { inst->bAnnotate = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "usepidfromsystem")) { + } else if(!strcmp(inppblk.descr[i].name, "usepidfromsystem")) { inst->bWritePid = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "ratelimit.interval")) { + } else if(!strcmp(inppblk.descr[i].name, "ratelimit.interval")) { inst->ratelimitInterval = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "ratelimit.burst")) { + } else if(!strcmp(inppblk.descr[i].name, "ratelimit.burst")) { inst->ratelimitBurst = (int) pvals[i].val.d.n; - } else if(!strcmp(modpblk.descr[i].name, "ratelimit.severity")) { + } else if(!strcmp(inppblk.descr[i].name, "ratelimit.severity")) { inst->ratelimitSeverity = (int) pvals[i].val.d.n; } else { dbgprintf("imuxsock: program error, non-handled " @@ -1286,10 +1278,28 @@ ENDcheckCnf BEGINactivateCnfPrePrivDrop instanceConf_t *inst; + int nLstn; + int i; CODESTARTactivateCnfPrePrivDrop runModConf = pModConf; + /* we first calculate the number of listeners so that we can + * appropriately size the listener array. Note that we will + * always allocate memory for the system log socket. + */ + nLstn = 0; for(inst = runModConf->root ; inst != NULL ; inst = inst->next) { - addListner(inst); + ++nLstn; + } + if(nLstn > 0) { + DBGPRINTF("imuxsock: allocating memory for %d addtl listeners\n", nLstn); + CHKmalloc(listeners = realloc(listeners, (1+nLstn)*sizeof(lstn_t))); + for(i = 1 ; i < nLstn ; ++i) { + listeners[i].sockName = NULL; + listeners[i].fd = -1; + } + for(inst = runModConf->root ; inst != NULL ; inst = inst->next) { + addListner(inst); + } } CHKiRet(activateListeners()); finalize_it: @@ -1329,6 +1339,8 @@ BEGINrunInput #endif CODESTARTrunInput + if(runModConf->bOmitLocalLogging && nfd == 1) + ABORT_FINALIZE(RS_RET_OK); /* this is an endless loop - it is terminated when the thread is * signalled to do so. This, however, is handled by the framework, * right into the sleep below. @@ -1419,6 +1431,7 @@ ENDafterRun BEGINmodExit CODESTARTmodExit + free(listeners); if(pInputName != NULL) prop.Destruct(&pInputName); @@ -1481,7 +1494,6 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a BEGINmodInit() - int i; CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr @@ -1512,6 +1524,7 @@ CODEmodInit_QueryRegCFSLineHdlr pLocalHostIP = glbl.GetLocalHostIP(); /* init system log socket settings */ + CHKmalloc(listeners = malloc(sizeof(lstn_t))); listeners[0].flags = IGNDATE; listeners[0].sockName = UCHAR_CONSTANT(_PATH_LOG); listeners[0].hostName = NULL; @@ -1533,12 +1546,6 @@ CODEmodInit_QueryRegCFSLineHdlr listeners[0].ratelimitInterval = 0; } - /* initialize socket names */ - for(i = 1 ; i < MAXFUNIX ; ++i) { - listeners[i].sockName = NULL; - listeners[i].fd = -1; - } - /* register config file handlers */ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputunixlistensocketignoremsgtimestamp", 0, eCmdHdlrBinary, NULL, &cs.bIgnoreTimestamp, STD_LOADABLE_MODULE_ID)); @@ -1598,13 +1605,13 @@ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(statsobj.SetName(modStats, UCHAR_CONSTANT("imuxsock"))); STATSCOUNTER_INIT(ctrSubmit, mutCtrSubmit); CHKiRet(statsobj.AddCounter(modStats, UCHAR_CONSTANT("submitted"), - ctrType_IntCtr, &ctrSubmit)); + ctrType_IntCtr, CTR_FLAG_RESETTABLE, &ctrSubmit)); STATSCOUNTER_INIT(ctrLostRatelimit, mutCtrLostRatelimit); CHKiRet(statsobj.AddCounter(modStats, UCHAR_CONSTANT("ratelimit.discarded"), - ctrType_IntCtr, &ctrLostRatelimit)); + ctrType_IntCtr, CTR_FLAG_RESETTABLE, &ctrLostRatelimit)); STATSCOUNTER_INIT(ctrNumRatelimiters, mutCtrNumRatelimiters); CHKiRet(statsobj.AddCounter(modStats, UCHAR_CONSTANT("ratelimit.numratelimiters"), - ctrType_IntCtr, &ctrNumRatelimiters)); + ctrType_IntCtr, CTR_FLAG_RESETTABLE, &ctrNumRatelimiters)); CHKiRet(statsobj.ConstructFinalize(modStats)); ENDmodInit |