1 /* The rsconf object. It models a complete rsyslog configuration.
2  *
3  * Copyright 2011-2020 Rainer Gerhards and Adiscon GmbH.
4  *
5  * This file is part of the rsyslog runtime library.
6  *
7  * The rsyslog runtime library is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * The rsyslog runtime library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the rsyslog runtime library.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * A copy of the GPL can be found in the file "COPYING" in this distribution.
21  * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
22  */
23 #ifndef INCLUDED_RSCONF_H
24 #define INCLUDED_RSCONF_H
25 
26 #include "linkedlist.h"
27 #include "queue.h"
28 #include "lookup.h"
29 #include "dynstats.h"
30 #include "perctile_stats.h"
31 
32 /* --- configuration objects (the plan is to have ALL upper layers in this file) --- */
33 
34 /* queue config parameters. TODO: move to queue.c? */
35 struct queuecnf_s {
36 	int iMainMsgQueueSize;		/* size of the main message queue above */
37 	int iMainMsgQHighWtrMark;	/* high water mark for disk-assisted queues */
38 	int iMainMsgQLowWtrMark;	/* low water mark for disk-assisted queues */
39 	int iMainMsgQDiscardMark;	/* begin to discard messages */
40 	int iMainMsgQDiscardSeverity;	/* by default, discard nothing to prevent unintentional loss */
41 	int iMainMsgQueueNumWorkers;	/* number of worker threads for the mm queue above */
42 	queueType_t MainMsgQueType;	/* type of the main message queue above */
43 	uchar *pszMainMsgQFName;	/* prefix for the main message queue file */
44 	int64 iMainMsgQueMaxFileSize;
45 	int iMainMsgQPersistUpdCnt;	/* persist queue info every n updates */
46 	int bMainMsgQSyncQeueFiles;	/* sync queue files on every write? */
47 	int iMainMsgQtoQShutdown;	/* queue shutdown (ms) */
48 	int iMainMsgQtoActShutdown;	/* action shutdown (in phase 2) */
49 	int iMainMsgQtoEnq;		/* timeout for queue enque */
50 	int iMainMsgQtoWrkShutdown;	/* timeout for worker thread shutdown */
51 	int iMainMsgQWrkMinMsgs;	/* minimum messages per worker needed to start a new one */
52 	int iMainMsgQDeqSlowdown;	/* dequeue slowdown (simple rate limiting) */
53 	int64 iMainMsgQueMaxDiskSpace;	/* max disk space allocated 0 ==> unlimited */
54 	int64 iMainMsgQueDeqBatchSize;	/* dequeue batch size */
55 	int bMainMsgQSaveOnShutdown;	/* save queue on shutdown (when DA enabled)? */
56 	int iMainMsgQueueDeqtWinFromHr;	/* hour begin of time frame when queue is to be dequeued */
57 	int iMainMsgQueueDeqtWinToHr;	/* hour begin of time frame when queue is to be dequeued */
58 };
59 
60 /* globals are data items that are really global, and can be set only
61  * once (at least in theory, because the legacy system permits them to
62  * be re-set as often as the user likes).
63  */
64 struct globals_s {
65 	int bDebugPrintTemplateList;
66 	int bDebugPrintModuleList;
67 	int bDebugPrintCfSysLineHandlerList;
68 	int bLogStatusMsgs;	/* log rsyslog start/stop/HUP messages? */
69 	int bErrMsgToStderr;	/* print error messages to stderr
70 				  (in addition to everything else)? */
71 	int maxErrMsgToStderr;	/* how many messages to forward at most to stderr? */
72 	int bAbortOnUncleanConfig; /* abort run (rather than starting with partial
73 				      config) if there was any issue in conf */
74 	int uidDropPriv;	/* user-id to which priveleges should be dropped to */
75 	int gidDropPriv;	/* group-id to which priveleges should be dropped to */
76 	int gidDropPrivKeepSupplemental; /* keep supplemental groups when dropping? */
77 	int abortOnIDResolutionFail;
78 	int umask;		/* umask to use */
79 	uchar *pszConfDAGFile;	/* name of config DAG file, non-NULL means generate one */
80 
81 	// TODO are the following ones defaults?
82 	int bReduceRepeatMsgs; /* reduce repeated message - 0 - no, 1 - yes */
83 
84 	//TODO: other representation for main queue? Or just load it differently?
85 	queuecnf_t mainQ;	/* main queue parameters */
86 };
87 
88 /* (global) defaults are global in the sense that they are accessible
89  * to all code, but they can change value and other objects (like
90  * actions) actually copy the value a global had at the time the action
91  * was defined. In that sense, a global default is just that, a default,
92  * wich can (and will) be changed in the course of config file
93  * processing. Once the config file has been processed, defaults
94  * can be dropped. The current code does not do this for simplicity.
95  * That is not a problem, because the defaults do not take up much memory.
96  * At a later stage, we may think about dropping them. -- rgerhards, 2011-04-19
97  */
98 struct defaults_s {
99 	int remove_me_when_first_real_member_is_added;
100 };
101 
102 
103 /* list of modules loaded in this configuration (config specific module list) */
104 struct cfgmodules_etry_s {
105 	cfgmodules_etry_t *next;
106 	modInfo_t *pMod;
107 	void *modCnf;		/* pointer to the input module conf */
108 	/* the following data is input module specific */
109 	sbool canActivate;	/* OK to activate this config? */
110 	sbool canRun;		/* OK to run this config? */
111 };
112 
113 struct cfgmodules_s {
114 	cfgmodules_etry_t *root;
115 };
116 
117 /* outchannel-specific data */
118 struct outchannels_s {
119 	struct outchannel *ochRoot;	/* the root of the outchannel list */
120 	struct outchannel *ochLast;	/* points to the last element of the outchannel list */
121 };
122 
123 struct templates_s {
124 	struct template *root;	/* the root of the template list */
125 	struct template *last;	/* points to the last element of the template list */
126 	struct template *lastStatic; /* last static element of the template list */
127 };
128 
129 
130 struct actions_s {
131 	unsigned nbrActions;		/* number of actions */
132 };
133 
134 
135 struct rulesets_s {
136 	linkedList_t llRulesets; /* this is NOT a pointer - no typo here ;) */
137 
138 	/* support for legacy rsyslog.conf format */
139 	ruleset_t *pCurr; /* currently "active" ruleset */
140 	ruleset_t *pDflt; /* current default ruleset, e.g. for binding to actions which have no other */
141 };
142 
143 
144 /* --- end configuration objects --- */
145 
146 /* the rsconf object */
147 struct rsconf_s {
148 	BEGINobjInstance;	/* Data to implement generic object - MUST be the first data element! */
149 	cfgmodules_t modules;
150 	globals_t globals;
151 	defaults_t defaults;
152 	templates_t templates;
153 	lookup_tables_t lu_tabs;
154 	dynstats_buckets_t dynstats_buckets;
155 	perctile_buckets_t perctile_buckets;
156 	outchannels_t och;
157 	actions_t actions;
158 	rulesets_t rulesets;
159 	/* note: rulesets include the complete output part:
160 	 *  - rules
161 	 *  - filter (as part of the action)
162 	 *  - actions
163 	 * Of course, we need to debate if we shall change that some time...
164 	 */
165 };
166 
167 
168 /* interfaces */
169 BEGINinterface(rsconf) /* name must also be changed in ENDinterface macro! */
170 	INTERFACEObjDebugPrint(rsconf);
171 	rsRetVal (*Destruct)(rsconf_t **ppThis);
172 	rsRetVal (*Load)(rsconf_t **ppThis, uchar *confFile);
173 	rsRetVal (*Activate)(rsconf_t *ppThis);
174 ENDinterface(rsconf)
175 // TODO: switch version to 1 for first "complete" version!!!! 2011-04-20
176 #define rsconfCURR_IF_VERSION 0 /* increment whenever you change the interface above! */
177 
178 
179 /* prototypes */
180 PROTOTYPEObj(rsconf);
181 
182 /* globally-visible external data */
183 extern rsconf_t *runConf;/* the currently running config */
184 extern rsconf_t *loadConf;/* the config currently being loaded (no concurrent config load supported!) */
185 
186 
187 int rsconfNeedDropPriv(rsconf_t *const cnf);
188 
189 /* some defaults (to be removed?) */
190 #define DFLT_bLogStatusMsgs 1
191 
192 #endif /* #ifndef INCLUDED_RSCONF_H */
193