static int log_cfg_read(config_file_t config, void *module_config, char *msg_out) { int rc, tmpval; char tmpstr[1024]; log_config_t *conf = (log_config_t *) module_config; config_item_t log_block; /* all allowed parameters names */ static const char * const allowed_params[] = { "debug_level", "log_file", "report_file", "alert_file", "alert_mail", "stats_interval", "batch_alert_max", "alert_show_attrs", "syslog_facility", "log_procname", "log_hostname", #ifdef HAVE_CHANGELOGS "changelogs_file", #endif NULL }; /* std parameters */ const cfg_param_t cfg_params[] = { {"log_file", PT_STRING, PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED, conf->log_file, sizeof(conf->log_file)} , {"report_file", PT_STRING, PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED, conf->report_file, sizeof(conf->report_file)} , {"alert_file", PT_STRING, PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED, conf->alert_file, sizeof(conf->alert_file)} , {"alert_mail", PT_STRING, PFLG_MAIL, conf->alert_mail, sizeof(conf->alert_mail)} , #ifdef HAVE_CHANGELOGS {"changelogs_file", PT_STRING, PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS | PFLG_STDIO_ALLOWED, conf->changelogs_file, sizeof(conf->changelogs_file)} , #endif /* TODO add cfg flag: clean if not found */ {"stats_interval", PT_DURATION, PFLG_POSITIVE | PFLG_NOT_NULL, &conf->stats_interval, 0} , {"batch_alert_max", PT_INT, PFLG_POSITIVE, &conf->batch_alert_max, 0} , {"alert_show_attrs", PT_BOOL, 0, &conf->alert_show_attrs, 0} , {"log_procname", PT_BOOL, 0, &conf->log_process, 0} , {"log_hostname", PT_BOOL, 0, &conf->log_host, 0} , {NULL, 0, 0, NULL, 0} }; /* get Log block */ rc = get_cfg_block(config, RBH_LOG_CONFIG_BLOCK, &log_block, msg_out); if (rc) return rc == ENOENT ? 0 : rc; /* not mandatory */ /* read std parameters */ rc = read_scalar_params(log_block, RBH_LOG_CONFIG_BLOCK, cfg_params, msg_out); if (rc) return rc; /* read specific parameters */ rc = GetStringParam(log_block, RBH_LOG_CONFIG_BLOCK, "debug_level", PFLG_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out); if ((rc != 0) && (rc != ENOENT)) return rc; else if (rc != ENOENT) { tmpval = str2debuglevel(tmpstr); if (tmpval < 0) { sprintf(msg_out, "Invalid value for " RBH_LOG_CONFIG_BLOCK "::debug_level: '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected", tmpstr); return EINVAL; } else conf->debug_level = tmpval; } rc = GetStringParam(log_block, RBH_LOG_CONFIG_BLOCK, "syslog_facility", PFLG_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out); if ((rc != 0) && (rc != ENOENT)) return rc; else if (rc == 0) { rc = check_syslog_facility(tmpstr, &conf->syslog_facility, &conf->syslog_priority); if (rc) { sprintf(msg_out, "Invalid syslog channel '%s': expected syntax: <facility>[.<priority>]", tmpstr); return rc; } } CheckUnknownParameters(log_block, RBH_LOG_CONFIG_BLOCK, allowed_params); return 0; }
int ReadLogConfig( config_file_t config, void *module_config, char *msg_out, int for_reload ) { int rc, tmpval; char tmpstr[1024]; log_config_t *conf = ( log_config_t * ) module_config; static const char *allowed_params[] = { "debug_level", "log_file", "report_file", "alert_file", "alert_mail", "stats_interval", "batch_alert_max", "alert_show_attrs", "syslog_facility", NULL }; /* get Log block */ config_item_t log_block = rh_config_FindItemByName( config, RBH_LOG_CONFIG_BLOCK ); if ( log_block == NULL ) { strcpy( msg_out, "Missing configuration block '" RBH_LOG_CONFIG_BLOCK "'" ); /* no parameter is mandatory => Not an error */ return 0; } if ( rh_config_ItemType( log_block ) != CONFIG_ITEM_BLOCK ) { sprintf( msg_out, "A block is expected for '" RBH_LOG_CONFIG_BLOCK "' item, line %d", rh_config_GetItemLine( log_block ) ); return EINVAL; } /* retrieve parameters */ rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "debug_level", STR_PARAM_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc != ENOENT ) { tmpval = str2debuglevel( tmpstr ); if ( tmpval < 0 ) { sprintf( msg_out, "Invalid value for " RBH_LOG_CONFIG_BLOCK "::debug_level: '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected", tmpstr ); return EINVAL; } else conf->debug_level = tmpval; } rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "log_file", STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED, conf->log_file, RBH_PATH_MAX, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "report_file", STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED, conf->report_file, RBH_PATH_MAX, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_file", STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED, conf->alert_file, 1024, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc == ENOENT ) conf->alert_file[0] = '\0'; rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "syslog_facility", STR_PARAM_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc == 0 ) { rc = check_syslog_facility( tmpstr, &conf->syslog_facility, &conf->syslog_priority ); if (rc) { sprintf( msg_out, "Invalid syslog channel '%s': expected syntax: <facility>[.<priority>]", tmpstr ); return rc; } } rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_mail", STR_PARAM_MAIL, conf->alert_mail, 256, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc == ENOENT ) conf->alert_mail[0] = '\0'; rc = GetDurationParam( log_block, RBH_LOG_CONFIG_BLOCK, "stats_interval", INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, &tmpval, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc != ENOENT ) conf->stats_interval = tmpval; rc = GetIntParam( log_block, RBH_LOG_CONFIG_BLOCK, "batch_alert_max", INT_PARAM_POSITIVE, (int *)&conf->batch_alert_max, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; rc = GetBoolParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_show_attrs", INT_PARAM_POSITIVE, &conf->alert_show_attrs, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; CheckUnknownParameters( log_block, RBH_LOG_CONFIG_BLOCK, allowed_params ); return 0; }