1 From caec174b203206185b6075c0e822c6f45070dd87 Mon Sep 17 00:00:00 2001
2 From: Alexander Scheel <ascheel@redhat.com>
3 Date: Wed, 9 Aug 2017 15:00:26 -0400
4 Subject: [PATCH] Fix silent crash with duplicate config sections
6 Signed-off-by: Alexander Scheel <ascheel@redhat.com>
7 Reviewed-by: Simo Sorce <simo@redhat.com>
10 (cherry picked from commit c0d85387fc38f9554d601ec2ddb111031a694387)
12 proxy/configure.ac | 125 ++++++++++++++++++++++++++++++++++++++++++
13 proxy/src/gp_config.c | 27 ++++-----
14 2 files changed, 137 insertions(+), 15 deletions(-)
16 diff --git a/proxy/configure.ac b/proxy/configure.ac
17 index c52dbb6..9e01f7d 100644
18 --- a/proxy/configure.ac
19 +++ b/proxy/configure.ac
20 @@ -107,6 +107,131 @@ fi
24 +AC_CHECK_LIB(ref_array, ref_array_destroy, [],
25 + [AC_MSG_WARN([ref_array library must support ref_array_destroy])],
28 +AC_RUN_IFELSE([AC_LANG_SOURCE([[
29 +/* See: https://pagure.io/SSSD/ding-libs/pull-request/3172 */
30 +#include <linux/limits.h>
36 +#include <ini_configobj.h>
37 +#include <ini_config.h>
39 +static int write_to_file(char *path, char *text)
41 + FILE *f = fopen(path, "w");
46 + bytes = fprintf(f, "%s", text);
47 + if (bytes != strlen(text))
55 + char base_path[PATH_MAX];
56 + char augment_path[PATH_MAX];
58 + char config_base[] =
63 + char config_augment[] =
70 + struct ini_cfgobj *in_cfg, *result_cfg;
71 + struct ini_cfgfile *file_ctx;
73 + uint32_t merge_flags = INI_MS_DETECT | INI_MS_PRESERVE;
77 + builddir = getenv("builddir");
78 + if (builddir == NULL) {
79 + builddir = strdup(".");
82 + snprintf(base_path, PATH_MAX, "%s/tmp_augment_base.conf", builddir);
83 + snprintf(augment_path, PATH_MAX, "%s/tmp_augment_augment.conf", builddir);
85 + ret = write_to_file(base_path, config_base);
91 + ret = write_to_file(augment_path, config_augment);
96 + /* Match only augment.conf */
97 + const char *m_patterns[] = { "^tmp_augment_augment.conf$", NULL };
99 + /* Match all sections */
100 + const char *m_sections[] = { ".*", NULL };
102 + /* Create config collection */
103 + ret = ini_config_create(&in_cfg);
107 + /* Open base.conf */
108 + ret = ini_config_file_open(base_path, 0, &file_ctx);
112 + /* Seed in_cfg with base.conf */
113 + ret = ini_config_parse(file_ctx, 1, 0, 0, in_cfg);
117 + /* Update base.conf with augment.conf */
118 + ret = ini_config_augment(in_cfg,
125 + INI_PARSE_NOSPACE|INI_PARSE_NOTAB,
130 + /* We always expect EEXIST due to DETECT being set. */
138 + remove(augment_path);
140 + /* Per autoconf guidelines */
147 +,, [AC_MSG_ERROR(["ini_config library must support extended INI_MS_DETECT. See: https://pagure.io/SSSD/ding-libs/pull-request/3172"])])
149 AX_PTHREAD(,[AC_MSG_ERROR([Could not find Pthreads support])])
151 LIBS="$PTHREAD_LIBS $LIBS"
152 diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c
153 index 07f7c8d..cd057a0 100644
154 --- a/proxy/src/gp_config.c
155 +++ b/proxy/src/gp_config.c
156 @@ -728,7 +728,7 @@ static int gp_config_from_file(const char *config_file,
157 0, /* metadata_flags, FIXME */
160 - GPDEBUG("Failed to open config file: %d (%s)\n",
161 + GPERROR("Failed to open config file: %d (%s)\n",
162 ret, gp_strerror(ret));
163 ini_config_destroy(ini_config);
165 @@ -742,7 +742,7 @@ static int gp_config_from_file(const char *config_file,
167 char **errors = NULL;
168 /* we had a parsing failure */
169 - GPDEBUG("Failed to parse config file: %d (%s)\n",
170 + GPERROR("Failed to parse config file: %d (%s)\n",
171 ret, gp_strerror(ret));
172 if (ini_config_error_count(ini_config)) {
173 ini_config_get_errors(ini_config, &errors);
174 @@ -791,26 +791,25 @@ static int gp_config_from_dir(const char *config_dir,
175 INI_STOP_ON_ANY, /* error_level */
178 - /* do not allow colliding sections with the same
179 - * name in different files */
181 + /* allow sections with the same name in
182 + * different files, but log warnings */
183 + INI_MS_DETECT | INI_MS_PRESERVE,
192 - GPAUDIT("Error when reading config directory number: %d\n", ret);
196 len = ref_array_len(error_list);
197 for (uint32_t i = 0; i < len; i++) {
198 /* libini has an unfixable bug where error strings are (char **) */
199 GPAUDIT("Error when reading config directory: %s\n",
200 *(char **)ref_array_get(error_list, i, NULL));
202 + ref_array_destroy(error_list);
205 + if (ret && ret != EEXIST) {
206 + GPERROR("Error when reading config directory number: %d\n", ret);
208 ref_array_destroy(error_list);
210 @@ -821,9 +820,7 @@ static int gp_config_from_dir(const char *config_dir,
211 ini_config_destroy(*ini_config);
212 *ini_config = result_cfg;
215 - ref_array_destroy(error_list);