renamed struct queue to gqueue due to solaris defining queue
[radsecproxy.git] / tls.c
diff --git a/tls.c b/tls.c
index 5014b46..fa43aea 100644 (file)
--- a/tls.c
+++ b/tls.c
 #include <pthread.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
-#include "debug.h"
 #include "list.h"
-#include "util.h"
 #include "radsecproxy.h"
-#include "tls.h"
+
+#ifdef RADPROT_TLS
+#include "debug.h"
+#include "util.h"
+
+static void setprotoopts(struct commonprotoopts *opts);
+static char **getlistenerargs();
+void *tlslistener(void *arg);
+int tlsconnect(struct server *server, struct timeval *when, int timeout, char *text);
+void *tlsclientrd(void *arg);
+int clientradputtls(struct server *server, unsigned char *rad);
+void tlssetsrcres();
+
+static const struct protodefs protodefs = {
+    "tls",
+    "mysecret", /* secretdefault */
+    SOCK_STREAM, /* socktype */
+    "2083", /* portdefault */
+    0, /* retrycountdefault */
+    0, /* retrycountmax */
+    REQUEST_RETRY_INTERVAL * REQUEST_RETRY_COUNT, /* retryintervaldefault */
+    60, /* retryintervalmax */
+    DUPLICATE_INTERVAL, /* duplicateintervaldefault */
+    setprotoopts, /* setprotoopts */
+    getlistenerargs, /* getlistenerargs */
+    tlslistener, /* listener */
+    tlsconnect, /* connecter */
+    tlsclientrd, /* clientconnreader */
+    clientradputtls, /* clientradput */
+    NULL, /* addclient */
+    NULL, /* addserverextra */
+    tlssetsrcres, /* setsrcres */
+    NULL /* initextra */
+};
+
+static struct addrinfo *srcres = NULL;
+static uint8_t handle;
+static struct commonprotoopts *protoopts = NULL;
+
+const struct protodefs *tlsinit(uint8_t h) {
+    handle = h;
+    return &protodefs;
+}
+
+static void setprotoopts(struct commonprotoopts *opts) {
+    protoopts = opts;
+}
+
+static char **getlistenerargs() {
+    return protoopts ? protoopts->listenargs : NULL;
+}
+
+void tlssetsrcres() {
+    if (!srcres)
+       srcres = resolve_hostport_addrinfo(handle, protoopts ? protoopts->sourcearg : NULL);
+    
+}
 
 int tlsconnect(struct server *server, struct timeval *when, int timeout, char *text) {
     struct timeval now;
@@ -76,14 +130,14 @@ int tlsconnect(struct server *server, struct timeval *when, int timeout, char *t
        debug(DBG_WARN, "tlsconnect: trying to open TLS connection to %s port %s", server->conf->host, server->conf->port);
        if (server->sock >= 0)
            close(server->sock);
-       if ((server->sock = connecttcp(server->conf->addrinfo, getsrcprotores(RAD_TLS))) < 0) {
+       if ((server->sock = connecttcp(server->conf->addrinfo, srcres)) < 0) {
            debug(DBG_ERR, "tlsconnect: connecttcp failed");
            continue;
        }
        
        SSL_free(server->ssl);
        server->ssl = NULL;
-       ctx = tlsgetctx(RAD_TLS, server->conf->tlsconf);
+       ctx = tlsgetctx(handle, server->conf->tlsconf);
        if (!ctx)
            continue;
        server->ssl = SSL_new(ctx);
@@ -245,7 +299,7 @@ void *tlsserverwr(void *arg) {
     int cnt;
     unsigned long error;
     struct client *client = (struct client *)arg;
-    struct queue *replyq;
+    struct gqueue *replyq;
     struct request *reply;
     
     debug(DBG_DBG, "tlsserverwr: starting for %s", addr2string(client->addr));
@@ -324,7 +378,7 @@ void tlsserverrd(struct client *client) {
 void *tlsservernew(void *arg) {
     int s;
     struct sockaddr_storage from;
-    size_t fromlen = sizeof(from);
+    socklen_t fromlen = sizeof(from);
     struct clsrvconf *conf;
     struct list_node *cur = NULL;
     SSL *ssl = NULL;
@@ -340,9 +394,9 @@ void *tlsservernew(void *arg) {
     }
     debug(DBG_WARN, "tlsservernew: incoming TLS connection from %s", addr2string((struct sockaddr *)&from));
 
-    conf = find_clconf(RAD_TLS, (struct sockaddr *)&from, &cur);
+    conf = find_clconf(handle, (struct sockaddr *)&from, &cur);
     if (conf) {
-       ctx = tlsgetctx(RAD_TLS, conf->tlsconf);
+       ctx = tlsgetctx(handle, conf->tlsconf);
        if (!ctx)
            goto exit;
        ssl = SSL_new(ctx);
@@ -374,7 +428,7 @@ void *tlsservernew(void *arg) {
                debug(DBG_WARN, "tlsservernew: failed to create new client instance");
            goto exit;
        }
-       conf = find_clconf(RAD_TLS, (struct sockaddr *)&from, &cur);
+       conf = find_clconf(handle, (struct sockaddr *)&from, &cur);
     }
     debug(DBG_WARN, "tlsservernew: ignoring request, no matching TLS client");
     if (cert)
@@ -395,7 +449,7 @@ void *tlslistener(void *arg) {
     pthread_t tlsserverth;
     int s, *sp = (int *)arg;
     struct sockaddr_storage from;
-    size_t fromlen = sizeof(from);
+    socklen_t fromlen = sizeof(from);
 
     listen(*sp, 0);
 
@@ -416,3 +470,8 @@ void *tlslistener(void *arg) {
     free(sp);
     return NULL;
 }
+#else
+const struct protodefs *tlsinit(uint8_t h) {
+    return NULL;
+}
+#endif