summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Makefile.am13
-rw-r--r--conf.c4
-rw-r--r--configure.ac3
-rw-r--r--modules.c29
-rw-r--r--modules.h1
-rw-r--r--net.c76
-rw-r--r--net.h70
-rw-r--r--obj-types.h2
-rw-r--r--obj.c3
-rw-r--r--obj.h2
-rw-r--r--omfwd.c6
-rw-r--r--plugins/imgssapi/imgssapi.c22
-rw-r--r--plugins/imtcp/imtcp.c12
-rw-r--r--plugins/imudp/imudp.c23
-rw-r--r--syslogd-types.h10
-rw-r--r--syslogd.c40
-rw-r--r--syslogd.h1
-rw-r--r--tcpsrv.c9
-rw-r--r--template.h10
20 files changed, 242 insertions, 97 deletions
diff --git a/ChangeLog b/ChangeLog
index fd111738..601765ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
---------------------------------------------------------------------------
Version 3.12.2 (rgerhards), 2008-03-??
+- added RSYSLOGD_MODDIR environment variable
+- added -M rsyslogd option (allows to specify module directory location)
+- converted net.c into a loadable library plugin
---------------------------------------------------------------------------
Version 3.12.1 (rgerhards), 2008-03-06
- added library plugins, which can be automatically loaded
diff --git a/Makefile.am b/Makefile.am
index 67b3e962..c4fc4b68 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,8 +50,6 @@ rsyslogd_SOURCES = \
queue.h \
sync.c \
sync.h \
- net.c \
- net.h \
obj.c \
obj.h \
obj-types.h \
@@ -111,6 +109,17 @@ tcpsrv_la_LDFLAGS = -module -avoid-version
tcpsrv_la_LIBADD =
#
+# network support
+#
+if ENABLE_INET
+pkglib_LTLIBRARIES += net.la
+net_la_SOURCES = net.c net.h
+net_la_CPPFLAGS = $(pthreads_cflags)
+net_la_LDFLAGS = -module -avoid-version
+net_la_LIBADD =
+endif
+
+#
# gssapi support
#
if ENABLE_GSSAPI
diff --git a/conf.c b/conf.c
index 5100965b..288c10f3 100644
--- a/conf.c
+++ b/conf.c
@@ -70,6 +70,7 @@ DEFobjCurrIf(expr)
DEFobjCurrIf(ctok)
DEFobjCurrIf(module)
DEFobjCurrIf(errmsg)
+DEFobjCurrIf(net)
/* The following global variables are used for building
* tag and host selector lines during startup and config reload.
@@ -296,7 +297,7 @@ doNameLine(uchar **pp, void* pVal)
ochAddLine(szName, &p);
break;
case DIR_ALLOWEDSENDER:
- addAllowedSenderLine(szName, &p);
+ net.addAllowedSenderLine(szName, &p);
break;
default:/* we do this to avoid compiler warning - not all
* enum values call this function, so an incomplete list
@@ -1170,6 +1171,7 @@ BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANG
CHKiRet(objUse(ctok, CORE_COMPONENT));
CHKiRet(objUse(module, CORE_COMPONENT));
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(net, "net"));
ENDObjClassInit(conf)
/* vi:set ai:
diff --git a/configure.ac b/configure.ac
index 65cfae82..c7050772 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,8 @@ case "${host}" in
;;
esac
+AC_DEFINE_UNQUOTED([HOSTENV], "$host", [the host environment, can be queried via a system variable])
+
# Checks for libraries.
save_LIBS=$LIBS
LIBS=
@@ -232,6 +234,7 @@ AC_ARG_ENABLE(inet,
esac],
[enable_inet="yes"]
)
+AM_CONDITIONAL(ENABLE_INET, test x$enable_inet = xyes)
if test "$enable_inet" = "yes"; then
AC_DEFINE(SYSLOG_INET, 1, [network support is integrated.])
fi
diff --git a/modules.c b/modules.c
index 9082283d..d9c1f983 100644
--- a/modules.c
+++ b/modules.c
@@ -515,6 +515,27 @@ finalize_it:
}
+/* set the default module load directory. A NULL value may be provided, in
+ * which case any previous value is deleted but no new one set. The caller-provided
+ * string is duplicated. If it needs to be freed, that's the caller's duty.
+ * rgerhards, 2008-03-07
+ */
+static rsRetVal
+SetModDir(uchar *pszModDir)
+{
+ DEFiRet;
+
+ dbgprintf("setting default module load directory '%s'\n", pszModDir);
+ if(pModDir != NULL) {
+ free(pModDir);
+ }
+
+ pModDir = (uchar*) strdup((char*)pszModDir);
+
+ RETiRet;
+}
+
+
/* queryInterface function
* rgerhards, 2008-03-05
*/
@@ -537,6 +558,7 @@ CODESTARTobjQueryInterface(module)
pIf->UnloadAndDestructAll = modUnloadAndDestructAll;
pIf->UnloadAndDestructDynamic = modUnloadAndDestructDynamic;
pIf->doModInit = doModInit;
+ pIf->SetModDir = SetModDir;
pIf->Load = Load;
finalize_it:
ENDobjQueryInterface(module)
@@ -547,6 +569,13 @@ ENDobjQueryInterface(module)
* rgerhards, 2008-03-05
*/
BEGINAbstractObjClassInit(module, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANGE class also in END MACRO! */
+ uchar *pModPath;
+
+ /* use any module load path specified in the environment */
+ if((pModPath = (uchar*) getenv("RSYSLOG_MODDIR")) != NULL) {
+ SetModDir(pModPath);
+ }
+
/* request objects we use */
CHKiRet(objUse(errmsg, CORE_COMPONENT));
ENDObjClassInit(module)
diff --git a/modules.h b/modules.h
index 2a26d5e3..e354ae05 100644
--- a/modules.h
+++ b/modules.h
@@ -113,6 +113,7 @@ BEGINinterface(module) /* name must also be changed in ENDinterface macro! */
rsRetVal (*UnloadAndDestructDynamic)(void);
rsRetVal (*doModInit)(rsRetVal (*modInit)(), uchar *name, void *pModHdlr);
rsRetVal (*Load)(uchar *name);
+ rsRetVal (*SetModDir)(uchar *name);
ENDinterface(module)
#define moduleCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
diff --git a/net.c b/net.c
index b7be521a..74b27806 100644
--- a/net.c
+++ b/net.c
@@ -33,8 +33,6 @@
*/
#include "config.h"
-#ifdef SYSLOG_INET
-
#include "rsyslog.h"
#include <stdio.h>
#include <stdarg.h>
@@ -51,14 +49,17 @@
#include "syslogd.h"
#include "syslogd-types.h"
-#include "net.h"
+#include "module-template.h"
#include "parse.h"
#include "srUtils.h"
#include "obj.h"
#include "errmsg.h"
+#include "net.h"
+
+MODULE_TYPE_LIB
/* static data */
-DEFobjCurrIf(obj)
+DEFobjStaticHelpers
DEFobjCurrIf(errmsg)
/* support for defining allowed TCP and UDP senders. We use the same
@@ -1023,19 +1024,64 @@ int *create_udp_socket(uchar *hostname, uchar *pszPort, int bIsServer)
}
-/* our init function. TODO: remove once converted to a class
+/* queryInterface function
+ * rgerhards, 2008-03-05
*/
-rsRetVal NetInit()
-{
- DEFiRet;
- CHKiRet(objGetObjInterface(&obj));
- CHKiRet(objUse(errmsg, CORE_COMPONENT));
+BEGINobjQueryInterface(net)
+CODESTARTobjQueryInterface(net)
+ if(pIf->ifVersion != netCURR_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->cvthname = cvthname;
+ /* things to go away after proper modularization */
+ pIf->addAllowedSenderLine = addAllowedSenderLine;
+ pIf->PrintAllowedSenders = PrintAllowedSenders;
+ pIf->clearAllowedSenders = clearAllowedSenders;
+ pIf->debugListenInfo = debugListenInfo;
+ pIf->create_udp_socket = create_udp_socket;
+ pIf->closeUDPListenSockets = closeUDPListenSockets;
finalize_it:
- RETiRet;
-}
+ENDobjQueryInterface(net)
+
+
+/* Initialize the net class. Must be called as the very first method
+ * before anything else is called inside this class.
+ * rgerhards, 2008-02-19
+ */
+BEGINAbstractObjClassInit(net, 1, OBJ_IS_CORE_MODULE) /* class, version */
+ /* request objects we use */
+ CHKiRet(objUse(errmsg, CORE_COMPONENT));
+
+ /* set our own handlers */
+ENDObjClassInit(net)
+
+
+/* --------------- 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 */
-#endif /* #ifdef SYSLOG_INET */
-/*
- * vi:set ai:
+ /* Initialize all classes that are in our module - this includes ourselfs */
+ CHKiRet(netClassInit()); /* must be done after tcps_sess, as we use it */
+ENDmodInit
+/* vi:set ai:
*/
diff --git a/net.h b/net.h
index e5844bf5..1916f3ed 100644
--- a/net.h
+++ b/net.h
@@ -35,9 +35,9 @@
#define ADDR_PRI6 0x02 /* use IPv6 address prior to IPv4 when resolving */
#ifdef BSD
-#ifndef _KERNEL
-#define s6_addr32 __u6_addr.__u6_addr32
-#endif
+# ifndef _KERNEL
+# define s6_addr32 __u6_addr.__u6_addr32
+# endif
#endif
struct NetAddr {
@@ -59,6 +59,20 @@ struct NetAddr {
# define SO_BSDCOMPAT 0
#endif
+
+/* IPv6 compatibility layer for older platforms
+ * We need to handle a few things different if we are running
+ * on an older platform which does not support all the glory
+ * of IPv6. We try to limit toll on features and reliability,
+ * but obviously it is better to run rsyslog on a platform that
+ * supports everything...
+ * rgerhards, 2007-06-22
+ */
+#ifndef AI_NUMERICSERV
+# define AI_NUMERICSERV 0
+#endif
+
+
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
#define SALEN(sa) ((sa)->sa_len)
#else
@@ -71,31 +85,43 @@ static inline size_t SALEN(struct sockaddr *sa) {
}
#endif
-rsRetVal cvthname(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN);
-/* things to go away after proper modularization */
-rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine);
-void PrintAllowedSenders(int iListToPrint);
-void clearAllowedSenders ();
-void debugListenInfo(int fd, char *type);
-int *create_udp_socket(uchar *hostname, uchar *LogPort, int bIsServer);
-void closeUDPListenSockets(int *finet);
+struct AllowedSenders {
+ struct NetAddr allowedSender; /* ip address allowed */
+ uint8_t SignificantBits; /* defines how many bits should be discarded (eqiv to mask) */
+ struct AllowedSenders *pNext;
+};
+
+
+/* interfaces */
+BEGINinterface(net) /* name must also be changed in ENDinterface macro! */
+ rsRetVal (*cvthname)(struct sockaddr_storage *f, uchar *pszHost, uchar *pszHostFQDN);
+ /* things to go away after proper modularization */
+ rsRetVal (*addAllowedSenderLine)(char* pName, uchar** ppRestOfConfLine);
+ void (*PrintAllowedSenders)(int iListToPrint);
+ void (*clearAllowedSenders) ();
+ void (*debugListenInfo)(int fd, char *type);
+ int *(*create_udp_socket)(uchar *hostname, uchar *LogPort, int bIsServer);
+ void (*closeUDPListenSockets)(int *finet);
+ /* data memebers - these should go away over time... TODO */
+ int *pACLAddHostnameOnFail; /* add hostname to acl when DNS resolving has failed */
+ int *pACLDontResolve; /* add hostname to acl instead of resolving it to IP(s) */
+ struct AllowedSenders *pAllowedSenders_UDP;
+ struct AllowedSenders *pAllowedSenders_TCP;
+ struct AllowedSenders *pAllowedSenders_GSS;
+ENDinterface(net)
+#define netCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+
+/* prototypes */
+PROTOTYPEObj(net);
+
+
+#if 0
extern int ACLAddHostnameOnFail; /* add hostname to acl when DNS resolving has failed */
extern int ACLDontResolve; /* add hostname to acl instead of resolving it to IP(s) */
extern struct AllowedSenders *pAllowedSenders_UDP;
extern struct AllowedSenders *pAllowedSenders_TCP;
extern struct AllowedSenders *pAllowedSenders_GSS;
-
-/* IPv6 compatibility layer for older platforms
- * We need to handle a few things different if we are running
- * on an older platform which does not support all the glory
- * of IPv6. We try to limit toll on features and reliability,
- * but obviously it is better to run rsyslog on a platform that
- * supports everything...
- * rgerhards, 2007-06-22
- */
-#ifndef AI_NUMERICSERV
-# define AI_NUMERICSERV 0
#endif
#endif /* #ifdef SYSLOG_INET */
diff --git a/obj-types.h b/obj-types.h
index 31fdd03d..3771d02d 100644
--- a/obj-types.h
+++ b/obj-types.h
@@ -348,7 +348,7 @@ finalize_it: \
*/
#define CORE_COMPONENT NULL /* use this to indicate this is a core component */
#define objUse(objName, FILENAME) \
- obj.UseObj((uchar*)#objName, (uchar*)FILENAME, (void*) &objName)
+ obj.UseObj(__FILE__, (uchar*)#objName, (uchar*)FILENAME, (void*) &objName)
/* defines data that must always be present at the very begin of the interface structure */
#define ifBEGIN \
diff --git a/obj.c b/obj.c
index b648a4e4..2bbbe4bb 100644
--- a/obj.c
+++ b/obj.c
@@ -1052,7 +1052,7 @@ RUNLOG_VAR("%p", errmsg.LogError);
* rgerhards, 2008-02-29
*/
static rsRetVal
-UseObj(uchar *pObjName, uchar *pObjFile, interface_t *ppIf)
+UseObj(char *srcFile, uchar *pObjName, uchar *pObjFile, interface_t *ppIf)
{
DEFiRet;
cstr_t *pStr = NULL;
@@ -1061,6 +1061,7 @@ UseObj(uchar *pObjName, uchar *pObjFile, interface_t *ppIf)
CHKiRet(rsCStrConstructFromszStr(&pStr, pObjName));
iRet = FindObjInfo(pStr, &pObjInfo);
+ dbgprintf("source file %s requests object '%s'\n", srcFile, pObjName);
if(iRet == RS_RET_NOT_FOUND) {
/* in this case, we need to see if we can dynamically load the object */
if(pObjFile == NULL) {
diff --git a/obj.h b/obj.h
index 6b9f7df4..cf7835a5 100644
--- a/obj.h
+++ b/obj.h
@@ -92,7 +92,7 @@
/* interfaces */
BEGINinterface(obj) /* name must also be changed in ENDinterface macro! */
- rsRetVal (*UseObj)(uchar *pObjName, uchar *pObjFile, interface_t *ppIf);
+ rsRetVal (*UseObj)(char *srcFile, uchar *pObjName, uchar *pObjFile, interface_t *ppIf);
rsRetVal (*InfoConstruct)(objInfo_t **ppThis, uchar *pszID, int iObjVers,
rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *),
rsRetVal (*pQueryIF)(interface_t*));
diff --git a/omfwd.c b/omfwd.c
index a9fed18c..a931fdec 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -83,6 +83,7 @@ MODULE_TYPE_OUTPUT
*/
DEF_OMOD_STATIC_DATA
DEFobjCurrIf(errmsg)
+DEFobjCurrIf(net)
typedef struct _instanceData {
char f_hname[MAXHOSTNAMELEN+1];
@@ -150,7 +151,7 @@ CODESTARTfreeInstance
if(pData->sock >= 0)
close(pData->sock);
if(pData->pSockArray != NULL)
- closeUDPListenSockets(pData->pSockArray);
+ net.closeUDPListenSockets(pData->pSockArray);
ENDfreeInstance
@@ -358,7 +359,7 @@ CODESTARTdoAction
*/
if(pData->protocol == FORW_UDP) {
if(pData->pSockArray == NULL) {
- pData->pSockArray = create_udp_socket((uchar*)pData->f_hname, NULL, 0);
+ pData->pSockArray = net.create_udp_socket((uchar*)pData->f_hname, NULL, 0);
}
}
if ( 0) // TODO: think about this strcmp(getHOSTNAME(f->f_pMsg), LocalHostName) && NoHops )
@@ -621,6 +622,7 @@ CODESTARTmodInit
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(net, "net"));
ENDmodInit
#endif /* #ifdef SYSLOG_INET */
diff --git a/plugins/imgssapi/imgssapi.c b/plugins/imgssapi/imgssapi.c
index 1c0dd79a..4a7479f4 100644
--- a/plugins/imgssapi/imgssapi.c
+++ b/plugins/imgssapi/imgssapi.c
@@ -77,6 +77,7 @@ DEFobjCurrIf(tcpsrv)
DEFobjCurrIf(tcps_sess)
DEFobjCurrIf(gssutil)
DEFobjCurrIf(errmsg)
+DEFobjCurrIf(net)
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;
@@ -171,10 +172,10 @@ isPermittedHost(struct sockaddr *addr, char *fromHostFQDN, void *pUsrSrv, void*p
pGSess = (gss_sess_t*) pUsrSess;
if((pGSrv->allowedMethods & ALLOWEDMETHOD_TCP) &&
- isAllowedSender(pAllowedSenders_TCP, addr, (char*)fromHostFQDN))
+ isAllowedSender(net.pAllowedSenders_TCP, addr, (char*)fromHostFQDN))
allowedMethods |= ALLOWEDMETHOD_TCP;
if((pGSrv->allowedMethods & ALLOWEDMETHOD_GSS) &&
- isAllowedSender(pAllowedSenders_GSS, addr, (char*)fromHostFQDN))
+ isAllowedSender(net.pAllowedSenders_GSS, addr, (char*)fromHostFQDN))
allowedMethods |= ALLOWEDMETHOD_GSS;
if(allowedMethods && pGSess != NULL)
pGSess->allowedMethods = allowedMethods;
@@ -636,8 +637,8 @@ CODESTARTwillRun
if(pOurTcpsrv == NULL)
ABORT_FINALIZE(RS_RET_NO_RUN);
- PrintAllowedSenders(2); /* TCP */
- PrintAllowedSenders(3); /* GSS */
+ net.PrintAllowedSenders(2); /* TCP */
+ net.PrintAllowedSenders(3); /* GSS */
finalize_it:
ENDwillRun
@@ -654,13 +655,13 @@ ENDmodExit
BEGINafterRun
CODESTARTafterRun
/* do cleanup here */
- if (pAllowedSenders_TCP != NULL) {
- clearAllowedSenders (pAllowedSenders_TCP);
- pAllowedSenders_TCP = NULL;
+ if (net.pAllowedSenders_TCP != NULL) {
+ net.clearAllowedSenders (net.pAllowedSenders_TCP);
+ net.pAllowedSenders_TCP = NULL;
}
- if (pAllowedSenders_GSS != NULL) {
- clearAllowedSenders (pAllowedSenders_GSS);
- pAllowedSenders_GSS = NULL;
+ if (net.pAllowedSenders_GSS != NULL) {
+ net.clearAllowedSenders (net.pAllowedSenders_GSS);
+ net.pAllowedSenders_GSS = NULL;
}
ENDafterRun
@@ -693,6 +694,7 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(tcpsrv, "tcpsrv"));
CHKiRet(objUse(gssutil, "gssutil"));
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(net, "net"));
/* register config file handlers */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverpermitplaintcp", 0, eCmdHdlrBinary,
diff --git a/plugins/imtcp/imtcp.c b/plugins/imtcp/imtcp.c
index ca52d3c5..2da094a4 100644
--- a/plugins/imtcp/imtcp.c
+++ b/plugins/imtcp/imtcp.c
@@ -51,6 +51,7 @@ MODULE_TYPE_INPUT
DEF_IMOD_STATIC_DATA
DEFobjCurrIf(tcpsrv)
DEFobjCurrIf(tcps_sess)
+DEFobjCurrIf(net)
/* Module static data */
static tcpsrv_t *pOurTcpsrv = NULL; /* our TCP server(listener) TODO: change for multiple instances */
@@ -65,7 +66,7 @@ static int
isPermittedHost(struct sockaddr *addr, char *fromHostFQDN, void __attribute__((unused)) *pUsrSrv,
void __attribute__((unused)) *pUsrSess)
{
- return isAllowedSender(pAllowedSenders_TCP, addr, fromHostFQDN);
+ return isAllowedSender(net.pAllowedSenders_TCP, addr, fromHostFQDN);
}
@@ -159,7 +160,7 @@ ENDrunInput
BEGINwillRun
CODESTARTwillRun
/* first apply some config settings */
- PrintAllowedSenders(2); /* TCP */
+ net.PrintAllowedSenders(2); /* TCP */
if(pOurTcpsrv == NULL)
ABORT_FINALIZE(RS_RET_NO_RUN);
finalize_it:
@@ -169,9 +170,9 @@ ENDwillRun
BEGINafterRun
CODESTARTafterRun
/* do cleanup here */
- if (pAllowedSenders_TCP != NULL) {
- clearAllowedSenders (pAllowedSenders_TCP);
- pAllowedSenders_TCP = NULL;
+ if(net.pAllowedSenders_TCP != NULL) {
+ net.clearAllowedSenders(net.pAllowedSenders_TCP);
+ net.pAllowedSenders_TCP = NULL;
}
ENDafterRun
@@ -204,6 +205,7 @@ CODESTARTmodInit
CODEmodInit_QueryRegCFSLineHdlr
pOurTcpsrv = NULL;
/* request objects we use */
+ CHKiRet(objUse(net, "net"));
CHKiRet(objUse(tcps_sess, "tcpsrv"));
CHKiRet(objUse(tcpsrv, "tcpsrv"));
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
index be9fb6cc..f18461e7 100644
--- a/plugins/imudp/imudp.c
+++ b/plugins/imudp/imudp.c
@@ -47,6 +47,8 @@ MODULE_TYPE_INPUT
/* Module static data */
DEF_IMOD_STATIC_DATA
DEFobjCurrIf(errmsg)
+DEFobjCurrIf(net)
+
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 */
@@ -84,7 +86,7 @@ static rsRetVal addListner(void __attribute__((unused)) *pVal, uchar *pNewVal)
dbgprintf("Trying to open syslog UDP ports at %s:%s.\n",
(bindAddr == NULL) ? (uchar*)"*" : bindAddr, pNewVal);
- newSocks = create_udp_socket(bindAddr, (pNewVal == NULL || *pNewVal == '\0') ? (uchar*) "514" : pNewVal, 1);
+ newSocks = net.create_udp_socket(bindAddr, (pNewVal == NULL || *pNewVal == '\0') ? (uchar*) "514" : pNewVal, 1);
if(newSocks != NULL) {
/* we now need to add the new sockets to the existing set */
if(udpLstnSocks == NULL) {
@@ -154,7 +156,7 @@ CODESTARTrunInput
for (i = 0; i < *udpLstnSocks; i++) {
if (udpLstnSocks[i+1] != -1) {
if(Debug)
- debugListenInfo(udpLstnSocks[i+1], "UDP");
+ net.debugListenInfo(udpLstnSocks[i+1], "UDP");
FD_SET(udpLstnSocks[i+1], &readfds);
if(udpLstnSocks[i+1]>maxfds) maxfds=udpLstnSocks[i+1];
}
@@ -178,7 +180,7 @@ CODESTARTrunInput
l = recvfrom(udpLstnSocks[i+1], (char*) pRcvBuf, MAXLINE - 1, 0,
(struct sockaddr *)&frominet, &socklen);
if (l > 0) {
- if(cvthname(&frominet, fromHost, fromHostFQDN) == RS_RET_OK) {
+ if(net.cvthname(&frominet, fromHost, fromHostFQDN) == RS_RET_OK) {
dbgprintf("Message from inetd socket: #%d, host: %s\n",
udpLstnSocks[i+1], fromHost);
/* Here we check if a host is permitted to send us
@@ -187,7 +189,7 @@ CODESTARTrunInput
* configured to do this).
* rgerhards, 2005-09-26
*/
- if(isAllowedSender(pAllowedSenders_UDP,
+ if(isAllowedSender(net.pAllowedSenders_UDP,
(struct sockaddr *)&frominet, (char*)fromHostFQDN)) {
parseAndSubmitMessage((char*)fromHost, (char*) pRcvBuf, l,
MSG_PARSE_HOSTNAME, NOFLAG);
@@ -220,7 +222,7 @@ ENDrunInput
/* initialize and return if will run or not */
BEGINwillRun
CODESTARTwillRun
- PrintAllowedSenders(1); /* UDP */
+ net.PrintAllowedSenders(1); /* UDP */
/* if we could not set up any listners, there is no point in running... */
if(udpLstnSocks == NULL)
@@ -236,12 +238,12 @@ ENDwillRun
BEGINafterRun
CODESTARTafterRun
/* do cleanup here */
- if (pAllowedSenders_UDP != NULL) {
- clearAllowedSenders (pAllowedSenders_UDP);
- pAllowedSenders_UDP = NULL;
+ if (net.pAllowedSenders_UDP != NULL) {
+ net.clearAllowedSenders (net.pAllowedSenders_UDP);
+ net.pAllowedSenders_UDP = NULL;
}
if(udpLstnSocks != NULL)
- closeUDPListenSockets(udpLstnSocks);
+ net.closeUDPListenSockets(udpLstnSocks);
if(pRcvBuf != NULL)
free(pRcvBuf);
ENDafterRun
@@ -264,7 +266,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
pszBindAddr = NULL;
}
if(udpLstnSocks != NULL) {
- closeUDPListenSockets(udpLstnSocks);
+ net.closeUDPListenSockets(udpLstnSocks);
udpLstnSocks = NULL;
}
return RS_RET_OK;
@@ -276,6 +278,7 @@ CODESTARTmodInit
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(net, "net"));
/* register config file handlers */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"udpserverrun", 0, eCmdHdlrGetWord,
diff --git a/syslogd-types.h b/syslogd-types.h
index 1d49cfb5..9aea3778 100644
--- a/syslogd-types.h
+++ b/syslogd-types.h
@@ -27,7 +27,7 @@
#define SYSLOGD_TYPES_INCLUDED 1
#include "stringbuf.h"
-#include "net.h"
+//#include "net.h"
#include <sys/param.h>
#if HAVE_SYSLOG_H
#include <syslog.h>
@@ -98,14 +98,6 @@ struct syslogTime {
};
typedef struct syslogTime syslogTime_t;
-#ifdef SYSLOG_INET
-struct AllowedSenders {
- struct NetAddr allowedSender; /* ip address allowed */
- uint8_t SignificantBits; /* defines how many bits should be discarded (eqiv to mask) */
- struct AllowedSenders *pNext;
-};
-#endif
-
#endif /* #ifndef SYSLOGD_TYPES_INCLUDED */
/*
* vi:set ai:
diff --git a/syslogd.c b/syslogd.c
index 88a3c384..09b9bb7b 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -175,6 +175,7 @@ DEFobjCurrIf(expr)
DEFobjCurrIf(vm)
DEFobjCurrIf(module)
DEFobjCurrIf(errmsg)
+DEFobjCurrIf(net) /* TODO: make go away! */
/* We define our own set of syslog defintions so that we
@@ -898,6 +899,7 @@ logmsgInternal(int pri, char *msg, int flags)
pMsg->iFacility = LOG_FAC(pri);
pMsg->iSeverity = LOG_PRI(pri);
pMsg->bParseHOSTNAME = 0;
+RUNLOG_VAR("%p", datetime.getCurrTime);
datetime.getCurrTime(&(pMsg->tTIMESTAMP)); /* use the current time! */
flags |= INTERNAL_MSG;
@@ -1956,6 +1958,7 @@ die(int sig)
legacyOptsFree();
dbgprintf("Clean shutdown completed, bye\n");
+dbgprintf("hostenv %s\n", HOSTENV);
/* exit classes... This MUST be after the dbgprintf (because it de-inits the debug system!) */
dbgClassExit();
@@ -2868,9 +2871,21 @@ static rsRetVal InitGlobalClasses(void)
DEFiRet;
CHKiRet(objClassInit()); /* *THIS* *MUST* always be the first class initilizer being called! */
+ CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */
+ /* the following classes were intialized by objClassInit() */
+ CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(module, CORE_COMPONENT));
- /* real ones */
+ /* initialize and use classes. We must be very careful with the order of events. Some
+ * classes use others and if we do not initialize them in the right order, we may end
+ * up with an invalid call. The most important thing that can happen is that an error
+ * is detected and needs to be logged, wich in turn requires a broader number of classes
+ * to be available. The solution is that we take care in the order of calls AND use a
+ * class immediately after it is initialized. And, of course, we load those classes
+ * first that we use ourselfs... -- rgerhards, 2008-03-07
+ */
CHKiRet(datetimeClassInit());
+ CHKiRet(objUse(datetime, CORE_COMPONENT));
CHKiRet(msgClassInit());
CHKiRet(strmClassInit());
CHKiRet(wtiClassInit());
@@ -2879,26 +2894,22 @@ static rsRetVal InitGlobalClasses(void)
CHKiRet(vmstkClassInit());
CHKiRet(sysvarClassInit());
CHKiRet(vmClassInit());
+ CHKiRet(objUse(vm, CORE_COMPONENT));
CHKiRet(vmopClassInit());
CHKiRet(vmprgClassInit());
CHKiRet(ctok_tokenClassInit());
CHKiRet(ctokClassInit());
CHKiRet(exprClassInit());
+ CHKiRet(objUse(expr, CORE_COMPONENT));
CHKiRet(confClassInit());
+ CHKiRet(objUse(conf, CORE_COMPONENT));
/* dummy "classes" */
CHKiRet(actionClassInit());
- CHKiRet(NetInit());
CHKiRet(templateInit());
- /* request objects we use */
- CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */
- CHKiRet(objUse(datetime, CORE_COMPONENT));
- CHKiRet(objUse(conf, CORE_COMPONENT));
- CHKiRet(objUse(expr, CORE_COMPONENT));
- CHKiRet(objUse(vm, CORE_COMPONENT));
- CHKiRet(objUse(module, CORE_COMPONENT));
- CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ /* TODO: the dependency on net shall go away! -- rgerhards, 2008-03-07 */
+ CHKiRet(objUse(net, "net"));
finalize_it:
RETiRet;
@@ -2936,7 +2947,7 @@ int realMain(int argc, char **argv)
/* END core initializations */
- while ((ch = getopt(argc, argv, "46Ac:dehi:f:g:l:m:nqQr::s:t:u:vwx")) != EOF) {
+ while ((ch = getopt(argc, argv, "46Ac:dehi:f:g:l:m:M:nqQr::s:t:u:vwx")) != EOF) {
switch((char)ch) {
case '4':
family = PF_INET;
@@ -2990,14 +3001,17 @@ int realMain(int argc, char **argv)
fprintf(stderr,
"-m option only supported in compatibility modes 0 to 2 - ignored\n");
break;
+ case 'M': /* default module load path */
+ module.SetModDir((uchar*)optarg);
+ break;
case 'n': /* don't fork */
NoFork = 1;
break;
case 'q': /* add hostname if DNS resolving has failed */
- ACLAddHostnameOnFail = 1;
+ *net.pACLAddHostnameOnFail = 1;
break;
case 'Q': /* dont resolve hostnames in ACL to IPs */
- ACLDontResolve = 1;
+ *net.pACLDontResolve = 1;
break;
case 'r': /* accept remote messages */
#ifdef SYSLOG_INET
diff --git a/syslogd.h b/syslogd.h
index 773a272b..a65749be 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -119,6 +119,7 @@ typedef struct filed selector_t; /* new type name */
#define MSG_PARSE_HOSTNAME 1
#define MSG_DONT_PARSE_HOSTNAME 0
rsRetVal parseAndSubmitMessage(char *hname, char *msg, int len, int bParseHost, int flags);
+#include "net.h" /* TODO: remove when you remoe isAllowedSender from here! */
int isAllowedSender(struct AllowedSenders *pAllowRoot, struct sockaddr *pFrom, const char *pszFromHost);
void untty(void);
rsRetVal selectorConstruct(selector_t **ppThis);
diff --git a/tcpsrv.c b/tcpsrv.c
index f89923ca..5e544a04 100644
--- a/tcpsrv.c
+++ b/tcpsrv.c
@@ -74,6 +74,7 @@ DEFobjStaticHelpers
DEFobjCurrIf(conf)
DEFobjCurrIf(tcps_sess)
DEFobjCurrIf(errmsg)
+DEFobjCurrIf(net)
@@ -464,7 +465,7 @@ RUNLOG_VAR("%p", pThis->pUsr);
/* OK, we have a "good" index... */
/* get the host name */
- if(cvthname(&addr, fromHost, fromHostFQDN) != RS_RET_OK) {
+ if(net.cvthname(&addr, fromHost, fromHostFQDN) != RS_RET_OK) {
/* we seem to have something malicous - at least we
* are now told to discard the connection request.
* Error message has been generated by cvthname.
@@ -548,7 +549,7 @@ Run(tcpsrv_t *pThis)
*/
if (pThis->pSocksLstn[i+1] != -1) {
if(Debug)
- debugListenInfo(pThis->pSocksLstn[i+1], "TCP");
+ net.debugListenInfo(pThis->pSocksLstn[i+1], "TCP");
FD_SET(pThis->pSocksLstn[i+1], &readfds);
if(pThis->pSocksLstn[i+1]>maxfds) maxfds=pThis->pSocksLstn[i+1];
}
@@ -558,11 +559,8 @@ Run(tcpsrv_t *pThis)
while(iTCPSess != -1) {
int fdSess;
fdSess = pThis->pSessions[iTCPSess]->sock; // TODO: NOT CLEAN!, use method
-RUNLOG_VAR("%d", iTCPSess);
-RUNLOG_VAR("%d", fdSess);
dbgprintf("Adding TCP Session %d\n", fdSess);
FD_SET(fdSess, &readfds);
-RUNLOG;
if (fdSess>maxfds) maxfds=fdSess;
/* now get next... */
iTCPSess = TCPSessGetNxtSess(pThis, iTCPSess);
@@ -839,6 +837,7 @@ CODESTARTmodInit
/* request objects we use */
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(net, "net"));
ENDmodInit
/* vim:set ai:
diff --git a/template.h b/template.h
index ced26c32..1179fe06 100644
--- a/template.h
+++ b/template.h
@@ -90,6 +90,16 @@ struct templateEntry {
} data;
};
+
+/* interfaces */
+BEGINinterface(tpl) /* name must also be changed in ENDinterface macro! */
+ENDinterface(tpl)
+#define tplCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+
+/* prototypes */
+PROTOTYPEObj(tpl);
+
+
struct template* tplConstruct(void);
struct template *tplAddLine(char* pName, unsigned char** pRestOfConfLine);
struct template *tplFind(char *pName, int iLenName);