diff options
Diffstat (limited to 'proxy/src')
-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 |
3 files changed, 126 insertions, 12 deletions
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; } |