|
|
562801 |
From 2b8b92486ac28aff4a7d99fc18084db3d6f9617c Mon Sep 17 00:00:00 2001
|
|
|
562801 |
From: Matej Habrnal <mhabrnal@redhat.com>
|
|
|
562801 |
Date: Fri, 12 Feb 2016 14:20:19 +0100
|
|
|
562801 |
Subject: [PATCH] lib: introduce global configuration + option for excluded
|
|
|
562801 |
elements
|
|
|
562801 |
|
|
|
562801 |
Related to rhbz#1168494
|
|
|
562801 |
|
|
|
562801 |
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
|
|
|
562801 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
562801 |
---
|
|
|
562801 |
src/include/Makefile.am | 2 +-
|
|
|
562801 |
src/include/global_configuration.h | 45 ++++++++++++
|
|
|
562801 |
src/include/internal_libreport.h | 2 +-
|
|
|
562801 |
src/include/libreport_types.h | 2 +
|
|
|
562801 |
src/lib/Makefile.am | 3 +-
|
|
|
562801 |
src/lib/global_configuration.c | 143 +++++++++++++++++++++++++++++++++++++
|
|
|
562801 |
src/plugins/reporter-upload.c | 4 +-
|
|
|
562801 |
7 files changed, 196 insertions(+), 5 deletions(-)
|
|
|
562801 |
create mode 100644 src/include/global_configuration.h
|
|
|
562801 |
create mode 100644 src/lib/global_configuration.c
|
|
|
562801 |
|
|
|
562801 |
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
|
|
|
562801 |
index de44cda..062bffb 100644
|
|
|
562801 |
--- a/src/include/Makefile.am
|
|
|
562801 |
+++ b/src/include/Makefile.am
|
|
|
562801 |
@@ -9,7 +9,7 @@ libreport_include_HEADERS = \
|
|
|
562801 |
run_event.h \
|
|
|
562801 |
libreport_curl.h \
|
|
|
562801 |
workflow.h \
|
|
|
562801 |
- \
|
|
|
562801 |
+ global_configuration.h \
|
|
|
562801 |
config_item_info.h \
|
|
|
562801 |
file_obj.h \
|
|
|
562801 |
internal_libreport.h \
|
|
|
562801 |
diff --git a/src/include/global_configuration.h b/src/include/global_configuration.h
|
|
|
562801 |
new file mode 100644
|
|
|
562801 |
index 0000000..9666796
|
|
|
562801 |
--- /dev/null
|
|
|
562801 |
+++ b/src/include/global_configuration.h
|
|
|
562801 |
@@ -0,0 +1,45 @@
|
|
|
562801 |
+/*
|
|
|
562801 |
+ Copyright (C) 2015 ABRT team
|
|
|
562801 |
+ Copyright (C) 2015 RedHat Inc
|
|
|
562801 |
+
|
|
|
562801 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
562801 |
+ it under the terms of the GNU General Public License as published by
|
|
|
562801 |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
562801 |
+ (at your option) any later version.
|
|
|
562801 |
+
|
|
|
562801 |
+ This program is distributed in the hope that it will be useful,
|
|
|
562801 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
562801 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
562801 |
+ GNU General Public License for more details.
|
|
|
562801 |
+
|
|
|
562801 |
+ You should have received a copy of the GNU General Public License along
|
|
|
562801 |
+ with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
562801 |
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
562801 |
+*/
|
|
|
562801 |
+
|
|
|
562801 |
+#ifndef LIBREPORT_GLOBAL_CONFIGURATION_H
|
|
|
562801 |
+#define LIBREPORT_GLOBAL_CONFIGURATION_H
|
|
|
562801 |
+
|
|
|
562801 |
+#include "libreport_types.h"
|
|
|
562801 |
+
|
|
|
562801 |
+#ifdef __cplusplus
|
|
|
562801 |
+extern "C" {
|
|
|
562801 |
+#endif
|
|
|
562801 |
+
|
|
|
562801 |
+#define load_global_configuration libreport_load_global_configuration
|
|
|
562801 |
+bool load_global_configuration(void);
|
|
|
562801 |
+
|
|
|
562801 |
+#define load_global_configuration_from_dirs libreport_load_global_configuration_from_dirs
|
|
|
562801 |
+bool load_global_configuration_from_dirs(const char *dirs[], int dir_flags[]);
|
|
|
562801 |
+
|
|
|
562801 |
+#define free_global_configuration libreport_free_global_configuration
|
|
|
562801 |
+void free_global_configuration(void);
|
|
|
562801 |
+
|
|
|
562801 |
+#define get_global_always_excluded_elements libreport_get_global_always_excluded_elements
|
|
|
562801 |
+string_vector_ptr_t get_global_always_excluded_elements(void);
|
|
|
562801 |
+
|
|
|
562801 |
+#ifdef __cplusplus
|
|
|
562801 |
+}
|
|
|
562801 |
+#endif
|
|
|
562801 |
+
|
|
|
562801 |
+#endif /* LIBREPORT_GLOBAL_CONFIGURATION_H */
|
|
|
562801 |
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
|
|
|
562801 |
index 2046e69..b632803 100644
|
|
|
562801 |
--- a/src/include/internal_libreport.h
|
|
|
562801 |
+++ b/src/include/internal_libreport.h
|
|
|
562801 |
@@ -45,7 +45,6 @@
|
|
|
562801 |
#include <termios.h>
|
|
|
562801 |
#include <time.h>
|
|
|
562801 |
#include <unistd.h>
|
|
|
562801 |
-#include <stdbool.h>
|
|
|
562801 |
/* Try to pull in PATH_MAX */
|
|
|
562801 |
#include <limits.h>
|
|
|
562801 |
#include <sys/param.h>
|
|
|
562801 |
@@ -91,6 +90,7 @@ int vdprintf(int d, const char *format, va_list ap);
|
|
|
562801 |
|
|
|
562801 |
/* Pull in entire public libreport API */
|
|
|
562801 |
#include "dump_dir.h"
|
|
|
562801 |
+#include "global_configuration.h"
|
|
|
562801 |
#include "event_config.h"
|
|
|
562801 |
#include "problem_data.h"
|
|
|
562801 |
#include "report.h"
|
|
|
562801 |
diff --git a/src/include/libreport_types.h b/src/include/libreport_types.h
|
|
|
562801 |
index 2c60972..eb70fca 100644
|
|
|
562801 |
--- a/src/include/libreport_types.h
|
|
|
562801 |
+++ b/src/include/libreport_types.h
|
|
|
562801 |
@@ -19,9 +19,11 @@
|
|
|
562801 |
#ifndef LIBREPORT_TYPES_H_
|
|
|
562801 |
#define LIBREPORT_TYPES_H_
|
|
|
562801 |
|
|
|
562801 |
+#include <stdbool.h>
|
|
|
562801 |
#include <glib.h>
|
|
|
562801 |
|
|
|
562801 |
typedef gchar **string_vector_ptr_t;
|
|
|
562801 |
+typedef const gchar *const *const_string_vector_const_ptr_t;
|
|
|
562801 |
|
|
|
562801 |
#define string_vector_new_from_string libreport_string_vector_new_from_string
|
|
|
562801 |
string_vector_ptr_t string_vector_new_from_string(const char *vector);
|
|
|
562801 |
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
|
|
|
562801 |
index 7d9722a..f9ea602 100644
|
|
|
562801 |
--- a/src/lib/Makefile.am
|
|
|
562801 |
+++ b/src/lib/Makefile.am
|
|
|
562801 |
@@ -55,7 +55,8 @@ libreport_la_SOURCES = \
|
|
|
562801 |
workflow_xml_parser.c \
|
|
|
562801 |
config_item_info.c \
|
|
|
562801 |
xml_parser.c \
|
|
|
562801 |
- libreport_init.c
|
|
|
562801 |
+ libreport_init.c \
|
|
|
562801 |
+ global_configuration.c
|
|
|
562801 |
|
|
|
562801 |
libreport_la_CPPFLAGS = \
|
|
|
562801 |
-I$(srcdir)/../include \
|
|
|
562801 |
diff --git a/src/lib/global_configuration.c b/src/lib/global_configuration.c
|
|
|
562801 |
new file mode 100644
|
|
|
562801 |
index 0000000..903a2fb
|
|
|
562801 |
--- /dev/null
|
|
|
562801 |
+++ b/src/lib/global_configuration.c
|
|
|
562801 |
@@ -0,0 +1,143 @@
|
|
|
562801 |
+/*
|
|
|
562801 |
+ Copyright (C) 2015 ABRT team
|
|
|
562801 |
+ Copyright (C) 2015 RedHat Inc
|
|
|
562801 |
+
|
|
|
562801 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
562801 |
+ it under the terms of the GNU General Public License as published by
|
|
|
562801 |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
562801 |
+ (at your option) any later version.
|
|
|
562801 |
+
|
|
|
562801 |
+ This program is distributed in the hope that it will be useful,
|
|
|
562801 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
562801 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
562801 |
+ GNU General Public License for more details.
|
|
|
562801 |
+
|
|
|
562801 |
+ You should have received a copy of the GNU General Public License along
|
|
|
562801 |
+ with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
562801 |
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
562801 |
+*/
|
|
|
562801 |
+
|
|
|
562801 |
+#include "global_configuration.h"
|
|
|
562801 |
+#include "internal_libreport.h"
|
|
|
562801 |
+
|
|
|
562801 |
+#define OPT_NAME_SCRUBBED_VARIABLES "ScrubbedENVVariables"
|
|
|
562801 |
+#define OPT_NAME_EXCLUDED_ELEMENTS "AlwaysExcludedElements"
|
|
|
562801 |
+
|
|
|
562801 |
+static const char *const s_recognized_options[] = {
|
|
|
562801 |
+ OPT_NAME_SCRUBBED_VARIABLES,
|
|
|
562801 |
+ OPT_NAME_EXCLUDED_ELEMENTS,
|
|
|
562801 |
+ NULL,
|
|
|
562801 |
+};
|
|
|
562801 |
+
|
|
|
562801 |
+static map_string_t *s_global_settings;
|
|
|
562801 |
+
|
|
|
562801 |
+bool load_global_configuration(void)
|
|
|
562801 |
+{
|
|
|
562801 |
+ static const char *dirs[] = {
|
|
|
562801 |
+ CONF_DIR,
|
|
|
562801 |
+ NULL,
|
|
|
562801 |
+ NULL,
|
|
|
562801 |
+ };
|
|
|
562801 |
+
|
|
|
562801 |
+ static int dir_flags[] = {
|
|
|
562801 |
+#if 0
|
|
|
562801 |
+ CONF_DIR_FLAG_NONE,
|
|
|
562801 |
+#else
|
|
|
562801 |
+ /* jfilak: RHEL-7 do not use global configuration file */
|
|
|
562801 |
+ CONF_DIR_FLAG_OPTIONAL,
|
|
|
562801 |
+#endif
|
|
|
562801 |
+ CONF_DIR_FLAG_OPTIONAL,
|
|
|
562801 |
+ -1,
|
|
|
562801 |
+ };
|
|
|
562801 |
+
|
|
|
562801 |
+ if (dirs[1] == NULL)
|
|
|
562801 |
+ dirs[1] = get_user_conf_base_dir();
|
|
|
562801 |
+
|
|
|
562801 |
+ return load_global_configuration_from_dirs(dirs, dir_flags);
|
|
|
562801 |
+}
|
|
|
562801 |
+
|
|
|
562801 |
+bool load_global_configuration_from_dirs(const char *dirs[], int dir_flags[])
|
|
|
562801 |
+{
|
|
|
562801 |
+ if (s_global_settings == NULL)
|
|
|
562801 |
+ {
|
|
|
562801 |
+ s_global_settings = new_map_string();
|
|
|
562801 |
+
|
|
|
562801 |
+ bool ret = load_conf_file_from_dirs_ext("libreport.conf", dirs, dir_flags, s_global_settings,
|
|
|
562801 |
+ /*don't skip without value*/ false);
|
|
|
562801 |
+ if (!ret)
|
|
|
562801 |
+ {
|
|
|
562801 |
+ error_msg("Failed to load libreport global configuration");
|
|
|
562801 |
+ free_global_configuration();
|
|
|
562801 |
+ return false;
|
|
|
562801 |
+ }
|
|
|
562801 |
+
|
|
|
562801 |
+ map_string_iter_t iter;
|
|
|
562801 |
+ init_map_string_iter(&iter, s_global_settings);
|
|
|
562801 |
+ const char *key, *value;
|
|
|
562801 |
+ while(next_map_string_iter(&iter, &key, &value))
|
|
|
562801 |
+ {
|
|
|
562801 |
+ /* Die to avoid security leaks in case where someone made a typo in a option name */
|
|
|
562801 |
+ if (!is_in_string_list(key, s_recognized_options))
|
|
|
562801 |
+ {
|
|
|
562801 |
+ error_msg("libreport global configuration contains unrecognized option : '%s'", key);
|
|
|
562801 |
+ free_global_configuration();
|
|
|
562801 |
+ return false;
|
|
|
562801 |
+ }
|
|
|
562801 |
+ }
|
|
|
562801 |
+ }
|
|
|
562801 |
+ else
|
|
|
562801 |
+ log_notice("libreport global configuration already loaded");
|
|
|
562801 |
+
|
|
|
562801 |
+ return true;
|
|
|
562801 |
+}
|
|
|
562801 |
+
|
|
|
562801 |
+void free_global_configuration(void)
|
|
|
562801 |
+{
|
|
|
562801 |
+ if (s_global_settings != NULL)
|
|
|
562801 |
+ {
|
|
|
562801 |
+ free_map_string(s_global_settings);
|
|
|
562801 |
+ s_global_settings = NULL;
|
|
|
562801 |
+ }
|
|
|
562801 |
+}
|
|
|
562801 |
+
|
|
|
562801 |
+static void assert_global_configuration_initialized(void)
|
|
|
562801 |
+{
|
|
|
562801 |
+ if (NULL == s_global_settings)
|
|
|
562801 |
+ {
|
|
|
562801 |
+ error_msg("libreport global configuration is not initialized");
|
|
|
562801 |
+ abort();
|
|
|
562801 |
+ }
|
|
|
562801 |
+}
|
|
|
562801 |
+
|
|
|
562801 |
+#define get_helper(type, getter, name) \
|
|
|
562801 |
+ ({ \
|
|
|
562801 |
+ assert_global_configuration_initialized(); \
|
|
|
562801 |
+ type opt; \
|
|
|
562801 |
+ if (getter(s_global_settings, name, &opt)) \
|
|
|
562801 |
+ /* Die to avoid security leaks in case where someone made a error */ \
|
|
|
562801 |
+ error_msg_and_die("libreport global settings contains invalid data: '"name"'"); \
|
|
|
562801 |
+ opt;\
|
|
|
562801 |
+ })
|
|
|
562801 |
+
|
|
|
562801 |
+string_vector_ptr_t get_global_always_excluded_elements(void)
|
|
|
562801 |
+{
|
|
|
562801 |
+ assert_global_configuration_initialized();
|
|
|
562801 |
+
|
|
|
562801 |
+ char *env_exclude = getenv("EXCLUDE_FROM_REPORT");
|
|
|
562801 |
+ const char *gc_exclude = get_map_string_item_or_NULL(s_global_settings, OPT_NAME_EXCLUDED_ELEMENTS);
|
|
|
562801 |
+
|
|
|
562801 |
+ if (env_exclude != NULL && gc_exclude == NULL)
|
|
|
562801 |
+ return string_vector_new_from_string(env_exclude);
|
|
|
562801 |
+
|
|
|
562801 |
+ if (env_exclude == NULL && gc_exclude != NULL)
|
|
|
562801 |
+ return string_vector_new_from_string(gc_exclude);
|
|
|
562801 |
+
|
|
|
562801 |
+ if (env_exclude == NULL && gc_exclude == NULL)
|
|
|
562801 |
+ return string_vector_new_from_string(NULL);
|
|
|
562801 |
+
|
|
|
562801 |
+ char *joined_exclude = xasprintf("%s, %s", env_exclude, gc_exclude);
|
|
|
562801 |
+ string_vector_ptr_t ret = string_vector_new_from_string(joined_exclude);
|
|
|
562801 |
+ free(joined_exclude);
|
|
|
562801 |
+
|
|
|
562801 |
+ return ret;
|
|
|
562801 |
+}
|
|
|
562801 |
diff --git a/src/plugins/reporter-upload.c b/src/plugins/reporter-upload.c
|
|
|
562801 |
index 84c827b..6d83d2f 100644
|
|
|
562801 |
--- a/src/plugins/reporter-upload.c
|
|
|
562801 |
+++ b/src/plugins/reporter-upload.c
|
|
|
562801 |
@@ -96,12 +96,12 @@ static int create_and_upload_archive(
|
|
|
562801 |
|
|
|
562801 |
/* Write data to the tarball */
|
|
|
562801 |
{
|
|
|
562801 |
- char *exclude_from_report = getenv("EXCLUDE_FROM_REPORT");
|
|
|
562801 |
+ string_vector_ptr_t exclude_from_report = get_global_always_excluded_elements();
|
|
|
562801 |
dd_init_next_file(dd);
|
|
|
562801 |
char *short_name, *full_name;
|
|
|
562801 |
while (dd_get_next_file(dd, &short_name, &full_name))
|
|
|
562801 |
{
|
|
|
562801 |
- if (exclude_from_report && is_in_comma_separated_list(short_name, exclude_from_report))
|
|
|
562801 |
+ if (exclude_from_report && is_in_string_list(short_name, (const_string_vector_const_ptr_t)exclude_from_report))
|
|
|
562801 |
goto next;
|
|
|
562801 |
|
|
|
562801 |
// dd_get_next_file guarantees that it's a REG:
|
|
|
562801 |
--
|
|
|
562801 |
1.8.3.1
|
|
|
562801 |
|