From 1aec40b19514481b4b155bf46a71e8bca139ccba Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 16 Jan 2012 11:35:51 -0500 Subject: Add gssproxy_ctx And store configuration context within it. --- proxy/src/gp_config.c | 10 ++++++---- proxy/src/gp_socket.c | 4 +++- proxy/src/gp_utils.h | 4 ++++ proxy/src/gssproxy.c | 15 +++++++++++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c index 4240819..552539d 100644 --- a/proxy/src/gp_config.c +++ b/proxy/src/gp_config.c @@ -73,18 +73,20 @@ struct gp_config *read_config(char *config_file, int opt_daemonize) cfg = calloc(1, sizeof(struct gp_config)); if (!cfg) { - exit(EXIT_FAILURE); + return NULL; } if (config_file) { cfg->config_file = strdup(config_file); if (!cfg->config_file) { - exit(EXIT_FAILURE); + free(cfg); + return NULL; } } else { ret = asprintf(&cfg->config_file, "%s/gssproxy.conf", PUBCONF_PATH); if (ret == -1) { - exit(EXIT_FAILURE); + free(cfg); + return NULL; } } @@ -101,7 +103,7 @@ struct gp_config *read_config(char *config_file, int opt_daemonize) ret = load_config(cfg); if (ret) { - syslog(LOG_INFO, "Config file not found"); + syslog(LOG_INFO, "Config file not found! Proceeding with defaults."); } return cfg; diff --git a/proxy/src/gp_socket.c b/proxy/src/gp_socket.c index 238b2d4..4b26ce1 100644 --- a/proxy/src/gp_socket.c +++ b/proxy/src/gp_socket.c @@ -40,6 +40,8 @@ struct unix_sock_conn { struct sockaddr_un sock_addr; socklen_t sock_addr_len; + struct gssproxy_ctx *gpctx; + #ifdef HAVE_UCRED struct ucred creds; #else @@ -52,7 +54,6 @@ struct unix_sock_conn { }; - static int set_status_flags(int fd, int flags) { int cur; @@ -201,6 +202,7 @@ void accept_sock_conn(verto_ctx *vctx, verto_ev *ev) ret = ENOMEM; goto done; } + conn->gpctx = verto_get_private(ev); listen_fd = verto_get_fd(ev); fd = accept(listen_fd, diff --git a/proxy/src/gp_utils.h b/proxy/src/gp_utils.h index 8f0ae81..70e3293 100644 --- a/proxy/src/gp_utils.h +++ b/proxy/src/gp_utils.h @@ -38,6 +38,10 @@ struct gp_config { char *socket_name; }; +struct gssproxy_ctx { + struct gp_config *config; +}; + /* from gp_config.c */ struct gp_config *read_config(char *config_file, int opt_daemonize); diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c index f1d679f..ba11fa2 100644 --- a/proxy/src/gssproxy.c +++ b/proxy/src/gssproxy.c @@ -24,6 +24,7 @@ */ #include "config.h" +#include #include "popt.h" #include "gp_utils.h" @@ -35,11 +36,11 @@ int main(int argc, const char *argv[]) int opt_interactive = 0; int opt_version = 0; char *opt_config_file = NULL; - struct gp_config *config; verto_ctx *vctx; verto_ev *ev; int vflags; int fd; + struct gssproxy_ctx *gpctx; struct poptOption long_options[] = { POPT_AUTOHELP @@ -80,11 +81,16 @@ int main(int argc, const char *argv[]) opt_daemon = 2; } - config = read_config(opt_config_file, opt_daemon); + gpctx = calloc(1, sizeof(struct gssproxy_ctx)); - init_server(config->daemonize); + gpctx->config = read_config(opt_config_file, opt_daemon); + if (!gpctx->config) { + exit(EXIT_FAILURE); + } + + init_server(gpctx->config->daemonize); - fd = init_unix_socket(config->socket_name); + fd = init_unix_socket(gpctx->config->socket_name); if (fd == -1) { return 1; } @@ -99,6 +105,7 @@ int main(int argc, const char *argv[]) if (!ev) { return 1; } + verto_set_private(ev, gpctx, NULL); verto_run(vctx); -- cgit