Mercurial > masqmail
annotate src/smtp_in.c @ 371:f122535c589e
Refactoring: early failure exit.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Tue, 25 Oct 2011 13:51:43 +0200 |
parents | b27f66555ba8 |
children | 028bc124d744 |
rev | line source |
---|---|
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
1 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
2 ** MasqMail |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
3 ** Copyright (C) 1999-2001 Oliver Kurth |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
4 ** Copyright (C) 2010 markus schnalke <meillo@marmaro.de> |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
5 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
6 ** This program is free software; you can redistribute it and/or modify |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
7 ** it under the terms of the GNU General Public License as published by |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
8 ** the Free Software Foundation; either version 2 of the License, or |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
9 ** (at your option) any later version. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
10 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
11 ** This program is distributed in the hope that it will be useful, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
14 ** GNU General Public License for more details. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
15 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
16 ** You should have received a copy of the GNU General Public License |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
17 ** along with this program; if not, write to the Free Software |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
0 | 19 */ |
20 | |
21 #include "masqmail.h" | |
22 #include "readsock.h" | |
23 | |
24 /* | |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
25 ** I always forget these rfc numbers: |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
26 ** RFC 821 (SMTP) |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
27 ** RFC 1869 (ESMTP) |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
28 ** RFC 1870 (ESMTP SIZE) |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
29 ** RFC 2197 (ESMTP PIPELINE) |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
30 ** RFC 2554 (ESMTP AUTH) |
0 | 31 */ |
32 | |
33 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
34 smtp_cmd smtp_cmds[] = { |
15 | 35 {SMTP_HELO, "HELO",}, |
36 {SMTP_EHLO, "EHLO",}, | |
37 {SMTP_MAIL_FROM, "MAIL FROM:",}, | |
38 {SMTP_RCPT_TO, "RCPT TO:",}, | |
39 {SMTP_DATA, "DATA",}, | |
40 {SMTP_QUIT, "QUIT",}, | |
41 {SMTP_RSET, "RSET",}, | |
42 {SMTP_NOOP, "NOOP",}, | |
43 {SMTP_HELP, "HELP"}, | |
0 | 44 }; |
45 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
46 static smtp_cmd_id |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
347
diff
changeset
|
47 get_id(const gchar *line) |
0 | 48 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
49 gint i; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
50 for (i = 0; i < SMTP_NUM_IDS; i++) { |
80 | 51 if (strncasecmp(smtp_cmds[i].cmd, line, strlen(smtp_cmds[i].cmd)) == 0) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
52 return (smtp_cmd_id) i; |
80 | 53 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
54 } |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
55 return SMTP_ERROR; |
0 | 56 } |
57 | |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
58 static gboolean |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
59 get_size(gchar *line, unsigned long *msize) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
60 gchar *s = NULL; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
61 |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
62 /* hope we need not to handle cases like SiZe= ...*/ |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
63 s = strstr(line, "SIZE="); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
64 if (!s) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
65 /* try it in lowercase too */ |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
66 if (!(s = strstr(line, "size="))) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
67 return FALSE; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
68 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
69 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
70 s += 5; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
71 *msize = atol(s); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
72 DEBUG(5) debugf("get_size(): line=%s, msize=%ld\n", line, *msize); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
73 |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
74 return TRUE; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
75 } |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
76 |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
77 |
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
78 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
79 ** this is a quick hack: we expect the address to be syntactically correct |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
80 ** and containing the mailbox only, though we first check for size in |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
81 ** smtp_in(). |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
82 ** Return false if address is too long. |
0 | 83 */ |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
84 static gboolean |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
347
diff
changeset
|
85 get_address(gchar *line, gchar *addr) |
0 | 86 { |
80 | 87 gchar *p = line; |
88 gchar *q = addr; | |
0 | 89 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
90 /* skip MAIL FROM: and RCPT TO: */ |
80 | 91 while (*p && (*p != ':')) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
92 p++; |
80 | 93 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
94 p++; |
0 | 95 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
96 /* skip spaces: */ |
80 | 97 while (*p && isspace(*p)) { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
98 p++; |
80 | 99 } |
0 | 100 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
101 /* get address: */ |
136
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
102 while (*p && !isspace(*p)) { |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
103 if (q >= addr + MAX_ADDRESS-1) { |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
104 *q = '\0'; |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
105 return FALSE; |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
106 } |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
107 *(q++) = *(p++); |
80 | 108 } |
136
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
109 *q = '\0'; |
0 | 110 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
111 return TRUE; |
0 | 112 } |
113 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
114 static smtp_connection* |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
347
diff
changeset
|
115 create_base(gchar *remote_host) |
0 | 116 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
117 smtp_connection *base = g_malloc(sizeof(smtp_connection)); |
80 | 118 if (!base) { |
119 return NULL; | |
120 } | |
121 | |
122 base->remote_host = g_strdup(remote_host); | |
0 | 123 |
80 | 124 base->prot = PROT_SMTP; |
125 base->next_id = 0; | |
126 base->helo_seen = 0; | |
127 base->from_seen = 0; | |
128 base->rcpt_seen = 0; | |
129 base->msg = NULL; | |
0 | 130 |
80 | 131 return base; |
0 | 132 } |
133 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
134 static void |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
347
diff
changeset
|
135 smtp_printf(FILE *out, gchar *fmt, ...) |
0 | 136 { |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
137 va_list args; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
138 va_start(args, fmt); |
0 | 139 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
140 DEBUG(4) { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
141 gchar buf[256]; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
142 va_list args_copy; |
0 | 143 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
144 va_copy(args_copy, args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
145 vsnprintf(buf, 255, fmt, args_copy); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
146 va_end(args_copy); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
147 |
208
3708b655a371
added newlines to the end of log and debug messages where missing
meillo@marmaro.de
parents:
204
diff
changeset
|
148 debugf(">>>%s\n", buf); |
0 | 149 } |
150 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
151 vfprintf(out, fmt, args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
152 fflush(out); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
153 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
154 va_end(args); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
155 } |
0 | 156 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
157 void |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
347
diff
changeset
|
158 smtp_in(FILE *in, FILE *out, gchar *remote_host, gchar *ident) |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
159 { |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
160 gchar *buffer; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
161 smtp_cmd_id cmd_id; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
162 message *msg = NULL; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
163 smtp_connection *psc; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
164 int len; |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
165 unsigned long size, msize; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
166 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
167 DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host); |
0 | 168 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
169 psc = create_base(remote_host); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
170 psc->msg = msg; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
171 |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
172 buffer = (gchar *) g_malloc(BUF_LEN); |
80 | 173 if (!buffer) { |
174 /* this check is actually unneccessary as g_malloc() | |
175 aborts on failure */ | |
176 return; | |
177 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
178 |
80 | 179 /* send greeting string, containing ESMTP: */ |
180 smtp_printf(out, "220 %s MasqMail %s ESMTP\r\n", conf.host_name, VERSION); | |
0 | 181 |
80 | 182 while ((len = read_sockline(in, buffer, BUF_LEN, 5 * 60, READSOCKL_CHUG)) >= 0) { |
183 cmd_id = get_id(buffer); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
184 |
135 | 185 if (conf.defer_all) { |
186 /* I need this to debug delivery failures */ | |
127 | 187 smtp_printf(out, "421 %s service temporarily unavailable.\r\n", conf.host_name); |
135 | 188 destroy_message(msg); |
189 msg = NULL; | |
190 return; | |
127 | 191 } |
192 | |
80 | 193 switch (cmd_id) { |
127 | 194 case SMTP_HELO: |
195 psc->prot = PROT_SMTP; | |
196 psc->helo_seen = TRUE; | |
197 smtp_printf(out, "250 %s pretty old mailer, huh?\r\n", conf.host_name); | |
198 break; | |
199 | |
80 | 200 case SMTP_EHLO: |
201 psc->prot = PROT_ESMTP; | |
202 psc->helo_seen = TRUE; | |
127 | 203 smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n", conf.host_name); |
204 smtp_printf(out, "250-SIZE %d\r\n", conf.max_msg_size); | |
205 smtp_printf(out, "250-PIPELINING\r\n"); | |
206 smtp_printf(out, "250 HELP\r\n"); | |
80 | 207 break; |
208 | |
209 case SMTP_MAIL_FROM: | |
210 { | |
211 gchar buf[MAX_ADDRESS]; | |
212 address *addr; | |
213 | |
214 if (!psc->helo_seen) { | |
215 smtp_printf(out, "503 need HELO or EHLO\r\n"); | |
216 break; | |
217 } | |
218 if (psc->from_seen) { | |
219 smtp_printf(out, "503 MAIL FROM: already given.\r\n"); | |
220 break; | |
221 } | |
128
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
222 if (get_size(buffer, &msize)) { |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
223 DEBUG(5) debugf("smtp_in(): get_size: msize=%ld, conf.mms=%d\n", |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
224 msize, conf.max_msg_size); |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
225 if (conf.max_msg_size && (msize > conf.max_msg_size)) { |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
226 smtp_printf(out, "552 Message size exceeds fixed limit.\r\n"); |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
227 break; |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
228 } |
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
229 } |
136
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
230 if (!get_address(buffer, buf)) { |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
231 smtp_printf(out, "553 Address too long.\r\n"); |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
232 break; |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
233 } |
128
f9d5469cb648
moved the SIZE check to a better location
meillo@marmaro.de
parents:
127
diff
changeset
|
234 |
80 | 235 msg = create_message(); |
236 msg->received_host = remote_host ? g_strdup(remote_host) : NULL; | |
237 msg->received_prot = psc->prot; | |
238 msg->ident = ident ? g_strdup(ident) : NULL; | |
239 /* get transfer id and increment for next one */ | |
240 msg->transfer_id = (psc->next_id)++; | |
241 | |
242 if (remote_host) { | |
243 addr = create_address(buf, TRUE); | |
244 } else { | |
245 addr = create_address_qualified(buf, TRUE, conf.host_name); | |
246 } | |
247 if (!addr) { | |
248 smtp_printf(out, "501 %s: syntax error.\r\n", buf); | |
249 } else if (!addr->domain) { | |
250 smtp_printf(out, "501 return path must be qualified.\r\n", buf); | |
251 } else { | |
252 psc->from_seen = TRUE; | |
253 msg->return_path = addr; | |
254 smtp_printf(out, "250 OK %s is a nice guy.\r\n", addr->address); | |
255 } | |
256 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
257 break; |
80 | 258 |
259 case SMTP_RCPT_TO: | |
260 { | |
261 char buf[MAX_ADDRESS]; | |
262 address *addr; | |
263 | |
264 if (!psc->helo_seen) { | |
265 smtp_printf(out, "503 need HELO or EHLO.\r\n"); | |
266 break; | |
267 } | |
268 if (!psc->from_seen) { | |
269 smtp_printf(out, "503 need MAIL FROM: before RCPT TO:\r\n"); | |
270 break; | |
271 } | |
136
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
272 if (!get_address(buffer, buf)) { |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
273 smtp_printf(out, "553 Address too long.\r\n"); |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
274 break; |
6b78aaced5e1
check max length of addresses in SMTP dialog
meillo@marmaro.de
parents:
135
diff
changeset
|
275 } |
80 | 276 |
277 if (remote_host) { | |
278 addr = create_address(buf, TRUE); | |
279 } else { | |
280 addr = create_address_qualified(buf, TRUE, conf.host_name); | |
281 } | |
282 if (!addr) { | |
283 smtp_printf(out, "501 %s: syntax error in address.\r\n", buf); | |
284 break; | |
285 } | |
286 if (addr->local_part[0] == '|') { | |
287 smtp_printf(out, "501 %s: no pipe allowed for SMTP connections\r\n", buf); | |
288 break; | |
289 } | |
290 if (!addr->domain) { | |
305 | 291 /* TODO: ``postmaster'' may be unqualified */ |
80 | 292 smtp_printf(out, "501 recipient address must be qualified.\r\n", buf); |
293 break; | |
294 } | |
305 | 295 if (!(conf.do_relay || addr_is_local(msg->return_path) || addr_is_local(addr))) { |
80 | 296 smtp_printf(out, "550 relaying to %s denied.\r\n", addr_string(addr)); |
297 break; | |
298 } | |
299 psc->rcpt_seen = TRUE; | |
300 msg->rcpt_list = g_list_append(msg->rcpt_list, addr); | |
301 smtp_printf(out, "250 OK %s is our friend.\r\n", addr->address); | |
302 } | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
303 break; |
80 | 304 |
305 case SMTP_DATA: | |
306 if (!psc->helo_seen) { | |
307 smtp_printf(out, "503 need HELO or EHLO.\r\n"); | |
308 break; | |
309 } | |
310 if (!psc->rcpt_seen) { | |
311 smtp_printf(out, "503 need RCPT TO: before DATA\r\n"); | |
312 break; | |
313 } | |
314 accept_error err; | |
315 | |
316 smtp_printf(out, "354 okay, and do not forget the dot\r\n"); | |
317 | |
318 err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0); | |
319 if (err != AERR_OK) { | |
117
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
320 switch (err) { |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
321 case AERR_TIMEOUT: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
322 case AERR_EOF: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
323 return; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
324 case AERR_SIZE: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
325 smtp_printf(out, "552 Error: message too large.\r\n"); |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
326 return; |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
327 default: |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
328 /* should never happen: */ |
5ec5e6637049
added server-side SMTP SIZE support (patch by Paolo)
meillo@marmaro.de
parents:
81
diff
changeset
|
329 smtp_printf(out, "451 Unknown error\r\n"); |
80 | 330 return; |
331 } | |
332 } | |
333 | |
334 | |
335 if (!spool_write(msg, TRUE)) { | |
336 smtp_printf(out, "451 Could not write spool file\r\n"); | |
337 return; | |
338 } | |
339 pid_t pid; | |
340 smtp_printf(out, "250 OK id=%s\r\n", msg->uid); | |
341 | |
342 if (remote_host != NULL) { | |
343 logwrite(LOG_NOTICE, "%s <= <%s@%s> host=%s with %s\n", msg->uid, | |
344 msg->return_path->local_part, msg->return_path->domain, | |
345 remote_host, prot_names[psc->prot]); | |
346 } else { | |
347 logwrite(LOG_NOTICE, "%s <= <%s@%s> with %s\n", msg->uid, | |
348 msg->return_path->local_part, msg->return_path->domain, | |
349 prot_names[psc->prot]); | |
350 } | |
351 | |
352 if (conf.do_queue) { | |
353 DEBUG(1) debugf("queuing forced by configuration or option.\n"); | |
354 } else { | |
355 pid = fork(); | |
347 | 356 if (pid < 0) { |
357 logwrite(LOG_ALERT, "could not fork for delivery, id = %s\n", msg->uid); | |
358 } else if (pid == 0) { | |
359 /* FIXME: most likely inverted exit code */ | |
80 | 360 _exit(deliver(msg)); |
361 } | |
362 } | |
363 psc->rcpt_seen = psc->from_seen = FALSE; | |
364 destroy_message(msg); | |
365 msg = NULL; | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
366 break; |
80 | 367 |
368 case SMTP_QUIT: | |
369 smtp_printf(out, "221 goodbye\r\n"); | |
81
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
370 destroy_message(msg); |
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
371 msg = NULL; |
80 | 372 return; |
373 | |
374 case SMTP_RSET: | |
375 psc->from_seen = psc->rcpt_seen = FALSE; | |
81
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
376 destroy_message(msg); |
71ce3a1568e9
moved check for NULL into destroy_message()
meillo@marmaro.de
parents:
80
diff
changeset
|
377 msg = NULL; |
80 | 378 smtp_printf(out, "250 OK\r\n"); |
379 break; | |
380 | |
381 case SMTP_NOOP: | |
382 smtp_printf(out, "250 OK\r\n"); | |
383 break; | |
384 | |
385 case SMTP_HELP: | |
386 { | |
387 int i; | |
388 | |
389 smtp_printf(out, "214-supported commands:\r\n"); | |
390 for (i = 0; i < SMTP_NUM_IDS - 1; i++) { | |
391 smtp_printf(out, "214-%s\r\n", smtp_cmds[i].cmd); | |
392 } | |
393 smtp_printf(out, "214 %s\r\n", smtp_cmds[i].cmd); | |
394 } | |
395 break; | |
396 | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
397 default: |
80 | 398 smtp_printf(out, "501 command not recognized\r\n"); |
399 DEBUG(1) debugf("command not recognized, was '%s'\n", buffer); | |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
400 break; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
401 } |
0 | 402 } |
80 | 403 switch (len) { |
404 case -3: | |
405 logwrite(LOG_NOTICE, "connection timed out\n"); | |
406 break; | |
407 case -2: | |
408 logwrite(LOG_NOTICE, "line overflow\n"); | |
409 break; | |
410 case -1: | |
411 logwrite(LOG_NOTICE, "received EOF\n"); | |
412 break; | |
413 default: | |
414 break; | |
415 } | |
0 | 416 } |