Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_handler.c @ 6760:9d61ecbe979e stable-1.10
HTTP/2: prevented output of the HEADERS frame for canceled streams.
It's useless to generate HEADERS if the stream has been canceled already.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 19 Jul 2016 20:22:44 +0300 |
parents | fc99323a3d79 |
children | bcb107bb89cd |
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); | |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
19 static ngx_int_t ngx_mail_verify_cert(ngx_mail_session_t *s, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
20 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 void |
1136 | 25 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
|
26 { |
6130 | 27 size_t len; |
28 ngx_uint_t i; | |
29 ngx_mail_port_t *port; | |
30 struct sockaddr *sa; | |
31 struct sockaddr_in *sin; | |
32 ngx_mail_log_ctx_t *ctx; | |
33 ngx_mail_in_addr_t *addr; | |
34 ngx_mail_session_t *s; | |
35 ngx_mail_addr_conf_t *addr_conf; | |
36 ngx_mail_core_srv_conf_t *cscf; | |
37 u_char text[NGX_SOCKADDR_STRLEN]; | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
38 #if (NGX_HAVE_INET6) |
6130 | 39 struct sockaddr_in6 *sin6; |
40 ngx_mail_in6_addr_t *addr6; | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
41 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
42 |
641 | 43 |
44 /* find the server configuration for the address:port */ | |
45 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
46 port = c->listening->servers; |
641 | 47 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
48 if (port->naddrs > 1) { |
641 | 49 |
50 /* | |
51 * There are several addresses on this port and one of them | |
52 * is the "*:port" wildcard so getsockname() is needed to determine | |
53 * the server address. | |
54 * | |
55 * AcceptEx() already gave this address. | |
56 */ | |
57 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
58 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
|
59 ngx_mail_close_connection(c); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
60 return; |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
63 sa = c->local_sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
64 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
65 switch (sa->sa_family) { |
541 | 66 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
67 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
68 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
69 sin6 = (struct sockaddr_in6 *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
70 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
71 addr6 = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
72 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
73 /* the last address is "*" */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
74 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
75 for (i = 0; i < port->naddrs - 1; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
76 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
|
77 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
78 } |
641 | 79 } |
80 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
81 addr_conf = &addr6[i].conf; |
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 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
84 #endif |
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 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
87 sin = (struct sockaddr_in *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
88 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
89 addr = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
90 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
91 /* the last address is "*" */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
92 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
93 for (i = 0; i < port->naddrs - 1; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
94 if (addr[i].addr == sin->sin_addr.s_addr) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
95 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
96 } |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
99 addr_conf = &addr[i].conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
100 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
101 break; |
641 | 102 } |
103 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
104 } else { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
105 switch (c->local_sockaddr->sa_family) { |
641 | 106 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
107 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
108 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
109 addr6 = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
110 addr_conf = &addr6[0].conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
111 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
112 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
113 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
114 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
115 addr = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
116 addr_conf = &addr[0].conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
117 break; |
641 | 118 } |
119 } | |
120 | |
1136 | 121 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t)); |
641 | 122 if (s == NULL) { |
1136 | 123 ngx_mail_close_connection(c); |
541 | 124 return; |
577 | 125 } |
541 | 126 |
5819
8e7ee4c70a3c
Mail: initialize the "signature" field of ngx_mail_session_t.
Valentin Bartenev <vbart@nginx.com>
parents:
5705
diff
changeset
|
127 s->signature = NGX_MAIL_MODULE; |
8e7ee4c70a3c
Mail: initialize the "signature" field of ngx_mail_session_t.
Valentin Bartenev <vbart@nginx.com>
parents:
5705
diff
changeset
|
128 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
129 s->main_conf = addr_conf->ctx->main_conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
130 s->srv_conf = addr_conf->ctx->srv_conf; |
641 | 131 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
132 s->addr_text = &addr_conf->addr_text; |
641 | 133 |
134 c->data = s; | |
135 s->connection = c; | |
136 | |
6130 | 137 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
138 | |
139 ngx_set_connection_log(c, cscf->error_log); | |
140 | |
5705
d5b8ee9f2201
Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents:
5632
diff
changeset
|
141 len = ngx_sock_ntop(c->sockaddr, c->socklen, text, NGX_SOCKADDR_STRLEN, 1); |
d5b8ee9f2201
Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents:
5632
diff
changeset
|
142 |
d5b8ee9f2201
Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents:
5632
diff
changeset
|
143 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %*s connected to %V", |
d5b8ee9f2201
Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents:
5632
diff
changeset
|
144 c->number, len, text, s->addr_text); |
641 | 145 |
1136 | 146 ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t)); |
641 | 147 if (ctx == NULL) { |
1136 | 148 ngx_mail_close_connection(c); |
641 | 149 return; |
150 } | |
151 | |
152 ctx->client = &c->addr_text; | |
153 ctx->session = s; | |
541 | 154 |
155 c->log->connection = c->number; | |
1136 | 156 c->log->handler = ngx_mail_log_error; |
641 | 157 c->log->data = ctx; |
541 | 158 c->log->action = "sending client greeting line"; |
159 | |
160 c->log_error = NGX_ERROR_INFO; | |
161 | |
1136 | 162 #if (NGX_MAIL_SSL) |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
163 { |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
164 ngx_mail_ssl_conf_t *sslcf; |
543 | 165 |
1136 | 166 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
543 | 167 |
168 if (sslcf->enable) { | |
2224 | 169 c->log->action = "SSL handshaking"; |
170 | |
1136 | 171 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
547 | 172 return; |
543 | 173 } |
2224 | 174 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
175 if (addr_conf->ssl) { |
2224 | 176 |
177 c->log->action = "SSL handshaking"; | |
178 | |
179 if (sslcf->ssl.ctx == NULL) { | |
180 ngx_log_error(NGX_LOG_ERR, c->log, 0, | |
181 "no \"ssl_certificate\" is defined " | |
182 "in server listening on SSL port"); | |
183 ngx_mail_close_connection(c); | |
184 return; | |
185 } | |
186 | |
187 ngx_mail_ssl_init_connection(&sslcf->ssl, c); | |
188 return; | |
189 } | |
190 | |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
191 } |
543 | 192 #endif |
193 | |
1136 | 194 ngx_mail_init_session(c); |
541 | 195 } |
196 | |
197 | |
1136 | 198 #if (NGX_MAIL_SSL) |
547 | 199 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
200 void |
1136 | 201 ngx_mail_starttls_handler(ngx_event_t *rev) |
583 | 202 { |
203 ngx_connection_t *c; | |
1136 | 204 ngx_mail_session_t *s; |
205 ngx_mail_ssl_conf_t *sslcf; | |
583 | 206 |
207 c = rev->data; | |
208 s = c->data; | |
641 | 209 s->starttls = 1; |
583 | 210 |
211 c->log->action = "in starttls state"; | |
212 | |
1136 | 213 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
583 | 214 |
1136 | 215 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
583 | 216 } |
217 | |
218 | |
219 static void | |
1136 | 220 ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c) |
583 | 221 { |
1136 | 222 ngx_mail_session_t *s; |
223 ngx_mail_core_srv_conf_t *cscf; | |
583 | 224 |
225 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) { | |
1136 | 226 ngx_mail_close_connection(c); |
583 | 227 return; |
228 } | |
229 | |
230 if (ngx_ssl_handshake(c) == NGX_AGAIN) { | |
231 | |
641 | 232 s = c->data; |
233 | |
1136 | 234 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
583 | 235 |
236 ngx_add_timer(c->read, cscf->timeout); | |
237 | |
1136 | 238 c->ssl->handler = ngx_mail_ssl_handshake_handler; |
583 | 239 |
240 return; | |
241 } | |
242 | |
1136 | 243 ngx_mail_ssl_handshake_handler(c); |
583 | 244 } |
245 | |
246 | |
247 static void | |
1136 | 248 ngx_mail_ssl_handshake_handler(ngx_connection_t *c) |
577 | 249 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
250 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
|
251 ngx_mail_core_srv_conf_t *cscf; |
641 | 252 |
547 | 253 if (c->ssl->handshaked) { |
583 | 254 |
641 | 255 s = c->data; |
256 | |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
257 if (ngx_mail_verify_cert(s, c) != NGX_OK) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
258 return; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
259 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
260 |
641 | 261 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
|
262 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
|
263 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
264 c->read->handler = cscf->protocol->init_protocol; |
1136 | 265 c->write->handler = ngx_mail_send; |
583 | 266 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
267 cscf->protocol->init_protocol(c->read); |
583 | 268 |
269 return; | |
270 } | |
271 | |
2165
cbf6f2eb57ad
backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
272 c->read->ready = 0; |
cbf6f2eb57ad
backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
273 |
1136 | 274 ngx_mail_init_session(c); |
547 | 275 return; |
276 } | |
277 | |
1136 | 278 ngx_mail_close_connection(c); |
547 | 279 } |
280 | |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
281 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
282 static ngx_int_t |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
283 ngx_mail_verify_cert(ngx_mail_session_t *s, ngx_connection_t *c) |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
284 { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
285 long rc; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
286 X509 *cert; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
287 ngx_mail_ssl_conf_t *sslcf; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
288 ngx_mail_core_srv_conf_t *cscf; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
289 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
290 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
291 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
292 if (!sslcf->verify) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
293 return NGX_OK; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
294 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
295 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
296 rc = SSL_get_verify_result(c->ssl->connection); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
297 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
298 if (rc != X509_V_OK |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
299 && (sslcf->verify != 3 || !ngx_ssl_verify_error_optional(rc))) |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
300 { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
301 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
302 "client SSL certificate verify error: (%l:%s)", |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
303 rc, X509_verify_cert_error_string(rc)); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
304 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
305 ngx_ssl_remove_cached_session(sslcf->ssl.ctx, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
306 (SSL_get0_session(c->ssl->connection))); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
307 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
308 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
309 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
310 s->out = cscf->protocol->cert_error; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
311 s->quit = 1; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
312 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
313 c->write->handler = ngx_mail_send; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
314 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
315 ngx_mail_send(s->connection->write); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
316 return NGX_ERROR; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
317 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
318 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
319 if (sslcf->verify == 1) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
320 cert = SSL_get_peer_certificate(c->ssl->connection); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
321 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
322 if (cert == NULL) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
323 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
324 "client sent no required SSL certificate"); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
325 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
326 ngx_ssl_remove_cached_session(sslcf->ssl.ctx, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
327 (SSL_get0_session(c->ssl->connection))); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
328 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
329 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
330 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
331 s->out = cscf->protocol->no_cert; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
332 s->quit = 1; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
333 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
334 c->write->handler = ngx_mail_send; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
335 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
336 ngx_mail_send(s->connection->write); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
337 return NGX_ERROR; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
338 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
339 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
340 X509_free(cert); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
341 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
342 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
343 return NGX_OK; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
344 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
345 |
547 | 346 #endif |
347 | |
348 | |
349 static void | |
1136 | 350 ngx_mail_init_session(ngx_connection_t *c) |
541 | 351 { |
1136 | 352 ngx_mail_session_t *s; |
353 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
|
354 |
641 | 355 s = c->data; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
356 |
1136 | 357 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
539 | 358 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
359 s->protocol = cscf->protocol->type; |
539 | 360 |
1136 | 361 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module); |
539 | 362 if (s->ctx == NULL) { |
1136 | 363 ngx_mail_session_internal_server_error(s); |
539 | 364 return; |
365 } | |
366 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
367 c->write->handler = ngx_mail_send; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
368 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
369 cscf->protocol->init_session(s, c); |
1476
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 |
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 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
374 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
|
375 ngx_mail_core_srv_conf_t *cscf) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
376 { |
2049 | 377 s->salt.data = ngx_pnalloc(c->pool, |
378 sizeof(" <18446744073709551616.@>" CRLF) - 1 | |
379 + NGX_TIME_T_LEN | |
380 + cscf->server_name.len); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
381 if (s->salt.data == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
382 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
383 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
384 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
385 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
|
386 ngx_random(), ngx_time(), &cscf->server_name) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
387 - s->salt.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
388 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
389 return NGX_OK; |
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 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
392 |
1479 | 393 #if (NGX_MAIL_SSL) |
394 | |
395 ngx_int_t | |
396 ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c) | |
397 { | |
398 ngx_mail_ssl_conf_t *sslcf; | |
399 | |
400 if (c->ssl) { | |
401 return 0; | |
402 } | |
403 | |
404 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); | |
405 | |
406 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) { | |
407 return 1; | |
408 } | |
409 | |
410 return 0; | |
411 } | |
412 | |
413 #endif | |
414 | |
415 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
416 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
417 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
|
418 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
419 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
420 ngx_str_t *arg, plain; |
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 arg = s->args.elts; |
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 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
425 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
|
426 "mail auth plain: \"%V\"", &arg[n]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
427 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
428 |
2049 | 429 plain.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
3642 | 430 if (plain.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
431 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
432 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
433 |
1494
6535fb51976a
fix "AUTH PLAIN [initial-response]" bug introduced in r1477
Igor Sysoev <igor@sysoev.ru>
parents:
1491
diff
changeset
|
434 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
|
435 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
|
436 "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
|
437 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
438 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
439 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
440 p = plain.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
441 last = p + plain.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
442 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
443 while (p < last && *p++) { /* void */ } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
444 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
445 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
446 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
|
447 "client sent invalid login in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
448 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
449 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
450 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
451 s->login.data = p; |
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 while (p < last && *p) { p++; } |
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 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
456 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
|
457 "client sent invalid password in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
458 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
459 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
460 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
461 s->login.len = p++ - s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
462 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
463 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
464 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
465 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
466 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
467 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
|
468 "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
|
469 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
470 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
471 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
472 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
473 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
474 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
475 ngx_int_t |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
476 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
|
477 ngx_uint_t n) |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
478 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
479 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
480 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
481 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
482 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
483 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
|
484 "mail auth login username: \"%V\"", &arg[n]); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
485 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
486 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
3642 | 487 if (s->login.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
488 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
489 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
490 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
491 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
|
492 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
|
493 "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
|
494 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
495 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
496 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
497 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
|
498 "mail auth login username: \"%V\"", &s->login); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
499 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
500 return NGX_OK; |
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 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
503 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
504 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
505 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
|
506 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
507 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
508 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
509 arg = s->args.elts; |
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 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
512 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
|
513 "mail auth login password: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
514 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
515 |
2049 | 516 s->passwd.data = ngx_pnalloc(c->pool, |
517 ngx_base64_decoded_length(arg[0].len)); | |
3642 | 518 if (s->passwd.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
519 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
520 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
521 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
522 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
|
523 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
|
524 "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
|
525 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
526 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
527 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
528 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
529 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
|
530 "mail auth login password: \"%V\"", &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
531 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
532 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
533 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
534 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
535 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
536 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
537 ngx_int_t |
1479 | 538 ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
539 char *prefix, size_t len) | |
540 { | |
541 u_char *p; | |
542 ngx_str_t salt; | |
543 ngx_uint_t n; | |
544 | |
2049 | 545 p = ngx_pnalloc(c->pool, len + ngx_base64_encoded_length(s->salt.len) + 2); |
1479 | 546 if (p == NULL) { |
547 return NGX_ERROR; | |
548 } | |
549 | |
550 salt.data = ngx_cpymem(p, prefix, len); | |
551 s->salt.len -= 2; | |
552 | |
553 ngx_encode_base64(&salt, &s->salt); | |
554 | |
555 s->salt.len += 2; | |
556 n = len + salt.len; | |
557 p[n++] = CR; p[n++] = LF; | |
558 | |
559 s->out.len = n; | |
560 s->out.data = p; | |
561 | |
562 return NGX_OK; | |
563 } | |
564 | |
565 | |
566 ngx_int_t | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
567 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
|
568 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
569 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
570 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
571 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
572 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
573 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
574 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
|
575 "mail auth cram-md5: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
576 |
2049 | 577 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len)); |
3642 | 578 if (s->login.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
579 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
580 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
581 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
582 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
|
583 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
|
584 "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
|
585 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
586 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
587 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
588 p = s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
589 last = p + s->login.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
590 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
591 while (p < last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
592 if (*p++ == ' ') { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
593 s->login.len = p - s->login.data - 1; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
594 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
595 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
596 break; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
597 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
598 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
599 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
600 if (s->passwd.len != 32) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
601 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
|
602 "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
|
603 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
604 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
605 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
606 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
|
607 "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
|
608 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
609 s->auth_method = NGX_MAIL_AUTH_CRAM_MD5; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
610 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
611 return NGX_DONE; |
539 | 612 } |
613 | |
614 | |
615 void | |
1136 | 616 ngx_mail_send(ngx_event_t *wev) |
539 | 617 { |
541 | 618 ngx_int_t n; |
619 ngx_connection_t *c; | |
1136 | 620 ngx_mail_session_t *s; |
621 ngx_mail_core_srv_conf_t *cscf; | |
539 | 622 |
623 c = wev->data; | |
624 s = c->data; | |
625 | |
626 if (wev->timedout) { | |
627 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 628 c->timedout = 1; |
1136 | 629 ngx_mail_close_connection(c); |
539 | 630 return; |
631 } | |
632 | |
633 if (s->out.len == 0) { | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
634 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
1136 | 635 ngx_mail_close_connection(c); |
539 | 636 } |
637 | |
638 return; | |
639 } | |
640 | |
641 n = c->send(c, s->out.data, s->out.len); | |
642 | |
643 if (n > 0) { | |
5632
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
644 s->out.data += n; |
539 | 645 s->out.len -= n; |
646 | |
5632
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
647 if (s->out.len != 0) { |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
648 goto again; |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
649 } |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
650 |
541 | 651 if (wev->timer_set) { |
652 ngx_del_timer(wev); | |
653 } | |
654 | |
539 | 655 if (s->quit) { |
1136 | 656 ngx_mail_close_connection(c); |
539 | 657 return; |
658 } | |
659 | |
660 if (s->blocked) { | |
661 c->read->handler(c->read); | |
662 } | |
663 | |
664 return; | |
665 } | |
666 | |
667 if (n == NGX_ERROR) { | |
1136 | 668 ngx_mail_close_connection(c); |
539 | 669 return; |
670 } | |
671 | |
672 /* n == NGX_AGAIN */ | |
673 | |
5632
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
674 again: |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
675 |
1136 | 676 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
541 | 677 |
678 ngx_add_timer(c->write, cscf->timeout); | |
679 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
680 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
1136 | 681 ngx_mail_close_connection(c); |
539 | 682 return; |
683 } | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
684 } |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
685 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
686 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
687 ngx_int_t |
1482 | 688 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
|
689 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
690 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
|
691 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
|
692 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
|
693 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
|
694 |
1482 | 695 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
|
696 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
697 if (n == NGX_ERROR || n == 0) { |
1482 | 698 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
|
699 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
700 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
701 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
702 if (n > 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
703 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
|
704 } |
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 if (n == NGX_AGAIN) { |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
707 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
1136 | 708 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
|
709 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
710 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
711 |
5398
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
712 if (s->buffer->pos == s->buffer->last) { |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
713 return NGX_AGAIN; |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
714 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
715 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
716 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
717 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
|
718 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
719 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
|
720 |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
721 if (rc == NGX_AGAIN) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
722 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
723 if (s->buffer->last < s->buffer->end) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
724 return rc; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
725 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
726 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
727 l.len = s->buffer->last - s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
728 l.data = s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
729 |
1482 | 730 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
|
731 "client sent too long command \"%V\"", &l); |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
732 |
1111
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
733 s->quit = 1; |
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
734 |
1136 | 735 return NGX_MAIL_PARSE_INVALID_COMMAND; |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
736 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
737 |
1136 | 738 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
|
739 return rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
740 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
741 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
742 if (rc == NGX_ERROR) { |
1482 | 743 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
|
744 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
745 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
746 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
747 return NGX_OK; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
748 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
749 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
750 |
521 | 751 void |
1482 | 752 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
|
753 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
754 s->args.nelts = 0; |
5398
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
755 |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
756 if (s->buffer->pos == s->buffer->last) { |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
757 s->buffer->pos = s->buffer->start; |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
758 s->buffer->last = s->buffer->start; |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
759 } |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
760 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
761 s->state = 0; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
762 |
1482 | 763 if (c->read->timer_set) { |
764 ngx_del_timer(c->read); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
765 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
766 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
767 s->login_attempt++; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
768 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
769 ngx_mail_auth_http_init(s); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
770 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
771 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
772 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
773 void |
1136 | 774 ngx_mail_session_internal_server_error(ngx_mail_session_t *s) |
525 | 775 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
776 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
|
777 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
778 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
|
779 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
780 s->out = cscf->protocol->internal_server_error; |
539 | 781 s->quit = 1; |
525 | 782 |
1136 | 783 ngx_mail_send(s->connection->write); |
525 | 784 } |
785 | |
786 | |
787 void | |
1136 | 788 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
|
789 { |
479 | 790 ngx_pool_t *pool; |
791 | |
1136 | 792 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
793 "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
|
794 |
1136 | 795 #if (NGX_MAIL_SSL) |
539 | 796 |
797 if (c->ssl) { | |
798 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
1136 | 799 c->ssl->handler = ngx_mail_close_connection; |
539 | 800 return; |
801 } | |
802 } | |
803 | |
804 #endif | |
805 | |
1472
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
806 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2855
diff
changeset
|
807 (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
|
808 #endif |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
809 |
583 | 810 c->destroyed = 1; |
543 | 811 |
479 | 812 pool = c->pool; |
813 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
814 ngx_close_connection(c); |
479 | 815 |
501 | 816 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
|
817 } |
539 | 818 |
819 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
820 u_char * |
1136 | 821 ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len) |
541 | 822 { |
567 | 823 u_char *p; |
1136 | 824 ngx_mail_session_t *s; |
825 ngx_mail_log_ctx_t *ctx; | |
541 | 826 |
827 if (log->action) { | |
828 p = ngx_snprintf(buf, len, " while %s", log->action); | |
829 len -= p - buf; | |
830 buf = p; | |
831 } | |
577 | 832 |
541 | 833 ctx = log->data; |
834 | |
835 p = ngx_snprintf(buf, len, ", client: %V", ctx->client); | |
836 len -= p - buf; | |
837 buf = p; | |
838 | |
839 s = ctx->session; | |
840 | |
841 if (s == NULL) { | |
842 return p; | |
843 } | |
844 | |
1491 | 845 p = ngx_snprintf(buf, len, "%s, server: %V", |
846 s->starttls ? " using starttls" : "", | |
847 s->addr_text); | |
541 | 848 len -= p - buf; |
849 buf = p; | |
850 | |
851 if (s->login.len == 0) { | |
852 return p; | |
853 } | |
854 | |
855 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login); | |
856 len -= p - buf; | |
857 buf = p; | |
858 | |
859 if (s->proxy == NULL) { | |
860 return p; | |
861 } | |
862 | |
884 | 863 p = ngx_snprintf(buf, len, ", upstream: %V", s->proxy->upstream.name); |
541 | 864 |
865 return p; | |
866 } |