aboutsummaryrefslogtreecommitdiffstats
path: root/testing/opensmtpd-extras/fix-opensmtpd-5.9+-compat.patch
blob: ec87bc149200ce37ffb80a293090878c15789e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
From 5cd4a2022b30a70dc02d030e4b7bc90d5afe61cb Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 28 Jul 2018 16:02:00 +0200
Subject: [PATCH] fix compatibility with opensmtpd 5.9+

This mirrors changes done in [1].

When a table from extras is used (tested with passwd and postgres),
opensmtpd failes to start (on Alpine Linux):

    passwd[7508]: warn: table-proc: bogus data
    passwd[7508]: fatal: table-proc: exiting
    warn: table-proc: pipe closed
    fatal: table-proc: exiting

The error is printed by the table process and it's cased by mismatch
between expected and actual size of the struct table_open_params.

Note: I've originally tried to port even changes of includes from [1],
but that would need to add many new includes to most of the extras.
Thus I've eventually decided that it's probably not the right approach.

Fixes: https://github.com/OpenSMTPD/OpenSMTPD/issues/816

[1]: https://github.com/OpenSMTPD/OpenSMTPD/commit/5dfecad33e1301343473f7e9a6e425cdd11b9c3f

Upstream-Issue: https://github.com/OpenSMTPD/OpenSMTPD-extras/pull/53
---
 api/filter_api.c                        | 6 +++---
 api/queue_api.c                         | 2 +-
 api/queue_utils.c                       | 2 +-
 api/smtpd-api.h                         | 3 ++-
 api/smtpd-defines.h                     | 5 -----
 api/to.c                                | 4 ++--
 extras/tables/table-mysql/table_mysql.c | 6 +++---
 7 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/api/filter_api.c b/api/filter_api.c
index e3743c8..659a5fc 100644
--- a/api/filter_api.c
+++ b/api/filter_api.c
@@ -652,8 +652,8 @@ filter_io_in(struct io *io, int evt)
 	case IO_DATAIN:
 	    nextline:
 		line = iobuf_getline(&s->pipe.ibuf, &len);
