summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/smtpd/util.c')
-rw-r--r--usr.sbin/smtpd/util.c118
1 files changed, 60 insertions, 58 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 820bbd4cf85..0be3106a140 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.88 2012/11/12 14:58:53 eric Exp $ */
+/* $OpenBSD: util.c,v 1.89 2012/11/23 10:55:25 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -349,7 +349,8 @@ mktmpfile(void)
char path[MAXPATHLEN];
int fd;
- if (! bsnprintf(path, sizeof(path), "%s/smtpd.XXXXXXXXXX", PATH_TEMPORARY))
+ if (! bsnprintf(path, sizeof(path), "%s/smtpd.XXXXXXXXXX",
+ PATH_TEMPORARY))
err(1, "snprintf");
if ((fd = mkstemp(path)) == -1)
@@ -413,20 +414,20 @@ valid_localpart(const char *s)
*/
#define IS_ATEXT(c) (isalnum((int)(c)) || strchr("%+-=_", (c)))
nextatom:
- if (! IS_ATEXT(*s) || *s == '\0')
- return 0;
- while (*(++s) != '\0') {
- if (*s == '.')
- break;
- if (IS_ATEXT(*s))
- continue;
- return 0;
- }
- if (*s == '.') {
- s++;
- goto nextatom;
- }
- return 1;
+ if (! IS_ATEXT(*s) || *s == '\0')
+ return 0;
+ while (*(++s) != '\0') {
+ if (*s == '.')
+ break;
+ if (IS_ATEXT(*s))
+ continue;
+ return 0;
+ }
+ if (*s == '.') {
+ s++;
+ goto nextatom;
+ }
+ return 1;
}
int
@@ -454,22 +455,22 @@ valid_domainpart(const char *s)
}
nextsub:
- if (!isalnum((int)*s))
- return 0;
- while (*(++s) != '\0') {
- if (*s == '.')
- break;
- if (isalnum((int)*s) || *s == '-')
- continue;
- return 0;
- }
- if (s[-1] == '-')
- return 0;
- if (*s == '.') {
+ if (!isalnum((int)*s))
+ return 0;
+ while (*(++s) != '\0') {
+ if (*s == '.')
+ break;
+ if (isalnum((int)*s) || *s == '-')
+ continue;
+ return 0;
+ }
+ if (s[-1] == '-')
+ return 0;
+ if (*s == '.') {
s++;
- goto nextsub;
+ goto nextsub;
}
- return 1;
+ return 1;
}
int
@@ -515,25 +516,22 @@ ss_to_text(const struct sockaddr_storage *ss)
buf[0] = '\0';
p = buf;
- if (ss->ss_family == AF_LOCAL) {
+ if (ss->ss_family == AF_LOCAL)
strlcpy(buf, "local", sizeof buf);
- }
else if (ss->ss_family == AF_INET) {
in_addr_t addr;
-
+
addr = ((const struct sockaddr_in *)ss)->sin_addr.s_addr;
- addr = ntohl(addr);
- bsnprintf(p, NI_MAXHOST,
- "%d.%d.%d.%d",
- (addr >> 24) & 0xff,
- (addr >> 16) & 0xff,
- (addr >> 8) & 0xff,
- addr & 0xff);
+ addr = ntohl(addr);
+ bsnprintf(p, NI_MAXHOST, "%d.%d.%d.%d",
+ (addr >> 24) & 0xff, (addr >> 16) & 0xff,
+ (addr >> 8) & 0xff, addr & 0xff);
}
else if (ss->ss_family == AF_INET6) {
- const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *)ss;
+ const struct sockaddr_in6 *in6;
const struct in6_addr *in6_addr;
+ in6 = (const struct sockaddr_in6 *)ss;
strlcpy(buf, "IPv6:", sizeof(buf));
p = buf + 5;
in6_addr = &in6->sin6_addr;
@@ -547,26 +545,27 @@ char *
time_to_text(time_t when)
{
struct tm *lt;
- static char buf[40];
+ static char buf[40];
char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char *month[] = {"Jan","Feb","Mar","Apr","May","Jun",
- "Jul","Aug","Sep","Oct","Nov","Dec"};
+ "Jul","Aug","Sep","Oct","Nov","Dec"};
lt = localtime(&when);
- if (lt == NULL || when == 0)
+ if (lt == NULL || when == 0)
fatalx("time_to_text: localtime");
/* We do not use strftime because it is subject to locale substitution*/
- if (! bsnprintf(buf, sizeof(buf), "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)",
- day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon],
- lt->tm_year + 1900,
- lt->tm_hour, lt->tm_min, lt->tm_sec,
- lt->tm_gmtoff >= 0 ? '+' : '-',
- abs((int)lt->tm_gmtoff / 3600),
- abs((int)lt->tm_gmtoff % 3600) / 60,
- lt->tm_zone))
+ if (! bsnprintf(buf, sizeof(buf),
+ "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)",
+ day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon],
+ lt->tm_year + 1900,
+ lt->tm_hour, lt->tm_min, lt->tm_sec,
+ lt->tm_gmtoff >= 0 ? '+' : '-',
+ abs((int)lt->tm_gmtoff / 3600),
+ abs((int)lt->tm_gmtoff % 3600) / 60,
+ lt->tm_zone))
fatalx("time_to_text: bsnprintf");
-
+
return buf;
}
@@ -694,7 +693,7 @@ text_to_relayhost(struct relayhost *relay, const char *s)
{ "smtp://", 0 },
{ "smtps://", F_SMTPS },
{ "tls://", F_STARTTLS },
- { "smtps+auth://", F_SMTPS|F_AUTH },
+ { "smtps+auth://", F_SMTPS|F_AUTH },
{ "tls+auth://", F_STARTTLS|F_AUTH },
{ "ssl://", F_SMTPS|F_STARTTLS },
{ "ssl+auth://", F_SMTPS|F_STARTTLS|F_AUTH }
@@ -706,7 +705,8 @@ text_to_relayhost(struct relayhost *relay, const char *s)
int len;
for (i = 0; i < nitems(schemas); ++i)
- if (strncasecmp(schemas[i].name, s, strlen(schemas[i].name)) == 0)
+ if (strncasecmp(schemas[i].name, s,
+ strlen(schemas[i].name)) == 0)
break;
if (i == nitems(schemas)) {
@@ -729,7 +729,7 @@ text_to_relayhost(struct relayhost *relay, const char *s)
return 0;
len = sep - p;
}
- else
+ else
len = strlen(p);
if (strlcpy(relay->hostname, p, sizeof (relay->hostname))
@@ -856,7 +856,8 @@ sa_set_port(struct sockaddr *sa, int port)
struct addrinfo hints, *res;
int error;
- error = getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);
+ error = getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0,
+ NI_NUMERICHOST);
if (error)
fatalx("sa_set_port: getnameinfo failed");
@@ -1087,7 +1088,8 @@ log_envelope(const struct envelope *evp, const char *extra, const char *prefix,
if (extra == NULL)
extra = "";
- log_info("%s: %s for %016" PRIx64 ": from=<%s@%s>, to=<%s@%s>, %s%sdelay=%s, %sstat=%s",
+ log_info("%s: %s for %016" PRIx64 ": from=<%s@%s>, to=<%s@%s>, "
+ "%s%sdelay=%s, %sstat=%s",
evp->type == D_MDA ? "delivery" : "relay",
prefix,
evp->id, evp->sender.user, evp->sender.domain,