Hi,

To implement multiple tls listen sockets in syslogd, I have to get
rid of the global variable fd_tls first.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.227
diff -u -p -r1.227 syslogd.c
--- usr.sbin/syslogd/syslogd.c  2 Jan 2017 15:58:02 -0000       1.227
+++ usr.sbin/syslogd/syslogd.c  9 Jan 2017 09:30:25 -0000
@@ -272,7 +272,7 @@ size_t      ctl_reply_offset = 0;   /* Number o
 char   *linebuf;
 int     linesize;
 
-int             fd_ctlconn, fd_udp, fd_udp6, fd_tls;
+int             fd_ctlconn, fd_udp, fd_udp6;
 struct event   *ev_ctlaccept, *ev_ctlread, *ev_ctlwrite;
 
 struct peer {
@@ -291,6 +291,8 @@ void         unix_readcb(int, short, void *);
 int     reserve_accept4(int, int, struct event *,
     void (*)(int, short, void *), struct sockaddr *, socklen_t *, int);
 void    tcp_acceptcb(int, short, void *);
+void    tls_acceptcb(int, short, void *);
+void    acceptcb(int, short, void *, int);
 int     octet_counting(struct evbuffer *, char **, int);
 int     non_transparent_framing(struct evbuffer *, char **);
 void    tcp_readcb(struct bufferevent *, void *);
@@ -354,7 +356,7 @@ main(int argc, char *argv[])
        int              ch, i;
        int              lockpipe[2] = { -1, -1}, pair[2], nullfd, fd;
        int              fd_ctlsock, fd_klog, fd_sendsys, *fd_bind, *fd_listen;
-       int             *fd_unix, nbind, nlisten;
+       int              fd_tls, *fd_unix, nbind, nlisten;
        char            **bind_host, **bind_port, **listen_host, **listen_port;
        char            *tls_hostport, *tls_host, *tls_port;
 
@@ -772,7 +774,7 @@ main(int argc, char *argv[])
        for (i = 0; i < nlisten; i++)
                event_set(&ev_listen[i], fd_listen[i], EV_READ|EV_PERSIST,
                    tcp_acceptcb, &ev_listen[i]);
-       event_set(ev_tls, fd_tls, EV_READ|EV_PERSIST, tcp_acceptcb, ev_tls);
+       event_set(ev_tls, fd_tls, EV_READ|EV_PERSIST, tls_acceptcb, ev_tls);
        for (i = 0; i < nunix; i++)
                event_set(&ev_unix[i], fd_unix[i], EV_READ|EV_PERSIST,
                    unix_readcb, &ev_unix[i]);
@@ -1088,6 +1090,18 @@ reserve_accept4(int lfd, int event, stru
 void
 tcp_acceptcb(int lfd, short event, void *arg)
 {
+       acceptcb(lfd, event, arg, 0);
+}
+
+void
+tls_acceptcb(int lfd, short event, void *arg)
+{
+       acceptcb(lfd, event, arg, 1);
+}
+
+void
+acceptcb(int lfd, short event, void *arg, int usetls)
+{
        struct event            *ev = arg;
        struct peer             *p;
        struct sockaddr_storage  ss;
@@ -1132,7 +1146,7 @@ tcp_acceptcb(int lfd, short event, void 
                return;
        }
        p->p_ctx = NULL;
-       if (lfd == fd_tls) {
+       if (usetls) {
                if (tls_accept_socket(server_ctx, &p->p_ctx, fd) < 0) {
                        snprintf(ebuf, sizeof(ebuf), "tls_accept_socket \"%s\"",
                            peername);

Reply via email to