summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2012-07-10 16:11:44 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2012-07-10 16:11:44 +0000
commitdc9bd4218a829331d3ce7723cb61c14e4717b55b (patch)
tree52cdd1f07730b4b622fada2f6bf022f54c2152c7 /usr.sbin/smtpd
parenta473d91196e7aa0aa2e7b7966c2e741ed2db2a94 (diff)
accept address literal for the recipient domain.
while there, change valid_{local,domain}part() prototypes to use const char *. with input from gilles@ and eric@ ok gilles@ eric@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/smtpd.h6
-rw-r--r--usr.sbin/smtpd/util.c27
2 files changed, 27 insertions, 6 deletions
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 55aec5b3bd6..0a7fe4d0067 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.307 2012/07/10 11:13:40 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.308 2012/07/10 16:11:43 chl Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1209,8 +1209,8 @@ int bsnprintf(char *, size_t, const char *, ...)
int safe_fclose(FILE *);
int hostname_match(char *, char *);
int email_to_mailaddr(struct mailaddr *, char *);
-int valid_localpart(char *);
-int valid_domainpart(char *);
+int valid_localpart(const char *);
+int valid_domainpart(const char *);
char *ss_to_text(struct sockaddr_storage *);
int valid_message_id(char *);
int valid_message_uid(char *);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index a4343a11b01..e6bc282e943 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.62 2012/07/08 15:48:00 gilles Exp $ */
+/* $OpenBSD: util.c,v 1.63 2012/07/10 16:11:43 chl Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -257,7 +257,7 @@ hostname_match(char *hostname, char *pattern)
}
int
-valid_localpart(char *s)
+valid_localpart(const char *s)
{
#define IS_ATEXT(c) (isalnum((int)(c)) || strchr("!#$%&'*+-/=?^_`{|}~", (c)))
nextatom:
@@ -278,8 +278,29 @@ nextatom:
}
int
-valid_domainpart(char *s)
+valid_domainpart(const char *s)
{
+ struct in_addr ina;
+ struct in6_addr ina6;
+ char *c, domain[MAX_DOMAINPART_SIZE];
+
+ if (*s == '[') {
+ strlcpy(domain, s + 1, sizeof domain);
+
+ c = strchr(domain, (int)']');
+ if (!c || c[1] != '\0')
+ return 0;
+
+ *c = '\0';
+
+ if (inet_pton(AF_INET6, domain, &ina6) == 1)
+ return 1;
+ if (inet_pton(AF_INET, domain, &ina) == 1)
+ return 1;
+
+ return 0;
+ }
+
nextsub:
if (!isalnum((int)*s))
return 0;