diff options
author | Robbie Harwood (frozencemetery) <rharwood@redhat.com> | 2015-08-24 16:24:51 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-08-31 15:57:39 -0400 |
commit | 9f1a8a8777ae144ccf34c6406e9bc8fa930e0047 (patch) | |
tree | 9aff242affe71f2b1becfcf736f7adaab9542073 | |
parent | 89197623cb3c3d84fc19d90fccbb8f7ac49fd562 (diff) | |
download | gss-proxy-9f1a8a8777ae144ccf34c6406e9bc8fa930e0047.tar.gz gss-proxy-9f1a8a8777ae144ccf34c6406e9bc8fa930e0047.tar.xz gss-proxy-9f1a8a8777ae144ccf34c6406e9bc8fa930e0047.zip |
Remove one layer of abstraction over dinglibs
A handful of parameter name differences (`key` vs. `keyname`) have been
tweaked but the function bodies are otherwise unchanged.
Signed-off-by: Robbie Harwood (frozencemetery) <rharwood@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
-rw-r--r-- | proxy/Makefile.am | 2 | ||||
-rw-r--r-- | proxy/configure.ac | 1 | ||||
-rw-r--r-- | proxy/src/gp_config.c | 274 | ||||
-rw-r--r-- | proxy/src/gp_config_dinglibs.c | 339 | ||||
-rw-r--r-- | proxy/src/gp_config_dinglibs.h | 45 |
5 files changed, 261 insertions, 400 deletions
diff --git a/proxy/Makefile.am b/proxy/Makefile.am index 8213625..013098b 100644 --- a/proxy/Makefile.am +++ b/proxy/Makefile.am @@ -132,7 +132,6 @@ dist_noinst_HEADERS = \ src/gp_export.h \ src/gp_conv.h \ src/gp_config.h \ - src/gp_config_dinglibs.h \ src/gp_debug.h \ src/gp_rpc_creds.h \ src/gp_selinux.h \ @@ -145,7 +144,6 @@ dist_noinst_HEADERS = \ gssproxy_SOURCES = \ src/gp_config.c \ - src/gp_config_dinglibs.c \ src/gp_init.c \ src/gp_socket.c \ src/gp_workers.c \ diff --git a/proxy/configure.ac b/proxy/configure.ac index 26430f8..c0bc9b0 100644 --- a/proxy/configure.ac +++ b/proxy/configure.ac @@ -95,7 +95,6 @@ else fi if test x$have_libini_config = x1; then - AC_DEFINE([WITH_DINGLIBS], [1], [Using ini_config]) INI_CFLAGS="$INI_CONFIG_CFLAGS" INI_LIBS="$INI_CONFIG_LIBS" else diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c index bace4c8..2812e88 100644 --- a/proxy/src/gp_config.c +++ b/proxy/src/gp_config.c @@ -35,6 +35,8 @@ #include <gssapi/gssapi.h> +#include <ini_configobj.h> + struct gp_flag_def { const char *name; uint32_t value; @@ -583,13 +585,62 @@ void free_config(struct gp_config **cfg) *cfg = NULL; } -#ifdef WITH_DINGLIBS -#include "gp_config_dinglibs.h" - int gp_config_init(const char *config_file, struct gp_ini_context *ctx) { - return gp_dinglibs_init(config_file, ctx); + struct ini_cfgobj *ini_config = NULL; + struct ini_cfgfile *file_ctx = NULL; + int ret; + + if (!ctx) { + return EINVAL; + } + + ret = ini_config_create(&ini_config); + if (ret) { + return ENOENT; + } + + ret = ini_config_file_open(config_file, + 0, /* metadata_flags, FIXME */ + &file_ctx); + if (ret) { + GPDEBUG("Failed to open config file: %d (%s)\n", + ret, gp_strerror(ret)); + ini_config_destroy(ini_config); + return ret; + } + + ret = ini_config_parse(file_ctx, + INI_STOP_ON_ANY, /* error_level */ + /* Merge section but allow duplicates */ + INI_MS_MERGE | + INI_MV1S_ALLOW | + INI_MV2S_ALLOW, + INI_PARSE_NOWRAP, /* parse_flags */ + ini_config); + if (ret) { + char **errors = NULL; + /* we had a parsing failure */ + GPDEBUG("Failed to parse config file: %d (%s)\n", + ret, gp_strerror(ret)); + if (ini_config_error_count(ini_config)) { + ini_config_get_errors(ini_config, &errors); + if (errors) { + ini_config_print_errors(stderr, errors); + ini_config_free_errors(errors); + } + } + ini_config_file_destroy(file_ctx); + ini_config_destroy(ini_config); + return ret; + } + + ini_config_file_destroy(file_ctx); + + ctx->private_data = ini_config; + + return 0; } int gp_config_get_string(struct gp_ini_context *ctx, @@ -597,7 +648,37 @@ int gp_config_get_string(struct gp_ini_context *ctx, const char *keyname, const char **value) { - return gp_dinglibs_get_string(ctx, secname, keyname, value); + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + struct value_obj *vo = NULL; + int ret; + const char *val; + + if (!value) { + return -1; + } + + *value = NULL; + + ret = ini_get_config_valueobj(secname, + keyname, + ini_config, + INI_GET_FIRST_VALUE, + &vo); + if (ret) { + return ret; + } + if (!vo) { + return ENOENT; + } + + val = ini_get_const_string_config_value(vo, &ret); + if (ret) { + return ret; + } + + *value = val; + + return 0; } int gp_config_get_string_array(struct gp_ini_context *ctx, @@ -606,8 +687,100 @@ int gp_config_get_string_array(struct gp_ini_context *ctx, int *num_values, const char ***values) { - return gp_dinglibs_get_string_array(ctx, secname, keyname, - num_values, values); + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + struct value_obj *vo = NULL; + const char *value; + int ret; + int i, count = 0; + const char **array = NULL; + const char **t_array; + + if (!values || !num_values) { + return EINVAL; + } + + *num_values = 0; + *values = NULL; + + ret = ini_get_config_valueobj(secname, + keyname, + ini_config, + INI_GET_FIRST_VALUE, + &vo); + if (ret) { + return ret; + } + if (!vo) { + return ENOENT; + } + + value = ini_get_const_string_config_value(vo, &ret); + if (ret) { + return ret; + } + + array = calloc(1, sizeof(char *)); + if (array == NULL) { + ret = ENOMEM; + goto done; + } + + array[count] = strdup(value); + if (array[count] == NULL) { + ret = ENOMEM; + goto done; + } + + count++; + + do { + ret = ini_get_config_valueobj(secname, + keyname, + ini_config, + INI_GET_NEXT_VALUE, + &vo); + if (ret) { + goto done; + } + if (!vo) { + break; + } + + value = ini_get_const_string_config_value(vo, &ret); + if (ret) { + goto done; + } + + t_array = realloc(array, (count+1) * sizeof(char *)); + if (t_array == NULL) { + ret = ENOMEM; + goto done; + } + array = t_array; + + array[count] = strdup(value); + if (array[count] == NULL) { + ret = ENOMEM; + goto done; + } + + count++; + + } while (1); + + *num_values = count; + *values = array; + + ret = 0; + +done: + if (ret && array) { + for (i = 0; i < count; i++) { + safefree(array[i]); + } + safefree(array); + } + return ret; } int gp_config_get_int(struct gp_ini_context *ctx, @@ -615,23 +788,98 @@ int gp_config_get_int(struct gp_ini_context *ctx, const char *keyname, int *value) { - return gp_dinglibs_get_int(ctx, secname, keyname, value); + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + struct value_obj *vo = NULL; + int ret; + int val; + + if (!value) { + return EINVAL; + } + + *value = -1; + + ret = ini_get_config_valueobj(secname, + keyname, + ini_config, + INI_GET_FIRST_VALUE, + &vo); + + if (ret) { + return ret; + } + if (!vo) { + return ENOENT; + } + + val = ini_get_int_config_value(vo, + 0, /* strict */ + 0, /* default */ + &ret); + if (ret) { + return ret; + } + + *value = val; + + return 0; } int gp_config_get_nsec(struct gp_ini_context *ctx) { - return gp_dinglibs_get_nsec(ctx); + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + char **list = NULL; + int count; + int error; + + list = ini_get_section_list(ini_config, &count, &error); + if (error) { + return 0; + } + + ini_free_section_list(list); + + return count; } char *gp_config_get_secname(struct gp_ini_context *ctx, int i) { - return gp_dinglibs_get_secname(ctx, i); + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + char **list = NULL; + int count; + int error; + char *secname; + + list = ini_get_section_list(ini_config, &count, &error); + if (error) { + return NULL; + } + + if (i >= count) { + return NULL; + } + + secname = strdup(list[i]); + ini_free_section_list(list); + if (!secname) { + return NULL; + } + + return secname; } int gp_config_close(struct gp_ini_context *ctx) { - return gp_dinglibs_close(ctx); -} + struct ini_cfgobj *ini_config = NULL; + + if (!ctx) { + return 0; + } -#endif /* WITH_DINGLIBS */ + ini_config = (struct ini_cfgobj *)ctx->private_data; + + ini_config_destroy(ini_config); + + return 0; +} diff --git a/proxy/src/gp_config_dinglibs.c b/proxy/src/gp_config_dinglibs.c deleted file mode 100644 index d2bd0e4..0000000 --- a/proxy/src/gp_config_dinglibs.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - GSS-PROXY - - Copyright (C) 2011 Red Hat, Inc. - Copyright (C) 2011 Simo Sorce <simo.sorce@redhat.com> - Copyright (C) 2012-2013 Guenther Deschner <guenther.deschner@redhat.com> - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#include "config.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include "gp_proxy.h" -#include "gp_config.h" -#include "gp_config_dinglibs.h" - -#ifdef WITH_DINGLIBS - -#include <ini_configobj.h> - -int gp_dinglibs_get_string(struct gp_ini_context *ctx, - const char *secname, - const char *key, - const char **value) -{ - struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; - struct value_obj *vo = NULL; - int ret; - const char *val; - - if (!value) { - return -1; - } - - *value = NULL; - - ret = ini_get_config_valueobj(secname, - key, - ini_config, - INI_GET_FIRST_VALUE, - &vo); - if (ret) { - return ret; - } - if (!vo) { - return ENOENT; - } - - val = ini_get_const_string_config_value(vo, &ret); - if (ret) { - return ret; - } - - *value = val; - - return 0; -} - -int gp_dinglibs_get_string_array(struct gp_ini_context *ctx, - const char *secname, - const char *key, - int *num_values, - const char ***values) -{ - struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; - struct value_obj *vo = NULL; - const char *value; - int ret; - int i, count = 0; - const char **array = NULL; - const char **t_array; - - if (!values || !num_values) { - return EINVAL; - } - - *num_values = 0; - *values = NULL; - - ret = ini_get_config_valueobj(secname, - key, - ini_config, - INI_GET_FIRST_VALUE, - &vo); - if (ret) { - return ret; - } - if (!vo) { - return ENOENT; - } - - value = ini_get_const_string_config_value(vo, &ret); - if (ret) { - return ret; - } - - array = calloc(1, sizeof(char *)); - if (array == NULL) { - ret = ENOMEM; - goto done; - } - - array[count] = strdup(value); - if (array[count] == NULL) { - ret = ENOMEM; - goto done; - } - - count++; - - do { - ret = ini_get_config_valueobj(secname, - key, - ini_config, - INI_GET_NEXT_VALUE, - &vo); - if (ret) { - goto done; - } - if (!vo) { - break; - } - - value = ini_get_const_string_config_value(vo, &ret); - if (ret) { - goto done; - } - - t_array = realloc(array, (count+1) * sizeof(char *)); - if (t_array == NULL) { - ret = ENOMEM; - goto done; - } - array = t_array; - - array[count] = strdup(value); - if (array[count] == NULL) { - ret = ENOMEM; - goto done; - } - - count++; - - } while (1); - - *num_values = count; - *values = array; - - ret = 0; - -done: - if (ret && array) { - for (i = 0; i < count; i++) { - safefree(array[i]); - } - safefree(array); - } - return ret; -} - -int gp_dinglibs_get_int(struct gp_ini_context *ctx, - const char *secname, - const char *key, - int *value) -{ - struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; - struct value_obj *vo = NULL; - int ret; - int val; - - if (!value) { - return EINVAL; - } - - *value = -1; - - ret = ini_get_config_valueobj(secname, - key, - ini_config, - INI_GET_FIRST_VALUE, - &vo); - - if (ret) { - return ret; - } - if (!vo) { - return ENOENT; - } - - val = ini_get_int_config_value(vo, - 0, /* strict */ - 0, /* default */ - &ret); - if (ret) { - return ret; - } - - *value = val; - - return 0; -} - -int gp_dinglibs_init(const char *config_file, - struct gp_ini_context *ctx) -{ - struct ini_cfgobj *ini_config = NULL; - struct ini_cfgfile *file_ctx = NULL; - int ret; - - if (!ctx) { - return EINVAL; - } - - ret = ini_config_create(&ini_config); - if (ret) { - return ENOENT; - } - - ret = ini_config_file_open(config_file, - 0, /* metadata_flags, FIXME */ - &file_ctx); - if (ret) { - GPDEBUG("Failed to open config file: %d (%s)\n", - ret, gp_strerror(ret)); - ini_config_destroy(ini_config); - return ret; - } - - ret = ini_config_parse(file_ctx, - INI_STOP_ON_ANY, /* error_level */ - /* Merge section but allow duplicates */ - INI_MS_MERGE | - INI_MV1S_ALLOW | - INI_MV2S_ALLOW, - INI_PARSE_NOWRAP, /* parse_flags */ - ini_config); - if (ret) { - char **errors = NULL; - /* we had a parsing failure */ - GPDEBUG("Failed to parse config file: %d (%s)\n", - ret, gp_strerror(ret)); - if (ini_config_error_count(ini_config)) { - ini_config_get_errors(ini_config, &errors); - if (errors) { - ini_config_print_errors(stderr, errors); - ini_config_free_errors(errors); - } - } - ini_config_file_destroy(file_ctx); - ini_config_destroy(ini_config); - return ret; - } - - ini_config_file_destroy(file_ctx); - - ctx->private_data = ini_config; - - return 0; -} - -int gp_dinglibs_close(struct gp_ini_context *ctx) -{ - struct ini_cfgobj *ini_config = NULL; - - if (!ctx) { - return 0; - } - - ini_config = (struct ini_cfgobj *)ctx->private_data; - - ini_config_destroy(ini_config); - - return 0; -} - -int gp_dinglibs_get_nsec(struct gp_ini_context *ctx) -{ - struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; - char **list = NULL; - int count; - int error; - - list = ini_get_section_list(ini_config, &count, &error); - if (error) { - return 0; - } - - ini_free_section_list(list); - - return count; -} - -char *gp_dinglibs_get_secname(struct gp_ini_context *ctx, - int i) -{ - struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; - char **list = NULL; - int count; - int error; - char *secname; - - list = ini_get_section_list(ini_config, &count, &error); - if (error) { - return NULL; - } - - if (i >= count) { - return NULL; - } - - secname = strdup(list[i]); - ini_free_section_list(list); - if (!secname) { - return NULL; - } - - return secname; -} - -#endif /* WITH_DINGLIBS */ diff --git a/proxy/src/gp_config_dinglibs.h b/proxy/src/gp_config_dinglibs.h deleted file mode 100644 index b969c76..0000000 --- a/proxy/src/gp_config_dinglibs.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - GSS-PROXY - - Copyright (C) 2011 Red Hat, Inc. - Copyright (C) 2011 Simo Sorce <simo.sorce@redhat.com> - Copyright (C) 2012-2013 Guenther Deschner <guenther.deschner@redhat.com> - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -int gp_dinglibs_get_string(struct gp_ini_context *ctx, - const char *secname, - const char *key, - const char **value); -int gp_dinglibs_get_string_array(struct gp_ini_context *ctx, - const char *secname, - const char *key, - int *num_values, - const char ***values); -int gp_dinglibs_get_int(struct gp_ini_context *ctx, - const char *secname, - const char *key, - int *value); -int gp_dinglibs_init(const char *config_file, - struct gp_ini_context *ctx); -int gp_dinglibs_close(struct gp_ini_context *ctx); -int gp_dinglibs_get_nsec(struct gp_ini_context *ctx); -char *gp_dinglibs_get_secname(struct gp_ini_context *ctx, - int i); |