diff options
author | Linus Nordberg <linus@nordu.net> | 2011-03-12 12:41:19 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2011-03-12 12:41:19 +0100 |
commit | 2af84872cb78becf43f7bf4a654418fb7fc532d5 (patch) | |
tree | 7c3f33df5316fd67431fc4e70356d7a62da4543f /lib/radsec.c | |
parent | 319c2bf1b2886b2e5cd1c5d60a8950493d2d4d75 (diff) | |
parent | efce8db03af505f76c0c579f2439757bd6998dc9 (diff) |
Merge branch 'udp' into libradsec.
Diffstat (limited to 'lib/radsec.c')
-rw-r--r-- | lib/radsec.c | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/lib/radsec.c b/lib/radsec.c index b771dc8..a05a22b 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -1,4 +1,5 @@ -/* See the file COPYING for licensing information. */ +/* Copyright 2010, 2011 NORDUnet A/S. All rights reserved. + See the file COPYING for licensing information. */ #if defined HAVE_CONFIG_H #include <config.h> @@ -16,16 +17,18 @@ #include <event2/util.h> #include <radsec/radsec.h> #include <radsec/radsec-impl.h> +#include "err.h" +#include "debug.h" +#include "rsp_debug.h" #if defined (RS_ENABLE_TLS) #include <regex.h> -#include "debug.h" #include "rsp_list.h" #include "../radsecproxy.h" #endif -#include "rsp_debug.h" +/* Public functions. */ int -rs_context_create(struct rs_context **ctx, const char *dict) +rs_context_create (struct rs_context **ctx, const char *dict) { int err = RSE_OK; struct rs_context *h; @@ -88,44 +91,48 @@ rs_context_create(struct rs_context **ctx, const char *dict) return err; } -struct rs_peer * -_rs_peer_create (struct rs_context *ctx, struct rs_peer **rootp) +struct rs_error * /* FIXME: Return int as all the others? */ +rs_resolv (struct evutil_addrinfo **addr, + rs_conn_type_t type, + const char *hostname, + const char *service) { - struct rs_peer *p; + int err; + struct evutil_addrinfo hints, *res = NULL; - p = (struct rs_peer *) rs_malloc (ctx, sizeof(*p)); - if (p) + memset (&hints, 0, sizeof(struct evutil_addrinfo)); + hints.ai_family = AF_INET; /* IPv4 only. TODO: Set AF_UNSPEC. */ + hints.ai_flags = AI_ADDRCONFIG; + switch (type) { - memset (p, 0, sizeof(struct rs_peer)); - if (*rootp) - { - p->next = (*rootp)->next; - (*rootp)->next = p; - } - else - *rootp = p; + case RS_CONN_TYPE_NONE: + return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL); + case RS_CONN_TYPE_TCP: + /* Fall through. */ + case RS_CONN_TYPE_TLS: + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + break; + case RS_CONN_TYPE_UDP: + /* Fall through. */ + case RS_CONN_TYPE_DTLS: + hints.ai_socktype = SOCK_DGRAM; + hints.ai_protocol = IPPROTO_UDP; + break; + default: + return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL); } - return p; + err = evutil_getaddrinfo (hostname, service, &hints, &res); + if (err) + return err_create (RSE_BADADDR, __FILE__, __LINE__, + "%s:%s: bad host name or service name (%s)", + hostname, service, evutil_gai_strerror(err)); + *addr = res; /* Simply use first result. */ + return NULL; } -static void -_rs_peer_destroy (struct rs_peer *p) -{ - assert (p); - assert (p->conn); - assert (p->conn->ctx); - /* NOTE: The peer object doesn't own its connection (conn), nor its - realm. */ - /* NOTE: secret is owned by config object. */ - if (p->addr) - { - evutil_freeaddrinfo (p->addr); - p->addr = NULL; - } - rs_free (p->conn->ctx, p); -} - -void rs_context_destroy(struct rs_context *ctx) +void +rs_context_destroy (struct rs_context *ctx) { struct rs_realm *r = NULL; struct rs_peer *p = NULL; @@ -136,9 +143,12 @@ void rs_context_destroy(struct rs_context *ctx) for (p = r->peers; p; ) { struct rs_peer *tmp = p; + if (p->addr) + evutil_freeaddrinfo (p->addr); p = p->next; - _rs_peer_destroy (tmp); + rs_free (ctx, tmp); } + rs_free (ctx, r->name); r = r->next; rs_free (ctx, tmp); } @@ -150,8 +160,10 @@ void rs_context_destroy(struct rs_context *ctx) rs_free (ctx, ctx); } -int rs_context_set_alloc_scheme(struct rs_context *ctx, - struct rs_alloc_scheme *scheme) +int +rs_context_set_alloc_scheme (struct rs_context *ctx, + struct rs_alloc_scheme *scheme) { return rs_err_ctx_push_fl (ctx, RSE_NOSYS, __FILE__, __LINE__, NULL); } + |