Index: Makefile =================================================================== RCS file: /cvs/src/usr.sbin/identd/Makefile,v retrieving revision 1.3 diff -u -p -r1.3 Makefile --- Makefile 16 Apr 2017 10:16:35 -0000 1.3 +++ Makefile 6 Jul 2017 07:07:52 -0000 @@ -1,8 +1,8 @@ # $OpenBSD: Makefile,v 1.3 2017/04/16 10:16:35 jsg Exp $ +DEBUG=-g PROG= identd -LDADD= -levent -DPADD= ${LIBEVENT} +LDADD= -levl CFLAGS+= -Wall MAN= identd.8 Index: identd.c =================================================================== RCS file: /cvs/src/usr.sbin/identd/identd.c,v retrieving revision 1.38 diff -u -p -r1.38 identd.c --- identd.c 4 Jul 2017 01:09:42 -0000 1.38 +++ identd.c 6 Jul 2017 07:07:52 -0000 @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include @@ -84,8 +84,8 @@ struct ident_client { } client, server; SIMPLEQ_ENTRY(ident_client) entry; enum ident_client_state state; - struct event ev; - struct event tmo; + struct evl_io *ev; + struct evl_tmo *tmo; size_t rxbytes; char *buf; @@ -102,30 +102,31 @@ struct ident_resolver { }; struct identd_listener { - struct event ev, pause; + struct evl_io *ev; + struct evl_tmo *pause; }; -void parent_rd(int, short, void *); -void parent_wr(int, short, void *); +void parent_rd(int, int, void *); +void parent_wr(int, int, void *); int parent_username(struct ident_resolver *, struct passwd *); int parent_uid(struct ident_resolver *, struct passwd *); int parent_token(struct ident_resolver *, struct passwd *); void parent_noident(struct ident_resolver *, struct passwd *); -void child_rd(int, short, void *); -void child_wr(int, short, void *); +void child_rd(int, int, void *); +void child_wr(int, int, void *); void identd_listen(const char *, const char *, int); -void identd_paused(int, short, void *); -void identd_accept(int, short, void *); +void identd_paused(int, int, void *); +void identd_accept(int, int, void *); int identd_error(struct ident_client *, const char *); void identd_close(struct ident_client *); -void identd_timeout(int, short, void *); -void identd_request(int, short, void *); +void identd_timeout(int, int, void *); +void identd_request(int, int, void *); enum ident_client_state identd_parse(struct ident_client *, int); -void identd_resolving(int, short, void *); -void identd_response(int, short, void *); +void identd_resolving(int, int, void *); +void identd_response(int, int, void *); int fetchuid(struct ident_client *); const char *gethost(struct sockaddr_storage *); @@ -199,16 +200,18 @@ usage(void) exit(1); } -struct timeval timeout = { TIMEOUT_DEFAULT, 0 }; +struct timespec timeout = { TIMEOUT_DEFAULT, 0 }; int debug = 0; int noident = 0; int unknown_err = 0; int hideall = 0; +struct evl_base *evl; + int (*parent_uprintf)(struct ident_resolver *, struct passwd *) = parent_username; -struct event proc_rd, proc_wr; +struct evl_io *proc_rd, *proc_wr; union { struct { SIMPLEQ_HEAD(, ident_resolver) replies; @@ -321,7 +324,9 @@ main(int argc, char *argv[]) logger = &syslogger; } - event_init(); + evl = evl_init(); + if (evl == NULL) + lerr(1, "evl init"); if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) lerr(1, "signal(SIGPIPE)"); @@ -332,10 +337,14 @@ main(int argc, char *argv[]) SIMPLEQ_INIT(&sc.parent.replies); - event_set(&proc_rd, sibling, EV_READ | EV_PERSIST, + proc_rd = evl_io_create(evl, sibling, EVL_READ | EVL_PERSIST, parent_rd, NULL); - event_set(&proc_wr, sibling, EV_WRITE, + if (proc_rd == NULL) + lerr(1, "evl io create: parent proc rd"); + proc_wr = evl_io_create(evl, sibling, EVL_WRITE, parent_wr, NULL); + if (proc_wr == NULL) + lerr(1, "evl io create: parent proc wr"); } else { SIMPLEQ_INIT(&sc.child.pushing); SIMPLEQ_INIT(&sc.child.popping); @@ -348,10 +357,14 @@ main(int argc, char *argv[]) if (chdir("/") == -1) lerr(1, "chdir(%s)", pw->pw_dir); - event_set(&proc_rd, sibling, EV_READ | EV_PERSIST, + proc_rd = evl_io_create(evl, sibling, EVL_READ | EVL_PERSIST, child_rd, NULL); - event_set(&proc_wr, sibling, EV_WRITE, + if (proc_rd == NULL) + lerr(1, "evl io create: child proc rd"); + proc_wr = evl_io_create(evl, sibling, EVL_WRITE, child_wr, NULL); + if (proc_wr == NULL) + lerr(1, "evl io create: child proc wr"); } if (setgroups(1, &pw->pw_gid) || @@ -369,13 +382,14 @@ main(int argc, char *argv[]) } } - event_add(&proc_rd, NULL); - event_dispatch(); + evl_io_add(proc_rd); + evl_dispatch(evl); + lwarnx("wat"); return (0); } void -parent_rd(int fd, short events, void *arg) +parent_rd(int fd, int events, void *arg) { struct ident_resolver *r; struct passwd *pw; @@ -427,7 +441,7 @@ parent_rd(int fd, short events, void *ar done: SIMPLEQ_INSERT_TAIL(&sc.parent.replies, r, entry); - event_add(&proc_wr, NULL); + evl_io_add(proc_wr); } int @@ -481,7 +495,7 @@ parent_noident(struct ident_resolver *r, } void -parent_wr(int fd, short events, void *arg) +parent_wr(int fd, int events, void *arg) { struct ident_resolver *r = SIMPLEQ_FIRST(&sc.parent.replies); struct iovec iov[2]; @@ -503,7 +517,7 @@ parent_wr(int fd, short events, void *ar switch (errno) { case EINTR: case EAGAIN: - event_add(&proc_wr, NULL); + evl_io_add(proc_wr); return; default: lerr(1, "parent write"); @@ -521,11 +535,11 @@ parent_wr(int fd, short events, void *ar free(r); if (!SIMPLEQ_EMPTY(&sc.parent.replies)) - event_add(&proc_wr, NULL); + evl_io_add(proc_wr); } void -child_rd(int fd, short events, void *arg) +child_rd(int fd, int events, void *arg) { struct ident_client *c; struct { @@ -593,11 +607,20 @@ child_rd(int fd, short events, void *arg c->buflen = n; - fd = EVENT_FD(&c->ev); - event_del(&c->ev); - event_set(&c->ev, fd, EV_READ | EV_WRITE | EV_PERSIST, + fd = evl_io_fd(c->ev); + evl_io_destroy(c->ev); + c->ev = evl_io_create(evl, fd, EVL_READ | EVL_WRITE | EVL_PERSIST, identd_response, c); - event_add(&c->ev, NULL); + if (c->ev == NULL) { + lwarn("create identd response event"); + evl_tmo_del(c->tmo); + evl_tmo_destroy(c->tmo); + close(fd); + free(c); + return; + } + + evl_io_add(c->ev); return; fail: @@ -605,7 +628,7 @@ fail: } void -child_wr(int fd, short events, void *arg) +child_wr(int fd, int events, void *arg) { struct ident_client *c = SIMPLEQ_FIRST(&sc.child.pushing); const char *errstr = NULL; @@ -617,7 +640,7 @@ child_wr(int fd, short events, void *arg switch (errno) { case EINTR: case EAGAIN: - event_add(&proc_wr, NULL); + evl_io_add(proc_wr); return; case ENOBUFS: /* parent has a backlog of requests */ errstr = "UNKNOWN-ERROR"; @@ -639,7 +662,7 @@ child_wr(int fd, short events, void *arg identd_close(c); if (!SIMPLEQ_EMPTY(&sc.child.pushing)) - event_add(&proc_wr, NULL); + evl_io_add(proc_wr); } void @@ -689,9 +712,15 @@ identd_listen(const char *addr, const ch if (l == NULL) err(1, "listener ev alloc"); - event_set(&l->ev, s, EV_READ | EV_PERSIST, identd_accept, l); - event_add(&l->ev, NULL); - evtimer_set(&l->pause, identd_paused, l); + l->ev = evl_io_create(evl, s, EVL_READ | EVL_PERSIST, + identd_accept, l); + if (l->ev == NULL) + err(1, "listener event creation"); + l->pause = evl_tmo_create(evl, identd_paused, l); + if (l->pause == NULL) + err(1, "listener pause creation"); + + evl_io_add(l->ev); } if (l == NULL) err(1, "%s", cause); @@ -700,18 +729,18 @@ identd_listen(const char *addr, const ch } void -identd_paused(int fd, short events, void *arg) +identd_paused(int fd, int events, void *arg) { struct identd_listener *l = arg; - event_add(&l->ev, NULL); + evl_io_add(l->ev); } void -identd_accept(int fd, short events, void *arg) +identd_accept(int fd, int events, void *arg) { struct identd_listener *l = arg; struct sockaddr_storage ss; - struct timeval pause = { 1, 0 }; + struct timespec pause = { 1, 0 }; struct ident_client *c = NULL; socklen_t len; int s; @@ -726,8 +755,8 @@ identd_accept(int fd, short events, void return; case EMFILE: case ENFILE: - event_del(&l->ev); - evtimer_add(&l->pause, &pause); + evl_io_del(l->ev); + evl_tmo_add(l->pause, &pause); return; default: lerr(1, "accept"); @@ -737,8 +766,7 @@ identd_accept(int fd, short events, void c = calloc(1, sizeof(*c)); if (c == NULL) { lwarn("client alloc"); - close(fd); - return; + goto close; } memcpy(&c->client.ss, &ss, len); @@ -750,19 +778,42 @@ identd_accept(int fd, short events, void if (getsockname(s, sa(&c->server.ss), &c->server.len) == -1) lerr(1, "getsockname"); - event_set(&c->ev, s, EV_READ | EV_PERSIST, identd_request, c); - event_add(&c->ev, NULL); + c->ev = evl_io_create(evl, s, EVL_READ | EVL_PERSIST, + identd_request, c); + if (c->ev == NULL) { + lwarn("connection request"); + goto free; + } + + c->tmo = evl_tmo_create(evl, identd_timeout, c); + if (c->tmo == NULL) { + lwarn("connection timeout"); + goto io_destroy; + } + + evl_io_add(c->ev); + evl_tmo_add(c->tmo, &timeout); - evtimer_set(&c->tmo, identd_timeout, c); - evtimer_add(&c->tmo, &timeout); + return; + +io_destroy: + evl_io_destroy(c->ev); +free: + free(c); +close: + close(fd); } void -identd_timeout(int fd, short events, void *arg) +identd_timeout(int nil, int events, void *arg) { struct ident_client *c = arg; + int fd = evl_io_fd(c->ev); + + evl_io_del(c->ev); - event_del(&c->ev); + evl_tmo_destroy(c->tmo); + evl_io_destroy(c->ev); close(fd); free(c->buf); @@ -773,7 +824,7 @@ identd_timeout(int fd, short events, voi } void -identd_request(int fd, short events, void *arg) +identd_request(int fd, int events, void *arg) { struct ident_client *c = arg; unsigned char buf[64]; @@ -823,11 +874,9 @@ identd_request(int fd, short events, voi SIMPLEQ_INSERT_TAIL(&sc.child.pushing, c, entry); c->state = S_QUEUED; - event_del(&c->ev); - event_set(&c->ev, fd, EV_READ | EV_PERSIST, identd_resolving, c); - event_add(&c->ev, NULL); + evl_io_set(c->ev, identd_resolving); - event_add(&proc_wr, NULL); + evl_io_add(proc_wr); return; error: @@ -843,7 +892,7 @@ fail: int identd_error(struct ident_client *c, const char *errstr) { - int fd = EVENT_FD(&c->ev); + int fd = evl_io_fd(c->ev); ssize_t n; n = asprintf(&c->buf, "%u , %u : ERROR : %s\r\n", @@ -853,10 +902,14 @@ identd_error(struct ident_client *c, con c->buflen = n; - event_del(&c->ev); - event_set(&c->ev, fd, EV_READ | EV_WRITE | EV_PERSIST, + evl_io_del(c->ev); + evl_io_destroy(c->ev); + c->ev = evl_io_create(evl, fd, EVL_READ | EVL_WRITE | EVL_PERSIST, identd_response, c); - event_add(&c->ev, NULL); + if (c->ev == NULL) /* XXX */ + lerr(1, "improperly handled error XXX"); + + evl_io_add(c->ev); return (0); } @@ -864,17 +917,20 @@ identd_error(struct ident_client *c, con void identd_close(struct ident_client *c) { - int fd = EVENT_FD(&c->ev); + int fd = evl_io_fd(c->ev); + + evl_tmo_del(c->tmo); + evl_io_del(c->ev); - evtimer_del(&c->tmo); - event_del(&c->ev); - close(fd); free(c->buf); + evl_tmo_destroy(c->tmo); + evl_io_destroy(c->ev); + close(fd); free(c); } void -identd_resolving(int fd, short events, void *arg) +identd_resolving(int fd, int events, void *arg) { struct ident_client *c = arg; char buf[64]; @@ -910,9 +966,13 @@ identd_resolving(int fd, short events, v return; } - evtimer_del(&c->tmo); - event_del(&c->ev); + evl_tmo_del(c->tmo); + evl_io_del(c->ev); + + evl_tmo_destroy(c->tmo); + evl_io_destroy(c->ev); close(fd); + c->state = S_DEAD; /* on the resolving queue */ } @@ -1001,13 +1061,13 @@ identd_parse(struct ident_client *c, int } void -identd_response(int fd, short events, void *arg) +identd_response(int fd, int events, void *arg) { struct ident_client *c = arg; char buf[64]; ssize_t n; - if (events & EV_READ) { + if (events & EVL_READ) { n = read(fd, buf, sizeof(buf)); switch (n) { case -1: @@ -1035,7 +1095,7 @@ identd_response(int fd, short events, vo } } - if (!(events & EV_WRITE)) + if (!(events & EVL_WRITE)) return; /* try again later */ n = write(fd, c->buf + c->bufoff, c->buflen - c->bufoff);