Blob


1 /*
2 * Copyright (c) 2020 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/mman.h>
18 #include <sys/socket.h>
19 #include <sys/stat.h>
21 #include <arpa/inet.h>
22 #include <netinet/in.h>
24 #include <assert.h>
25 #include <err.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <poll.h>
29 #include <signal.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <tls.h>
34 #include <unistd.h>
36 #ifndef __OpenBSD__
37 # define pledge(a, b) 0
38 # define unveil(a, b) 0
39 #endif /* __OpenBSD__ */
41 #ifndef INFTIM
42 # define INFTIM -1
43 #endif /* INFTIM */
45 #define GEMINI_URL_LEN (1024+3) /* URL max len + \r\n + \0 */
47 /* large enough to hold a copy of a gemini URL and still have extra room */
48 #define PATHBUF 2048
50 #define SUCCESS 20
51 #define TEMP_FAILURE 40
52 #define NOT_FOUND 51
53 #define BAD_REQUEST 59
55 #ifndef MAX_USERS
56 #define MAX_USERS 64
57 #endif
59 enum {
60 S_OPEN,
61 S_INITIALIZING,
62 S_SENDING,
63 S_CLOSING,
64 };
66 struct client {
67 struct tls *ctx;
68 int state;
69 int code;
70 const char *meta;
71 int fd, waiting_on_child;
72 pid_t child;
73 char sbuf[1024]; /* static buffer */
74 void *buf, *i; /* mmap buffer */
75 ssize_t len, off; /* mmap/static buffer */
76 int af;
77 struct in_addr addr;
78 };
80 struct etm { /* file extension to mime */
81 const char *mime;
82 const char *ext;
83 } filetypes[] = {
84 {"application/pdf", "pdf"},
86 {"image/gif", "gif"},
87 {"image/jpeg", "jpg"},
88 {"image/jpeg", "jpeg"},
89 {"image/png", "png"},
90 {"image/svg+xml", "svg"},
92 {"text/gemini", "gemini"},
93 {"text/gemini", "gmi"},
94 {"text/markdown", "markdown"},
95 {"text/markdown", "md"},
96 {"text/plain", "txt"},
97 {"text/xml", "xml"},
99 {NULL, NULL}
100 };
102 #define LOG(c, fmt, ...) \
103 do { \
104 char buf[INET_ADDRSTRLEN]; \
105 if (inet_ntop((c)->af, &(c)->addr, buf, sizeof(buf)) == NULL) \
106 err(1, "inet_ntop"); \
107 dprintf(logfd, "[%s] " fmt "\n", buf, __VA_ARGS__); \
108 } while (0)
110 const char *dir;
111 int dirfd, logfd;
112 int cgi;
114 char *url_after_proto(char*);
115 char *url_start_of_request(char*);
116 int url_trim(struct client*, char*);
117 char *adjust_path(char*);
118 int path_isdir(char*);
119 ssize_t filesize(int);
121 int start_reply(struct pollfd*, struct client*, int, const char*);
122 const char *path_ext(const char*);
123 const char *mime(const char*);
124 int open_file(char*, char*, struct pollfd*, struct client*);
125 void start_cgi(const char*, const char*, struct pollfd*, struct client*);
126 void cgi_setpoll_on_child(struct pollfd*, struct client*);
127 void cgi_setpoll_on_client(struct pollfd*, struct client*);
128 void handle_cgi(struct pollfd*, struct client*);
129 void send_file(char*, char*, struct pollfd*, struct client*);
130 void send_dir(char*, struct pollfd*, struct client*);
131 void handle(struct pollfd*, struct client*);
133 void mark_nonblock(int);
134 int make_soket(int);
135 void do_accept(int, struct tls*, struct pollfd*, struct client*);
136 void goodbye(struct pollfd*, struct client*);
137 void loop(struct tls*, int);
139 void usage(const char*);
141 char *
142 url_after_proto(char *url)
144 char *s;
145 const char *proto = "gemini";
146 const char *marker = "://";
147 size_t i;
149 /* a relative URL */
150 if ((s = strstr(url, marker)) == NULL)
151 return url;
153 if (s - strlen(proto) != url)
154 return NULL;
156 for (i = 0; proto[i] != '\0'; ++i)
157 if (url[i] != proto[i])
158 return NULL;
160 /* a valid gemini:// URL */
161 return s + strlen(marker);
164 char *
165 url_start_of_request(char *url)
167 char *s, *t;
169 if ((s = url_after_proto(url)) == NULL)
170 return NULL;
172 if ((t = strstr(s, "/")) == NULL)
173 return s + strlen(s);
174 return t;
177 int
178 url_trim(struct client *c, char *url)
180 const char *e = "\r\n";
181 char *s;
183 if ((s = strstr(url, e)) == NULL)
184 return 0;
185 s[0] = '\0';
186 s[1] = '\0';
188 if (s[2] != '\0') {
189 LOG(c, "%s", "request longer than 1024 bytes\n");
190 return 0;
193 return 1;
196 char *
197 adjust_path(char *path)
199 char *s, *query;
200 size_t len;
202 if ((query = strchr(path, '?')) != NULL) {
203 *query = '\0';
204 query++;
207 /* /.. -> / */
208 len = strlen(path);
209 if (len >= 3) {
210 if (!strcmp(&path[len-3], "/..")) {
211 path[len-2] = '\0';
215 /* if the path is only `..` trim out and exit */
216 if (!strcmp(path, "..")) {
217 path[0] = '\0';
218 return query;
221 /* remove every ../ in the path */
222 while (1) {
223 if ((s = strstr(path, "../")) == NULL)
224 return query;
225 memmove(s, s+3, strlen(s)+1); /* copy also the \0 */
229 int
230 path_isdir(char *path)
232 if (*path == '\0')
233 return 1;
234 return path[strlen(path)-1] == '/';
237 int
238 start_reply(struct pollfd *pfd, struct client *client, int code, const char *reason)
240 char buf[1030] = {0}; /* status + ' ' + max reply len + \r\n\0 */
241 int len;
242 int ret;
244 client->code = code;
245 client->meta = reason;
246 client->state = S_INITIALIZING;
248 len = snprintf(buf, sizeof(buf), "%d %s\r\n", code, reason);
249 assert(len < (int)sizeof(buf));
250 ret = tls_write(client->ctx, buf, len);
251 if (ret == TLS_WANT_POLLIN) {
252 pfd->events = POLLIN;
253 return 0;
256 if (ret == TLS_WANT_POLLOUT) {
257 pfd->events = POLLOUT;
258 return 0;
261 return 1;
264 ssize_t
265 filesize(int fd)
267 ssize_t len;
269 if ((len = lseek(fd, 0, SEEK_END)) == -1)
270 return -1;
271 if (lseek(fd, 0, SEEK_SET) == -1)
272 return -1;
273 return len;
276 const char *
277 path_ext(const char *path)
279 const char *end;
281 end = path + strlen(path)-1; /* the last byte before the NUL */
282 for (; end != path; --end) {
283 if (*end == '.')
284 return end+1;
285 if (*end == '/')
286 break;
289 return NULL;
292 const char *
293 mime(const char *path)
295 const char *ext, *def = "application/octet-stream";
296 struct etm *t;
298 if ((ext = path_ext(path)) == NULL)
299 return def;
301 for (t = filetypes; t->mime != NULL; ++t)
302 if (!strcmp(ext, t->ext))
303 return t->mime;
305 return def;
308 int
309 open_file(char *path, char *query, struct pollfd *fds, struct client *c)
311 char fpath[PATHBUF];
312 struct stat sb;
314 assert(path != NULL);
316 bzero(fpath, sizeof(fpath));
318 if (*path != '.')
319 fpath[0] = '.';
320 strlcat(fpath, path, PATHBUF);
322 if ((c->fd = openat(dirfd, fpath,
323 O_RDONLY | O_NOFOLLOW | O_CLOEXEC)) == -1) {
324 LOG(c, "open failed: %s", fpath);
325 if (!start_reply(fds, c, NOT_FOUND, "not found"))
326 return 0;
327 goodbye(fds, c);
328 return 0;
331 if (fstat(c->fd, &sb) == -1) {
332 LOG(c, "fstat failed for %s", fpath);
333 if (!start_reply(fds, c, TEMP_FAILURE, "internal server error"))
334 return 0;
335 goodbye(fds, c);
336 return 0;
339 if (S_ISDIR(sb.st_mode)) {
340 LOG(c, "%s is a directory, trying %s/index.gmi", fpath, fpath);
341 close(c->fd);
342 c->fd = -1;
343 send_dir(fpath, fds, c);
344 return 0;
347 if (cgi && (sb.st_mode & S_IXUSR)) {
348 start_cgi(fpath, query, fds, c);
349 return 0;
352 if ((c->len = filesize(c->fd)) == -1) {
353 LOG(c, "failed to get file size for %s", fpath);
354 goodbye(fds, c);
355 return 0;
358 if ((c->buf = mmap(NULL, c->len, PROT_READ, MAP_PRIVATE,
359 c->fd, 0)) == MAP_FAILED) {
360 warn("mmap: %s", fpath);
361 goodbye(fds, c);
362 return 0;
364 c->i = c->buf;
366 return start_reply(fds, c, SUCCESS, mime(fpath));
369 void
370 start_cgi(const char *path, const char *query,
371 struct pollfd *fds, struct client *c)
373 pid_t pid;
374 int p[2];
376 if (pipe(p) == -1)
377 goto err;
379 switch (pid = fork()) {
380 case -1:
381 goto err;
383 case 0: { /* child */
384 char *expath;
385 char addr[INET_ADDRSTRLEN];
386 char *argv[] = { NULL, NULL, NULL };
388 /* skip the initial ./ */
389 path += 2;
391 close(p[0]); /* close the read end */
392 if (dup2(p[1], 1) == -1)
393 goto childerr;
395 if (inet_ntop(c->af, &c->addr, addr, sizeof(addr)) == NULL)
396 goto childerr;
398 /* skip the ./ at the start of path*/
399 if (asprintf(&expath, "%s%s", dir, path) == -1)
400 goto childerr;
401 argv[0] = argv[1] = expath;
403 /* fix the env */
404 setenv("SERVER_SOFTWARE", "gmid", 1);
405 /* setenv("SERVER_NAME", "", 1); */
406 /* setenv("GATEWAY_INTERFACE", "CGI/version", 1); */
407 setenv("SERVER_PROTOCOL", "gemini", 1);
408 setenv("SERVER_PORT", "1965", 1);
409 setenv("PATH_INFO", path, 1);
410 setenv("PATH_TRANSLATED", expath, 1);
411 setenv("QUERY_STRING", query ? query : "", 1);
412 setenv("REMOTE_ADDR", addr, 1);
414 execvp(expath, argv);
415 goto childerr;
418 default: /* parent */
419 close(p[1]); /* close the write end */
420 close(c->fd);
421 c->fd = p[0];
422 c->child = pid;
423 mark_nonblock(c->fd);
424 c->state = S_SENDING;
425 handle_cgi(fds, c);
426 return;
429 err:
430 if (!start_reply(fds, c, TEMP_FAILURE, "internal server error"))
431 return;
432 goodbye(fds, c);
433 return;
435 childerr:
436 dprintf(p[1], "%d internal server error\r\n", TEMP_FAILURE);
437 close(p[1]);
439 /* don't call atexit stuff */
440 _exit(1);
443 void
444 cgi_setpoll_on_child(struct pollfd *fds, struct client *c)
446 int fd;
448 if (c->waiting_on_child)
449 return;
450 c->waiting_on_child = 1;
452 fds->events = POLLIN;
454 fd = fds->fd;
455 fds->fd = c->fd;
456 c->fd = fd;
459 void
460 cgi_setpoll_on_client(struct pollfd *fds, struct client *c)
462 int fd;
464 if (!c->waiting_on_child)
465 return;
466 c->waiting_on_child = 0;
468 fd = fds->fd;
469 fds->fd = c->fd;
470 c->fd = fd;
473 void
474 handle_cgi(struct pollfd *fds, struct client *c)
476 ssize_t r;
478 /* ensure c->fd is the child and fds->fd the client */
479 cgi_setpoll_on_client(fds, c);
481 while (1) {
482 if (c->len == 0) {
483 if ((r = read(c->fd, c->sbuf, sizeof(c->sbuf))) == 0)
484 goto end;
485 if (r == -1) {
486 if (errno == EAGAIN || errno == EWOULDBLOCK) {
487 cgi_setpoll_on_child(fds, c);
488 return;
490 goto end;
492 c->len = r;
493 c->off = 0;
496 while (c->len > 0) {
497 switch (r = tls_write(c->ctx, c->sbuf + c->off, c->len)) {
498 case -1:
499 goto end;
501 case TLS_WANT_POLLOUT:
502 fds->events = POLLOUT;
503 return;
505 case TLS_WANT_POLLIN:
506 fds->events = POLLIN;
507 return;
509 default:
510 c->off += r;
511 c->len -= r;
512 break;
517 end:
518 goodbye(fds, c);
521 void
522 send_file(char *path, char *query, struct pollfd *fds, struct client *c)
524 ssize_t ret, len;
526 if (c->fd == -1) {
527 if (!open_file(path, query, fds, c))
528 return;
529 c->state = S_SENDING;
532 len = (c->buf + c->len) - c->i;
534 while (len > 0) {
535 switch (ret = tls_write(c->ctx, c->i, len)) {
536 case -1:
537 LOG(c, "tls_write: %s", tls_error(c->ctx));
538 goodbye(fds, c);
539 return;
541 case TLS_WANT_POLLIN:
542 fds->events = POLLIN;
543 return;
545 case TLS_WANT_POLLOUT:
546 fds->events = POLLOUT;
547 return;
549 default:
550 c->i += ret;
551 len -= ret;
552 break;
556 goodbye(fds, c);
559 void
560 send_dir(char *path, struct pollfd *fds, struct client *client)
562 char fpath[PATHBUF];
563 size_t len;
565 bzero(fpath, PATHBUF);
567 if (path[0] != '.')
568 fpath[0] = '.';
570 /* this cannot fail since sizeof(fpath) > maxlen of path */
571 strlcat(fpath, path, PATHBUF);
572 len = strlen(fpath);
574 /* add a trailing / in case. */
575 if (fpath[len-1] != '/') {
576 fpath[len] = '/';
579 strlcat(fpath, "index.gmi", sizeof(fpath));
581 send_file(fpath, NULL, fds, client);
584 void
585 handle(struct pollfd *fds, struct client *client)
587 char buf[GEMINI_URL_LEN];
588 char *path;
589 char *query;
591 switch (client->state) {
592 case S_OPEN:
593 bzero(buf, GEMINI_URL_LEN);
594 switch (tls_read(client->ctx, buf, sizeof(buf)-1)) {
595 case -1:
596 LOG(client, "tls_read: %s", tls_error(client->ctx));
597 goodbye(fds, client);
598 return;
600 case TLS_WANT_POLLIN:
601 fds->events = POLLIN;
602 return;
604 case TLS_WANT_POLLOUT:
605 fds->events = POLLOUT;
606 return;
609 if (!url_trim(client, buf)) {
610 if (!start_reply(fds, client, BAD_REQUEST, "bad request"))
611 return;
612 goodbye(fds, client);
613 return;
616 if ((path = url_start_of_request(buf)) == NULL) {
617 if (!start_reply(fds, client, BAD_REQUEST, "bad request"))
618 return;
619 goodbye(fds, client);
620 return;
623 query = adjust_path(path);
624 LOG(client, "get %s%s%s", path,
625 query ? "?" : "",
626 query ? query : "");
628 if (path_isdir(path))
629 send_dir(path, fds, client);
630 else
631 send_file(path, query, fds, client);
632 break;
634 case S_INITIALIZING:
635 if (!start_reply(fds, client, client->code, client->meta))
636 return;
638 if (client->code != SUCCESS) {
639 /* we don't need a body */
640 goodbye(fds, client);
641 return;
644 client->state = S_SENDING;
646 /* fallthrough */
648 case S_SENDING:
649 if (client->child != -1)
650 handle_cgi(fds, client);
651 else
652 send_file(NULL, NULL, fds, client);
653 break;
655 case S_CLOSING:
656 goodbye(fds, client);
657 break;
659 default:
660 /* unreachable */
661 abort();
665 void
666 mark_nonblock(int fd)
668 int flags;
670 if ((flags = fcntl(fd, F_GETFL)) == -1)
671 err(1, "fcntl(F_GETFL)");
672 if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
673 err(1, "fcntl(F_SETFL)");
676 int
677 make_socket(int port, int family)
679 int sock, v;
680 struct sockaddr_in addr4;
681 struct sockaddr_in6 addr6;
682 struct sockaddr *addr;
683 socklen_t len;
685 switch (family) {
686 case AF_INET:
687 bzero(&addr4, sizeof(addr4));
688 addr4.sin_family = family;
689 addr4.sin_port = htons(port);
690 addr4.sin_addr.s_addr = INADDR_ANY;
691 addr = (struct sockaddr*)&addr4;
692 len = sizeof(addr4);
693 break;
695 case AF_INET6:
696 bzero(&addr6, sizeof(addr6));
697 addr6.sin6_family = AF_INET6;
698 addr6.sin6_port = htons(port);
699 addr6.sin6_addr = in6addr_any;
700 addr = (struct sockaddr*)&addr6;
701 len = sizeof(addr6);
702 break;
704 default:
705 /* unreachable */
706 abort();
709 if ((sock = socket(family, SOCK_STREAM, 0)) == -1)
710 err(1, "socket");
712 v = 1;
713 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)) == -1)
714 err(1, "setsockopt(SO_REUSEADDR)");
716 v = 1;
717 if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(v)) == -1)
718 err(1, "setsockopt(SO_REUSEPORT)");
720 mark_nonblock(sock);
722 if (bind(sock, addr, len) == -1)
723 err(1, "bind");
725 if (listen(sock, 16) == -1)
726 err(1, "listen");
728 return sock;
731 void
732 do_accept(int sock, struct tls *ctx, struct pollfd *fds, struct client *clients)
734 int i, fd;
735 struct sockaddr_in addr;
736 socklen_t len;
738 len = sizeof(addr);
739 if ((fd = accept(sock, (struct sockaddr*)&addr, &len)) == -1) {
740 if (errno == EWOULDBLOCK)
741 return;
742 err(1, "accept");
745 mark_nonblock(fd);
747 for (i = 0; i < MAX_USERS; ++i) {
748 if (fds[i].fd == -1) {
749 bzero(&clients[i], sizeof(struct client));
750 if (tls_accept_socket(ctx, &clients[i].ctx, fd) == -1)
751 break; /* goodbye fd! */
753 fds[i].fd = fd;
754 fds[i].events = POLLIN;
756 clients[i].state = S_OPEN;
757 clients[i].fd = -1;
758 clients[i].child = -1;
759 clients[i].buf = MAP_FAILED;
760 clients[i].af = AF_INET;
761 clients[i].addr = addr.sin_addr;
763 return;
767 close(fd);
770 void
771 goodbye(struct pollfd *pfd, struct client *c)
773 ssize_t ret;
775 c->state = S_CLOSING;
777 ret = tls_close(c->ctx);
778 if (ret == TLS_WANT_POLLIN) {
779 pfd->events = POLLIN;
780 return;
782 if (ret == TLS_WANT_POLLOUT) {
783 pfd->events = POLLOUT;
784 return;
787 tls_free(c->ctx);
788 c->ctx = NULL;
790 if (c->buf != MAP_FAILED)
791 munmap(c->buf, c->len);
793 if (c->fd != -1)
794 close(c->fd);
796 close(pfd->fd);
797 pfd->fd = -1;
800 void
801 loop(struct tls *ctx, int sock)
803 int i, todo;
804 struct client clients[MAX_USERS];
805 struct pollfd fds[MAX_USERS];
807 for (i = 0; i < MAX_USERS; ++i) {
808 fds[i].fd = -1;
809 fds[i].events = POLLIN;
810 bzero(&clients[i], sizeof(struct client));
813 fds[0].fd = sock;
815 for (;;) {
816 if ((todo = poll(fds, MAX_USERS, INFTIM)) == -1)
817 err(1, "poll");
819 for (i = 0; i < MAX_USERS; i++) {
820 assert(i < MAX_USERS);
822 if (fds[i].revents == 0)
823 continue;
825 if (fds[i].revents & (POLLERR|POLLNVAL))
826 err(1, "bad fd %d", fds[i].fd);
828 if (fds[i].revents & POLLHUP) {
829 /* fds[i] may be the fd of the stdin
830 * of a cgi script that has exited. */
831 if (!clients[i].waiting_on_child) {
832 goodbye(&fds[i], &clients[i]);
833 continue;
837 todo--;
839 if (i == 0) { /* new client */
840 do_accept(sock, ctx, fds, clients);
841 continue;
844 handle(&fds[i], &clients[i]);
849 void
850 usage(const char *me)
852 fprintf(stderr,
853 "USAGE: %s [-h] [-c cert.pem] [-d docs] [-k key.pem]\n",
854 me);
857 int
858 main(int argc, char **argv)
860 const char *cert = "cert.pem", *key = "key.pem";
861 struct tls *ctx = NULL;
862 struct tls_config *conf;
863 int sock, ch;
865 signal(SIGPIPE, SIG_IGN);
866 signal(SIGCHLD, SIG_IGN);
868 dir = "docs/";
869 logfd = 2; /* stderr */
870 cgi = 0;
872 while ((ch = getopt(argc, argv, "c:d:hk:l:x")) != -1) {
873 switch (ch) {
874 case 'c':
875 cert = optarg;
876 break;
878 case 'd':
879 dir = optarg;
880 break;
882 case 'h':
883 usage(*argv);
884 return 0;
886 case 'k':
887 key = optarg;
888 break;
890 case 'l':
891 /* open log file or create it with 644 */
892 if ((logfd = open(optarg, O_WRONLY | O_CREAT | O_CLOEXEC,
893 S_IRUSR | S_IWUSR | S_IRGRP | S_IWOTH)) == -1)
894 err(1, "%s", optarg);
895 break;
897 case 'x':
898 cgi = 1;
899 break;
901 default:
902 usage(*argv);
903 return 1;
907 if ((conf = tls_config_new()) == NULL)
908 err(1, "tls_config_new");
910 if (tls_config_set_protocols(conf,
911 TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3) == -1)
912 err(1, "tls_config_set_protocols");
914 if (tls_config_set_cert_file(conf, cert) == -1)
915 err(1, "tls_config_set_cert_file: %s", cert);
917 if (tls_config_set_key_file(conf, key) == -1)
918 err(1, "tls_config_set_key_file: %s", key);
920 if ((ctx = tls_server()) == NULL)
921 err(1, "tls_server");
923 if (tls_configure(ctx, conf) == -1)
924 errx(1, "tls_configure: %s", tls_error(ctx));
926 sock = make_socket(1965, AF_INET);
928 if ((dirfd = open(dir, O_RDONLY | O_DIRECTORY)) == -1)
929 err(1, "open: %s", dir);
931 if (unveil(dir, cgi ? "rx" : "r") == -1)
932 err(1, "unveil");
934 if (pledge(cgi ? "stdio rpath inet proc exec" : "stdio rpath inet", NULL) == -1)
935 err(1, "pledge");
937 loop(ctx, sock);
939 close(sock);
940 tls_free(ctx);
941 tls_config_free(conf);