1 /* Copyright 2010, 2011 NORDUnet A/S. All rights reserved.
2 See the file COPYING for licensing information. */
4 #if defined HAVE_CONFIG_H
15 #include <freeradius/libradius.h>
16 #include <event2/event.h>
17 #include <event2/util.h>
18 #include <radsec/radsec.h>
19 #include <radsec/radsec-impl.h>
22 #include "rsp_debug.h"
23 #if defined (RS_ENABLE_TLS)
26 #include "../radsecproxy.h"
29 /* Public functions. */
31 rs_context_create (struct rs_context **ctx, const char *dict)
35 char *buf1 = NULL, *buf2 = NULL;
42 h = (struct rs_context *) malloc (sizeof(struct rs_context));
46 /* Initialize freeradius dictionary. */
47 buf1 = malloc (strlen (dict) + 1);
48 buf2 = malloc (strlen (dict) + 1);
58 if (dict_init (dir, fn) < 0)
66 #if defined (RS_ENABLE_TLS)
73 debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
75 memset (h, 0, sizeof(struct rs_context));
76 fr_randinit (&h->fr_randctx, 0);
77 fr_rand_seed (NULL, 0);
94 struct rs_error * /* FIXME: Return int as all the others? */
95 rs_resolv (struct evutil_addrinfo **addr,
101 struct evutil_addrinfo hints, *res = NULL;
103 memset (&hints, 0, sizeof(struct evutil_addrinfo));
104 hints.ai_family = AF_INET; /* IPv4 only. TODO: Set AF_UNSPEC. */
105 hints.ai_flags = AI_ADDRCONFIG;
108 case RS_CONN_TYPE_NONE:
109 return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
110 case RS_CONN_TYPE_TCP:
112 case RS_CONN_TYPE_TLS:
113 hints.ai_socktype = SOCK_STREAM;
114 hints.ai_protocol = IPPROTO_TCP;
116 case RS_CONN_TYPE_UDP:
118 case RS_CONN_TYPE_DTLS:
119 hints.ai_socktype = SOCK_DGRAM;
120 hints.ai_protocol = IPPROTO_UDP;
123 return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
125 err = evutil_getaddrinfo (hostname, service, &hints, &res);
127 return err_create (RSE_BADADDR, __FILE__, __LINE__,
128 "%s:%s: bad host name or service name (%s)",
129 hostname, service, evutil_gai_strerror(err));
130 *addr = res; /* Simply use first result. */
135 rs_context_destroy (struct rs_context *ctx)
137 struct rs_realm *r = NULL;
138 struct rs_peer *p = NULL;
140 for (r = ctx->realms; r; )
142 struct rs_realm *tmp = r;
143 for (p = r->peers; p; )
145 struct rs_peer *tmp = p;
147 evutil_freeaddrinfo (p->addr);
151 rs_free (ctx, r->name);
164 rs_context_set_alloc_scheme (struct rs_context *ctx,
165 struct rs_alloc_scheme *scheme)
167 return rs_err_ctx_push_fl (ctx, RSE_NOSYS, __FILE__, __LINE__, NULL);