diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2004-06-21 17:05:44 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2004-06-21 17:05:44 +0000 |
commit | 83e2b5e2dcfbef9059817c203f316a4d3e255098 (patch) | |
tree | e1473d401626dc1d069dfe1ba08af2ee416b2bb2 /libexec | |
parent | e1b3207a2aba3c3da49d8bf06b99e55e648ad67e (diff) |
use getaddr/nameinfo for address resolution. beck, henning ok
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/spamd/grey.c | 29 | ||||
-rw-r--r-- | libexec/spamd/spamd.c | 26 |
2 files changed, 36 insertions, 19 deletions
diff --git a/libexec/spamd/grey.c b/libexec/spamd/grey.c index 426da9bcbc9..c3694aee3f8 100644 --- a/libexec/spamd/grey.c +++ b/libexec/spamd/grey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grey.c,v 1.12 2004/03/13 17:46:15 beck Exp $ */ +/* $OpenBSD: grey.c,v 1.13 2004/06/21 17:05:43 itojun Exp $ */ /* * Copyright (c) 2004 Bob Beck. All rights reserved. @@ -37,6 +37,7 @@ #include <syslog.h> #include <time.h> #include <unistd.h> +#include <netdb.h> #include "grey.h" @@ -149,10 +150,14 @@ freewhiteaddr(void) int addwhiteaddr(char *addr) { - struct in_addr ia; - struct in6_addr ia6; + struct addrinfo hints, *res; - if (inet_pton(AF_INET, addr, &ia) == 1) { + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_DGRAM; /*dummy*/ + hints.ai_protocol = IPPROTO_UDP; /*dummy*/ + hints.ai_flags = AI_NUMERICHOST; + + if (getaddrinfo(addr, NULL, &hints, &res) == 0) { if (whitecount == whitealloc) { char **tmp; @@ -167,9 +172,7 @@ addwhiteaddr(char *addr) if (whitelist[whitecount] == NULL) return(-1); whitecount++; - } else if (inet_pton(AF_INET6, addr, &ia6) == 1) { - /* XXX deal with v6 later */ - return(-1); + freeaddrinfo(res); } else return(-1); return(0); @@ -368,7 +371,12 @@ greyreader(void) char ip[32], from[MAX_MAIL], to[MAX_MAIL], *buf; size_t len; int state; - struct in_addr ia; + struct addrinfo hints, *res; + + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_DGRAM; /*dummy*/ + hints.ai_protocol = IPPROTO_UDP; /*dummy*/ + hints.ai_flags = AI_NUMERICHOST; state = 0; if (grey == NULL) { @@ -389,9 +397,10 @@ greyreader(void) if (strncmp(buf, "IP:", 3) != 0) break; strlcpy(ip, buf+3, sizeof(ip)); - if (inet_pton(AF_INET, ip, &ia) == 1) + if (getaddrinfo(ip, NULL, &hints, &res) == 0) { + freeaddrinfo(res); state = 1; - else + } else state = 0; break; case 1: diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c index 1df9b21f4b4..d2daefb7fae 100644 --- a/libexec/spamd/spamd.c +++ b/libexec/spamd/spamd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spamd.c,v 1.66 2004/04/03 01:37:18 dhartmei Exp $ */ +/* $OpenBSD: spamd.c,v 1.67 2004/06/21 17:05:43 itojun Exp $ */ /* * Copyright (c) 2002 Theo de Raadt. All rights reserved. @@ -55,7 +55,7 @@ struct con { int state; int laststate; int af; - struct sockaddr_in sin; + struct sockaddr_storage ss; void *ia; char addr[32]; char mail[MAX_MAIL], rcpt[MAX_MAIL]; @@ -94,7 +94,7 @@ int append_error_string (struct con *, size_t, char *, int, void *); void build_reply(struct con *); void doreply(struct con *); void setlog(char *, size_t, char *); -void initcon(struct con *, int, struct sockaddr_in *); +void initcon(struct con *, int, struct sockaddr *); void closecon(struct con *); int match(const char *, const char *); void nextstate(struct con *); @@ -528,10 +528,11 @@ setlog(char *p, size_t len, char *f) } void -initcon(struct con *cp, int fd, struct sockaddr_in *sin) +initcon(struct con *cp, int fd, struct sockaddr *sa) { time_t t; char *tmp; + int error; time(&t); free(cp->obuf); @@ -545,12 +546,19 @@ initcon(struct con *cp, int fd, struct sockaddr_in *sin) if (grow_obuf(cp, 0) == NULL) err(1, "malloc"); cp->fd = fd; - memcpy(&cp->sin, sin, sizeof(struct sockaddr_in)); - cp->af = sin->sin_family; - cp->ia = (void *) &cp->sin.sin_addr; + if (sa->sa_len > sizeof(cp->ss)) + errx(1, "sockaddr size"); + if (sa->sa_family != AF_INET) + errx(1, "not supported yet"); + memcpy(&cp->ss, sa, sa->sa_len); + cp->af = sa->sa_family; + cp->ia = &((struct sockaddr_in *)sa)->sin_addr; cp->blacklists = sdl_lookup(blacklists, cp->af, cp->ia); cp->stutter = (greylist && cp->blacklists == NULL) ? 0 : stutter; - strlcpy(cp->addr, inet_ntoa(sin->sin_addr), sizeof(cp->addr)); + error = getnameinfo(sa, sa->sa_len, cp->addr, sizeof(cp->addr), NULL, 0, + NI_NUMERICHOST); + if (error) + errx(1, "%s", gai_strerror(error)); tmp = strdup(ctime(&t)); if (tmp == NULL) err(1, "malloc"); @@ -1194,7 +1202,7 @@ jail: if (i == maxcon) close(s2); else { - initcon(&con[i], s2, &sin); + initcon(&con[i], s2, (struct sockaddr *)&sin); syslog_r(LOG_INFO, &sdata, "%s: connected (%d/%d)%s%s", con[i].addr, clients, blackcount, |