lib: Added the bufdel macro.
[ashd.git] / src / ssl-gnutls.c
CommitLineData
6ca53b2e
FT
1/*
2 ashd - A Sane HTTP Daemon
3 Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <stdlib.h>
20#include <unistd.h>
21#include <string.h>
22#include <fcntl.h>
26902200 23#include <dirent.h>
6ca53b2e
FT
24#include <sys/socket.h>
25#include <netinet/in.h>
26#include <arpa/inet.h>
27#include <errno.h>
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32#include <utils.h>
33#include <mt.h>
34#include <mtio.h>
35#include <req.h>
36#include <log.h>
37
38#include "htparser.h"
39
40#ifdef HAVE_GNUTLS
41
42#include <gnutls/gnutls.h>
28b2e619
FT
43#include <gnutls/x509.h>
44
45struct namedcreds {
46 char **names;
47 gnutls_certificate_credentials_t creds;
48};
49
50struct ncredbuf {
51 struct namedcreds **b;
52 size_t s, d;
53};
6ca53b2e
FT
54
55struct sslport {
56 int fd;
57 int sport;
58 gnutls_certificate_credentials_t creds;
28b2e619 59 struct namedcreds **ncreds;
6ca53b2e
FT
60};
61
62struct sslconn {
63 int fd;
64 struct sslport *port;
65 struct sockaddr_storage name;
66 gnutls_session_t sess;
67 struct charbuf in;
68};
69
d8d4ed57
FT
70struct savedsess {
71 struct savedsess *next, *prev;
72 gnutls_datum_t key, value;
73};
74
75static int numconn = 0, numsess = 0;
76static struct btree *sessidx = NULL;
77static struct savedsess *sesslistf = NULL, *sesslistl = NULL;
78
79static int sesscmp(void *ap, void *bp)
80{
81 struct savedsess *a = ap, *b = bp;
82
83 if(a->key.size != b->key.size)
84 return(a->key.size - b->key.size);
85 return(memcmp(a->key.data, b->key.data, a->key.size));
86}
87
88static gnutls_datum_t sessdbfetch(void *uudata, gnutls_datum_t key)
89{
90 struct savedsess *sess, lkey;
91 gnutls_datum_t ret;
92
93 memset(&ret, 0, sizeof(ret));
94 lkey.key = key;
95 if((sess = btreeget(sessidx, &lkey, sesscmp)) == NULL)
96 return(ret);
97 ret.data = memcpy(gnutls_malloc(ret.size = sess->value.size), sess->value.data, sess->value.size);
98 return(ret);
99}
100
101static void freesess(struct savedsess *sess)
102{
103 bbtreedel(&sessidx, sess, sesscmp);
104 if(sess->next)
105 sess->next->prev = sess->prev;
106 if(sess->prev)
107 sess->prev->next = sess->next;
108 if(sess == sesslistf)
109 sesslistf = sess->next;
110 if(sess == sesslistl)
111 sesslistl = sess->prev;
112 free(sess->key.data);
113 free(sess->value.data);
114 free(sess);
115 numsess--;
116}
117
118static int sessdbdel(void *uudata, gnutls_datum_t key)
119{
120 struct savedsess *sess, lkey;
121
122 lkey.key = key;
123 if((sess = btreeget(sessidx, &lkey, sesscmp)) == NULL)
124 return(-1);
125 freesess(sess);
126 return(0);
127}
128
129static void cleansess(void)
130{
131 while(numsess > (max(numconn, 1) * 100))
132 freesess(sesslistl);
133}
134
135static int sessdbstore(void *uudata, gnutls_datum_t key, gnutls_datum_t value)
136{
137 static int cc = 0;
138 struct savedsess *sess, lkey;
139
140 if((value.data == NULL) || (value.size == 0)) {
141 sessdbdel(NULL, key);
142 return(0);
143 }
144 lkey.key = key;
145 if((sess = btreeget(sessidx, &lkey, sesscmp)) == NULL) {
146 omalloc(sess);
147 sess->key.data = memcpy(smalloc(sess->key.size = key.size), key.data, key.size);
148 sess->value.data = memcpy(smalloc(sess->value.size = value.size), value.data, value.size);
149 bbtreeput(&sessidx, sess, sesscmp);
150 sess->prev = NULL;
151 sess->next = sesslistf;
152 if(sesslistf)
153 sesslistf->prev = sess;
154 sesslistf = sess;
155 if(sesslistl == NULL)
156 sesslistl = sess;
157 numsess++;
158 } else {
159 free(sess->value.data);
160 sess->value.data = memcpy(smalloc(sess->value.size = value.size), value.data, value.size);
161 if(sess != sesslistf) {
162 if(sess->next)
163 sess->next->prev = sess->prev;
164 if(sess->prev)
165 sess->prev->next = sess->next;
166 if(sess == sesslistl)
167 sesslistl = sess->prev;
168 sess->prev = NULL;
169 sess->next = sesslistf;
170 if(sesslistf)
171 sesslistf->prev = sess;
172 sesslistf = sess;
173 }
174 }
175 if(cc++ > 100) {
176 cleansess();
177 cc = 0;
178 }
179 return(0);
180}
181
6ca53b2e
FT
182static int tlsblock(int fd, gnutls_session_t sess, time_t to)
183{
184 if(gnutls_record_get_direction(sess))
185 return(block(fd, EV_WRITE, to));
186 else
187 return(block(fd, EV_READ, to));
188}
189
190static ssize_t sslread(void *cookie, char *buf, size_t len)
191{
192 struct sslconn *ssl = cookie;
193 ssize_t xf;
194 int ret;
195
196 while(ssl->in.d == 0) {
197 sizebuf(ssl->in, ssl->in.d + 1024);
198 ret = gnutls_record_recv(ssl->sess, ssl->in.b + ssl->in.d, ssl->in.s - ssl->in.d);
199 if((ret == GNUTLS_E_INTERRUPTED) || (ret == GNUTLS_E_AGAIN)) {
200 if(tlsblock(ssl->fd, ssl->sess, 60) == 0) {
201 errno = ETIMEDOUT;
202 return(-1);
203 }
204 } else if(ret < 0) {
205 errno = EIO;
206 return(-1);
207 } else if(ret == 0) {
208 return(0);
209 } else {
210 ssl->in.d += ret;
211 }
212 }
213 xf = min(ssl->in.d, len);
214 memcpy(buf, ssl->in.b, xf);
215 memmove(ssl->in.b, ssl->in.b + xf, ssl->in.d -= xf);
216 return(xf);
217}
218
219static ssize_t sslwrite(void *cookie, const char *buf, size_t len)
220{
221 struct sslconn *ssl = cookie;
222 int ret;
223 size_t off;
224
225 off = 0;
226 while(off < len) {
227 ret = gnutls_record_send(ssl->sess, buf + off, len - off);
228 if((ret == GNUTLS_E_INTERRUPTED) || (ret == GNUTLS_E_AGAIN)) {
229 if(tlsblock(ssl->fd, ssl->sess, 60) == 0) {
230 if(off == 0) {
231 errno = ETIMEDOUT;
232 return(-1);
233 }
234 return(off);
235 }
236 } else if(ret < 0) {
237 if(off == 0) {
238 errno = EIO;
239 return(-1);
240 }
241 return(off);
242 } else {
243 off += ret;
244 }
245 }
246 return(off);
247}
248
249static int sslclose(void *cookie)
250{
5ba5dd0b
FT
251 struct sslconn *ssl = cookie;
252
253 buffree(ssl->in);
6ca53b2e
FT
254 return(0);
255}
256
257static cookie_io_functions_t iofuns = {
258 .read = sslread,
259 .write = sslwrite,
260 .close = sslclose,
261};
262
263static int initreq(struct conn *conn, struct hthead *req)
264{
265 struct sslconn *ssl = conn->pdata;
6b84641a
FT
266 struct sockaddr_storage sa;
267 socklen_t salen;
6ca53b2e
FT
268 char nmbuf[256];
269
7595e3a4 270 headappheader(req, "X-Ash-Address", formathaddress((struct sockaddr *)&ssl->name, sizeof(sa)));
6ca53b2e
FT
271 if(ssl->name.ss_family == AF_INET) {
272 headappheader(req, "X-Ash-Address", inet_ntop(AF_INET, &((struct sockaddr_in *)&ssl->name)->sin_addr, nmbuf, sizeof(nmbuf)));
273 headappheader(req, "X-Ash-Port", sprintf3("%i", ntohs(((struct sockaddr_in *)&ssl->name)->sin_port)));
274 } else if(ssl->name.ss_family == AF_INET6) {
275 headappheader(req, "X-Ash-Address", inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&ssl->name)->sin6_addr, nmbuf, sizeof(nmbuf)));
276 headappheader(req, "X-Ash-Port", sprintf3("%i", ntohs(((struct sockaddr_in6 *)&ssl->name)->sin6_port)));
277 }
6b84641a 278 salen = sizeof(sa);
7595e3a4
FT
279 if(!getsockname(ssl->fd, (struct sockaddr *)&sa, &salen))
280 headappheader(req, "X-Ash-Server-Address", formathaddress((struct sockaddr *)&sa, sizeof(sa)));
6ca53b2e
FT
281 headappheader(req, "X-Ash-Server-Port", sprintf3("%i", ssl->port->sport));
282 headappheader(req, "X-Ash-Protocol", "https");
283 return(0);
284}
285
286static void servessl(struct muth *muth, va_list args)
287{
288 vavar(int, fd);
289 vavar(struct sockaddr_storage, name);
290 vavar(struct sslport *, pd);
291 struct conn conn;
292 struct sslconn ssl;
293 gnutls_session_t sess;
294 int ret;
295 FILE *in;
296
1b77e192
FT
297 int setcreds(gnutls_session_t sess)
298 {
28b2e619 299 int i, o, u;
1b77e192
FT
300 unsigned int ntype;
301 char nambuf[256];
302 size_t namlen;
303
304 for(i = 0; 1; i++) {
305 namlen = sizeof(nambuf);
306 if(gnutls_server_name_get(sess, nambuf, &namlen, &ntype, i) != 0)
307 break;
308 if(ntype != GNUTLS_NAME_DNS)
309 continue;
28b2e619
FT
310 for(o = 0; pd->ncreds[o] != NULL; o++) {
311 for(u = 0; pd->ncreds[o]->names[u] != NULL; u++) {
312 if(!strcmp(pd->ncreds[o]->names[u], nambuf)) {
313 gnutls_credentials_set(sess, GNUTLS_CRD_CERTIFICATE, pd->ncreds[o]->creds);
314 gnutls_certificate_server_set_request(sess, GNUTLS_CERT_REQUEST);
315 return(0);
316 }
317 }
318 }
1b77e192
FT
319 }
320 gnutls_credentials_set(sess, GNUTLS_CRD_CERTIFICATE, pd->creds);
321 gnutls_certificate_server_set_request(sess, GNUTLS_CERT_REQUEST);
322 return(0);
323 }
324
d8d4ed57 325 numconn++;
6ca53b2e
FT
326 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
327 gnutls_init(&sess, GNUTLS_SERVER);
328 gnutls_set_default_priority(sess);
d8d4ed57
FT
329 gnutls_db_set_retrieve_function(sess, sessdbfetch);
330 gnutls_db_set_store_function(sess, sessdbstore);
331 gnutls_db_set_remove_function(sess, sessdbdel);
332 gnutls_db_set_ptr(sess, NULL);
1b77e192 333 gnutls_handshake_set_post_client_hello_function(sess, setcreds);
6ca53b2e
FT
334 gnutls_transport_set_ptr(sess, (gnutls_transport_ptr_t)(intptr_t)fd);
335 while((ret = gnutls_handshake(sess)) != 0) {
336 if((ret != GNUTLS_E_INTERRUPTED) && (ret != GNUTLS_E_AGAIN))
337 goto out;
338 if(tlsblock(fd, sess, 60) <= 0)
339 goto out;
340 }
341 memset(&conn, 0, sizeof(conn));
342 memset(&ssl, 0, sizeof(ssl));
343 conn.pdata = &ssl;
344 conn.initreq = initreq;
345 ssl.fd = fd;
346 ssl.port = pd;
347 ssl.name = name;
348 ssl.sess = sess;
349 bufinit(ssl.in);
350 in = fopencookie(&ssl, "r+", iofuns);
351 serve(in, &conn);
352
353out:
354 gnutls_deinit(sess);
355 close(fd);
d8d4ed57 356 numconn--;
6ca53b2e
FT
357}
358
359static void listenloop(struct muth *muth, va_list args)
360{
361 vavar(struct sslport *, pd);
362 int ns;
363 struct sockaddr_storage name;
364 socklen_t namelen;
365
366 while(1) {
367 namelen = sizeof(name);
cac13158
FT
368 if(block(pd->fd, EV_READ, 0) == 0)
369 goto out;
6ca53b2e
FT
370 ns = accept(pd->fd, (struct sockaddr *)&name, &namelen);
371 if(ns < 0) {
372 flog(LOG_ERR, "accept: %s", strerror(errno));
373 goto out;
374 }
375 mustart(servessl, ns, name, pd);
376 }
377
378out:
379 close(pd->fd);
380 free(pd);
381}
382
2daf4411
FT
383static gnutls_dh_params_t dhparams(void)
384{
385 static int inited = 0;
386 static gnutls_dh_params_t pars;
387 int ret;
388
389 if(!inited) {
390 if(((ret = gnutls_dh_params_init(&pars)) != 0) ||
391 ((ret = gnutls_dh_params_generate2(pars, 2048)) != 0)) {
392 flog(LOG_ERR, "GnuTLS could not generate Diffie-Hellman parameters: %s", gnutls_strerror(ret));
393 exit(1);
394 }
395 inited = 1;
396 }
397 return(pars);
398}
399
6ca53b2e
FT
400static void init(void)
401{
402 static int inited = 0;
403 int ret;
404
405 if(inited)
406 return;
407 inited = 1;
408 if((ret = gnutls_global_init()) != 0) {
409 flog(LOG_ERR, "could not initialize GnuTLS: %s", gnutls_strerror(ret));
410 exit(1);
411 }
6ca53b2e
FT
412}
413
28b2e619
FT
414static struct namedcreds *readncreds(char *file)
415{
416 int i, fd, ret;
417 struct namedcreds *nc;
418 gnutls_x509_crt_t crt;
419 gnutls_x509_privkey_t key;
420 char cn[1024];
421 size_t cnl;
422 gnutls_datum_t d;
423 struct charbuf keybuf;
424 struct charvbuf names;
425 unsigned int type;
426
427 bufinit(keybuf);
428 bufinit(names);
429 if((fd = open(file, O_RDONLY)) < 0) {
430 flog(LOG_ERR, "ssl: %s: %s", file, strerror(errno));
431 exit(1);
432 }
433 while(1) {
434 sizebuf(keybuf, keybuf.d + 1024);
435 ret = read(fd, keybuf.b + keybuf.d, keybuf.s - keybuf.d);
436 if(ret < 0) {
437 flog(LOG_ERR, "ssl: reading from %s: %s", file, strerror(errno));
438 exit(1);
439 } else if(ret == 0) {
440 break;
441 }
442 keybuf.d += ret;
443 }
444 close(fd);
445 d.data = (unsigned char *)keybuf.b;
446 d.size = keybuf.d;
447 gnutls_x509_crt_init(&crt);
448 if((ret = gnutls_x509_crt_import(crt, &d, GNUTLS_X509_FMT_PEM)) != 0) {
449 flog(LOG_ERR, "ssl: could not load certificate from %s: %s", file, gnutls_strerror(ret));
450 exit(1);
451 }
452 cnl = sizeof(cn) - 1;
453 if((ret = gnutls_x509_crt_get_dn_by_oid(crt, GNUTLS_OID_X520_COMMON_NAME, 0, 0, cn, &cnl)) != 0) {
454 flog(LOG_ERR, "ssl: could not read common name from %s: %s", file, gnutls_strerror(ret));
455 exit(1);
456 }
457 cn[cnl] = 0;
458 bufadd(names, sstrdup(cn));
459 for(i = 0; 1; i++) {
460 cnl = sizeof(cn) - 1;
461 if(gnutls_x509_crt_get_subject_alt_name2(crt, i, cn, &cnl, &type, NULL) < 0)
462 break;
463 cn[cnl] = 0;
464 if(type == GNUTLS_SAN_DNSNAME)
465 bufadd(names, sstrdup(cn));
466 }
467 gnutls_x509_privkey_init(&key);
468 if((ret = gnutls_x509_privkey_import(key, &d, GNUTLS_X509_FMT_PEM)) != 0) {
469 flog(LOG_ERR, "ssl: could not load key from %s: %s", file, gnutls_strerror(ret));
470 exit(1);
471 }
472 buffree(keybuf);
473 bufadd(names, NULL);
474 omalloc(nc);
475 nc->names = names.b;
476 gnutls_certificate_allocate_credentials(&nc->creds);
477 if((ret = gnutls_certificate_set_x509_key(nc->creds, &crt, 1, key)) != 0) {
478 flog(LOG_ERR, "ssl: could not use certificate from %s: %s", file, gnutls_strerror(ret));
479 exit(1);
480 }
2daf4411 481 gnutls_certificate_set_dh_params(nc->creds, dhparams());
28b2e619
FT
482 return(nc);
483}
484
26902200
FT
485static void readncdir(struct ncredbuf *buf, char *dir)
486{
487 DIR *d;
488 struct dirent *e;
489 size_t es;
490
491 if((d = opendir(dir)) == NULL) {
492 flog(LOG_ERR, "ssl: could not read certificate directory %s: %s", dir, strerror(errno));
493 exit(1);
494 }
495 while((e = readdir(d)) != NULL) {
496 if(e->d_name[0] == '.')
497 continue;
498 if((es = strlen(e->d_name)) <= 4)
499 continue;
500 if(strcmp(e->d_name + es - 4, ".crt"))
501 continue;
502 bufadd(*buf, readncreds(sprintf3("%s/%s", dir, e->d_name)));
503 }
504 closedir(d);
505}
506
6ca53b2e
FT
507void handlegnussl(int argc, char **argp, char **argv)
508{
509 int i, ret, port, fd;
510 gnutls_certificate_credentials_t creds;
28b2e619 511 struct ncredbuf ncreds;
6ca53b2e
FT
512 struct sslport *pd;
513 char *crtfile, *keyfile;
514
515 init();
516 port = 443;
28b2e619 517 bufinit(ncreds);
6ca53b2e
FT
518 gnutls_certificate_allocate_credentials(&creds);
519 keyfile = crtfile = NULL;
520 for(i = 0; i < argc; i++) {
521 if(!strcmp(argp[i], "help")) {
522 printf("ssl handler parameters:\n");
523 printf("\tcert=CERT-FILE [mandatory]\n");
524 printf("\t\tThe name of the file to read the certificate from.\n");
525 printf("\tkey=KEY-FILE [same as CERT-FILE]\n");
526 printf("\t\tThe name of the file to read the private key from.\n");
527 printf("\ttrust=CA-FILE [no default]\n");
528 printf("\t\tThe name of a file to read trusted certificates from.\n");
529 printf("\t\tMay be given multiple times.\n");
530 printf("\tcrl=CRL-FILE [no default]\n");
531 printf("\t\tThe name of a file to read revocation lists from.\n");
532 printf("\t\tMay be given multiple times.\n");
4094af22
FT
533 printf("\tncert=CERT-FILE [no default]\n");
534 printf("\t\tThe name of a file to read a named certificate from,\n");
535 printf("\t\tfor use with SNI-enabled clients.\n");
536 printf("\t\tMay be given multiple times.\n");
537 printf("\tncertdir=DIR [no default]\n");
538 printf("\t\tRead all *.crt files in the given directory as if they\n");
539 printf("\t\twere given with `ncert' options.\n");
540 printf("\t\tMay be given multiple times.\n");
6ca53b2e
FT
541 printf("\tport=PORT [443]\n");
542 printf("\t\tThe TCP port to listen on.\n");
543 printf("\n");
544 printf("\tAll X.509 data files must be PEM-encoded.\n");
4094af22
FT
545 printf("\tIf any certificates were given with `ncert' options, they will be\n");
546 printf("\tused if a client explicitly names one of them with a\n");
547 printf("\tserver-name indication. If a client indicates no server name,\n");
548 printf("\tor if a server-name indication does not match any given\n");
549 printf("\tcertificate, the certificate given with the `cert' option will\n");
550 printf("\tbe used instead.\n");
6ca53b2e
FT
551 exit(0);
552 } else if(!strcmp(argp[i], "cert")) {
553 crtfile = argv[i];
554 } else if(!strcmp(argp[i], "key")) {
555 keyfile = argv[i];
556 } else if(!strcmp(argp[i], "trust")) {
557 if((ret = gnutls_certificate_set_x509_trust_file(creds, argv[i], GNUTLS_X509_FMT_PEM)) != 0) {
558 flog(LOG_ERR, "ssl: could not load trust file `%s': %s", argv[i], gnutls_strerror(ret));
559 exit(1);
560 }
28b2e619
FT
561 for(i = 0; i < ncreds.d; i++) {
562 if((ret = gnutls_certificate_set_x509_trust_file(ncreds.b[i]->creds, argv[i], GNUTLS_X509_FMT_PEM)) != 0) {
563 flog(LOG_ERR, "ssl: could not load trust file `%s': %s", argv[i], gnutls_strerror(ret));
564 exit(1);
565 }
566 }
6ca53b2e
FT
567 } else if(!strcmp(argp[i], "crl")) {
568 if((ret = gnutls_certificate_set_x509_crl_file(creds, argv[i], GNUTLS_X509_FMT_PEM)) != 0) {
569 flog(LOG_ERR, "ssl: could not load CRL file `%s': %s", argv[i], gnutls_strerror(ret));
570 exit(1);
571 }
28b2e619
FT
572 for(i = 0; i < ncreds.d; i++) {
573 if((ret = gnutls_certificate_set_x509_crl_file(ncreds.b[i]->creds, argv[i], GNUTLS_X509_FMT_PEM)) != 0) {
574 flog(LOG_ERR, "ssl: could not load CRL file `%s': %s", argv[i], gnutls_strerror(ret));
575 exit(1);
576 }
577 }
6ca53b2e
FT
578 } else if(!strcmp(argp[i], "port")) {
579 port = atoi(argv[i]);
28b2e619
FT
580 } else if(!strcmp(argp[i], "ncert")) {
581 bufadd(ncreds, readncreds(argv[i]));
26902200
FT
582 } else if(!strcmp(argp[i], "ncertdir")) {
583 readncdir(&ncreds, argv[i]);
6ca53b2e
FT
584 } else {
585 flog(LOG_ERR, "unknown parameter `%s' to ssl handler", argp[i]);
586 exit(1);
587 }
588 }
589 if(crtfile == NULL) {
590 flog(LOG_ERR, "ssl: needs certificate file at the very least");
591 exit(1);
592 }
2daf4411
FT
593 if((fd = listensock6(port)) < 0) {
594 flog(LOG_ERR, "could not listen on IPv6 port (port %i): %s", port, strerror(errno));
595 exit(1);
596 }
6ca53b2e
FT
597 if(keyfile == NULL)
598 keyfile = crtfile;
599 if((ret = gnutls_certificate_set_x509_key_file(creds, crtfile, keyfile, GNUTLS_X509_FMT_PEM)) != 0) {
600 flog(LOG_ERR, "ssl: could not load certificate or key: %s", gnutls_strerror(ret));
601 exit(1);
602 }
2daf4411 603 gnutls_certificate_set_dh_params(creds, dhparams());
28b2e619 604 bufadd(ncreds, NULL);
6ca53b2e
FT
605 omalloc(pd);
606 pd->fd = fd;
607 pd->sport = port;
608 pd->creds = creds;
28b2e619 609 pd->ncreds = ncreds.b;
cac13158 610 bufadd(listeners, mustart(listenloop, pd));
aa06d1b3 611 if((fd = listensock4(port)) < 0) {
6ca53b2e 612 if(errno != EADDRINUSE) {
aa06d1b3 613 flog(LOG_ERR, "could not listen on IPv4 port (port %i): %s", port, strerror(errno));
6ca53b2e
FT
614 exit(1);
615 }
616 } else {
617 omalloc(pd);
618 pd->fd = fd;
619 pd->sport = port;
620 pd->creds = creds;
cac13158 621 bufadd(listeners, mustart(listenloop, pd));
6ca53b2e
FT
622 }
623}
624
625#endif