-		if ((line == NULL && iobuf_len(&s->pipe.ibuf) >= SMTPD_MAXLINESIZE) ||
-		    (line && len >= SMTPD_MAXLINESIZE)) {
+		if ((line == NULL && iobuf_len(&s->pipe.ibuf) >= LINE_MAX) ||
+		    (line && len >= LINE_MAX)) {
 			s->pipe.error = 1;
 			break;
 		}
@@ -1210,7 +1210,7 @@ filter_api_sockaddr_to_text(const struct sockaddr *sa)
 const char *
 filter_api_mailaddr_to_text(const struct mailaddr *maddr)
 {
-	static char  buffer[SMTPD_MAXLINESIZE];
+	static char  buffer[LINE_MAX];
 
 	strlcpy(buffer, maddr->user, sizeof buffer);
 	if (maddr->domain[0] == '\0')
diff --git a/api/queue_api.c b/api/queue_api.c
index 4c6de84..3c1ea8d 100644
--- a/api/queue_api.c
+++ b/api/queue_api.c
@@ -111,7 +111,7 @@ queue_msg_dispatch(void)
 	uint64_t	 evpid;
 	uint32_t	 msgid, version;
 	size_t		 n, m;
-	char		 buffer[8192], path[SMTPD_MAXPATHLEN];
+	char		 buffer[8192], path[PATH_MAX];
 	int		 r, fd;
 	FILE		*ifile, *ofile;
 
diff --git a/api/queue_utils.c b/api/queue_utils.c
index 45dced5..7eafd1b 100644
--- a/api/queue_utils.c
+++ b/api/queue_utils.c
@@ -59,7 +59,7 @@ int
 mktmpfile(void)
 {
 	static char	*tempdir = "/temporary";
-	char		 path[SMTPD_MAXPATHLEN];
+	char		 path[PATH_MAX];
 	int		 fd;
 	mode_t		 omode;
 
diff --git a/api/smtpd-api.h b/api/smtpd-api.h
index 3416989..2595d68 100644
--- a/api/smtpd-api.h
+++ b/api/smtpd-api.h
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <netinet/in.h>
 #include <netdb.h>
+#include <limits.h>
 
 #include <event.h>
 #include <imsg.h>
@@ -229,7 +230,7 @@ struct scheduler_info {
 
 struct table_open_params {
 	uint32_t	version;
-	char		name[SMTPD_MAXLINESIZE];
+	char		name[LINE_MAX];
 };
 
 enum table_service {
diff --git a/api/smtpd-defines.h b/api/smtpd-defines.h
index 2ced70e..f34eda8 100644
--- a/api/smtpd-defines.h
+++ b/api/smtpd-defines.h
@@ -61,11 +61,6 @@ enum smtp_proc_type {
 #define SMTPD_MAXLOCALPARTSIZE	 (255 + 1)
 #define SMTPD_MAXDOMAINPARTSIZE	 (255 + 1)
 
-#define	SMTPD_MAXLOGNAME	32
-#define	SMTPD_MAXPATHLEN	1024
-#define	SMTPD_MAXHOSTNAMELEN	256
-#define	SMTPD_MAXLINESIZE	2048
-
 #define SMTPD_USER		"_smtpd"
 #define PATH_CHROOT		"/var/empty"
 #define SMTPD_QUEUE_USER	 "_smtpq"
diff --git a/api/to.c b/api/to.c
index e048341..2f0d294 100644
--- a/api/to.c
+++ b/api/to.c
@@ -92,7 +92,7 @@ text_to_mailaddr(struct mailaddr *maddr, const char *email)
 {
 	char *username;
 	char *hostname;
-	char  buffer[SMTPD_MAXLINESIZE];
+	char  buffer[LINE_MAX];
 
 	if (strlcpy(buffer, email, sizeof buffer) >= sizeof buffer)
 		return 0;
@@ -129,7 +129,7 @@ text_to_mailaddr(struct mailaddr *maddr, const char *email)
 const char *
 mailaddr_to_text(const struct mailaddr *maddr)
 {
-	static char  buffer[SMTPD_MAXLINESIZE];
+	static char  buffer[LINE_MAX];
 
 	(void)strlcpy(buffer, maddr->user, sizeof buffer);
 	(void)strlcat(buffer, "@", sizeof buffer);
diff --git a/extras/tables/table-mysql/table_mysql.c b/extras/tables/table-mysql/table_mysql.c
index 449a693..2c32060 100644
--- a/extras/tables/table-mysql/table_mysql.c
+++ b/extras/tables/table-mysql/table_mysql.c
@@ -68,7 +68,7 @@ static void		 config_free(struct config *);
 #define	DEFAULT_REFRESH	1000
 
 static MYSQL_BIND	 results[SQL_MAX_RESULT];
-static char		 results_buffer[SQL_MAX_RESULT][SMTPD_MAXLINESIZE];
+static char		 results_buffer[SQL_MAX_RESULT][LINE_MAX];
 static char		*conffile;
 static struct config	*config;
 
@@ -333,7 +333,7 @@ table_mysql_query(const char *key, int service)
 	MYSQL_STMT	*stmt;
 	MYSQL_BIND	 param[1];
 	unsigned long	 keylen;
-	char		 buffer[SMTPD_MAXLINESIZE];
+	char		 buffer[LINE_MAX];
 	int		 i;
 
 retry:
@@ -586,7 +586,7 @@ main(int argc, char **argv)
 	for (i = 0; i < SQL_MAX_RESULT; i++) {
 		results[i].buffer_type = MYSQL_TYPE_STRING;
 		results[i].buffer = results_buffer[i];
-		results[i].buffer_length = SMTPD_MAXLINESIZE;
+		results[i].buffer_length = LINE_MAX;
 		results[i].is_null = 0;
 	}