Mercurial > hg > nginx-quic
annotate src/imap/ngx_imap_handler.c @ 837:3611dca3c53a
fix subrequest limit
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 02 Nov 2006 13:38:25 +0000 |
parents | 760ed037a5a4 |
children | 7b8692910220 |
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> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
10 #include <ngx_imap.h> |
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 |
547 | 13 static void ngx_imap_init_session(ngx_connection_t *c); |
541 | 14 static void ngx_imap_init_protocol(ngx_event_t *rev); |
527 | 15 static ngx_int_t ngx_imap_read_command(ngx_imap_session_t *s); |
541 | 16 static u_char *ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 |
539 | 18 #if (NGX_IMAP_SSL) |
583 | 19 static void ngx_imap_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); |
547 | 20 static void ngx_imap_ssl_handshake_handler(ngx_connection_t *c); |
539 | 21 #endif |
22 | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
521 | 24 static ngx_str_t greetings[] = { |
527 | 25 ngx_string("+OK POP3 ready" CRLF), |
529 | 26 ngx_string("* OK IMAP4 ready" CRLF) |
521 | 27 }; |
28 | |
525 | 29 static ngx_str_t internal_server_errors[] = { |
30 ngx_string("-ERR internal server error" CRLF), | |
31 ngx_string("* BAD internal server error" CRLF), | |
32 }; | |
33 | |
521 | 34 static u_char pop3_ok[] = "+OK" CRLF; |
809 | 35 static u_char pop3_next[] = "+ " CRLF; |
36 static u_char pop3_username[] = "+ VXNlcm5hbWU6" CRLF; | |
37 static u_char pop3_password[] = "+ UGFzc3dvcmQ6" CRLF; | |
521 | 38 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF; |
39 | |
543 | 40 static u_char imap_star[] = "* "; |
529 | 41 static u_char imap_ok[] = "OK completed" CRLF; |
527 | 42 static u_char imap_next[] = "+ OK" CRLF; |
43 static u_char imap_bye[] = "* BYE" CRLF; | |
44 static u_char imap_invalid_command[] = "BAD invalid command" CRLF; | |
45 | |
521 | 46 |
47 void | |
48 ngx_imap_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
|
49 { |
641 | 50 in_addr_t in_addr; |
51 socklen_t len; | |
52 ngx_uint_t i; | |
53 struct sockaddr_in sin; | |
54 ngx_imap_log_ctx_t *ctx; | |
55 ngx_imap_in_port_t *imip; | |
56 ngx_imap_in_addr_t *imia; | |
57 ngx_imap_session_t *s; | |
543 | 58 #if (NGX_IMAP_SSL) |
583 | 59 ngx_imap_ssl_conf_t *sslcf; |
543 | 60 #endif |
541 | 61 |
641 | 62 |
63 /* find the server configuration for the address:port */ | |
64 | |
65 /* AF_INET only */ | |
66 | |
67 imip = c->listening->servers; | |
68 imia = imip->addrs; | |
69 | |
70 i = 0; | |
71 | |
72 if (imip->naddrs > 1) { | |
73 | |
74 /* | |
75 * There are several addresses on this port and one of them | |
76 * is the "*:port" wildcard so getsockname() is needed to determine | |
77 * the server address. | |
78 * | |
79 * AcceptEx() already gave this address. | |
80 */ | |
81 | |
82 #if (NGX_WIN32) | |
83 if (c->local_sockaddr) { | |
84 in_addr = | |
85 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; | |
541 | 86 |
641 | 87 } else |
88 #endif | |
89 { | |
90 len = sizeof(struct sockaddr_in); | |
91 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { | |
92 ngx_connection_error(c, ngx_socket_errno, | |
93 "getsockname() failed"); | |
94 ngx_imap_close_connection(c); | |
95 return; | |
96 } | |
97 | |
98 in_addr = sin.sin_addr.s_addr; | |
99 } | |
100 | |
101 /* the last address is "*" */ | |
102 | |
103 for ( /* void */ ; i < imip->naddrs - 1; i++) { | |
104 if (in_addr == imia[i].addr) { | |
105 break; | |
106 } | |
107 } | |
108 } | |
109 | |
110 | |
111 s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)); | |
112 if (s == NULL) { | |
541 | 113 ngx_imap_close_connection(c); |
114 return; | |
577 | 115 } |
541 | 116 |
641 | 117 s->main_conf = imia[i].ctx->main_conf; |
118 s->srv_conf = imia[i].ctx->srv_conf; | |
119 | |
120 s->addr_text = &imia[i].addr_text; | |
121 | |
122 c->data = s; | |
123 s->connection = c; | |
124 | |
125 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V", | |
126 c->number, &c->addr_text, s->addr_text); | |
127 | |
128 ctx = ngx_palloc(c->pool, sizeof(ngx_imap_log_ctx_t)); | |
129 if (ctx == NULL) { | |
130 ngx_imap_close_connection(c); | |
131 return; | |
132 } | |
133 | |
134 ctx->client = &c->addr_text; | |
135 ctx->session = s; | |
541 | 136 |
137 c->log->connection = c->number; | |
138 c->log->handler = ngx_imap_log_error; | |
641 | 139 c->log->data = ctx; |
541 | 140 c->log->action = "sending client greeting line"; |
141 | |
142 c->log_error = NGX_ERROR_INFO; | |
143 | |
543 | 144 #if (NGX_IMAP_SSL) |
145 | |
641 | 146 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module); |
543 | 147 |
148 if (sslcf->enable) { | |
583 | 149 ngx_imap_ssl_init_connection(&sslcf->ssl, c); |
547 | 150 return; |
543 | 151 } |
152 | |
153 #endif | |
154 | |
547 | 155 ngx_imap_init_session(c); |
541 | 156 } |
157 | |
158 | |
547 | 159 #if (NGX_IMAP_SSL) |
160 | |
541 | 161 static void |
583 | 162 ngx_imap_starttls_handler(ngx_event_t *rev) |
163 { | |
164 ngx_connection_t *c; | |
165 ngx_imap_session_t *s; | |
166 ngx_imap_ssl_conf_t *sslcf; | |
167 | |
168 c = rev->data; | |
169 s = c->data; | |
641 | 170 s->starttls = 1; |
583 | 171 |
172 c->log->action = "in starttls state"; | |
173 | |
174 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module); | |
175 | |
176 ngx_imap_ssl_init_connection(&sslcf->ssl, c); | |
177 } | |
178 | |
179 | |
180 static void | |
181 ngx_imap_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c) | |
182 { | |
641 | 183 ngx_imap_session_t *s; |
583 | 184 ngx_imap_core_srv_conf_t *cscf; |
185 | |
186 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) { | |
187 ngx_imap_close_connection(c); | |
188 return; | |
189 } | |
190 | |
191 if (ngx_ssl_handshake(c) == NGX_AGAIN) { | |
192 | |
641 | 193 s = c->data; |
194 | |
195 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
583 | 196 |
197 ngx_add_timer(c->read, cscf->timeout); | |
198 | |
199 c->ssl->handler = ngx_imap_ssl_handshake_handler; | |
200 | |
201 return; | |
202 } | |
203 | |
204 ngx_imap_ssl_handshake_handler(c); | |
205 } | |
206 | |
207 | |
208 static void | |
547 | 209 ngx_imap_ssl_handshake_handler(ngx_connection_t *c) |
577 | 210 { |
641 | 211 ngx_imap_session_t *s; |
212 | |
547 | 213 if (c->ssl->handshaked) { |
583 | 214 |
641 | 215 s = c->data; |
216 | |
217 if (s->starttls) { | |
583 | 218 c->read->handler = ngx_imap_init_protocol; |
219 c->write->handler = ngx_imap_send; | |
220 | |
221 ngx_imap_init_protocol(c->read); | |
222 | |
223 return; | |
224 } | |
225 | |
547 | 226 ngx_imap_init_session(c); |
227 return; | |
228 } | |
229 | |
230 ngx_imap_close_connection(c); | |
231 } | |
232 | |
233 #endif | |
234 | |
235 | |
236 static void | |
237 ngx_imap_init_session(ngx_connection_t *c) | |
541 | 238 { |
800 | 239 u_char *p; |
539 | 240 ngx_imap_session_t *s; |
541 | 241 ngx_imap_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
|
242 |
547 | 243 c->read->handler = ngx_imap_init_protocol; |
244 c->write->handler = ngx_imap_send; | |
539 | 245 |
641 | 246 s = c->data; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 |
641 | 248 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); |
539 | 249 |
250 s->protocol = cscf->protocol; | |
251 | |
252 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_imap_max_module); | |
253 if (s->ctx == NULL) { | |
254 ngx_imap_session_internal_server_error(s); | |
255 return; | |
256 } | |
257 | |
258 s->out = greetings[s->protocol]; | |
259 | |
800 | 260 if ((cscf->auth_methods & NGX_IMAP_AUTH_APOP_ENABLED) |
261 && s->protocol == NGX_IMAP_POP3_PROTOCOL) | |
262 { | |
263 s->salt.data = ngx_palloc(c->pool, | |
264 sizeof(" <18446744073709551616.@>" CRLF) - 1 | |
265 + NGX_TIME_T_LEN | |
266 + cscf->server_name.len); | |
267 if (s->salt.data == NULL) { | |
268 ngx_imap_session_internal_server_error(s); | |
269 return; | |
270 } | |
271 | |
272 s->salt.len = ngx_sprintf(s->salt.data, "<%ul.%T@%V>" CRLF, | |
273 ngx_random(), ngx_time(), &cscf->server_name) | |
274 - s->salt.data; | |
275 | |
276 s->out.data = ngx_palloc(c->pool, greetings[0].len + 1 + s->salt.len); | |
277 if (s->out.data == NULL) { | |
278 ngx_imap_session_internal_server_error(s); | |
279 return; | |
280 } | |
281 | |
282 p = ngx_cpymem(s->out.data, greetings[0].data, greetings[0].len - 2); | |
283 *p++ = ' '; | |
284 p = ngx_cpymem(p, s->salt.data, s->salt.len); | |
285 | |
286 s->out.len = p - s->out.data; | |
287 } | |
288 | |
547 | 289 ngx_add_timer(c->read, cscf->timeout); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
290 |
547 | 291 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
292 ngx_imap_close_connection(c); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
293 } |
539 | 294 |
295 ngx_imap_send(c->write); | |
296 } | |
297 | |
298 | |
299 void | |
300 ngx_imap_send(ngx_event_t *wev) | |
301 { | |
541 | 302 ngx_int_t n; |
303 ngx_connection_t *c; | |
304 ngx_imap_session_t *s; | |
305 ngx_imap_core_srv_conf_t *cscf; | |
539 | 306 |
307 c = wev->data; | |
308 s = c->data; | |
309 | |
310 if (wev->timedout) { | |
311 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 312 c->timedout = 1; |
539 | 313 ngx_imap_close_connection(c); |
314 return; | |
315 } | |
316 | |
317 if (s->out.len == 0) { | |
318 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { | |
319 ngx_imap_close_connection(c); | |
320 } | |
321 | |
322 return; | |
323 } | |
324 | |
325 n = c->send(c, s->out.data, s->out.len); | |
326 | |
327 if (n > 0) { | |
328 s->out.len -= n; | |
329 | |
541 | 330 if (wev->timer_set) { |
331 ngx_del_timer(wev); | |
332 } | |
333 | |
539 | 334 if (s->quit) { |
335 ngx_imap_close_connection(c); | |
336 return; | |
337 } | |
338 | |
339 if (s->blocked) { | |
340 c->read->handler(c->read); | |
341 } | |
342 | |
343 return; | |
344 } | |
345 | |
346 if (n == NGX_ERROR) { | |
347 ngx_imap_close_connection(c); | |
348 return; | |
349 } | |
350 | |
351 /* n == NGX_AGAIN */ | |
352 | |
541 | 353 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); |
354 | |
355 ngx_add_timer(c->write, cscf->timeout); | |
356 | |
539 | 357 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { |
358 ngx_imap_close_connection(c); | |
359 return; | |
360 } | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
361 } |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
362 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
363 |
521 | 364 static void |
541 | 365 ngx_imap_init_protocol(ngx_event_t *rev) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
366 { |
521 | 367 size_t size; |
368 ngx_connection_t *c; | |
369 ngx_imap_session_t *s; | |
370 ngx_imap_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
|
371 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
372 c = rev->data; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
373 |
541 | 374 c->log->action = "in auth state"; |
375 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
376 if (rev->timedout) { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
377 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
577 | 378 c->timedout = 1; |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
379 ngx_imap_close_connection(c); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
380 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
381 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
382 |
539 | 383 s = c->data; |
521 | 384 |
539 | 385 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) { |
521 | 386 size = 128; |
527 | 387 s->imap_state = ngx_pop3_start; |
521 | 388 c->read->handler = ngx_pop3_auth_state; |
389 | |
390 } else { | |
539 | 391 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); |
521 | 392 size = cscf->imap_client_buffer_size; |
527 | 393 s->imap_state = ngx_imap_start; |
521 | 394 c->read->handler = ngx_imap_auth_state; |
395 } | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
396 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
397 if (s->buffer == NULL) { |
583 | 398 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) |
399 == NGX_ERROR) | |
400 { | |
401 ngx_imap_session_internal_server_error(s); | |
402 return; | |
403 } | |
404 | |
405 s->buffer = ngx_create_temp_buf(c->pool, size); | |
406 if (s->buffer == NULL) { | |
407 ngx_imap_session_internal_server_error(s); | |
408 return; | |
409 } | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
410 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
411 |
521 | 412 c->read->handler(rev); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
413 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
414 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
415 |
527 | 416 void |
521 | 417 ngx_imap_auth_state(ngx_event_t *rev) |
418 { | |
543 | 419 u_char *text, *last, *p, *dst, *src, *end; |
539 | 420 ssize_t text_len, last_len; |
527 | 421 ngx_str_t *arg; |
422 ngx_int_t rc; | |
543 | 423 ngx_uint_t tag, i; |
527 | 424 ngx_connection_t *c; |
425 ngx_imap_session_t *s; | |
426 ngx_imap_core_srv_conf_t *cscf; | |
583 | 427 #if (NGX_IMAP_SSL) |
428 ngx_imap_ssl_conf_t *sslcf; | |
429 #endif | |
521 | 430 |
431 c = rev->data; | |
527 | 432 s = c->data; |
521 | 433 |
527 | 434 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth state"); |
435 | |
436 if (rev->timedout) { | |
437 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 438 c->timedout = 1; |
527 | 439 ngx_imap_close_connection(c); |
440 return; | |
441 } | |
442 | |
539 | 443 if (s->out.len) { |
444 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap send handler busy"); | |
445 s->blocked = 1; | |
446 return; | |
447 } | |
448 | |
449 s->blocked = 0; | |
450 | |
527 | 451 rc = ngx_imap_read_command(s); |
452 | |
453 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth: %i", rc); | |
454 | |
455 if (rc == NGX_AGAIN || rc == NGX_ERROR) { | |
456 return; | |
457 } | |
458 | |
459 tag = 1; | |
460 | |
461 text = NULL; | |
462 text_len = 0; | |
463 | |
464 last = imap_ok; | |
465 last_len = sizeof(imap_ok) - 1; | |
466 | |
467 if (rc == NGX_OK) { | |
468 | |
469 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth command: %i", | |
470 s->command); | |
471 | |
543 | 472 if (s->backslash) { |
473 | |
474 arg = s->args.elts; | |
475 | |
476 for (i = 0; i < s->args.nelts; i++) { | |
477 dst = arg[i].data; | |
478 end = dst + arg[i].len; | |
479 | |
480 for (src = dst; src < end; dst++) { | |
481 *dst = *src; | |
482 if (*src++ == '\\') { | |
483 *dst = *src++; | |
484 } | |
485 } | |
486 | |
487 arg[i].len = dst - arg[i].data; | |
488 } | |
489 | |
490 s->backslash = 0; | |
491 } | |
492 | |
527 | 493 switch (s->command) { |
494 | |
495 case NGX_IMAP_LOGIN: | |
583 | 496 |
497 #if (NGX_IMAP_SSL) | |
498 | |
499 if (c->ssl == NULL) { | |
500 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module); | |
501 | |
502 if (sslcf->starttls == NGX_IMAP_STARTTLS_ONLY) { | |
503 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
504 break; | |
505 } | |
506 } | |
507 #endif | |
508 | |
569 | 509 arg = s->args.elts; |
527 | 510 |
569 | 511 if (s->args.nelts == 2 && arg[0].len) { |
527 | 512 |
513 s->login.len = arg[0].len; | |
514 s->login.data = ngx_palloc(c->pool, s->login.len); | |
515 if (s->login.data == NULL) { | |
516 ngx_imap_session_internal_server_error(s); | |
517 return; | |
518 } | |
519 | |
520 ngx_memcpy(s->login.data, arg[0].data, s->login.len); | |
521 | |
522 s->passwd.len = arg[1].len; | |
523 s->passwd.data = ngx_palloc(c->pool, s->passwd.len); | |
524 if (s->passwd.data == NULL) { | |
525 ngx_imap_session_internal_server_error(s); | |
526 return; | |
527 } | |
528 | |
529 ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len); | |
530 | |
547 | 531 #if (NGX_DEBUG_IMAP_PASSWD) |
527 | 532 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0, |
533 "imap login:\"%V\" passwd:\"%V\"", | |
534 &s->login, &s->passwd); | |
547 | 535 #else |
536 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
537 "imap login:\"%V\"", &s->login); | |
538 #endif | |
527 | 539 |
540 s->args.nelts = 0; | |
541 s->buffer->pos = s->buffer->start; | |
542 s->buffer->last = s->buffer->start; | |
543 | |
544 if (rev->timer_set) { | |
545 ngx_del_timer(rev); | |
546 } | |
547 | |
548 s->login_attempt++; | |
549 | |
550 ngx_imap_auth_http_init(s); | |
551 | |
552 return; | |
553 } | |
554 | |
809 | 555 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
527 | 556 break; |
557 | |
558 case NGX_IMAP_CAPABILITY: | |
559 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
583 | 560 |
561 #if (NGX_IMAP_SSL) | |
562 | |
563 if (c->ssl == NULL) { | |
564 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module); | |
565 | |
566 if (sslcf->starttls == NGX_IMAP_STARTTLS_ON) { | |
567 text_len = cscf->imap_starttls_capability.len; | |
568 text = cscf->imap_starttls_capability.data; | |
569 break; | |
570 } | |
571 | |
572 if (sslcf->starttls == NGX_IMAP_STARTTLS_ONLY) { | |
573 text_len = cscf->imap_starttls_only_capability.len; | |
574 text = cscf->imap_starttls_only_capability.data; | |
575 break; | |
576 } | |
577 } | |
578 #endif | |
579 | |
580 text_len = cscf->imap_capability.len; | |
581 text = cscf->imap_capability.data; | |
527 | 582 break; |
583 | |
584 case NGX_IMAP_LOGOUT: | |
539 | 585 s->quit = 1; |
527 | 586 text = imap_bye; |
587 text_len = sizeof(imap_bye) - 1; | |
588 break; | |
589 | |
590 case NGX_IMAP_NOOP: | |
591 break; | |
592 | |
583 | 593 #if (NGX_IMAP_SSL) |
594 | |
595 case NGX_IMAP_STARTTLS: | |
596 if (c->ssl == NULL) { | |
597 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module); | |
598 if (sslcf->starttls) { | |
599 c->read->handler = ngx_imap_starttls_handler; | |
600 break; | |
601 } | |
602 } | |
603 | |
604 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
605 break; | |
606 #endif | |
607 | |
527 | 608 default: |
609 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
610 break; | |
611 } | |
612 | |
613 } else if (rc == NGX_IMAP_NEXT) { | |
614 last = imap_next; | |
615 last_len = sizeof(imap_next) - 1; | |
616 tag = 0; | |
617 } | |
618 | |
619 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) { | |
620 last = imap_invalid_command; | |
621 last_len = sizeof(imap_invalid_command) - 1; | |
622 } | |
623 | |
624 if (tag) { | |
543 | 625 if (s->tag.len == 0) { |
626 s->tag.len = sizeof(imap_star) - 1; | |
627 s->tag.data = (u_char *) imap_star; | |
628 } | |
629 | |
539 | 630 if (s->tagged_line.len < s->tag.len + text_len + last_len) { |
631 s->tagged_line.len = s->tag.len + text_len + last_len; | |
632 s->tagged_line.data = ngx_palloc(c->pool, s->tagged_line.len); | |
633 if (s->tagged_line.data == NULL) { | |
527 | 634 ngx_imap_close_connection(c); |
635 return; | |
636 } | |
637 } | |
638 | |
539 | 639 s->out.data = s->tagged_line.data; |
640 s->out.len = s->tag.len + text_len + last_len; | |
641 | |
642 p = s->out.data; | |
527 | 643 |
644 if (text) { | |
645 p = ngx_cpymem(p, text, text_len); | |
646 } | |
647 p = ngx_cpymem(p, s->tag.data, s->tag.len); | |
648 ngx_memcpy(p, last, last_len); | |
649 | |
650 | |
651 } else { | |
539 | 652 s->out.data = last; |
653 s->out.len = last_len; | |
527 | 654 } |
655 | |
539 | 656 if (rc != NGX_IMAP_NEXT) { |
657 s->args.nelts = 0; | |
658 s->buffer->pos = s->buffer->start; | |
659 s->buffer->last = s->buffer->start; | |
660 s->tag.len = 0; | |
527 | 661 } |
662 | |
539 | 663 ngx_imap_send(c->write); |
521 | 664 } |
665 | |
666 | |
527 | 667 void |
521 | 668 ngx_pop3_auth_state(ngx_event_t *rev) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
669 { |
809 | 670 u_char *text, *p, *last; |
527 | 671 ssize_t size; |
672 ngx_int_t rc; | |
809 | 673 ngx_str_t *arg, salt, plain; |
527 | 674 ngx_connection_t *c; |
675 ngx_imap_session_t *s; | |
676 ngx_imap_core_srv_conf_t *cscf; | |
583 | 677 #if (NGX_IMAP_SSL) |
678 ngx_imap_ssl_conf_t *sslcf; | |
679 #endif | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
680 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
681 c = rev->data; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
682 s = c->data; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
683 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
684 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state"); |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
685 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
686 if (rev->timedout) { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
687 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
577 | 688 c->timedout = 1; |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
689 ngx_imap_close_connection(c); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
690 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
691 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
692 |
539 | 693 if (s->out.len) { |
694 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap send handler busy"); | |
695 s->blocked = 1; | |
696 return; | |
697 } | |
698 | |
699 s->blocked = 0; | |
700 | |
527 | 701 rc = ngx_imap_read_command(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
702 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
703 if (rc == NGX_AGAIN || rc == NGX_ERROR) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
704 return; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
705 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
706 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
707 text = pop3_ok; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
708 size = sizeof(pop3_ok) - 1; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
709 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
710 if (rc == NGX_OK) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
711 switch (s->imap_state) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
712 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
713 case ngx_pop3_start: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
714 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
715 switch (s->command) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
716 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
717 case NGX_POP3_USER: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
718 if (s->args.nelts == 1) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
719 s->imap_state = ngx_pop3_user; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
720 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
721 arg = s->args.elts; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
722 s->login.len = arg[0].len; |
527 | 723 s->login.data = ngx_palloc(c->pool, s->login.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
724 if (s->login.data == NULL) { |
527 | 725 ngx_imap_session_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
726 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
727 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
728 |
527 | 729 ngx_memcpy(s->login.data, arg[0].data, s->login.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
730 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
731 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
527 | 732 "pop3 login: \"%V\"", &s->login); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
733 |
809 | 734 break; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
735 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
736 |
809 | 737 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
738 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
739 |
527 | 740 case NGX_POP3_CAPA: |
741 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
583 | 742 |
743 #if (NGX_IMAP_SSL) | |
744 | |
745 if (c->ssl == NULL) { | |
746 sslcf = ngx_imap_get_module_srv_conf(s, | |
747 ngx_imap_ssl_module); | |
748 if (sslcf->starttls) { | |
749 size = cscf->pop3_starttls_capability.len; | |
750 text = cscf->pop3_starttls_capability.data; | |
751 break; | |
752 } | |
753 } | |
754 #endif | |
755 | |
756 size = cscf->pop3_capability.len; | |
757 text = cscf->pop3_capability.data; | |
527 | 758 break; |
759 | |
800 | 760 case NGX_POP3_APOP: |
761 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
762 | |
763 if ((cscf->auth_methods & NGX_IMAP_AUTH_APOP_ENABLED) | |
764 && s->args.nelts == 2) | |
765 { | |
766 arg = s->args.elts; | |
767 | |
768 s->login.len = arg[0].len; | |
769 s->login.data = ngx_palloc(c->pool, s->login.len); | |
770 if (s->login.data == NULL) { | |
771 ngx_imap_session_internal_server_error(s); | |
772 return; | |
773 } | |
774 | |
775 ngx_memcpy(s->login.data, arg[0].data, s->login.len); | |
776 | |
777 s->passwd.len = arg[1].len; | |
778 s->passwd.data = ngx_palloc(c->pool, s->passwd.len); | |
779 if (s->passwd.data == NULL) { | |
780 ngx_imap_session_internal_server_error(s); | |
781 return; | |
782 } | |
783 | |
784 ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len); | |
785 | |
786 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
787 "pop3 apop: \"%V\" \"%V\"", | |
788 &s->login, &s->passwd); | |
789 | |
790 s->auth_method = NGX_IMAP_AUTH_APOP; | |
791 | |
792 s->args.nelts = 0; | |
793 s->buffer->pos = s->buffer->start; | |
794 s->buffer->last = s->buffer->start; | |
795 | |
796 if (rev->timer_set) { | |
797 ngx_del_timer(rev); | |
798 } | |
799 | |
800 ngx_imap_auth_http_init(s); | |
801 | |
802 return; | |
809 | 803 } |
800 | 804 |
809 | 805 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
806 break; | |
807 | |
808 case NGX_POP3_AUTH: | |
809 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
810 | |
811 if (s->args.nelts == 0) { | |
812 size = cscf->pop3_auth_capability.len; | |
813 text = cscf->pop3_auth_capability.data; | |
810 | 814 s->state = 0; |
809 | 815 break; |
816 } | |
817 | |
818 if (s->args.nelts != 1) { | |
800 | 819 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
809 | 820 break; |
800 | 821 } |
822 | |
809 | 823 arg = s->args.elts; |
824 | |
825 if (arg[0].len == 5) { | |
826 | |
827 if (ngx_strncasecmp(arg[0].data, "LOGIN", 5) == 0) { | |
828 s->imap_state = ngx_pop3_auth_login_username; | |
829 | |
830 size = sizeof(pop3_username) - 1; | |
831 text = pop3_username; | |
832 | |
833 break; | |
834 | |
835 } else if (ngx_strncasecmp(arg[0].data, "PLAIN", 5) == 0) { | |
836 s->imap_state = ngx_pop3_auth_plain; | |
837 | |
838 size = sizeof(pop3_next) - 1; | |
839 text = pop3_next; | |
840 | |
841 break; | |
842 } | |
843 | |
844 } else if (arg[0].len == 8 | |
845 && ngx_strncasecmp(arg[0].data, "CRAM-MD5", 8) == 0) | |
846 { | |
847 s->imap_state = ngx_pop3_auth_cram_md5; | |
848 | |
849 text = ngx_palloc(c->pool, | |
850 sizeof("+ " CRLF) - 1 | |
851 + ngx_base64_encoded_length(s->salt.len)); | |
852 if (text == NULL) { | |
853 ngx_imap_session_internal_server_error(s); | |
854 return; | |
855 } | |
856 | |
857 text[0] = '+'; text[1]= ' '; | |
858 salt.data = &text[2]; | |
859 s->salt.len -= 2; | |
860 | |
861 ngx_encode_base64(&salt, &s->salt); | |
862 | |
863 s->salt.len += 2; | |
864 size = 2 + salt.len; | |
865 text[size++] = CR; text[size++] = LF; | |
866 | |
867 break; | |
868 } | |
869 | |
870 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
800 | 871 break; |
872 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
873 case NGX_POP3_QUIT: |
539 | 874 s->quit = 1; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
875 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
876 |
527 | 877 case NGX_POP3_NOOP: |
878 break; | |
879 | |
583 | 880 #if (NGX_IMAP_SSL) |
881 | |
882 case NGX_POP3_STLS: | |
883 if (c->ssl == NULL) { | |
884 sslcf = ngx_imap_get_module_srv_conf(s, | |
885 ngx_imap_ssl_module); | |
886 if (sslcf->starttls) { | |
887 c->read->handler = ngx_imap_starttls_handler; | |
888 break; | |
889 } | |
890 } | |
891 | |
892 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
893 break; | |
894 #endif | |
895 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
896 default: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
897 s->imap_state = ngx_pop3_start; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
898 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
899 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
900 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
901 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
902 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
903 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
904 case ngx_pop3_user: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
905 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
906 switch (s->command) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
907 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
908 case NGX_POP3_PASS: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
909 if (s->args.nelts == 1) { |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
910 arg = s->args.elts; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
911 s->passwd.len = arg[0].len; |
527 | 912 s->passwd.data = ngx_palloc(c->pool, s->passwd.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
913 if (s->passwd.data == NULL) { |
527 | 914 ngx_imap_session_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
915 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
916 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
917 |
527 | 918 ngx_memcpy(s->passwd.data, arg[0].data, s->passwd.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
919 |
547 | 920 #if (NGX_DEBUG_IMAP_PASSWD) |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
921 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
527 | 922 "pop3 passwd: \"%V\"", &s->passwd); |
547 | 923 #endif |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
924 |
527 | 925 s->args.nelts = 0; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
926 s->buffer->pos = s->buffer->start; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
927 s->buffer->last = s->buffer->start; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
928 |
527 | 929 if (rev->timer_set) { |
930 ngx_del_timer(rev); | |
931 } | |
932 | |
521 | 933 ngx_imap_auth_http_init(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
934 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
935 return; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
936 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
937 |
809 | 938 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
939 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
940 |
527 | 941 case NGX_POP3_CAPA: |
942 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
583 | 943 size = cscf->pop3_capability.len; |
944 text = cscf->pop3_capability.data; | |
527 | 945 break; |
946 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
947 case NGX_POP3_QUIT: |
539 | 948 s->quit = 1; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
949 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
950 |
527 | 951 case NGX_POP3_NOOP: |
952 break; | |
953 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
954 default: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
955 s->imap_state = ngx_pop3_start; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
956 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
957 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
958 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
959 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
960 break; |
527 | 961 |
962 /* suppress warinings */ | |
963 case ngx_pop3_passwd: | |
964 break; | |
809 | 965 |
966 case ngx_pop3_auth_login_username: | |
967 arg = s->args.elts; | |
968 s->imap_state = ngx_pop3_auth_login_password; | |
969 | |
970 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
971 "pop3 auth login username: \"%V\"", &arg[0]); | |
972 | |
973 s->login.data = ngx_palloc(c->pool, | |
974 ngx_base64_decoded_length(arg[0].len)); | |
975 if (s->login.data == NULL){ | |
976 ngx_imap_session_internal_server_error(s); | |
977 return; | |
978 } | |
979 | |
980 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) { | |
981 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
982 "client sent invalid base64 encoding " | |
983 "in AUTH LOGIN command"); | |
810 | 984 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
985 break; | |
809 | 986 } |
987 | |
988 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
989 "pop3 auth login username: \"%V\"", &s->login); | |
990 | |
991 size = sizeof(pop3_password) - 1; | |
992 text = pop3_password; | |
993 | |
994 break; | |
995 | |
996 case ngx_pop3_auth_login_password: | |
997 arg = s->args.elts; | |
998 | |
999 #if (NGX_DEBUG_IMAP_PASSWD) | |
1000 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
1001 "pop3 auth login password: \"%V\"", &arg[0]); | |
1002 #endif | |
1003 | |
1004 s->passwd.data = ngx_palloc(c->pool, | |
1005 ngx_base64_decoded_length(arg[0].len)); | |
1006 if (s->passwd.data == NULL){ | |
1007 ngx_imap_session_internal_server_error(s); | |
1008 return; | |
1009 } | |
1010 | |
1011 if (ngx_decode_base64(&s->passwd, &arg[0]) != NGX_OK) { | |
1012 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
1013 "client sent invalid base64 encoding " | |
1014 "in AUTH LOGIN command"); | |
810 | 1015 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
1016 break; | |
809 | 1017 } |
1018 | |
1019 #if (NGX_DEBUG_IMAP_PASSWD) | |
1020 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
1021 "pop3 auth login password: \"%V\"", &s->passwd); | |
1022 #endif | |
1023 | |
1024 s->args.nelts = 0; | |
1025 s->buffer->pos = s->buffer->start; | |
1026 s->buffer->last = s->buffer->start; | |
1027 | |
1028 if (rev->timer_set) { | |
1029 ngx_del_timer(rev); | |
1030 } | |
1031 | |
1032 ngx_imap_auth_http_init(s); | |
1033 | |
1034 return; | |
1035 | |
1036 case ngx_pop3_auth_plain: | |
1037 arg = s->args.elts; | |
1038 | |
1039 #if (NGX_DEBUG_IMAP_PASSWD) | |
1040 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
1041 "pop3 auth plain: \"%V\"", &arg[0]); | |
1042 #endif | |
1043 | |
1044 plain.data = ngx_palloc(c->pool, | |
1045 ngx_base64_decoded_length(arg[0].len)); | |
1046 if (plain.data == NULL){ | |
1047 ngx_imap_session_internal_server_error(s); | |
1048 return; | |
1049 } | |
1050 | |
1051 if (ngx_decode_base64(&plain, &arg[0]) != NGX_OK) { | |
1052 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
1053 "client sent invalid base64 encoding " | |
1054 "in AUTH PLAIN command"); | |
810 | 1055 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
1056 break; | |
809 | 1057 } |
1058 | |
1059 p = plain.data; | |
1060 last = p + plain.len; | |
1061 | |
1062 while (p < last && *p++) { /* void */ } | |
1063 | |
810 | 1064 if (p == last) { |
1065 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
814 | 1066 "client sent invalid login " |
810 | 1067 "in AUTH PLAIN command"); |
1068 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
1069 break; | |
1070 } | |
1071 | |
809 | 1072 s->login.data = p; |
1073 | |
1074 while (p < last && *p) { p++; } | |
1075 | |
810 | 1076 if (p == last) { |
1077 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
814 | 1078 "client sent invalid password " |
810 | 1079 "in AUTH PLAIN command"); |
1080 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
1081 break; | |
1082 } | |
809 | 1083 |
810 | 1084 s->login.len = p++ - s->login.data; |
809 | 1085 |
810 | 1086 s->passwd.len = last - p; |
1087 s->passwd.data = p; | |
809 | 1088 |
1089 #if (NGX_DEBUG_IMAP_PASSWD) | |
1090 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
1091 "pop3 auth plain: \"%V\" \"%V\"", | |
1092 &s->login, &s->passwd); | |
1093 #endif | |
1094 | |
1095 s->args.nelts = 0; | |
1096 s->buffer->pos = s->buffer->start; | |
1097 s->buffer->last = s->buffer->start; | |
1098 | |
1099 if (rev->timer_set) { | |
1100 ngx_del_timer(rev); | |
1101 } | |
1102 | |
1103 ngx_imap_auth_http_init(s); | |
1104 | |
1105 return; | |
1106 | |
1107 case ngx_pop3_auth_cram_md5: | |
1108 arg = s->args.elts; | |
1109 | |
1110 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
1111 "pop3 auth cram-md5: \"%V\"", &arg[0]); | |
1112 | |
1113 s->login.data = ngx_palloc(c->pool, | |
1114 ngx_base64_decoded_length(arg[0].len)); | |
1115 if (s->login.data == NULL){ | |
1116 ngx_imap_session_internal_server_error(s); | |
1117 return; | |
1118 } | |
1119 | |
1120 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) { | |
1121 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
1122 "client sent invalid base64 encoding " | |
810 | 1123 "in AUTH CRAM-MD5 command"); |
1124 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
1125 break; | |
809 | 1126 } |
1127 | |
1128 p = s->login.data; | |
1129 last = p + s->login.len; | |
1130 | |
1131 while (p < last) { | |
1132 if (*p++ == ' ') { | |
1133 s->login.len = p - s->login.data - 1; | |
1134 s->passwd.len = last - p; | |
1135 s->passwd.data = p; | |
1136 break; | |
1137 } | |
1138 } | |
1139 | |
810 | 1140 if (s->passwd.len != 32) { |
1141 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
1142 "client sent invalid CRAM-MD5 hash " | |
1143 "in AUTH CRAM-MD5 command"); | |
1144 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
1145 break; | |
1146 } | |
1147 | |
809 | 1148 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0, |
1149 "pop3 auth cram-md5: \"%V\" \"%V\"", | |
1150 &s->login, &s->passwd); | |
1151 | |
1152 s->auth_method = NGX_IMAP_AUTH_CRAM_MD5; | |
1153 | |
1154 s->args.nelts = 0; | |
1155 s->buffer->pos = s->buffer->start; | |
1156 s->buffer->last = s->buffer->start; | |
1157 | |
1158 if (rev->timer_set) { | |
1159 ngx_del_timer(rev); | |
1160 } | |
1161 | |
1162 ngx_imap_auth_http_init(s); | |
1163 | |
1164 return; | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
1165 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
1166 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1167 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1168 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) { |
810 | 1169 s->imap_state = ngx_pop3_start; |
1170 s->state = 0; | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1171 text = pop3_invalid_command; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1172 size = sizeof(pop3_invalid_command) - 1; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1173 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1174 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
1175 s->args.nelts = 0; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
1176 s->buffer->pos = s->buffer->start; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
1177 s->buffer->last = s->buffer->start; |
539 | 1178 |
810 | 1179 if (s->state) { |
1180 s->arg_start = s->buffer->start; | |
1181 } | |
1182 | |
539 | 1183 s->out.data = text; |
1184 s->out.len = size; | |
1185 | |
1186 ngx_imap_send(c->write); | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1187 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1188 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1189 |
521 | 1190 static ngx_int_t |
527 | 1191 ngx_imap_read_command(ngx_imap_session_t *s) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1192 { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1193 ssize_t n; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1194 ngx_int_t rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1195 |
539 | 1196 n = s->connection->recv(s->connection, s->buffer->last, |
1197 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
|
1198 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1199 if (n == NGX_ERROR || n == 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1200 ngx_imap_close_connection(s->connection); |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1201 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1202 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1203 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1204 if (n > 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1205 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
|
1206 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1207 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1208 if (n == NGX_AGAIN) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1209 if (ngx_handle_read_event(s->connection->read, 0) == NGX_ERROR) { |
527 | 1210 ngx_imap_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
|
1211 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1212 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1213 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1214 return NGX_AGAIN; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1215 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1216 |
527 | 1217 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) { |
1218 rc = ngx_pop3_parse_command(s); | |
1219 } else { | |
1220 rc = ngx_imap_parse_command(s); | |
1221 } | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1222 |
527 | 1223 if (rc == NGX_AGAIN |
1224 || rc == NGX_IMAP_NEXT | |
1225 || rc == NGX_IMAP_PARSE_INVALID_COMMAND) | |
1226 { | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1227 return rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1228 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1229 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1230 if (rc == NGX_ERROR) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1231 ngx_imap_close_connection(s->connection); |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1232 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1233 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1234 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1235 return NGX_OK; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1236 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1237 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1238 |
521 | 1239 void |
525 | 1240 ngx_imap_session_internal_server_error(ngx_imap_session_t *s) |
1241 { | |
539 | 1242 s->out = internal_server_errors[s->protocol]; |
1243 s->quit = 1; | |
525 | 1244 |
539 | 1245 ngx_imap_send(s->connection->write); |
525 | 1246 } |
1247 | |
1248 | |
1249 void | |
521 | 1250 ngx_imap_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
|
1251 { |
479 | 1252 ngx_pool_t *pool; |
1253 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1254 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1255 "close imap connection: %d", c->fd); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1256 |
539 | 1257 #if (NGX_IMAP_SSL) |
1258 | |
1259 if (c->ssl) { | |
1260 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
577 | 1261 c->ssl->handler = ngx_imap_close_connection; |
539 | 1262 return; |
1263 } | |
1264 } | |
1265 | |
1266 #endif | |
1267 | |
583 | 1268 c->destroyed = 1; |
543 | 1269 |
479 | 1270 pool = c->pool; |
1271 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1272 ngx_close_connection(c); |
479 | 1273 |
501 | 1274 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
|
1275 } |
539 | 1276 |
1277 | |
541 | 1278 static u_char * |
1279 ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
1280 { | |
567 | 1281 u_char *p; |
1282 ngx_imap_session_t *s; | |
1283 ngx_imap_log_ctx_t *ctx; | |
541 | 1284 |
1285 if (log->action) { | |
1286 p = ngx_snprintf(buf, len, " while %s", log->action); | |
1287 len -= p - buf; | |
1288 buf = p; | |
1289 } | |
577 | 1290 |
541 | 1291 ctx = log->data; |
1292 | |
1293 p = ngx_snprintf(buf, len, ", client: %V", ctx->client); | |
1294 len -= p - buf; | |
1295 buf = p; | |
1296 | |
1297 s = ctx->session; | |
1298 | |
1299 if (s == NULL) { | |
1300 return p; | |
1301 } | |
1302 | |
641 | 1303 p = ngx_snprintf(buf, len, ", server: %V", s->addr_text); |
541 | 1304 len -= p - buf; |
1305 buf = p; | |
1306 | |
1307 if (s->login.len == 0) { | |
1308 return p; | |
1309 } | |
1310 | |
1311 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login); | |
1312 len -= p - buf; | |
1313 buf = p; | |
1314 | |
1315 if (s->proxy == NULL) { | |
1316 return p; | |
1317 } | |
1318 | |
1319 p = ngx_snprintf(buf, len, ", upstream: %V", | |
1320 &s->proxy->upstream.peers->peer[0].name); | |
1321 | |
1322 return p; | |
1323 } |