From dc9bd4218a829331d3ce7723cb61c14e4717b55b Mon Sep 17 00:00:00 2001 From: Charles Longeau Date: Tue, 10 Jul 2012 16:11:44 +0000 Subject: 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@ --- usr.sbin/smtpd/smtpd.h | 6 +++--- usr.sbin/smtpd/util.c | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'usr.sbin/smtpd') 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 @@ -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; -- cgit v1.2.3