Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
smtpd: spell HOST_NAME_MAX differently (for -portable)
To:
tech@openbsd.org
Cc:
gilles@poolp.org
Date:
Tue, 20 Aug 2024 12:40:43 +0200

Download raw body.

Thread
in -portable land there's an issue on glibc-based systems because
HOST_NAME_MAX is set at 64.  We end up truncating longer names and this
makes checks like fcrdns fails.

In the spirit of reducing the number of portable only changes to carry,
would something like this be acceptable for base?  An alternative would
be to use _POSIX_HOST_NAME_MAX instead.

The diff is mostly by Romain Petit via[0] adapted for base.
[0]: <https://github.com/OpenSMTPD/OpenSMTPD/pull/1260>

Thoughts?

diff /home/op/w/smtpd
commit - 4ec79e90906150d8ad2e80322cd41778d6546f40
path + /home/op/w/smtpd
blob - c13d2bef933951b39b335cdeadae9211c2a847dd
file + config.c
--- config.c
+++ config.c
@@ -35,7 +35,7 @@ config_default(void)
 	struct smtpd	       *conf = NULL;
 	struct mta_limits      *limits = NULL;
 	struct table	       *t = NULL;
-	char			hostname[HOST_NAME_MAX+1];
+	char			hostname[SMTPD_HOST_NAME_MAX+1];
 
 	if (getmailname(hostname, sizeof hostname) == -1)
 		return NULL;
