Debian Codegraph @

runtime/glbl.c

raw
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-2024 Rainer Gerhards and Adiscon GmbH.
11 *
12 * This file is part of the rsyslog runtime library.
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 * -or-
20 * see COPYING.ASL20 in the source distribution
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28
29 #include "config.h"
30 #include <stdlib.h>
31 #include <sys/socket.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <sys/wait.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <pthread.h>
38 #include <ctype.h>
39 #include <assert.h>
40 #include <stdint.h>
41 #include <string.h>
42 #include <errno.h>
43 #include <json.h>
44
45 #include "rsyslog.h"
46 #include "obj.h"
47 #include "unicode-helper.h"
48 #include "cfsysline.h"
49 #include "glbl.h"
50 #include "prop.h"
51 #include "atomic.h"
52 #include "errmsg.h"
53 #include "action.h"
54 #include "parserif.h"
55 #include "rainerscript.h"
56 #include "srUtils.h"
57 #include "operatingstate.h"
58 #include "net.h"
59 #include "rsconf.h"
60 #include "queue.h"
61 #include "dnscache.h"
62 #include "parser.h"
63 #include "timezones.h"
64
65 /* some defaults */
66 #ifndef DFLT_NETSTRM_DRVR
67 #define DFLT_NETSTRM_DRVR ((uchar *)"ptcp")
68 #endif
69
70 /* static data */
71 DEFobjStaticHelpers;
72 DEFobjCurrIf(prop) DEFobjCurrIf(net)
73
74 /* static data
75 * For this object, these variables are obviously what makes the "meat" of the
76 * class...
77 */
78
79 static struct cnfobj *mainqCnfObj = NULL; /* main queue object, to be used later in startup sequence */
80 static int bPreserveFQDN = 0; /* should FQDNs always be preserved? */
81 static prop_t *propLocalIPIF = NULL; /* IP address to report for the local host (default is 127.0.0.1) */
82 static int propLocalIPIF_set = 0; /* is propLocalIPIF already set? */
83 static prop_t *propLocalHostName = NULL; /* our hostname as FQDN - read-only after startup */
84 static prop_t *propLocalHostNameToDelete = NULL; /* see GenerateLocalHostName function hdr comment! */
85 static uchar *LocalHostName = NULL; /* our hostname - read-only after startup, except HUP */
86 static uchar *LocalHostNameOverride = NULL; /* user-overridden hostname - read-only after startup */
87 static uchar *LocalFQDNName = NULL; /* our hostname as FQDN - read-only after startup, except HUP */
88 static uchar *LocalDomain = NULL; /* our local domain name - read-only after startup, except HUP */
89 static int iMaxLine = 8096;
90 int bTerminateInputs = 0; /* global switch that inputs shall terminate ASAP (1=> terminate) */
91 int glblUnloadModules = 1;
92 int glblAbortOnProgramError = 0;
93 char **glblDbgFiles = NULL;
94 size_t glblDbgFilesNum = 0;
95 int glblDbgWhitelist = 1;
96 int glblPermitCtlC = 0;
97 /* For global option CompactJsonString:
98 * Compact the JSON variable string, without extra space.
99 * Considering compatibility issues, the default options(CompactJsonString = "off")
100 * keep the same as before.
101 */
102 int glblJsonFormatOpt = JSON_C_TO_STRING_SPACED;
103
104
105 pid_t glbl_ourpid;
106 #ifndef HAVE_ATOMIC_BUILTINS
107 DEF_ATOMIC_HELPER_MUT(mutTerminateInputs);
108 #endif
109 #ifdef USE_UNLIMITED_SELECT
110 static int iFdSetSize = howmany(FD_SETSIZE, __NFDBITS) * sizeof(fd_mask); /* size of select() bitmask in bytes */
111 #endif
112 static uchar *SourceIPofLocalClient = NULL; /* [ar] Source IP for local client to be used on multihomed host */
113
114 /* tables for interfacing with the v6 config system */
115 static struct cnfparamdescr cnfparamdescr[] = {
116 {"workdirectory", eCmdHdlrString, 0},
117 {"operatingstatefile", eCmdHdlrString, 0},
118 {"dropmsgswithmaliciousdnsptrrecords", eCmdHdlrBinary, 0},
119 {"localhostname", eCmdHdlrGetWord, 0},
120 {"compactjsonstring", eCmdHdlrBinary, 0},
121 {"preservefqdn", eCmdHdlrBinary, 0},
122 {"debug.onshutdown", eCmdHdlrBinary, 0},
123 {"debug.logfile", eCmdHdlrString, 0},
124 {"debug.gnutls", eCmdHdlrNonNegInt, 0},
125 {"debug.abortonprogramerror", eCmdHdlrBinary, 0},
126 {"debug.unloadmodules", eCmdHdlrBinary, 0},
127 {"defaultnetstreamdrivercafile", eCmdHdlrString, 0},
128 {"defaultnetstreamdrivercrlfile", eCmdHdlrString, 0},
129 {"defaultnetstreamdriverkeyfile", eCmdHdlrString, 0},
130 {"defaultnetstreamdrivercertfile", eCmdHdlrString, 0},
131 {"defaultnetstreamdriver", eCmdHdlrString, 0},
132 {"defaultopensslengine", eCmdHdlrString, 0},
133 {"netstreamdrivercaextrafiles", eCmdHdlrString, 0},
134 {"maxmessagesize", eCmdHdlrSize, 0},
135 {"oversizemsg.errorfile", eCmdHdlrGetWord, 0},
136 {"oversizemsg.report", eCmdHdlrBinary, 0},
137 {"oversizemsg.input.mode", eCmdHdlrGetWord, 0},
138 {"reportchildprocessexits", eCmdHdlrGetWord, 0},
139 {"action.reportsuspension", eCmdHdlrBinary, 0},
140 {"action.reportsuspensioncontinuation", eCmdHdlrBinary, 0},
141 {"parser.controlcharacterescapeprefix", eCmdHdlrGetChar, 0},
142 {"parser.droptrailinglfonreception", eCmdHdlrBinary, 0},
143 {"parser.escapecontrolcharactersonreceive", eCmdHdlrBinary, 0},
144 {"parser.spacelfonreceive", eCmdHdlrBinary, 0},
145 {"parser.escape8bitcharactersonreceive", eCmdHdlrBinary, 0},
146 {"parser.escapecontrolcharactertab", eCmdHdlrBinary, 0},
147 {"parser.escapecontrolcharacterscstyle", eCmdHdlrBinary, 0},
148 {"parser.parsehostnameandtag", eCmdHdlrBinary, 0},
149 {"parser.permitslashinprogramname", eCmdHdlrBinary, 0},
150 {"stdlog.channelspec", eCmdHdlrString, 0},
151 {"janitor.interval", eCmdHdlrPositiveInt, 0},
152 {"senders.reportnew", eCmdHdlrBinary, 0},
153 {"senders.reportgoneaway", eCmdHdlrBinary, 0},
154 {"senders.timeoutafter", eCmdHdlrPositiveInt, 0},
155 {"senders.keeptrack", eCmdHdlrBinary, 0},
156 {"inputs.timeout.shutdown", eCmdHdlrPositiveInt, 0},
157 {"privdrop.group.keepsupplemental", eCmdHdlrBinary, 0},
158 {"privdrop.group.id", eCmdHdlrPositiveInt, 0},
159 {"privdrop.group.name", eCmdHdlrGID, 0},
160 {"privdrop.user.id", eCmdHdlrPositiveInt, 0},
161 {"privdrop.user.name", eCmdHdlrUID, 0},
162 {"net.ipprotocol", eCmdHdlrGetWord, 0},
163 {"net.acladdhostnameonfail", eCmdHdlrBinary, 0},
164 {"net.aclresolvehostname", eCmdHdlrBinary, 0},
165 {"net.enabledns", eCmdHdlrBinary, 0},
166 {"net.permitACLwarning", eCmdHdlrBinary, 0},
167 {"abortonuncleanconfig", eCmdHdlrBinary, 0},
168 {"abortonfailedqueuestartup", eCmdHdlrBinary, 0},
169 {"variables.casesensitive", eCmdHdlrBinary, 0},
170 {"environment", eCmdHdlrArray, 0},
171 {"processinternalmessages", eCmdHdlrBinary, 0},
172 {"umask", eCmdHdlrFileCreateMode, 0},
173 {"security.abortonidresolutionfail", eCmdHdlrBinary, 0},
174 {"internal.developeronly.options", eCmdHdlrInt, 0},
175 {"internalmsg.ratelimit.interval", eCmdHdlrPositiveInt, 0},
176 {"internalmsg.ratelimit.burst", eCmdHdlrPositiveInt, 0},
177 {"internalmsg.severity", eCmdHdlrSeverity, 0},
178 {"allmessagestostderr", eCmdHdlrBinary, 0},
179 {"errormessagestostderr.maxnumber", eCmdHdlrPositiveInt, 0},
180 {"shutdown.enable.ctlc", eCmdHdlrBinary, 0},
181 {"default.action.queue.timeoutshutdown", eCmdHdlrInt, 0},
182 {"default.action.queue.timeoutactioncompletion", eCmdHdlrInt, 0},
183 {"default.action.queue.timeoutenqueue", eCmdHdlrInt, 0},
184 {"default.action.queue.timeoutworkerthreadshutdown", eCmdHdlrInt, 0},
185 {"default.ruleset.queue.timeoutshutdown", eCmdHdlrInt, 0},
186 {"default.ruleset.queue.timeoutactioncompletion", eCmdHdlrInt, 0},
187 {"default.ruleset.queue.timeoutenqueue", eCmdHdlrInt, 0},
188 {"default.ruleset.queue.timeoutworkerthreadshutdown", eCmdHdlrInt, 0},
189 {"reverselookup.cache.ttl.default", eCmdHdlrNonNegInt, 0},
190 {"reverselookup.cache.ttl.enable", eCmdHdlrBinary, 0},
191 {"parser.supportcompressionextension", eCmdHdlrBinary, 0},
192 {"shutdown.queue.doublesize", eCmdHdlrBinary, 0},
193 {"debug.files", eCmdHdlrArray, 0},
194 {"debug.whitelist", eCmdHdlrBinary, 0},
195 {"libcapng.default", eCmdHdlrBinary, 0},
196 {"libcapng.enable", eCmdHdlrBinary, 0},
197 };
198 static struct cnfparamblk paramblk = {CNFPARAMBLK_VERSION, sizeof(cnfparamdescr) / sizeof(struct cnfparamdescr),
199 cnfparamdescr};
200
201 static struct cnfparamvals *cnfparamvals = NULL;
202 /* we need to support multiple calls into our param block, so we need
203 * to persist the current settings. Note that this must be re-set
204 * each time a new config load begins. This is a hint if we will
205 * ever implement multi-config support, which is just an idea right now.
206 */
207
208 int glblGetMaxLine(rsconf_t *cnf) {
209 /* glblGetMaxLine might be invoked before our configuration exists */
210 return ((cnf != NULL) ? cnf->globals.iMaxLine : iMaxLine);
211 }
212
213
214 int GetGnuTLSLoglevel(rsconf_t *cnf) {
215 return (cnf->globals.iGnuTLSLoglevel);
216 }
217
218 /* define a macro for the simple properties' set and get functions
219 * (which are always the same). This is only suitable for pretty
220 * simple cases which require neither checks nor memory allocation.
221 */
222 #define SIMP_PROP(nameFunc, nameVar, dataType) \
223 SIMP_PROP_GET(nameFunc, nameVar, dataType) \
224 SIMP_PROP_SET(nameFunc, nameVar, dataType)
225 #define SIMP_PROP_SET(nameFunc, nameVar, dataType) \
226 static rsRetVal Set##nameFunc(dataType newVal) { \
227 nameVar = newVal; \
228 return RS_RET_OK; \
229 }
230 #define SIMP_PROP_GET(nameFunc, nameVar, dataType) \
231 static dataType Get##nameFunc(void) { \
232 return (nameVar); \
233 }
234
235 SIMP_PROP(PreserveFQDN, bPreserveFQDN, int)
236 SIMP_PROP(mainqCnfObj, mainqCnfObj, struct cnfobj *)
237 #ifdef USE_UNLIMITED_SELECT
238 SIMP_PROP(FdSetSize, iFdSetSize, int)
239 #endif
240
241 #undef SIMP_PROP
242 #undef SIMP_PROP_SET
243 #undef SIMP_PROP_GET
244
245 /* This is based on the previous SIMP_PROP but as a getter it uses
246 * additional parameter specifying the configuration it belongs to.
247 * The setter uses loadConf
248 */
249 #define SIMP_PROP(nameFunc, nameVar, dataType) \
250 SIMP_PROP_GET(nameFunc, nameVar, dataType) \
251 SIMP_PROP_SET(nameFunc, nameVar, dataType)
252 #define SIMP_PROP_SET(nameFunc, nameVar, dataType) \
253 static rsRetVal Set##nameFunc(dataType newVal) { \
254 loadConf->globals.nameVar = newVal; \
255 return RS_RET_OK; \
256 }
257 #define SIMP_PROP_GET(nameFunc, nameVar, dataType) \
258 static dataType Get##nameFunc(rsconf_t *cnf) { \
259 return (cnf->globals.nameVar); \
260 }
261
262 SIMP_PROP(DropMalPTRMsgs, bDropMalPTRMsgs, int)
263 SIMP_PROP(DisableDNS, bDisableDNS, int)
264 SIMP_PROP(ParserEscapeControlCharactersCStyle, parser.bParserEscapeCCCStyle, int)
265 SIMP_PROP(ParseHOSTNAMEandTAG, parser.bParseHOSTNAMEandTAG, int)
266 SIMP_PROP(OptionDisallowWarning, optionDisallowWarning, int)
267 /* We omit setter on purpose, because we want to customize it */
268 SIMP_PROP_GET(DfltNetstrmDrvrCAF, pszDfltNetstrmDrvrCAF, uchar *)
269 SIMP_PROP_GET(DfltNetstrmDrvrCRLF, pszDfltNetstrmDrvrCRLF, uchar *)
270 SIMP_PROP_GET(DfltNetstrmDrvrCertFile, pszDfltNetstrmDrvrCertFile, uchar *)
271 SIMP_PROP_GET(DfltNetstrmDrvrKeyFile, pszDfltNetstrmDrvrKeyFile, uchar *)
272 SIMP_PROP_GET(NetstrmDrvrCAExtraFiles, pszNetstrmDrvrCAExtraFiles, uchar *)
273 SIMP_PROP_GET(ParserControlCharacterEscapePrefix, parser.cCCEscapeChar, uchar)
274 SIMP_PROP_GET(ParserDropTrailingLFOnReception, parser.bDropTrailingLF, int)
275 SIMP_PROP_GET(ParserEscapeControlCharactersOnReceive, parser.bEscapeCCOnRcv, int)
276 SIMP_PROP_GET(ParserSpaceLFOnReceive, parser.bSpaceLFOnRcv, int)
277 SIMP_PROP_GET(ParserEscape8BitCharactersOnReceive, parser.bEscape8BitChars, int)
278 SIMP_PROP_GET(ParserEscapeControlCharacterTab, parser.bEscapeTab, int)
279
280 #undef SIMP_PROP
281 #undef SIMP_PROP_SET
282 #undef SIMP_PROP_GET
283
284 /* return global input termination status
285 * rgerhards, 2009-07-20
286 */
287 static int GetGlobalInputTermState(void) {
288 return ATOMIC_FETCH_32BIT(&bTerminateInputs, &mutTerminateInputs);
289 }
290
291
292 /* set global termination state to "terminate". Note that this is a
293 * "once in a lifetime" action which can not be undone. -- gerhards, 2009-07-20
294 */
295 static void SetGlobalInputTermination(void) {
296 ATOMIC_STORE_1_TO_INT(&bTerminateInputs, &mutTerminateInputs);
297 }
298
299
300 /* set the local host IP address to a specific string. Helper to
301 * small set of functions. No checks done, caller must ensure it is
302 * ok to call. Most importantly, the IP address must not already have
303 * been set. -- rgerhards, 2012-03-21
304 */
305 static rsRetVal storeLocalHostIPIF(uchar *myIP) {
306 DEFiRet;
307 if (propLocalIPIF != NULL) {
308 CHKiRet(prop.Destruct(&propLocalIPIF));
309 }
310 CHKiRet(prop.Construct(&propLocalIPIF));
311 CHKiRet(prop.SetString(propLocalIPIF, myIP, ustrlen(myIP)));
312 CHKiRet(prop.ConstructFinalize(propLocalIPIF));
313 DBGPRINTF("rsyslog/glbl: using '%s' as localhost IP\n", myIP);
314 finalize_it:
315 RETiRet;
316 }
317
318
319 /* This function is used to set the IP address that is to be
320 * reported for the local host. Note that in order to ease things
321 * for the v6 config interface, we do not allow this to be set more
322 * than once.
323 * rgerhards, 2012-03-21
324 */
325 static rsRetVal setLocalHostIPIF(void __attribute__((unused)) * pVal, uchar *pNewVal) {
326 uchar myIP[128];
327 rsRetVal localRet;
328 DEFiRet;
329
330 CHKiRet(objUse(net, CORE_COMPONENT));
331
332 if (propLocalIPIF_set) {
333 LogError(0, RS_RET_ERR,
334 "$LocalHostIPIF is already set "
335 "and cannot be reset; place it at TOP OF rsyslog.conf!");
336 ABORT_FINALIZE(RS_RET_ERR);
337 }
338
339 localRet = net.GetIFIPAddr(pNewVal, AF_UNSPEC, myIP, (int)sizeof(myIP));
340 if (localRet != RS_RET_OK) {
341 LogError(0, RS_RET_ERR,
342 "$LocalHostIPIF: IP address for interface "
343 "'%s' cannnot be obtained - ignoring directive",
344 pNewVal);
345 } else {
346 storeLocalHostIPIF(myIP);
347 }
348
349
350 finalize_it:
351 free(pNewVal); /* no longer needed -> is in prop! */
352 RETiRet;
353 }
354
355
356 /* This function is used to set the global work directory name.
357 * It verifies that the provided directory actually exists and
358 * emits an error message if not.
359 * rgerhards, 2011-02-16
360 */
361 static rsRetVal setWorkDir(void __attribute__((unused)) * pVal, uchar *pNewVal) {
362 size_t lenDir;
363 int i;
364 struct stat sb;
365 DEFiRet;
366
367 /* remove trailing slashes */
368 lenDir = ustrlen(pNewVal);
369 i = lenDir - 1;
370 while (i > 0 && pNewVal[i] == '/') {
371 --i;
372 }
373
374 if (i < 0) {
375 LogError(0, RS_RET_ERR_WRKDIR,
376 "$WorkDirectory: empty value "
377 "- directive ignored");
378 ABORT_FINALIZE(RS_RET_ERR_WRKDIR);
379 }
380
381 if (i != (int)lenDir - 1) {
382 pNewVal[i + 1] = '\0';
383 LogError(0, RS_RET_WRN_WRKDIR,
384 "$WorkDirectory: trailing slashes "
385 "removed, new value is '%s'",
386 pNewVal);
387 }
388
389 if (stat((char *)pNewVal, &sb) != 0) {
390 LogError(0, RS_RET_ERR_WRKDIR,
391 "$WorkDirectory: %s can not be "
392 "accessed, probably does not exist - directive ignored",
393 pNewVal);
394 ABORT_FINALIZE(RS_RET_ERR_WRKDIR);
395 }
396
397 if (!S_ISDIR(sb.st_mode)) {
398 LogError(0, RS_RET_ERR_WRKDIR, "$WorkDirectory: %s not a directory - directive ignored", pNewVal);
399 ABORT_FINALIZE(RS_RET_ERR_WRKDIR);
400 }
401
402 free(loadConf->globals.pszWorkDir);
403 loadConf->globals.pszWorkDir = pNewVal;
404
405 finalize_it:
406 RETiRet;
407 }
408
409
410 static rsRetVal setDfltNetstrmDrvrCAF(void __attribute__((unused)) * pVal, uchar *pNewVal) {
411 DEFiRet;
412 FILE *fp;
413 free(loadConf->globals.pszDfltNetstrmDrvrCAF);
414 loadConf->globals.pszDfltNetstrmDrvrCAF = pNewVal;
415 fp = fopen((const char *)pNewVal, "r");
416 if (fp == NULL) {
417 LogError(errno, RS_RET_NO_FILE_ACCESS,
418 "error: defaultnetstreamdrivercafile file '%s' "
419 "could not be accessed",
420 pNewVal);
421 } else {
422 fclose(fp);
423 }
424
425 RETiRet;
426 }
427
428 static rsRetVal setNetstrmDrvrCAExtraFiles(void __attribute__((unused)) * pVal, uchar *pNewVal) {
429 DEFiRet;
430 FILE *fp;
431 char *token;
432 char *saveptr;
433 int error = 0;
434 char *valCopy = NULL;
435
436 free(loadConf->globals.pszNetstrmDrvrCAExtraFiles);
437
438 /* Validate files without modifying the original comma-separated string */
439 if (pNewVal != NULL) {
440 valCopy = strdup((const char *)pNewVal);
441 if (valCopy == NULL) {
442 LogError(errno, RS_RET_OUT_OF_MEMORY, "error: strdup failed in setNetstrmDrvrCAExtraFiles");
443 free(pNewVal);
444 ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
445 }
446 for (token = strtok_r(valCopy, ",", &saveptr); token != NULL; token = strtok_r(NULL, ",", &saveptr)) {
447 while (isspace((unsigned char)*token)) {
448 token++;
449 }
450 char *end = token + strlen(token) - 1;
451 while (end > token && isspace((unsigned char)*end)) {
452 end--;
453 }
454 *(end + 1) = '\0';
455
456 if (*token == '\0') {
457 continue;
458 }
459
460 fp = fopen((const char *)token, "r");
461 if (fp == NULL) {
462 LogError(errno, RS_RET_NO_FILE_ACCESS,
463 "error: netstreamdrivercaextrafiles file '%s' "
464 "could not be accessed",
465 token);
466 error = 1;
467 } else {
468 fclose(fp);
469 }
470 }
471 }
472
473 if (!error) {
474 loadConf->globals.pszNetstrmDrvrCAExtraFiles = pNewVal;
475 } else {
476 /* Validation failed: prevent leak of newly allocated pNewVal */
477 free(pNewVal);
478 loadConf->globals.pszNetstrmDrvrCAExtraFiles = NULL;
479 }
480
481 finalize_it:
482 if (valCopy != NULL) {
483 free(valCopy);
484 }
485 RETiRet;
486 }
487
488 static rsRetVal setDfltNetstrmDrvrCRLF(void __attribute__((unused)) * pVal, uchar *pNewVal) {
489 DEFiRet;
490 FILE *fp;
491 free(loadConf->globals.pszDfltNetstrmDrvrCRLF);
492 loadConf->globals.pszDfltNetstrmDrvrCRLF = pNewVal;
493 fp = fopen((const char *)pNewVal, "r");
494 if (fp == NULL) {
495 LogError(errno, RS_RET_NO_FILE_ACCESS,
496 "error: defaultnetstreamdrivercrlfile file '%s' "
497 "could not be accessed",
498 pNewVal);
499 } else {
500 fclose(fp);
501 }
502
503 RETiRet;
504 }
505
506
507 static rsRetVal setDfltNetstrmDrvrCertFile(void __attribute__((unused)) * pVal, uchar *pNewVal) {
508 DEFiRet;
509 FILE *fp;
510
511 free(loadConf->globals.pszDfltNetstrmDrvrCertFile);
512 loadConf->globals.pszDfltNetstrmDrvrCertFile = pNewVal;
513 fp = fopen((const char *)pNewVal, "r");
514 if (fp == NULL) {
515 LogError(errno, RS_RET_NO_FILE_ACCESS,
516 "error: defaultnetstreamdrivercertfile '%s' "
517 "could not be accessed",
518 pNewVal);
519 } else {
520 fclose(fp);
521 }
522
523 RETiRet;
524 }
525
526 static rsRetVal setDfltNetstrmDrvrKeyFile(void __attribute__((unused)) * pVal, uchar *pNewVal) {
527 DEFiRet;
528 FILE *fp;
529
530 free(loadConf->globals.pszDfltNetstrmDrvrKeyFile);
531 loadConf->globals.pszDfltNetstrmDrvrKeyFile = pNewVal;
532 fp = fopen((const char *)pNewVal, "r");
533 if (fp == NULL) {
534 LogError(errno, RS_RET_NO_FILE_ACCESS,
535 "error: defaultnetstreamdriverkeyfile '%s' "
536 "could not be accessed",
537 pNewVal);
538 } else {
539 fclose(fp);
540 }
541
542 RETiRet;
543 }
544
545 static rsRetVal setDfltNetstrmDrvr(void __attribute__((unused)) * pVal, uchar *pNewVal) {
546 DEFiRet;
547 free(loadConf->globals.pszDfltNetstrmDrvr);
548 loadConf->globals.pszDfltNetstrmDrvr = pNewVal;
549 RETiRet;
550 }
551
552 static rsRetVal setDfltOpensslEngine(void __attribute__((unused)) * pVal, uchar *pNewVal) {
553 DEFiRet;
554 free(loadConf->globals.pszDfltOpensslEngine);
555 loadConf->globals.pszDfltOpensslEngine = pNewVal;
556 RETiRet;
557 }
558
559
560 static rsRetVal setParserControlCharacterEscapePrefix(void __attribute__((unused)) * pVal, uchar *pNewVal) {
561 DEFiRet;
562 loadConf->globals.parser.cCCEscapeChar = *pNewVal;
563 RETiRet;
564 }
565
566 static rsRetVal setParserDropTrailingLFOnReception(void __attribute__((unused)) * pVal, int pNewVal) {
567 DEFiRet;
568 loadConf->globals.parser.bDropTrailingLF = pNewVal;
569 RETiRet;
570 }
571
572 static rsRetVal setParserEscapeControlCharactersOnReceive(void __attribute__((unused)) * pVal, int pNewVal) {
573 DEFiRet;
574 loadConf->globals.parser.bEscapeCCOnRcv = pNewVal;
575 RETiRet;
576 }
577
578 static rsRetVal setParserSpaceLFOnReceive(void __attribute__((unused)) * pVal, int pNewVal) {
579 DEFiRet;
580 loadConf->globals.parser.bSpaceLFOnRcv = pNewVal;
581 RETiRet;
582 }
583
584 static rsRetVal setParserEscape8BitCharactersOnReceive(void __attribute__((unused)) * pVal, int pNewVal) {
585 DEFiRet;
586 loadConf->globals.parser.bEscape8BitChars = pNewVal;
587 RETiRet;
588 }
589
590 static rsRetVal setParserEscapeControlCharacterTab(void __attribute__((unused)) * pVal, int pNewVal) {
591 DEFiRet;
592 loadConf->globals.parser.bEscapeTab = pNewVal;
593 RETiRet;
594 }
595
596 /* This function is used both by legacy and RainerScript conf. It is a real setter. */
597 static void setMaxLine(const int64_t iNew) {
598 if (iNew < 128) {
599 LogError(0, RS_RET_INVALID_VALUE,
600 "maxMessageSize tried to set "
601 "to %lld, but cannot be less than 128 - set to 128 "
602 "instead",
603 (long long)iNew);
604 loadConf->globals.iMaxLine = 128;
605 } else if (iNew > (int64_t)INT_MAX) {
606 LogError(0, RS_RET_INVALID_VALUE,
607 "maxMessageSize larger than "
608 "INT_MAX (%d) - reduced to INT_MAX",
609 INT_MAX);
610 loadConf->globals.iMaxLine = INT_MAX;
611 } else {
612 loadConf->globals.iMaxLine = (int)iNew;
613 }
614 }
615
616
617 static rsRetVal legacySetMaxMessageSize(void __attribute__((unused)) * pVal, int64_t iNew) {
618 setMaxLine(iNew);
619 return RS_RET_OK;
620 }
621
622 static rsRetVal setDebugFile(void __attribute__((unused)) * pVal, uchar *pNewVal) {
623 DEFiRet;
624 dbgSetDebugFile(pNewVal);
625 free(pNewVal);
626 RETiRet;
627 }
628
629 static rsRetVal setDebugLevel(void __attribute__((unused)) * pVal, int level) {
630 DEFiRet;
631 dbgSetDebugLevel(level);
632 dbgprintf("debug level %d set via config file\n", level);
633 dbgprintf("This is rsyslog version " VERSION "\n");
634 RETiRet;
635 }
636
637 static rsRetVal ATTR_NONNULL() setOversizeMsgInputMode(const uchar *const mode) {
638 DEFiRet;
639 if (!strcmp((char *)mode, "truncate")) {
640 loadConf->globals.oversizeMsgInputMode = glblOversizeMsgInputMode_Truncate;
641 } else if (!strcmp((char *)mode, "split")) {
642 loadConf->globals.oversizeMsgInputMode = glblOversizeMsgInputMode_Split;
643 } else if (!strcmp((char *)mode, "accept")) {
644 loadConf->globals.oversizeMsgInputMode = glblOversizeMsgInputMode_Accept;
645 } else {
646 loadConf->globals.oversizeMsgInputMode = glblOversizeMsgInputMode_Truncate;
647 }
648 RETiRet;
649 }
650
651 static rsRetVal ATTR_NONNULL() setReportChildProcessExits(const uchar *const mode) {
652 DEFiRet;
653 if (!strcmp((char *)mode, "none")) {
654 loadConf->globals.reportChildProcessExits = REPORT_CHILD_PROCESS_EXITS_NONE;
655 } else if (!strcmp((char *)mode, "errors")) {
656 loadConf->globals.reportChildProcessExits = REPORT_CHILD_PROCESS_EXITS_ERRORS;
657 } else if (!strcmp((char *)mode, "all")) {
658 loadConf->globals.reportChildProcessExits = REPORT_CHILD_PROCESS_EXITS_ALL;
659 } else {
660 LogError(0, RS_RET_CONF_PARAM_INVLD,
661 "invalid value '%s' for global parameter reportChildProcessExits -- ignored", mode);
662 iRet = RS_RET_CONF_PARAM_INVLD;
663 }
664 RETiRet;
665 }
666
667 static int getDefPFFamily(rsconf_t *cnf) {
668 return cnf->globals.iDefPFFamily;
669 }
670
671 /* return our local IP.
672 * If no local IP is set, "127.0.0.1" is selected *and* set. This
673 * is an intensional side effect that we do in order to keep things
674 * consistent and avoid config errors (this will make us not accept
675 * setting the local IP address once a module has obtained it - so
676 * it forces the $LocalHostIPIF directive high up in rsyslog.conf)
677 * rgerhards, 2012-03-21
678 */
679 static prop_t *GetLocalHostIP(void) {
680 assert(propLocalIPIF != NULL);
681 return (propLocalIPIF);
682 }
683
684
685 /* set our local hostname. Free previous hostname, if it was already set.
686 * Note that we do now do this in a thread. As such, the method here
687 * is NOT 100% clean. If we run into issues, we need to think about
688 * refactoring the whole way we handle the local host name processing.
689 * Possibly using a PROP might be the right solution then.
690 */
691 static rsRetVal SetLocalHostName(uchar *const newname) {
692 uchar *toFree;
693 if (LocalHostName == NULL || strcmp((const char *)LocalHostName, (const char *)newname)) {
694 toFree = LocalHostName;
695 LocalHostName = newname;
696 } else {
697 toFree = newname;
698 }
699 free(toFree);
700 return RS_RET_OK;
701 }
702
703
704 /* return our local hostname. if it is not set, "[localhost]" is returned
705 */
706 uchar *glblGetLocalHostName(void) {
707 uchar *pszRet;
708
709 if (LocalHostNameOverride != NULL) {
710 pszRet = LocalHostNameOverride;
711 goto done;
712 }
713
714 if (LocalHostName == NULL)
715 pszRet = (uchar *)"[localhost]";
716 else {
717 if (GetPreserveFQDN() == 1)
718 pszRet = LocalFQDNName;
719 else
720 pszRet = LocalHostName;
721 }
722 done:
723 return (pszRet);
724 }
725
726
727 /* return the name of the file where oversize messages are written to
728 */
729 uchar *glblGetOversizeMsgErrorFile(rsconf_t *cnf) {
730 return cnf->globals.oversizeMsgErrorFile;
731 }
732
733 const uchar *glblGetOperatingStateFile(rsconf_t *cnf) {
734 return cnf->globals.operatingStateFile;
735 }
736
737 /* return the mode with which oversize messages will be put forward
738 */
739 int glblGetOversizeMsgInputMode(rsconf_t *cnf) {
740 return cnf->globals.oversizeMsgInputMode;
741 }
742
743 int glblReportOversizeMessage(rsconf_t *cnf) {
744 return cnf->globals.reportOversizeMsg;
745 }
746
747
748 /* logs a message indicating that a child process has terminated.
749 * If name != NULL, prints it as the program name.
750 */
751 void glblReportChildProcessExit(rsconf_t *cnf, const uchar *name, pid_t pid, int status) {
752 DBGPRINTF("waitpid for child %ld returned status: %2.2x\n", (long)pid, status);
753
754 if (cnf->globals.reportChildProcessExits == REPORT_CHILD_PROCESS_EXITS_NONE ||
755 (cnf->globals.reportChildProcessExits == REPORT_CHILD_PROCESS_EXITS_ERRORS && WIFEXITED(status) &&
756 WEXITSTATUS(status) == 0)) {
757 return;
758 }
759
760 if (WIFEXITED(status)) {
761 int severity = WEXITSTATUS(status) == 0 ? LOG_INFO : LOG_WARNING;
762 if (name != NULL) {
763 LogMsg(0, NO_ERRCODE, severity, "program '%s' (pid %ld) exited with status %d", name, (long)pid,
764 WEXITSTATUS(status));
765 } else {
766 LogMsg(0, NO_ERRCODE, severity, "child process (pid %ld) exited with status %d", (long)pid,
767 WEXITSTATUS(status));
768 }
769 } else if (WIFSIGNALED(status)) {
770 if (name != NULL) {
771 LogMsg(0, NO_ERRCODE, LOG_WARNING, "program '%s' (pid %ld) terminated by signal %d", name, (long)pid,
772 WTERMSIG(status));
773 } else {
774 LogMsg(0, NO_ERRCODE, LOG_WARNING, "child process (pid %ld) terminated by signal %d", (long)pid,
775 WTERMSIG(status));
776 }
777 }
778 }
779
780
781 /* set our local domain name. Free previous domain, if it was already set.
782 */
783 static rsRetVal SetLocalDomain(uchar *newname) {
784 free(LocalDomain);
785 LocalDomain = newname;
786 return RS_RET_OK;
787 }
788
789
790 /* return our local hostname. if it is not set, "[localhost]" is returned
791 */
792 static uchar *GetLocalDomain(void) {
793 return LocalDomain;
794 }
795
796
797 /* generate the local hostname property. This must be done after the hostname info
798 * has been set as well as PreserveFQDN.
799 * rgerhards, 2009-06-30
800 * NOTE: This function tries to avoid locking by not destructing the previous value
801 * immediately. This is so that current readers can continue to use the previous name.
802 * Otherwise, we would need to use read/write locks to protect the update process.
803 * In order to do so, we save the previous value and delete it when we are called again
804 * the next time. Note that this in theory is racy and can lead to a double-free.
805 * In practice, however, the window of exposure to trigger this is extremely short
806 * and as this functions is very infrequently being called (on HUP), the trigger
807 * condition for this bug is so highly unlikely that it never occurs in practice.
808 * Probably if you HUP rsyslog every few milliseconds, but who does that...
809 * To further reduce risk potential, we do only update the property when there
810 * actually is a hostname change, which makes it even less likely.
811 * rgerhards, 2013-10-28
812 */
813 static rsRetVal GenerateLocalHostNameProperty(void) {
814 uchar *pszPrev;
815 int lenPrev;
816 prop_t *hostnameNew;
817 uchar *pszName;
818 DEFiRet;
819
820 if (propLocalHostNameToDelete != NULL) prop.Destruct(&propLocalHostNameToDelete);
821
822 if (LocalHostNameOverride == NULL) {
823 if (LocalHostName == NULL)
824 pszName = (uchar *)"[localhost]";
825 else {
826 if (GetPreserveFQDN() == 1)
827 pszName = LocalFQDNName;
828 else
829 pszName = LocalHostName;
830 }
831 } else { /* local hostname is overriden via config */
832 pszName = LocalHostNameOverride;
833 }
834 DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName);
835
836 if (propLocalHostName == NULL)
837 pszPrev = (uchar *)""; /* make sure strcmp() below does not match */
838 else
839 prop.GetString(propLocalHostName, &pszPrev, &lenPrev);
840
841 if (ustrcmp(pszPrev, pszName)) {
842 /* we need to update */
843 CHKiRet(prop.Construct(&hostnameNew));
844 CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName)));
845 CHKiRet(prop.ConstructFinalize(hostnameNew));
846 propLocalHostNameToDelete = propLocalHostName;
847 propLocalHostName = hostnameNew;
848 }
849
850 finalize_it:
851 RETiRet;
852 }
853
854
855 /* return our local hostname as a string property
856 */
857 static prop_t *GetLocalHostNameProp(void) {
858 return (propLocalHostName);
859 }
860
861
862 static rsRetVal SetLocalFQDNName(uchar *newname) {
863 free(LocalFQDNName);
864 LocalFQDNName = newname;
865 return RS_RET_OK;
866 }
867
868 /* return the current localhost name as FQDN (requires FQDN to be set)
869 */
870 static uchar *GetLocalFQDNName(void) {
871 return (LocalFQDNName == NULL ? (uchar *)"[localhost]" : LocalFQDNName);
872 }
873
874
875 /* return the current working directory */
876 static uchar *GetWorkDir(rsconf_t *cnf) {
877 return (cnf->globals.pszWorkDir == NULL ? (uchar *)"" : cnf->globals.pszWorkDir);
878 }
879
880 /* return the "raw" working directory, which means
881 * NULL if unset.
882 */
883 const uchar *glblGetWorkDirRaw(rsconf_t *cnf) {
884 return cnf->globals.pszWorkDir;
885 }
886
887 /* return the current default netstream driver */
888 static uchar *GetDfltNetstrmDrvr(rsconf_t *cnf) {
889 return (cnf->globals.pszDfltNetstrmDrvr == NULL ? DFLT_NETSTRM_DRVR : cnf->globals.pszDfltNetstrmDrvr);
890 }
891
892 /* return the current default openssl engine name */
893 static uchar *GetDfltOpensslEngine(rsconf_t *cnf) {
894 return (cnf->globals.pszDfltOpensslEngine);
895 }
896
897 /* [ar] Source IP for local client to be used on multihomed host */
898 static rsRetVal SetSourceIPofLocalClient(uchar *newname) {
899 if (SourceIPofLocalClient != NULL) {
900 free(SourceIPofLocalClient);
901 }
902 SourceIPofLocalClient = newname;
903 return RS_RET_OK;
904 }
905
906 static uchar *GetSourceIPofLocalClient(void) {
907 return (SourceIPofLocalClient);
908 }
909
910
911 /* queryInterface function
912 * rgerhards, 2008-02-21
913 */
914 BEGINobjQueryInterface(glbl)
915 CODESTARTobjQueryInterface(glbl);
916 if (pIf->ifVersion != glblCURR_IF_VERSION) { /* check for current version, increment on each change */
917 ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
918 }
919
920 /* ok, we have the right interface, so let's fill it
921 * Please note that we may also do some backwards-compatibility
922 * work here (if we can support an older interface version - that,
923 * of course, also affects the "if" above).
924 */
925 pIf->GetWorkDir = GetWorkDir;
926 pIf->GenerateLocalHostNameProperty = GenerateLocalHostNameProperty;
927 pIf->GetLocalHostNameProp = GetLocalHostNameProp;
928 pIf->GetLocalHostIP = GetLocalHostIP;
929 pIf->SetGlobalInputTermination = SetGlobalInputTermination;
930 pIf->GetGlobalInputTermState = GetGlobalInputTermState;
931 pIf->GetSourceIPofLocalClient = GetSourceIPofLocalClient; /* [ar] */
932 pIf->SetSourceIPofLocalClient = SetSourceIPofLocalClient; /* [ar] */
933 pIf->GetDefPFFamily = getDefPFFamily;
934 pIf->GetDisableDNS = GetDisableDNS;
935 pIf->GetMaxLine = glblGetMaxLine;
936 pIf->GetOptionDisallowWarning = GetOptionDisallowWarning;
937 pIf->GetDfltNetstrmDrvrCAF = GetDfltNetstrmDrvrCAF;
938 pIf->GetDfltNetstrmDrvrCRLF = GetDfltNetstrmDrvrCRLF;
939 pIf->GetDfltNetstrmDrvrCertFile = GetDfltNetstrmDrvrCertFile;
940 pIf->GetDfltNetstrmDrvrKeyFile = GetDfltNetstrmDrvrKeyFile;
941 pIf->GetDfltNetstrmDrvr = GetDfltNetstrmDrvr;
942 pIf->GetDfltOpensslEngine = GetDfltOpensslEngine;
943 pIf->GetNetstrmDrvrCAExtraFiles = GetNetstrmDrvrCAExtraFiles;
944 pIf->GetParserControlCharacterEscapePrefix = GetParserControlCharacterEscapePrefix;
945 pIf->GetParserDropTrailingLFOnReception = GetParserDropTrailingLFOnReception;
946 pIf->GetParserEscapeControlCharactersOnReceive = GetParserEscapeControlCharactersOnReceive;
947 pIf->GetParserSpaceLFOnReceive = GetParserSpaceLFOnReceive;
948 pIf->GetParserEscape8BitCharactersOnReceive = GetParserEscape8BitCharactersOnReceive;
949 pIf->GetParserEscapeControlCharacterTab = GetParserEscapeControlCharacterTab;
950 pIf->GetLocalHostName = glblGetLocalHostName;
951 pIf->SetLocalHostName = SetLocalHostName;
952 #define SIMP_PROP(name) \
953 pIf->Get##name = Get##name; \
954 pIf->Set##name = Set##name;
955 SIMP_PROP(PreserveFQDN);
956 SIMP_PROP(DropMalPTRMsgs);
957 SIMP_PROP(mainqCnfObj);
958 SIMP_PROP(LocalFQDNName)
959 SIMP_PROP(LocalDomain)
960 SIMP_PROP(ParserEscapeControlCharactersCStyle)
961 SIMP_PROP(ParseHOSTNAMEandTAG)
962 #ifdef USE_UNLIMITED_SELECT
963 SIMP_PROP(FdSetSize)
964 #endif
965 #undef SIMP_PROP
966 finalize_it:
967 ENDobjQueryInterface(glbl)
968
969 /* Reset config variables to default values.
970 * rgerhards, 2008-04-17
971 */
972 static rsRetVal resetConfigVariables(uchar __attribute__((unused)) * pp, void __attribute__((unused)) * pVal) {
973 free(loadConf->globals.pszDfltNetstrmDrvr);
974 loadConf->globals.pszDfltNetstrmDrvr = NULL;
975 free(loadConf->globals.pszDfltNetstrmDrvrCAF);
976 loadConf->globals.pszDfltNetstrmDrvrCAF = NULL;
977 free(loadConf->globals.pszDfltNetstrmDrvrCRLF);
978 loadConf->globals.pszDfltNetstrmDrvrCRLF = NULL;
979 free(loadConf->globals.pszDfltNetstrmDrvrKeyFile);
980 loadConf->globals.pszDfltNetstrmDrvrKeyFile = NULL;
981 free(loadConf->globals.pszDfltNetstrmDrvrCertFile);
982 loadConf->globals.pszDfltNetstrmDrvrCertFile = NULL;
983 free(loadConf->globals.pszDfltOpensslEngine);
984 loadConf->globals.pszDfltOpensslEngine = NULL;
985 free(LocalHostNameOverride);
986 LocalHostNameOverride = NULL;
987 free(loadConf->globals.oversizeMsgErrorFile);
988 loadConf->globals.oversizeMsgErrorFile = NULL;
989 loadConf->globals.oversizeMsgInputMode = glblOversizeMsgInputMode_Accept;
990 loadConf->globals.reportChildProcessExits = REPORT_CHILD_PROCESS_EXITS_ERRORS;
991 free(loadConf->globals.pszWorkDir);
992 loadConf->globals.pszWorkDir = NULL;
993 free((void *)loadConf->globals.operatingStateFile);
994 loadConf->globals.operatingStateFile = NULL;
995 loadConf->globals.bDropMalPTRMsgs = 0;
996 bPreserveFQDN = 0;
997 loadConf->globals.iMaxLine = 8192;
998 loadConf->globals.reportOversizeMsg = 1;
999 loadConf->globals.parser.cCCEscapeChar = '#';
1000 loadConf->globals.parser.bDropTrailingLF = 1;
1001 loadConf->globals.parser.bEscapeCCOnRcv = 1; /* default is to escape control characters */
1002 loadConf->globals.parser.bSpaceLFOnRcv = 0;
1003 loadConf->globals.parser.bEscape8BitChars = 0; /* default is not to escape control characters */
1004 loadConf->globals.parser.bEscapeTab = 1; /* default is to escape tab characters */
1005 loadConf->globals.parser.bParserEscapeCCCStyle = 0;
1006 #ifdef USE_UNLIMITED_SELECT
1007 iFdSetSize = howmany(FD_SETSIZE, __NFDBITS) * sizeof(fd_mask);
1008 #endif
1009 return RS_RET_OK;
1010 }
1011
1012
1013 /* Prepare for new config
1014 */
1015 void glblPrepCnf(void) {
1016 free(mainqCnfObj);
1017 mainqCnfObj = NULL;
1018 free(cnfparamvals);
1019 cnfparamvals = NULL;
1020 }
1021
1022 /* handle the timezone() object. Each incarnation adds one additional
1023 * zone info to the global table of time zones.
1024 */
1025
1026 int bs_arrcmp_glblDbgFiles(const void *s1, const void *s2) {
1027 return strcmp((char *)s1, *(char **)s2);
1028 }
1029
1030
1031 /* handle a global config object. Note that multiple global config statements
1032 * are permitted (because of plugin support), so once we got a param block,
1033 * we need to hold to it.
1034 * rgerhards, 2011-07-19
1035 */
1036 void glblProcessCnf(struct cnfobj *o) {
1037 int i;
1038
1039 cnfparamvals = nvlstGetParams(o->nvlst, &paramblk, cnfparamvals);
1040 if (cnfparamvals == NULL) {
1041 LogError(0, RS_RET_MISSING_CNFPARAMS,
1042 "error processing global "
1043 "config parameters [global(...)]");
1044 goto done;
1045 }
1046 if (Debug) {
1047 dbgprintf("glbl param blk after glblProcessCnf:\n");
1048 cnfparamsPrint(&paramblk, cnfparamvals);
1049 }
1050
1051 /* The next thing is a bit hackish and should be changed in higher
1052 * versions. There are a select few parameters which we need to
1053 * act on immediately. These are processed here.
1054 */
1055 for (i = 0; i < paramblk.nParams; ++i) {
1056 if (!cnfparamvals[i].bUsed) continue;
1057 if (!strcmp(paramblk.descr[i].name, "processinternalmessages")) {
1058 loadConf->globals.bProcessInternalMessages = (int)cnfparamvals[i].val.d.n;
1059 cnfparamvals[i].bUsed = TRUE;
1060 } else if (!strcmp(paramblk.descr[i].name, "internal.developeronly.options")) {
1061 loadConf->globals.glblDevOptions = (uint64_t)cnfparamvals[i].val.d.n;
1062 cnfparamvals[i].bUsed = TRUE;
1063 } else if (!strcmp(paramblk.descr[i].name, "stdlog.channelspec")) {
1064 #ifndef ENABLE_LIBLOGGING_STDLOG
1065 LogError(0, RS_RET_ERR,
1066 "rsyslog wasn't "
1067 "compiled with liblogging-stdlog support. "
1068 "The 'stdlog.channelspec' parameter "
1069 "is ignored. Note: the syslog API is used instead.\n");
1070 #else
1071 loadConf->globals.stdlog_chanspec = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1072 /* we need to re-open with the new channel */
1073 stdlog_close(loadConf->globals.stdlog_hdl);
1074 loadConf->globals.stdlog_hdl =
1075 stdlog_open("rsyslogd", 0, STDLOG_SYSLOG, (char *)loadConf->globals.stdlog_chanspec);
1076 cnfparamvals[i].bUsed = TRUE;
1077 #endif
1078 } else if (!strcmp(paramblk.descr[i].name, "operatingstatefile")) {
1079 if (loadConf->globals.operatingStateFile != NULL) {
1080 LogError(errno, RS_RET_PARAM_ERROR,
1081 "error: operatingStateFile already set to '%s' - "
1082 "new value ignored",
1083 loadConf->globals.operatingStateFile);
1084 } else {
1085 loadConf->globals.operatingStateFile = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1086 osf_open();
1087 }
1088 } else if (!strcmp(paramblk.descr[i].name, "security.abortonidresolutionfail")) {
1089 loadConf->globals.abortOnIDResolutionFail = (int)cnfparamvals[i].val.d.n;
1090 cnfparamvals[i].bUsed = TRUE;
1091 }
1092 }
1093 done:
1094 return;
1095 }
1096
1097 /* Set mainq parameters. Note that when this is not called, we'll use the
1098 * legacy parameter config. mainq parameters can only be set once.
1099 */
1100 void glblProcessMainQCnf(struct cnfobj *o) {
1101 if (mainqCnfObj == NULL) {
1102 mainqCnfObj = o;
1103 } else {
1104 LogError(0, RS_RET_ERR,
1105 "main_queue() object can only be specified "
1106 "once - all but first ignored\n");
1107 }
1108 }
1109
1110 /* destruct the main q cnf object after it is no longer needed. This is
1111 * also used to do some final checks.
1112 */
1113 void glblDestructMainqCnfObj(void) {
1114 /* Only destruct if not NULL! */
1115 if (mainqCnfObj != NULL) {
1116 nvlstChkUnused(mainqCnfObj->nvlst);
1117 cnfobjDestruct(mainqCnfObj);
1118 mainqCnfObj = NULL;
1119 }
1120 }
1121
1122 static int qs_arrcmp_glblDbgFiles(const void *s1, const void *s2) {
1123 return strcmp(*((char **)s1), *((char **)s2));
1124 }
1125
1126 /* set an environment variable */
1127 static rsRetVal do_setenv(const char *const var) {
1128 char varname[128];
1129 const char *val = var;
1130 size_t i;
1131 DEFiRet;
1132
1133 for (i = 0; *val != '='; ++i, ++val) {
1134 if (i == sizeof(varname) - i) {
1135 parser_errmsg(
1136 "environment variable name too long "
1137 "[max %zu chars] or malformed entry: '%s'",
1138 sizeof(varname) - 1, var);
1139 ABORT_FINALIZE(RS_RET_ERR_SETENV);
1140 }
1141 if (*val == '\0') {
1142 parser_errmsg(
1143 "environment variable entry is missing "
1144 "equal sign (for value): '%s'",
1145 var);
1146 ABORT_FINALIZE(RS_RET_ERR_SETENV);
1147 }
1148 varname[i] = *val;
1149 }
1150 varname[i] = '\0';
1151 ++val;
1152 DBGPRINTF("do_setenv, var '%s', val '%s'\n", varname, val);
1153
1154 if (setenv(varname, val, 1) != 0) {
1155 char errStr[1024];
1156 rs_strerror_r(errno, errStr, sizeof(errStr));
1157 parser_errmsg(
1158 "error setting environment variable "
1159 "'%s' to '%s': %s",
1160 varname, val, errStr);
1161 ABORT_FINALIZE(RS_RET_ERR_SETENV);
1162 }
1163
1164
1165 finalize_it:
1166 RETiRet;
1167 }
1168
1169
1170 /* This processes the "regular" parameters which are to be set after the
1171 * config has been fully loaded.
1172 */
1173 rsRetVal glblDoneLoadCnf(void) {
1174 int i;
1175 unsigned char *cstr;
1176 DEFiRet;
1177 CHKiRet(objUse(net, CORE_COMPONENT));
1178
1179 sortTimezones(loadConf);
1180 DBGPRINTF("Timezone information table (%d entries):\n", loadConf->timezones.ntzinfos);
1181 displayTimezones(loadConf);
1182
1183 if (cnfparamvals == NULL) goto finalize_it;
1184
1185 for (i = 0; i < paramblk.nParams; ++i) {
1186 if (!cnfparamvals[i].bUsed) continue;
1187 if (!strcmp(paramblk.descr[i].name, "workdirectory")) {
1188 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1189 setWorkDir(NULL, cstr);
1190 } else if (!strcmp(paramblk.descr[i].name, "libcapng.default")) {
1191 #ifdef ENABLE_LIBCAPNG
1192 loadConf->globals.bAbortOnFailedLibcapngSetup = (int)cnfparamvals[i].val.d.n;
1193 #else
1194 LogError(0, RS_RET_ERR,
1195 "rsyslog wasn't "
1196 "compiled with libcap-ng support.");
1197 #endif
1198 } else if (!strcmp(paramblk.descr[i].name, "libcapng.enable")) {
1199 #ifdef ENABLE_LIBCAPNG
1200 loadConf->globals.bCapabilityDropEnabled = (int)cnfparamvals[i].val.d.n;
1201 #else
1202 LogError(0, RS_RET_ERR,
1203 "rsyslog wasn't "
1204 "compiled with libcap-ng support.");
1205 #endif
1206 } else if (!strcmp(paramblk.descr[i].name, "variables.casesensitive")) {
1207 const int val = (int)cnfparamvals[i].val.d.n;
1208 fjson_global_do_case_sensitive_comparison(val);
1209 DBGPRINTF("global/config: set case sensitive variables to %d\n", val);
1210 } else if (!strcmp(paramblk.descr[i].name, "localhostname")) {
1211 free(LocalHostNameOverride);
1212 LocalHostNameOverride = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1213 } else if (!strcmp(paramblk.descr[i].name, "defaultnetstreamdriverkeyfile")) {
1214 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1215 setDfltNetstrmDrvrKeyFile(NULL, cstr);
1216 } else if (!strcmp(paramblk.descr[i].name, "defaultnetstreamdrivercertfile")) {
1217 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1218 setDfltNetstrmDrvrCertFile(NULL, cstr);
1219 } else if (!strcmp(paramblk.descr[i].name, "defaultnetstreamdrivercafile")) {
1220 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1221 setDfltNetstrmDrvrCAF(NULL, cstr);
1222 } else if (!strcmp(paramblk.descr[i].name, "defaultnetstreamdrivercrlfile")) {
1223 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1224 setDfltNetstrmDrvrCRLF(NULL, cstr);
1225 } else if (!strcmp(paramblk.descr[i].name, "defaultnetstreamdriver")) {
1226 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1227 setDfltNetstrmDrvr(NULL, cstr);
1228 } else if (!strcmp(paramblk.descr[i].name, "defaultopensslengine")) {
1229 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1230 setDfltOpensslEngine(NULL, cstr);
1231 } else if (!strcmp(paramblk.descr[i].name, "netstreamdrivercaextrafiles")) {
1232 cstr = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1233 setNetstrmDrvrCAExtraFiles(NULL, cstr);
1234 } else if (!strcmp(paramblk.descr[i].name, "preservefqdn")) {
1235 bPreserveFQDN = (int)cnfparamvals[i].val.d.n;
1236 } else if (!strcmp(paramblk.descr[i].name, "compactjsonstring")) {
1237 glblJsonFormatOpt = cnfparamvals[i].val.d.n ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED;
1238 } else if (!strcmp(paramblk.descr[i].name, "dropmsgswithmaliciousdnsptrrecords")) {
1239 loadConf->globals.bDropMalPTRMsgs = (int)cnfparamvals[i].val.d.n;
1240 } else if (!strcmp(paramblk.descr[i].name, "action.reportsuspension")) {
1241 loadConf->globals.bActionReportSuspension = (int)cnfparamvals[i].val.d.n;
1242 } else if (!strcmp(paramblk.descr[i].name, "action.reportsuspensioncontinuation")) {
1243 loadConf->globals.bActionReportSuspensionCont = (int)cnfparamvals[i].val.d.n;
1244 } else if (!strcmp(paramblk.descr[i].name, "maxmessagesize")) {
1245 setMaxLine(cnfparamvals[i].val.d.n);
1246 } else if (!strcmp(paramblk.descr[i].name, "oversizemsg.errorfile")) {
1247 free(loadConf->globals.oversizeMsgErrorFile);
1248 loadConf->globals.oversizeMsgErrorFile = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1249 } else if (!strcmp(paramblk.descr[i].name, "oversizemsg.report")) {
1250 loadConf->globals.reportOversizeMsg = (int)cnfparamvals[i].val.d.n;
1251 } else if (!strcmp(paramblk.descr[i].name, "oversizemsg.input.mode")) {
1252 const char *const tmp = es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1253 setOversizeMsgInputMode((uchar *)tmp);
1254 free((void *)tmp);
1255 } else if (!strcmp(paramblk.descr[i].name, "reportchildprocessexits")) {
1256 const char *const tmp = es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1257 setReportChildProcessExits((uchar *)tmp);
1258 free((void *)tmp);
1259 } else if (!strcmp(paramblk.descr[i].name, "debug.onshutdown")) {
1260 loadConf->globals.debugOnShutdown = (int)cnfparamvals[i].val.d.n;
1261 LogError(0, RS_RET_OK, "debug: onShutdown set to %d", loadConf->globals.debugOnShutdown);
1262 } else if (!strcmp(paramblk.descr[i].name, "debug.gnutls")) {
1263 loadConf->globals.iGnuTLSLoglevel = (int)cnfparamvals[i].val.d.n;
1264 } else if (!strcmp(paramblk.descr[i].name, "debug.abortonprogramerror")) {
1265 glblAbortOnProgramError = (int)cnfparamvals[i].val.d.n;
1266 } else if (!strcmp(paramblk.descr[i].name, "debug.unloadmodules")) {
1267 glblUnloadModules = (int)cnfparamvals[i].val.d.n;
1268 } else if (!strcmp(paramblk.descr[i].name, "parser.controlcharacterescapeprefix")) {
1269 uchar *tmp = (uchar *)es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1270 setParserControlCharacterEscapePrefix(NULL, tmp);
1271 free(tmp);
1272 } else if (!strcmp(paramblk.descr[i].name, "parser.droptrailinglfonreception")) {
1273 const int tmp = (int)cnfparamvals[i].val.d.n;
1274 setParserDropTrailingLFOnReception(NULL, tmp);
1275 } else if (!strcmp(paramblk.descr[i].name, "parser.escapecontrolcharactersonreceive")) {
1276 const int tmp = (int)cnfparamvals[i].val.d.n;
1277 setParserEscapeControlCharactersOnReceive(NULL, tmp);
1278 } else if (!strcmp(paramblk.descr[i].name, "parser.spacelfonreceive")) {
1279 const int tmp = (int)cnfparamvals[i].val.d.n;
1280 setParserSpaceLFOnReceive(NULL, tmp);
1281 } else if (!strcmp(paramblk.descr[i].name, "parser.escape8bitcharactersonreceive")) {
1282 const int tmp = (int)cnfparamvals[i].val.d.n;
1283 setParserEscape8BitCharactersOnReceive(NULL, tmp);
1284 } else if (!strcmp(paramblk.descr[i].name, "parser.escapecontrolcharactertab")) {
1285 const int tmp = (int)cnfparamvals[i].val.d.n;
1286 setParserEscapeControlCharacterTab(NULL, tmp);
1287 } else if (!strcmp(paramblk.descr[i].name, "parser.escapecontrolcharacterscstyle")) {
1288 const int tmp = (int)cnfparamvals[i].val.d.n;
1289 SetParserEscapeControlCharactersCStyle(tmp);
1290 } else if (!strcmp(paramblk.descr[i].name, "parser.parsehostnameandtag")) {
1291 const int tmp = (int)cnfparamvals[i].val.d.n;
1292 SetParseHOSTNAMEandTAG(tmp);
1293 } else if (!strcmp(paramblk.descr[i].name, "parser.permitslashinprogramname")) {
1294 loadConf->globals.parser.bPermitSlashInProgramname = (int)cnfparamvals[i].val.d.n;
1295 } else if (!strcmp(paramblk.descr[i].name, "debug.logfile")) {
1296 if (pszAltDbgFileName == NULL) {
1297 pszAltDbgFileName = es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1298 /* can actually happen if debug system also opened altdbg */
1299 if (altdbg != -1) {
1300 close(altdbg);
1301 }
1302 if ((altdbg = open(pszAltDbgFileName, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY | O_CLOEXEC,
1303 S_IRUSR | S_IWUSR)) == -1) {
1304 LogError(0, RS_RET_ERR, "debug log file '%s' could not be opened", pszAltDbgFileName);
1305 }
1306 }
1307 LogError(0, RS_RET_OK, "debug log file is '%s', fd %d", pszAltDbgFileName, altdbg);
1308 } else if (!strcmp(paramblk.descr[i].name, "janitor.interval")) {
1309 loadConf->globals.janitorInterval = (int)cnfparamvals[i].val.d.n;
1310 } else if (!strcmp(paramblk.descr[i].name, "net.ipprotocol")) {
1311 char *proto = es_str2cstr(cnfparamvals[i].val.d.estr, NULL);
1312 if (!strcmp(proto, "unspecified")) {
1313 loadConf->globals.iDefPFFamily = PF_UNSPEC;
1314 } else if (!strcmp(proto, "ipv4-only")) {
1315 loadConf->globals.iDefPFFamily = PF_INET;
1316 } else if (!strcmp(proto, "ipv6-only")) {
1317 loadConf->globals.iDefPFFamily = PF_INET6;
1318 } else {
1319 LogError(0, RS_RET_ERR,
1320 "invalid net.ipprotocol "
1321 "parameter '%s' -- ignored",
1322 proto);
1323 }
1324 free(proto);
1325 } else if (!strcmp(paramblk.descr[i].name, "senders.reportnew")) {
1326 loadConf->globals.reportNewSenders = (int)cnfparamvals[i].val.d.n;
1327 } else if (!strcmp(paramblk.descr[i].name, "senders.reportgoneaway")) {
1328 loadConf->globals.reportGoneAwaySenders = (int)cnfparamvals[i].val.d.n;
1329 } else if (!strcmp(paramblk.descr[i].name, "senders.timeoutafter")) {
1330 loadConf->globals.senderStatsTimeout = (int)cnfparamvals[i].val.d.n;
1331 } else if (!strcmp(paramblk.descr[i].name, "senders.keeptrack")) {
1332 loadConf->globals.senderKeepTrack = (int)cnfparamvals[i].val.d.n;
1333 } else if (!strcmp(paramblk.descr[i].name, "inputs.timeout.shutdown")) {
1334 loadConf->globals.inputTimeoutShutdown = (int)cnfparamvals[i].val.d.n;
1335 } else if (!strcmp(paramblk.descr[i].name, "privdrop.group.keepsupplemental")) {
1336 loadConf->globals.gidDropPrivKeepSupplemental = (int)cnfparamvals[i].val.d.n;
1337 } else if (!strcmp(paramblk.descr[i].name, "privdrop.group.id")) {
1338 loadConf->globals.gidDropPriv = (int)cnfparamvals[i].val.d.n;
1339 } else if (!strcmp(paramblk.descr[i].name, "privdrop.group.name")) {
1340 loadConf->globals.gidDropPriv = (int)cnfparamvals[i].val.d.n;
1341 } else if (!strcmp(paramblk.descr[i].name, "privdrop.user.id")) {
1342 loadConf->globals.uidDropPriv = (int)cnfparamvals[i].val.d.n;
1343 } else if (!strcmp(paramblk.descr[i].name, "privdrop.user.name")) {
1344 loadConf->globals.uidDropPriv = (int)cnfparamvals[i].val.d.n;
1345 } else if (!strcmp(paramblk.descr[i].name, "security.abortonidresolutionfail")) {
1346 loadConf->globals.abortOnIDResolutionFail = (int)cnfparamvals[i].val.d.n;
1347 } else if (!strcmp(paramblk.descr[i].name, "net.acladdhostnameonfail")) {
1348 loadConf->globals.ACLAddHostnameOnFail = (int)cnfparamvals[i].val.d.n;
1349 } else if (!strcmp(paramblk.descr[i].name, "net.aclresolvehostname")) {
1350 loadConf->globals.ACLDontResolve = !((int)cnfparamvals[i].val.d.n);
1351 } else if (!strcmp(paramblk.descr[i].name, "net.enabledns")) {
1352 SetDisableDNS(!((int)cnfparamvals[i].val.d.n));
1353 } else if (!strcmp(paramblk.descr[i].name, "net.permitwarning")) {
1354 SetOptionDisallowWarning(!((int)cnfparamvals[i].val.d.n));
1355 } else if (!strcmp(paramblk.descr[i].name, "abortonuncleanconfig")) {
1356 loadConf->globals.bAbortOnUncleanConfig = cnfparamvals[i].val.d.n;
1357 } else if (!strcmp(paramblk.descr[i].name, "abortonfailedqueuestartup")) {
1358 loadConf->globals.bAbortOnFailedQueueStartup = cnfparamvals[i].val.d.n;
1359 } else if (!strcmp(paramblk.descr[i].name, "internalmsg.ratelimit.burst")) {
1360 loadConf->globals.intMsgRateLimitBurst = (int)cnfparamvals[i].val.d.n;
1361 } else if (!strcmp(paramblk.descr[i].name, "internalmsg.ratelimit.interval")) {
1362 loadConf->globals.intMsgRateLimitItv = (int)cnfparamvals[i].val.d.n;
1363 } else if (!strcmp(paramblk.descr[i].name, "internalmsg.severity")) {
1364 loadConf->globals.intMsgsSeverityFilter = (int)cnfparamvals[i].val.d.n;
1365 if ((loadConf->globals.intMsgsSeverityFilter < 0) || (loadConf->globals.intMsgsSeverityFilter > 7)) {
1366 parser_errmsg("invalid internalmsg.severity value");
1367 loadConf->globals.intMsgsSeverityFilter = DFLT_INT_MSGS_SEV_FILTER;
1368 }
1369 } else if (!strcmp(paramblk.descr[i].name, "environment")) {
1370 for (int j = 0; j < cnfparamvals[i].val.d.ar->nmemb; ++j) {
1371 char *const var = es_str2cstr(cnfparamvals[i].val.d.ar->arr[j], NULL);
1372 do_setenv(var);
1373 free(var);
1374 }
1375 } else if (!strcmp(paramblk.descr[i].name, "errormessagestostderr.maxnumber")) {
1376 loadConf->globals.maxErrMsgToStderr = (int)cnfparamvals[i].val.d.n;
1377 } else if (!strcmp(paramblk.descr[i].name, "allmessagestostderr")) {
1378 loadConf->globals.bAllMsgToStderr = (int)cnfparamvals[i].val.d.n;
1379 } else if (!strcmp(paramblk.descr[i].name, "debug.files")) {
1380 free(glblDbgFiles); /* "fix" Coverity false positive */
1381 glblDbgFilesNum = cnfparamvals[i].val.d.ar->nmemb;
1382 glblDbgFiles = (char **)malloc(cnfparamvals[i].val.d.ar->nmemb * sizeof(char *));
1383 for (int j = 0; j < cnfparamvals[i].val.d.ar->nmemb; ++j) {
1384 glblDbgFiles[j] = es_str2cstr(cnfparamvals[i].val.d.ar->arr[j], NULL);
1385 }
1386 qsort(glblDbgFiles, glblDbgFilesNum, sizeof(char *), qs_arrcmp_glblDbgFiles);
1387 } else if (!strcmp(paramblk.descr[i].name, "debug.whitelist")) {
1388 glblDbgWhitelist = (int)cnfparamvals[i].val.d.n;
1389 } else if (!strcmp(paramblk.descr[i].name, "shutdown.queue.doublesize")) {
1390 loadConf->globals.shutdownQueueDoubleSize = (int)cnfparamvals[i].val.d.n;
1391 } else if (!strcmp(paramblk.descr[i].name, "umask")) {
1392 loadConf->globals.umask = (int)cnfparamvals[i].val.d.n;
1393 } else if (!strcmp(paramblk.descr[i].name, "shutdown.enable.ctlc")) {
1394 loadConf->globals.permitCtlC = (int)cnfparamvals[i].val.d.n;
1395 } else if (!strcmp(paramblk.descr[i].name, "default.action.queue.timeoutshutdown")) {
1396 loadConf->globals.actq_dflt_toQShutdown = cnfparamvals[i].val.d.n;
1397 } else if (!strcmp(paramblk.descr[i].name, "default.action.queue.timeoutactioncompletion")) {
1398 loadConf->globals.actq_dflt_toActShutdown = cnfparamvals[i].val.d.n;
1399 } else if (!strcmp(paramblk.descr[i].name, "default.action.queue.timeoutenqueue")) {
1400 loadConf->globals.actq_dflt_toEnq = cnfparamvals[i].val.d.n;
1401 } else if (!strcmp(paramblk.descr[i].name, "default.action.queue.timeoutworkerthreadshutdown")) {
1402 loadConf->globals.actq_dflt_toWrkShutdown = cnfparamvals[i].val.d.n;
1403 } else if (!strcmp(paramblk.descr[i].name, "default.ruleset.queue.timeoutshutdown")) {
1404 loadConf->globals.ruleset_dflt_toQShutdown = cnfparamvals[i].val.d.n;
1405 } else if (!strcmp(paramblk.descr[i].name, "default.ruleset.queue.timeoutactioncompletion")) {
1406 loadConf->globals.ruleset_dflt_toActShutdown = cnfparamvals[i].val.d.n;
1407 } else if (!strcmp(paramblk.descr[i].name, "default.ruleset.queue.timeoutenqueue")) {
1408 loadConf->globals.ruleset_dflt_toEnq = cnfparamvals[i].val.d.n;
1409 } else if (!strcmp(paramblk.descr[i].name, "default.ruleset.queue.timeoutworkerthreadshutdown")) {
1410 loadConf->globals.ruleset_dflt_toWrkShutdown = cnfparamvals[i].val.d.n;
1411 } else if (!strcmp(paramblk.descr[i].name, "reverselookup.cache.ttl.default")) {
1412 loadConf->globals.dnscacheDefaultTTL = cnfparamvals[i].val.d.n;
1413 } else if (!strcmp(paramblk.descr[i].name, "reverselookup.cache.ttl.enable")) {
1414 loadConf->globals.dnscacheEnableTTL = cnfparamvals[i].val.d.n;
1415 } else if (!strcmp(paramblk.descr[i].name, "parser.supportcompressionextension")) {
1416 loadConf->globals.bSupportCompressionExtension = cnfparamvals[i].val.d.n;
1417 } else {
1418 dbgprintf(
1419 "glblDoneLoadCnf: program error, non-handled "
1420 "param '%s'\n",
1421 paramblk.descr[i].name);
1422 }
1423 }
1424
1425 if (loadConf->globals.debugOnShutdown && Debug != DEBUG_FULL) {
1426 Debug = DEBUG_ONDEMAND;
1427 stddbg = -1;
1428 }
1429
1430 finalize_it:
1431 /* we have now read the config. We need to query the local host name now
1432 * as it was set by the config.
1433 *
1434 * Note: early messages are already emited, and have "[localhost]" as
1435 * hostname. These messages are currently in iminternal queue. Once they
1436 * are taken from that queue, the hostname will be adapted.
1437 */
1438 queryLocalHostname(loadConf);
1439 RETiRet;
1440 }
1441
1442
1443 /* Initialize the glbl class. Must be called as the very first method
1444 * before anything else is called inside this class.
1445 * rgerhards, 2008-02-19
1446 */
1447 BEGINAbstractObjClassInit(glbl, 1, OBJ_IS_CORE_MODULE) /* class, version */
1448 /* request objects we use */
1449 CHKiRet(objUse(prop, CORE_COMPONENT));
1450
1451 /* initialize properties */
1452 storeLocalHostIPIF((uchar *)"127.0.0.1");
1453
1454 /* config handlers are never unregistered and need not be - we are always loaded ;) */
1455 CHKiRet(regCfSysLineHdlr((uchar *)"debugfile", 0, eCmdHdlrGetWord, setDebugFile, NULL, NULL));
1456 CHKiRet(regCfSysLineHdlr((uchar *)"debuglevel", 0, eCmdHdlrInt, setDebugLevel, NULL, NULL));
1457 CHKiRet(regCfSysLineHdlr((uchar *)"workdirectory", 0, eCmdHdlrGetWord, setWorkDir, NULL, NULL));
1458 CHKiRet(regCfSysLineHdlr((uchar *)"dropmsgswithmaliciousdnsptrrecords", 0, eCmdHdlrBinary, SetDropMalPTRMsgs, NULL,
1459 NULL));
1460 CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdriver", 0, eCmdHdlrGetWord, setDfltNetstrmDrvr, NULL, NULL));
1461 CHKiRet(regCfSysLineHdlr((uchar *)"defaultopensslengine", 0, eCmdHdlrGetWord, setDfltOpensslEngine, NULL, NULL));
1462 CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercafile", 0, eCmdHdlrGetWord, setDfltNetstrmDrvrCAF, NULL,
1463 NULL));
1464 CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercrlfile", 0, eCmdHdlrGetWord, setDfltNetstrmDrvrCRLF, NULL,
1465 NULL));
1466 CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdriverkeyfile", 0, eCmdHdlrGetWord, setDfltNetstrmDrvrKeyFile,
1467 NULL, NULL));
1468 CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercertfile", 0, eCmdHdlrGetWord, setDfltNetstrmDrvrCertFile,
1469 NULL, NULL));
1470 CHKiRet(regCfSysLineHdlr((uchar *)"localhostname", 0, eCmdHdlrGetWord, NULL, &LocalHostNameOverride, NULL));
1471 CHKiRet(regCfSysLineHdlr((uchar *)"localhostipif", 0, eCmdHdlrGetWord, setLocalHostIPIF, NULL, NULL));
1472 CHKiRet(regCfSysLineHdlr((uchar *)"netstreamdrivercaextrafiles", 0, eCmdHdlrGetWord, setNetstrmDrvrCAExtraFiles,
1473 NULL, NULL));
1474 CHKiRet(regCfSysLineHdlr((uchar *)"optimizeforuniprocessor", 0, eCmdHdlrGoneAway, NULL, NULL, NULL));
1475 CHKiRet(regCfSysLineHdlr((uchar *)"preservefqdn", 0, eCmdHdlrBinary, NULL, &bPreserveFQDN, NULL));
1476 CHKiRet(regCfSysLineHdlr((uchar *)"maxmessagesize", 0, eCmdHdlrSize, legacySetMaxMessageSize, NULL, NULL));
1477
1478 /* Deprecated parser config options */
1479 CHKiRet(regCfSysLineHdlr((uchar *)"controlcharacterescapeprefix", 0, eCmdHdlrGetChar,
1480 setParserControlCharacterEscapePrefix, NULL, NULL));
1481 CHKiRet(regCfSysLineHdlr((uchar *)"droptrailinglfonreception", 0, eCmdHdlrBinary,
1482 setParserDropTrailingLFOnReception, NULL, NULL));
1483 CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactersonreceive", 0, eCmdHdlrBinary,
1484 setParserEscapeControlCharactersOnReceive, NULL, NULL));
1485 CHKiRet(regCfSysLineHdlr((uchar *)"spacelfonreceive", 0, eCmdHdlrBinary, setParserSpaceLFOnReceive, NULL, NULL));
1486 CHKiRet(regCfSysLineHdlr((uchar *)"escape8bitcharactersonreceive", 0, eCmdHdlrBinary,
1487 setParserEscape8BitCharactersOnReceive, NULL, NULL));
1488 CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactertab", 0, eCmdHdlrBinary,
1489 setParserEscapeControlCharacterTab, NULL, NULL));
1490
1491 CHKiRet(
1492 regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
1493
1494 INIT_ATOMIC_HELPER_MUT(mutTerminateInputs);
1495 ENDObjClassInit(glbl)
1496
1497
1498 /* Exit the glbl class.
1499 * rgerhards, 2008-04-17
1500 */
1501 BEGINObjClassExit(glbl, OBJ_IS_CORE_MODULE) /* class, version */
1502 free(LocalDomain);
1503 free(LocalHostName);
1504 free(LocalHostNameOverride);
1505 free(LocalFQDNName);
1506 objRelease(prop, CORE_COMPONENT);
1507 if (propLocalHostNameToDelete != NULL) prop.Destruct(&propLocalHostNameToDelete);
1508 DESTROY_ATOMIC_HELPER_MUT(mutTerminateInputs);
1509 ENDObjClassExit(glbl)