syslog-ng source
cfg.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  * Copyright (c) 1998-2012 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 #ifndef CFG_H_INCLUDED
26 #define CFG_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 #include "cfg-tree.h"
30 #include "cfg-lexer.h"
31 #include "cfg-parser.h"
32 #include "cfg-persist.h"
33 #include "plugin.h"
34 #include "persist-state.h"
35 #include "template/templates.h"
36 #include "host-resolve.h"
37 #include "logmsg/type-hinting.h"
38 #include "stats/stats.h"
40 #include "dnscache.h"
41 #include "file-perms.h"
42 
43 #include <sys/types.h>
44 #include <regex.h>
45 
46 /* destination mark modes */
47 enum
48 {
55 };
56 
57 /* configuration data as loaded from the config file */
59 {
60  /* version number specified by the user, set _after_ parsing is complete */
61  /* hex-encoded syslog-ng major/minor, e.g. 0x0201 is syslog-ng 2.1 format */
63 
64  /* config identifier specified by the user */
66 
67  guint8 *config_hash;
68 
69  const gchar *filename;
70  PluginContext plugin_context;
73  CfgLexer *lexer;
74  CfgArgs *globals;
75 
78  gint mark_freq;
80  gint mark_mode;
81  gboolean threaded;
83  gboolean chain_hostnames;
84  gboolean keep_hostname;
85  gboolean check_hostname;
86  gboolean check_program;
88  regex_t bad_hostname;
90  gchar *custom_domain;
93  gint time_reap;
94  gint suppress;
96 
100  gint log_level;
101 
102  gboolean create_dirs;
105  gboolean use_uniqid;
106 
107  gboolean keep_timestamp;
108 
110  LogTemplateOptions template_options;
112 
115 
116  LogTemplate *file_template;
117  LogTemplate *proto_template;
118 
120 
122  PersistState *state;
123  GHashTable *module_config;
124 
126 
128  GString *original_config;
129 
130  GList *file_list;
131 };
132 
133 gboolean cfg_load_module_with_args(GlobalConfig *cfg, const gchar *module_name, CfgArgs *args);
134 gboolean cfg_load_module(GlobalConfig *cfg, const gchar *module_name);
135 gboolean cfg_is_module_available(GlobalConfig *self, const gchar *module_name);
136 void cfg_discover_candidate_modules(GlobalConfig *self);
137 
138 Plugin *cfg_find_plugin(GlobalConfig *cfg, gint plugin_type, const gchar *plugin_name);
139 gpointer cfg_parse_plugin(GlobalConfig *cfg, Plugin *plugin, CFG_LTYPE *yylloc, gpointer arg);
140 
141 gboolean cfg_allow_config_dups(GlobalConfig *self);
142 
143 void cfg_bad_hostname_set(GlobalConfig *self, gchar *bad_hostname_re);
144 gint cfg_lookup_mark_mode(const gchar *mark_mode);
145 void cfg_set_mark_mode(GlobalConfig *self, const gchar *mark_mode);
146 gboolean cfg_set_log_level(GlobalConfig *self, const gchar *log_level);
147 
148 gint cfg_tz_convert_value(gchar *convert);
149 gint cfg_ts_format_value(gchar *format);
150 
151 void cfg_set_version_without_validation(GlobalConfig *self, gint version);
152 gboolean cfg_set_version(GlobalConfig *self, gint version);
153 gboolean cfg_set_current_version(GlobalConfig *self);
154 void cfg_set_user_config_id(GlobalConfig *self, const gchar *id);
155 
156 void cfg_format_id(GlobalConfig *self, GString *id);
157 
158 void cfg_set_global_paths(GlobalConfig *self);
159 
160 GlobalConfig *cfg_new(gint version);
161 GlobalConfig *cfg_new_snippet(void);
162 GlobalConfig *cfg_new_subordinate(GlobalConfig *master);
163 gboolean cfg_run_parser(GlobalConfig *self, CfgLexer *lexer, CfgParser *parser, gpointer *result, gpointer arg);
164 gboolean cfg_run_parser_with_main_context(GlobalConfig *self, CfgLexer *lexer, CfgParser *parser, gpointer *result,
165  gpointer arg, const gchar *desc);
166 gboolean cfg_read_config(GlobalConfig *cfg, const gchar *fname, gchar *preprocess_into);
167 void cfg_load_forced_modules(GlobalConfig *self);
168 void cfg_shutdown(GlobalConfig *self);
169 gboolean cfg_is_shutting_down(GlobalConfig *cfg);
170 void cfg_free(GlobalConfig *self);
171 gboolean cfg_init(GlobalConfig *cfg);
172 gboolean cfg_deinit(GlobalConfig *cfg);
173 
176 void cfg_persist_config_move(GlobalConfig *src, GlobalConfig *dest);
177 void cfg_persist_config_add(GlobalConfig *cfg, const gchar *name, gpointer value, GDestroyNotify destroy);
178 gpointer cfg_persist_config_fetch(GlobalConfig *cfg, const gchar *name);
179 
180 typedef gboolean(* mangle_callback)(GlobalConfig *cfg, LogMessage *msg, gpointer user_data);
181 
182 void register_source_mangle_callback(GlobalConfig *src, mangle_callback cb);
183 gboolean is_source_mangle_callback_registered(GlobalConfig *src, mangle_callback cb);
184 void uregister_source_mangle_callback(GlobalConfig *src, mangle_callback cb);
185 
186 static inline gboolean
187 __cfg_is_config_version_older(GlobalConfig *cfg, gint req)
188 {
189  if (!cfg)
190  return FALSE;
191  if (version_convert_from_user(cfg->user_version) >= req)
192  return FALSE;
193  return TRUE;
194 }
195 
196 /* VERSION_VALUE_LAST_SEMANTIC_CHANGE needs to be bumped in versioning.h whenever
197  * we add a conditional on the config version anywhere in the codebase. The
198  * G_STATIC_ASSERT checks that we indeed did that.
199  *
200  * We also allow merging the features for the upcoming major version.
201  */
202 
203 #define cfg_is_config_version_older(__cfg, __req) \
204  ({ \
205  /* check that VERSION_VALUE_LAST_SEMANTIC_CHANGE is set correctly */ G_STATIC_ASSERT((__req) <= VERSION_VALUE_LAST_SEMANTIC_CHANGE || (__req) == VERSION_VALUE_NEXT_MAJOR); \
206  __cfg_is_config_version_older(__cfg, __req); \
207  })
208 
209 /* This function returns TRUE if a version based feature flip is enabled.
210  * This will enable or disable feature related upgrade warnings.
211  *
212  * This was initially introduced for "typing" support, where the following
213  * is implemented:
214  *
215  * As long as we are using a 3.x version number (less than 3.255), the upgrade
216  * warnings are suppressed and compatibility mode is enabled. Once @version
217  * is something equal or larger than 3.255, we still enable compatibility but
218  * warnings will NOT be suppressed. This is controlled with
219  * FEATURE_TYPING_MIN_VERSION.
220  *
221  * Once we release 4.0, FEATURE_TYPING_MIN_VERSION needs to be set to zero in
222  * versioning.h With that all upgrade notices start to appear when syslog-ng
223  * finds a 3.x configuration.
224  */
225 #define __cfg_is_feature_enabled(cfg, min_version) \
226  ({ \
227  /* the flip-over for min_version reached, set min_version to 0 */ G_STATIC_ASSERT(min_version == 0 || VERSION_VALUE_CURRENT < ((min_version) - 1)); \
228  version_convert_from_user(cfg->user_version) >= (min_version) - 1; \
229  })
230 
231 #define cfg_is_feature_enabled(cfg, topic) __cfg_is_feature_enabled(cfg, FEATURE_ ## topic ## _MIN_VERSION)
232 #define cfg_is_typing_feature_enabled(cfg) cfg_is_feature_enabled(cfg, TYPING)
233 
234 #define cfg_is_experimental_feature_enabled(cfg) 0
235 
236 static inline void
237 cfg_set_use_uniqid(gboolean flag)
238 {
239  configuration->use_uniqid = !!flag;
240 }
241 
242 gint cfg_get_user_version(const GlobalConfig *cfg);
243 guint cfg_get_parsed_version(const GlobalConfig *cfg);
244 const gchar *cfg_get_filename(const GlobalConfig *cfg);
245 
246 static inline EVTTAG *
247 cfg_format_version_tag(const gchar *tag_name, gint version)
248 {
249  return evt_tag_printf(tag_name, "%d.%d", (version & 0xFF00) >> 8, version & 0xFF);
250 }
251 
252 static inline EVTTAG *
253 cfg_format_config_version_tag(GlobalConfig *self)
254 {
255  return cfg_format_version_tag("config-version", self->user_version);
256 }
257 
258 
259 #endif
PersistConfig * persist_config_new(void)
Definition: cfg-persist.c:88
gboolean cfg_is_module_available(GlobalConfig *self, const gchar *module_name)
Definition: cfg.c:190
guint cfg_get_parsed_version(const GlobalConfig *cfg)
gpointer cfg_parse_plugin(GlobalConfig *cfg, Plugin *plugin, CFG_LTYPE *yylloc, gpointer arg)
Definition: cfg.c:246
void cfg_set_global_paths(GlobalConfig *self)
Definition: cfg.c:532
gboolean cfg_load_module_with_args(GlobalConfig *cfg, const gchar *module_name, CfgArgs *args)
Definition: cfg.c:142
void cfg_bad_hostname_set(GlobalConfig *self, gchar *bad_hostname_re)
Definition: cfg.c:80
void cfg_persist_config_add(GlobalConfig *cfg, const gchar *name, gpointer value, GDestroyNotify destroy)
Definition: cfg.c:774
gboolean cfg_run_parser_with_main_context(GlobalConfig *self, CfgLexer *lexer, CfgParser *parser, gpointer *result, gpointer arg, const gchar *desc)
Definition: cfg.c:575
gint cfg_get_user_version(const GlobalConfig *cfg)
Definition: cfg.c:797
gpointer cfg_persist_config_fetch(GlobalConfig *cfg, const gchar *name)
Definition: cfg.c:789
const gchar * cfg_get_filename(const GlobalConfig *cfg)
Definition: cfg.c:819
gboolean cfg_set_log_level(GlobalConfig *self, const gchar *log_level)
Definition: cfg.c:113
void persist_config_free(PersistConfig *self)
Definition: cfg-persist.c:98
GlobalConfig * cfg_new(gint version)
Definition: cfg.c:457
gint cfg_lookup_mark_mode(const gchar *mark_mode)
Definition: cfg.c:88
gboolean cfg_load_module(GlobalConfig *cfg, const gchar *module_name)
Definition: cfg.c:148
void cfg_persist_config_move(GlobalConfig *src, GlobalConfig *dest)
Definition: cfg.c:763
gboolean is_source_mangle_callback_registered(GlobalConfig *src, mangle_callback cb)
Definition: cfg.c:808
gint cfg_ts_format_value(gchar *format)
Definition: cfg.c:61
gboolean(* mangle_callback)(GlobalConfig *cfg, LogMessage *msg, gpointer user_data)
Definition: cfg.h:180
gboolean cfg_is_shutting_down(GlobalConfig *cfg)
Definition: cfg.c:283
void cfg_set_user_config_id(GlobalConfig *self, const gchar *id)
Definition: cfg.c:646
gboolean cfg_set_version(GlobalConfig *self, gint version)
Definition: cfg.c:363
Plugin * cfg_find_plugin(GlobalConfig *cfg, gint plugin_type, const gchar *plugin_name)
Definition: cfg.c:202
gboolean cfg_set_current_version(GlobalConfig *self)
Definition: cfg.c:423
void cfg_free(GlobalConfig *self)
Definition: cfg.c:722
gboolean cfg_init(GlobalConfig *cfg)
Definition: cfg.c:290
void cfg_set_mark_mode(GlobalConfig *self, const gchar *mark_mode)
Definition: cfg.c:107
void cfg_load_forced_modules(GlobalConfig *self)
Definition: cfg.c:154
@ MM_INTERNAL
Definition: cfg.h:49
@ MM_DST_IDLE
Definition: cfg.h:50
@ MM_HOST_IDLE
Definition: cfg.h:51
@ MM_PERIODICAL
Definition: cfg.h:52
@ MM_NONE
Definition: cfg.h:53
@ MM_GLOBAL
Definition: cfg.h:54
void register_source_mangle_callback(GlobalConfig *src, mangle_callback cb)
Definition: cfg.c:802
gboolean cfg_run_parser(GlobalConfig *self, CfgLexer *lexer, CfgParser *parser, gpointer *result, gpointer arg)
Definition: cfg.c:552
GlobalConfig * cfg_new_subordinate(GlobalConfig *master)
Definition: cfg.c:523
void cfg_set_version_without_validation(GlobalConfig *self, gint version)
Definition: cfg.c:357
gint cfg_tz_convert_value(gchar *convert)
void cfg_shutdown(GlobalConfig *self)
Definition: cfg.c:276
void cfg_discover_candidate_modules(GlobalConfig *self)
Definition: cfg.c:180
gboolean cfg_deinit(GlobalConfig *cfg)
Definition: cfg.c:349
GlobalConfig * cfg_new_snippet(void)
Definition: cfg.c:511
gboolean cfg_read_config(GlobalConfig *cfg, const gchar *fname, gchar *preprocess_into)
Definition: cfg.c:670
gboolean cfg_allow_config_dups(GlobalConfig *self)
Definition: cfg.c:430
void uregister_source_mangle_callback(GlobalConfig *src, mangle_callback cb)
Definition: cfg.c:813
void cfg_format_id(GlobalConfig *self, GString *id)
Definition: cfg.c:653
const gchar * name
Definition: debugger.c:265
void version(void)
Definition: dqtool.c:719
EVTTAG * evt_tag_printf(const char *tag, const char *format,...) G_GNUC_PRINTF(2
GlobalConfig * configuration
Definition: globals.c:27
#define self
Definition: rcptid.c:38
Definition: cfg-lexer.h:88
Definition: cfg-parser.h:34
Definition: cfg-tree.h:165
Definition: dnscache.h:32
Definition: file-perms.h:31
Definition: healthcheck-stats.h:30
Definition: host-resolve.h:30
Definition: cfg-persist.h:31
Definition: stats.h:33
Definition: cfg.h:59
gchar * bad_hostname_re
Definition: cfg.h:89
gchar * recv_time_zone
Definition: cfg.h:109
LogTemplate * proto_template
Definition: cfg.h:117
GHashTable * module_config
Definition: cfg.h:123
gint type_cast_strictness
Definition: cfg.h:95
gint time_reap
Definition: cfg.h:93
CfgArgs * globals
Definition: cfg.h:74
gint time_reopen
Definition: cfg.h:92
gboolean enable_forced_modules
Definition: cfg.h:72
gint mark_mode
Definition: cfg.h:80
gboolean create_dirs
Definition: cfg.h:102
gint suppress
Definition: cfg.h:94
PluginContext plugin_context
Definition: cfg.h:70
gboolean trim_large_messages
Definition: cfg.h:99
gint log_fifo_size
Definition: cfg.h:97
gboolean bad_hostname_compiled
Definition: cfg.h:87
gint log_level
Definition: cfg.h:100
gboolean use_plugin_discovery
Definition: cfg.h:71
gchar * user_config_id
Definition: cfg.h:65
PersistConfig * persist
Definition: cfg.h:121
CfgTree tree
Definition: cfg.h:125
gchar * custom_domain
Definition: cfg.h:90
gboolean use_uniqid
Definition: cfg.h:105
gboolean pass_unix_credentials
Definition: cfg.h:82
LogTemplateOptions template_options
Definition: cfg.h:110
gboolean threaded
Definition: cfg.h:81
LogTemplate * file_template
Definition: cfg.h:116
HostResolveOptions host_resolve_options
Definition: cfg.h:111
gint log_msg_size
Definition: cfg.h:98
HealthCheckStatsOptions healthcheck_options
Definition: cfg.h:77
gboolean check_hostname
Definition: cfg.h:85
gboolean keep_hostname
Definition: cfg.h:84
gboolean chain_hostnames
Definition: cfg.h:83
gboolean check_program
Definition: cfg.h:86
gchar * proto_template_name
Definition: cfg.h:114
GString * preprocess_config
Definition: cfg.h:127
DNSCacheOptions dns_cache_options
Definition: cfg.h:91
const gchar * filename
Definition: cfg.h:69
gint user_version
Definition: cfg.h:62
StatsOptions stats_options
Definition: cfg.h:76
GList * source_mangle_callback_list
Definition: cfg.h:104
guint8 * config_hash
Definition: cfg.h:67
GString * original_config
Definition: cfg.h:128
FilePermOptions file_perm_options
Definition: cfg.h:103
gint mark_freq
Definition: cfg.h:78
CfgLexer * lexer
Definition: cfg.h:73
gboolean keep_timestamp
Definition: cfg.h:107
PersistState * state
Definition: cfg.h:122
guint min_iw_size_per_reader
Definition: cfg.h:119
gint flush_lines
Definition: cfg.h:79
GList * file_list
Definition: cfg.h:130
gchar * file_template_name
Definition: cfg.h:113
regex_t bad_hostname
Definition: cfg.h:88
GlobalConfig * cfg
Definition: test_batched_ack_tracker.c:34
GString * value
Definition: test_decode.c:28
CfgParserMock * parser
Definition: test_lexer.c:36
GString * result
Definition: test_lexer_block.c:34
LogMessage * msg
Definition: test_rename.c:35
#define version_convert_from_user(v)
Definition: versioning.h:217