Mercurial > hg > nginx
annotate src/mail/ngx_mail_proxy_module.c @ 9196:6c8595b77e66
QUIC: path aware in-flight bytes accounting.
On-packet acknowledgement is made path aware, as per RFC 9000, Section 9.4:
Packets sent on the old path MUST NOT contribute to congestion control
or RTT estimation for the new path.
To make this possible in a single congestion control context, the first packet
to be sent after the new path has been validated, which includes resetting the
congestion controller and RTT estimator, is now remembered in the connection.
Packets sent previously, such as on the old path, are not taken into account.
Note that although the packet number is saved per-connection, the added checks
affect application level packets only. For non-application level packets,
which are only processed prior to the handshake is complete, the remembered
packet number remains set to zero.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 12 Dec 2023 20:21:12 +0400 |
parents | a5e6e8510634 |
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:
426
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:
426
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:
426
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:
426
diff
changeset
|
6 |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
11 #include <ngx_event_connect.h> |
1136 | 12 #include <ngx_mail.h> |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
521 | 15 typedef struct { |
16 ngx_flag_t enable; | |
857 | 17 ngx_flag_t pass_error_message; |
1136 | 18 ngx_flag_t xclient; |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
19 ngx_flag_t smtp_auth; |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
20 ngx_flag_t proxy_protocol; |
539 | 21 size_t buffer_size; |
22 ngx_msec_t timeout; | |
1136 | 23 } ngx_mail_proxy_conf_t; |
521 | 24 |
25 | |
1136 | 26 static void ngx_mail_proxy_block_read(ngx_event_t *rev); |
27 static void ngx_mail_proxy_pop3_handler(ngx_event_t *rev); | |
28 static void ngx_mail_proxy_imap_handler(ngx_event_t *rev); | |
29 static void ngx_mail_proxy_smtp_handler(ngx_event_t *rev); | |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
30 static void ngx_mail_proxy_write_handler(ngx_event_t *wev); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
31 static ngx_int_t ngx_mail_proxy_send_proxy_protocol(ngx_mail_session_t *s); |
1136 | 32 static ngx_int_t ngx_mail_proxy_read_response(ngx_mail_session_t *s, |
663 | 33 ngx_uint_t state); |
1136 | 34 static void ngx_mail_proxy_handler(ngx_event_t *ev); |
35 static void ngx_mail_proxy_upstream_error(ngx_mail_session_t *s); | |
36 static void ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s); | |
37 static void ngx_mail_proxy_close_session(ngx_mail_session_t *s); | |
38 static void *ngx_mail_proxy_create_conf(ngx_conf_t *cf); | |
39 static char *ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent, | |
521 | 40 void *child); |
41 | |
42 | |
1136 | 43 static ngx_command_t ngx_mail_proxy_commands[] = { |
539 | 44 |
521 | 45 { ngx_string("proxy"), |
1136 | 46 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
521 | 47 ngx_conf_set_flag_slot, |
1136 | 48 NGX_MAIL_SRV_CONF_OFFSET, |
49 offsetof(ngx_mail_proxy_conf_t, enable), | |
521 | 50 NULL }, |
51 | |
539 | 52 { ngx_string("proxy_buffer"), |
1136 | 53 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
539 | 54 ngx_conf_set_size_slot, |
1136 | 55 NGX_MAIL_SRV_CONF_OFFSET, |
56 offsetof(ngx_mail_proxy_conf_t, buffer_size), | |
539 | 57 NULL }, |
58 | |
59 { ngx_string("proxy_timeout"), | |
1136 | 60 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
539 | 61 ngx_conf_set_msec_slot, |
1136 | 62 NGX_MAIL_SRV_CONF_OFFSET, |
63 offsetof(ngx_mail_proxy_conf_t, timeout), | |
539 | 64 NULL }, |
65 | |
857 | 66 { ngx_string("proxy_pass_error_message"), |
4273
e444e8f6538b
Fixed NGX_CONF_TAKE1/NGX_CONF_FLAG misuse.
Sergey Budnevitch <sb@waeme.net>
parents:
3516
diff
changeset
|
67 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
857 | 68 ngx_conf_set_flag_slot, |
1136 | 69 NGX_MAIL_SRV_CONF_OFFSET, |
70 offsetof(ngx_mail_proxy_conf_t, pass_error_message), | |
71 NULL }, | |
72 | |
73 { ngx_string("xclient"), | |
74 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, | |
75 ngx_conf_set_flag_slot, | |
76 NGX_MAIL_SRV_CONF_OFFSET, | |
77 offsetof(ngx_mail_proxy_conf_t, xclient), | |
857 | 78 NULL }, |
79 | |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
80 { ngx_string("proxy_smtp_auth"), |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
81 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
82 ngx_conf_set_flag_slot, |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
83 NGX_MAIL_SRV_CONF_OFFSET, |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
84 offsetof(ngx_mail_proxy_conf_t, smtp_auth), |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
85 NULL }, |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
86 |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
87 { ngx_string("proxy_protocol"), |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
88 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
89 ngx_conf_set_flag_slot, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
90 NGX_MAIL_SRV_CONF_OFFSET, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
91 offsetof(ngx_mail_proxy_conf_t, proxy_protocol), |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
92 NULL }, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
93 |
521 | 94 ngx_null_command |
95 }; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 |
1136 | 98 static ngx_mail_module_t ngx_mail_proxy_module_ctx = { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1342
diff
changeset
|
99 NULL, /* protocol */ |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1342
diff
changeset
|
100 |
521 | 101 NULL, /* create main configuration */ |
102 NULL, /* init main configuration */ | |
103 | |
1136 | 104 ngx_mail_proxy_create_conf, /* create server configuration */ |
105 ngx_mail_proxy_merge_conf /* merge server configuration */ | |
521 | 106 }; |
107 | |
108 | |
1136 | 109 ngx_module_t ngx_mail_proxy_module = { |
521 | 110 NGX_MODULE_V1, |
1136 | 111 &ngx_mail_proxy_module_ctx, /* module context */ |
112 ngx_mail_proxy_commands, /* module directives */ | |
113 NGX_MAIL_MODULE, /* module type */ | |
541 | 114 NULL, /* init master */ |
521 | 115 NULL, /* init module */ |
541 | 116 NULL, /* init process */ |
117 NULL, /* init thread */ | |
118 NULL, /* exit thread */ | |
119 NULL, /* exit process */ | |
120 NULL, /* exit master */ | |
121 NGX_MODULE_V1_PADDING | |
521 | 122 }; |
123 | |
124 | |
2440
939b40aa9ab4
update r2439: make clear name
Igor Sysoev <igor@sysoev.ru>
parents:
2438
diff
changeset
|
125 static u_char smtp_auth_ok[] = "235 2.0.0 OK" CRLF; |
1136 | 126 |
127 | |
521 | 128 void |
3269
f0d596e84634
rename ngx_peer_addr_t to ngx_addr_t
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
129 ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_addr_t *peer) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
130 { |
527 | 131 ngx_int_t rc; |
1136 | 132 ngx_mail_proxy_ctx_t *p; |
133 ngx_mail_proxy_conf_t *pcf; | |
134 ngx_mail_core_srv_conf_t *cscf; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
135 |
587 | 136 s->connection->log->action = "connecting to upstream"; |
137 | |
1136 | 138 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
587 | 139 |
1136 | 140 p = ngx_pcalloc(s->connection->pool, sizeof(ngx_mail_proxy_ctx_t)); |
501 | 141 if (p == NULL) { |
1136 | 142 ngx_mail_session_internal_server_error(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
143 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
144 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
145 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
146 s->proxy = p; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
147 |
884 | 148 p->upstream.sockaddr = peer->sockaddr; |
149 p->upstream.socklen = peer->socklen; | |
150 p->upstream.name = &peer->name; | |
151 p->upstream.get = ngx_event_get_peer; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
152 p->upstream.log = s->connection->log; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
153 p->upstream.log_error = NGX_ERROR_ERR; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
154 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
155 rc = ngx_event_connect_peer(&p->upstream); |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
156 |
543 | 157 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) { |
1136 | 158 ngx_mail_proxy_internal_server_error(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
159 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
160 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
161 |
527 | 162 ngx_add_timer(p->upstream.connection->read, cscf->timeout); |
163 | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
164 p->upstream.connection->data = s; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
165 p->upstream.connection->pool = s->connection->pool; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
166 |
1136 | 167 s->connection->read->handler = ngx_mail_proxy_block_read; |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
168 p->upstream.connection->write->handler = ngx_mail_proxy_write_handler; |
1136 | 169 |
170 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
171 | |
172 s->proxy->buffer = ngx_create_temp_buf(s->connection->pool, | |
173 pcf->buffer_size); | |
174 if (s->proxy->buffer == NULL) { | |
175 ngx_mail_proxy_internal_server_error(s); | |
176 return; | |
177 } | |
178 | |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
179 s->proxy->proxy_protocol = pcf->proxy_protocol; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
180 |
1981 | 181 s->out.len = 0; |
182 | |
1136 | 183 switch (s->protocol) { |
527 | 184 |
1136 | 185 case NGX_MAIL_POP3_PROTOCOL: |
186 p->upstream.connection->read->handler = ngx_mail_proxy_pop3_handler; | |
187 s->mail_state = ngx_pop3_start; | |
188 break; | |
527 | 189 |
1136 | 190 case NGX_MAIL_IMAP_PROTOCOL: |
191 p->upstream.connection->read->handler = ngx_mail_proxy_imap_handler; | |
192 s->mail_state = ngx_imap_start; | |
193 break; | |
194 | |
195 default: /* NGX_MAIL_SMTP_PROTOCOL */ | |
196 p->upstream.connection->read->handler = ngx_mail_proxy_smtp_handler; | |
197 s->mail_state = ngx_smtp_start; | |
198 break; | |
527 | 199 } |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
200 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
201 if (rc == NGX_AGAIN) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
202 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
203 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
204 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
205 ngx_mail_proxy_write_handler(p->upstream.connection->write); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
206 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
207 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
208 |
521 | 209 static void |
1136 | 210 ngx_mail_proxy_block_read(ngx_event_t *rev) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
211 { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
212 ngx_connection_t *c; |
1136 | 213 ngx_mail_session_t *s; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
214 |
1136 | 215 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy block read"); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
216 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
217 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
218 c = rev->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
219 s = c->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
220 |
1136 | 221 ngx_mail_proxy_close_session(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
222 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
223 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
224 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
225 |
521 | 226 static void |
1136 | 227 ngx_mail_proxy_pop3_handler(ngx_event_t *rev) |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 { |
539 | 229 u_char *p; |
230 ngx_int_t rc; | |
231 ngx_str_t line; | |
232 ngx_connection_t *c; | |
1136 | 233 ngx_mail_session_t *s; |
234 ngx_mail_proxy_conf_t *pcf; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
235 |
1136 | 236 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
237 "mail proxy pop3 auth handler"); | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
238 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
239 c = rev->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
240 s = c->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
241 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
242 if (rev->timedout) { |
527 | 243 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
244 "upstream timed out"); | |
577 | 245 c->timedout = 1; |
1136 | 246 ngx_mail_proxy_internal_server_error(s); |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
247 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
248 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
249 |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
250 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
251 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "mail proxy pop3 busy"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
252 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
253 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
254 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
255 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
256 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
257 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
258 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
259 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
260 |
1136 | 261 rc = ngx_mail_proxy_read_response(s, 0); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
262 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
263 if (rc == NGX_AGAIN) { |
7790
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
264 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
265 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
266 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
267 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
268 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
269 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
270 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
271 |
571 | 272 if (rc == NGX_ERROR) { |
1136 | 273 ngx_mail_proxy_upstream_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
274 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
275 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
276 |
1136 | 277 switch (s->mail_state) { |
587 | 278 |
1136 | 279 case ngx_pop3_start: |
280 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user"); | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
281 |
587 | 282 s->connection->log->action = "sending user name to upstream"; |
283 | |
1136 | 284 line.len = sizeof("USER ") - 1 + s->login.len + 2; |
2049 | 285 line.data = ngx_pnalloc(c->pool, line.len); |
527 | 286 if (line.data == NULL) { |
1136 | 287 ngx_mail_proxy_internal_server_error(s); |
527 | 288 return; |
289 } | |
290 | |
1136 | 291 p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1); |
292 p = ngx_cpymem(p, s->login.data, s->login.len); | |
293 *p++ = CR; *p = LF; | |
527 | 294 |
1136 | 295 s->mail_state = ngx_pop3_user; |
527 | 296 break; |
297 | |
1136 | 298 case ngx_pop3_user: |
299 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send pass"); | |
527 | 300 |
587 | 301 s->connection->log->action = "sending password to upstream"; |
302 | |
1136 | 303 line.len = sizeof("PASS ") - 1 + s->passwd.len + 2; |
2049 | 304 line.data = ngx_pnalloc(c->pool, line.len); |
501 | 305 if (line.data == NULL) { |
1136 | 306 ngx_mail_proxy_internal_server_error(s); |
527 | 307 return; |
308 } | |
309 | |
1136 | 310 p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1); |
311 p = ngx_cpymem(p, s->passwd.data, s->passwd.len); | |
527 | 312 *p++ = CR; *p = LF; |
313 | |
1136 | 314 s->mail_state = ngx_pop3_passwd; |
527 | 315 break; |
316 | |
1136 | 317 case ngx_pop3_passwd: |
318 s->connection->read->handler = ngx_mail_proxy_handler; | |
319 s->connection->write->handler = ngx_mail_proxy_handler; | |
320 rev->handler = ngx_mail_proxy_handler; | |
321 c->write->handler = ngx_mail_proxy_handler; | |
663 | 322 |
1136 | 323 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
663 | 324 ngx_add_timer(s->connection->read, pcf->timeout); |
325 ngx_del_timer(c->read); | |
326 | |
327 c->log->action = NULL; | |
328 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
329 | |
8151
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
330 if (s->buffer->pos < s->buffer->last |
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
331 || s->connection->read->ready) |
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
332 { |
7838
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7835
diff
changeset
|
333 ngx_post_event(c->write, &ngx_posted_events); |
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7835
diff
changeset
|
334 } |
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7835
diff
changeset
|
335 |
1136 | 336 ngx_mail_proxy_handler(s->connection->write); |
663 | 337 |
338 return; | |
339 | |
527 | 340 default: |
341 #if (NGX_SUPPRESS_WARN) | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3505
diff
changeset
|
342 ngx_str_null(&line); |
527 | 343 #endif |
344 break; | |
345 } | |
346 | |
539 | 347 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { |
527 | 348 /* |
349 * we treat the incomplete sending as NGX_ERROR | |
350 * because it is very strange here | |
351 */ | |
1136 | 352 ngx_mail_proxy_internal_server_error(s); |
527 | 353 return; |
354 } | |
355 | |
7790
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
356 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
357 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
358 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
359 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
360 |
527 | 361 s->proxy->buffer->pos = s->proxy->buffer->start; |
362 s->proxy->buffer->last = s->proxy->buffer->start; | |
363 } | |
364 | |
365 | |
366 static void | |
1136 | 367 ngx_mail_proxy_imap_handler(ngx_event_t *rev) |
527 | 368 { |
539 | 369 u_char *p; |
370 ngx_int_t rc; | |
371 ngx_str_t line; | |
372 ngx_connection_t *c; | |
1136 | 373 ngx_mail_session_t *s; |
374 ngx_mail_proxy_conf_t *pcf; | |
527 | 375 |
1136 | 376 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
377 "mail proxy imap auth handler"); | |
527 | 378 |
379 c = rev->data; | |
380 s = c->data; | |
381 | |
382 if (rev->timedout) { | |
383 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
384 "upstream timed out"); | |
577 | 385 c->timedout = 1; |
1136 | 386 ngx_mail_proxy_internal_server_error(s); |
527 | 387 return; |
388 } | |
389 | |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
390 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
391 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "mail proxy imap busy"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
392 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
393 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
394 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
395 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
396 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
397 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
398 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
399 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
400 |
1136 | 401 rc = ngx_mail_proxy_read_response(s, s->mail_state); |
527 | 402 |
403 if (rc == NGX_AGAIN) { | |
7790
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
404 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
405 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
406 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
407 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
408 |
527 | 409 return; |
410 } | |
411 | |
571 | 412 if (rc == NGX_ERROR) { |
1136 | 413 ngx_mail_proxy_upstream_error(s); |
527 | 414 return; |
415 } | |
416 | |
1136 | 417 switch (s->mail_state) { |
527 | 418 |
1136 | 419 case ngx_imap_start: |
420 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
421 "mail proxy send login"); | |
527 | 422 |
1136 | 423 s->connection->log->action = "sending LOGIN command to upstream"; |
587 | 424 |
1136 | 425 line.len = s->tag.len + sizeof("LOGIN ") - 1 |
426 + 1 + NGX_SIZE_T_LEN + 1 + 2; | |
2049 | 427 line.data = ngx_pnalloc(c->pool, line.len); |
527 | 428 if (line.data == NULL) { |
1136 | 429 ngx_mail_proxy_internal_server_error(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
430 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
431 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
432 |
1136 | 433 line.len = ngx_sprintf(line.data, "%VLOGIN {%uz}" CRLF, |
434 &s->tag, s->login.len) | |
435 - line.data; | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
436 |
1136 | 437 s->mail_state = ngx_imap_login; |
527 | 438 break; |
439 | |
1136 | 440 case ngx_imap_login: |
441 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user"); | |
442 | |
443 s->connection->log->action = "sending user name to upstream"; | |
444 | |
445 line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2; | |
2049 | 446 line.data = ngx_pnalloc(c->pool, line.len); |
1136 | 447 if (line.data == NULL) { |
448 ngx_mail_proxy_internal_server_error(s); | |
449 return; | |
450 } | |
451 | |
452 line.len = ngx_sprintf(line.data, "%V {%uz}" CRLF, | |
453 &s->login, s->passwd.len) | |
454 - line.data; | |
455 | |
456 s->mail_state = ngx_imap_user; | |
457 break; | |
458 | |
459 case ngx_imap_user: | |
460 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
461 "mail proxy send passwd"); | |
527 | 462 |
587 | 463 s->connection->log->action = "sending password to upstream"; |
464 | |
1136 | 465 line.len = s->passwd.len + 2; |
2049 | 466 line.data = ngx_pnalloc(c->pool, line.len); |
527 | 467 if (line.data == NULL) { |
1136 | 468 ngx_mail_proxy_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
469 return; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
470 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
471 |
1136 | 472 p = ngx_cpymem(line.data, s->passwd.data, s->passwd.len); |
527 | 473 *p++ = CR; *p = LF; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
474 |
1136 | 475 s->mail_state = ngx_imap_passwd; |
527 | 476 break; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
477 |
1136 | 478 case ngx_imap_passwd: |
479 s->connection->read->handler = ngx_mail_proxy_handler; | |
480 s->connection->write->handler = ngx_mail_proxy_handler; | |
481 rev->handler = ngx_mail_proxy_handler; | |
482 c->write->handler = ngx_mail_proxy_handler; | |
663 | 483 |
1136 | 484 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
663 | 485 ngx_add_timer(s->connection->read, pcf->timeout); |
486 ngx_del_timer(c->read); | |
487 | |
488 c->log->action = NULL; | |
489 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
490 | |
8151
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
491 if (s->buffer->pos < s->buffer->last |
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
492 || s->connection->read->ready) |
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
493 { |
7843
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7838
diff
changeset
|
494 ngx_post_event(c->write, &ngx_posted_events); |
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7838
diff
changeset
|
495 } |
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7838
diff
changeset
|
496 |
1136 | 497 ngx_mail_proxy_handler(s->connection->write); |
663 | 498 |
499 return; | |
500 | |
527 | 501 default: |
502 #if (NGX_SUPPRESS_WARN) | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3505
diff
changeset
|
503 ngx_str_null(&line); |
527 | 504 #endif |
505 break; | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
506 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
507 |
539 | 508 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
509 /* |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
510 * we treat the incomplete sending as NGX_ERROR |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
511 * because it is very strange here |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
512 */ |
1136 | 513 ngx_mail_proxy_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
514 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
515 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
516 |
7790
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
517 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
518 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
519 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
520 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
521 |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
522 s->proxy->buffer->pos = s->proxy->buffer->start; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
523 s->proxy->buffer->last = s->proxy->buffer->start; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
524 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
525 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
526 |
521 | 527 static void |
1136 | 528 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) |
529 { | |
530 u_char *p; | |
531 ngx_int_t rc; | |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
532 ngx_str_t line, auth, encoded; |
2309 | 533 ngx_buf_t *b; |
1136 | 534 ngx_connection_t *c; |
535 ngx_mail_session_t *s; | |
536 ngx_mail_proxy_conf_t *pcf; | |
537 ngx_mail_core_srv_conf_t *cscf; | |
538 | |
539 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
540 "mail proxy smtp auth handler"); | |
541 | |
542 c = rev->data; | |
543 s = c->data; | |
544 | |
545 if (rev->timedout) { | |
546 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
547 "upstream timed out"); | |
548 c->timedout = 1; | |
549 ngx_mail_proxy_internal_server_error(s); | |
550 return; | |
551 } | |
552 | |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
553 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
554 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "mail proxy smtp busy"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
555 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
556 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
557 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
558 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
559 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
560 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
561 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
562 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
563 |
1136 | 564 rc = ngx_mail_proxy_read_response(s, s->mail_state); |
565 | |
566 if (rc == NGX_AGAIN) { | |
7790
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
567 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
568 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
569 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
570 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
571 |
1136 | 572 return; |
573 } | |
574 | |
575 if (rc == NGX_ERROR) { | |
576 ngx_mail_proxy_upstream_error(s); | |
577 return; | |
578 } | |
579 | |
580 switch (s->mail_state) { | |
581 | |
582 case ngx_smtp_start: | |
583 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send ehlo"); | |
584 | |
585 s->connection->log->action = "sending HELO/EHLO to upstream"; | |
586 | |
587 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); | |
588 | |
589 line.len = sizeof("HELO ") - 1 + cscf->server_name.len + 2; | |
2049 | 590 line.data = ngx_pnalloc(c->pool, line.len); |
1136 | 591 if (line.data == NULL) { |
592 ngx_mail_proxy_internal_server_error(s); | |
593 return; | |
594 } | |
595 | |
596 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
597 | |
598 p = ngx_cpymem(line.data, | |
599 ((s->esmtp || pcf->xclient) ? "EHLO " : "HELO "), | |
600 sizeof("HELO ") - 1); | |
601 | |
602 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); | |
603 *p++ = CR; *p = LF; | |
604 | |
2309 | 605 if (pcf->xclient) { |
606 s->mail_state = ngx_smtp_helo_xclient; | |
607 | |
608 } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { | |
609 s->mail_state = ngx_smtp_helo_from; | |
610 | |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
611 } else if (pcf->smtp_auth) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
612 s->mail_state = ngx_smtp_helo_auth; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
613 |
2309 | 614 } else { |
615 s->mail_state = ngx_smtp_helo; | |
616 } | |
1136 | 617 |
618 break; | |
619 | |
2309 | 620 case ngx_smtp_helo_xclient: |
1136 | 621 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
622 "mail proxy send xclient"); | |
623 | |
624 s->connection->log->action = "sending XCLIENT to upstream"; | |
625 | |
2497 | 626 line.len = sizeof("XCLIENT ADDR= LOGIN= NAME=" |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
627 CRLF) - 1 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
628 + s->connection->addr_text.len + s->login.len + s->host.len; |
1136 | 629 |
5522
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
630 #if (NGX_HAVE_INET6) |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
631 if (s->connection->sockaddr->sa_family == AF_INET6) { |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
632 line.len += sizeof("IPV6:") - 1; |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
633 } |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
634 #endif |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
635 |
2049 | 636 line.data = ngx_pnalloc(c->pool, line.len); |
1136 | 637 if (line.data == NULL) { |
638 ngx_mail_proxy_internal_server_error(s); | |
639 return; | |
640 } | |
641 | |
5522
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
642 p = ngx_cpymem(line.data, "XCLIENT ADDR=", sizeof("XCLIENT ADDR=") - 1); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
643 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
644 #if (NGX_HAVE_INET6) |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
645 if (s->connection->sockaddr->sa_family == AF_INET6) { |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
646 p = ngx_cpymem(p, "IPV6:", sizeof("IPV6:") - 1); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
647 } |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
648 #endif |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
649 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
650 p = ngx_copy(p, s->connection->addr_text.data, |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
651 s->connection->addr_text.len); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
652 |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
653 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
654 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
655 if (s->login.len && !pcf->smtp_auth) { |
5522
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
656 p = ngx_cpymem(p, " LOGIN=", sizeof(" LOGIN=") - 1); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
657 p = ngx_copy(p, s->login.data, s->login.len); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
658 } |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
659 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
660 p = ngx_cpymem(p, " NAME=", sizeof(" NAME=") - 1); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
661 p = ngx_copy(p, s->host.data, s->host.len); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
662 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
663 *p++ = CR; *p++ = LF; |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
664 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
665 line.len = p - line.data; |
2309 | 666 |
2497 | 667 if (s->smtp_helo.len) { |
668 s->mail_state = ngx_smtp_xclient_helo; | |
669 | |
670 } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { | |
671 s->mail_state = ngx_smtp_xclient_from; | |
672 | |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
673 } else if (pcf->smtp_auth) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
674 s->mail_state = ngx_smtp_xclient_auth; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
675 |
2497 | 676 } else { |
677 s->mail_state = ngx_smtp_xclient; | |
678 } | |
679 | |
680 break; | |
681 | |
682 case ngx_smtp_xclient_helo: | |
683 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
684 "mail proxy send client ehlo"); | |
685 | |
686 s->connection->log->action = "sending client HELO/EHLO to upstream"; | |
687 | |
688 line.len = sizeof("HELO " CRLF) - 1 + s->smtp_helo.len; | |
689 | |
690 line.data = ngx_pnalloc(c->pool, line.len); | |
691 if (line.data == NULL) { | |
692 ngx_mail_proxy_internal_server_error(s); | |
693 return; | |
694 } | |
695 | |
696 line.len = ngx_sprintf(line.data, | |
697 ((s->esmtp) ? "EHLO %V" CRLF : "HELO %V" CRLF), | |
698 &s->smtp_helo) | |
699 - line.data; | |
700 | |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
701 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
702 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
703 if (s->auth_method == NGX_MAIL_AUTH_NONE) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
704 s->mail_state = ngx_smtp_helo_from; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
705 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
706 } else if (pcf->smtp_auth) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
707 s->mail_state = ngx_smtp_helo_auth; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
708 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
709 } else { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
710 s->mail_state = ngx_smtp_helo; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
711 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
712 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
713 break; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
714 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
715 case ngx_smtp_helo_auth: |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
716 case ngx_smtp_xclient_auth: |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
717 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
718 "mail proxy send auth"); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
719 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
720 s->connection->log->action = "sending AUTH to upstream"; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
721 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
722 if (s->passwd.data == NULL) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
723 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
724 "no password available"); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
725 ngx_mail_proxy_internal_server_error(s); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
726 return; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
727 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
728 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
729 auth.len = 1 + s->login.len + 1 + s->passwd.len; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
730 auth.data = ngx_pnalloc(c->pool, auth.len); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
731 if (auth.data == NULL) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
732 ngx_mail_proxy_internal_server_error(s); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
733 return; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
734 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
735 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
736 auth.len = ngx_sprintf(auth.data, "%Z%V%Z%V", &s->login, &s->passwd) |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
737 - auth.data; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
738 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
739 line.len = sizeof("AUTH PLAIN " CRLF) - 1 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
740 + ngx_base64_encoded_length(auth.len); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
741 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
742 line.data = ngx_pnalloc(c->pool, line.len); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
743 if (line.data == NULL) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
744 ngx_mail_proxy_internal_server_error(s); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
745 return; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
746 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
747 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
748 encoded.data = ngx_cpymem(line.data, "AUTH PLAIN ", |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
749 sizeof("AUTH PLAIN ") - 1); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
750 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
751 ngx_encode_base64(&encoded, &auth); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
752 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
753 p = encoded.data + encoded.len; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
754 *p++ = CR; *p = LF; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
755 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
756 s->mail_state = ngx_smtp_auth_plain; |
2309 | 757 |
758 break; | |
759 | |
760 case ngx_smtp_helo_from: | |
761 case ngx_smtp_xclient_from: | |
762 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
763 "mail proxy send mail from"); | |
764 | |
765 s->connection->log->action = "sending MAIL FROM to upstream"; | |
766 | |
767 line.len = s->smtp_from.len + sizeof(CRLF) - 1; | |
768 line.data = ngx_pnalloc(c->pool, line.len); | |
769 if (line.data == NULL) { | |
770 ngx_mail_proxy_internal_server_error(s); | |
771 return; | |
1136 | 772 } |
773 | |
2309 | 774 p = ngx_cpymem(line.data, s->smtp_from.data, s->smtp_from.len); |
775 *p++ = CR; *p = LF; | |
776 | |
777 s->mail_state = ngx_smtp_from; | |
778 | |
1136 | 779 break; |
780 | |
2309 | 781 case ngx_smtp_from: |
782 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
783 "mail proxy send rcpt to"); | |
784 | |
785 s->connection->log->action = "sending RCPT TO to upstream"; | |
786 | |
787 line.len = s->smtp_to.len + sizeof(CRLF) - 1; | |
788 line.data = ngx_pnalloc(c->pool, line.len); | |
789 if (line.data == NULL) { | |
790 ngx_mail_proxy_internal_server_error(s); | |
791 return; | |
792 } | |
793 | |
794 p = ngx_cpymem(line.data, s->smtp_to.data, s->smtp_to.len); | |
795 *p++ = CR; *p = LF; | |
796 | |
797 s->mail_state = ngx_smtp_to; | |
1136 | 798 |
2309 | 799 break; |
800 | |
801 case ngx_smtp_helo: | |
802 case ngx_smtp_xclient: | |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
803 case ngx_smtp_auth_plain: |
2309 | 804 case ngx_smtp_to: |
805 | |
806 b = s->proxy->buffer; | |
1136 | 807 |
2309 | 808 if (s->auth_method == NGX_MAIL_AUTH_NONE) { |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
809 b->pos = b->start; |
2309 | 810 |
811 } else { | |
2440
939b40aa9ab4
update r2439: make clear name
Igor Sysoev <igor@sysoev.ru>
parents:
2438
diff
changeset
|
812 ngx_memcpy(b->start, smtp_auth_ok, sizeof(smtp_auth_ok) - 1); |
939b40aa9ab4
update r2439: make clear name
Igor Sysoev <igor@sysoev.ru>
parents:
2438
diff
changeset
|
813 b->last = b->start + sizeof(smtp_auth_ok) - 1; |
2309 | 814 } |
815 | |
1136 | 816 s->connection->read->handler = ngx_mail_proxy_handler; |
817 s->connection->write->handler = ngx_mail_proxy_handler; | |
818 rev->handler = ngx_mail_proxy_handler; | |
819 c->write->handler = ngx_mail_proxy_handler; | |
820 | |
821 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
822 ngx_add_timer(s->connection->read, pcf->timeout); | |
823 ngx_del_timer(c->read); | |
824 | |
825 c->log->action = NULL; | |
826 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
827 | |
8151
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
828 if (s->buffer->pos < s->buffer->last |
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
829 || s->connection->read->ready) |
a5e6e8510634
Mail: fixed handling of blocked client read events in proxy.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8099
diff
changeset
|
830 { |
7835
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7796
diff
changeset
|
831 ngx_post_event(c->write, &ngx_posted_events); |
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7796
diff
changeset
|
832 } |
5398
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
833 |
7835
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7796
diff
changeset
|
834 ngx_mail_proxy_handler(s->connection->write); |
1136 | 835 |
836 return; | |
837 | |
838 default: | |
839 #if (NGX_SUPPRESS_WARN) | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3505
diff
changeset
|
840 ngx_str_null(&line); |
1136 | 841 #endif |
842 break; | |
843 } | |
844 | |
845 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { | |
846 /* | |
847 * we treat the incomplete sending as NGX_ERROR | |
848 * because it is very strange here | |
849 */ | |
850 ngx_mail_proxy_internal_server_error(s); | |
851 return; | |
852 } | |
853 | |
7790
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
854 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
855 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
856 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
857 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7725
diff
changeset
|
858 |
1136 | 859 s->proxy->buffer->pos = s->proxy->buffer->start; |
860 s->proxy->buffer->last = s->proxy->buffer->start; | |
861 } | |
862 | |
863 | |
864 static void | |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
865 ngx_mail_proxy_write_handler(ngx_event_t *wev) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
866 { |
583 | 867 ngx_connection_t *c; |
1136 | 868 ngx_mail_session_t *s; |
583 | 869 |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
870 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0, "mail proxy write handler"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
871 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
872 c = wev->data; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
873 s = c->data; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
874 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
875 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
876 if (ngx_mail_proxy_send_proxy_protocol(s) != NGX_OK) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
877 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
878 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
879 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
880 s->proxy->proxy_protocol = 0; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
881 } |
583 | 882 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
883 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
884 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
885 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
886 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
887 if (c->read->ready) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
888 ngx_post_event(c->read, &ngx_posted_events); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
889 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
890 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
891 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
892 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
893 static ngx_int_t |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
894 ngx_mail_proxy_send_proxy_protocol(ngx_mail_session_t *s) |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
895 { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
896 u_char *p; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
897 ssize_t n, size; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
898 ngx_connection_t *c; |
8099
17d6a537fb1b
Increased maximum read PROXY protocol header size.
Roman Arutyunyan <arut@nginx.com>
parents:
7843
diff
changeset
|
899 u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
900 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
901 s->connection->log->action = "sending PROXY protocol header to upstream"; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
902 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
903 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
904 "mail proxy send PROXY protocol header"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
905 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
906 p = ngx_proxy_protocol_write(s->connection, buf, |
8099
17d6a537fb1b
Increased maximum read PROXY protocol header size.
Roman Arutyunyan <arut@nginx.com>
parents:
7843
diff
changeset
|
907 buf + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
908 if (p == NULL) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
909 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
910 return NGX_ERROR; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
911 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
912 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
913 c = s->proxy->upstream.connection; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
914 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
915 size = p - buf; |
583 | 916 |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
917 n = c->send(c, buf, size); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
918 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
919 if (n == NGX_AGAIN) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
920 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
921 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
922 return NGX_ERROR; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
923 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
924 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
925 return NGX_AGAIN; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
926 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
927 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
928 if (n == NGX_ERROR) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
929 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
930 return NGX_ERROR; |
583 | 931 } |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
932 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
933 if (n != size) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
934 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
935 /* |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
936 * PROXY protocol specification: |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
937 * The sender must always ensure that the header |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
938 * is sent at once, so that the transport layer |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
939 * maintains atomicity along the path to the receiver. |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
940 */ |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
941 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
942 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
943 "could not send PROXY protocol header at once"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
944 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
945 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
946 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
947 return NGX_ERROR; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
948 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
949 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
950 return NGX_OK; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
951 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
952 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
953 |
521 | 954 static ngx_int_t |
1136 | 955 ngx_mail_proxy_read_response(ngx_mail_session_t *s, ngx_uint_t state) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
956 { |
5399
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
957 u_char *p, *m; |
857 | 958 ssize_t n; |
959 ngx_buf_t *b; | |
1136 | 960 ngx_mail_proxy_conf_t *pcf; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
961 |
587 | 962 s->connection->log->action = "reading response from upstream"; |
963 | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
964 b = s->proxy->buffer; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
965 |
539 | 966 n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection, |
967 b->last, b->end - b->last); | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
968 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
969 if (n == NGX_ERROR || n == 0) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
970 return NGX_ERROR; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
971 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
972 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
973 if (n == NGX_AGAIN) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
974 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
975 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
976 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
977 b->last += n; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
978 |
3505
c631ef8beaaa
Zimbra IMAP server may return only 4 bytes: "+ \r\n"
Igor Sysoev <igor@sysoev.ru>
parents:
3269
diff
changeset
|
979 if (b->last - b->pos < 4) { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
980 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
981 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
982 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
983 if (*(b->last - 2) != CR || *(b->last - 1) != LF) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
984 if (b->last == b->end) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
985 *(b->last - 1) = '\0'; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
986 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
987 "upstream sent too long response line: \"%s\"", |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
988 b->pos); |
571 | 989 return NGX_ERROR; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
990 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
991 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
992 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
993 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
994 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
995 p = b->pos; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
996 |
1136 | 997 switch (s->protocol) { |
998 | |
999 case NGX_MAIL_POP3_PROTOCOL: | |
527 | 1000 if (p[0] == '+' && p[1] == 'O' && p[2] == 'K') { |
1001 return NGX_OK; | |
1002 } | |
1136 | 1003 break; |
527 | 1004 |
1136 | 1005 case NGX_MAIL_IMAP_PROTOCOL: |
663 | 1006 switch (state) { |
1007 | |
1008 case ngx_imap_start: | |
527 | 1009 if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') { |
1010 return NGX_OK; | |
1011 } | |
663 | 1012 break; |
527 | 1013 |
663 | 1014 case ngx_imap_login: |
1015 case ngx_imap_user: | |
529 | 1016 if (p[0] == '+') { |
527 | 1017 return NGX_OK; |
1018 } | |
663 | 1019 break; |
1020 | |
1021 case ngx_imap_passwd: | |
1022 if (ngx_strncmp(p, s->tag.data, s->tag.len) == 0) { | |
1023 p += s->tag.len; | |
1024 if (p[0] == 'O' && p[1] == 'K') { | |
1025 return NGX_OK; | |
1026 } | |
1027 } | |
1028 break; | |
527 | 1029 } |
1136 | 1030 |
1031 break; | |
1032 | |
1033 default: /* NGX_MAIL_SMTP_PROTOCOL */ | |
5399
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1034 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1035 if (p[3] == '-') { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1036 /* multiline reply, check if we got last line */ |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1037 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1038 m = b->last - (sizeof(CRLF "200" CRLF) - 1); |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1039 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1040 while (m > p) { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1041 if (m[0] == CR && m[1] == LF) { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1042 break; |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1043 } |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1044 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1045 m--; |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1046 } |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1047 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1048 if (m <= p || m[5] == '-') { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1049 return NGX_AGAIN; |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1050 } |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1051 } |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1052 |
1136 | 1053 switch (state) { |
1054 | |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1055 case ngx_smtp_start: |
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1056 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { |
1166 | 1057 return NGX_OK; |
1058 } | |
1059 break; | |
1136 | 1060 |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1061 case ngx_smtp_helo: |
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1062 case ngx_smtp_helo_xclient: |
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1063 case ngx_smtp_helo_from: |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1064 case ngx_smtp_helo_auth: |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1065 case ngx_smtp_from: |
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1066 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { |
2309 | 1067 return NGX_OK; |
1068 } | |
1069 break; | |
1070 | |
1136 | 1071 case ngx_smtp_xclient: |
2309 | 1072 case ngx_smtp_xclient_from: |
2497 | 1073 case ngx_smtp_xclient_helo: |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1074 case ngx_smtp_xclient_auth: |
2309 | 1075 if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') { |
1166 | 1076 return NGX_OK; |
1077 } | |
1078 break; | |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1079 |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1080 case ngx_smtp_auth_plain: |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1081 if (p[0] == '2' && p[1] == '3' && p[2] == '5') { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1082 return NGX_OK; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1083 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1084 break; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1085 |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1086 case ngx_smtp_to: |
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1087 return NGX_OK; |
1136 | 1088 } |
1089 | |
1166 | 1090 break; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1091 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1092 |
1136 | 1093 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
857 | 1094 |
1095 if (pcf->pass_error_message == 0) { | |
1096 *(b->last - 2) = '\0'; | |
1097 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | |
1098 "upstream sent invalid response: \"%s\"", p); | |
1099 return NGX_ERROR; | |
1100 } | |
1101 | |
1102 s->out.len = b->last - p - 2; | |
1103 s->out.data = p; | |
1104 | |
1105 ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, | |
1106 "upstream sent invalid response: \"%V\"", &s->out); | |
1107 | |
1108 s->out.len = b->last - b->pos; | |
1109 s->out.data = b->pos; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1110 |
571 | 1111 return NGX_ERROR; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1112 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1113 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1114 |
521 | 1115 static void |
1136 | 1116 ngx_mail_proxy_handler(ngx_event_t *ev) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1117 { |
583 | 1118 char *action, *recv_action, *send_action; |
539 | 1119 size_t size; |
1120 ssize_t n; | |
1121 ngx_buf_t *b; | |
583 | 1122 ngx_uint_t do_write; |
539 | 1123 ngx_connection_t *c, *src, *dst; |
1136 | 1124 ngx_mail_session_t *s; |
1125 ngx_mail_proxy_conf_t *pcf; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1126 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1127 c = ev->data; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1128 s = c->data; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1129 |
7156
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1130 if (ev->timedout || c->close) { |
583 | 1131 c->log->action = "proxying"; |
1132 | |
7156
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1133 if (c->close) { |
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1134 ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout"); |
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1135 |
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1136 } else if (c == s->connection) { |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1137 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1138 "client timed out"); |
577 | 1139 c->timedout = 1; |
1140 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1141 } else { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1142 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1143 "upstream timed out"); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1144 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1145 |
1136 | 1146 ngx_mail_proxy_close_session(s); |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1147 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1148 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1149 |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1150 if (c == s->connection) { |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1151 if (ev->write) { |
583 | 1152 recv_action = "proxying and reading from upstream"; |
1153 send_action = "proxying and sending to client"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1154 src = s->proxy->upstream.connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1155 dst = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1156 b = s->proxy->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1157 |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1158 } else { |
583 | 1159 recv_action = "proxying and reading from client"; |
1160 send_action = "proxying and sending to upstream"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1161 src = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1162 dst = s->proxy->upstream.connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1163 b = s->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1164 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1165 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1166 } else { |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1167 if (ev->write) { |
589 | 1168 recv_action = "proxying and reading from client"; |
1169 send_action = "proxying and sending to upstream"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1170 src = s->connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1171 dst = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1172 b = s->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1173 |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1174 } else { |
589 | 1175 recv_action = "proxying and reading from upstream"; |
1176 send_action = "proxying and sending to client"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1177 src = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1178 dst = s->connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1179 b = s->proxy->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1180 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1181 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1182 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1183 do_write = ev->write ? 1 : 0; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1184 |
1136 | 1185 ngx_log_debug3(NGX_LOG_DEBUG_MAIL, ev->log, 0, |
6480 | 1186 "mail proxy handler: %ui, #%d > #%d", |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1187 do_write, src->fd, dst->fd); |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1188 |
583 | 1189 for ( ;; ) { |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1190 |
583 | 1191 if (do_write) { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1192 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1193 size = b->last - b->pos; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1194 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1195 if (size && dst->write->ready) { |
583 | 1196 c->log->action = send_action; |
1197 | |
539 | 1198 n = dst->send(dst, b->pos, size); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1199 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1200 if (n == NGX_ERROR) { |
1136 | 1201 ngx_mail_proxy_close_session(s); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1202 return; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1203 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1204 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1205 if (n > 0) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1206 b->pos += n; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1207 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1208 if (b->pos == b->last) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1209 b->pos = b->start; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1210 b->last = b->start; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1211 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1212 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1213 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1214 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1215 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1216 size = b->end - b->last; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1217 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1218 if (size && src->read->ready) { |
583 | 1219 c->log->action = recv_action; |
1220 | |
539 | 1221 n = src->recv(src, b->last, size); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1222 |
583 | 1223 if (n == NGX_AGAIN || n == 0) { |
1224 break; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1225 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1226 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1227 if (n > 0) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1228 do_write = 1; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1229 b->last += n; |
583 | 1230 |
1231 continue; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1232 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1233 |
583 | 1234 if (n == NGX_ERROR) { |
1235 src->read->eof = 1; | |
539 | 1236 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1237 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1238 |
583 | 1239 break; |
1240 } | |
1241 | |
1242 c->log->action = "proxying"; | |
1243 | |
1342
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1244 if ((s->connection->read->eof && s->buffer->pos == s->buffer->last) |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1245 || (s->proxy->upstream.connection->read->eof |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1246 && s->proxy->buffer->pos == s->proxy->buffer->last) |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1247 || (s->connection->read->eof |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1248 && s->proxy->upstream.connection->read->eof)) |
583 | 1249 { |
1250 action = c->log->action; | |
1251 c->log->action = NULL; | |
1252 ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxied session done"); | |
1253 c->log->action = action; | |
1254 | |
1136 | 1255 ngx_mail_proxy_close_session(s); |
583 | 1256 return; |
1257 } | |
1258 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1259 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { |
1136 | 1260 ngx_mail_proxy_close_session(s); |
583 | 1261 return; |
1262 } | |
1263 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1264 if (ngx_handle_read_event(dst->read, 0) != NGX_OK) { |
1136 | 1265 ngx_mail_proxy_close_session(s); |
583 | 1266 return; |
1267 } | |
1268 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1269 if (ngx_handle_write_event(src->write, 0) != NGX_OK) { |
1136 | 1270 ngx_mail_proxy_close_session(s); |
583 | 1271 return; |
1272 } | |
1273 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1274 if (ngx_handle_read_event(src->read, 0) != NGX_OK) { |
1136 | 1275 ngx_mail_proxy_close_session(s); |
583 | 1276 return; |
1277 } | |
1278 | |
1279 if (c == s->connection) { | |
1136 | 1280 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
583 | 1281 ngx_add_timer(c->read, pcf->timeout); |
1282 } | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1283 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1284 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1285 |
521 | 1286 static void |
1136 | 1287 ngx_mail_proxy_upstream_error(ngx_mail_session_t *s) |
857 | 1288 { |
1289 if (s->proxy->upstream.connection) { | |
1136 | 1290 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
1291 "close mail proxy connection: %d", | |
857 | 1292 s->proxy->upstream.connection->fd); |
1293 | |
1294 ngx_close_connection(s->proxy->upstream.connection); | |
1295 } | |
1296 | |
1297 if (s->out.len == 0) { | |
1136 | 1298 ngx_mail_session_internal_server_error(s); |
857 | 1299 return; |
1300 } | |
1301 | |
1302 s->quit = 1; | |
1136 | 1303 ngx_mail_send(s->connection->write); |
857 | 1304 } |
1305 | |
1306 | |
1307 static void | |
1136 | 1308 ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s) |
527 | 1309 { |
1310 if (s->proxy->upstream.connection) { | |
1136 | 1311 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
1312 "close mail proxy connection: %d", | |
527 | 1313 s->proxy->upstream.connection->fd); |
1314 | |
1315 ngx_close_connection(s->proxy->upstream.connection); | |
1316 } | |
1317 | |
1136 | 1318 ngx_mail_session_internal_server_error(s); |
527 | 1319 } |
1320 | |
1321 | |
1322 static void | |
1136 | 1323 ngx_mail_proxy_close_session(ngx_mail_session_t *s) |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1324 { |
521 | 1325 if (s->proxy->upstream.connection) { |
1136 | 1326 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
1327 "close mail proxy connection: %d", | |
521 | 1328 s->proxy->upstream.connection->fd); |
1329 | |
1330 ngx_close_connection(s->proxy->upstream.connection); | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1331 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1332 |
1136 | 1333 ngx_mail_close_connection(s->connection); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1334 } |
521 | 1335 |
1336 | |
1337 static void * | |
1136 | 1338 ngx_mail_proxy_create_conf(ngx_conf_t *cf) |
577 | 1339 { |
1136 | 1340 ngx_mail_proxy_conf_t *pcf; |
577 | 1341 |
1136 | 1342 pcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_proxy_conf_t)); |
521 | 1343 if (pcf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2497
diff
changeset
|
1344 return NULL; |
521 | 1345 } |
1346 | |
1347 pcf->enable = NGX_CONF_UNSET; | |
857 | 1348 pcf->pass_error_message = NGX_CONF_UNSET; |
1136 | 1349 pcf->xclient = NGX_CONF_UNSET; |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1350 pcf->smtp_auth = NGX_CONF_UNSET; |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
1351 pcf->proxy_protocol = NGX_CONF_UNSET; |
539 | 1352 pcf->buffer_size = NGX_CONF_UNSET_SIZE; |
1353 pcf->timeout = NGX_CONF_UNSET_MSEC; | |
521 | 1354 |
1355 return pcf; | |
1356 } | |
1357 | |
1358 | |
1359 static char * | |
1136 | 1360 ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 1361 { |
1136 | 1362 ngx_mail_proxy_conf_t *prev = parent; |
1363 ngx_mail_proxy_conf_t *conf = child; | |
521 | 1364 |
539 | 1365 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
857 | 1366 ngx_conf_merge_value(conf->pass_error_message, prev->pass_error_message, 0); |
1136 | 1367 ngx_conf_merge_value(conf->xclient, prev->xclient, 1); |
7725
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1368 ngx_conf_merge_value(conf->smtp_auth, prev->smtp_auth, 0); |
7796
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7790
diff
changeset
|
1369 ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); |
539 | 1370 ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, |
1371 (size_t) ngx_pagesize); | |
1372 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 24 * 60 * 60000); | |
521 | 1373 |
1374 return NGX_CONF_OK; | |
1375 } |