summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-04-28 22:38:23 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-04-28 22:38:23 +0000
commit01edd61facb96cf511fecaf6372cb462a0db6f3c (patch)
tree8735447874f694f5e149e73008e674b96d5cd08c /usr.sbin
parentf3690a488e4eeecf898f71fbe8a8238c7998997b (diff)
fix a bug where client with unresolvable revdns is never greeted; ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/lka.c56
-rw-r--r--usr.sbin/smtpd/smtp.c5
2 files changed, 32 insertions, 29 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 4a7c3ddf6b0..7ad7fd6519a 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.41 2009/04/21 14:37:32 eric Exp $ */
+/* $OpenBSD: lka.c,v 1.42 2009/04/28 22:38:22 jacekm Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -69,6 +69,7 @@ int lka_expand_rcpt_iteration(struct smtpd *, struct aliaseslist *, struct lkas
void lka_rcpt_action(struct smtpd *, struct path *);
void lka_clear_aliaseslist(struct aliaseslist *);
int lka_encode_credentials(char *, char *);
+void lka_dns_reverse(struct session *s);
void
lka_sig_handler(int sig, short event, void *p)
@@ -570,32 +571,11 @@ lka_dispatch_smtp(int sig, short event, void *p)
break;
switch (imsg.hdr.type) {
- case IMSG_LKA_HOST: {
- struct sockaddr *sa;
- char addr[NI_MAXHOST];
- struct addrinfo hints, *res;
- struct session *s;
-
- s = imsg.data;
- sa = (struct sockaddr *)&s->s_ss;
- if (getnameinfo(sa, sa->sa_len, addr, sizeof(addr),
- NULL, 0, NI_NAMEREQD))
- break;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_flags = AI_NUMERICHOST;
- if (getaddrinfo(addr, NULL, &hints, &res) == 0) {
- /* Malicious PTR record. */
- freeaddrinfo(res);
- break;
- }
-
- strlcpy(s->s_hostname, addr, sizeof(s->s_hostname));
- imsg_compose(ibuf, IMSG_LKA_HOST, 0, 0, -1, s,
+ case IMSG_LKA_HOST:
+ lka_dns_reverse(imsg.data);
+ imsg_compose(ibuf, IMSG_LKA_HOST, 0, 0, -1, imsg.data,
sizeof(struct session));
break;
- }
default:
log_warnx("lka_dispatch_smtp: got imsg %d",
imsg.hdr.type);
@@ -1258,4 +1238,30 @@ lka_encode_credentials(char *dest, char *src)
return 1;
}
+void
+lka_dns_reverse(struct session *s)
+{
+ char addr[NI_MAXHOST];
+ struct addrinfo hints, *res;
+ struct sockaddr *sa;
+
+ strlcpy(s->s_hostname, "<unknown>", sizeof(s->s_hostname));
+
+ sa = (struct sockaddr *)&s->s_ss;
+ if (getnameinfo(sa, sa->sa_len, addr, sizeof(addr),
+ NULL, 0, NI_NAMEREQD))
+ return;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_flags = AI_NUMERICHOST;
+
+ if (getaddrinfo(addr, NULL, &hints, &res))
+ return; /* malicious PTR record. */
+
+ freeaddrinfo(res);
+
+ strlcpy(s->s_hostname, addr, sizeof(s->s_hostname));
+}
+
SPLAY_GENERATE(lkatree, lkasession, nodes, lkasession_cmp);
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index 7126463bd3d..5b8e2fa52d2 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.40 2009/04/28 21:55:16 jacekm Exp $ */
+/* $OpenBSD: smtp.c,v 1.41 2009/04/28 22:38:22 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -716,9 +716,6 @@ smtp_accept(int fd, short event, void *p)
if (s_smtp.sessions_active == s->s_env->sc_maxconn)
event_del(&l->ev);
- strlcpy(s->s_hostname, "<unknown>", sizeof(s->s_hostname));
- strlcpy(s->s_msg.session_hostname, s->s_hostname,
- sizeof(s->s_msg.session_hostname));
imsg_compose(s->s_env->sc_ibufs[PROC_LKA], IMSG_LKA_HOST, 0, 0, -1, s,
sizeof(struct session));