From 0274b29916883efac50e0961c0a3b49ce8a11f1f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 20 Apr 2011 18:23:56 +0200 Subject: delete ugly parse_conf(), use load_abrt_conf() instead Therefore moved abrt_conf.* to libreport Signed-off-by: Denys Vlasenko --- src/lib/Makefile.am | 1 + src/lib/abrt_conf.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/abrt_conf.h | 50 ++++++++++++++++ src/lib/hash_sha1.h | 4 ++ src/lib/hooklib.c | 72 ----------------------- src/lib/hooklib.h | 10 ++-- 6 files changed, 225 insertions(+), 78 deletions(-) create mode 100644 src/lib/abrt_conf.c create mode 100644 src/lib/abrt_conf.h (limited to 'src/lib') diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index d2dc9cae..decfeffd 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -42,6 +42,7 @@ libreport_la_SOURCES = \ hooklib.c hooklib.h \ parse_release.c \ parse_options.c parse_options.h \ + abrt_conf.c abrt_conf.h \ steal_directory.c \ event_xml_parser.c \ event_config.c diff --git a/src/lib/abrt_conf.c b/src/lib/abrt_conf.c new file mode 100644 index 00000000..2a1cf369 --- /dev/null +++ b/src/lib/abrt_conf.c @@ -0,0 +1,166 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "abrtlib.h" + +bool g_settings_bOpenGPGCheck = false; +GList * g_settings_setOpenGPGPublicKeys = NULL; +GList * g_settings_setBlackListedPkgs = NULL; +GList * g_settings_setBlackListedPaths = NULL; +char * g_settings_sWatchCrashdumpArchiveDir = NULL; +unsigned int g_settings_nMaxCrashReportsSize = 1000; +bool g_settings_bProcessUnpackaged = false; + + +void free_abrt_conf_data() +{ + list_free_with_free(g_settings_setOpenGPGPublicKeys); + g_settings_setOpenGPGPublicKeys = NULL; + + list_free_with_free(g_settings_setBlackListedPkgs); + g_settings_setBlackListedPkgs = NULL; + + list_free_with_free(g_settings_setBlackListedPaths); + g_settings_setBlackListedPaths = NULL; + + free(g_settings_sWatchCrashdumpArchiveDir); + g_settings_sWatchCrashdumpArchiveDir = NULL; +} + +static GList *parse_list(const char* list) +{ + struct strbuf *item = strbuf_new(); + GList *l = NULL; + + char *trim_item = NULL; + + for (unsigned ii = 0; list[ii]; ii++) + { + if (list[ii] == ',') + { + trim_item = strtrim(item->buf); + l = g_list_append(l, xstrdup(trim_item)); + strbuf_clear(item); + } + else + strbuf_append_char(item, list[ii]); + } + + if (item->len > 0) + { + trim_item = strtrim(item->buf); + l = g_list_append(l, xstrdup(trim_item)); + } + + strbuf_free(item); + + return l; +} + +static void ParseCommon(map_string_h *settings, const char *conf_filename) +{ + char *value; + + value = g_hash_table_lookup(settings, "OpenGPGCheck"); + if (value) + { + g_settings_bOpenGPGCheck = string_to_bool(value); + g_hash_table_remove(settings, "OpenGPGCheck"); + } + + value = g_hash_table_lookup(settings, "BlackList"); + if (value) + { + g_settings_setBlackListedPkgs = parse_list(value); + g_hash_table_remove(settings, "BlackList"); + } + + value = g_hash_table_lookup(settings, "BlackListedPaths"); + if (value) + { + g_settings_setBlackListedPaths = parse_list(value); + g_hash_table_remove(settings, "BlackListedPaths"); + } + + value = g_hash_table_lookup(settings, "WatchCrashdumpArchiveDir"); + if (value) + { + g_settings_sWatchCrashdumpArchiveDir = xstrdup(value); + g_hash_table_remove(settings, "WatchCrashdumpArchiveDir"); + } + + value = g_hash_table_lookup(settings, "MaxCrashReportsSize"); + if (value) + { +//FIXME: dont die + g_settings_nMaxCrashReportsSize = xatoi_positive(value); + g_hash_table_remove(settings, "MaxCrashReportsSize"); + } + + value = g_hash_table_lookup(settings, "ProcessUnpackaged"); + if (value) + { + g_settings_bProcessUnpackaged = string_to_bool(value); + g_hash_table_remove(settings, "ProcessUnpackaged"); + } + + GHashTableIter iter; + char *name; + /*char *value; - already declared */ + g_hash_table_iter_init(&iter, settings); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) + { + error_msg("Unrecognized variable '%s' in '%s'", name, conf_filename); + } +} + +static void LoadGPGKeys() +{ + FILE *fp = fopen(CONF_DIR"/gpg_keys", "r"); + if (fp) + { + /* every line is one key + * FIXME: make it more robust, it doesn't handle comments + */ + char *line; + while ((line = xmalloc_fgetline(fp)) != NULL) + { + if (line[0] == '/') // probably the beginning of a path, so let's handle it as a key + g_settings_setOpenGPGPublicKeys = g_list_append(g_settings_setOpenGPGPublicKeys, line); + else + free(line); + } + fclose(fp); + } +} + +int load_abrt_conf() +{ + free_abrt_conf_data(); + + map_string_h *settings = new_map_string(); + if (!load_conf_file(CONF_DIR"/abrt.conf", settings, /*skip key w/o values:*/ false)) + error_msg("Can't open '%s'", CONF_DIR"/abrt.conf"); + + ParseCommon(settings, CONF_DIR"/abrt.conf"); + free_map_string(settings); + + LoadGPGKeys(); + + return 0; +} diff --git a/src/lib/abrt_conf.h b/src/lib/abrt_conf.h new file mode 100644 index 00000000..2ca7542b --- /dev/null +++ b/src/lib/abrt_conf.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2010 ABRT team + Copyright (C) 2010 RedHat Inc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#ifndef ABRT_CONF_H_ +#define ABRT_CONF_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define g_settings_setOpenGPGPublicKeys abrt_g_settings_setOpenGPGPublicKeys +extern GList * g_settings_setOpenGPGPublicKeys; +#define g_settings_setBlackListedPkgs abrt_g_settings_setBlackListedPkgs +extern GList * g_settings_setBlackListedPkgs; +#define g_settings_setBlackListedPaths abrt_g_settings_setBlackListedPaths +extern GList * g_settings_setBlackListedPaths; +#define g_settings_nMaxCrashReportsSize abrt_g_settings_nMaxCrashReportsSize +extern unsigned int g_settings_nMaxCrashReportsSize; +#define g_settings_bOpenGPGCheck abrt_g_settings_bOpenGPGCheck +extern bool g_settings_bOpenGPGCheck; +#define g_settings_bProcessUnpackaged abrt_g_settings_bProcessUnpackaged +extern bool g_settings_bProcessUnpackaged; +#define g_settings_sWatchCrashdumpArchiveDir abrt_g_settings_sWatchCrashdumpArchiveDir +extern char * g_settings_sWatchCrashdumpArchiveDir; + +#define load_abrt_conf abrt_load_abrt_conf +int load_abrt_conf(); +#define free_abrt_conf_data abrt_free_abrt_conf_data +void free_abrt_conf_data(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/hash_sha1.h b/src/lib/hash_sha1.h index 2b6b7606..850fd21f 100644 --- a/src/lib/hash_sha1.h +++ b/src/lib/hash_sha1.h @@ -17,6 +17,8 @@ * * --------------------------------------------------------------------------- */ +#ifndef HASH_SHA1_H +#define HASH_SHA1_H 1 #ifdef __cplusplus extern "C" { @@ -41,3 +43,5 @@ void sha1_end(sha1_ctx_t *ctx, void *resbuf); #ifdef __cplusplus } #endif + +#endif diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c index fd7ecc9a..3bde4dfa 100644 --- a/src/lib/hooklib.c +++ b/src/lib/hooklib.c @@ -19,78 +19,6 @@ #include "hooklib.h" #include -void parse_conf(const char *additional_conf, unsigned *setting_MaxCrashReportsSize, bool *setting_MakeCompatCore, bool *setting_SaveBinaryImage) -{ - FILE *fp = fopen(CONF_DIR"/abrt.conf", "r"); - if (!fp) - return; - - while (1) - { - char *line = xmalloc_fgetline(fp); - if (!line) - { - fclose(fp); - if (additional_conf) - { - /* Next .conf file plz */ - fp = fopen(additional_conf, "r"); - if (fp) - { - additional_conf = NULL; - continue; - } - } - break; - } - - const char *p = skip_whitespace(line); -#undef DIRECTIVE -#define DIRECTIVE "MaxCrashReportsSize" - if (setting_MaxCrashReportsSize && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - goto free_line; - p = skip_whitespace(p + 1); - if (isdigit(*p)) - { - /* x1.25: go a bit up, so that usual in-daemon trimming - * kicks in first, and we don't "fight" with it. */ - *setting_MaxCrashReportsSize = (unsigned long)xatou(p) * 5 / 4; - } - goto free_line; - } -#undef DIRECTIVE -#define DIRECTIVE "MakeCompatCore" - if (setting_MakeCompatCore && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - goto free_line; - p = skip_whitespace(p + 1); - *setting_MakeCompatCore = string_to_bool(p); - goto free_line; - } -#undef DIRECTIVE -#define DIRECTIVE "SaveBinaryImage" - if (setting_SaveBinaryImage && strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0) - { - p = skip_whitespace(p + sizeof(DIRECTIVE)-1); - if (*p != '=') - goto free_line; - p = skip_whitespace(p + 1); - *setting_SaveBinaryImage = string_to_bool(p); - goto free_line; - } -#undef DIRECTIVE - /* add more 'if (strncmp(p, DIRECTIVE, sizeof(DIRECTIVE)-1) == 0)' here... */ - - free_line: - free(line); - } -} - void check_free_space(unsigned setting_MaxCrashReportsSize) { struct statvfs vfs; diff --git a/src/lib/hooklib.h b/src/lib/hooklib.h index a7421e06..c140f951 100644 --- a/src/lib/hooklib.h +++ b/src/lib/hooklib.h @@ -15,17 +15,13 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef HOOKLIB_H +#define HOOKLIB_H 1 #ifdef __cplusplus extern "C" { #endif -#define parse_conf abrt_parse_conf -void parse_conf(const char *additional_conf, - unsigned *setting_MaxCrashReportsSize, - bool *setting_MakeCompatCore, - bool *setting_SaveBinaryImage); - #define check_free_space abrt_check_free_space void check_free_space(unsigned setting_MaxCrashReportsSize); @@ -35,3 +31,5 @@ void trim_debug_dumps(const char *dirname, double cap_size, const char *exclude_ #ifdef __cplusplus } #endif + +#endif -- cgit