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