Improve initialisation of OpenSSL PRNG.
[radsecproxy.git] / lib / event.c
index bfb34bc..a532da9 100644 (file)
@@ -1,11 +1,14 @@
-/* Copyright 2011 NORDUnet A/S. All rights reserved.
-   See the file COPYING for licensing information.  */
+/* Copyright 2011-2013 NORDUnet A/S. All rights reserved.
+   See LICENSE for licensing information. */
 
 #if defined HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 #include <assert.h>
+#include <string.h>
+#include <errno.h>
+
 #include <event2/event.h>
 #include <event2/bufferevent.h>
 #if defined (RS_ENABLE_TLS)
@@ -89,6 +92,21 @@ event_retransmit_timeout_cb (int fd, short event, void *data)
       rs_debug (("%s: retransmission timeout on %p (fd %d) sending to %p\n",
                 __func__, conn, conn->fd, conn->active_peer));
       rs_err_conn_push_fl (conn, RSE_TIMEOUT_IO, __FILE__, __LINE__, NULL);
+
+      /* Disable/delete read and write events. Timing out on reading
+         might f.ex. trigger resending of a message. It'd be
+         surprising to end up reading without having enabled/created a
+         read event in that case. */
+      if (conn->bev)            /* TCP. */
+        bufferevent_disable (conn->bev, EV_WRITE|EV_READ);
+      else                      /* UDP. */
+        {
+          if (conn->wev)
+            event_del (conn->wev);
+          if (conn->rev)
+            event_del (conn->rev);
+        }
+
       event_loopbreak (conn);
     }
 }
@@ -140,7 +158,7 @@ event_init_bufferevent (struct rs_connection *conn, struct rs_peer *peer)
 #if defined (RS_ENABLE_TLS)
   else if (conn->realm->type == RS_CONN_TYPE_TLS)
     {
-      if (rs_tls_init (conn))
+      if (tls_init_conn (conn))
        return -1;
       /* Would be convenient to pass BEV_OPT_CLOSE_ON_FREE but things
         seem to break when be_openssl_ctrl() (in libevent) calls
@@ -219,9 +237,7 @@ event_loopbreak (struct rs_connection *conn)
 {
   int err = event_base_loopbreak (conn->evb);
   if (err < 0)
-    rs_err_conn_push_fl (conn, RSE_EVENT, __FILE__, __LINE__,
-                        "event_base_loopbreak: %s",
-                        evutil_gai_strerror (err));
+    rs_err_conn_push (conn, RSE_EVENT, "event_base_loopbreak");
   return err;
 }
 
@@ -243,8 +259,7 @@ event_on_connect (struct rs_connection *conn, struct rs_packet *pkt)
   assert (!conn->is_connecting);
 
 #if defined (RS_ENABLE_TLS)
-  if (conn->realm->type == RS_CONN_TYPE_TLS
-      || conn->realm->type == RS_CONN_TYPE_DTLS)
+  if (conn_type_tls(conn) && !conn_cred_psk(conn))
     if (tls_verify_cert (conn) != RSE_OK)
       {
         rs_debug (("%s: server cert verification failed\n", __func__));