summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-11-10 14:54:14 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-11-10 14:54:14 +0000
commitb98edc6807159478da0e488da17f7d809e9a88a5 (patch)
treefbaa4a3d8c47e1ee9d77fd7bcd70cdb409bdde01
parent99f1b54ac81129b2ac08d78c04ea17fb62c21711 (diff)
In absence of the ehlo parameter, generate one based on locally
bound IP address ("EHLO [1.2.3.4]") as dictated by RFC. ok gilles@
-rw-r--r--usr.sbin/smtpd/client.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/usr.sbin/smtpd/client.c b/usr.sbin/smtpd/client.c
index a34a7247e6d..fbf82806547 100644
--- a/usr.sbin/smtpd/client.c
+++ b/usr.sbin/smtpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.10 2009/11/10 00:24:53 jacekm Exp $ */
+/* $OpenBSD: client.c,v 1.11 2009/11/10 14:54:13 jacekm Exp $ */
/*
* Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/queue.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/uio.h>
@@ -26,6 +27,7 @@
#include <ctype.h>
#include <errno.h>
#include <limits.h>
+#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -66,7 +68,20 @@ client_init(int fd, char *ehlo)
if ((sp = calloc(1, sizeof(*sp))) == NULL)
goto done;
- if ((sp->ehlo = strdup(ehlo)) == NULL)
+ if (ehlo == NULL || *ehlo == '\0') {
+ char buf[NI_MAXHOST];
+ struct sockaddr_storage sa;
+ socklen_t len;
+
+ len = sizeof(sa);
+ if (getsockname(fd, (struct sockaddr *)&sa, &len))
+ goto done;
+ if (getnameinfo((struct sockaddr *)&sa, len, buf, sizeof(buf),
+ NULL, 0, NI_NUMERICHOST))
+ goto done;
+ if (asprintf(&sp->ehlo, "[%s]", buf) == -1)
+ goto done;
+ } else if ((sp->ehlo = strdup(ehlo)) == NULL)
goto done;
if ((sp->sender = strdup("")) == NULL)
goto done;