diff options
author | Simo Sorce <simo@redhat.com> | 2012-01-13 12:05:14 -0500 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2012-01-14 16:48:08 -0500 |
commit | abcb0ac958269fbeecf05100f90cc8dd61d811f2 (patch) | |
tree | 9c4074118ab3bdd1882e067aa372d1ee7bc5959f | |
parent | 666087f91afd309267b0390fc21f481d3e72317f (diff) | |
download | gss-proxy-abcb0ac958269fbeecf05100f90cc8dd61d811f2.tar.gz gss-proxy-abcb0ac958269fbeecf05100f90cc8dd61d811f2.tar.xz gss-proxy-abcb0ac958269fbeecf05100f90cc8dd61d811f2.zip |
Add utils to read a configuration file
-rw-r--r-- | proxy/Makefile.am | 6 | ||||
-rw-r--r-- | proxy/configure.ac | 9 | ||||
-rw-r--r-- | proxy/src/gp_config.c | 109 | ||||
-rw-r--r-- | proxy/src/gp_utils.h | 10 | ||||
-rw-r--r-- | proxy/src/gssproxy.c | 19 |
5 files changed, 138 insertions, 15 deletions
diff --git a/proxy/Makefile.am b/proxy/Makefile.am index 34caffb..d1e4940 100644 --- a/proxy/Makefile.am +++ b/proxy/Makefile.am @@ -65,13 +65,12 @@ AM_CPPFLAGS = \ -DLIBDIR=\"$(libdir)\" \ -DVARDIR=\"$(localstatedir)\" \ -DSHLIBEXT=\"$(SHLIBEXT)\" \ - -DGSS_PROXY_CONF_DIR=\"$(gsspconfdir)\" \ - -DGSS_PROXY_SOCKET_NAME=\"$(pipepath)/gssproxy.socket\" \ + -DSYSCONFDIR=\"$(sysconfdir)\" \ -DLOCALEDIR=\"$(localedir)\" EXTRA_DIST = build/config.rpath -GSS_PROXY_LIBS = $(POPT_LIBS) $(KRB5_LIBS) $(VERTO_LIBS) +GSS_PROXY_LIBS = $(POPT_LIBS) $(KRB5_LIBS) $(VERTO_LIBS) $(INI_LIBS) if BUILD_SELINUX GSS_PROXY_LIBS += $(SELINUX_LIBS) @@ -83,6 +82,7 @@ dist_noinst_HEADERS = # Program Binaries # #################### gssproxy_SOURCES = \ + src/gp_config.c \ src/gp_init.c \ src/gp_socket.c \ src/gssproxy.c diff --git a/proxy/configure.ac b/proxy/configure.ac index f188a59..0ac439a 100644 --- a/proxy/configure.ac +++ b/proxy/configure.ac @@ -79,6 +79,15 @@ if test x$have_libverto = x; then AC_MSG_ERROR([Could not find VERTO headers]) fi +#Check for iniparser +AC_CHECK_HEADERS([iniparser.h], + [AC_CHECK_LIB(iniparser, iniparser_set, [ INI_LIBS="-liniparser" ], + [AC_MSG_ERROR([Iniparser library must support iniparser_set])])], + [AC_MSG_ERROR([Iniparser development package is not installed])] +) + +AC_SUBST(INI_LIBS) + WITH_INITSCRIPT if test x$initscript = xsystemd; then WITH_SYSTEMD_UNIT_DIR diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c new file mode 100644 index 0000000..4240819 --- /dev/null +++ b/proxy/src/gp_config.c @@ -0,0 +1,109 @@ +/* + GSS-PROXY + + Copyright (C) 2011 Red Hat, Inc. + Copyright (C) 2011 Simo Sorce <simo.sorce@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 <syslog.h> +#include <errno.h> +#include "gp_utils.h" +#include "iniparser.h" + +#define GP_SOCKET_NAME "gssproxy.socket" + +int load_config(struct gp_config *cfg) +{ + dictionary *d; + char *tmpstr; + int ret; + + d = iniparser_load(cfg->config_file); + if (!d) { + return ENOENT; + } + + tmpstr = iniparser_getstring(d, "gssproxy:socket", NULL); + if (tmpstr) { + cfg->socket_name = strdup(tmpstr); + if (!cfg->socket_name) { + ret = ENOMEM; + goto done; + } + } else { + ret = asprintf(&cfg->socket_name, "%s/%s", + PIPE_PATH, GP_SOCKET_NAME); + if (ret == -1) { + ret = ENOMEM; + goto done; + } + } + +done: + iniparser_freedict(d); + return ret; +} + +struct gp_config *read_config(char *config_file, int opt_daemonize) +{ + struct gp_config *cfg; + int ret; + + cfg = calloc(1, sizeof(struct gp_config)); + if (!cfg) { + exit(EXIT_FAILURE); + } + + if (config_file) { + cfg->config_file = strdup(config_file); + if (!cfg->config_file) { + exit(EXIT_FAILURE); + } + } else { + ret = asprintf(&cfg->config_file, "%s/gssproxy.conf", PUBCONF_PATH); + if (ret == -1) { + exit(EXIT_FAILURE); + } + } + + switch (opt_daemonize) { + case 0: + /* daemonize by default */ + case 1: + cfg->daemonize = true; + break; + case 2: + cfg->daemonize = false; + break; + } + + ret = load_config(cfg); + if (ret) { + syslog(LOG_INFO, "Config file not found"); + } + + return cfg; +} + diff --git a/proxy/src/gp_utils.h b/proxy/src/gp_utils.h index aed9362..ac690ac 100644 --- a/proxy/src/gp_utils.h +++ b/proxy/src/gp_utils.h @@ -27,10 +27,20 @@ #define _SRV_UTILS_H_ #include <libintl.h> +#include <stdbool.h> #include "verto.h" #define _(STRING) gettext(STRING) +struct gp_config { + char *config_file; + bool daemonize; + char *socket_name; +}; + +/* from gp_config.c */ +struct gp_config *read_config(char *config_file, int opt_daemonize); + /* from gp_init.c */ void init_server(void); void fini_server(void); diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c index c46edcd..5fc80cb 100644 --- a/proxy/src/gssproxy.c +++ b/proxy/src/gssproxy.c @@ -35,7 +35,7 @@ int main(int argc, const char *argv[]) int opt_interactive = 0; int opt_version = 0; char *opt_config_file = NULL; - char *config_file = NULL; + struct gp_config *config; verto_ctx *vctx; verto_ev *ev; int vflags; @@ -76,22 +76,15 @@ int main(int argc, const char *argv[]) return 1; } - if (!opt_daemon && !opt_interactive) { - opt_daemon = 1; + if (opt_interactive) { + opt_daemon = 2; } - poptFreeContext(pc); - - /* 1. Init server and sockets - * 2. Create thread pools and queues - * 3. Create mainloop and start serving clients - * 4. ... - * 5. Profit - */ + config = read_config(opt_config_file, opt_daemon); init_server(); - fd = init_unix_socket(GSS_PROXY_SOCKET_NAME); + fd = init_unix_socket(config->socket_name); if (fd == -1) { return 1; } @@ -111,5 +104,7 @@ int main(int argc, const char *argv[]) fini_server(); + poptFreeContext(pc); + return 0; } |