From c1de57efcaa05f4127a73f99c9f366149dc4b98f Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 4 Mar 2011 13:27:57 +0100 Subject: Revert 578e3551 -- double free in second invocation of dict_free(). --- lib/radsec.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index 6cc9fe4..f8bd246 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -142,7 +142,6 @@ void rs_context_destroy(struct rs_context *ctx) r = r->next; rs_free (ctx, tmp); } - dict_free (); rs_free (ctx, ctx); } -- cgit v1.1 From f87be530d67823a5d82367468e33d58b201ebee1 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 6 Mar 2011 14:30:14 +0100 Subject: Don't free config object until we destroy the context. --- lib/radsec.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index f8bd246..afb871e 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -142,6 +142,11 @@ void rs_context_destroy(struct rs_context *ctx) r = r->next; rs_free (ctx, tmp); } + + if (ctx->cfg) + cfg_free (ctx->cfg); + ctx->cfg = NULL; + rs_free (ctx, ctx); } -- cgit v1.1 From 7636505962a348d9564e53922834dc6df1274653 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 6 Mar 2011 14:46:57 +0100 Subject: UDP w/o bufferevents, part 1. Sending, no retransmitting and no receiving. --- lib/radsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index afb871e..f191e73 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -125,7 +125,8 @@ _rs_peer_destroy (struct rs_peer *p) 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; -- cgit v1.1 From 5c60297a1eaab7b10d6f584ba329493a41b812d0 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 6 Mar 2011 15:53:58 +0100 Subject: Restructure code, moving most code out of packet.c Also, move copyright notice out of COPYING and into every file. --- lib/radsec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index f191e73..6eb7c39 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 @@ -24,6 +25,8 @@ #endif #include "rsp_debug.h" + +/* Public functions. */ int rs_context_create(struct rs_context **ctx, const char *dict) { -- cgit v1.1 From 41af6cd03dac4eb905d0d3de574d2e4f3f9600eb Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 7 Mar 2011 09:53:40 +0100 Subject: Formatting changes. --- lib/radsec.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index 6eb7c39..dd182c6 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -28,7 +28,7 @@ /* 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; @@ -154,8 +154,10 @@ 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); } + -- cgit v1.1 From eff368434eafc492c8b4f8a455e2cb53a101708b Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Tue, 8 Mar 2011 14:29:09 +0100 Subject: Zap a double free. --- lib/radsec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index dd182c6..ddd4edd 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -117,14 +117,14 @@ _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). */ + + /* NOTE: The peer object doesn't own conn, nor realm. */ + /* NOTE: secret is owned by config */ if (p->addr) { evutil_freeaddrinfo (p->addr); p->addr = NULL; } - if (p->secret) - rs_free (p->conn->ctx, p->secret); rs_free (p->conn->ctx, p); } -- cgit v1.1 From ce4d6dfe1728e5633a8f49fc4b16c36df0d23521 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 9 Mar 2011 10:18:06 +0100 Subject: Add retransmission timer support (UDP). --- lib/radsec.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index ddd4edd..ec43b2f 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -20,6 +20,7 @@ #if defined (RS_ENABLE_TLS) #include #include "debug.h" +#include "err.h" #include "rsp_list.h" #include "../radsecproxy.h" #endif @@ -91,24 +92,44 @@ 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 -- cgit v1.1 From a48992622d54c6d5dbf5abe3022cfe5b06167261 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 10 Mar 2011 00:20:25 +0100 Subject: Don't miscompile without --enable-tls. Include err.h and debug.h even w/o RS_ENABLE_TLS. --- lib/radsec.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index ec43b2f..2ae515d 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -17,15 +17,14 @@ #include #include #include +#include "err.h" +#include "debug.h" +#include "rsp_debug.h" #if defined (RS_ENABLE_TLS) #include -#include "debug.h" -#include "err.h" #include "rsp_list.h" #include "../radsecproxy.h" #endif -#include "rsp_debug.h" - /* Public functions. */ int -- cgit v1.1 From c19e71100032927bf5d88ef700a5034dc3f08565 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 11 Mar 2011 13:19:39 +0100 Subject: Free the realm name which is strdup'd when config is read. --- lib/radsec.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index 2ae515d..0957365 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -163,6 +163,7 @@ rs_context_destroy (struct rs_context *ctx) p = p->next; _rs_peer_destroy (tmp); } + rs_free (ctx, r->name); r = r->next; rs_free (ctx, tmp); } -- cgit v1.1 From efce8db03af505f76c0c579f2439757bd6998dc9 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sat, 12 Mar 2011 01:03:43 +0100 Subject: Fix crash bug in _rs_peer_destroy(). Don't expect a peer to always have a connection. --- lib/radsec.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'lib/radsec.c') diff --git a/lib/radsec.c b/lib/radsec.c index 0957365..a05a22b 100644 --- a/lib/radsec.c +++ b/lib/radsec.c @@ -131,23 +131,6 @@ rs_resolv (struct evutil_addrinfo **addr, 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 conn, nor realm. */ - /* NOTE: secret is owned by config */ - if (p->addr) - { - evutil_freeaddrinfo (p->addr); - p->addr = NULL; - } - rs_free (p->conn->ctx, p); -} - void rs_context_destroy (struct rs_context *ctx) { @@ -160,8 +143,10 @@ 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; -- cgit v1.1