blob - b1b49ea757665739e33a643293dfb1c9ed0aa79f
file + dns.c
--- dns.c
+++ dns.c
@@ -40,7 +40,7 @@ struct dns_session {
 	struct mproc		*p;
 	uint64_t		 reqid;
 	int			 type;
-	char			 name[HOST_NAME_MAX+1];
+	char			 name[SMTPD_HOST_NAME_MAX+1];
 	size_t			 mxfound;
 	int			 error;
 	int			 refcount;
@@ -342,7 +342,7 @@ dns_lookup_host(struct dns_session *s, const char *hos
 {
 	struct dns_lookup	*lookup;
 	struct addrinfo		 hints;
-	char			 hostcopy[HOST_NAME_MAX+1];
+	char			 hostcopy[SMTPD_HOST_NAME_MAX+1];
 	char			*p;
 	void			*as;
 
blob - 51616d0d59059e807fc387b3ba17526804ede2ff
file + enqueue.c
--- enqueue.c
+++ enqueue.c
@@ -88,7 +88,7 @@ struct {
 #define WSP(c)			(c == ' ' || c == '\t')
 
 int		 verbose = 0;
-static char	 host[HOST_NAME_MAX+1];
+static char	 host[SMTPD_HOST_NAME_MAX+1];
 char		*user = NULL;
 time_t		 timestamp;
 
blob - fb221da2e289695e44646632c0964dbaeff92854
file + mail.maildir.c
--- mail.maildir.c
+++ mail.maildir.c
@@ -32,6 +32,8 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "smtpd-defines.h"
+
 #define	MAILADDR_ESCAPE		"!#$%&'*/?^`{|}~"
 
 static int	maildir_subdir(const char *, char *, size_t);
@@ -116,7 +118,7 @@ maildir_engine(const char *dirname, int junk)
 	char	extpath[PATH_MAX];
 	char	subdir[PATH_MAX];
 	char	filename[PATH_MAX];
-	char	hostname[HOST_NAME_MAX+1];
+	char	hostname[SMTPD_HOST_NAME_MAX+1];
 
 	char	tmp[PATH_MAX];
 	char	new[PATH_MAX];
blob - 8022d23ecb02e4654968912bb112c2042701e89e
file + mta.c
--- mta.c
+++ mta.c
@@ -156,7 +156,7 @@ static time_t	max_seen_discdelay_route;
 
 #define	HOSTSTAT_EXPIRE_DELAY	(4 * 3600)
 struct hoststat {
-	char			 name[HOST_NAME_MAX+1];
+	char			 name[SMTPD_HOST_NAME_MAX+1];
 	time_t			 tm;
 	char			 error[LINE_MAX];
 	struct tree		 deferred;
@@ -2627,7 +2627,7 @@ void
 mta_hoststat_update(const char *host, const char *error)
 {
 	struct hoststat	*hs = NULL;
-	char		 buf[HOST_NAME_MAX+1];
+	char		 buf[SMTPD_HOST_NAME_MAX+1];
 
 	if (!lowercase(buf, host, sizeof buf))
 		return;
@@ -2652,7 +2652,7 @@ void
 mta_hoststat_cache(const char *host, uint64_t evpid)
 {
 	struct hoststat	*hs = NULL;
-	char buf[HOST_NAME_MAX+1];
+	char buf[SMTPD_HOST_NAME_MAX+1];
 
 	if (!lowercase(buf, host, sizeof buf))
 		return;
@@ -2671,7 +2671,7 @@ void
 mta_hoststat_uncache(const char *host, uint64_t evpid)
 {
 	struct hoststat	*hs = NULL;
-	char buf[HOST_NAME_MAX+1];
+	char buf[SMTPD_HOST_NAME_MAX+1];
 
 	if (!lowercase(buf, host, sizeof buf))
 		return;
@@ -2687,7 +2687,7 @@ void
 mta_hoststat_reschedule(const char *host)
 {
 	struct hoststat	*hs = NULL;
-	char		 buf[HOST_NAME_MAX+1];
+	char		 buf[SMTPD_HOST_NAME_MAX+1];
 	uint64_t	 evpid;
 
 	if (!lowercase(buf, host, sizeof buf))
blob - b4cf1f21ddb02dce7a4911285e33eebfcf517067
file + parse.y
--- parse.y
+++ parse.y
@@ -319,7 +319,7 @@ ADMD STRING {
 
 ca:
 CA STRING {
-	char buf[HOST_NAME_MAX+1];
+	char buf[SMTPD_HOST_NAME_MAX+1];
 
 	/* if not catchall, check that it is a valid domain */
 	if (strcmp($2, "*") != 0) {
@@ -388,7 +388,7 @@ MTA MAX_DEFERRED NUMBER  {
 
 pki:
 PKI STRING {
-	char buf[HOST_NAME_MAX+1];
+	char buf[SMTPD_HOST_NAME_MAX+1];
 
 	/* if not catchall, check that it is a valid domain */
 	if (strcmp($2, "*") != 0) {
blob - 85659829f541b3e7827120d6cfec379721b1481c
file + smtp_session.c
--- smtp_session.c
+++ smtp_session.c
@@ -123,8 +123,8 @@ struct smtp_session {
 	struct listener		*listener;
 	void			*ssl_ctx;
 	struct sockaddr_storage	 ss;
-	char			 rdns[HOST_NAME_MAX+1];
-	char			 smtpname[HOST_NAME_MAX+1];
+	char			 rdns[SMTPD_HOST_NAME_MAX+1];
+	char			 smtpname[SMTPD_HOST_NAME_MAX+1];
 	int			 fcrdns;
 
 	int			 flags;
blob - 279d9e27b1e5c414a6288b0e13e34017f6214ee6
file + smtpd-defines.h
--- smtpd-defines.h
+++ smtpd-defines.h
@@ -20,6 +20,9 @@
 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
 #endif
 
+/* for -portable because some systems have a value too short */
+#define SMTPD_HOST_NAME_MAX	 HOST_NAME_MAX
+
 #define	SMTPD_TABLENAME_SIZE	 (64 + 1)
 #define	SMTPD_TAG_SIZE		 (32 + 1)
 
blob - 2be11bf2b536398ce24c3942b665cdefc21d7f94
file + smtpd.h
--- smtpd.h
+++ smtpd.h
@@ -120,7 +120,7 @@ struct netaddr {
 struct relayhost {
 	uint16_t flags;
 	int tls;
-	char hostname[HOST_NAME_MAX+1];
+	char hostname[SMTPD_HOST_NAME_MAX+1];
 	uint16_t port;
 	char authlabel[PATH_MAX];
 };
@@ -131,7 +131,7 @@ struct credentials {
 };
 
 struct destination {
-	char	name[HOST_NAME_MAX+1];
+	char	name[SMTPD_HOST_NAME_MAX+1];
 };
 
 struct source {
@@ -140,7 +140,7 @@ struct source {
 
 struct addrname {
 	struct sockaddr_storage	addr;
-	char			name[HOST_NAME_MAX+1];
+	char			name[SMTPD_HOST_NAME_MAX+1];
 };
 
 union lookup {
@@ -475,7 +475,7 @@ struct maddrmap {
 struct envelope {
 	TAILQ_ENTRY(envelope)		entry;
 
-	char				dispatcher[HOST_NAME_MAX+1];
+	char				dispatcher[SMTPD_HOST_NAME_MAX+1];
 
 	char				tag[SMTPD_TAG_SIZE];
 
@@ -483,9 +483,9 @@ struct envelope {
 	uint64_t			id;
 	enum envelope_flags		flags;
 
-	char				smtpname[HOST_NAME_MAX+1];
-	char				helo[HOST_NAME_MAX+1];
-	char				hostname[HOST_NAME_MAX+1];
+	char				smtpname[SMTPD_HOST_NAME_MAX+1];
+	char				helo[SMTPD_HOST_NAME_MAX+1];
+	char				hostname[SMTPD_HOST_NAME_MAX+1];
 	char				username[SMTPD_MAXMAILADDRSIZE];
 	char				errorline[LINE_MAX];
 	struct sockaddr_storage		ss;
@@ -531,7 +531,7 @@ struct listener {
 	char			 ca_name[PATH_MAX];
 	char			 tag[SMTPD_TAG_SIZE];
 	char			 authtable[LINE_MAX];
-	char			 hostname[HOST_NAME_MAX+1];
+	char			 hostname[SMTPD_HOST_NAME_MAX+1];
 	char			 hostnametable[PATH_MAX];
 	char			 sendertable[PATH_MAX];
 
@@ -593,7 +593,7 @@ struct smtpd {
 	int				sc_ttl;
 #define MAX_BOUNCE_WARN			4
 	time_t				sc_bounce_warn[MAX_BOUNCE_WARN];
-	char				sc_hostname[HOST_NAME_MAX+1];
+	char				sc_hostname[SMTPD_HOST_NAME_MAX+1];
 	struct stat_backend	       *sc_stat;
 	struct compress_backend	       *sc_comp;
 
blob - ef719264f7191cf2c2f3ed55aa913cac004a4cde
file + ssl.c
--- ssl.c
+++ ssl.c
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "smtpd-defines.h"
 #include "log.h"
 #include "ssl.h"
 
blob - ced63ebd6d4aa93c1b002ab77157cc6339c101f2
file + ssl.h
--- ssl.h
+++ ssl.h
@@ -16,7 +16,7 @@
  */
 
 struct pki {
-	char			 pki_name[HOST_NAME_MAX+1];
+	char			 pki_name[SMTPD_HOST_NAME_MAX+1];
 
 	char			*pki_cert_file;
 	char			*pki_cert;
@@ -30,7 +30,7 @@ struct pki {
 };
 
 struct ca {
-	char			 ca_name[HOST_NAME_MAX+1];
+	char			 ca_name[SMTPD_HOST_NAME_MAX+1];
 
 	char			*ca_cert_file;
 	char			*ca_cert;