Create threads with a 32 KB stack rather than what happens to be the default.
[radsecproxy.git] / tls.c
diff --git a/tls.c b/tls.c
index f79529f..d60d59b 100644 (file)
--- a/tls.c
+++ b/tls.c
@@ -26,9 +26,8 @@
 #include <pthread.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
-#include "list.h"
-#include "hostport.h"
 #include "radsecproxy.h"
+#include "hostport.h"
 
 #ifdef RADPROT_TLS
 #include "debug.h"
@@ -44,7 +43,7 @@ void tlssetsrcres();
 
 static const struct protodefs protodefs = {
     "tls",
-    "mysecret", /* secretdefault */
+    "radsec", /* secretdefault */
     SOCK_STREAM, /* socktype */
     "2083", /* portdefault */
     0, /* retrycountdefault */
@@ -83,7 +82,9 @@ static char **getlistenerargs() {
 
 void tlssetsrcres() {
     if (!srcres)
-       srcres = resolvepassiveaddrinfo(protoopts ? protoopts->sourcearg : NULL, NULL, protodefs.socktype);
+       srcres =
+            resolvepassiveaddrinfo(protoopts ? protoopts->sourcearg : NULL,
+                                   AF_UNSPEC, NULL, protodefs.socktype);
 }
 
 int tlsconnect(struct server *server, struct timeval *when, int timeout, char *text) {
@@ -338,7 +339,7 @@ void tlsserverrd(struct client *client) {
 
     debug(DBG_DBG, "tlsserverrd: starting for %s", addr2string(client->addr));
 
-    if (pthread_create(&tlsserverwrth, NULL, tlsserverwr, (void *)client)) {
+    if (pthread_create(&tlsserverwrth, &pthread_attr, tlsserverwr, (void *)client)) {
        debug(DBG_ERR, "tlsserverrd: pthread_create failed");
        return;
     }
@@ -384,6 +385,7 @@ void *tlsservernew(void *arg) {
     SSL_CTX *ctx = NULL;
     unsigned long error;
     struct client *client;
+    struct tls *accepted_tls = NULL;
 
     s = *(int *)arg;
     if (getpeername(s, (struct sockaddr *)&from, &fromlen)) {
@@ -411,22 +413,23 @@ void *tlsservernew(void *arg) {
        cert = verifytlscert(ssl);
        if (!cert)
            goto exit;
+        accepted_tls = conf->tlsconf;
     }
 
     while (conf) {
-       if (verifyconfcert(cert, conf)) {
-           X509_free(cert);
-           client = addclient(conf, 1);
-           if (client) {
-               client->ssl = ssl;
-               client->addr = addr_copy((struct sockaddr *)&from);
-               tlsserverrd(client);
-               removeclient(client);
-           } else
-               debug(DBG_WARN, "tlsservernew: failed to create new client instance");
-           goto exit;
-       }
-       conf = find_clconf(handle, (struct sockaddr *)&from, &cur);
+        if (accepted_tls == conf->tlsconf && verifyconfcert(cert, conf)) {
+            X509_free(cert);
+            client = addclient(conf, 1);
+            if (client) {
+                client->ssl = ssl;
+                client->addr = addr_copy((struct sockaddr *)&from);
+                tlsserverrd(client);
+                removeclient(client);
+            } else
+                debug(DBG_WARN, "tlsservernew: failed to create new client instance");
+            goto exit;
+        }
+        conf = find_clconf(handle, (struct sockaddr *)&from, &cur);
     }
     debug(DBG_WARN, "tlsservernew: ignoring request, no matching TLS client");
     if (cert)
@@ -457,7 +460,7 @@ void *tlslistener(void *arg) {
            debug(DBG_WARN, "accept failed");
            continue;
        }
-       if (pthread_create(&tlsserverth, NULL, tlsservernew, (void *)&s)) {
+       if (pthread_create(&tlsserverth, &pthread_attr, tlsservernew, (void *)&s)) {
            debug(DBG_ERR, "tlslistener: pthread_create failed");
            shutdown(s, SHUT_RDWR);
            close(s);