1 /* Copyright 2010, 2011 NORDUnet A/S. All rights reserved.
2 See LICENSE for licensing information. */
4 #if defined HAVE_CONFIG_H
15 #include <radius/client.h>
16 #include <event2/event.h>
17 #include <event2/util.h>
18 #include <radsec/radsec.h>
19 #include <radsec/radsec-impl.h>
22 #include "radsecproxy/debug.h"
23 #if defined (RS_ENABLE_TLS)
25 #include "radsecproxy/list.h"
26 #include "radsecproxy/radsecproxy.h"
29 /* Public functions. */
31 rs_context_create (struct rs_context **ctx)
35 h = calloc (1, sizeof(*h));
39 #if defined (RS_ENABLE_TLS)
43 debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
52 rs_resolve (struct evutil_addrinfo **addr,
58 struct evutil_addrinfo hints, *res = NULL;
60 memset (&hints, 0, sizeof(struct evutil_addrinfo));
61 hints.ai_family = AF_UNSPEC;
62 hints.ai_flags = AI_ADDRCONFIG;
65 case RS_CONN_TYPE_NONE:
66 return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
67 case RS_CONN_TYPE_TCP:
69 case RS_CONN_TYPE_TLS:
70 hints.ai_socktype = SOCK_STREAM;
71 hints.ai_protocol = IPPROTO_TCP;
73 case RS_CONN_TYPE_UDP:
75 case RS_CONN_TYPE_DTLS:
76 hints.ai_socktype = SOCK_DGRAM;
77 hints.ai_protocol = IPPROTO_UDP;
80 return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
82 err = evutil_getaddrinfo (hostname, service, &hints, &res);
84 return err_create (RSE_BADADDR, __FILE__, __LINE__,
85 "%s:%s: bad host name or service name (%s)",
86 hostname, service, evutil_gai_strerror(err));
87 *addr = res; /* Simply use first result. */
92 rs_context_destroy (struct rs_context *ctx)
94 struct rs_realm *r = NULL;
95 struct rs_peer *p = NULL;
99 for (r = ctx->config->realms; r; )
101 struct rs_realm *tmp = r;
102 for (p = r->peers; p; )
104 struct rs_peer *tmp = p;
107 evutil_freeaddrinfo (p->addr_cache);
108 p->addr_cache = NULL;
114 rs_free (ctx, r->transport_cred);
122 if (ctx->config->cfg)
124 cfg_free (ctx->config->cfg);
125 ctx->config->cfg = NULL;
127 rs_free (ctx, ctx->config);
134 rs_context_set_alloc_scheme (struct rs_context *ctx,
135 struct rs_alloc_scheme *scheme)
137 return rs_err_ctx_push_fl (ctx, RSE_NOSYS, __FILE__, __LINE__, NULL);