void cfg_load_candidate_modules(GlobalConfig *self) { /* we enable autoload for pre-3.1 configs or when the user requested * auto-load (the default) */ if ((cfg_is_config_version_older(self, 0x0302) || atoi(cfg_args_get(self->lexer->globals, "autoload-compiled-modules"))) && !self->candidate_plugins) { plugin_load_candidate_modules(self); } }
void log_reader_options_defaults(LogReaderOptions *options) { log_source_options_defaults(&options->super); log_proto_server_options_defaults(&options->proto_options.super); msg_format_options_defaults(&options->parse_options); options->fetch_limit = 10; if (configuration && cfg_is_config_version_older(configuration, 0x0300)) { msg_warning_once("WARNING: input: sources do not remove new-line characters from messages by default from " VERSION_3_0 ", please add 'no-multi-line' flag to your configuration if you want to retain this functionality", NULL); options->parse_options.flags |= LP_NO_MULTI_LINE; } }
void cfg_set_version(GlobalConfig *self, gint version) { self->user_version = version; if (cfg_is_config_version_older(self, VERSION_VALUE)) { msg_warning("WARNING: Configuration file format is too old, syslog-ng is running in compatibility mode " "Please update it to use the " VERSION_CURRENT " format at your time of convinience, " "compatibility mode can operate less efficiently in some cases. " "To upgrade the configuration, please review the warnings about incompatible changes printed " "by syslog-ng, and once completed change the @version header at the top of the configuration " "file.", NULL); } else if (version_convert_from_user(self->user_version) > VERSION_VALUE) { msg_warning("WARNING: Configuration file format is newer than the current version, please specify the " "current version number (" VERSION_CURRENT_VER_ONLY ") in the @version directive. " "syslog-ng will operate at its highest supported version in this mode", NULL); self->user_version = VERSION_VALUE; } if (cfg_is_config_version_older(self, 0x0300)) { msg_warning("WARNING: global: the default value of chain_hostnames is changing to 'no' in " VERSION_3_0 ", please update your configuration accordingly", NULL); self->chain_hostnames = TRUE; } if (cfg_is_config_version_older(self, 0x0303)) { msg_warning("WARNING: global: the default value of log_fifo_size() has changed to 10000 in " VERSION_3_3 " to reflect log_iw_size() changes for tcp()/udp() window size changes", NULL); } }
void log_matcher_options_init(LogMatcherOptions *options, GlobalConfig *cfg) { if (!options->type) { const gchar *default_matcher = "pcre"; if (cfg_is_config_version_older(cfg, 0x0306)) { default_matcher = "posix"; } if (!log_matcher_options_set_type(options, default_matcher)) g_assert_not_reached(); } }
void log_matcher_options_init(LogMatcherOptions *options, GlobalConfig *cfg) { if (!options->type) { const gchar *default_matcher = "pcre"; if (cfg_is_config_version_older(cfg, 0x0306)) { msg_warning_once("WARNING: syslog-ng changed the default regexp implementation to PCRE starting from " VERSION_3_6 ", please ensure your regexp works with PCRE or please specify type(\"posix\") in filters explicitly", NULL); default_matcher = "posix"; } if (!log_matcher_options_set_type(options, default_matcher)) g_assert_not_reached(); } }
static gboolean afunix_sd_adjust_reader_options(AFUnixSourceDriver *self, GlobalConfig *cfg) { self->super.reader_options.parse_options.flags |= LP_LOCAL; if (cfg_is_config_version_older(cfg, 0x0302)) { msg_warning_once("WARNING: the expected message format is being changed for unix-domain transports to improve " "syslogd compatibity with " VERSION_3_2 ". If you are using custom " "applications which bypass the syslog() API, you might " "need the 'expect-hostname' flag to get the old behaviour back", NULL); } else { self->super.reader_options.parse_options.flags &= ~LP_EXPECT_HOSTNAME; } return TRUE; }
LogMatcher * log_matcher_posix_re_new(const LogMatcherOptions *options) { LogMatcherPosixRe *self = g_new0(LogMatcherPosixRe, 1); log_matcher_init(&self->super, options); self->super.compile = log_matcher_posix_re_compile; self->super.match = log_matcher_posix_re_match; self->super.replace = log_matcher_posix_re_replace; self->super.free_fn = log_matcher_posix_re_free; if (configuration && cfg_is_config_version_older(configuration, 0x0300)) { msg_warning_once("WARNING: filters do not store matches in macros by default from " VERSION_3_0 ", please update your configuration by using an explicit 'store-matches' flag to achieve that", NULL); self->super.flags = LMF_STORE_MATCHES; } return &self->super; }
gboolean cfg_allow_config_dups(GlobalConfig *self) { const gchar *s; if (cfg_is_config_version_older(self, 0x0303)) return TRUE; s = cfg_args_get(self->lexer->globals, "allow-config-dups"); if (s && atoi(s)) { return TRUE; } else { /* duplicate found, but allow-config-dups is not enabled, hint the user that he might want to use allow-config-dups */ msg_warning_once("WARNING: Duplicate configuration objects (sources, destinations, ...) are not allowed by default starting with syslog-ng 3.3, add \"@define allow-config-dups 1\" to your configuration to reenable", NULL); return FALSE; } }
void log_reader_options_defaults(LogReaderOptions *options) { log_source_options_defaults(&options->super); msg_format_options_defaults(&options->parse_options); options->padding = 0; options->fetch_limit = 10; options->msg_size = -1; options->follow_freq = -1; options->text_encoding = NULL; if (configuration && cfg_is_config_version_older(configuration, 0x0300)) { static gboolean warned; if (!warned) { msg_warning("WARNING: input: sources do not remove new-line characters from messages by default from " VERSION_3_0 ", please add 'no-multi-line' flag to your configuration if you want to retain this functionality", NULL); warned = TRUE; } options->parse_options.flags |= LP_NO_MULTI_LINE; } }
LogDriver * afpipe_sd_new(gchar *filename, GlobalConfig *cfg) { AFFileSourceDriver *self = affile_sd_new_instance(filename, cfg); self->file_open_options.is_pipe = TRUE; self->file_open_options.open_flags = DEFAULT_SD_OPEN_FLAGS_PIPE; if (cfg_is_config_version_older(cfg, 0x0302)) { msg_warning_once("WARNING: the expected message format is being changed for pipe() to improve " "syslogd compatibity with " VERSION_3_2 ". If you are using custom " "applications which bypass the syslog() API, you might " "need the 'expect-hostname' flag to get the old behaviour back", NULL); } else { self->reader_options.parse_options.flags &= ~LP_EXPECT_HOSTNAME; } return &self->super.super; }
static gboolean transport_mapper_syslog_apply_transport(TransportMapper *s, GlobalConfig *cfg) { TransportMapperInet *self = (TransportMapperInet *) s; const gchar *transport = self->super.transport; /* determine default port, apply transport setting to afsocket flags */ if (!transport_mapper_apply_transport_method(s, cfg)) return FALSE; if (strcasecmp(transport, "udp") == 0) { if (cfg_is_config_version_older(cfg, 0x0303)) { self->server_port_change_warning = "WARNING: Default port for syslog(transport(udp)) has changed from 601 to 514 in " VERSION_3_3 ", please update your configuration"; self->server_port = 601; } else self->server_port = SYSLOG_TRANSPORT_UDP_PORT; self->super.sock_type = SOCK_DGRAM; self->super.sock_proto = IPPROTO_UDP; self->super.logproto = "dgram"; } else if (strcasecmp(transport, "tcp") == 0) { self->server_port = SYSLOG_TRANSPORT_TCP_PORT; self->super.logproto = "framed"; self->super.sock_type = SOCK_STREAM; self->super.sock_proto = IPPROTO_TCP; } else if (strcasecmp(transport, "tls") == 0) { if (cfg_is_config_version_older(cfg, 0x0303)) { self->server_port_change_warning = "WARNING: Default port for syslog(transport(tls)) has changed from 601 to 6514 in " VERSION_3_3 ", please update your configuration"; self->server_port = 601; } else self->server_port = SYSLOG_TRANSPORT_TLS_PORT; self->super.logproto = "framed"; self->super.sock_type = SOCK_STREAM; self->super.sock_proto = IPPROTO_TCP; self->require_tls = TRUE; } else { self->super.logproto = self->super.transport; self->super.sock_type = SOCK_STREAM; /* FIXME: look up port/protocol from the logproto */ self->server_port = 514; self->super.sock_proto = IPPROTO_TCP; self->allow_tls = TRUE; } g_assert(self->server_port != 0); if (!transport_mapper_inet_validate_tls_options(self)) return FALSE; return TRUE; }
gboolean log_macro_expand(GString *result, gint id, gboolean escape, LogTemplateOptions *opts, gint tz, gint32 seq_num, const gchar *context_id, LogMessage *msg) { static LogTemplateOptions default_opts = { TRUE, TS_FMT_BSD, 0, { NULL, NULL }, { NULL, NULL } }; if (!opts) opts = &default_opts; switch (id) { case M_FACILITY: { /* facility */ const char *n; n = syslog_name_lookup_name_by_value(msg->pri & LOG_FACMASK, sl_facilities); if (n) { g_string_append(result, n); } else { format_uint32_padded(result, 0, 0, 16, (msg->pri & LOG_FACMASK) >> 3); } break; } case M_FACILITY_NUM: { format_uint32_padded(result, 0, 0, 10, (msg->pri & LOG_FACMASK) >> 3); break; } case M_LEVEL: { /* level */ const char *n; n = syslog_name_lookup_name_by_value(msg->pri & LOG_PRIMASK, sl_levels); if (n) { g_string_append(result, n); } else { format_uint32_padded(result, 0, 0, 10, msg->pri & LOG_PRIMASK); } break; } case M_LEVEL_NUM: { format_uint32_padded(result, 0, 0, 10, msg->pri & LOG_PRIMASK); break; } case M_TAG: { format_uint32_padded(result, 2, '0', 16, msg->pri); break; } case M_TAGS: { log_msg_print_tags(msg, result); break; } case M_BSDTAG: { format_uint32_padded(result, 0, 0, 10, (msg->pri & LOG_PRIMASK)); g_string_append_c(result, (((msg->pri & LOG_FACMASK) >> 3) + 'A')); break; } case M_PRI: { format_uint32_padded(result, 0, 0, 10, msg->pri); break; } case M_HOST: { if (msg->flags & LF_CHAINED_HOSTNAME) { /* host */ const gchar *p1, *p2; int remaining, length; gssize host_len; const gchar *host = log_msg_get_value(msg, LM_V_HOST, &host_len); p1 = memchr(host, '@', host_len); if (p1) p1++; else p1 = host; remaining = host_len - (p1 - host); p2 = memchr(p1, '/', remaining); length = p2 ? p2 - p1 : host_len - (p1 - host); result_append(result, p1, length, escape); } else { result_append_value(result, msg, LM_V_HOST, escape); } break; } case M_SDATA: if (escape) { GString *sdstr = g_string_sized_new(0); log_msg_append_format_sdata(msg, sdstr, seq_num); result_append(result, sdstr->str, sdstr->len, TRUE); g_string_free(sdstr, TRUE); } else { log_msg_append_format_sdata(msg, result, seq_num); } break; case M_MSGHDR: if ((msg->flags & LF_LEGACY_MSGHDR)) { /* fast path for now, as most messages come from legacy devices */ result_append_value(result, msg, LM_V_LEGACY_MSGHDR, escape); } else { /* message, complete with program name and pid */ gssize len; len = result->len; result_append_value(result, msg, LM_V_PROGRAM, escape); if (len != result->len) { const gchar *pid = log_msg_get_value(msg, LM_V_PID, &len); if (len > 0) { result_append(result, "[", 1, FALSE); result_append(result, pid, len, escape); result_append(result, "]", 1, FALSE); } result_append(result, ": ", 2, FALSE); } } break; case M_MESSAGE: if (cfg_is_config_version_older(configuration, 0x0300)) log_macro_expand(result, M_MSGHDR, escape, opts, tz, seq_num, context_id, msg); result_append_value(result, msg, LM_V_MESSAGE, escape); break; case M_SOURCE_IP: { gchar *ip; if (msg->saddr && (g_sockaddr_inet_check(msg->saddr) || #if ENABLE_IPV6 g_sockaddr_inet6_check(msg->saddr)) #else 0) #endif ) { gchar buf[MAX_SOCKADDR_STRING]; g_sockaddr_format(msg->saddr, buf, sizeof(buf), GSA_ADDRESS_ONLY); ip = buf; } else { ip = "127.0.0.1"; } result_append(result, ip, strlen(ip), escape); break; } case M_SEQNUM: { if (seq_num) { format_uint32_padded(result, 0, 0, 10, seq_num); } break; } case M_CONTEXT_ID: { if (context_id) { result_append(result, context_id, strlen(context_id), escape); } break; } case M_LOGHOST: { gsize hname_len; const gchar *hname = get_local_hostname(&hname_len); result_append(result, hname, hname_len, escape); break; } case M_SYSUPTIME: { GTimeVal ct; g_get_current_time(&ct); format_uint64_padded(result, 0, 0, 10, g_time_val_diff(&ct, &app_uptime) / 1000 / 10); break; } default: { /* year, month, day */ struct tm *tm, tm_storage; gchar buf[64]; gint length; time_t t; LogStamp *stamp, sstamp; glong zone_ofs; guint tmp_hour; if (id >= M_TIME_FIRST && id <= M_TIME_LAST) { stamp = &msg->timestamps[LM_TS_STAMP]; } else if (id >= M_TIME_FIRST + M_RECVD_OFS && id <= M_TIME_LAST + M_RECVD_OFS) { id -= M_RECVD_OFS; stamp = &msg->timestamps[LM_TS_RECVD]; } else if (id >= M_TIME_FIRST + M_STAMP_OFS && id <= M_TIME_LAST + M_STAMP_OFS) { id -= M_STAMP_OFS; stamp = &msg->timestamps[LM_TS_STAMP]; } else if (id >= M_TIME_FIRST + M_CSTAMP_OFS && id <= M_TIME_LAST + M_CSTAMP_OFS) { GTimeVal tv; id -= M_CSTAMP_OFS; cached_g_current_time(&tv); sstamp.tv_sec = tv.tv_sec; sstamp.tv_usec = tv.tv_usec; sstamp.zone_offset = -1; stamp = &sstamp; } else { g_assert_not_reached(); break; } /* try to use the following zone values in order: * destination specific timezone, if one is specified * message specific timezone, if one is specified * local timezone */ zone_ofs = (opts->time_zone_info[tz] != NULL ? time_zone_info_get_offset(opts->time_zone_info[tz], stamp->tv_sec) : stamp->zone_offset); if (zone_ofs == -1) zone_ofs = stamp->zone_offset; t = stamp->tv_sec + zone_ofs; cached_gmtime(&t, &tm_storage); tm = &tm_storage; switch (id) { case M_WEEK_DAY_ABBREV: g_string_append_len(result, weekday_names_abbrev[tm->tm_wday], 3); break; case M_WEEK_DAY_NAME: g_string_append(result, weekday_names[tm->tm_wday]); break; case M_WEEK_DAY: format_uint32_padded(result, 0, 0, 10, tm->tm_wday + 1); break; case M_WEEK: format_uint32_padded(result, 2, '0', 10, (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7); break; case M_YEAR: format_uint32_padded(result, 4, '0', 10, tm->tm_year + 1900); break; case M_YEAR_DAY: format_uint32_padded(result, 3, '0', 10, tm->tm_yday + 1); break; case M_MONTH: format_uint32_padded(result, 2, '0', 10, tm->tm_mon + 1); break; case M_MONTH_WEEK: format_uint32_padded(result, 0, 0, 10, ((tm->tm_mday / 7) + ((tm->tm_wday > 0) && ((tm->tm_mday % 7) >= tm->tm_wday)))); break; case M_MONTH_ABBREV: g_string_append_len(result, month_names_abbrev[tm->tm_mon], 3); break; case M_MONTH_NAME: g_string_append(result, month_names[tm->tm_mon]); break; case M_DAY: format_uint32_padded(result, 2, '0', 10, tm->tm_mday); break; case M_HOUR: format_uint32_padded(result, 2, '0', 10, tm->tm_hour); break; case M_HOUR12: if (tm->tm_hour < 12) tmp_hour = tm->tm_hour; else tmp_hour = tm->tm_hour - 12; if (tmp_hour == 0) tmp_hour = 12; format_uint32_padded(result, 2, '0', 10, tmp_hour); break; case M_MIN: format_uint32_padded(result, 2, '0', 10, tm->tm_min); break; case M_SEC: format_uint32_padded(result, 2, '0', 10, tm->tm_sec); break; case M_MSEC: format_uint32_padded(result, 3, '0', 10, stamp->tv_usec/1000); break; case M_USEC: format_uint32_padded(result, 6, '0', 10, stamp->tv_usec); break; case M_AMPM: g_string_append(result, tm->tm_hour < 12 ? "AM" : "PM"); break; case M_DATE: case M_STAMP: case M_ISODATE: case M_FULLDATE: case M_UNIXTIME: { gint format = id == M_DATE ? TS_FMT_BSD : id == M_ISODATE ? TS_FMT_ISO : id == M_FULLDATE ? TS_FMT_FULL : id == M_UNIXTIME ? TS_FMT_UNIX : opts->ts_format; log_stamp_append_format(stamp, result, format, zone_ofs, opts->frac_digits); break; } case M_TZ: case M_TZOFFSET: length = format_zone_info(buf, sizeof(buf), zone_ofs); g_string_append_len(result, buf, length); break; } break; } }
FilterExprNode * fop_cmp_new(LogTemplate *left, LogTemplate *right, gint op) { FilterCmp *self = g_new0(FilterCmp, 1); filter_expr_node_init_instance(&self->super); self->super.eval = fop_cmp_eval; self->super.free_fn = fop_cmp_free; self->left = left; self->right = right; self->super.type = "CMP"; switch (op) { case KW_NUM_LT: self->cmp_op = FCMP_NUM; case KW_LT: self->cmp_op |= FCMP_LT; break; case KW_NUM_LE: self->cmp_op = FCMP_NUM; case KW_LE: self->cmp_op |= FCMP_LT | FCMP_EQ; break; case KW_NUM_EQ: self->cmp_op = FCMP_NUM; case KW_EQ: self->cmp_op |= FCMP_EQ; break; case KW_NUM_NE: self->cmp_op = FCMP_NUM; case KW_NE: self->cmp_op |= 0; break; case KW_NUM_GE: self->cmp_op = FCMP_NUM; case KW_GE: self->cmp_op |= FCMP_GT | FCMP_EQ; break; case KW_NUM_GT: self->cmp_op = FCMP_NUM; case KW_GT: self->cmp_op |= FCMP_GT; break; } if (self->cmp_op & FCMP_NUM && cfg_is_config_version_older(left->cfg, 0x0308)) { msg_warning("WARNING: due to a bug in " VERSION_3_7 " and earlier, " "numeric comparison operators like '!=' in filter " "expressions were evaluated as string operators. This is fixed in " VERSION_3_8 ". " "As we are operating in compatibility mode, syslog-ng will exhibit the buggy " "behaviour as previous versions until you bump the @version value in your " "configuration file", NULL); self->cmp_op &= ~FCMP_NUM; } return &self->super; }
static gboolean afinet_dd_apply_transport(AFSocketDestDriver *s) { AFInetDestDriver *self = (AFInetDestDriver *) s; GlobalConfig *cfg = log_pipe_get_config(&s->super.super.super); gchar *default_dest_port = NULL; struct protoent *ipproto_ent; g_sockaddr_unref(self->super.bind_addr); g_sockaddr_unref(self->super.dest_addr); if (self->super.address_family == AF_INET) { self->super.bind_addr = g_sockaddr_inet_new("0.0.0.0", 0); self->super.dest_addr = g_sockaddr_inet_new("0.0.0.0", 0); } #if ENABLE_IPV6 else if (self->super.address_family == AF_INET6) { self->super.bind_addr = g_sockaddr_inet6_new("::", 0); self->super.dest_addr = g_sockaddr_inet6_new("::", 0); } #endif else { /* address family not known */ g_assert_not_reached(); } if (self->super.transport == NULL) { if (self->super.sock_type == SOCK_STREAM) afsocket_dd_set_transport(&self->super.super.super, "tcp"); else afsocket_dd_set_transport(&self->super.super.super, "udp"); } if (strcasecmp(self->super.transport, "udp") == 0) { static gboolean msg_udp_source_port_warning = FALSE; if (!self->dest_port) { /* NOTE: this version number change has happened in a different * major version in OSE vs. PE, thus the update behaviour must * be triggered differently. In OSE it needs to be triggered * when the config version has changed to 3.3, in PE when 3.2. * * This is unfortunate, the only luck we have to be less * confusing is that syslog() driver was seldom used. * */ if (self->super.syslog_protocol && cfg_is_config_version_older(cfg, 0x0303)) { if (!msg_udp_source_port_warning) { msg_warning("WARNING: Default port for syslog(transport(udp)) has changed from 601 to 514 in syslog-ng 3.3, please update your configuration", evt_tag_str("id", self->super.super.super.id), NULL); msg_udp_source_port_warning = TRUE; } default_dest_port = "601"; } else default_dest_port = "514"; } self->super.sock_type = SOCK_DGRAM; self->super.sock_protocol = 0; self->super.logproto_name = "dgram"; } else if (strcasecmp(self->super.transport, "tcp") == 0) { if (self->super.syslog_protocol) { self->super.logproto_name = "framed"; default_dest_port = "601"; } else { self->super.logproto_name = "text"; default_dest_port = "514"; } self->super.sock_type = SOCK_STREAM; self->super.sock_protocol = 0; } else if (strcasecmp(self->super.transport, "tls") == 0) { static gboolean msg_tls_source_port_warning = FALSE; g_assert(self->super.syslog_protocol); if (!self->dest_port) { /* NOTE: this version number change has happened in a different * major version in OSE vs. PE, thus the update behaviour must * be triggered differently. In OSE it needs to be triggered * when the config version has changed to 3.3, in PE when 3.2. * * This is unfortunate, the only luck we have to be less * confusing is that syslog() driver was seldom used. * */ if (cfg_is_config_version_older(cfg, 0x0303)) { if (!msg_tls_source_port_warning) { msg_warning("WARNING: Default port for syslog(transport(tls)) is modified from 601 to 6514", evt_tag_str("id", self->super.super.super.id), NULL); msg_tls_source_port_warning = TRUE; } default_dest_port = "601"; } else default_dest_port = "6514"; } self->super.require_tls = TRUE; self->super.sock_type = SOCK_STREAM; self->super.logproto_name = "framed"; } else { self->super.sock_type = SOCK_STREAM; self->super.logproto_name = self->super.transport; } if ((self->bind_ip && !resolve_hostname(&self->super.bind_addr, self->bind_ip))) return FALSE; if (!self->super.sock_protocol) { if (self->super.sock_type == SOCK_STREAM) self->super.sock_protocol = IPPROTO_TCP; else self->super.sock_protocol = IPPROTO_UDP; } ipproto_ent = getprotobynumber(self->super.sock_protocol); afinet_set_port(self->super.dest_addr, self->dest_port ? : default_dest_port, ipproto_ent ? ipproto_ent->p_name : (self->super.sock_type == SOCK_STREAM) ? "tcp" : "udp"); if (!self->super.dest_name) self->super.dest_name = g_strdup_printf("%s:%d", self->super.hostname, g_sockaddr_inet_check(self->super.dest_addr) ? g_sockaddr_inet_get_port(self->super.dest_addr) #if ENABLE_IPV6 : g_sockaddr_inet6_get_port(self->super.dest_addr) #else : 0 #endif ); #if BUILD_WITH_SSL if (self->super.require_tls && !self->super.tls_context) { msg_error("transport(tls) was specified, but tls() options missing", evt_tag_str("id", self->super.super.super.id), NULL); return FALSE; } #endif return TRUE; }