1
/* glbl.c - this module holds global defintions and data items.
2
* These are shared among the runtime library. Their use should be
3
* limited to cases where it is actually needed. The main intension for
4
* implementing them was support for the transistion from v2 to v4
5
* (with fully modular design), but it turned out that there may also
6
* be some other good use cases besides backwards-compatibility.
8
* Module begun 2008-04-16 by Rainer Gerhards
10
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
12
* This file is part of the rsyslog runtime library.
14
* The rsyslog runtime library is free software: you can redistribute it and/or modify
15
* it under the terms of the GNU Lesser General Public License as published by
16
* the Free Software Foundation, either version 3 of the License, or
17
* (at your option) any later version.
19
* The rsyslog runtime library is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU Lesser General Public License for more details.
24
* You should have received a copy of the GNU Lesser General Public License
25
* along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
27
* A copy of the GPL can be found in the file "COPYING" in this distribution.
28
* A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
33
#include <sys/socket.h>
38
#include "cfsysline.h"
42
#ifndef DFLT_NETSTRM_DRVR
43
# define DFLT_NETSTRM_DRVR ((uchar*)"ptcp")
50
* For this object, these variables are obviously what makes the "meat" of the
53
static uchar *pszWorkDir = NULL;
54
static int iDefPFFamily = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */
55
static int bDropMalPTRMsgs = 0;/* Drop messages which have malicious PTR records during DNS lookup */
56
static int option_DisallowWarning = 1; /* complain if message from disallowed sender is received */
57
static int bDisableDNS = 0; /* don't look up IP addresses of remote messages */
58
static uchar *LocalHostName = NULL;/* our hostname - read-only after startup */
59
static uchar *LocalDomain; /* our local domain name - read-only after startup */
60
static char **StripDomains = NULL;/* these domains may be stripped before writing logs - r/o after s.u., never touched by init */
61
static char **LocalHosts = NULL;/* these hosts are logged with their hostname - read-only after startup, never touched by init */
62
static uchar *pszDfltNetstrmDrvr = NULL; /* module name of default netstream driver */
63
static uchar *pszDfltNetstrmDrvrCAF = NULL; /* default CA file for the netstrm driver */
64
static uchar *pszDfltNetstrmDrvrKeyFile = NULL; /* default key file for the netstrm driver (server) */
65
static uchar *pszDfltNetstrmDrvrCertFile = NULL; /* default cert file for the netstrm driver (server) */
68
/* define a macro for the simple properties' set and get functions
69
* (which are always the same). This is only suitable for pretty
70
* simple cases which require neither checks nor memory allocation.
72
#define SIMP_PROP(nameFunc, nameVar, dataType) \
73
SIMP_PROP_GET(nameFunc, nameVar, dataType) \
74
SIMP_PROP_SET(nameFunc, nameVar, dataType)
75
#define SIMP_PROP_SET(nameFunc, nameVar, dataType) \
76
static rsRetVal Set##nameFunc(dataType newVal) \
81
#define SIMP_PROP_GET(nameFunc, nameVar, dataType) \
82
static dataType Get##nameFunc(void) \
87
SIMP_PROP(DefPFFamily, iDefPFFamily, int) /* note that in the future we may check the family argument */
88
SIMP_PROP(DropMalPTRMsgs, bDropMalPTRMsgs, int)
89
SIMP_PROP(Option_DisallowWarning, option_DisallowWarning, int)
90
SIMP_PROP(DisableDNS, bDisableDNS, int)
91
SIMP_PROP(LocalDomain, LocalDomain, uchar*)
92
SIMP_PROP(StripDomains, StripDomains, char**)
93
SIMP_PROP(LocalHosts, LocalHosts, char**)
95
SIMP_PROP_SET(LocalHostName, LocalHostName, uchar*)
96
SIMP_PROP_SET(DfltNetstrmDrvr, pszDfltNetstrmDrvr, uchar*) /* TODO: use custom function which frees existing value */
97
SIMP_PROP_SET(DfltNetstrmDrvrCAF, pszDfltNetstrmDrvrCAF, uchar*) /* TODO: use custom function which frees existing value */
98
SIMP_PROP_SET(DfltNetstrmDrvrKeyFile, pszDfltNetstrmDrvrKeyFile, uchar*) /* TODO: use custom function which frees existing value */
99
SIMP_PROP_SET(DfltNetstrmDrvrCertFile, pszDfltNetstrmDrvrCertFile, uchar*) /* TODO: use custom function which frees existing value */
106
/* return our local hostname. if it is not set, "[localhost]" is returned
109
GetLocalHostName(void)
111
return(LocalHostName == NULL ? (uchar*) "[localhost]" : LocalHostName);
115
/* return the current working directory */
119
return(pszWorkDir == NULL ? (uchar*) "" : pszWorkDir);
123
/* return the current default netstream driver */
125
GetDfltNetstrmDrvr(void)
127
return(pszDfltNetstrmDrvr == NULL ? DFLT_NETSTRM_DRVR : pszDfltNetstrmDrvr);
131
/* return the current default netstream driver CA File */
133
GetDfltNetstrmDrvrCAF(void)
135
return(pszDfltNetstrmDrvrCAF);
139
/* return the current default netstream driver key File */
141
GetDfltNetstrmDrvrKeyFile(void)
143
return(pszDfltNetstrmDrvrKeyFile);
147
/* return the current default netstream driver certificate File */
149
GetDfltNetstrmDrvrCertFile(void)
151
return(pszDfltNetstrmDrvrCertFile);
155
/* queryInterface function
156
* rgerhards, 2008-02-21
158
BEGINobjQueryInterface(glbl)
159
CODESTARTobjQueryInterface(glbl)
160
if(pIf->ifVersion != glblCURR_IF_VERSION) { /* check for current version, increment on each change */
161
ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
164
/* ok, we have the right interface, so let's fill it
165
* Please note that we may also do some backwards-compatibility
166
* work here (if we can support an older interface version - that,
167
* of course, also affects the "if" above).
169
pIf->GetWorkDir = GetWorkDir;
170
#define SIMP_PROP(name) \
171
pIf->Get##name = Get##name; \
172
pIf->Set##name = Set##name;
173
SIMP_PROP(DefPFFamily);
174
SIMP_PROP(DropMalPTRMsgs);
175
SIMP_PROP(Option_DisallowWarning);
176
SIMP_PROP(DisableDNS);
177
SIMP_PROP(LocalHostName)
178
SIMP_PROP(LocalDomain)
179
SIMP_PROP(StripDomains)
180
SIMP_PROP(LocalHosts)
181
SIMP_PROP(DfltNetstrmDrvr)
182
SIMP_PROP(DfltNetstrmDrvrCAF)
183
SIMP_PROP(DfltNetstrmDrvrKeyFile)
184
SIMP_PROP(DfltNetstrmDrvrCertFile)
187
ENDobjQueryInterface(glbl)
190
/* Reset config variables to default values.
191
* rgerhards, 2008-04-17
193
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
195
if(pszDfltNetstrmDrvr != NULL) {
196
free(pszDfltNetstrmDrvr);
197
pszDfltNetstrmDrvr = NULL;
199
if(pszDfltNetstrmDrvrCAF != NULL) {
200
free(pszDfltNetstrmDrvrCAF);
201
pszDfltNetstrmDrvrCAF = NULL;
203
if(pszDfltNetstrmDrvrKeyFile != NULL) {
204
free(pszDfltNetstrmDrvrKeyFile);
205
pszDfltNetstrmDrvrKeyFile = NULL;
207
if(pszDfltNetstrmDrvrCertFile != NULL) {
208
free(pszDfltNetstrmDrvrCertFile);
209
pszDfltNetstrmDrvrCertFile = NULL;
211
if(pszWorkDir != NULL) {
221
/* Initialize the glbl class. Must be called as the very first method
222
* before anything else is called inside this class.
223
* rgerhards, 2008-02-19
225
BEGINAbstractObjClassInit(glbl, 1, OBJ_IS_CORE_MODULE) /* class, version */
226
/* request objects we use */
228
/* register config handlers (TODO: we need to implement a way to unregister them) */
229
CHKiRet(regCfSysLineHdlr((uchar *)"workdirectory", 0, eCmdHdlrGetWord, NULL, &pszWorkDir, NULL));
230
CHKiRet(regCfSysLineHdlr((uchar *)"dropmsgswithmaliciousdnsptrrecords", 0, eCmdHdlrBinary, NULL, &bDropMalPTRMsgs, NULL));
231
CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdriver", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvr, NULL));
232
CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercafile", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvrCAF, NULL));
233
CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdriverkeyfile", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvrKeyFile, NULL));
234
CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercertfile", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvrCertFile, NULL));
235
CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
236
ENDObjClassInit(glbl)
239
/* Exit the glbl class.
240
* rgerhards, 2008-04-17
242
BEGINObjClassExit(glbl, OBJ_IS_CORE_MODULE) /* class, version */
243
if(pszDfltNetstrmDrvr != NULL)
244
free(pszDfltNetstrmDrvr);
245
if(pszDfltNetstrmDrvrCAF != NULL)
246
free(pszDfltNetstrmDrvrCAF);
247
if(pszDfltNetstrmDrvrKeyFile != NULL)
248
free(pszDfltNetstrmDrvrKeyFile);
249
if(pszDfltNetstrmDrvrCertFile != NULL)
250
free(pszDfltNetstrmDrvrCertFile);
251
if(pszWorkDir != NULL)
253
if(LocalHostName != NULL)
255
ENDObjClassExit(glbl)