bool load_global_configuration_from_dirs(const char *dirs[], int dir_flags[]) { if (s_global_settings == NULL) { s_global_settings = new_map_string(); bool ret = load_conf_file_from_dirs_ext("libreport.conf", dirs, dir_flags, s_global_settings, /*don't skip without value*/ false); if (!ret) { error_msg("Failed to load libreport global configuration"); free_global_configuration(); return false; } map_string_iter_t iter; init_map_string_iter(&iter, s_global_settings); const char *key, *value; while(next_map_string_iter(&iter, &key, &value)) { /* Die to avoid security leaks in case where someone made a typo in a option name */ if (!is_in_string_list(key, s_recognized_options)) { error_msg("libreport global configuration contains unrecognized option : '%s'", key); free_global_configuration(); return false; } } } else log_notice("libreport global configuration already loaded"); return true; }
static void ParseCommon(map_string_t *settings, const char *conf_filename) { const char *value; value = get_map_string_item_or_NULL(settings, "OpenGPGCheck"); if (value) { settings_bOpenGPGCheck = string_to_bool(value); remove_map_string_item(settings, "OpenGPGCheck"); } value = get_map_string_item_or_NULL(settings, "BlackList"); if (value) { settings_setBlackListedPkgs = parse_list(value); remove_map_string_item(settings, "BlackList"); } value = get_map_string_item_or_NULL(settings, "BlackListedPaths"); if (value) { settings_setBlackListedPaths = parse_list(value); remove_map_string_item(settings, "BlackListedPaths"); } value = get_map_string_item_or_NULL(settings, "ProcessUnpackaged"); if (value) { settings_bProcessUnpackaged = string_to_bool(value); remove_map_string_item(settings, "ProcessUnpackaged"); } value = get_map_string_item_or_NULL(settings, "Interpreters"); if (value) { settings_Interpreters = parse_list(value); remove_map_string_item(settings, "Interpreters"); } map_string_iter_t iter; const char *name; /*char *value; - already declared */ init_map_string_iter(&iter, settings); while (next_map_string_iter(&iter, &name, &value)) { error_msg("Unrecognized variable '%s' in '%s'", name, conf_filename); } }
map_string_t *clone_map_string(map_string_t *ms) { if (ms == NULL) return NULL; map_string_t *clone = new_map_string(); const char *key; const char *value; map_string_iter_t iter; init_map_string_iter(&iter, ms); while(next_map_string_iter(&iter, &key, &value)) insert_map_string(clone, xstrdup(key), xstrdup(value)); return clone; }
static void ParseCommon(map_string_t *settings, const char *conf_filename) { const char *value; value = get_map_string_item_or_NULL(settings, "WatchCrashdumpArchiveDir"); if (value) { g_settings_sWatchCrashdumpArchiveDir = xstrdup(value); remove_map_string_item(settings, "WatchCrashdumpArchiveDir"); } value = get_map_string_item_or_NULL(settings, "MaxCrashReportsSize"); if (value) { char *end; errno = 0; unsigned long ul = strtoul(value, &end, 10); if (errno || end == value || *end != '\0' || ul > INT_MAX) error_msg("Error parsing %s setting: '%s'", "MaxCrashReportsSize", value); else g_settings_nMaxCrashReportsSize = ul; remove_map_string_item(settings, "MaxCrashReportsSize"); } value = get_map_string_item_or_NULL(settings, "DumpLocation"); if (value) { g_settings_dump_location = xstrdup(value); remove_map_string_item(settings, "DumpLocation"); } else g_settings_dump_location = xstrdup(DEFAULT_DUMP_LOCATION); value = get_map_string_item_or_NULL(settings, "DeleteUploaded"); if (value) { g_settings_delete_uploaded = string_to_bool(value); remove_map_string_item(settings, "DeleteUploaded"); } value = get_map_string_item_or_NULL(settings, "AutoreportingEnabled"); if (value) { g_settings_autoreporting = string_to_bool(value); remove_map_string_item(settings, "AutoreportingEnabled"); } value = get_map_string_item_or_NULL(settings, "AutoreportingEvent"); if (value) { g_settings_autoreporting_event = xstrdup(value); remove_map_string_item(settings, "AutoreportingEvent"); } else g_settings_autoreporting_event = xstrdup("report_uReport"); value = get_map_string_item_or_NULL(settings, "ShortenedReporting"); if (value) { g_settings_shortenedreporting = string_to_bool(value); remove_map_string_item(settings, "ShortenedReporting"); } else { /* Default: enabled for GNOME desktop, else disabled */ const char *desktop_env = getenv("DESKTOP_SESSION"); g_settings_shortenedreporting = (desktop_env && strcasestr(desktop_env, "gnome") != NULL); } value = get_map_string_item_or_NULL(settings, "ExploreChroots"); if (value) { g_settings_explorechroots = string_to_bool(value); remove_map_string_item(settings, "ExploreChroots"); } else g_settings_explorechroots = false; value = get_map_string_item_or_NULL(settings, "DebugLevel"); if (value) { char *end; errno = 0; unsigned long ul = strtoul(value, &end, 10); if (errno || end == value || *end != '\0' || ul > INT_MAX) error_msg("Error parsing %s setting: '%s'", "DebugLevel", value); else g_settings_debug_level = ul; remove_map_string_item(settings, "DebugLevel"); } GHashTableIter iter; const char *name; /*char *value; - already declared */ init_map_string_iter(&iter, settings); while (next_map_string_iter(&iter, &name, &value)) { error_msg("Unrecognized variable '%s' in '%s'", name, conf_filename); } }