diff options
author | Günther Deschner <gdeschner@redhat.com> | 2012-10-23 16:19:35 +0200 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2013-04-08 09:27:47 -0400 |
commit | f5fb025d692e429b9be5aef890179efd1a40e360 (patch) | |
tree | 42a0519e01a5bf3c5c2bb0e2280abf9023333997 | |
parent | 19d091b9eaddc52d9c33ab0419029603f15db1da (diff) | |
download | gss-proxy-f5fb025d692e429b9be5aef890179efd1a40e360.tar.gz gss-proxy-f5fb025d692e429b9be5aef890179efd1a40e360.tar.xz gss-proxy-f5fb025d692e429b9be5aef890179efd1a40e360.zip |
Add dinglibs ini configuration detection and backend.
Signed-off-by: Günther Deschner <gdeschner@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
-rw-r--r-- | proxy/Makefile.am | 3 | ||||
-rw-r--r-- | proxy/configure.ac | 15 | ||||
-rw-r--r-- | proxy/src/gp_config.c | 41 | ||||
-rw-r--r-- | proxy/src/gp_config_dinglibs.c | 205 | ||||
-rw-r--r-- | proxy/src/gp_config_dinglibs.h | 38 |
5 files changed, 302 insertions, 0 deletions
diff --git a/proxy/Makefile.am b/proxy/Makefile.am index 79df078..ea16bed 100644 --- a/proxy/Makefile.am +++ b/proxy/Makefile.am @@ -71,6 +71,7 @@ AM_CPPFLAGS = \ -I. \ $(POPT_CFLAGS) \ $(GSSAPI_CFLAGS) \ + $(INI_CFLAGS) \ -DLIBDIR=\"$(libdir)\" \ -DVARDIR=\"$(localstatedir)\" \ -DSHLIBEXT=\"$(SHLIBEXT)\" \ @@ -128,6 +129,7 @@ dist_noinst_HEADERS = \ src/gp_conv.h \ src/gp_config.h \ src/gp_config_iniparser.h \ + src/gp_config_dinglibs.h \ src/gp_debug.h \ src/gp_rpc_creds.h \ src/mechglue/gss_plugin.h @@ -140,6 +142,7 @@ dist_noinst_HEADERS = \ gssproxy_SOURCES = \ src/gp_config.c \ src/gp_config_iniparser.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 42ab027..edfb43b 100644 --- a/proxy/configure.ac +++ b/proxy/configure.ac @@ -90,7 +90,22 @@ AC_CHECK_HEADERS([iniparser.h], [AC_MSG_ERROR([Iniparser development package is not installed])] ) +#Check for libini_config +PKG_CHECK_MODULES([LIBINI_CONFIG], [ini_config >= 1.0.0], [have_libini_config=1], [have_libini_config=]) +if test x$have_libini_config = x; then + AC_MSG_WARN([Could not find LIBINI_CONFIG headers]) +else + INI_CONFIG_CFLAGS="`$PKG_CONFIG --cflags ini_config`" + INI_CONFIG_LIBS="`$PKG_CONFIG --libs ini_config`" + AC_CHECK_LIB(ini_config, ini_config_file_open, + [INI_LIBS="$INI_LIBS $INI_CONFIG_LIBS"; INI_CFLAGS="$INI_CONFIG_CFLAGS"; + AC_DEFINE([HAVE_DINGLIBS], [1], [Dinglibs library available.])], + [AC_MSG_WARN([ini_config library must support ini_config_file_open])], + [$INI_CONFIG_LIBS]) +fi + AC_SUBST(INI_LIBS) +AC_SUBST(INI_CFLAGS) AX_PTHREAD(,[AC_MSG_ERROR([Could not find Pthreads support])]) diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c index b19c095..8e3953a 100644 --- a/proxy/src/gp_config.c +++ b/proxy/src/gp_config.c @@ -399,3 +399,44 @@ int gp_config_close(struct gp_ini_context *ctx) } #endif /* WITH_INIPARSER */ + +#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); +} + +char *gp_config_get_string(struct gp_ini_context *ctx, + const char *secname, + const char *keyname) +{ + return gp_dinglibs_get_string(ctx, secname, keyname); +} + +int gp_config_get_int(struct gp_ini_context *ctx, + const char *secname, + const char *keyname) +{ + return gp_dinglibs_get_int(ctx, secname, keyname); +} + +int gp_config_get_nsec(struct gp_ini_context *ctx) +{ + return gp_dinglibs_get_nsec(ctx); +} + +char *gp_config_get_secname(struct gp_ini_context *ctx, + int i) +{ + return gp_dinglibs_get_secname(ctx, i); +} + +int gp_config_close(struct gp_ini_context *ctx) +{ + return gp_dinglibs_close(ctx); +} + +#endif /* WITH_DINGLIBS */ diff --git a/proxy/src/gp_config_dinglibs.c b/proxy/src/gp_config_dinglibs.c new file mode 100644 index 0000000..3ad16c2 --- /dev/null +++ b/proxy/src/gp_config_dinglibs.c @@ -0,0 +1,205 @@ +/* + 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 HAVE_DINGLIBS + +#include <ini_configobj.h> + +char *gp_dinglibs_get_string(struct gp_ini_context *ctx, + const char *secname, + const char *key) +{ + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + struct value_obj *vo = NULL; + const char *value; + int ret; + + ret = ini_get_config_valueobj(secname, + key, + ini_config, + INI_GET_FIRST_VALUE, + &vo); + if (ret || !vo) { + return NULL; + } + + value = ini_get_const_string_config_value(vo, &ret); + if (ret) { + return NULL; + } + + return value; +} + +int gp_dinglibs_get_int(struct gp_ini_context *ctx, + const char *secname, + const char *key) +{ + struct ini_cfgobj *ini_config = (struct ini_cfgobj *)ctx->private_data; + struct value_obj *vo = NULL; + int value; + int ret; + + ret = ini_get_config_valueobj(secname, + key, + ini_config, + INI_GET_FIRST_VALUE, + &vo); + + if (ret || !vo) { + return -1; + } + + value = ini_get_int_config_value(vo, + 0, /* strict */ + 0, /* default */ + &ret); + if (ret) { + return -1; + } + + return value; +} + +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, strerror(ret)); + ini_config_destroy(ini_config); + return ret; + } + + ret = ini_config_parse(file_ctx, + INI_STOP_ON_NONE, /* 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) { + /* we had a parsing failure */ + GPDEBUG("Failed to parse config file: %d (%s)\n", + ret, strerror(ret)); + 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 /* HAVE_DINGLIBS */ diff --git a/proxy/src/gp_config_dinglibs.h b/proxy/src/gp_config_dinglibs.h new file mode 100644 index 0000000..3dadbee --- /dev/null +++ b/proxy/src/gp_config_dinglibs.h @@ -0,0 +1,38 @@ +/* + 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. +*/ + +char *gp_dinglibs_get_string(struct gp_ini_context *ctx, + const char *secname, + const char *key); +int gp_dinglibs_get_int(struct gp_ini_context *ctx, + const char *secname, + const char *key); +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); |