Mercurial > hg > nginx
annotate src/mail/ngx_mail_handler.c @ 2733:edc01cc34b3e
allow condensed command lines options
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 21 Apr 2009 15:42:15 +0000 |
parents | a59b26eee816 |
children | 268d8d3faa34 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
5 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
1136 | 10 #include <ngx_mail.h> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
11 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
12 |
1136 | 13 static void ngx_mail_init_session(ngx_connection_t *c); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
1136 | 15 #if (NGX_MAIL_SSL) |
16 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); | |
17 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c); | |
539 | 18 #endif |
19 | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
521 | 21 void |
1136 | 22 ngx_mail_init_connection(ngx_connection_t *c) |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 { |
641 | 24 in_addr_t in_addr; |
25 socklen_t len; | |
26 ngx_uint_t i; | |
27 struct sockaddr_in sin; | |
1136 | 28 ngx_mail_log_ctx_t *ctx; |
29 ngx_mail_in_port_t *imip; | |
30 ngx_mail_in_addr_t *imia; | |
31 ngx_mail_session_t *s; | |
641 | 32 |
33 /* find the server configuration for the address:port */ | |
34 | |
35 /* AF_INET only */ | |
36 | |
37 imip = c->listening->servers; | |
38 imia = imip->addrs; | |
39 | |
40 i = 0; | |
41 | |
42 if (imip->naddrs > 1) { | |
43 | |
44 /* | |
45 * There are several addresses on this port and one of them | |
46 * is the "*:port" wildcard so getsockname() is needed to determine | |
47 * the server address. | |
48 * | |
49 * AcceptEx() already gave this address. | |
50 */ | |
51 | |
52 #if (NGX_WIN32) | |
53 if (c->local_sockaddr) { | |
54 in_addr = | |
55 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; | |
541 | 56 |
641 | 57 } else |
58 #endif | |
59 { | |
60 len = sizeof(struct sockaddr_in); | |
61 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { | |
62 ngx_connection_error(c, ngx_socket_errno, | |
63 "getsockname() failed"); | |
1136 | 64 ngx_mail_close_connection(c); |
641 | 65 return; |
66 } | |
67 | |
68 in_addr = sin.sin_addr.s_addr; | |
69 } | |
70 | |
71 /* the last address is "*" */ | |
72 | |
73 for ( /* void */ ; i < imip->naddrs - 1; i++) { | |
74 if (in_addr == imia[i].addr) { | |
75 break; | |
76 } | |
77 } | |
78 } | |
79 | |
80 | |
1136 | 81 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t)); |
641 | 82 if (s == NULL) { |
1136 | 83 ngx_mail_close_connection(c); |
541 | 84 return; |
577 | 85 } |
541 | 86 |
641 | 87 s->main_conf = imia[i].ctx->main_conf; |
88 s->srv_conf = imia[i].ctx->srv_conf; | |
89 | |
90 s->addr_text = &imia[i].addr_text; | |
91 | |
92 c->data = s; | |
93 s->connection = c; | |
94 | |
95 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V", | |
96 c->number, &c->addr_text, s->addr_text); | |
97 | |
1136 | 98 ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t)); |
641 | 99 if (ctx == NULL) { |
1136 | 100 ngx_mail_close_connection(c); |
641 | 101 return; |
102 } | |
103 | |
104 ctx->client = &c->addr_text; | |
105 ctx->session = s; | |
541 | 106 |
107 c->log->connection = c->number; | |
1136 | 108 c->log->handler = ngx_mail_log_error; |
641 | 109 c->log->data = ctx; |
541 | 110 c->log->action = "sending client greeting line"; |
111 | |
112 c->log_error = NGX_ERROR_INFO; | |
113 | |
1136 | 114 #if (NGX_MAIL_SSL) |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
115 { |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
116 ngx_mail_ssl_conf_t *sslcf; |
543 | 117 |
1136 | 118 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
543 | 119 |
120 if (sslcf->enable) { | |
2224 | 121 c->log->action = "SSL handshaking"; |
122 | |
1136 | 123 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
547 | 124 return; |
543 | 125 } |
2224 | 126 |
127 if (imia[i].ssl) { | |
128 | |
129 c->log->action = "SSL handshaking"; | |
130 | |
131 if (sslcf->ssl.ctx == NULL) { | |
132 ngx_log_error(NGX_LOG_ERR, c->log, 0, | |
133 "no \"ssl_certificate\" is defined " | |
134 "in server listening on SSL port"); | |
135 ngx_mail_close_connection(c); | |
136 return; | |
137 } | |
138 | |
139 ngx_mail_ssl_init_connection(&sslcf->ssl, c); | |
140 return; | |
141 } | |
142 | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
143 } |
543 | 144 #endif |
145 | |
1136 | 146 ngx_mail_init_session(c); |
541 | 147 } |
148 | |
149 | |
1136 | 150 #if (NGX_MAIL_SSL) |
547 | 151 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
152 void |
1136 | 153 ngx_mail_starttls_handler(ngx_event_t *rev) |
583 | 154 { |
155 ngx_connection_t *c; | |
1136 | 156 ngx_mail_session_t *s; |
157 ngx_mail_ssl_conf_t *sslcf; | |
583 | 158 |
159 c = rev->data; | |
160 s = c->data; | |
641 | 161 s->starttls = 1; |
583 | 162 |
163 c->log->action = "in starttls state"; | |
164 | |
1136 | 165 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
583 | 166 |
1136 | 167 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
583 | 168 } |
169 | |
170 | |
171 static void | |
1136 | 172 ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c) |
583 | 173 { |
1136 | 174 ngx_mail_session_t *s; |
175 ngx_mail_core_srv_conf_t *cscf; | |
583 | 176 |
177 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) { | |
1136 | 178 ngx_mail_close_connection(c); |
583 | 179 return; |
180 } | |
181 | |
182 if (ngx_ssl_handshake(c) == NGX_AGAIN) { | |
183 | |
641 | 184 s = c->data; |
185 | |
1136 | 186 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
583 | 187 |
188 ngx_add_timer(c->read, cscf->timeout); | |
189 | |
1136 | 190 c->ssl->handler = ngx_mail_ssl_handshake_handler; |
583 | 191 |
192 return; | |
193 } | |
194 | |
1136 | 195 ngx_mail_ssl_handshake_handler(c); |
583 | 196 } |
197 | |
198 | |
199 static void | |
1136 | 200 ngx_mail_ssl_handshake_handler(ngx_connection_t *c) |
577 | 201 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
202 ngx_mail_session_t *s; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
203 ngx_mail_core_srv_conf_t *cscf; |
641 | 204 |
547 | 205 if (c->ssl->handshaked) { |
583 | 206 |
641 | 207 s = c->data; |
208 | |
209 if (s->starttls) { | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
210 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
211 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
212 c->read->handler = cscf->protocol->init_protocol; |
1136 | 213 c->write->handler = ngx_mail_send; |
583 | 214 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
215 cscf->protocol->init_protocol(c->read); |
583 | 216 |
217 return; | |
218 } | |
219 | |
2165
cbf6f2eb57ad
backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
220 c->read->ready = 0; |
cbf6f2eb57ad
backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
221 |
1136 | 222 ngx_mail_init_session(c); |
547 | 223 return; |
224 } | |
225 | |
1136 | 226 ngx_mail_close_connection(c); |
547 | 227 } |
228 | |
229 #endif | |
230 | |
231 | |
232 static void | |
1136 | 233 ngx_mail_init_session(ngx_connection_t *c) |
541 | 234 { |
1136 | 235 ngx_mail_session_t *s; |
236 ngx_mail_core_srv_conf_t *cscf; | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
237 |
641 | 238 s = c->data; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
239 |
1136 | 240 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
539 | 241 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
242 s->protocol = cscf->protocol->type; |
539 | 243 |
1136 | 244 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module); |
539 | 245 if (s->ctx == NULL) { |
1136 | 246 ngx_mail_session_internal_server_error(s); |
539 | 247 return; |
248 } | |
249 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
250 c->write->handler = ngx_mail_send; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
251 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
252 cscf->protocol->init_session(s, c); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
253 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
254 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
255 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
256 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
257 ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
258 ngx_mail_core_srv_conf_t *cscf) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
259 { |
2049 | 260 s->salt.data = ngx_pnalloc(c->pool, |
261 sizeof(" <18446744073709551616.@>" CRLF) - 1 | |
262 + NGX_TIME_T_LEN | |
263 + cscf->server_name.len); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
264 if (s->salt.data == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
265 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
266 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
267 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
268 s->salt.len = ngx_sprintf(s->salt.data, "<%ul.%T@%V>" CRLF, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
269 ngx_random(), ngx_time(), &cscf->server_name) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
270 - s->salt.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
271 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
272 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
273 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
274 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
275 |
1479 | 276 #if (NGX_MAIL_SSL) |
277 | |
278 ngx_int_t | |
279 ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c) | |
280 { | |
281 ngx_mail_ssl_conf_t *sslcf; | |
282 | |
283 if (c->ssl) { | |
284 return 0; | |
285 } | |
286 | |
287 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); | |
288 | |
289 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) { | |
290 return 1; | |
291 } | |
292 | |
293 return 0; | |
294 } | |
295 | |
296 #endif | |
297 | |
298 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
299 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
300 ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
301 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
302 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
303 ngx_str_t *arg, plain; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
304 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
305 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
306 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
307 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
308 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
309 "mail auth plain: \"%V\"", &arg[n]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
310 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
311 |
2049 | 312 plain.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
313 if (plain.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
314 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
315 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
316 |
1494
6535fb51976a
fix "AUTH PLAIN [initial-response]" bug introduced in r1477
Igor Sysoev <igor@sysoev.ru>
parents:
1491
diff
changeset
|
317 if (ngx_decode_base64(&plain, &arg[n]) != NGX_OK) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
318 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
319 "client sent invalid base64 encoding in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
320 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
321 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
322 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
323 p = plain.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
324 last = p + plain.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
325 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
326 while (p < last && *p++) { /* void */ } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
327 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
328 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
329 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
330 "client sent invalid login in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
331 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
332 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
333 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
334 s->login.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
335 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
336 while (p < last && *p) { p++; } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
337 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
338 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
339 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
340 "client sent invalid password in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
341 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
342 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
343 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
344 s->login.len = p++ - s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
345 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
346 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
347 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
348 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
349 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
350 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
351 "mail auth plain: \"%V\" \"%V\"", &s->login, &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
352 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
353 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
354 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
355 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
356 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
357 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
358 ngx_int_t |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
359 ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c, |
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
360 ngx_uint_t n) |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
361 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
362 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
363 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
364 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
365 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
366 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
367 "mail auth login username: \"%V\"", &arg[n]); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
368 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
369 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
370 if (s->login.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
371 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
372 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
373 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
374 if (ngx_decode_base64(&s->login, &arg[n]) != NGX_OK) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
375 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
376 "client sent invalid base64 encoding in AUTH LOGIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
377 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
378 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
379 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
380 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
381 "mail auth login username: \"%V\"", &s->login); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
382 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
383 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
384 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
385 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
386 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
387 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
388 ngx_mail_auth_login_password(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
389 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
390 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
391 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
392 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
393 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
394 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
395 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
396 "mail auth login password: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
397 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
398 |
2049 | 399 s->passwd.data = ngx_pnalloc(c->pool, |
400 ngx_base64_decoded_length(arg[0].len)); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
401 if (s->passwd.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
402 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
403 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
404 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
405 if (ngx_decode_base64(&s->passwd, &arg[0]) != NGX_OK) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
406 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
407 "client sent invalid base64 encoding in AUTH LOGIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
408 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
409 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
410 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
411 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
412 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
413 "mail auth login password: \"%V\"", &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
414 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
415 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
416 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
417 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
418 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
419 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
420 ngx_int_t |
1479 | 421 ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
422 char *prefix, size_t len) | |
423 { | |
424 u_char *p; | |
425 ngx_str_t salt; | |
426 ngx_uint_t n; | |
427 | |
2049 | 428 p = ngx_pnalloc(c->pool, len + ngx_base64_encoded_length(s->salt.len) + 2); |
1479 | 429 if (p == NULL) { |
430 return NGX_ERROR; | |
431 } | |
432 | |
433 salt.data = ngx_cpymem(p, prefix, len); | |
434 s->salt.len -= 2; | |
435 | |
436 ngx_encode_base64(&salt, &s->salt); | |
437 | |
438 s->salt.len += 2; | |
439 n = len + salt.len; | |
440 p[n++] = CR; p[n++] = LF; | |
441 | |
442 s->out.len = n; | |
443 s->out.data = p; | |
444 | |
445 return NGX_OK; | |
446 } | |
447 | |
448 | |
449 ngx_int_t | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
450 ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
451 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
452 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
453 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
454 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
455 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
456 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
457 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
458 "mail auth cram-md5: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
459 |
2049 | 460 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len)); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
461 if (s->login.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
462 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
463 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
464 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
465 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
466 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
467 "client sent invalid base64 encoding in AUTH CRAM-MD5 command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
468 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
469 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
470 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
471 p = s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
472 last = p + s->login.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
473 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
474 while (p < last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
475 if (*p++ == ' ') { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
476 s->login.len = p - s->login.data - 1; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
477 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
478 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
479 break; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
480 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
481 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
482 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
483 if (s->passwd.len != 32) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
484 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
485 "client sent invalid CRAM-MD5 hash in AUTH CRAM-MD5 command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
486 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
487 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
488 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
489 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
490 "mail auth cram-md5: \"%V\" \"%V\"", &s->login, &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
491 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
492 s->auth_method = NGX_MAIL_AUTH_CRAM_MD5; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
493 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
494 return NGX_DONE; |
539 | 495 } |
496 | |
497 | |
498 void | |
1136 | 499 ngx_mail_send(ngx_event_t *wev) |
539 | 500 { |
541 | 501 ngx_int_t n; |
502 ngx_connection_t *c; | |
1136 | 503 ngx_mail_session_t *s; |
504 ngx_mail_core_srv_conf_t *cscf; | |
539 | 505 |
506 c = wev->data; | |
507 s = c->data; | |
508 | |
509 if (wev->timedout) { | |
510 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 511 c->timedout = 1; |
1136 | 512 ngx_mail_close_connection(c); |
539 | 513 return; |
514 } | |
515 | |
516 if (s->out.len == 0) { | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
517 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
1136 | 518 ngx_mail_close_connection(c); |
539 | 519 } |
520 | |
521 return; | |
522 } | |
523 | |
524 n = c->send(c, s->out.data, s->out.len); | |
525 | |
526 if (n > 0) { | |
527 s->out.len -= n; | |
528 | |
541 | 529 if (wev->timer_set) { |
530 ngx_del_timer(wev); | |
531 } | |
532 | |
539 | 533 if (s->quit) { |
1136 | 534 ngx_mail_close_connection(c); |
539 | 535 return; |
536 } | |
537 | |
538 if (s->blocked) { | |
539 c->read->handler(c->read); | |
540 } | |
541 | |
542 return; | |
543 } | |
544 | |
545 if (n == NGX_ERROR) { | |
1136 | 546 ngx_mail_close_connection(c); |
539 | 547 return; |
548 } | |
549 | |
550 /* n == NGX_AGAIN */ | |
551 | |
1136 | 552 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
541 | 553 |
554 ngx_add_timer(c->write, cscf->timeout); | |
555 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
556 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
1136 | 557 ngx_mail_close_connection(c); |
539 | 558 return; |
559 } | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
560 } |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
561 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
562 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
563 ngx_int_t |
1482 | 564 ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
565 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
566 ssize_t n; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
567 ngx_int_t rc; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
568 ngx_str_t l; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
569 ngx_mail_core_srv_conf_t *cscf; |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
570 |
1482 | 571 n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
572 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
573 if (n == NGX_ERROR || n == 0) { |
1482 | 574 ngx_mail_close_connection(c); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
575 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
576 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
577 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
578 if (n > 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
579 s->buffer->last += n; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
580 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
581 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
582 if (n == NGX_AGAIN) { |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
583 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
1136 | 584 ngx_mail_session_internal_server_error(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
585 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
586 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
587 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
588 return NGX_AGAIN; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
589 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
590 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
591 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
592 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
593 rc = cscf->protocol->parse_command(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
594 |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
595 if (rc == NGX_AGAIN) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
596 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
597 if (s->buffer->last < s->buffer->end) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
598 return rc; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
599 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
600 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
601 l.len = s->buffer->last - s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
602 l.data = s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
603 |
1482 | 604 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
605 "client sent too long command \"%V\"", &l); |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
606 |
1111
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
607 s->quit = 1; |
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
608 |
1136 | 609 return NGX_MAIL_PARSE_INVALID_COMMAND; |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
610 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
611 |
1136 | 612 if (rc == NGX_IMAP_NEXT || rc == NGX_MAIL_PARSE_INVALID_COMMAND) { |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
613 return rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
614 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
615 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
616 if (rc == NGX_ERROR) { |
1482 | 617 ngx_mail_close_connection(c); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
618 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
619 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
620 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
621 return NGX_OK; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
622 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
623 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
624 |
521 | 625 void |
1482 | 626 ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c) |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
627 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
628 s->args.nelts = 0; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
629 s->buffer->pos = s->buffer->start; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
630 s->buffer->last = s->buffer->start; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
631 s->state = 0; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
632 |
1482 | 633 if (c->read->timer_set) { |
634 ngx_del_timer(c->read); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
635 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
636 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
637 s->login_attempt++; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
638 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
639 ngx_mail_auth_http_init(s); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
640 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
641 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
642 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
643 void |
1136 | 644 ngx_mail_session_internal_server_error(ngx_mail_session_t *s) |
525 | 645 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
646 ngx_mail_core_srv_conf_t *cscf; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
647 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
648 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
649 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
650 s->out = cscf->protocol->internal_server_error; |
539 | 651 s->quit = 1; |
525 | 652 |
1136 | 653 ngx_mail_send(s->connection->write); |
525 | 654 } |
655 | |
656 | |
657 void | |
1136 | 658 ngx_mail_close_connection(ngx_connection_t *c) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
659 { |
479 | 660 ngx_pool_t *pool; |
661 | |
1136 | 662 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
663 "close mail connection: %d", c->fd); | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
664 |
1136 | 665 #if (NGX_MAIL_SSL) |
539 | 666 |
667 if (c->ssl) { | |
668 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
1136 | 669 c->ssl->handler = ngx_mail_close_connection; |
539 | 670 return; |
671 } | |
672 } | |
673 | |
674 #endif | |
675 | |
1472
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
676 #if (NGX_STAT_STUB) |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
677 ngx_atomic_fetch_add(ngx_stat_active, -1); |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
678 #endif |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
679 |
583 | 680 c->destroyed = 1; |
543 | 681 |
479 | 682 pool = c->pool; |
683 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
684 ngx_close_connection(c); |
479 | 685 |
501 | 686 ngx_destroy_pool(pool); |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
687 } |
539 | 688 |
689 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
690 u_char * |
1136 | 691 ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len) |
541 | 692 { |
567 | 693 u_char *p; |
1136 | 694 ngx_mail_session_t *s; |
695 ngx_mail_log_ctx_t *ctx; | |
541 | 696 |
697 if (log->action) { | |
698 p = ngx_snprintf(buf, len, " while %s", log->action); | |
699 len -= p - buf; | |
700 buf = p; | |
701 } | |
577 | 702 |
541 | 703 ctx = log->data; |
704 | |
705 p = ngx_snprintf(buf, len, ", client: %V", ctx->client); | |
706 len -= p - buf; | |
707 buf = p; | |
708 | |
709 s = ctx->session; | |
710 | |
711 if (s == NULL) { | |
712 return p; | |
713 } | |
714 | |
1491 | 715 p = ngx_snprintf(buf, len, "%s, server: %V", |
716 s->starttls ? " using starttls" : "", | |
717 s->addr_text); | |
541 | 718 len -= p - buf; |
719 buf = p; | |
720 | |
721 if (s->login.len == 0) { | |
722 return p; | |
723 } | |
724 | |
725 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login); | |
726 len -= p - buf; | |
727 buf = p; | |
728 | |
729 if (s->proxy == NULL) { | |
730 return p; | |
731 } | |
732 | |
884 | 733 p = ngx_snprintf(buf, len, ", upstream: %V", s->proxy->upstream.name); |
541 | 734 |
735 return p; | |
736 } |