1 /* Copyright 2010-2013 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)
26 #include "radsecproxy/list.h"
27 #include "radsecproxy/radsecproxy.h"
30 /* Public functions. */
32 rs_context_create (struct rs_context **ctx)
36 #if defined (RS_ENABLE_TLS)
41 h = calloc (1, sizeof(*h));
45 debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
54 rs_resolve (struct evutil_addrinfo **addr,
60 struct evutil_addrinfo hints, *res = NULL;
62 memset (&hints, 0, sizeof(struct evutil_addrinfo));
63 hints.ai_family = AF_UNSPEC;
64 hints.ai_flags = AI_ADDRCONFIG;
67 case RS_CONN_TYPE_NONE:
68 return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
69 case RS_CONN_TYPE_TCP:
71 case RS_CONN_TYPE_TLS:
72 hints.ai_socktype = SOCK_STREAM;
73 hints.ai_protocol = IPPROTO_TCP;
75 case RS_CONN_TYPE_UDP:
77 case RS_CONN_TYPE_DTLS:
78 hints.ai_socktype = SOCK_DGRAM;
79 hints.ai_protocol = IPPROTO_UDP;
82 return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
84 err = evutil_getaddrinfo (hostname, service, &hints, &res);
86 return err_create (RSE_BADADDR, __FILE__, __LINE__,
87 "%s:%s: bad host name or service name (%s)",
88 hostname, service, evutil_gai_strerror(err));
89 *addr = res; /* Simply use first result. */
94 rs_context_destroy (struct rs_context *ctx)
96 struct rs_realm *r = NULL;
97 struct rs_peer *p = NULL;
101 for (r = ctx->config->realms; r; )
103 struct rs_realm *tmp = r;
104 for (p = r->peers; p; )
106 struct rs_peer *tmp = p;
109 evutil_freeaddrinfo (p->addr_cache);
110 p->addr_cache = NULL;
116 rs_free (ctx, r->transport_cred);
124 if (ctx->config->cfg)
126 cfg_free (ctx->config->cfg);
127 ctx->config->cfg = NULL;
129 rs_free (ctx, ctx->config);
136 rs_context_set_alloc_scheme (struct rs_context *ctx,
137 struct rs_alloc_scheme *scheme)
139 return rs_err_ctx_push_fl (ctx, RSE_NOSYS, __FILE__, __LINE__, NULL);