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 ba2c5a3..d60d59b 100644 (file)
--- a/tls.c
+++ b/tls.c
@@ -339,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;
     }
@@ -385,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)) {
@@ -412,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)
@@ -458,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);