diff options
-rw-r--r-- | Makefile.am | 24 | ||||
-rw-r--r-- | action.c | 9 | ||||
-rw-r--r-- | cfsysline.c | 54 | ||||
-rw-r--r-- | conf.c | 37 | ||||
-rw-r--r-- | errmsg.c | 121 | ||||
-rw-r--r-- | errmsg.h | 45 | ||||
-rw-r--r-- | gss-misc.c | 116 | ||||
-rw-r--r-- | gss-misc.h | 39 | ||||
-rw-r--r-- | modules.c | 16 | ||||
-rw-r--r-- | net.c | 69 | ||||
-rw-r--r-- | obj.c | 11 | ||||
-rw-r--r-- | omfile.c | 23 | ||||
-rw-r--r-- | omfwd.c | 15 | ||||
-rw-r--r-- | omshell.c | 5 | ||||
-rw-r--r-- | plugins/imfile/imfile.c | 13 | ||||
-rw-r--r-- | plugins/imgssapi/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/imgssapi/imgssapi.c | 44 | ||||
-rw-r--r-- | plugins/imudp/imudp.c | 8 | ||||
-rw-r--r-- | plugins/imuxsock/imuxsock.c | 8 | ||||
-rw-r--r-- | plugins/omgssapi/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/omgssapi/omgssapi.c | 40 | ||||
-rw-r--r-- | plugins/omsnmp/omsnmp.c | 15 | ||||
-rw-r--r-- | syslogd.c | 138 | ||||
-rw-r--r-- | syslogd.h | 5 | ||||
-rw-r--r-- | tcps_sess.c | 11 | ||||
-rw-r--r-- | tcpsrv.c | 41 | ||||
-rw-r--r-- | template.c | 31 |
27 files changed, 627 insertions, 315 deletions
diff --git a/Makefile.am b/Makefile.am index ce9f80da..ed6f2287 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,8 @@ sbin_PROGRAMS = rfc3195d rsyslogd rfc3195d_SOURCES = rfc3195d.c rsyslog.h rsyslogd_SOURCES = \ + errmsg.c \ + errmsg.h \ syslogd.c \ syslogd.h \ sysvar.c \ @@ -91,15 +93,13 @@ rsyslogd_CPPFLAGS = $(mudflap_cflags) -D_PATH_MODDIR=\"$(pkglibdir)/\" $(pthrea rsyslogd_LDADD = $(mudflap_libs) $(zlib_libs) $(pthreads_libs) $(dl_libs) $(rt_libs) rsyslogd_LDFLAGS = -export-dynamic -if ENABLE_GSSAPI -noinst_LTLIBRARIES = libgssapi-misc.la -libgssapi_misc_la_SOURCES = gss-misc.c gss-misc.h -libgssapi_misc_la_LIBADD = $(gss_libs) -endif - # now come the library plugins -pkglib_LTLIBRARIES = tcpsrv.la +# TODO: how? build gssutil.la only if gssapi is supported rgerhards, 2008-03-05 +pkglib_LTLIBRARIES = tcpsrv.la gssutil.la +# +# TCP (Stream) Server support +# tcpsrv_la_SOURCES = \ tcps_sess.c \ tcps_sess.h \ @@ -109,6 +109,16 @@ tcpsrv_la_CPPFLAGS = $(pthreads_cflags) $(mudflap_cflags) tcpsrv_la_LDFLAGS = $(mudflap_libs) -module -avoid-version tcpsrv_la_LIBADD = +# +# gssapi support +# +if ENABLE_GSSAPI +gssutil_la_SOURCES = gss-misc.c gss-misc.h +gssutil_la_CPPFLAGS = $(pthreads_cflags) $(mudflap_cflags) +gssutil_la_LDFLAGS = $(mudflap_libs) -module -avoid-version +gssutil_la_LIBADD = +endif + man_MANS = rfc3195d.8 rsyslogd.8 rsyslog.conf.5 EXTRA_DIST = \ @@ -40,6 +40,7 @@ #include "sync.h" #include "cfsysline.h" #include "srUtils.h" +#include "errmsg.h" /* forward definitions */ rsRetVal actionCallDoAction(action_t *pAction, msg_t *pMsg); @@ -47,6 +48,7 @@ rsRetVal actionCallDoAction(action_t *pAction, msg_t *pMsg); /* object static data (once for all instances) */ DEFobjStaticHelpers DEFobjCurrIf(module) +DEFobjCurrIf(errmsg) static int glbliActionResumeInterval = 30; int glbliActionResumeRetryCount = 0; /* how often should suspended actions be retried? */ @@ -209,11 +211,11 @@ actionConstructFinalize(action_t *pThis) /* ... set some properties ... */ # define setQPROP(func, directive, data) \ CHKiRet_Hdlr(func(pThis->pQueue, data)) { \ - logerrorInt("Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ + errmsg.LogError(NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } # define setQPROPstr(func, directive, data) \ CHKiRet_Hdlr(func(pThis->pQueue, data, (data == NULL)? 0 : strlen((char*) data))) { \ - logerrorInt("Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ + errmsg.LogError(NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } queueSetpUsr(pThis->pQueue, pThis); @@ -460,7 +462,7 @@ static rsRetVal setActionQueType(void __attribute__((unused)) *pVal, uchar *pszT ActionQueType = QUEUETYPE_DIRECT; dbgprintf("action queue type set to DIRECT (no queueing at all)\n"); } else { - logerrorSz("unknown actionqueue parameter: %s", (char *) pszType); + errmsg.LogError(NO_ERRCODE, "unknown actionqueue parameter: %s", (char *) pszType); iRet = RS_RET_INVALID_PARAMS; } d_free(pszType); /* no longer needed */ @@ -685,6 +687,7 @@ rsRetVal actionClassInit(void) /* request objects we use */ CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */ CHKiRet(objUse(module, CORE_COMPONENT)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); finalize_it: RETiRet; diff --git a/cfsysline.c b/cfsysline.c index 67dc0940..e0be4ed7 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -34,10 +34,15 @@ #include "syslogd.h" /* TODO: when the module interface & library design is done, this should be able to go away */ #include "cfsysline.h" +#include "obj.h" +#include "errmsg.h" #include "srUtils.h" /* static data */ +DEFobjCurrIf(obj) +DEFobjCurrIf(errmsg) + linkedList_t llCmdList; /* this is NOT a pointer - no typo here ;) */ /* --------------- START functions for handling canned syntaxes --------------- */ @@ -60,7 +65,7 @@ static rsRetVal doGetChar(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void * /* if we are not at a '\0', we have our new char - no validity checks here... */ if(**pp == '\0') { - logerror("No character available"); + errmsg.LogError(NO_ERRCODE, "No character available"); iRet = RS_RET_NOT_FOUND; } else { if(pSetHdlr == NULL) { @@ -124,7 +129,7 @@ static rsRetVal parseIntVal(uchar **pp, int64 *pVal) if(!isdigit((int) *p)) { errno = 0; - logerror("invalid number"); + errmsg.LogError(NO_ERRCODE, "invalid number"); ABORT_FINALIZE(RS_RET_INVALID_INT); } @@ -263,7 +268,7 @@ static rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), "value must be octal (e.g 0644)."); errno = 0; - logerror((char*) errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); ABORT_FINALIZE(RS_RET_INVALID_VALUE); } @@ -308,7 +313,7 @@ static int doParseOnOffOption(uchar **pp) skipWhiteSpace(pp); /* skip over any whitespace */ if(getSubString(pp, (char*) szOpt, sizeof(szOpt) / sizeof(uchar), ' ') != 0) { - logerror("Invalid $-configline - could not extract on/off option"); + errmsg.LogError(NO_ERRCODE, "Invalid $-configline - could not extract on/off option"); return -1; } @@ -317,7 +322,7 @@ static int doParseOnOffOption(uchar **pp) } else if(!strcmp((char*)szOpt, "off")) { return 0; } else { - logerrorSz("Option value must be on or off, but is '%s'", (char*)pOptStart); + errmsg.LogError(NO_ERRCODE, "Option value must be on or off, but is '%s'", (char*)pOptStart); return -1; } } @@ -338,14 +343,14 @@ static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p assert(*pp != NULL); if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { - logerror("could not extract group name"); + errmsg.LogError(NO_ERRCODE, "could not extract group name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } getgrnam_r((char*)szName, &gBuf, stringBuf, sizeof(stringBuf), &pgBuf); if(pgBuf == NULL) { - logerrorSz("ID for group '%s' could not be found or error", (char*)szName); + errmsg.LogError(NO_ERRCODE, "ID for group '%s' could not be found or error", (char*)szName); iRet = RS_RET_NOT_FOUND; } else { if(pSetHdlr == NULL) { @@ -380,14 +385,14 @@ static rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p assert(*pp != NULL); if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { - logerror("could not extract user name"); + errmsg.LogError(NO_ERRCODE, "could not extract user name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } getpwnam_r((char*)szName, &pwBuf, stringBuf, sizeof(stringBuf), &ppwBuf); if(ppwBuf == NULL) { - logerrorSz("ID for user '%s' could not be found or error", (char*)szName); + errmsg.LogError(NO_ERRCODE, "ID for user '%s' could not be found or error", (char*)szName); iRet = RS_RET_NOT_FOUND; } else { if(pSetHdlr == NULL) { @@ -782,20 +787,6 @@ finalize_it: } -/* function that initializes this module here. This is primarily a hook - * for syslogd. - */ -rsRetVal cfsyslineInit(void) -{ - DEFiRet; - - CHKiRet(llInit(&llCmdList, cslcDestruct, cslcKeyDestruct, strcasecmp)); - -finalize_it: - RETiRet; -} - - /* function that registers cfsysline handlers. * The supplied pCmdName is copied and a new buffer is allocated. This * buffer is automatically destroyed when the element is freed, the @@ -912,7 +903,7 @@ rsRetVal processCfSysLineCommand(uchar *pCmdName, uchar **p) iRet = llFind(&llCmdList, (void *) pCmdName, (void*) &pCmd); if(iRet == RS_RET_NOT_FOUND) { - logerror("invalid or yet-unknown config file command - have you forgotten to load a module?"); + errmsg.LogError(NO_ERRCODE, "invalid or yet-unknown config file command - have you forgotten to load a module?"); } if(iRet != RS_RET_OK) @@ -978,5 +969,20 @@ void dbgPrintCfSysLineHandlers(void) ENDfunc } + +/* our init function. TODO: remove once converted to a class + */ +rsRetVal cfsyslineInit() +{ + DEFiRet; + CHKiRet(objGetObjInterface(&obj)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); + + CHKiRet(llInit(&llCmdList, cslcDestruct, cslcKeyDestruct, strcasecmp)); + +finalize_it: + RETiRet; +} + /* vim:set ai: */ @@ -56,6 +56,7 @@ #include "conf.h" #include "stringbuf.h" #include "srUtils.h" +#include "errmsg.h" /* forward definitions */ @@ -68,6 +69,7 @@ DEFobjStaticHelpers DEFobjCurrIf(expr) DEFobjCurrIf(ctok) DEFobjCurrIf(module) +DEFobjCurrIf(errmsg) /* The following global variables are used for building * tag and host selector lines during startup and config reload. @@ -106,7 +108,7 @@ static rsRetVal doIncludeDirectory(uchar *pDirName) ASSERT(pDirName != NULL); if((pDir = opendir((char*) pDirName)) == NULL) { - logerror("error opening include directory"); + errmsg.LogError(NO_ERRCODE, "error opening include directory"); ABORT_FINALIZE(RS_RET_FOPEN_FAILURE); } @@ -181,7 +183,7 @@ doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal) ASSERT(*pp != NULL); if(getSubString(pp, (char*) pattern, sizeof(pattern) / sizeof(char), ' ') != 0) { - logerror("could not extract group name"); + errmsg.LogError(NO_ERRCODE, "could not extract group name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } @@ -227,7 +229,7 @@ doModLoad(uchar **pp, __attribute__((unused)) void* pVal) ASSERT(*pp != NULL); if(getSubString(pp, (char*) szName, sizeof(szName) / sizeof(uchar), ' ') != 0) { - logerror("could not extract module name"); + errmsg.LogError(NO_ERRCODE, "could not extract module name"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } skipWhiteSpace(pp); /* skip over any whitespace */ @@ -274,7 +276,7 @@ doNameLine(uchar **pp, void* pVal) eDir = (enum eDirective) pVal; /* this time, it actually is NOT a pointer! */ if(getSubString(&p, szName, sizeof(szName) / sizeof(char), ',') != 0) { - logerror("Invalid config line: could not extract name - line ignored"); + errmsg.LogError(NO_ERRCODE, "Invalid config line: could not extract name - line ignored"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } if(*p == ',') @@ -328,7 +330,7 @@ cfsysline(uchar *p) ASSERT(p != NULL); errno = 0; if(getSubString(&p, (char*) szCmd, sizeof(szCmd) / sizeof(uchar), ' ') != 0) { - logerror("Invalid $-configline - could not extract command - line ignored\n"); + errmsg.LogError(NO_ERRCODE, "Invalid $-configline - could not extract command - line ignored\n"); ABORT_FINALIZE(RS_RET_NOT_FOUND); } @@ -349,7 +351,7 @@ cfsysline(uchar *p) snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), "error: extra characters in config line ignored: '%s'", p); errno = 0; - logerror((char*) errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); } finalize_it: @@ -421,7 +423,7 @@ processConfFile(uchar *pConfFile) dbgprintf("config line NOT successfully processed\n"); snprintf((char*)szErrLoc, sizeof(szErrLoc) / sizeof(uchar), "%s, line %d", pConfFile, iLnNbr); - logerrorSz("the last error occured in %s", (char*)szErrLoc); + errmsg.LogError(NO_ERRCODE, "the last error occured in %s", (char*)szErrLoc); } } @@ -470,7 +472,7 @@ rsRetVal cflineParseTemplateName(uchar** pp, omodStringRequest_t *pOMSR, int iEn if(*p == ';') ++p; /* eat it */ else if(*p != '\0' && *p != '#') { - logerror("invalid character in selector line - ';template' expected"); + errmsg.LogError(NO_ERRCODE, "invalid character in selector line - ';template' expected"); iRet = RS_RET_ERR; goto finalize_it; } @@ -610,7 +612,7 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f if (pri < 0) { snprintf((char*) xbuf, sizeof(xbuf), "unknown priority name \"%s\"", buf); - logerror((char*) xbuf); + errmsg.LogError(NO_ERRCODE, "%s", xbuf); return RS_RET_ERR; } @@ -657,7 +659,7 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f if (i < 0) { snprintf((char*) xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf); - logerror((char*) xbuf); + errmsg.LogError(NO_ERRCODE, "%s", xbuf); return RS_RET_ERR; } @@ -761,7 +763,7 @@ dbgprintf("calling expression parser, pp %p ('%s')\n", *pline, *pline); finalize_it: RUNLOG_VAR("%d", iRet); if(iRet == RS_RET_SYNTAX_ERROR) { - logerror("syntax error in expression"); + errmsg.LogError(NO_ERRCODE, "syntax error in expression"); } RETiRet; @@ -791,14 +793,14 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) /* create parser object starting with line string without leading colon */ if((iRet = rsParsConstructFromSz(&pPars, (*pline)+1)) != RS_RET_OK) { - logerrorInt("Error %d constructing parser object - ignoring selector", iRet); + errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring selector", iRet); return(iRet); } /* read property */ iRet = parsDelimCStr(pPars, &f->f_filterData.prop.pCSPropName, ',', 1, 1); if(iRet != RS_RET_OK) { - logerrorInt("error %d parsing filter property - ignoring selector", iRet); + errmsg.LogError(NO_ERRCODE, "error %d parsing filter property - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } @@ -806,7 +808,7 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) /* read operation */ iRet = parsDelimCStr(pPars, &pCSCompOp, ',', 1, 1); if(iRet != RS_RET_OK) { - logerrorInt("error %d compare operation property - ignoring selector", iRet); + errmsg.LogError(NO_ERRCODE, "error %d compare operation property - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } @@ -838,7 +840,7 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "regex", 5)) { f->f_filterData.prop.operation = FIOP_REGEX; } else { - logerrorSz("error: invalid compare operation '%s' - ignoring selector", + errmsg.LogError(NO_ERRCODE, "error: invalid compare operation '%s' - ignoring selector", (char*) rsCStrGetSzStrNoNULL(pCSCompOp)); } rsCStrDestruct(&pCSCompOp); /* no longer needed */ @@ -846,14 +848,14 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) /* read compare value */ iRet = parsQuotedCStr(pPars, &f->f_filterData.prop.pCSCompValue); if(iRet != RS_RET_OK) { - logerrorInt("error %d compare value property - ignoring selector", iRet); + errmsg.LogError(NO_ERRCODE, "error %d compare value property - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } /* skip to action part */ if((iRet = parsSkipWhitespace(pPars)) != RS_RET_OK) { - logerrorInt("error %d skipping to action part - ignoring selector", iRet); + errmsg.LogError(NO_ERRCODE, "error %d skipping to action part - ignoring selector", iRet); rsParsDestruct(pPars); return(iRet); } @@ -1167,6 +1169,7 @@ BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANG CHKiRet(objUse(expr, CORE_COMPONENT)); CHKiRet(objUse(ctok, CORE_COMPONENT)); CHKiRet(objUse(module, CORE_COMPONENT)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); ENDObjClassInit(conf) /* vi:set ai: diff --git a/errmsg.c b/errmsg.c new file mode 100644 index 00000000..a1952ddb --- /dev/null +++ b/errmsg.c @@ -0,0 +1,121 @@ +/* The errmsg object. + * + * Module begun 2008-03-05 by Rainer Gerhards, based on some code + * from syslogd.c + * + * Copyright 2008 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ + +#include "config.h" +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <errno.h> +#include <assert.h> + +#include "rsyslog.h" +#include "syslogd.h" +#include "obj.h" +#include "errmsg.h" +#include "sysvar.h" +#include "srUtils.h" +#include "stringbuf.h" + +/* static data */ +DEFobjStaticHelpers + + +/* ------------------------------ methods ------------------------------ */ + + +/* TODO: restructure this code some time. Especially look if we need + * to check errno and, if so, how to do that in a clean way. + */ +static void __attribute__((format(printf, 2, 3))) +LogError(int iErrCode, char *fmt, ... ) +{ + va_list ap; + char buf[1024]; + char msg[1024]; + char errStr[1024]; + size_t lenBuf; + + BEGINfunc + assert(fmt != NULL); + /* Format parameters */ + va_start(ap, fmt); + lenBuf = vsnprintf(buf, sizeof(buf), fmt, ap); + if(lenBuf >= sizeof(buf)) { + /* if our buffer was too small, we simply truncate. */ + lenBuf--; + } + va_end(ap); + + /* Log the error now */ + buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ + + dbgprintf("Called LogError, msg: %s\n", buf); + + if (errno == 0) { + snprintf(msg, sizeof(msg), "%s", buf); + } else { + rs_strerror_r(errno, errStr, sizeof(errStr)); + snprintf(msg, sizeof(msg), "%s: %s", buf, errStr); + } + msg[sizeof(msg)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ + errno = 0; + logmsgInternal(LOG_SYSLOG|LOG_ERR, msg, ADDDATE); + + ENDfunc +} + + +/* queryInterface function + * rgerhards, 2008-03-05 + */ +BEGINobjQueryInterface(errmsg) +CODESTARTobjQueryInterface(errmsg) + if(pIf->ifVersion != errmsgCURR_IF_VERSION) { /* check for current version, increment on each change */ + ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED); + } + + /* ok, we have the right interface, so let's fill it + * Please note that we may also do some backwards-compatibility + * work here (if we can support an older interface version - that, + * of course, also affects the "if" above). + */ + pIf->LogError = LogError; +finalize_it: +ENDobjQueryInterface(errmsg) + + +/* Initialize the errmsg class. Must be called as the very first method + * before anything else is called inside this class. + * rgerhards, 2008-02-19 + */ +BEGINAbstractObjClassInit(errmsg, 1, OBJ_IS_CORE_MODULE) /* class, version */ + /* request objects we use */ +RUNLOG_STR("errmsg ClassInit is called!\n"); + + /* set our own handlers */ +ENDObjClassInit(errmsg) + +/* vi:set ai: + */ diff --git a/errmsg.h b/errmsg.h new file mode 100644 index 00000000..12469581 --- /dev/null +++ b/errmsg.h @@ -0,0 +1,45 @@ +/* The errmsg object. It is used to emit error message inside rsyslog. + * + * Copyright 2008 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ +#ifndef INCLUDED_ERRMSG_H +#define INCLUDED_ERRMSG_H + +#include "errmsg.h" + +/* TODO: define error codes */ +#define NO_ERRCODE -1 + +/* the errmsg object */ +typedef struct errmsg_s { +} errmsg_t; + + +/* interfaces */ +BEGINinterface(errmsg) /* name must also be changed in ENDinterface macro! */ + void __attribute__((format(printf, 2, 3))) (*LogError)(int iErrCode, char *pszErrFmt, ... ); +ENDinterface(errmsg) +#define errmsgCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */ + + +/* prototypes */ +PROTOTYPEObj(errmsg); + +#endif /* #ifndef INCLUDED_ERRMSG_H */ @@ -1,5 +1,26 @@ +/* gss-misc.c + * This is a miscellaneous helper class for gss-api features. + * + * Copyright 2007 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ #include "config.h" -#if defined(SYSLOG_INET) && defined(USE_GSSAPI) #include "rsyslog.h" #include <stdio.h> #include <stdarg.h> @@ -29,8 +50,15 @@ #include "msg.h" #include "tcpsyslog.h" #include "module-template.h" +#include "obj.h" +#include "errmsg.h" #include "gss-misc.h" +MODULE_TYPE_LIB + +/* static data */ +DEFobjStaticHelpers +DEFobjCurrIf(errmsg) static void display_status_(char *m, OM_uint32 code, int type) { @@ -40,13 +68,13 @@ static void display_status_(char *m, OM_uint32 code, int type) do { maj_stat = gss_display_status(&min_stat, code, type, GSS_C_NO_OID, &msg_ctx, &msg); if (maj_stat != GSS_S_COMPLETE) { - logerrorSz("GSS-API error in gss_display_status called from <%s>\n", m); + errmsg.LogError(NO_ERRCODE, "GSS-API error in gss_display_status called from <%s>\n", m); break; } else { char buf[1024]; snprintf(buf, sizeof(buf), "GSS-API error %s: %s\n", m, (char *) msg.value); buf[sizeof(buf)/sizeof(char) - 1] = '\0'; - logerror(buf); + errmsg.LogError(NO_ERRCODE, "%s", buf); } if (msg.length != 0) gss_release_buffer(&min_stat, &msg); @@ -54,14 +82,14 @@ static void display_status_(char *m, OM_uint32 code, int type) } -void display_status(char *m, OM_uint32 maj_stat, OM_uint32 min_stat) +static void display_status(char *m, OM_uint32 maj_stat, OM_uint32 min_stat) { display_status_(m, maj_stat, GSS_C_GSS_CODE); display_status_(m, min_stat, GSS_C_MECH_CODE); } -void display_ctx_flags(OM_uint32 flags) +static void display_ctx_flags(OM_uint32 flags) { if (flags & GSS_C_DELEG_FLAG) dbgprintf("GSS_C_DELEG_FLAG\n"); @@ -128,7 +156,7 @@ static int write_all(int fd, char *buf, unsigned int nbyte) } -int recv_token(int s, gss_buffer_t tok) +static int recv_token(int s, gss_buffer_t tok) { int ret; unsigned char lenbuf[4]; @@ -136,12 +164,12 @@ int recv_token(int s, gss_buffer_t tok) ret = read_all(s, (char *) lenbuf, 4); if (ret < 0) { - logerror("GSS-API error reading token length"); + errmsg.LogError(NO_ERRCODE, "GSS-API error reading token length"); return -1; } else if (!ret) { return 0; } else if (ret != 4) { - logerror("GSS-API error reading token length"); + errmsg.LogError(NO_ERRCODE, "GSS-API error reading token length"); return -1; } @@ -153,17 +181,17 @@ int recv_token(int s, gss_buffer_t tok) tok->value = (char *) malloc(tok->length ? tok->length : 1); if (tok->length && tok->value == NULL) { - logerror("Out of memory allocating token data\n"); + errmsg.LogError(NO_ERRCODE, "Out of memory allocating token data\n"); return -1; } ret = read_all(s, (char *) tok->value, tok->length); if (ret < 0) { - logerror("GSS-API error reading token data"); + errmsg.LogError(NO_ERRCODE, "GSS-API error reading token data"); free(tok->value); return -1; } else if (ret != (int) tok->length) { - logerror("GSS-API error reading token data"); + errmsg.LogError(NO_ERRCODE, "GSS-API error reading token data"); free(tok->value); return -1; } @@ -172,7 +200,7 @@ int recv_token(int s, gss_buffer_t tok) } -int send_token(int s, gss_buffer_t tok) +static int send_token(int s, gss_buffer_t tok) { int ret; unsigned char lenbuf[4]; @@ -188,23 +216,77 @@ int send_token(int s, gss_buffer_t tok) ret = write_all(s, (char *) lenbuf, 4); if (ret < 0) { - logerror("GSS-API error sending token length"); + errmsg.LogError(NO_ERRCODE, "GSS-API error sending token length"); return -1; } else if (ret != 4) { - logerror("GSS-API error sending token length"); + errmsg.LogError(NO_ERRCODE, "GSS-API error sending token length"); return -1; } ret = write_all(s, tok->value, tok->length); if (ret < 0) { - logerror("GSS-API error sending token data"); + errmsg.LogError(NO_ERRCODE, "GSS-API error sending token data"); return -1; } else if (ret != (int) tok->length) { - logerror("GSS-API error sending token data"); + errmsg.LogError(NO_ERRCODE, "GSS-API error sending token data"); return -1; } return 0; } -#endif /* #if defined(SYSLOG_INET) && defined(USE_GSSAPI) */ + +/* queryInterface function + * rgerhards, 2008-02-29 + */ +BEGINobjQueryInterface(gssutil) +CODESTARTobjQueryInterface(gssutil) + if(pIf->ifVersion != gssutilCURR_IF_VERSION) { /* check for current version, increment on each change */ + ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED); + } + + /* ok, we have the right interface, so let's fill it + * Please note that we may also do some backwards-compatibility + * work here (if we can support an older interface version - that, + * of course, also affects the "if" above). + */ + pIf->recv_token = recv_token; + pIf->send_token = send_token; + pIf->display_status = display_status; + pIf->display_ctx_flags = display_ctx_flags; + +finalize_it: +ENDobjQueryInterface(gssutil) + + +/* Initialize our class. Must be called as the very first method + * before anything else is called inside this class. + * rgerhards, 2008-02-29 + */ +BEGINAbstractObjClassInit(gssutil, 1, OBJ_IS_LOADABLE_MODULE) /* class, version - CHANGE class also in END MACRO! */ + /* request objects we use */ + CHKiRet(objUse(errmsg, CORE_COMPONENT)); +ENDObjClassInit(gssutil) + + +/* --------------- here now comes the plumbing that makes as a library module --------------- */ + + +BEGINmodExit +CODESTARTmodExit +ENDmodExit + + +BEGINqueryEtryPt +CODESTARTqueryEtryPt +CODEqueryEtryPt_STD_LIB_QUERIES +ENDqueryEtryPt + + +BEGINmodInit() +CODESTARTmodInit + *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ + + /* Initialize all classes that are in our module - this includes ourselfs */ + CHKiRet(gssutilClassInit()); /* must be done after tcps_sess, as we use it */ +ENDmodInit @@ -1,11 +1,42 @@ +/* Definitions for gssutil class. This implements a session of the + * plain TCP server. + * + * Copyright 2008 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ #ifndef GSS_MISC_H_INCLUDED #define GSS_MISC_H_INCLUDED 1 #include <gssapi/gssapi.h> +#include "obj.h" -int recv_token(int s, gss_buffer_t tok); -int send_token(int s, gss_buffer_t tok); -void display_status(char *m, OM_uint32 maj_stat, OM_uint32 min_stat); -void display_ctx_flags(OM_uint32 flags); +/* interfaces */ +BEGINinterface(gssutil) /* name must also be changed in ENDinterface macro! */ + int (*recv_token)(int s, gss_buffer_t tok); + int (*send_token)(int s, gss_buffer_t tok); + void (*display_status)(char *m, OM_uint32 maj_stat, OM_uint32 min_stat); + void (*display_ctx_flags)(OM_uint32 flags); +ENDinterface(gssutil) +#define gssutilCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */ + + +/* prototypes */ +PROTOTYPEObj(gssutil); #endif /* #ifndef GSS_MISC_H_INCLUDED */ @@ -41,13 +41,14 @@ #include "syslogd.h" #include "cfsysline.h" #include "modules.h" +#include "errmsg.h" /* static data */ DEFobjStaticHelpers +DEFobjCurrIf(errmsg) static modInfo_t *pLoadedModules = NULL; /* list of currently-loaded modules */ static modInfo_t *pLoadedModulesLast = NULL; /* tail-pointer */ -static int bCfsyslineInitialized = 0; /* config settings */ uchar *pModDir = NULL; /* read-only after startup */ @@ -224,12 +225,6 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)()), uchar * assert(modInit != NULL); - if(bCfsyslineInitialized == 0) { - /* we need to initialize the cfsysline subsystem first */ - CHKiRet(cfsyslineInit()); - bCfsyslineInitialized = 1; - } - if((iRet = moduleConstruct(&pNew)) != RS_RET_OK) { pNew = NULL; ABORT_FINALIZE(iRet); @@ -471,20 +466,20 @@ Load(uchar *pModName) if(!(pModHdlr = dlopen((char *) szPath, RTLD_NOW))) { snprintf((char *) errMsg, sizeof(errMsg), "could not load module '%s', dlopen: %s\n", szPath, dlerror()); errMsg[sizeof(errMsg)/sizeof(uchar) - 1] = '\0'; - logerror((char *) errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); ABORT_FINALIZE(RS_RET_ERR); } if(!(pModInit = dlsym(pModHdlr, "modInit"))) { snprintf((char *) errMsg, sizeof(errMsg), "could not load module '%s', dlsym: %s\n", szPath, dlerror()); errMsg[sizeof(errMsg)/sizeof(uchar) - 1] = '\0'; - logerror((char *) errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); dlclose(pModHdlr); ABORT_FINALIZE(RS_RET_ERR); } if((iRet = doModInit(pModInit, (uchar*) pModName, pModHdlr)) != RS_RET_OK) { snprintf((char *) errMsg, sizeof(errMsg), "could not load module '%s', rsyslog error %d\n", szPath, iRet); errMsg[sizeof(errMsg)/sizeof(uchar) - 1] = '\0'; - logerror((char *) errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); dlclose(pModHdlr); ABORT_FINALIZE(RS_RET_ERR); } @@ -527,6 +522,7 @@ ENDobjQueryInterface(module) */ BEGINAbstractObjClassInit(module, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANGE class also in END MACRO! */ /* request objects we use */ + CHKiRet(objUse(errmsg, CORE_COMPONENT)); ENDObjClassInit(module) /* vi:set ai: @@ -54,6 +54,12 @@ #include "net.h" #include "parse.h" #include "srUtils.h" +#include "obj.h" +#include "errmsg.h" + +/* static data */ +DEFobjCurrIf(obj) +DEFobjCurrIf(errmsg) /* support for defining allowed TCP and UDP senders. We use the same * structure to implement this (a linked list), but we define two different @@ -182,14 +188,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS /* we handle this seperatly just to provide a better * error message. */ - logerror("You can not specify 0 bits of the netmask, this would " + errmsg.LogError(NO_ERRCODE, "You can not specify 0 bits of the netmask, this would " "match ALL systems. If you really intend to do that, " "remove all $AllowedSender directives."); switch (iAllow->addr.NetAddr->sa_family) { case AF_INET: if((iSignificantBits < 1) || (iSignificantBits > 32)) { - logerrorInt("Invalid bit number in IPv4 address - adjusted to 32", + errmsg.LogError(NO_ERRCODE, "Invalid bit number in IPv4 address - adjusted to 32", (int)iSignificantBits); iSignificantBits = 32; } @@ -198,7 +204,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS break; case AF_INET6: if((iSignificantBits < 1) || (iSignificantBits > 128)) { - logerrorInt("Invalid bit number in IPv6 address - adjusted to 128", + errmsg.LogError(NO_ERRCODE, "Invalid bit number in IPv6 address - adjusted to 128", iSignificantBits); iSignificantBits = 128; } @@ -213,7 +219,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS * worst thing that happens is that one host will not be allowed to * log. */ - logerrorInt("Internal error caused AllowedSender to be ignored, AF = %d", + errmsg.LogError(NO_ERRCODE, "Internal error caused AllowedSender to be ignored, AF = %d", iAllow->addr.NetAddr->sa_family); ABORT_FINALIZE(RS_RET_ERR); } @@ -222,7 +228,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS } else { /* we need to process a hostname ACL */ if (DisableDNS) { - logerror ("Ignoring hostname based ACLs because DNS is disabled."); + errmsg.LogError(NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled."); ABORT_FINALIZE(RS_RET_OK); } @@ -243,14 +249,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS # endif if (getaddrinfo (iAllow->addr.HostWildcard, NULL, &hints, &res) != 0) { - logerrorSz("DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard); + errmsg.LogError(NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard); if (ACLAddHostnameOnFail) { - logerrorSz("Adding hostname \"%s\" to ACL as a wildcard entry.", iAllow->addr.HostWildcard); + errmsg.LogError(NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard entry.", iAllow->addr.HostWildcard); iRet = AddAllowedSenderEntry(ppRoot, ppLast, iAllow, iSignificantBits); FINALIZE; } else { - logerrorSz("Hostname \"%s\" WON\'T be added to ACL.", iAllow->addr.HostWildcard); + errmsg.LogError(NO_ERRCODE, "Hostname \"%s\" WON\'T be added to ACL.", iAllow->addr.HostWildcard); ABORT_FINALIZE(RS_RET_NOENTRY); } } @@ -410,7 +416,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) ppLast = &pLastAllowedSenders_GSS; #endif } else { - logerrorSz("Invalid protocol '%s' in allowed sender " + errmsg.LogError(NO_ERRCODE, "Invalid protocol '%s' in allowed sender " "list, line ignored", pName); return RS_RET_ERR; } @@ -421,7 +427,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) */ /* create parser object starting with line string without leading colon */ if((iRet = rsParsConstructFromSz(&pPars, (uchar*) *ppRestOfConfLine) != RS_RET_OK)) { - logerrorInt("Error %d constructing parser object - ignoring allowed sender list", iRet); + errmsg.LogError(NO_ERRCODE, "Error %d constructing parser object - ignoring allowed sender list", iRet); return(iRet); } @@ -430,7 +436,7 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) break; /* a comment-sign stops processing of line */ /* now parse a single IP address */ if((iRet = parsAddrWithBits(pPars, &uIP, &iBits)) != RS_RET_OK) { - logerrorInt("Error %d parsing address in allowed sender" + errmsg.LogError(NO_ERRCODE, "Error %d parsing address in allowed sender" "list - ignoring.", iRet); rsParsDestruct(pPars); return(iRet); @@ -438,10 +444,10 @@ rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine) if((iRet = AddAllowedSender(ppRoot, ppLast, uIP, iBits)) != RS_RET_OK) { if (iRet == RS_RET_NOENTRY) { - logerrorInt("Error %d adding allowed sender entry " + errmsg.LogError(NO_ERRCODE, "Error %d adding allowed sender entry " "- ignoring.", iRet); } else { - logerrorInt("Error %d adding allowed sender entry " + errmsg.LogError(NO_ERRCODE, "Error %d adding allowed sender entry " "- terminating, nothing more will be added.", iRet); rsParsDestruct(pPars); return(iRet); @@ -678,7 +684,7 @@ rsRetVal gethname(struct sockaddr_storage *f, uchar *pszHostFQDN) "Malicious PTR record, message dropped " "IP = \"%s\" HOST = \"%s\"", ip, pszHostFQDN); - logerror((char*)szErrMsg); + errmsg.LogError(NO_ERRCODE, "%s", szErrMsg); pthread_sigmask(SIG_SETMASK, &omask, NULL); ABORT_FINALIZE(RS_RET_MALICIOUS_ENTITY); } @@ -693,7 +699,7 @@ rsRetVal gethname(struct sockaddr_storage *f, uchar *pszHostFQDN) "Malicious PTR record (message accepted, but used IP " "instead of PTR name: IP = \"%s\" HOST = \"%s\"", ip, pszHostFQDN); - logerror((char*)szErrMsg); + errmsg.LogError(NO_ERRCODE, "%s", szErrMsg); error = 1; /* that will trigger using IP address below. */ } @@ -883,8 +889,8 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) hints.ai_socktype = SOCK_DGRAM; error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res); if(error) { - logerror((char*) gai_strerror(error)); - logerror("UDP message reception disabled due to error logged in last message.\n"); + errmsg.LogError(NO_ERRCODE, "%s", gai_strerror(error)); + errmsg.LogError(NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n"); return NULL; } @@ -893,7 +899,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) /* EMPTY */; socks = malloc((maxs+1) * sizeof(int)); if (socks == NULL) { - logerror("couldn't allocate memory for UDP sockets, suspending UDP message reception"); + errmsg.LogError(NO_ERRCODE, "couldn't allocate memory for UDP sockets, suspending UDP message reception"); freeaddrinfo(res); return NULL; } @@ -904,7 +910,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); if (*s < 0) { if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT)) - logerror("create_udp_socket(), socket"); + errmsg.LogError(NO_ERRCODE, "create_udp_socket(), socket"); /* it is debateble if PF_INET with EAFNOSUPPORT should * also be ignored... */ @@ -916,7 +922,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) int ion = 1; if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ion, sizeof (ion)) < 0) { - logerror("setsockopt"); + errmsg.LogError(NO_ERRCODE, "setsockopt"); close(*s); *s = -1; continue; @@ -933,7 +939,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) */ if (setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) { - logerror("setsockopt(REUSEADDR)"); + errmsg.LogError(NO_ERRCODE, "setsockopt(REUSEADDR)"); close(*s); *s = -1; continue; @@ -946,7 +952,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) if (should_use_so_bsdcompat()) { if (setsockopt(*s, SOL_SOCKET, SO_BSDCOMPAT, (char *) &on, sizeof(on)) < 0) { - logerror("setsockopt(BSDCOMPAT)"); + errmsg.LogError(NO_ERRCODE, "setsockopt(BSDCOMPAT)"); close(*s); *s = -1; continue; @@ -968,7 +974,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) sockflags = fcntl(*s, F_SETFL, sockflags); } if (sockflags == -1) { - logerror("fcntl(O_NONBLOCK)"); + errmsg.LogError(NO_ERRCODE, "fcntl(O_NONBLOCK)"); close(*s); *s = -1; continue; @@ -987,7 +993,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) && (errno != EADDRINUSE) # endif ) { - logerror("bind"); + errmsg.LogError(NO_ERRCODE, "bind"); close(*s); *s = -1; continue; @@ -1006,7 +1012,7 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) "- this may or may not be an error indication.\n", *socks, maxs); if(*socks == 0) { - logerror("No UDP listen socket could successfully be initialized, " + errmsg.LogError(NO_ERRCODE, "No UDP listen socket could successfully be initialized, " "message reception via UDP disabled.\n"); /* we do NOT need to free any sockets, because there were none... */ free(socks); @@ -1016,6 +1022,19 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer) return(socks); } + +/* our init function. TODO: remove once converted to a class + */ +rsRetVal NetInit() +{ + DEFiRet; + CHKiRet(objGetObjInterface(&obj)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); + +finalize_it: + RETiRet; +} + #endif /* #ifdef SYSLOG_INET */ /* * vi:set ai: @@ -84,11 +84,13 @@ #include "obj.h" #include "stream.h" #include "modules.h" +#include "errmsg.h" /* static data */ DEFobjCurrIf(obj) /* we define our own interface, as this is expected by some macros! */ DEFobjCurrIf(var) DEFobjCurrIf(module) +DEFobjCurrIf(errmsg) static objInfo_t *arrObjInfo[OBJ_NUM_IDS]; /* array with object information pointers */ @@ -1036,7 +1038,8 @@ RegisterObj(uchar *pszObjName, objInfo_t *pInfo) finalize_it: if(iRet != RS_RET_OK) { - logerrorVar("registering object '%s' failed with error code %d", pszObjName, iRet); +RUNLOG_VAR("%p", errmsg.LogError); + errmsg.LogError(NO_ERRCODE, "registering object '%s' failed with error code %d", pszObjName, iRet); } RETiRet; @@ -1154,10 +1157,16 @@ objClassInit(void) CHKiRet(objGetObjInterface(&obj)); /* get ourselves ;) */ /* init classes we use (limit to as few as possible!) */ +RUNLOG_VAR("%p", errmsg.LogError); + CHKiRet(errmsgClassInit()); + CHKiRet(cfsyslineInit()); CHKiRet(varClassInit()); CHKiRet(moduleClassInit()); CHKiRet(objUse(var, CORE_COMPONENT)); CHKiRet(objUse(module, CORE_COMPONENT)); +RUNLOG_VAR("%p", errmsg.LogError); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); +RUNLOG_VAR("%p", errmsg.LogError); finalize_it: RETiRet; @@ -52,12 +52,14 @@ #include "omfile.h" #include "cfsysline.h" #include "module-template.h" +#include "errmsg.h" MODULE_TYPE_OUTPUT /* internal structures */ DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) /* The following structure is a dynafile name cache entry. */ @@ -157,14 +159,14 @@ rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal) snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar), "DynaFileCacheSize must be greater 0 (%d given), changed to 1.", iNewVal); errno = 0; - logerror((char*) errMsg); + errmsg.LogError(NO_ERRCODE, "%s", 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); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); iRet = RS_RET_VAL_OUT_OF_RANGE; iNewVal = 10000; } @@ -217,7 +219,7 @@ static rsRetVal cflineParseOutchannel(instanceData *pData, uchar* p, omodStringR snprintf(errMsg, sizeof(errMsg)/sizeof(char), "outchannel '%s' not found - ignoring action line", szBuf); - logerror(errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); ABORT_FINALIZE(RS_RET_NOT_FOUND); } @@ -228,7 +230,7 @@ static rsRetVal cflineParseOutchannel(instanceData *pData, uchar* p, omodStringR snprintf(errMsg, sizeof(errMsg)/sizeof(char), "outchannel '%s' has no file name template - ignoring action line", szBuf); - logerror(errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); ABORT_FINALIZE(RS_RET_ERR); } @@ -492,7 +494,7 @@ static int prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsg if(iMsgOpts & INTERNAL_MSG) dbgprintf("Could not open dynaFile, discarding message\n"); else - logerrorSz("Could not open dynamic file '%s' - discarding message", (char*)newFileName); + errmsg.LogError(NO_ERRCODE, "Could not open dynamic file '%s' - discarding message", (char*)newFileName); dynaFileDelCacheEntry(pCache, iFirstFree, 1); pData->iCurrElt = -1; return -1; @@ -549,14 +551,14 @@ again: "no longer writing to file %s; grown beyond configured file size of %lld bytes, actual size %lld - configured command did not resolve situation", pData->f_fname, (long long) pData->f_sizeLimit, (long long) actualFileSize); errno = 0; - logerror(errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); ABORT_FINALIZE(RS_RET_DISABLE_ACTION); } else { snprintf(errMsg, sizeof(errMsg), "file %s had grown beyond configured file size of %lld bytes, actual size was %lld - configured command resolved situation", pData->f_fname, (long long) pData->f_sizeLimit, (long long) actualFileSize); errno = 0; - logerror(errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); } } } @@ -590,7 +592,7 @@ again: pData->fd = open((char*) pData->f_fname, O_WRONLY|O_APPEND|O_NOCTTY); if (pData->fd < 0) { iRet = RS_RET_DISABLE_ACTION; - logerror((char*) pData->f_fname); + errmsg.LogError(NO_ERRCODE, "%s", pData->f_fname); } else { untty(); goto again; @@ -598,7 +600,7 @@ again: } else { iRet = RS_RET_DISABLE_ACTION; errno = e; - logerror((char*) pData->f_fname); + errmsg.LogError(NO_ERRCODE, "%s", pData->f_fname); } } else if (pData->bSyncFile) fsync(pData->fd); @@ -763,7 +765,7 @@ CODESTARTparseSelectorAct if ( pData->fd < 0 ){ pData->fd = -1; dbgprintf("Error opening log file: %s\n", pData->f_fname); - logerror((char*) pData->f_fname); + errmsg.LogError(NO_ERRCODE, "%s", pData->f_fname); break; } if (isatty(pData->fd)) { @@ -815,6 +817,7 @@ BEGINmodInit(File) CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dynafilecachesize", 0, eCmdHdlrInt, (void*) setDynaFileCacheSize, NULL, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirowner", 0, eCmdHdlrUID, NULL, &dirUID, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dirgroup", 0, eCmdHdlrGID, NULL, &dirGID, STD_LOADABLE_MODULE_ID)); @@ -58,6 +58,7 @@ #include "tcpsyslog.h" #include "cfsysline.h" #include "module-template.h" +#include "errmsg.h" MODULE_TYPE_OUTPUT @@ -81,6 +82,7 @@ MODULE_TYPE_OUTPUT /* internal structures */ DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) typedef struct _instanceData { char f_hname[MAXHOSTNAMELEN+1]; @@ -480,12 +482,12 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) ++p; /* eat */ pData->compressionLevel = iLevel; } else { - logerrorInt("Invalid compression level '%c' specified in " + errmsg.LogError(NO_ERRCODE, "Invalid compression level '%c' specified in " "forwardig action - NOT turning on compression.", *p); } # else - logerror("Compression requested, but rsyslogd is not compiled " + errmsg.LogError(NO_ERRCODE, "Compression requested, but rsyslogd is not compiled " "with compression support - request ignored."); # endif /* #ifdef USE_NETZIP */ } else if(*p == 'o') { /* octet-couting based TCP framing? */ @@ -493,7 +495,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* no further options settable */ pData->tcp_framing = TCP_FRAMING_OCTET_COUNTING; } else { /* invalid option! Just skip it... */ - logerrorInt("Invalid option %c in forwarding action - ignoring.", *p); + errmsg.LogError(NO_ERRCODE, "Invalid option %c in forwarding action - ignoring.", *p); ++p; /* eat invalid option */ } /* the option processing is done. We now do a generic skip @@ -509,7 +511,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* we probably have end of string - leave it for the rest * of the code to handle it (but warn the user) */ - logerror("Option block not terminated in forwarding action."); + errmsg.LogError(NO_ERRCODE, "Option block not terminated in forwarding action."); } /* extract the host first (we do a trick - we replace the ';' or ':' with a '\0') * now skip to port and then template name. rgerhards 2005-07-06 @@ -527,7 +529,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* SKIP AND COUNT */; pData->port = malloc(i + 1); if(pData->port == NULL) { - logerror("Could not get memory to store syslog forwarding port, " + errmsg.LogError(NO_ERRCODE, "Could not get memory to store syslog forwarding port, " "using default port, results may not be what you intend\n"); /* we leave f_forw.port set to NULL, this is then handled by * getFwdSyslogPt(). @@ -545,7 +547,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) if(bErr == 0) { /* only 1 error msg! */ bErr = 1; errno = 0; - logerror("invalid selector line (port), probably not doing " + errmsg.LogError(NO_ERRCODE, "invalid selector line (port), probably not doing " "what was intended"); } } @@ -618,6 +620,7 @@ BEGINmodInit(Fwd) CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); ENDmodInit #endif /* #ifdef SYSLOG_INET */ @@ -43,12 +43,14 @@ #include "srUtils.h" #include "omshell.h" #include "module-template.h" +#include "errmsg.h" MODULE_TYPE_OUTPUT /* internal structures */ DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) typedef struct _instanceData { uchar progName[MAXFNAME]; /* program to execute */ @@ -90,7 +92,7 @@ CODESTARTdoAction */ dbgprintf("\n"); if(execProg((uchar*) pData->progName, 1, ppString[0]) == 0) - logerrorSz("Executing program '%s' failed", (char*)pData->progName); + errmsg.LogError(NO_ERRCODE, "Executing program '%s' failed", (char*)pData->progName); ENDdoAction @@ -142,6 +144,7 @@ BEGINmodInit(Shell) CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); ENDmodInit /* diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c index ef452bc5..aa866a6d 100644 --- a/plugins/imfile/imfile.c +++ b/plugins/imfile/imfile.c @@ -39,6 +39,7 @@ #include "srUtils.h" /* some utility functions */ #include "msg.h" #include "stream.h" +#include "errmsg.h" MODULE_TYPE_INPUT /* must be present for input modules, do not remove */ @@ -46,6 +47,7 @@ MODULE_TYPE_INPUT /* must be present for input modules, do not remove */ /* Module static data */ DEF_IMOD_STATIC_DATA /* must be present, starts static data */ +DEFobjCurrIf(errmsg) typedef struct fileInfo_s { uchar *pszFileName; @@ -278,7 +280,7 @@ ENDrunInput BEGINwillRun CODESTARTwillRun if(iFilPtr == 0) { - logerror("No files configured to be monitored"); + errmsg.LogError(NO_ERRCODE, "No files configured to be monitored"); ABORT_FINALIZE(RS_RET_NO_RUN); } @@ -398,21 +400,21 @@ static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar __attribute pThis = &files[iFilPtr]; /* TODO: check for strdup() NULL return */ if(pszFileName == NULL) { - logerror("imfile error: no file name given, file monitor can not be created"); + errmsg.LogError(NO_ERRCODE, "imfile error: no file name given, file monitor can not be created"); ABORT_FINALIZE(RS_RET_CONFIG_ERROR); } else { pThis->pszFileName = (uchar*) strdup((char*) pszFileName); } if(pszFileTag == NULL) { - logerror("imfile error: no tag value given , file monitor can not be created"); + errmsg.LogError(NO_ERRCODE, "imfile error: no tag value given , file monitor can not be created"); ABORT_FINALIZE(RS_RET_CONFIG_ERROR); } else { pThis->pszTag = (uchar*) strdup((char*) pszFileTag); } if(pszStateFile == NULL) { - logerror("imfile error: not state file name given, file monitor can not be created"); + errmsg.LogError(NO_ERRCODE, "imfile error: not state file name given, file monitor can not be created"); ABORT_FINALIZE(RS_RET_CONFIG_ERROR); } else { pThis->pszStateFile = (uchar*) strdup((char*) pszStateFile); @@ -421,7 +423,7 @@ static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar __attribute pThis->iSeverity = iSeverity; pThis->iFacility = iFacility; } else { - logerror("Too many file monitors configured - ignoring this one"); + errmsg.LogError(NO_ERRCODE, "Too many file monitors configured - ignoring this one"); ABORT_FINALIZE(RS_RET_OUT_OF_DESRIPTORS); } @@ -447,6 +449,7 @@ BEGINmodInit() CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilename", 0, eCmdHdlrGetWord, NULL, &pszFileName, STD_LOADABLE_MODULE_ID)); diff --git a/plugins/imgssapi/Makefile.am b/plugins/imgssapi/Makefile.am index 6c2d6625..33f2d32d 100644 --- a/plugins/imgssapi/Makefile.am +++ b/plugins/imgssapi/Makefile.am @@ -3,4 +3,4 @@ pkglib_LTLIBRARIES = imgssapi.la imgssapi_la_SOURCES = imgssapi.c imgssapi_la_CPPFLAGS = -I$(top_srcdir) $(pthreads_cflags) $(mudflap_cflags) imgssapi_la_LDFLAGS = $(mudflap_libs) -module -avoid-version -imgssapi_la_LIBADD = $(gss_libs) $(top_builddir)/libgssapi-misc.la +imgssapi_la_LIBADD = $(gss_libs) diff --git a/plugins/imgssapi/imgssapi.c b/plugins/imgssapi/imgssapi.c index d93799f3..fb80f3e2 100644 --- a/plugins/imgssapi/imgssapi.c +++ b/plugins/imgssapi/imgssapi.c @@ -28,7 +28,6 @@ * * A copy of the GPL can be found in the file "COPYING" in this distribution. */ - #include "config.h" #include <stdlib.h> #include <assert.h> @@ -54,6 +53,7 @@ #include "gss-misc.h" #include "tcpsrv.h" #include "tcps_sess.h" +#include "errmsg.h" MODULE_TYPE_INPUT @@ -75,6 +75,8 @@ static rsRetVal OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd); DEF_IMOD_STATIC_DATA DEFobjCurrIf(tcpsrv) DEFobjCurrIf(tcps_sess) +DEFobjCurrIf(gssutil) +DEFobjCurrIf(errmsg) static tcpsrv_t *pOurTcpsrv = NULL; /* our TCP server(listener) TODO: change for multiple instances */ static gss_cred_id_t gss_server_creds = GSS_C_NO_CREDENTIAL; @@ -143,7 +145,7 @@ OnSessDestruct(void *ppUsr) OM_uint32 maj_stat, min_stat; maj_stat = gss_delete_sec_context(&min_stat, &(*ppGSess)->gss_context, GSS_C_NO_BUFFER); if (maj_stat != GSS_S_COMPLETE) - display_status("deleting context", maj_stat, min_stat); + gssutil.display_status("deleting context", maj_stat, min_stat); } free(*ppGSess); @@ -258,7 +260,7 @@ doOpenLstnSocks(tcpsrv_t *pSrv) if(pGSrv->allowedMethods) { if(pGSrv->allowedMethods & ALLOWEDMETHOD_GSS) { if(TCPSessGSSInit()) { - logerror("GSS-API initialization failed\n"); + errmsg.LogError(NO_ERRCODE, "GSS-API initialization failed\n"); pGSrv->allowedMethods &= ~(ALLOWEDMETHOD_GSS); } } @@ -345,7 +347,7 @@ static int TCPSessGSSInit(void) name_buf.length = strlen(name_buf.value) + 1; maj_stat = gss_import_name(&min_stat, &name_buf, GSS_C_NT_HOSTBASED_SERVICE, &server_name); if (maj_stat != GSS_S_COMPLETE) { - display_status("importing name", maj_stat, min_stat); + gssutil.display_status("importing name", maj_stat, min_stat); return -1; } @@ -353,7 +355,7 @@ static int TCPSessGSSInit(void) GSS_C_NULL_OID_SET, GSS_C_ACCEPT, &gss_server_creds, NULL, NULL); if (maj_stat != GSS_S_COMPLETE) { - display_status("acquiring credentials", maj_stat, min_stat); + gssutil.display_status("acquiring credentials", maj_stat, min_stat); return -1; } @@ -413,7 +415,7 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) ret = select(fdSess + 1, &fds, NULL, NULL, &tv); } while (ret < 0 && errno == EINTR); if (ret < 0) { - logerrorVar("TCP session %p will be closed, error ignored\n", pSess); + errmsg.LogError(NO_ERRCODE, "TCP session %p will be closed, error ignored\n", pSess); tcps_sess.Close(pSess); ABORT_FINALIZE(RS_RET_ERR); // TODO: define good error codes // was: return -1; @@ -431,7 +433,7 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) if (ret == 0) dbgprintf("GSS-API Connection closed by peer\n"); else - logerrorVar("TCP(GSS) session %p will be closed, error ignored\n", pSess); + errmsg.LogError(NO_ERRCODE, "TCP(GSS) session %p will be closed, error ignored\n", pSess); tcps_sess.Close(pSess); ABORT_FINALIZE(RS_RET_ERR); // TODO: define good error codes // was: return -1; @@ -454,7 +456,7 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) if (ret == 0) dbgprintf("GSS-API Connection closed by peer\n"); else - logerrorVar("TCP session %p will be closed, error ignored\n", pSess); + errmsg.LogError(NO_ERRCODE, "TCP session %p will be closed, error ignored\n", pSess); tcps_sess.Close(pSess); ABORT_FINALIZE(RS_RET_ERR); // TODO: define good error codes //was: return -1; @@ -478,8 +480,8 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) *context = GSS_C_NO_CONTEXT; sess_flags = &pGSess->gss_flags; do { - if (recv_token(fdSess, &recv_tok) <= 0) { - logerrorVar("TCP session %p will be closed, error ignored\n", pSess); + if (gssutil.recv_token(fdSess, &recv_tok) <= 0) { + errmsg.LogError(NO_ERRCODE, "TCP session %p will be closed, error ignored\n", pSess); tcps_sess.Close(pSess); ABORT_FINALIZE(RS_RET_ERR); // TODO: define good error codes //was: return -1; @@ -500,7 +502,7 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) dbgprintf("GSS-API Reverting to plain TCP\n"); dbgprintf("tcp session socket with new data: #%d\n", fdSess); if(tcps_sess.DataRcvd(pSess, buf, ret) == 0) { - logerrorVar("Tearing down TCP Session %p - see " + errmsg.LogError(NO_ERRCODE, "Tearing down TCP Session %p - see " "previous messages for reason(s)\n", pSess); tcps_sess.Close(pSess); @@ -511,15 +513,15 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) ABORT_FINALIZE(RS_RET_OK); // TODO: define good error codes // was: return 0; } - display_status("accepting context", maj_stat, acc_sec_min_stat); + gssutil.display_status("accepting context", maj_stat, acc_sec_min_stat); tcps_sess.Close(pSess); ABORT_FINALIZE(RS_RET_ERR); // TODO: define good error codes //was: return -1; } if (send_tok.length != 0) { - if (send_token(fdSess, &send_tok) < 0) { + if(gssutil.send_token(fdSess, &send_tok) < 0) { gss_release_buffer(&min_stat, &send_tok); - logerrorVar("TCP session %p will be closed, error ignored\n", pSess); + errmsg.LogError(NO_ERRCODE, "TCP session %p will be closed, error ignored\n", pSess); if (*context != GSS_C_NO_CONTEXT) gss_delete_sec_context(&min_stat, context, GSS_C_NO_BUFFER); tcps_sess.Close(pSess); @@ -532,14 +534,14 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) maj_stat = gss_display_name(&min_stat, client, &recv_tok, NULL); if (maj_stat != GSS_S_COMPLETE) - display_status("displaying name", maj_stat, min_stat); + gssutil.display_status("displaying name", maj_stat, min_stat); else dbgprintf("GSS-API Accepted connection from: %s\n", (char*) recv_tok.value); gss_release_name(&min_stat, &client); gss_release_buffer(&min_stat, &recv_tok); dbgprintf("GSS-API Provided context flags:\n"); - display_ctx_flags(*sess_flags); + gssutil.display_ctx_flags(*sess_flags); pGSess->allowedMethods = ALLOWEDMETHOD_GSS; } @@ -567,14 +569,14 @@ int TCPSessGSSRecv(tcps_sess_t *pSess, void *buf, size_t buf_len) pGSess = (gss_sess_t*) pSess->pUsr; fdSess = pSess->sock; - if ((state = recv_token(fdSess, &xmit_buf)) <= 0) + if ((state = gssutil.recv_token(fdSess, &xmit_buf)) <= 0) return state; context = &pGSess->gss_context; maj_stat = gss_unwrap(&min_stat, *context, &xmit_buf, &msg_buf, &conf_state, (gss_qop_t *) NULL); if(maj_stat != GSS_S_COMPLETE) { - display_status("unsealing message", maj_stat, min_stat); + gssutil.display_status("unsealing message", maj_stat, min_stat); if(xmit_buf.value) { free(xmit_buf.value); xmit_buf.value = 0; @@ -609,7 +611,7 @@ void TCPSessGSSClose(tcps_sess_t* pSess) context = &pGSess->gss_context; maj_stat = gss_delete_sec_context(&min_stat, context, GSS_C_NO_BUFFER); if (maj_stat != GSS_S_COMPLETE) - display_status("deleting context", maj_stat, min_stat); + gssutil.display_status("deleting context", maj_stat, min_stat); *context = GSS_C_NO_CONTEXT; pGSess->gss_flags = 0; pGSess->allowedMethods = 0; @@ -629,7 +631,7 @@ TCPSessGSSDeinit(void) maj_stat = gss_release_cred(&min_stat, &gss_server_creds); if (maj_stat != GSS_S_COMPLETE) - display_status("releasing credentials", maj_stat, min_stat); + gssutil.display_status("releasing credentials", maj_stat, min_stat); RETiRet; } @@ -702,6 +704,8 @@ CODEmodInit_QueryRegCFSLineHdlr /* request objects we use */ CHKiRet(objUse(tcps_sess, "tcpsrv.so")); CHKiRet(objUse(tcpsrv, "tcpsrv")); + CHKiRet(objUse(gssutil, "gssutil")); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); /* register config file handlers */ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverpermitplaintcp", 0, eCmdHdlrBinary, diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c index df497632..70a7b3f7 100644 --- a/plugins/imudp/imudp.c +++ b/plugins/imudp/imudp.c @@ -38,6 +38,7 @@ #include "cfsysline.h" #include "module-template.h" #include "srUtils.h" +#include "errmsg.h" MODULE_TYPE_INPUT @@ -45,6 +46,7 @@ MODULE_TYPE_INPUT /* Module static data */ DEF_IMOD_STATIC_DATA +DEFobjCurrIf(errmsg) static int *udpLstnSocks = NULL; /* Internet datagram sockets, first element is nbr of elements * read-only after init(), but beware of restart! */ static uchar *pszBindAddr = NULL; /* IP to bind socket to */ @@ -191,7 +193,7 @@ CODESTARTrunInput } else { dbgprintf("%s is not an allowed sender\n", (char*)fromHostFQDN); if(option_DisallowWarning) { - logerrorSz("UDP message from disallowed sender %s discarded", + errmsg.LogError(NO_ERRCODE, "UDP message from disallowed sender %s discarded", (char*)fromHost); } } @@ -200,7 +202,7 @@ CODESTARTrunInput char errStr[1024]; rs_strerror_r(errno, errStr, sizeof(errStr)); dbgprintf("INET socket error: %d = %s.\n", errno, errStr); - logerror("recvfrom inet"); + errmsg.LogError(NO_ERRCODE, "recvfrom inet"); /* should be harmless */ sleep(1); } @@ -272,6 +274,8 @@ BEGINmodInit() CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); + /* register config file handlers */ CHKiRet(omsdRegCFSLineHdlr((uchar *)"udpserverrun", 0, eCmdHdlrGetWord, addListner, NULL, STD_LOADABLE_MODULE_ID)); diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c index 1be2e66f..68978231 100644 --- a/plugins/imuxsock/imuxsock.c +++ b/plugins/imuxsock/imuxsock.c @@ -39,6 +39,7 @@ #include "cfsysline.h" #include "module-template.h" #include "srUtils.h" +#include "errmsg.h" MODULE_TYPE_INPUT @@ -60,6 +61,7 @@ MODULE_TYPE_INPUT #endif /* Module static data */ DEF_IMOD_STATIC_DATA +DEFobjCurrIf(errmsg) static int startIndexUxLocalSockets; /* process funix from that index on (used to * suppress local logging. rgerhards 2005-08-01 @@ -142,7 +144,7 @@ static int create_unix_socket(const char *path) SUN_LEN(&sunx)) < 0 || chmod(path, 0666) < 0) { snprintf(line, sizeof(line), "cannot create %s", path); - logerror(line); + errmsg.LogError(NO_ERRCODE, "%s", line); dbgprintf("cannot create %s (%d).\n", path, errno); close(fd); return -1; @@ -169,7 +171,7 @@ static rsRetVal readSocket(int fd, int bParseHost) char errStr[1024]; rs_strerror_r(errno, errStr, sizeof(errStr)); dbgprintf("UNIX socket error: %d = %s.\n", errno, errStr); - logerror("recvfrom UNIX"); + errmsg.LogError(NO_ERRCODE, "recvfrom UNIX"); } RETiRet; @@ -300,6 +302,8 @@ BEGINmodInit() CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); + /* initialize funixn[] array */ for(i = 1 ; i < MAXFUNIX ; ++i) { funixn[i] = NULL; diff --git a/plugins/omgssapi/Makefile.am b/plugins/omgssapi/Makefile.am index 3557388c..3ec18282 100644 --- a/plugins/omgssapi/Makefile.am +++ b/plugins/omgssapi/Makefile.am @@ -3,4 +3,4 @@ pkglib_LTLIBRARIES = omgssapi.la omgssapi_la_SOURCES = omgssapi.c omgssapi_la_CPPFLAGS = -I$(top_srcdir) $(pthreads_cflags) $(mudflap_cflags) omgssapi_la_LDFLAGS = $(mudflap_libs) -module -avoid-version -omgssapi_la_LIBADD = $(gss_libs) $(top_builddir)/libgssapi-misc.la +omgssapi_la_LIBADD = $(gss_libs) diff --git a/plugins/omgssapi/omgssapi.c b/plugins/omgssapi/omgssapi.c index 8ca2f879..bb4a2712 100644 --- a/plugins/omgssapi/omgssapi.c +++ b/plugins/omgssapi/omgssapi.c @@ -54,6 +54,7 @@ #include "cfsysline.h" #include "module-template.h" #include "gss-misc.h" +#include "errmsg.h" MODULE_TYPE_OUTPUT @@ -75,6 +76,8 @@ MODULE_TYPE_OUTPUT /* internal structures */ DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) +DEFobjCurrIf(gssutil) typedef struct _instanceData { char f_hname[MAXHOSTNAMELEN+1]; @@ -144,7 +147,7 @@ CODESTARTfreeInstance if (pData->gss_context != GSS_C_NO_CONTEXT) { maj_stat = gss_delete_sec_context(&min_stat, &pData->gss_context, GSS_C_NO_BUFFER); if (maj_stat != GSS_S_COMPLETE) - display_status("deleting context", maj_stat, min_stat); + gssutil.display_status("deleting context", maj_stat, min_stat); } /* this is meant to be done when module is unloaded, but since this module is static... @@ -217,7 +220,7 @@ static rsRetVal TCPSendGSSInit(void *pvData) out_tok.length = 0; if (maj_stat != GSS_S_COMPLETE) { - display_status("parsing name", maj_stat, min_stat); + gssutil.display_status("parsing name", maj_stat, min_stat); goto fail; } @@ -230,7 +233,7 @@ static rsRetVal TCPSendGSSInit(void *pvData) *sess_flags |= GSS_C_CONF_FLAG; } dbgprintf("GSS-API requested context flags:\n"); - display_ctx_flags(*sess_flags); + gssutil.display_ctx_flags(*sess_flags); do { maj_stat = gss_init_sec_context(&init_sec_min_stat, GSS_C_NO_CREDENTIAL, context, @@ -241,7 +244,7 @@ static rsRetVal TCPSendGSSInit(void *pvData) if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED) { - display_status("initializing context", maj_stat, init_sec_min_stat); + gssutil.display_status("initializing context", maj_stat, init_sec_min_stat); goto fail; } @@ -251,7 +254,7 @@ static rsRetVal TCPSendGSSInit(void *pvData) if (out_tok.length != 0) { dbgprintf("GSS-API Sending init_sec_context token (length: %ld)\n", (long) out_tok.length); - if (send_token(s, &out_tok) < 0) { + if (gssutil.send_token(s, &out_tok) < 0) { goto fail; } } @@ -259,7 +262,7 @@ static rsRetVal TCPSendGSSInit(void *pvData) if (maj_stat == GSS_S_CONTINUE_NEEDED) { dbgprintf("GSS-API Continue needed...\n"); - if (recv_token(s, &in_tok) <= 0) { + if (gssutil.recv_token(s, &in_tok) <= 0) { goto fail; } tok_ptr = &in_tok; @@ -268,7 +271,7 @@ static rsRetVal TCPSendGSSInit(void *pvData) dbgprintf("GSS-API Provided context flags:\n"); *sess_flags = ret_flags; - display_ctx_flags(*sess_flags); + gssutil.display_ctx_flags(*sess_flags); dbgprintf("GSS-API Context initialized\n"); gss_release_name(&min_stat, &target_name); @@ -277,7 +280,7 @@ finalize_it: RETiRet; fail: - logerror("GSS-API Context initialization failed\n"); + errmsg.LogError(NO_ERRCODE, "GSS-API Context initialization failed\n"); gss_release_name(&min_stat, &target_name); gss_release_buffer(&min_stat, &out_tok); if (*context != GSS_C_NO_CONTEXT) { @@ -310,11 +313,11 @@ static rsRetVal TCPSendGSSSend(void *pvData, char *msg, size_t len) maj_stat = gss_wrap(&min_stat, *context, (gss_mode == GSSMODE_ENC) ? 1 : 0, GSS_C_QOP_DEFAULT, &in_buf, NULL, &out_buf); if (maj_stat != GSS_S_COMPLETE) { - display_status("wrapping message", maj_stat, min_stat); + gssutil.display_status("wrapping message", maj_stat, min_stat); goto fail; } - if (send_token(s, &out_buf) < 0) { + if (gssutil.send_token(s, &out_buf) < 0) { goto fail; } gss_release_buffer(&min_stat, &out_buf); @@ -511,12 +514,12 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) ++p; /* eat */ pData->compressionLevel = iLevel; } else { - logerrorInt("Invalid compression level '%c' specified in " + errmsg.LogError(NO_ERRCODE, "Invalid compression level '%c' specified in " "forwardig action - NOT turning on compression.", *p); } # else - logerror("Compression requested, but rsyslogd is not compiled " + errmsg.LogError(NO_ERRCODE, "Compression requested, but rsyslogd is not compiled " "with compression support - request ignored."); # endif /* #ifdef USE_NETZIP */ } else if(*p == 'o') { /* octet-couting based TCP framing? */ @@ -524,7 +527,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* no further options settable */ pData->tcp_framing = TCP_FRAMING_OCTET_COUNTING; } else { /* invalid option! Just skip it... */ - logerrorInt("Invalid option %c in forwarding action - ignoring.", *p); + errmsg.LogError(NO_ERRCODE, "Invalid option %c in forwarding action - ignoring.", *p); ++p; /* eat invalid option */ } /* the option processing is done. We now do a generic skip @@ -540,7 +543,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* we probably have end of string - leave it for the rest * of the code to handle it (but warn the user) */ - logerror("Option block not terminated in gssapi forward action."); + errmsg.LogError(NO_ERRCODE, "Option block not terminated in gssapi forward action."); } /* extract the host first (we do a trick - we replace the ';' or ':' with a '\0') * now skip to port and then template name. rgerhards 2005-07-06 @@ -558,7 +561,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) /* SKIP AND COUNT */; pData->port = malloc(i + 1); if(pData->port == NULL) { - logerror("Could not get memory to store syslog forwarding port, " + errmsg.LogError(NO_ERRCODE, "Could not get memory to store syslog forwarding port, " "using default port, results may not be what you intend\n"); /* we leave f_forw.port set to NULL, this is then handled by * getFwdSyslogPt(). @@ -576,7 +579,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1) if(bErr == 0) { /* only 1 error msg! */ bErr = 1; errno = 0; - logerror("invalid selector line (port), probably not doing " + errmsg.LogError(NO_ERRCODE, "invalid selector line (port), probably not doing " "what was intended"); } } @@ -647,7 +650,7 @@ static rsRetVal setGSSMode(void __attribute__((unused)) *pVal, uchar *mode) gss_mode = GSSMODE_ENC; dbgprintf("GSS-API gssmode set to GSSMODE_ENC\n"); } else { - logerrorSz("unknown gssmode parameter: %s", (char *) mode); + errmsg.LogError(NO_ERRCODE, "unknown gssmode parameter: %s", (char *) mode); iRet = RS_RET_INVALID_PARAMS; } free(mode); @@ -671,6 +674,9 @@ BEGINmodInit() CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); + CHKiRet(objUse(gssutil, "gssutil")); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"gssforwardservicename", 0, eCmdHdlrGetWord, NULL, &gss_base_service_name, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"gssmode", 0, eCmdHdlrGetWord, setGSSMode, &gss_mode, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); diff --git a/plugins/omsnmp/omsnmp.c b/plugins/omsnmp/omsnmp.c index 618a3f10..d7c8950c 100644 --- a/plugins/omsnmp/omsnmp.c +++ b/plugins/omsnmp/omsnmp.c @@ -44,12 +44,14 @@ #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include "omsnmp.h" +#include "errmsg.h" MODULE_TYPE_OUTPUT /* internal structures */ DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) /* Default static snmp OID's */ /*unused @@ -175,7 +177,7 @@ static rsRetVal omsnmp_initSession(instanceData *pData) pData->snmpsession = snmp_open(&session); if (pData->snmpsession == NULL) { - logerrorVar("omsnmp_initSession: snmp_open to host '%s' on Port '%d' failed\n", pData->szTarget, pData->iPort); + errmsg.LogError(NO_ERRCODE, "omsnmp_initSession: snmp_open to host '%s' on Port '%d' failed\n", pData->szTarget, pData->iPort); /* Stay suspended */ iRet = RS_RET_SUSPENDED; } @@ -214,7 +216,7 @@ static rsRetVal omsnmp_sendsnmp(instanceData *pData, uchar *psz) if (!snmp_parse_oid( (char*) pData->szEnterpriseOID, enterpriseoid, &enterpriseoidlen )) { strErr = snmp_api_errstring(snmp_errno); - logerrorVar("omsnmp_sendsnmp: Parsing EnterpriseOID failed '%s' with error '%s' \n", pData->szSyslogMessageOID, strErr); + errmsg.LogError(NO_ERRCODE, "omsnmp_sendsnmp: Parsing EnterpriseOID failed '%s' with error '%s' \n", pData->szSyslogMessageOID, strErr); ABORT_FINALIZE(RS_RET_DISABLE_ACTION); } @@ -250,7 +252,7 @@ static rsRetVal omsnmp_sendsnmp(instanceData *pData, uchar *psz) if ( snmp_add_var(pdu, objid_snmptrap, sizeof(objid_snmptrap) / sizeof(oid), 'o', (char*) pData->szSnmpTrapOID ) != 0) { strErr = snmp_api_errstring(snmp_errno); - logerrorVar("omsnmp_sendsnmp: Adding trap OID failed '%s' with error '%s' \n", pData->szSnmpTrapOID, strErr); + errmsg.LogError(NO_ERRCODE, "omsnmp_sendsnmp: Adding trap OID failed '%s' with error '%s' \n", pData->szSnmpTrapOID, strErr); ABORT_FINALIZE(RS_RET_DISABLE_ACTION); } } @@ -265,14 +267,14 @@ static rsRetVal omsnmp_sendsnmp(instanceData *pData, uchar *psz) if (iErrCode) { const char *str = snmp_api_errstring(iErrCode); - logerrorVar( "omsnmp_sendsnmp: Invalid SyslogMessage OID, error code '%d' - '%s'\n", iErrCode, str ); + errmsg.LogError(NO_ERRCODE, "omsnmp_sendsnmp: Invalid SyslogMessage OID, error code '%d' - '%s'\n", iErrCode, str ); ABORT_FINALIZE(RS_RET_DISABLE_ACTION); } } else { strErr = snmp_api_errstring(snmp_errno); - logerrorVar("omsnmp_sendsnmp: Parsing SyslogMessageOID failed '%s' with error '%s' \n", pData->szSyslogMessageOID, strErr); + errmsg.LogError(NO_ERRCODE, "omsnmp_sendsnmp: Parsing SyslogMessageOID failed '%s' with error '%s' \n", pData->szSyslogMessageOID, strErr); ABORT_FINALIZE(RS_RET_DISABLE_ACTION); } @@ -283,7 +285,7 @@ static rsRetVal omsnmp_sendsnmp(instanceData *pData, uchar *psz) { /* Debug Output! */ int iErrorCode = pData->snmpsession->s_snmp_errno; - logerrorVar( "omsnmp_sendsnmp: snmp_send failed error '%d', Description='%s'\n", iErrorCode*(-1), api_errors[iErrorCode*(-1)]); + errmsg.LogError(NO_ERRCODE, "omsnmp_sendsnmp: snmp_send failed error '%d', Description='%s'\n", iErrorCode*(-1), api_errors[iErrorCode*(-1)]); /* Clear Session */ omsnmp_exitSession(pData); @@ -504,6 +506,7 @@ BEGINmodInit() CODESTARTmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); CHKiRet(omsdRegCFSLineHdlr( (uchar *)"actionsnmptransport", 0, eCmdHdlrGetWord, NULL, &pszTransport, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr( (uchar *)"actionsnmptarget", 0, eCmdHdlrGetWord, NULL, &pszTarget, STD_LOADABLE_MODULE_ID)); @@ -179,6 +179,7 @@ #include "vmstk.h" #include "vm.h" #include "vmprg.h" +#include "errmsg.h" #include "sysvar.h" /* definitions for objects we access */ @@ -187,6 +188,7 @@ DEFobjCurrIf(conf) DEFobjCurrIf(expr) DEFobjCurrIf(vm) DEFobjCurrIf(module) +DEFobjCurrIf(errmsg) /* We define our own set of syslog defintions so that we @@ -1341,7 +1343,7 @@ parseAndSubmitMessage(char *hname, char *msg, int len, int bParseHost) * rgerhards, 2006-12-07 */ if(ret != Z_OK) { - logerrorInt("Uncompression of a message failed with return code %d " + errmsg.LogError(NO_ERRCODE, "Uncompression of a message failed with return code %d " "- enable debug logging if you need further information. " "Message ignored.", ret); FINALIZE; /* unconditional exit, nothing left to do... */ @@ -1354,7 +1356,7 @@ parseAndSubmitMessage(char *hname, char *msg, int len, int bParseHost) * tell the user we can not accept it. */ if(len > 0 && *msg == 'z') { - logerror("Received a compressed message, but rsyslogd does not have compression " + errmsg.LogError(NO_ERRCODE, "Received a compressed message, but rsyslogd does not have compression " "support enabled. The message will be ignored."); FINALIZE; } @@ -2270,89 +2272,6 @@ static void debug_switch() } -/* - * Add a string to error message and send it to logerror() - * The error message is passed to snprintf() and must be - * correctly formatted for it (containing a single %s param). - * rgerhards 2005-09-19 - */ -void logerrorSz(char *type, char *errMsg) -{ - char buf[1024]; - - snprintf(buf, sizeof(buf), type, errMsg); - buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ - logerror(buf); - return; -} - -/* - * Add an integer to error message and send it to logerror() - * The error message is passed to snprintf() and must be - * correctly formatted for it (containing a single %d param). - * rgerhards 2005-09-19 - */ -void logerrorInt(char *type, int errCode) -{ - char buf[1024]; - - snprintf(buf, sizeof(buf), type, errCode); - buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ - logerror(buf); - return; -} - -/* - * Error Output with variable number of parameters. - * This functions works pretty much like dbgprintf, - * except it logs an error. - */ -void logerrorVar(char *fmt, ...) -{ - va_list ap; - char buf[1024]; - size_t lenBuf; - - /* Format parameters */ - va_start(ap, fmt); - lenBuf = vsnprintf(buf, sizeof(buf), fmt, ap); - if(lenBuf >= sizeof(buf)) { - /* if our buffer was too small, we simply truncate. */ - lenBuf--; - } - va_end(ap); - - /* Log the error now */ - buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ - logerror(buf); - return; -} - - -/* Print syslogd errors some place. - */ -void logerror(char *type) -{ - char buf[1024]; - char errStr[1024]; - - BEGINfunc - dbgprintf("Called logerr, msg: %s\n", type); - - if (errno == 0) - snprintf(buf, sizeof(buf), "%s", type); - else { - rs_strerror_r(errno, errStr, sizeof(errStr)); - snprintf(buf, sizeof(buf), "%s: %s", type, errStr); - } - buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ - errno = 0; - logmsgInternal(LOG_SYSLOG|LOG_ERR, buf, ADDDATE); - ENDfunc - return; -} - - void legacyOptsEnq(uchar *line) { legacyOptsLL_t *pNew; @@ -2893,19 +2812,19 @@ init(void) /* some checks */ if(iMainMsgQueueNumWorkers < 1) { - logerror("$MainMsgQueueNumWorkers must be at least 1! Set to 1.\n"); + errmsg.LogError(NO_ERRCODE, "$MainMsgQueueNumWorkers must be at least 1! Set to 1.\n"); iMainMsgQueueNumWorkers = 1; } if(MainMsgQueType == QUEUETYPE_DISK) { errno = 0; /* for logerror! */ if(pszWorkDir == NULL) { - logerror("No $WorkDirectory specified - can not run main message queue in 'disk' mode. " + errmsg.LogError(NO_ERRCODE, "No $WorkDirectory specified - can not run main message queue in 'disk' mode. " "Using 'FixedArray' instead.\n"); MainMsgQueType = QUEUETYPE_FIXED_ARRAY; } if(pszMainMsgQFName == NULL) { - logerror("No $MainMsgQueueFileName specified - can not run main message queue in " + errmsg.LogError(NO_ERRCODE, "No $MainMsgQueueFileName specified - can not run main message queue in " "'disk' mode. Using 'FixedArray' instead.\n"); MainMsgQueType = QUEUETYPE_FIXED_ARRAY; } @@ -2928,11 +2847,11 @@ init(void) /* ... set some properties ... */ # define setQPROP(func, directive, data) \ CHKiRet_Hdlr(func(pMsgQueue, data)) { \ - logerrorInt("Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ + errmsg.LogError(NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } # define setQPROPstr(func, directive, data) \ CHKiRet_Hdlr(func(pMsgQueue, data, (data == NULL)? 0 : strlen((char*) data))) { \ - logerrorInt("Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ + errmsg.LogError(NO_ERRCODE, "Invalid " #directive ", error %d. Ignored, running with default setting", iRet); \ } setQPROP(queueSetMaxFileSize, "$MainMsgQueueFileSize", iMainMsgQueMaxFileSize); @@ -3044,14 +2963,14 @@ addAction(action_t **ppAction, modInfo_t *pMod, void *pModData, omodStringReques " Could not find template '%s' - action disabled\n", pTplName); errno = 0; - logerror(errMsg); + errmsg.LogError(NO_ERRCODE, "%s", errMsg); ABORT_FINALIZE(RS_RET_NOT_FOUND); } /* check required template options */ if( (iTplOpts & OMSR_RQD_TPL_OPT_SQL) && (pAction->ppTpl[i]->optFormatForSQL == 0)) { errno = 0; - logerror("Action disabled. To use this action, you have to specify " + errmsg.LogError(NO_ERRCODE, "Action disabled. To use this action, you have to specify " "the SQL or stdSQL option in your template!\n"); ABORT_FINALIZE(RS_RET_RQD_TPLOPT_MISSING); } @@ -3149,11 +3068,11 @@ selectorAddList(selector_t *f) if(f != NULL) { CHKiRet(llGetNumElts(&f->llActList, &iActionCnt)); if(iActionCnt == 0) { - logerror("warning: selector line without actions will be discarded"); + errmsg.LogError(NO_ERRCODE, "warning: selector line without actions will be discarded"); selectorDestruct(f); } else { if((iRet = selectorAddListCheckActions(f)) != RS_RET_OK) { - logerror("selector line will be discarded due to error in action(s)"); + errmsg.LogError(NO_ERRCODE, "selector line will be discarded due to error in action(s)"); selectorDestruct(f); goto finalize_it; } @@ -3201,7 +3120,7 @@ static rsRetVal setMainMsgQueType(void __attribute__((unused)) *pVal, uchar *psz MainMsgQueType = QUEUETYPE_DIRECT; dbgprintf("main message queue type set to DIRECT (no queueing at all)\n"); } else { - logerrorSz("unknown mainmessagequeuetype parameter: %s", (char *) pszType); + errmsg.LogError(NO_ERRCODE, "unknown mainmessagequeuetype parameter: %s", (char *) pszType); iRet = RS_RET_INVALID_PARAMS; } free(pszType); /* no longer needed */ @@ -3615,12 +3534,10 @@ static rsRetVal InitGlobalClasses(void) CHKiRet(exprClassInit()); CHKiRet(confClassInit()); -/* testing aides */ -//CHKiRet(tcps_sessClassInit()); -//CHKiRet(tcpsrvClassInit()); - /* dummy "classes" */ CHKiRet(actionClassInit()); + CHKiRet(NetInit()); + CHKiRet(templateInit()); /* request objects we use */ CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */ @@ -3628,6 +3545,7 @@ static rsRetVal InitGlobalClasses(void) CHKiRet(objUse(expr, CORE_COMPONENT)); CHKiRet(objUse(vm, CORE_COMPONENT)); CHKiRet(objUse(module, CORE_COMPONENT)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); finalize_it: RETiRet; @@ -3942,5 +3860,27 @@ int main(int argc, char **argv) } + +/* TODO: remove the "compatibility layer" below once we are done with modularization + * rgerhards, 2008-03-05 + */ +#if 0 +void logerror(char *msg) +{ + errmsg.LogError(NO_ERRCODE, "%s", msg); +} + +void logerrorInt(char *msg, int i) +{ + errmsg.LogError(NO_ERRCODE, msg, i); +} + +void logerrorSz(char *msg, char* str) +{ + errmsg.LogError(NO_ERRCODE, msg, str); +} +#endif + + /* vim:set ai: */ @@ -114,11 +114,6 @@ struct filed { }; typedef struct filed selector_t; /* new type name */ -void logerror(char *type); -void logerrorVar(char *fmt, ...) __attribute__((format(printf, 1, 2))); -/* the following two are legacy and should be replaced over time */ -void logerrorSz(char *type, char *errMsg); -void logerrorInt(char *type, int iErr); #define MSG_PARSE_HOSTNAME 1 #define MSG_DONT_PARSE_HOSTNAME 0 diff --git a/tcps_sess.c b/tcps_sess.c index 95f287d4..f8f9f5bd 100644 --- a/tcps_sess.c +++ b/tcps_sess.c @@ -50,10 +50,12 @@ #include "tcpsrv.h" #include "tcps_sess.h" #include "obj.h" +#include "errmsg.h" /* static data */ DEFobjStaticHelpers +DEFobjCurrIf(errmsg) /* Standard-Constructor */ @@ -196,7 +198,7 @@ PrepareClose(tcps_sess_t *pThis) /* In this case, we have an invalid frame count and thus * generate an error message and discard the frame. */ - logerrorInt("Incomplete frame at end of stream in session %d - " + errmsg.LogError(NO_ERRCODE, "Incomplete frame at end of stream in session %d - " "ignoring extra data (a message may be lost).\n", pThis->sock); /* nothing more to do */ @@ -324,7 +326,7 @@ DataRcvd(tcps_sess_t *pThis, char *pData, size_t iLen) /* IETF20061218 ++iNbrOctets; */ } else { /* TODO: handle "invalid frame" case */ - logerrorInt("Framing Error in received TCP message: " + errmsg.LogError(NO_ERRCODE, "Framing Error in received TCP message: " "delimiter is not SP but has ASCII value %d.\n", *pData); return(0); /* unconditional error exit */ @@ -334,7 +336,7 @@ DataRcvd(tcps_sess_t *pThis, char *pData, size_t iLen) if(pThis->iOctetsRemain < 1) { /* TODO: handle the case where the octet count is 0 or negative! */ dbgprintf("Framing Error: invalid octet count\n"); - logerrorInt("Framing Error in received TCP message: " + errmsg.LogError(NO_ERRCODE, "Framing Error in received TCP message: " "invalid octet count %d.\n", pThis->iOctetsRemain); return(0); /* unconditional error exit */ @@ -427,11 +429,10 @@ ENDobjQueryInterface(tcps_sess) * before anything else is called inside this class. * rgerhards, 2008-02-29 */ -//BEGINObjClassInit(tcps_sess, 1, OBJ_IS_LOADABLE_MODULE) /* class, version - CHANGE class also in END MACRO! */ BEGINObjClassInit(tcps_sess, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANGE class also in END MACRO! */ RUNLOG_STR("initializing tcps_sess class"); /* request objects we use */ - //CHKiRet(objUse(expr, CORE_COMPONENT)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); /* set our own handlers */ OBJSetMethodHandler(objMethod_DEBUGPRINT, tcps_sessDebugPrint); @@ -62,6 +62,7 @@ #include "conf.h" #include "tcpsrv.h" #include "obj.h" +#include "errmsg.h" MODULE_TYPE_LIB @@ -72,6 +73,7 @@ MODULE_TYPE_LIB DEFobjStaticHelpers DEFobjCurrIf(conf) DEFobjCurrIf(tcps_sess) +DEFobjCurrIf(errmsg) @@ -107,7 +109,7 @@ static void freeAllSockets(int **socks) * NOTE: you can not use dbgprintf() in here - the dbgprintf() system is * not yet initilized when this function is called. * rgerhards, 2007-06-21 - * We can also not use logerror(), as that system is also not yet + * We can also not use errmsg.LogError(NO_ERRCODE, ), as that system is also not yet * initialized... rgerhards, 2007-06-28 */ static void @@ -128,7 +130,7 @@ configureTCPListen(tcpsrv_t *pThis, char *cOptarg) if( i >= 0 && i <= 65535) { pThis->TCPLstnPort = cOptarg; } else { - logerrorSz("Invalid TCP listen port %s - changed to 514.\n", cOptarg); + errmsg.LogError(NO_ERRCODE, "Invalid TCP listen port %s - changed to 514.\n", cOptarg); pThis->TCPLstnPort = "514"; } } @@ -153,7 +155,7 @@ configureTCPListenSessMax(char *cOptarg) pThis->iSessMax = i; else { /* too small, need to adjust */ - logerrorSz("TCP session max configured to %s - changing to 1.\n", cOptarg); + errmsg.LogError(NO_ERRCODE, "TCP session max configured to %s - changing to 1.\n", cOptarg); pThis->iSessMax = 1; } } @@ -290,7 +292,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) error = getaddrinfo(NULL, pThis->TCPLstnPort, &hints, &res); if(error) { - logerror((char*) gai_strerror(error)); + errmsg.LogError(NO_ERRCODE, "%s", gai_strerror(error)); return NULL; } @@ -299,7 +301,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) /* EMPTY */; socks = malloc((maxs+1) * sizeof(int)); if (socks == NULL) { - logerror("couldn't allocate memory for TCP listen sockets, suspending TCP message reception."); + errmsg.LogError(NO_ERRCODE, "couldn't allocate memory for TCP listen sockets, suspending TCP message reception."); freeaddrinfo(res); return NULL; } @@ -310,7 +312,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); if (*s < 0) { if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT)) - logerror("create_tcp_socket(), socket"); + errmsg.LogError(NO_ERRCODE, "create_tcp_socket(), socket"); /* it is debatable if PF_INET with EAFNOSUPPORT should * also be ignored... */ @@ -322,7 +324,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) int iOn = 1; if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&iOn, sizeof (iOn)) < 0) { - logerror("TCP setsockopt"); + errmsg.LogError(NO_ERRCODE, "TCP setsockopt"); close(*s); *s = -1; continue; @@ -331,7 +333,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) #endif if (setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) { - logerror("TCP setsockopt(REUSEADDR)"); + errmsg.LogError(NO_ERRCODE, "TCP setsockopt(REUSEADDR)"); close(*s); *s = -1; continue; @@ -344,7 +346,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) if (should_use_so_bsdcompat()) { if (setsockopt(*s, SOL_SOCKET, SO_BSDCOMPAT, (char *) &on, sizeof(on)) < 0) { - logerror("TCP setsockopt(BSDCOMPAT)"); + errmsg.LogError(NO_ERRCODE, "TCP setsockopt(BSDCOMPAT)"); close(*s); *s = -1; continue; @@ -357,7 +359,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) && (errno != EADDRINUSE) #endif ) { - logerror("TCP bind"); + errmsg.LogError(NO_ERRCODE, "TCP bind"); close(*s); *s = -1; continue; @@ -369,10 +371,10 @@ static int *create_tcp_socket(tcpsrv_t *pThis) * to a fixed, reasonable, limit that should work. Only if * that fails, too, we give up. */ - logerrorInt("listen with a backlog of %d failed - retrying with default of 32.", + errmsg.LogError(NO_ERRCODE, "listen with a backlog of %d failed - retrying with default of 32.", pThis->iSessMax / 10 + 5); if(listen(*s, 32) < 0) { - logerror("TCP listen, suspending tcp inet"); + errmsg.LogError(NO_ERRCODE, "TCP listen, suspending tcp inet"); close(*s); *s = -1; continue; @@ -391,7 +393,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) "- this may or may not be an error indication.\n", *socks, maxs); if(*socks == 0) { - logerror("No TCP listen socket could successfully be initialized, " + errmsg.LogError(NO_ERRCODE, "No TCP listen socket could successfully be initialized, " "message reception via TCP disabled.\n"); free(socks); return(NULL); @@ -405,7 +407,7 @@ static int *create_tcp_socket(tcpsrv_t *pThis) * session table, so we can not continue. We need to free all * we have assigned so far, because we can not really use it... */ - logerror("Could not initialize TCP session table, suspending TCP message reception."); + errmsg.LogError(NO_ERRCODE, "Could not initialize TCP session table, suspending TCP message reception."); freeAllSockets(&socks); /* prevent a socket leak */ return(NULL); } @@ -438,7 +440,7 @@ SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, int fd) RUNLOG_VAR("%p", pThis->pUsr); newConn = accept(fd, (struct sockaddr*) &addr, &addrlen); if (newConn < 0) { - logerror("tcp accept, ignoring error and connection request"); + errmsg.LogError(NO_ERRCODE, "tcp accept, ignoring error and connection request"); ABORT_FINALIZE(RS_RET_ERR); // TODO: better error code //was: return -1; } @@ -447,7 +449,7 @@ RUNLOG_VAR("%p", pThis->pUsr); iSess = TCPSessTblFindFreeSpot(pThis); if(iSess == -1) { errno = 0; - logerror("too many tcp sessions - dropping incoming request"); + errmsg.LogError(NO_ERRCODE, "too many tcp sessions - dropping incoming request"); close(newConn); ABORT_FINALIZE(RS_RET_ERR); // TODO: better error code //was: return -1; @@ -482,7 +484,7 @@ RUNLOG_VAR("%p", pThis->pUsr); dbgprintf("%s is not an allowed sender\n", (char *) fromHostFQDN); if(option_DisallowWarning) { errno = 0; - logerrorSz("TCP message from disallowed sender %s discarded", + errmsg.LogError(NO_ERRCODE, "TCP message from disallowed sender %s discarded", (char*)fromHost); } close(newConn); @@ -603,7 +605,7 @@ RUNLOG; pThis->pOnRegularClose(pThis->pSessions[iTCPSess]); tcps_sess.Destruct(&pThis->pSessions[iTCPSess]); } else if(state == -1) { - logerrorInt("TCP session %d will be closed, error ignored\n", fdSess); + errmsg.LogError(NO_ERRCODE, "TCP session %d will be closed, error ignored\n", fdSess); pThis->pOnErrClose(pThis->pSessions[iTCPSess]); tcps_sess.Destruct(&pThis->pSessions[iTCPSess]); } else { @@ -612,7 +614,7 @@ RUNLOG; /* in this case, something went awfully wrong. * We are instructed to terminate the session. */ - logerrorInt("Tearing down TCP Session %d - see " + errmsg.LogError(NO_ERRCODE, "Tearing down TCP Session %d - see " "previous messages for reason(s)\n", iTCPSess); pThis->pOnErrClose(pThis->pSessions[iTCPSess]); @@ -836,6 +838,7 @@ CODESTARTmodInit CHKiRet(tcpsrvClassInit()); /* must be done after tcps_sess, as we use it */ /* request objects we use */ + CHKiRet(objUse(errmsg, CORE_COMPONENT)); ENDmodInit /* vim:set ai: @@ -34,6 +34,12 @@ #include "template.h" #include "msg.h" #include "syslogd.h" +#include "obj.h" +#include "errmsg.h" + +/* static data */ +DEFobjCurrIf(obj) +DEFobjCurrIf(errmsg) static struct template *tplRoot = NULL; /* the root of the template list */ static struct template *tplLast = NULL; /* points to the last element of the template list */ @@ -520,8 +526,7 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) if (*p != ':') { /* There is something more than an R , this is invalid ! */ /* Complain on extra characters */ - logerrorSz - ("error: invalid character in frompos after \"R\", property: '%%%s'", + errmsg.LogError(NO_ERRCODE, "error: invalid character in frompos after \"R\", property: '%%%s'", (char*) *pp); } else { pTpe->data.field.has_regex = 1; @@ -545,8 +550,7 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) pTpe->data.field.has_fields = 1; if(!isdigit((int)*p)) { /* complain and use default */ - logerrorSz - ("error: invalid character in frompos after \"F,\", property: '%%%s' - using 9 (HT) as field delimiter", + errmsg.LogError(NO_ERRCODE, "error: invalid character in frompos after \"F,\", property: '%%%s' - using 9 (HT) as field delimiter", (char*) *pp); pTpe->data.field.field_delim = 9; } else { @@ -554,8 +558,7 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) while(isdigit((int)*p)) iNum = iNum * 10 + *p++ - '0'; if(iNum < 0 || iNum > 255) { - logerrorInt - ("error: non-USASCII delimiter character value in template - using 9 (HT) as substitute", iNum); + errmsg.LogError(NO_ERRCODE, "error: non-USASCII delimiter character value %d in template - using 9 (HT) as substitute", iNum); pTpe->data.field.field_delim = 9; } else { pTpe->data.field.field_delim = iNum; @@ -565,8 +568,7 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) /* invalid character after F, so we need to reject * this. */ - logerrorSz - ("error: invalid character in frompos after \"F\", property: '%%%s'", + errmsg.LogError(NO_ERRCODE, "error: invalid character in frompos after \"F\", property: '%%%s'", (char*) *pp); } } else { @@ -1011,6 +1013,19 @@ int tplGetEntryCount(struct template *pTpl) assert(pTpl != NULL); return(pTpl->tpenElements); } + +/* our init function. TODO: remove once converted to a class + */ +rsRetVal templateInit() +{ + DEFiRet; + CHKiRet(objGetObjInterface(&obj)); + CHKiRet(objUse(errmsg, CORE_COMPONENT)); + +finalize_it: + RETiRet; +} + /* * vi:set ai: */ |