Commit de2b1316 authored by Leigh B. Stoller's avatar Leigh B. Stoller

A couple of fixes suggested by Chad, one of which has the potential to

solve the problem with tmcd hanging!
parent c6342a2b
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -58,7 +59,7 @@ static char *clientcertdirs[] = { ...@@ -58,7 +59,7 @@ static char *clientcertdirs[] = {
static SSL *ssl; static SSL *ssl;
static SSL_CTX *ctx; static SSL_CTX *ctx;
static int client = 0; static int client = 0;
static char nosslbuf[MYBUFSIZE]; static char nosslbuf[BUFSIZ];
static int nosslbuflen, nosslbufidx; static int nosslbuflen, nosslbufidx;
static void tmcd_sslerror(); static void tmcd_sslerror();
static void tmcd_sslprint(const char *fmt, ...); static void tmcd_sslprint(const char *fmt, ...);
...@@ -211,18 +212,22 @@ tmcd_sslaccept(int sock, struct sockaddr *addr, socklen_t *addrlen) ...@@ -211,18 +212,22 @@ tmcd_sslaccept(int sock, struct sockaddr *addr, socklen_t *addrlen)
/* /*
* Read the first bit. It indicates whether we need to SSL * Read the first bit. It indicates whether we need to SSL
* handshake or not. * handshake or not. Clear the buffer to avoid confusing
* the last connection with this new connection.
*/ */
if ((cc = read(newsock, nosslbuf, sizeof(nosslbuf) - 1)) <= 0) { bzero(nosslbuf, strlen(SPEAKSSL));
if ((cc = read(newsock, nosslbuf, strlen(SPEAKSSL))) <= 0) {
error("sslaccept: reading request"); error("sslaccept: reading request");
if (cc == 0) if (cc == 0)
errno = EIO; errno = EIO;
goto badauth; goto badauth;
} }
if (strncmp(nosslbuf, SPEAKSSL, strlen(SPEAKSSL))) {
if (strncmp(nosslbuf, SPEAKSSL, cc)) {
/* /*
* No ssl. Need to return this data on the next read. * No ssl. Need to return this data on the next read.
* See below. * See below.
*/ */
isssl = 0; isssl = 0;
nosslbuflen = cc; nosslbuflen = cc;
...@@ -429,22 +434,40 @@ tmcd_sslwrite(int sock, const void *buf, size_t nbytes) ...@@ -429,22 +434,40 @@ tmcd_sslwrite(int sock, const void *buf, size_t nbytes)
} }
/* /*
* Read stuff in. * Read stuff in. The nosslbuf stuff is overly general; the caller behaves
* in a much more constrained manner.
*/ */
int int
tmcd_sslread(int sock, void *buf, size_t nbytes) tmcd_sslread(int sock, void *buf, size_t nbytes)
{ {
int cc = 0; int cc = 0, nosslcount = 0;
/*
* This cruft only happens on the server.
*/
if (nosslbuflen) { if (nosslbuflen) {
char *bp = (char *) buf, *cp = &nosslbuf[nosslbufidx]; nosslcount = (nosslbuflen > nbytes ? nbytes : nosslbuflen);
while (cc < nbytes && nosslbuflen) { memcpy(buf, &nosslbuf[nosslbufidx], nosslcount);
*bp = *cp; nosslbuflen -= nosslcount;
bp++; cp++; cc++; nosslbufidx += nosslcount;
nosslbuflen--; nosslbufidx++;
} if (nosslcount == nbytes)
return cc; return nosslcount;
/*
* The request has to be presented to the caller as a single
* message. Since we read just enough to look for the
* SPEAKSSL tag above, see if there is more, and get it.
*/
if (ioctl(sock, FIONREAD, &cc) < 0)
return -1;
if (cc == 0)
return nosslcount;
nbytes -= nosslcount;
buf = (void *) (((char *) buf) + nosslcount);
} }
errno = 0; errno = 0;
...@@ -459,7 +482,7 @@ tmcd_sslread(int sock, void *buf, size_t nbytes) ...@@ -459,7 +482,7 @@ tmcd_sslread(int sock, void *buf, size_t nbytes)
} }
return cc; return cc;
} }
return cc; return cc + nosslcount;
} }
/* /*
......
...@@ -66,7 +66,7 @@ int mydb_update(char *query, ...); ...@@ -66,7 +66,7 @@ int mydb_update(char *query, ...);
#define MINCHILDREN 5 #define MINCHILDREN 5
static int udpchild; static int udpchild;
static int numchildren; static int numchildren;
static int maxchildren = MINCHILDREN; static int maxchildren = 10;
static volatile int killme; static volatile int killme;
#ifdef EVENTSYS #ifdef EVENTSYS
...@@ -450,7 +450,7 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp) ...@@ -450,7 +450,7 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp)
while (isspace(*bp)) while (isspace(*bp))
bp++; bp++;
/* /*
* Look for VERSION. * Look for VERSION.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment