Skip to content

Commit

Permalink
Add gssproxy_ctx
Browse files Browse the repository at this point in the history
And store configuration context within it.
  • Loading branch information
simo5 committed Jan 18, 2012
1 parent e4a560e commit 1aec40b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
10 changes: 6 additions & 4 deletions proxy/src/gp_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion proxy/src/gp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +54,6 @@ struct unix_sock_conn {
};



static int set_status_flags(int fd, int flags)
{
int cur;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions proxy/src/gp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 11 additions & 4 deletions proxy/src/gssproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include "config.h"
#include <stdlib.h>
#include "popt.h"
#include "gp_utils.h"

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -99,6 +105,7 @@ int main(int argc, const char *argv[])
if (!ev) {
return 1;
}
verto_set_private(ev, gpctx, NULL);

verto_run(vctx);

Expand Down

0 comments on commit 1aec40b

Please sign in to comment.