~arges/ubuntu/quantal/rsyslog/fix-lp1059592

« back to all changes in this revision

Viewing changes to runtime/glbl.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-15 21:56:23 UTC
  • mto: (3.2.4 squeeze) (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090215215623-xsycf628eo3kguc0
Tags: upstream-3.20.4
ImportĀ upstreamĀ versionĀ 3.20.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
7
 *
 
8
 * Module begun 2008-04-16 by Rainer Gerhards
 
9
 *
 
10
 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
 
11
 *
 
12
 * This file is part of the rsyslog runtime library.
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 *
 
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/>.
 
26
 *
 
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.
 
29
 */
 
30
 
 
31
#include "config.h"
 
32
#include <stdlib.h>
 
33
#include <sys/socket.h>
 
34
#include <assert.h>
 
35
 
 
36
#include "rsyslog.h"
 
37
#include "obj.h"
 
38
#include "cfsysline.h"
 
39
#include "glbl.h"
 
40
 
 
41
/* some defaults */
 
42
#ifndef DFLT_NETSTRM_DRVR
 
43
#       define DFLT_NETSTRM_DRVR ((uchar*)"ptcp")
 
44
#endif
 
45
 
 
46
/* static data */
 
47
DEFobjStaticHelpers
 
48
 
 
49
/* static data
 
50
 * For this object, these variables are obviously what makes the "meat" of the
 
51
 * class...
 
52
 */
 
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) */
 
66
 
 
67
 
 
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.
 
71
 */
 
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) \
 
77
{ \
 
78
        nameVar = newVal; \
 
79
        return RS_RET_OK; \
 
80
 
81
#define SIMP_PROP_GET(nameFunc, nameVar, dataType) \
 
82
static dataType Get##nameFunc(void) \
 
83
{ \
 
84
        return(nameVar); \
 
85
}
 
86
 
 
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**)
 
94
 
 
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 */
 
100
 
 
101
#undef SIMP_PROP
 
102
#undef SIMP_PROP_SET
 
103
#undef SIMP_PROP_GET
 
104
 
 
105
 
 
106
/* return our local hostname. if it is not set, "[localhost]" is returned
 
107
 */
 
108
static uchar*
 
109
GetLocalHostName(void)
 
110
{
 
111
        return(LocalHostName == NULL ? (uchar*) "[localhost]" : LocalHostName);
 
112
}
 
113
 
 
114
 
 
115
/* return the current working directory */
 
116
static uchar*
 
117
GetWorkDir(void)
 
118
{
 
119
        return(pszWorkDir == NULL ? (uchar*) "" : pszWorkDir);
 
120
}
 
121
 
 
122
 
 
123
/* return the current default netstream driver */
 
124
static uchar*
 
125
GetDfltNetstrmDrvr(void)
 
126
{
 
127
        return(pszDfltNetstrmDrvr == NULL ? DFLT_NETSTRM_DRVR : pszDfltNetstrmDrvr);
 
128
}
 
129
 
 
130
 
 
131
/* return the current default netstream driver CA File */
 
132
static uchar*
 
133
GetDfltNetstrmDrvrCAF(void)
 
134
{
 
135
        return(pszDfltNetstrmDrvrCAF);
 
136
}
 
137
 
 
138
 
 
139
/* return the current default netstream driver key File */
 
140
static uchar*
 
141
GetDfltNetstrmDrvrKeyFile(void)
 
142
{
 
143
        return(pszDfltNetstrmDrvrKeyFile);
 
144
}
 
145
 
 
146
 
 
147
/* return the current default netstream driver certificate File */
 
148
static uchar*
 
149
GetDfltNetstrmDrvrCertFile(void)
 
150
{
 
151
        return(pszDfltNetstrmDrvrCertFile);
 
152
}
 
153
 
 
154
 
 
155
/* queryInterface function
 
156
 * rgerhards, 2008-02-21
 
157
 */
 
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);
 
162
        }
 
163
 
 
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).
 
168
         */
 
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)
 
185
#undef  SIMP_PROP
 
186
finalize_it:
 
187
ENDobjQueryInterface(glbl)
 
188
 
 
189
 
 
190
/* Reset config variables to default values.
 
191
 * rgerhards, 2008-04-17
 
192
 */
 
193
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
 
194
{
 
195
        if(pszDfltNetstrmDrvr != NULL) {
 
196
                free(pszDfltNetstrmDrvr);
 
197
                pszDfltNetstrmDrvr = NULL;
 
198
        }
 
199
        if(pszDfltNetstrmDrvrCAF != NULL) {
 
200
                free(pszDfltNetstrmDrvrCAF);
 
201
                pszDfltNetstrmDrvrCAF = NULL;
 
202
        }
 
203
        if(pszDfltNetstrmDrvrKeyFile != NULL) {
 
204
                free(pszDfltNetstrmDrvrKeyFile);
 
205
                pszDfltNetstrmDrvrKeyFile = NULL;
 
206
        }
 
207
        if(pszDfltNetstrmDrvrCertFile != NULL) {
 
208
                free(pszDfltNetstrmDrvrCertFile);
 
209
                pszDfltNetstrmDrvrCertFile = NULL;
 
210
        }
 
211
        if(pszWorkDir != NULL) {
 
212
                free(pszWorkDir);
 
213
                pszWorkDir = NULL;
 
214
        }
 
215
        bDropMalPTRMsgs = 0;
 
216
        return RS_RET_OK;
 
217
}
 
218
 
 
219
 
 
220
 
 
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
 
224
 */
 
225
BEGINAbstractObjClassInit(glbl, 1, OBJ_IS_CORE_MODULE) /* class, version */
 
226
        /* request objects we use */
 
227
 
 
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)
 
237
 
 
238
 
 
239
/* Exit the glbl class.
 
240
 * rgerhards, 2008-04-17
 
241
 */
 
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)
 
252
                free(pszWorkDir);
 
253
        if(LocalHostName != NULL)
 
254
                free(LocalHostName);
 
255
ENDObjClassExit(glbl)
 
256
 
 
257
/* vi:set ai:
 
258
 */