diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2018-09-05 17:32:57 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2018-09-05 17:32:57 +0000 |
commit | 8746606c45b8fc7be9927fe631cd3c9a74930aa0 (patch) | |
tree | ef2a89241d98127742536c568d11669e3d67247d /usr.sbin/lpd | |
parent | 1774f936b0a0de626710bc738d85222ecf38cd59 (diff) |
synchronize resolver code with smtpd
Diffstat (limited to 'usr.sbin/lpd')
-rw-r--r-- | usr.sbin/lpd/engine.c | 6 | ||||
-rw-r--r-- | usr.sbin/lpd/frontend.c | 8 | ||||
-rw-r--r-- | usr.sbin/lpd/logmsg.c | 14 | ||||
-rw-r--r-- | usr.sbin/lpd/lpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/lpd/resolver.c | 80 |
5 files changed, 63 insertions, 53 deletions
diff --git a/usr.sbin/lpd/engine.c b/usr.sbin/lpd/engine.c index 3fbb53dc510..bab89733a3e 100644 --- a/usr.sbin/lpd/engine.c +++ b/usr.sbin/lpd/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.1 2018/04/27 16:14:35 eric Exp $ */ +/* $OpenBSD: engine.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -148,8 +148,8 @@ engine_dispatch_frontend(struct imsgproc *proc, struct imsg *imsg, void *arg) log_imsg(proc, imsg); switch (imsg->hdr.type) { - case IMSG_RES_GETADDRINFO: - case IMSG_RES_GETNAMEINFO: + case IMSG_GETADDRINFO: + case IMSG_GETNAMEINFO: resolver_dispatch_request(proc, imsg); break; diff --git a/usr.sbin/lpd/frontend.c b/usr.sbin/lpd/frontend.c index b92bba1f0db..bb285b14df4 100644 --- a/usr.sbin/lpd/frontend.c +++ b/usr.sbin/lpd/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.1 2018/04/27 16:14:35 eric Exp $ */ +/* $OpenBSD: frontend.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -313,9 +313,9 @@ frontend_dispatch_engine(struct imsgproc *proc, struct imsg *imsg, void *arg) log_imsg(proc, imsg); switch (imsg->hdr.type) { - case IMSG_RES_GETADDRINFO: - case IMSG_RES_GETADDRINFO_END: - case IMSG_RES_GETNAMEINFO: + case IMSG_GETADDRINFO: + case IMSG_GETADDRINFO_END: + case IMSG_GETNAMEINFO: resolver_dispatch_result(proc, imsg); break; diff --git a/usr.sbin/lpd/logmsg.c b/usr.sbin/lpd/logmsg.c index b928e468084..b2e21c558d1 100644 --- a/usr.sbin/lpd/logmsg.c +++ b/usr.sbin/lpd/logmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: logmsg.c,v 1.1 2018/04/27 16:14:36 eric Exp $ */ +/* $OpenBSD: logmsg.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -57,12 +57,12 @@ log_fmt_imsgtype(int type) return "IMSG_CONF_LISTENER"; case IMSG_CONF_END: return "IMSG_CONF_END"; - case IMSG_RES_GETADDRINFO: - return "IMSG_RES_GETADDRINFO"; - case IMSG_RES_GETADDRINFO_END: - return "IMSG_RES_GETADDRINFO_END"; - case IMSG_RES_GETNAMEINFO: - return "IMSG_RES_GETNAMEINFO"; + case IMSG_GETADDRINFO: + return "IMSG_GETADDRINFO"; + case IMSG_GETADDRINFO_END: + return "IMSG_GETADDRINFO_END"; + case IMSG_GETNAMEINFO: + return "IMSG_GETNAMEINFO"; case IMSG_LPR_ALLOWEDHOST: return "IMSG_LPR_ALLOWEDHOST"; case IMSG_LPR_DISPLAYQ: diff --git a/usr.sbin/lpd/lpd.h b/usr.sbin/lpd/lpd.h index 5a07b379824..f82dd6e643e 100644 --- a/usr.sbin/lpd/lpd.h +++ b/usr.sbin/lpd/lpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lpd.h,v 1.1 2018/04/27 16:14:37 eric Exp $ */ +/* $OpenBSD: lpd.h,v 1.2 2018/09/05 17:32:56 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -51,9 +51,9 @@ enum { IMSG_CONF_LISTENER, IMSG_CONF_END, - IMSG_RES_GETADDRINFO, - IMSG_RES_GETADDRINFO_END, - IMSG_RES_GETNAMEINFO, + IMSG_GETADDRINFO, + IMSG_GETADDRINFO_END, + IMSG_GETNAMEINFO, IMSG_LPR_ALLOWEDHOST, IMSG_LPR_DISPLAYQ, diff --git a/usr.sbin/lpd/resolver.c b/usr.sbin/lpd/resolver.c index 41afad4a07e..adcbb13c3b6 100644 --- a/usr.sbin/lpd/resolver.c +++ b/usr.sbin/lpd/resolver.c @@ -1,7 +1,7 @@ -/* $OpenBSD: resolver.c,v 1.1 2018/04/27 16:14:37 eric Exp $ */ +/* $OpenBSD: resolver.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */ /* - * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> + * Copyright (c) 2017-2018 Eric Faurot <eric@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,13 +18,17 @@ #include <sys/types.h> #include <sys/socket.h> +#include <sys/tree.h> +#include <sys/queue.h> #include <netinet/in.h> #include <asr.h> #include <ctype.h> #include <errno.h> +#include <imsg.h> #include <limits.h> #include <stdarg.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -34,6 +38,8 @@ #include "log.h" #include "proc.h" +#define p_resolver p_engine + struct request { SPLAY_ENTRY(request) entry; uint32_t id; @@ -83,14 +89,14 @@ resolver_getaddrinfo(const char *hostname, const char *servname, SPLAY_INSERT(reqtree, &reqs, req); - m_create(p_engine, IMSG_RES_GETADDRINFO, req->id, 0, -1); - m_add_int(p_engine, hints ? hints->ai_flags : 0); - m_add_int(p_engine, hints ? hints->ai_family : 0); - m_add_int(p_engine, hints ? hints->ai_socktype : 0); - m_add_int(p_engine, hints ? hints->ai_protocol : 0); - m_add_string(p_engine, hostname); - m_add_string(p_engine, servname ? servname : ""); - m_close(p_engine); + m_create(p_resolver, IMSG_GETADDRINFO, req->id, 0, -1); + m_add_int(p_resolver, hints ? hints->ai_flags : 0); + m_add_int(p_resolver, hints ? hints->ai_family : 0); + m_add_int(p_resolver, hints ? hints->ai_socktype : 0); + m_add_int(p_resolver, hints ? hints->ai_protocol : 0); + m_add_string(p_resolver, hostname); + m_add_string(p_resolver, servname ? servname : ""); + m_close(p_resolver); } void @@ -112,10 +118,12 @@ resolver_getnameinfo(const struct sockaddr *sa, int flags, req->cb_ni = cb; req->arg = arg; - m_create(p_engine, IMSG_RES_GETNAMEINFO, req->id, 0, -1); - m_add_sockaddr(p_engine, sa); - m_add_int(p_engine, flags); - m_close(p_engine); + SPLAY_INSERT(reqtree, &reqs, req); + + m_create(p_resolver, IMSG_GETNAMEINFO, req->id, 0, -1); + m_add_sockaddr(p_resolver, sa); + m_add_int(p_resolver, flags); + m_close(p_resolver); } void @@ -134,7 +142,7 @@ resolver_dispatch_request(struct imsgproc *proc, struct imsg *imsg) switch (imsg->hdr.type) { - case IMSG_RES_GETADDRINFO: + case IMSG_GETADDRINFO: servname = NULL; memset(&hints, 0 , sizeof(hints)); m_get_int(proc, &hints.ai_flags); @@ -162,13 +170,13 @@ resolver_dispatch_request(struct imsgproc *proc, struct imsg *imsg) if (s) free(s); - m_create(proc, IMSG_RES_GETADDRINFO_END, reqid, 0, -1); + m_create(proc, IMSG_GETADDRINFO_END, reqid, 0, -1); m_add_int(proc, EAI_SYSTEM); m_add_int(proc, save_errno); m_close(proc); break; - case IMSG_RES_GETNAMEINFO: + case IMSG_GETNAMEINFO: sa = (struct sockaddr*)&ss; m_get_sockaddr(proc, sa); m_get_int(proc, &flags); @@ -196,11 +204,9 @@ resolver_dispatch_request(struct imsgproc *proc, struct imsg *imsg) free(s); } - m_create(proc, IMSG_RES_GETNAMEINFO, reqid, 0, -1); + m_create(proc, IMSG_GETNAMEINFO, reqid, 0, -1); m_add_int(proc, EAI_SYSTEM); m_add_int(proc, save_errno); - m_add_string(proc, ""); - m_add_string(proc, ""); m_close(proc); break; @@ -225,7 +231,7 @@ resolver_dispatch_result(struct imsgproc *proc, struct imsg *imsg) switch (imsg->hdr.type) { - case IMSG_RES_GETADDRINFO: + case IMSG_GETADDRINFO: ai = calloc(1, sizeof(*ai)); if (ai == NULL) { log_warn("%s: calloc", __func__); @@ -262,7 +268,7 @@ resolver_dispatch_result(struct imsgproc *proc, struct imsg *imsg) req->ai = ai; break; - case IMSG_RES_GETADDRINFO_END: + case IMSG_GETADDRINFO_END: m_get_int(proc, &gai_errno); m_get_int(proc, &errno); m_end(proc); @@ -272,16 +278,18 @@ resolver_dispatch_result(struct imsgproc *proc, struct imsg *imsg) free(req); break; - case IMSG_RES_GETNAMEINFO: + case IMSG_GETNAMEINFO: m_get_int(proc, &gai_errno); m_get_int(proc, &errno); - m_get_string(proc, &host); - m_get_string(proc, &serv); + if (gai_errno == 0) { + m_get_string(proc, &host); + m_get_string(proc, &serv); + } m_end(proc); SPLAY_REMOVE(reqtree, &reqs, req); - req->cb_ni(req->arg, gai_errno, host[0] ? host : NULL, - serv[0] ? serv : NULL); + req->cb_ni(req->arg, gai_errno, gai_errno ? NULL : host, + gai_errno ? NULL : serv); free(req); break; } @@ -305,7 +313,7 @@ resolver_getaddrinfo_cb(struct asr_result *ar, void *arg) struct addrinfo *ai; for (ai = ar->ar_addrinfo; ai; ai = ai->ai_next) { - m_create(s->proc, IMSG_RES_GETADDRINFO, s->reqid, 0, -1); + m_create(s->proc, IMSG_GETADDRINFO, s->reqid, 0, -1); m_add_int(s->proc, ai->ai_flags); m_add_int(s->proc, ai->ai_family); m_add_int(s->proc, ai->ai_socktype); @@ -316,7 +324,7 @@ resolver_getaddrinfo_cb(struct asr_result *ar, void *arg) m_close(s->proc); } - m_create(s->proc, IMSG_RES_GETADDRINFO_END, s->reqid, 0, -1); + m_create(s->proc, IMSG_GETADDRINFO_END, s->reqid, 0, -1); m_add_int(s->proc, ar->ar_gai_errno); m_add_int(s->proc, ar->ar_errno); m_close(s->proc); @@ -330,11 +338,13 @@ resolver_getnameinfo_cb(struct asr_result *ar, void *arg) { struct session *s = arg; - m_create(s->proc, IMSG_RES_GETNAMEINFO, s->reqid, 0, -1); + m_create(s->proc, IMSG_GETNAMEINFO, s->reqid, 0, -1); m_add_int(s->proc, ar->ar_gai_errno); m_add_int(s->proc, ar->ar_errno); - m_add_string(s->proc, s->host ? s->host : ""); - m_add_string(s->proc, s->serv ? s->serv : ""); + if (ar->ar_gai_errno == 0) { + m_add_string(s->proc, s->host); + m_add_string(s->proc, s->serv); + } m_close(s->proc); free(s->host); @@ -346,10 +356,10 @@ static int request_cmp(struct request *a, struct request *b) { if (a->id < b->id) - return (-1); + return -1; if (a->id > b->id) - return (1); - return (0); + return 1; + return 0; } SPLAY_GENERATE(reqtree, request, entry, request_cmp); |