diff options
author | Michael Biebl <biebl@debian.org> | 2014-03-13 17:57:11 +0100 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2014-03-13 17:57:11 +0100 |
commit | 29867b5cc18d25191fbbdcc4af4f79cc3a4da43e (patch) | |
tree | 1ffedd33b2a2e167aeb4b01a6c5c72aeb98a1b90 /plugins/imjournal | |
parent | 5fccf771f37973a2cea543fbdf1ed94ed9706faf (diff) | |
download | rsyslog-29867b5cc18d25191fbbdcc4af4f79cc3a4da43e.tar.gz |
Imported Upstream version 7.6.1upstream/7.6.1
Diffstat (limited to 'plugins/imjournal')
-rw-r--r-- | plugins/imjournal/Makefile.in | 23 | ||||
-rw-r--r-- | plugins/imjournal/imjournal.c | 127 |
2 files changed, 111 insertions, 39 deletions
diff --git a/plugins/imjournal/Makefile.in b/plugins/imjournal/Makefile.in index d181e2e..5ad1ce2 100644 --- a/plugins/imjournal/Makefile.in +++ b/plugins/imjournal/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@ @@ -388,22 +392,25 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imjournal_la-imjournal.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/imjournal/imjournal.c b/plugins/imjournal/imjournal.c index 36c7e04..c18a279 100644 --- a/plugins/imjournal/imjournal.c +++ b/plugins/imjournal/imjournal.c @@ -68,15 +68,21 @@ static struct configSettings_s { int ratelimitInterval; int ratelimitBurst; int bIgnorePrevious; + int iDfltSeverity; + int iDfltFacility; } cs; +static rsRetVal facilityHdlr(uchar **pp, void *pVal); + /* module-global parameters */ static struct cnfparamdescr modpdescr[] = { { "statefile", eCmdHdlrGetWord, 0 }, { "ratelimit.interval", eCmdHdlrInt, 0 }, { "ratelimit.burst", eCmdHdlrInt, 0 }, { "persiststateinterval", eCmdHdlrInt, 0 }, - { "ignorepreviousmessages", eCmdHdlrBinary, 0 } + { "ignorepreviousmessages", eCmdHdlrBinary, 0 }, + { "defaultseverity", eCmdHdlrSeverity, 0 }, + { "defaultfacility", eCmdHdlrString, 0 } }; static struct cnfparamblk modpblk = { CNFPARAMBLK_VERSION, @@ -85,6 +91,8 @@ static struct cnfparamblk modpblk = }; #define DFLT_persiststateinterval 10 +#define DFLT_SEVERITY LOG_PRI(LOG_NOTICE) +#define DFLT_FACILITY LOG_FAC(LOG_USER) static int bLegacyCnfModGlobalsPermitted = 1;/* are legacy module-global config parameters permitted? */ @@ -94,6 +102,40 @@ static prop_t *pLocalHostIP = NULL; /* a pseudo-constant propterty for 127.0.0.1 static ratelimit_t *ratelimiter = NULL; static sd_journal *j; + +/* ugly workaround to handle facility numbers; values + * derived from names need to be eight times smaller, + * i.e.: 0..23 + */ +static rsRetVal facilityHdlr(uchar **pp, void *pVal) +{ + DEFiRet; + char *p; + + skipWhiteSpace(pp); + p = (char *) *pp; + + if (isdigit((int) *p)) { + *((int *) pVal) = (int) strtol(p, (char **) pp, 10); + } else { + int len; + syslogName_t *c; + + for (len = 0; p[len] && !isspace((int) p[len]); len++) + /* noop */; + for (c = syslogFacNames; c->c_name; c++) { + if (!strncasecmp(p, (char *) c->c_name, len)) { + *((int *) pVal) = LOG_FAC(c->c_val); + break; + } + } + *pp += len; + } + + RETiRet; +} + + /* enqueue the the journal message into the message queue. * The provided msg string is not freed - thus must be done * by the caller. @@ -158,7 +200,6 @@ readjournal() { const void *get; const void *pidget; char *parse; - char *get2; size_t length; size_t pidlength; @@ -170,45 +211,52 @@ readjournal() { long prefixlen = 0; - int priority = 0; - int facility = 0; + int severity = cs.iDfltSeverity; + int facility = cs.iDfltFacility; /* Get message text */ if (sd_journal_get_data(j, "MESSAGE", &get, &length) < 0) { - logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar *)"log message from journal doesn't have MESSAGE", 0); - iRet = RS_RET_OK; - goto ret; - } - message = strndup(get+8, length-8); - if (message == NULL) { - iRet = RS_RET_OUT_OF_MEMORY; - goto ret; + message = strdup(""); + } else { + message = strndup(get+8, length-8); + if (message == NULL) { + iRet = RS_RET_OUT_OF_MEMORY; + goto ret; + } } - /* Get message priority */ + /* Get message severity ("priority" in journald's terminology) */ if (sd_journal_get_data(j, "PRIORITY", &get, &length) >= 0) { - get2 = strndup(get, length); - priority = ((char *)get2)[9] - '0'; - free (get2); + if (length == 10) { + severity = ((char *)get)[9] - '0'; + if (severity < 0 || 7 < severity) { + dbgprintf("The value of the 'PRIORITY' field is " + "out of bounds: %d, resetting\n", severity); + severity = cs.iDfltSeverity; + } + } else { + dbgprintf("The value of the 'PRIORITY' field has an " + "unexpected length: %d\n", length); + } } /* Get syslog facility */ if (sd_journal_get_data(j, "SYSLOG_FACILITY", &get, &length) >= 0) { - get2 = strndup(get, length); - char f = ((char *)get2)[16]; - if (f >= '0' && f <= '9') { - facility += f - '0'; - } - f = ((char *)get2)[17]; - if (f >= '0' && f <= '9') { - facility *= 10; - facility += (f - '0'); + if (length == 17 || length == 18) { + facility = ((char *)get)[16] - '0'; + if (length == 18) { + facility *= 10; + facility += ((char *)get)[17] - '0'; + } + if (facility < 0 || 23 < facility) { + dbgprintf("The value of the 'FACILITY' field is " + "out of bounds: %d, resetting\n", facility); + facility = cs.iDfltFacility; + } + } else { + dbgprintf("The value of the 'FACILITY' field has an " + "unexpected length: %d\n", length); } - free (get2); - } else { - /* message is missing facility -> internal systemd journal msg, drop */ - iRet = RS_RET_OK; - goto free_message; } /* Get message identifier, client pid and add ':' */ @@ -349,7 +397,7 @@ readjournal() { } /* submit message */ - enqMsg((uchar *)message, (uchar *) sys_iden_help, facility, priority, &tv, json); + enqMsg((uchar *)message, (uchar *) sys_iden_help, facility, severity, &tv, json); finalize_it: free(sys_iden_help); @@ -569,6 +617,8 @@ CODESTARTbeginCnfLoad cs.stateFile = NULL; cs.ratelimitBurst = 20000; cs.ratelimitInterval = 600; + cs.iDfltSeverity = DFLT_SEVERITY; + cs.iDfltFacility = DFLT_FACILITY; ENDbeginCnfLoad @@ -657,6 +707,17 @@ CODESTARTsetModCnf cs.ratelimitInterval = (int) pvals[i].val.d.n; } else if (!strcmp(modpblk.descr[i].name, "ignorepreviousmessages")) { cs.bIgnorePrevious = (int) pvals[i].val.d.n; + } else if (!strcmp(modpblk.descr[i].name, "defaultseverity")) { + cs.iDfltSeverity = (int) pvals[i].val.d.n; + } else if (!strcmp(modpblk.descr[i].name, "defaultfacility")) { + /* ugly workaround to handle facility numbers; values + derived from names need to be eight times smaller */ + + char *fac, *p; + + fac = p = es_str2cstr(pvals[i].val.d.estr, NULL); + facilityHdlr((uchar **) &p, (void *) &cs.iDfltFacility); + free(fac); } else { dbgprintf("imjournal: program error, non-handled " "param '%s' in beginCnfLoad\n", modpblk.descr[i].name); @@ -710,6 +771,10 @@ CODEmodInit_QueryRegCFSLineHdlr NULL, &cs.stateFile, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"imjournalignorepreviousmessages", 0, eCmdHdlrBinary, NULL, &cs.bIgnorePrevious, STD_LOADABLE_MODULE_ID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"imjournaldefaultseverity", 0, eCmdHdlrSeverity, + NULL, &cs.iDfltSeverity, STD_LOADABLE_MODULE_ID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"imjournaldefaultfacility", 0, eCmdHdlrCustomHandler, + facilityHdlr, &cs.iDfltFacility, STD_LOADABLE_MODULE_ID)); ENDmodInit |