Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_handler.c @ 8606:062080651d50 quic
Changed the OpenSSL QUIC support detection.
As was changed in 253cf267f95a.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 09 Sep 2021 15:34:00 +0300 |
parents | ec1071830799 |
children |
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 |
8343
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
14 static void ngx_mail_proxy_protocol_handler(ngx_event_t *rev); |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
15 static void ngx_mail_init_session_handler(ngx_event_t *rev); |
1136 | 16 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
|
17 |
1136 | 18 #if (NGX_MAIL_SSL) |
19 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); | |
20 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
|
21 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
|
22 ngx_connection_t *c); |
539 | 23 #endif |
24 | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
521 | 26 void |
1136 | 27 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
|
28 { |
6130 | 29 size_t len; |
30 ngx_uint_t i; | |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
31 ngx_event_t *rev; |
6130 | 32 ngx_mail_port_t *port; |
33 struct sockaddr *sa; | |
34 struct sockaddr_in *sin; | |
35 ngx_mail_log_ctx_t *ctx; | |
36 ngx_mail_in_addr_t *addr; | |
37 ngx_mail_session_t *s; | |
38 ngx_mail_addr_conf_t *addr_conf; | |
39 ngx_mail_core_srv_conf_t *cscf; | |
40 u_char text[NGX_SOCKADDR_STRLEN]; | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
41 #if (NGX_HAVE_INET6) |
6130 | 42 struct sockaddr_in6 *sin6; |
43 ngx_mail_in6_addr_t *addr6; | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
44 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
45 |
641 | 46 |
47 /* find the server configuration for the address:port */ | |
48 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
49 port = c->listening->servers; |
641 | 50 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
51 if (port->naddrs > 1) { |
641 | 52 |
53 /* | |
54 * There are several addresses on this port and one of them | |
55 * is the "*:port" wildcard so getsockname() is needed to determine | |
56 * the server address. | |
57 * | |
58 * AcceptEx() already gave this address. | |
59 */ | |
60 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
61 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
|
62 ngx_mail_close_connection(c); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
63 return; |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
66 sa = c->local_sockaddr; |
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 switch (sa->sa_family) { |
541 | 69 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
70 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
71 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
72 sin6 = (struct sockaddr_in6 *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
73 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
74 addr6 = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
75 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
76 /* the last address is "*" */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
77 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
78 for (i = 0; i < port->naddrs - 1; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
79 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
|
80 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
81 } |
641 | 82 } |
83 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
84 addr_conf = &addr6[i].conf; |
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 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
87 #endif |
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 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
90 sin = (struct sockaddr_in *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
91 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
92 addr = port->addrs; |
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 /* the last address is "*" */ |
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 for (i = 0; i < port->naddrs - 1; i++) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
97 if (addr[i].addr == sin->sin_addr.s_addr) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
98 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
99 } |
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 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
102 addr_conf = &addr[i].conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
103 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
104 break; |
641 | 105 } |
106 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
107 } else { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
108 switch (c->local_sockaddr->sa_family) { |
641 | 109 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
110 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
111 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
112 addr6 = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
113 addr_conf = &addr6[0].conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
114 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
115 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
116 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
117 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
118 addr = port->addrs; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
119 addr_conf = &addr[0].conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
120 break; |
641 | 121 } |
122 } | |
123 | |
1136 | 124 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t)); |
641 | 125 if (s == NULL) { |
1136 | 126 ngx_mail_close_connection(c); |
541 | 127 return; |
577 | 128 } |
541 | 129 |
5819
8e7ee4c70a3c
Mail: initialize the "signature" field of ngx_mail_session_t.
Valentin Bartenev <vbart@nginx.com>
parents:
5705
diff
changeset
|
130 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
|
131 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
132 s->main_conf = addr_conf->ctx->main_conf; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
133 s->srv_conf = addr_conf->ctx->srv_conf; |
641 | 134 |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
135 #if (NGX_MAIL_SSL) |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
136 s->ssl = addr_conf->ssl; |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
137 #endif |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
138 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
139 s->addr_text = &addr_conf->addr_text; |
641 | 140 |
141 c->data = s; | |
142 s->connection = c; | |
143 | |
6130 | 144 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
145 | |
146 ngx_set_connection_log(c, cscf->error_log); | |
147 | |
5705
d5b8ee9f2201
Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents:
5632
diff
changeset
|
148 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
|
149 |
d5b8ee9f2201
Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents:
5632
diff
changeset
|
150 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
|
151 c->number, len, text, s->addr_text); |
641 | 152 |
1136 | 153 ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t)); |
641 | 154 if (ctx == NULL) { |
1136 | 155 ngx_mail_close_connection(c); |
641 | 156 return; |
157 } | |
158 | |
159 ctx->client = &c->addr_text; | |
160 ctx->session = s; | |
541 | 161 |
162 c->log->connection = c->number; | |
1136 | 163 c->log->handler = ngx_mail_log_error; |
641 | 164 c->log->data = ctx; |
541 | 165 c->log->action = "sending client greeting line"; |
166 | |
167 c->log_error = NGX_ERROR_INFO; | |
168 | |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
169 rev = c->read; |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
170 rev->handler = ngx_mail_init_session_handler; |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
171 |
8343
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
172 if (addr_conf->proxy_protocol) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
173 c->log->action = "reading PROXY protocol"; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
174 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
175 rev->handler = ngx_mail_proxy_protocol_handler; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
176 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
177 if (!rev->ready) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
178 ngx_add_timer(rev, cscf->timeout); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
179 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
180 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
181 ngx_mail_close_connection(c); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
182 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
183 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
184 return; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
185 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
186 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
187 |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
188 if (ngx_use_accept_mutex) { |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
189 ngx_post_event(rev, &ngx_posted_events); |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
190 return; |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
191 } |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
192 |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
193 rev->handler(rev); |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
194 } |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
195 |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
196 |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
197 static void |
8343
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
198 ngx_mail_proxy_protocol_handler(ngx_event_t *rev) |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
199 { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
200 u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER]; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
201 size_t size; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
202 ssize_t n; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
203 ngx_err_t err; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
204 ngx_connection_t *c; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
205 ngx_mail_session_t *s; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
206 ngx_mail_core_srv_conf_t *cscf; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
207 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
208 c = rev->data; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
209 s = c->data; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
210 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
211 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
212 "mail PROXY protocol handler"); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
213 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
214 if (rev->timedout) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
215 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
216 c->timedout = 1; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
217 ngx_mail_close_connection(c); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
218 return; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
219 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
220 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
221 n = recv(c->fd, (char *) buf, sizeof(buf), MSG_PEEK); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
222 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
223 err = ngx_socket_errno; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
224 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
225 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "recv(): %z", n); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
226 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
227 if (n == -1) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
228 if (err == NGX_EAGAIN) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
229 rev->ready = 0; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
230 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
231 if (!rev->timer_set) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
232 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
233 ngx_add_timer(rev, cscf->timeout); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
234 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
235 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
236 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
237 ngx_mail_close_connection(c); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
238 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
239 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
240 return; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
241 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
242 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
243 ngx_connection_error(c, err, "recv() failed"); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
244 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
245 ngx_mail_close_connection(c); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
246 return; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
247 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
248 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
249 p = ngx_proxy_protocol_read(c, buf, buf + n); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
250 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
251 if (p == NULL) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
252 ngx_mail_close_connection(c); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
253 return; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
254 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
255 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
256 size = p - buf; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
257 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
258 if (c->recv(c, buf, size) != (ssize_t) size) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
259 ngx_mail_close_connection(c); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
260 return; |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
261 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
262 |
8344 | 263 if (ngx_mail_realip_handler(s) != NGX_OK) { |
264 ngx_mail_close_connection(c); | |
265 return; | |
266 } | |
267 | |
8343
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
268 ngx_mail_init_session_handler(rev); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
269 } |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
270 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
271 |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
272 static void |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
273 ngx_mail_init_session_handler(ngx_event_t *rev) |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
274 { |
8364
777373b5a169
Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8344
diff
changeset
|
275 ngx_connection_t *c; |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
276 |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
277 c = rev->data; |
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
278 |
1136 | 279 #if (NGX_MAIL_SSL) |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
280 { |
8364
777373b5a169
Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8344
diff
changeset
|
281 ngx_mail_session_t *s; |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
282 ngx_mail_ssl_conf_t *sslcf; |
543 | 283 |
8364
777373b5a169
Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8344
diff
changeset
|
284 s = c->data; |
777373b5a169
Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8344
diff
changeset
|
285 |
1136 | 286 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
543 | 287 |
8340
d84f13618277
Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
288 if (sslcf->enable || s->ssl) { |
2224 | 289 c->log->action = "SSL handshaking"; |
290 | |
1136 | 291 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
547 | 292 return; |
543 | 293 } |
2224 | 294 |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1494
diff
changeset
|
295 } |
543 | 296 #endif |
297 | |
1136 | 298 ngx_mail_init_session(c); |
541 | 299 } |
300 | |
301 | |
1136 | 302 #if (NGX_MAIL_SSL) |
547 | 303 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
304 void |
1136 | 305 ngx_mail_starttls_handler(ngx_event_t *rev) |
583 | 306 { |
307 ngx_connection_t *c; | |
1136 | 308 ngx_mail_session_t *s; |
309 ngx_mail_ssl_conf_t *sslcf; | |
583 | 310 |
311 c = rev->data; | |
312 s = c->data; | |
641 | 313 s->starttls = 1; |
583 | 314 |
315 c->log->action = "in starttls state"; | |
316 | |
1136 | 317 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
583 | 318 |
1136 | 319 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
583 | 320 } |
321 | |
322 | |
323 static void | |
1136 | 324 ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c) |
583 | 325 { |
1136 | 326 ngx_mail_session_t *s; |
327 ngx_mail_core_srv_conf_t *cscf; | |
583 | 328 |
7009
03444167a3bb
Style: changed checks of ngx_ssl_create_connection() to != NGX_OK.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6774
diff
changeset
|
329 if (ngx_ssl_create_connection(ssl, c, 0) != NGX_OK) { |
1136 | 330 ngx_mail_close_connection(c); |
583 | 331 return; |
332 } | |
333 | |
334 if (ngx_ssl_handshake(c) == NGX_AGAIN) { | |
335 | |
641 | 336 s = c->data; |
337 | |
8343
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
338 if (!c->read->timer_set) { |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
339 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
340 ngx_add_timer(c->read, cscf->timeout); |
12ea1de7d87c
Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8341
diff
changeset
|
341 } |
583 | 342 |
1136 | 343 c->ssl->handler = ngx_mail_ssl_handshake_handler; |
583 | 344 |
345 return; | |
346 } | |
347 | |
1136 | 348 ngx_mail_ssl_handshake_handler(c); |
583 | 349 } |
350 | |
351 | |
352 static void | |
1136 | 353 ngx_mail_ssl_handshake_handler(ngx_connection_t *c) |
577 | 354 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
355 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
|
356 ngx_mail_core_srv_conf_t *cscf; |
641 | 357 |
547 | 358 if (c->ssl->handshaked) { |
583 | 359 |
641 | 360 s = c->data; |
361 | |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
362 if (ngx_mail_verify_cert(s, c) != NGX_OK) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
363 return; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
364 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
365 |
641 | 366 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
|
367 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
|
368 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
369 c->read->handler = cscf->protocol->init_protocol; |
1136 | 370 c->write->handler = ngx_mail_send; |
583 | 371 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
372 cscf->protocol->init_protocol(c->read); |
583 | 373 |
374 return; | |
375 } | |
376 | |
2165
cbf6f2eb57ad
backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
377 c->read->ready = 0; |
cbf6f2eb57ad
backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
378 |
1136 | 379 ngx_mail_init_session(c); |
547 | 380 return; |
381 } | |
382 | |
1136 | 383 ngx_mail_close_connection(c); |
547 | 384 } |
385 | |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
386 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
387 static ngx_int_t |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
388 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
|
389 { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
390 long rc; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
391 X509 *cert; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
392 ngx_mail_ssl_conf_t *sslcf; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
393 ngx_mail_core_srv_conf_t *cscf; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
394 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
395 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
|
396 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
397 if (!sslcf->verify) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
398 return NGX_OK; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
399 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
400 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
401 rc = SSL_get_verify_result(c->ssl->connection); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
402 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
403 if (rc != X509_V_OK |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
404 && (sslcf->verify != 3 || !ngx_ssl_verify_error_optional(rc))) |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
405 { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
406 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
407 "client SSL certificate verify error: (%l:%s)", |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
408 rc, X509_verify_cert_error_string(rc)); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
409 |
7193
9d14931cec8c
SSL: using default server context in session remove (closes #1464).
Sergey Kandaurov <pluknet@nginx.com>
parents:
7009
diff
changeset
|
410 ngx_ssl_remove_cached_session(c->ssl->session_ctx, |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
411 (SSL_get0_session(c->ssl->connection))); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
412 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
413 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
|
414 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
415 s->out = cscf->protocol->cert_error; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
416 s->quit = 1; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
417 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
418 c->write->handler = ngx_mail_send; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
419 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
420 ngx_mail_send(s->connection->write); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
421 return NGX_ERROR; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
422 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
423 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
424 if (sslcf->verify == 1) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
425 cert = SSL_get_peer_certificate(c->ssl->connection); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
426 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
427 if (cert == NULL) { |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
428 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
429 "client sent no required SSL certificate"); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
430 |
7193
9d14931cec8c
SSL: using default server context in session remove (closes #1464).
Sergey Kandaurov <pluknet@nginx.com>
parents:
7009
diff
changeset
|
431 ngx_ssl_remove_cached_session(c->ssl->session_ctx, |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
432 (SSL_get0_session(c->ssl->connection))); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
433 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
434 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
|
435 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
436 s->out = cscf->protocol->no_cert; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
437 s->quit = 1; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
438 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
439 c->write->handler = ngx_mail_send; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
440 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
441 ngx_mail_send(s->connection->write); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
442 return NGX_ERROR; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
443 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
444 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
445 X509_free(cert); |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
446 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
447 |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
448 return NGX_OK; |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
449 } |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5819
diff
changeset
|
450 |
547 | 451 #endif |
452 | |
453 | |
454 static void | |
1136 | 455 ngx_mail_init_session(ngx_connection_t *c) |
541 | 456 { |
1136 | 457 ngx_mail_session_t *s; |
458 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
|
459 |
641 | 460 s = c->data; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
461 |
8341
adee10c7fac8
Mail: fixed log action after SSL handshake.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8340
diff
changeset
|
462 c->log->action = "sending client greeting line"; |
adee10c7fac8
Mail: fixed log action after SSL handshake.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8340
diff
changeset
|
463 |
1136 | 464 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
539 | 465 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
466 s->protocol = cscf->protocol->type; |
539 | 467 |
1136 | 468 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module); |
539 | 469 if (s->ctx == NULL) { |
1136 | 470 ngx_mail_session_internal_server_error(s); |
539 | 471 return; |
472 } | |
473 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
474 c->write->handler = ngx_mail_send; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
475 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
476 cscf->protocol->init_session(s, c); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
477 } |
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 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
480 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
481 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
|
482 ngx_mail_core_srv_conf_t *cscf) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
483 { |
2049 | 484 s->salt.data = ngx_pnalloc(c->pool, |
485 sizeof(" <18446744073709551616.@>" CRLF) - 1 | |
486 + NGX_TIME_T_LEN | |
487 + cscf->server_name.len); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
488 if (s->salt.data == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
489 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
490 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
491 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
492 s->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
|
493 ngx_random(), ngx_time(), &cscf->server_name) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
494 - s->salt.data; |
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 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
497 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
498 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
499 |
1479 | 500 #if (NGX_MAIL_SSL) |
501 | |
502 ngx_int_t | |
503 ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c) | |
504 { | |
505 ngx_mail_ssl_conf_t *sslcf; | |
506 | |
507 if (c->ssl) { | |
508 return 0; | |
509 } | |
510 | |
511 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); | |
512 | |
513 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) { | |
514 return 1; | |
515 } | |
516 | |
517 return 0; | |
518 } | |
519 | |
520 #endif | |
521 | |
522 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
523 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
524 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
|
525 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
526 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
527 ngx_str_t *arg, plain; |
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 arg = s->args.elts; |
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 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
532 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
|
533 "mail auth plain: \"%V\"", &arg[n]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
534 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
535 |
2049 | 536 plain.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
3642 | 537 if (plain.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
538 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
539 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
540 |
1494
6535fb51976a
fix "AUTH PLAIN [initial-response]" bug introduced in r1477
Igor Sysoev <igor@sysoev.ru>
parents:
1491
diff
changeset
|
541 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
|
542 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
|
543 "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
|
544 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
545 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
546 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
547 p = plain.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
548 last = p + plain.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
549 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
550 while (p < last && *p++) { /* void */ } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
551 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
552 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
553 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
|
554 "client sent invalid login in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
555 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
556 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
557 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
558 s->login.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
559 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
560 while (p < last && *p) { p++; } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
561 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
562 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
563 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
|
564 "client sent invalid password in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
565 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
566 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
567 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
568 s->login.len = p++ - s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
569 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
570 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
571 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
572 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
573 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
574 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
|
575 "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
|
576 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
577 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
578 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
579 } |
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 ngx_int_t |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
583 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
|
584 ngx_uint_t n) |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
585 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
586 ngx_str_t *arg; |
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 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
589 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
590 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
|
591 "mail auth login username: \"%V\"", &arg[n]); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
592 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
593 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
3642 | 594 if (s->login.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
595 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
596 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
597 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
598 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
|
599 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
|
600 "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
|
601 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
602 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
603 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
604 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
|
605 "mail auth login username: \"%V\"", &s->login); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
606 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
607 return NGX_OK; |
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 |
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 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
612 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
|
613 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
614 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
615 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
616 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
617 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
618 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
619 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
|
620 "mail auth login password: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
621 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
622 |
2049 | 623 s->passwd.data = ngx_pnalloc(c->pool, |
624 ngx_base64_decoded_length(arg[0].len)); | |
3642 | 625 if (s->passwd.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
626 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
627 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
628 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
629 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
|
630 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
|
631 "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
|
632 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
633 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
634 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
635 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
636 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
|
637 "mail auth login password: \"%V\"", &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
638 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
639 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
640 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
641 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
642 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
643 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
644 ngx_int_t |
1479 | 645 ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
646 char *prefix, size_t len) | |
647 { | |
648 u_char *p; | |
649 ngx_str_t salt; | |
650 ngx_uint_t n; | |
651 | |
2049 | 652 p = ngx_pnalloc(c->pool, len + ngx_base64_encoded_length(s->salt.len) + 2); |
1479 | 653 if (p == NULL) { |
654 return NGX_ERROR; | |
655 } | |
656 | |
657 salt.data = ngx_cpymem(p, prefix, len); | |
658 s->salt.len -= 2; | |
659 | |
660 ngx_encode_base64(&salt, &s->salt); | |
661 | |
662 s->salt.len += 2; | |
663 n = len + salt.len; | |
664 p[n++] = CR; p[n++] = LF; | |
665 | |
666 s->out.len = n; | |
667 s->out.data = p; | |
668 | |
669 return NGX_OK; | |
670 } | |
671 | |
672 | |
673 ngx_int_t | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
674 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
|
675 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
676 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
677 ngx_str_t *arg; |
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 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
680 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
681 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
|
682 "mail auth cram-md5: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
683 |
2049 | 684 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len)); |
3642 | 685 if (s->login.data == NULL) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
686 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
687 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
688 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
689 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
|
690 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
|
691 "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
|
692 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
693 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
694 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
695 p = s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
696 last = p + s->login.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
697 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
698 while (p < last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
699 if (*p++ == ' ') { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
700 s->login.len = p - s->login.data - 1; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
701 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
702 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
703 break; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
704 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
705 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
706 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
707 if (s->passwd.len != 32) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
708 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
|
709 "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
|
710 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
711 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
712 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
713 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
|
714 "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
|
715 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
716 s->auth_method = NGX_MAIL_AUTH_CRAM_MD5; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
717 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
718 return NGX_DONE; |
539 | 719 } |
720 | |
721 | |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
722 ngx_int_t |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
723 ngx_mail_auth_external(ngx_mail_session_t *s, ngx_connection_t *c, |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
724 ngx_uint_t n) |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
725 { |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
726 ngx_str_t *arg, external; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
727 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
728 arg = s->args.elts; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
729 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
730 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
731 "mail auth external: \"%V\"", &arg[n]); |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
732 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
733 external.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
734 if (external.data == NULL) { |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
735 return NGX_ERROR; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
736 } |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
737 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
738 if (ngx_decode_base64(&external, &arg[n]) != NGX_OK) { |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
739 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
740 "client sent invalid base64 encoding in AUTH EXTERNAL command"); |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
741 return NGX_MAIL_PARSE_INVALID_COMMAND; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
742 } |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
743 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
744 s->login.len = external.len; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
745 s->login.data = external.data; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
746 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
747 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
748 "mail auth external: \"%V\"", &s->login); |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
749 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
750 s->auth_method = NGX_MAIL_AUTH_EXTERNAL; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
751 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
752 return NGX_DONE; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
753 } |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
754 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6130
diff
changeset
|
755 |
539 | 756 void |
1136 | 757 ngx_mail_send(ngx_event_t *wev) |
539 | 758 { |
541 | 759 ngx_int_t n; |
760 ngx_connection_t *c; | |
1136 | 761 ngx_mail_session_t *s; |
762 ngx_mail_core_srv_conf_t *cscf; | |
539 | 763 |
764 c = wev->data; | |
765 s = c->data; | |
766 | |
767 if (wev->timedout) { | |
768 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 769 c->timedout = 1; |
1136 | 770 ngx_mail_close_connection(c); |
539 | 771 return; |
772 } | |
773 | |
774 if (s->out.len == 0) { | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
775 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
1136 | 776 ngx_mail_close_connection(c); |
539 | 777 } |
778 | |
779 return; | |
780 } | |
781 | |
782 n = c->send(c, s->out.data, s->out.len); | |
783 | |
784 if (n > 0) { | |
5632
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
785 s->out.data += n; |
539 | 786 s->out.len -= n; |
787 | |
5632
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
788 if (s->out.len != 0) { |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
789 goto again; |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
790 } |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
791 |
541 | 792 if (wev->timer_set) { |
793 ngx_del_timer(wev); | |
794 } | |
795 | |
539 | 796 if (s->quit) { |
1136 | 797 ngx_mail_close_connection(c); |
539 | 798 return; |
799 } | |
800 | |
801 if (s->blocked) { | |
802 c->read->handler(c->read); | |
803 } | |
804 | |
805 return; | |
806 } | |
807 | |
808 if (n == NGX_ERROR) { | |
1136 | 809 ngx_mail_close_connection(c); |
539 | 810 return; |
811 } | |
812 | |
813 /* n == NGX_AGAIN */ | |
814 | |
5632
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
815 again: |
b42e7c790b81
Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5600
diff
changeset
|
816 |
1136 | 817 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
541 | 818 |
819 ngx_add_timer(c->write, cscf->timeout); | |
820 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
821 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
1136 | 822 ngx_mail_close_connection(c); |
539 | 823 return; |
824 } | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
825 } |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
826 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
827 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
828 ngx_int_t |
1482 | 829 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
|
830 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
831 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
|
832 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
|
833 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
|
834 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
|
835 |
8450
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
836 if (s->buffer->last < s->buffer->end) { |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
837 |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
838 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
|
839 |
8450
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
840 if (n == NGX_ERROR || n == 0) { |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
841 ngx_mail_close_connection(c); |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
842 return NGX_ERROR; |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
843 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
844 |
8450
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
845 if (n > 0) { |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
846 s->buffer->last += n; |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
847 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
848 |
8450
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
849 if (n == NGX_AGAIN) { |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
850 if (s->buffer->pos == s->buffer->last) { |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
851 return NGX_AGAIN; |
2851e4c7de03
Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents:
8364
diff
changeset
|
852 } |
5398
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
853 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
854 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
855 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
856 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
|
857 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
858 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
|
859 |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
860 if (rc == NGX_AGAIN) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
861 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
862 if (s->buffer->last < s->buffer->end) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
863 return rc; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
864 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
865 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
866 l.len = s->buffer->last - s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
867 l.data = s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
868 |
1482 | 869 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
|
870 "client sent too long command \"%V\"", &l); |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
871 |
1111
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
872 s->quit = 1; |
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
873 |
1136 | 874 return NGX_MAIL_PARSE_INVALID_COMMAND; |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
875 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
876 |
8465
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
877 if (rc == NGX_MAIL_PARSE_INVALID_COMMAND) { |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
878 |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
879 s->errors++; |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
880 |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
881 if (s->errors >= cscf->max_errors) { |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
882 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
883 "client sent too many invalid commands"); |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
884 s->quit = 1; |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
885 } |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
886 |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
887 return rc; |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
888 } |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
889 |
ec1071830799
Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8450
diff
changeset
|
890 if (rc == NGX_IMAP_NEXT) { |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
891 return rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
892 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
893 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
894 if (rc == NGX_ERROR) { |
1482 | 895 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
|
896 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
897 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
898 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
899 return NGX_OK; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
900 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
901 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
902 |
521 | 903 void |
1482 | 904 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
|
905 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
906 s->args.nelts = 0; |
5398
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
907 |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
908 if (s->buffer->pos == s->buffer->last) { |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
909 s->buffer->pos = s->buffer->start; |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
910 s->buffer->last = s->buffer->start; |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
911 } |
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4818
diff
changeset
|
912 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
913 s->state = 0; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
914 |
1482 | 915 if (c->read->timer_set) { |
916 ngx_del_timer(c->read); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
917 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
918 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
919 s->login_attempt++; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
920 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
921 ngx_mail_auth_http_init(s); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
922 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
923 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
924 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
925 void |
1136 | 926 ngx_mail_session_internal_server_error(ngx_mail_session_t *s) |
525 | 927 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
928 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
|
929 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
930 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
|
931 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
932 s->out = cscf->protocol->internal_server_error; |
539 | 933 s->quit = 1; |
525 | 934 |
1136 | 935 ngx_mail_send(s->connection->write); |
525 | 936 } |
937 | |
938 | |
939 void | |
1136 | 940 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
|
941 { |
479 | 942 ngx_pool_t *pool; |
943 | |
1136 | 944 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
945 "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
|
946 |
1136 | 947 #if (NGX_MAIL_SSL) |
539 | 948 |
949 if (c->ssl) { | |
950 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
1136 | 951 c->ssl->handler = ngx_mail_close_connection; |
539 | 952 return; |
953 } | |
954 } | |
955 | |
956 #endif | |
957 | |
1472
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
958 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2855
diff
changeset
|
959 (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
|
960 #endif |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
961 |
583 | 962 c->destroyed = 1; |
543 | 963 |
479 | 964 pool = c->pool; |
965 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
966 ngx_close_connection(c); |
479 | 967 |
501 | 968 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
|
969 } |
539 | 970 |
971 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
972 u_char * |
1136 | 973 ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len) |
541 | 974 { |
567 | 975 u_char *p; |
1136 | 976 ngx_mail_session_t *s; |
977 ngx_mail_log_ctx_t *ctx; | |
541 | 978 |
979 if (log->action) { | |
980 p = ngx_snprintf(buf, len, " while %s", log->action); | |
981 len -= p - buf; | |
982 buf = p; | |
983 } | |
577 | 984 |
541 | 985 ctx = log->data; |
986 | |
987 p = ngx_snprintf(buf, len, ", client: %V", ctx->client); | |
988 len -= p - buf; | |
989 buf = p; | |
990 | |
991 s = ctx->session; | |
992 | |
993 if (s == NULL) { | |
994 return p; | |
995 } | |
996 | |
1491 | 997 p = ngx_snprintf(buf, len, "%s, server: %V", |
998 s->starttls ? " using starttls" : "", | |
999 s->addr_text); | |
541 | 1000 len -= p - buf; |
1001 buf = p; | |
1002 | |
1003 if (s->login.len == 0) { | |
1004 return p; | |
1005 } | |
1006 | |
1007 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login); | |
1008 len -= p - buf; | |
1009 buf = p; | |
1010 | |
1011 if (s->proxy == NULL) { | |
1012 return p; | |
1013 } | |
1014 | |
884 | 1015 p = ngx_snprintf(buf, len, ", upstream: %V", s->proxy->upstream.name); |
541 | 1016 |
1017 return p; | |
1018 } |