Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_proxy_module.c @ 8651:7189cb2b4c5d
Version bump.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Tue, 14 Sep 2021 12:12:02 +0300 |
parents | b38728495e1a |
children | 17d6a537fb1b |
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; |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
19 ngx_flag_t smtp_auth; |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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); | |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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:
8339
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 | |
8178
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 |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
87 { ngx_string("proxy_protocol"), |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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:
8339
diff
changeset
|
89 ngx_conf_set_flag_slot, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
90 NGX_MAIL_SRV_CONF_OFFSET, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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:
8339
diff
changeset
|
92 NULL }, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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; |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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 | |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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:
8339
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 } |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
200 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
201 if (rc == NGX_AGAIN) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
202 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
203 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
204 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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 |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
250 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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:
8339
diff
changeset
|
252 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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:
8339
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:
8339
diff
changeset
|
255 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
256 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
257 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
258 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
259 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
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) { |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
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:
8178
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:
8178
diff
changeset
|
266 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
267 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
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 | |
8459
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8456
diff
changeset
|
330 if (s->buffer->pos < s->buffer->last) { |
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8456
diff
changeset
|
331 ngx_post_event(c->write, &ngx_posted_events); |
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8456
diff
changeset
|
332 } |
815c63581be4
Mail: POP3 pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8456
diff
changeset
|
333 |
1136 | 334 ngx_mail_proxy_handler(s->connection->write); |
663 | 335 |
336 return; | |
337 | |
527 | 338 default: |
339 #if (NGX_SUPPRESS_WARN) | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3505
diff
changeset
|
340 ngx_str_null(&line); |
527 | 341 #endif |
342 break; | |
343 } | |
344 | |
539 | 345 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { |
527 | 346 /* |
347 * we treat the incomplete sending as NGX_ERROR | |
348 * because it is very strange here | |
349 */ | |
1136 | 350 ngx_mail_proxy_internal_server_error(s); |
527 | 351 return; |
352 } | |
353 | |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
354 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:
8178
diff
changeset
|
355 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
356 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
357 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
358 |
527 | 359 s->proxy->buffer->pos = s->proxy->buffer->start; |
360 s->proxy->buffer->last = s->proxy->buffer->start; | |
361 } | |
362 | |
363 | |
364 static void | |
1136 | 365 ngx_mail_proxy_imap_handler(ngx_event_t *rev) |
527 | 366 { |
539 | 367 u_char *p; |
368 ngx_int_t rc; | |
369 ngx_str_t line; | |
370 ngx_connection_t *c; | |
1136 | 371 ngx_mail_session_t *s; |
372 ngx_mail_proxy_conf_t *pcf; | |
527 | 373 |
1136 | 374 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
375 "mail proxy imap auth handler"); | |
527 | 376 |
377 c = rev->data; | |
378 s = c->data; | |
379 | |
380 if (rev->timedout) { | |
381 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
382 "upstream timed out"); | |
577 | 383 c->timedout = 1; |
1136 | 384 ngx_mail_proxy_internal_server_error(s); |
527 | 385 return; |
386 } | |
387 | |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
388 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
389 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:
8339
diff
changeset
|
390 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
391 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:
8339
diff
changeset
|
392 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
393 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
394 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
395 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
396 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
397 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
398 |
1136 | 399 rc = ngx_mail_proxy_read_response(s, s->mail_state); |
527 | 400 |
401 if (rc == NGX_AGAIN) { | |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
402 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:
8178
diff
changeset
|
403 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
404 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
405 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
406 |
527 | 407 return; |
408 } | |
409 | |
571 | 410 if (rc == NGX_ERROR) { |
1136 | 411 ngx_mail_proxy_upstream_error(s); |
527 | 412 return; |
413 } | |
414 | |
1136 | 415 switch (s->mail_state) { |
527 | 416 |
1136 | 417 case ngx_imap_start: |
418 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
419 "mail proxy send login"); | |
527 | 420 |
1136 | 421 s->connection->log->action = "sending LOGIN command to upstream"; |
587 | 422 |
1136 | 423 line.len = s->tag.len + sizeof("LOGIN ") - 1 |
424 + 1 + NGX_SIZE_T_LEN + 1 + 2; | |
2049 | 425 line.data = ngx_pnalloc(c->pool, line.len); |
527 | 426 if (line.data == NULL) { |
1136 | 427 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
|
428 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
429 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
430 |
1136 | 431 line.len = ngx_sprintf(line.data, "%VLOGIN {%uz}" CRLF, |
432 &s->tag, s->login.len) | |
433 - line.data; | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
434 |
1136 | 435 s->mail_state = ngx_imap_login; |
527 | 436 break; |
437 | |
1136 | 438 case ngx_imap_login: |
439 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user"); | |
440 | |
441 s->connection->log->action = "sending user name to upstream"; | |
442 | |
443 line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2; | |
2049 | 444 line.data = ngx_pnalloc(c->pool, line.len); |
1136 | 445 if (line.data == NULL) { |
446 ngx_mail_proxy_internal_server_error(s); | |
447 return; | |
448 } | |
449 | |
450 line.len = ngx_sprintf(line.data, "%V {%uz}" CRLF, | |
451 &s->login, s->passwd.len) | |
452 - line.data; | |
453 | |
454 s->mail_state = ngx_imap_user; | |
455 break; | |
456 | |
457 case ngx_imap_user: | |
458 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
459 "mail proxy send passwd"); | |
527 | 460 |
587 | 461 s->connection->log->action = "sending password to upstream"; |
462 | |
1136 | 463 line.len = s->passwd.len + 2; |
2049 | 464 line.data = ngx_pnalloc(c->pool, line.len); |
527 | 465 if (line.data == NULL) { |
1136 | 466 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
|
467 return; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
468 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
469 |
1136 | 470 p = ngx_cpymem(line.data, s->passwd.data, s->passwd.len); |
527 | 471 *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
|
472 |
1136 | 473 s->mail_state = ngx_imap_passwd; |
527 | 474 break; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
475 |
1136 | 476 case ngx_imap_passwd: |
477 s->connection->read->handler = ngx_mail_proxy_handler; | |
478 s->connection->write->handler = ngx_mail_proxy_handler; | |
479 rev->handler = ngx_mail_proxy_handler; | |
480 c->write->handler = ngx_mail_proxy_handler; | |
663 | 481 |
1136 | 482 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
663 | 483 ngx_add_timer(s->connection->read, pcf->timeout); |
484 ngx_del_timer(c->read); | |
485 | |
486 c->log->action = NULL; | |
487 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
488 | |
8464
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8459
diff
changeset
|
489 if (s->buffer->pos < s->buffer->last) { |
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8459
diff
changeset
|
490 ngx_post_event(c->write, &ngx_posted_events); |
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8459
diff
changeset
|
491 } |
b38728495e1a
Mail: IMAP pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8459
diff
changeset
|
492 |
1136 | 493 ngx_mail_proxy_handler(s->connection->write); |
663 | 494 |
495 return; | |
496 | |
527 | 497 default: |
498 #if (NGX_SUPPRESS_WARN) | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3505
diff
changeset
|
499 ngx_str_null(&line); |
527 | 500 #endif |
501 break; | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
502 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
503 |
539 | 504 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
|
505 /* |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
506 * 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
|
507 * 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
|
508 */ |
1136 | 509 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
|
510 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
511 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
512 |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
513 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:
8178
diff
changeset
|
514 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
515 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
516 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
517 |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
518 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
|
519 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
|
520 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
521 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
522 |
521 | 523 static void |
1136 | 524 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) |
525 { | |
526 u_char *p; | |
527 ngx_int_t rc; | |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
528 ngx_str_t line, auth, encoded; |
2309 | 529 ngx_buf_t *b; |
1136 | 530 ngx_connection_t *c; |
531 ngx_mail_session_t *s; | |
532 ngx_mail_proxy_conf_t *pcf; | |
533 ngx_mail_core_srv_conf_t *cscf; | |
534 | |
535 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
536 "mail proxy smtp auth handler"); | |
537 | |
538 c = rev->data; | |
539 s = c->data; | |
540 | |
541 if (rev->timedout) { | |
542 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
543 "upstream timed out"); | |
544 c->timedout = 1; | |
545 ngx_mail_proxy_internal_server_error(s); | |
546 return; | |
547 } | |
548 | |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
549 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
550 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:
8339
diff
changeset
|
551 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
552 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:
8339
diff
changeset
|
553 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
554 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
555 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
556 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
557 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
558 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
559 |
1136 | 560 rc = ngx_mail_proxy_read_response(s, s->mail_state); |
561 | |
562 if (rc == NGX_AGAIN) { | |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
563 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:
8178
diff
changeset
|
564 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
565 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
566 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
567 |
1136 | 568 return; |
569 } | |
570 | |
571 if (rc == NGX_ERROR) { | |
572 ngx_mail_proxy_upstream_error(s); | |
573 return; | |
574 } | |
575 | |
576 switch (s->mail_state) { | |
577 | |
578 case ngx_smtp_start: | |
579 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send ehlo"); | |
580 | |
581 s->connection->log->action = "sending HELO/EHLO to upstream"; | |
582 | |
583 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); | |
584 | |
585 line.len = sizeof("HELO ") - 1 + cscf->server_name.len + 2; | |
2049 | 586 line.data = ngx_pnalloc(c->pool, line.len); |
1136 | 587 if (line.data == NULL) { |
588 ngx_mail_proxy_internal_server_error(s); | |
589 return; | |
590 } | |
591 | |
592 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
593 | |
594 p = ngx_cpymem(line.data, | |
595 ((s->esmtp || pcf->xclient) ? "EHLO " : "HELO "), | |
596 sizeof("HELO ") - 1); | |
597 | |
598 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); | |
599 *p++ = CR; *p = LF; | |
600 | |
2309 | 601 if (pcf->xclient) { |
602 s->mail_state = ngx_smtp_helo_xclient; | |
603 | |
604 } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { | |
605 s->mail_state = ngx_smtp_helo_from; | |
606 | |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
607 } else if (pcf->smtp_auth) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
608 s->mail_state = ngx_smtp_helo_auth; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
609 |
2309 | 610 } else { |
611 s->mail_state = ngx_smtp_helo; | |
612 } | |
1136 | 613 |
614 break; | |
615 | |
2309 | 616 case ngx_smtp_helo_xclient: |
1136 | 617 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
618 "mail proxy send xclient"); | |
619 | |
620 s->connection->log->action = "sending XCLIENT to upstream"; | |
621 | |
2497 | 622 line.len = sizeof("XCLIENT ADDR= LOGIN= NAME=" |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
623 CRLF) - 1 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
624 + s->connection->addr_text.len + s->login.len + s->host.len; |
1136 | 625 |
5522
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
626 #if (NGX_HAVE_INET6) |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
627 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
|
628 line.len += sizeof("IPV6:") - 1; |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
629 } |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
630 #endif |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
631 |
2049 | 632 line.data = ngx_pnalloc(c->pool, line.len); |
1136 | 633 if (line.data == NULL) { |
634 ngx_mail_proxy_internal_server_error(s); | |
635 return; | |
636 } | |
637 | |
5522
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
638 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
|
639 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
640 #if (NGX_HAVE_INET6) |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
641 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
|
642 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
|
643 } |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
644 #endif |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
645 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
646 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
|
647 s->connection->addr_text.len); |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
648 |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
649 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
|
650 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 } |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
655 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
656 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
|
657 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
|
658 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
659 *p++ = CR; *p++ = LF; |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
660 |
bb3dc21c89ef
Mail: fixed passing of IPv6 client address in XCLIENT.
Ruslan Ermilov <ru@nginx.com>
parents:
5399
diff
changeset
|
661 line.len = p - line.data; |
2309 | 662 |
2497 | 663 if (s->smtp_helo.len) { |
664 s->mail_state = ngx_smtp_xclient_helo; | |
665 | |
666 } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { | |
667 s->mail_state = ngx_smtp_xclient_from; | |
668 | |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
669 } else if (pcf->smtp_auth) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
670 s->mail_state = ngx_smtp_xclient_auth; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
671 |
2497 | 672 } else { |
673 s->mail_state = ngx_smtp_xclient; | |
674 } | |
675 | |
676 break; | |
677 | |
678 case ngx_smtp_xclient_helo: | |
679 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
680 "mail proxy send client ehlo"); | |
681 | |
682 s->connection->log->action = "sending client HELO/EHLO to upstream"; | |
683 | |
684 line.len = sizeof("HELO " CRLF) - 1 + s->smtp_helo.len; | |
685 | |
686 line.data = ngx_pnalloc(c->pool, line.len); | |
687 if (line.data == NULL) { | |
688 ngx_mail_proxy_internal_server_error(s); | |
689 return; | |
690 } | |
691 | |
692 line.len = ngx_sprintf(line.data, | |
693 ((s->esmtp) ? "EHLO %V" CRLF : "HELO %V" CRLF), | |
694 &s->smtp_helo) | |
695 - line.data; | |
696 | |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
697 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
|
698 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
699 if (s->auth_method == NGX_MAIL_AUTH_NONE) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
700 s->mail_state = ngx_smtp_helo_from; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
701 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
702 } else if (pcf->smtp_auth) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
703 s->mail_state = ngx_smtp_helo_auth; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
704 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
705 } else { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
706 s->mail_state = ngx_smtp_helo; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
707 } |
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 break; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
710 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
711 case ngx_smtp_helo_auth: |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
712 case ngx_smtp_xclient_auth: |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
713 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
|
714 "mail proxy send auth"); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
715 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
716 s->connection->log->action = "sending AUTH to upstream"; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
717 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
718 if (s->passwd.data == NULL) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
719 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
|
720 "no password available"); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
721 ngx_mail_proxy_internal_server_error(s); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
722 return; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
723 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
724 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
725 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
|
726 auth.data = ngx_pnalloc(c->pool, auth.len); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
727 if (auth.data == NULL) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
728 ngx_mail_proxy_internal_server_error(s); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
729 return; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
730 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
731 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
732 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
|
733 - auth.data; |
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 line.len = sizeof("AUTH PLAIN " CRLF) - 1 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
736 + ngx_base64_encoded_length(auth.len); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
737 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
738 line.data = ngx_pnalloc(c->pool, line.len); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
739 if (line.data == NULL) { |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
740 ngx_mail_proxy_internal_server_error(s); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
741 return; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
742 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
743 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
744 encoded.data = ngx_cpymem(line.data, "AUTH PLAIN ", |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
745 sizeof("AUTH PLAIN ") - 1); |
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 ngx_encode_base64(&encoded, &auth); |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
748 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
749 p = encoded.data + encoded.len; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
750 *p++ = CR; *p = LF; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
751 |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
752 s->mail_state = ngx_smtp_auth_plain; |
2309 | 753 |
754 break; | |
755 | |
756 case ngx_smtp_helo_from: | |
757 case ngx_smtp_xclient_from: | |
758 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
759 "mail proxy send mail from"); | |
760 | |
761 s->connection->log->action = "sending MAIL FROM to upstream"; | |
762 | |
763 line.len = s->smtp_from.len + sizeof(CRLF) - 1; | |
764 line.data = ngx_pnalloc(c->pool, line.len); | |
765 if (line.data == NULL) { | |
766 ngx_mail_proxy_internal_server_error(s); | |
767 return; | |
1136 | 768 } |
769 | |
2309 | 770 p = ngx_cpymem(line.data, s->smtp_from.data, s->smtp_from.len); |
771 *p++ = CR; *p = LF; | |
772 | |
773 s->mail_state = ngx_smtp_from; | |
774 | |
1136 | 775 break; |
776 | |
2309 | 777 case ngx_smtp_from: |
778 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
779 "mail proxy send rcpt to"); | |
780 | |
781 s->connection->log->action = "sending RCPT TO to upstream"; | |
782 | |
783 line.len = s->smtp_to.len + sizeof(CRLF) - 1; | |
784 line.data = ngx_pnalloc(c->pool, line.len); | |
785 if (line.data == NULL) { | |
786 ngx_mail_proxy_internal_server_error(s); | |
787 return; | |
788 } | |
789 | |
790 p = ngx_cpymem(line.data, s->smtp_to.data, s->smtp_to.len); | |
791 *p++ = CR; *p = LF; | |
792 | |
793 s->mail_state = ngx_smtp_to; | |
1136 | 794 |
2309 | 795 break; |
796 | |
797 case ngx_smtp_helo: | |
798 case ngx_smtp_xclient: | |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
799 case ngx_smtp_auth_plain: |
2309 | 800 case ngx_smtp_to: |
801 | |
802 b = s->proxy->buffer; | |
1136 | 803 |
2309 | 804 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
|
805 b->pos = b->start; |
2309 | 806 |
807 } else { | |
2440
939b40aa9ab4
update r2439: make clear name
Igor Sysoev <igor@sysoev.ru>
parents:
2438
diff
changeset
|
808 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
|
809 b->last = b->start + sizeof(smtp_auth_ok) - 1; |
2309 | 810 } |
811 | |
1136 | 812 s->connection->read->handler = ngx_mail_proxy_handler; |
813 s->connection->write->handler = ngx_mail_proxy_handler; | |
814 rev->handler = ngx_mail_proxy_handler; | |
815 c->write->handler = ngx_mail_proxy_handler; | |
816 | |
817 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
818 ngx_add_timer(s->connection->read, pcf->timeout); | |
819 ngx_del_timer(c->read); | |
820 | |
821 c->log->action = NULL; | |
822 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
823 | |
8456
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8345
diff
changeset
|
824 if (s->buffer->pos < s->buffer->last) { |
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8345
diff
changeset
|
825 ngx_post_event(c->write, &ngx_posted_events); |
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8345
diff
changeset
|
826 } |
5398
04e43d03e153
Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
827 |
8456
c72d8839f427
Mail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8345
diff
changeset
|
828 ngx_mail_proxy_handler(s->connection->write); |
1136 | 829 |
830 return; | |
831 | |
832 default: | |
833 #if (NGX_SUPPRESS_WARN) | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3505
diff
changeset
|
834 ngx_str_null(&line); |
1136 | 835 #endif |
836 break; | |
837 } | |
838 | |
839 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { | |
840 /* | |
841 * we treat the incomplete sending as NGX_ERROR | |
842 * because it is very strange here | |
843 */ | |
844 ngx_mail_proxy_internal_server_error(s); | |
845 return; | |
846 } | |
847 | |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
848 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:
8178
diff
changeset
|
849 ngx_mail_proxy_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
850 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
851 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8178
diff
changeset
|
852 |
1136 | 853 s->proxy->buffer->pos = s->proxy->buffer->start; |
854 s->proxy->buffer->last = s->proxy->buffer->start; | |
855 } | |
856 | |
857 | |
858 static void | |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
859 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
|
860 { |
583 | 861 ngx_connection_t *c; |
1136 | 862 ngx_mail_session_t *s; |
583 | 863 |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
864 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:
8339
diff
changeset
|
865 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
866 c = wev->data; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
867 s = c->data; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
868 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
869 if (s->proxy->proxy_protocol) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
870 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:
8339
diff
changeset
|
871 return; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
872 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
873 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
874 s->proxy->proxy_protocol = 0; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
875 } |
583 | 876 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
877 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
878 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
879 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
880 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
881 if (c->read->ready) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
882 ngx_post_event(c->read, &ngx_posted_events); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
883 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
884 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
885 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
886 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
887 static ngx_int_t |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
888 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:
8339
diff
changeset
|
889 { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
890 u_char *p; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
891 ssize_t n, size; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
892 ngx_connection_t *c; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
893 u_char buf[NGX_PROXY_PROTOCOL_MAX_HEADER]; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
894 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
895 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:
8339
diff
changeset
|
896 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
897 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:
8339
diff
changeset
|
898 "mail proxy send PROXY protocol header"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
899 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
900 p = ngx_proxy_protocol_write(s->connection, buf, |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
901 buf + NGX_PROXY_PROTOCOL_MAX_HEADER); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
902 if (p == NULL) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
903 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
904 return NGX_ERROR; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
905 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
906 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
907 c = s->proxy->upstream.connection; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
908 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
909 size = p - buf; |
583 | 910 |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
911 n = c->send(c, buf, size); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
912 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
913 if (n == NGX_AGAIN) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
914 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:
8339
diff
changeset
|
915 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
916 return NGX_ERROR; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
917 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
918 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
919 return NGX_AGAIN; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
920 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
921 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
922 if (n == NGX_ERROR) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
923 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
924 return NGX_ERROR; |
583 | 925 } |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
926 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
927 if (n != size) { |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
928 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
929 /* |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
930 * PROXY protocol specification: |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
931 * The sender must always ensure that the header |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
932 * is sent at once, so that the transport layer |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
933 * maintains atomicity along the path to the receiver. |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
934 */ |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
935 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
936 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:
8339
diff
changeset
|
937 "could not send PROXY protocol header at once"); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
938 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
939 ngx_mail_proxy_internal_server_error(s); |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
940 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
941 return NGX_ERROR; |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
942 } |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
943 |
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
944 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
|
945 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
946 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
947 |
521 | 948 static ngx_int_t |
1136 | 949 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
|
950 { |
5399
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
951 u_char *p, *m; |
857 | 952 ssize_t n; |
953 ngx_buf_t *b; | |
1136 | 954 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
|
955 |
587 | 956 s->connection->log->action = "reading response from upstream"; |
957 | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
958 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
|
959 |
539 | 960 n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection, |
961 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
|
962 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
963 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
|
964 return NGX_ERROR; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
965 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
966 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
967 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
|
968 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
969 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
970 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
971 b->last += n; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
972 |
3505
c631ef8beaaa
Zimbra IMAP server may return only 4 bytes: "+ \r\n"
Igor Sysoev <igor@sysoev.ru>
parents:
3269
diff
changeset
|
973 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
|
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 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
|
978 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
|
979 *(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
|
980 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
|
981 "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
|
982 b->pos); |
571 | 983 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
|
984 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
985 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
986 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
987 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
988 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
989 p = b->pos; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
990 |
1136 | 991 switch (s->protocol) { |
992 | |
993 case NGX_MAIL_POP3_PROTOCOL: | |
527 | 994 if (p[0] == '+' && p[1] == 'O' && p[2] == 'K') { |
995 return NGX_OK; | |
996 } | |
1136 | 997 break; |
527 | 998 |
1136 | 999 case NGX_MAIL_IMAP_PROTOCOL: |
663 | 1000 switch (state) { |
1001 | |
1002 case ngx_imap_start: | |
527 | 1003 if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') { |
1004 return NGX_OK; | |
1005 } | |
663 | 1006 break; |
527 | 1007 |
663 | 1008 case ngx_imap_login: |
1009 case ngx_imap_user: | |
529 | 1010 if (p[0] == '+') { |
527 | 1011 return NGX_OK; |
1012 } | |
663 | 1013 break; |
1014 | |
1015 case ngx_imap_passwd: | |
1016 if (ngx_strncmp(p, s->tag.data, s->tag.len) == 0) { | |
1017 p += s->tag.len; | |
1018 if (p[0] == 'O' && p[1] == 'K') { | |
1019 return NGX_OK; | |
1020 } | |
1021 } | |
1022 break; | |
527 | 1023 } |
1136 | 1024 |
1025 break; | |
1026 | |
1027 default: /* NGX_MAIL_SMTP_PROTOCOL */ | |
5399
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1028 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1029 if (p[3] == '-') { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1030 /* multiline reply, check if we got last line */ |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1031 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1032 m = b->last - (sizeof(CRLF "200" CRLF) - 1); |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1033 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1034 while (m > p) { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1035 if (m[0] == CR && m[1] == LF) { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1036 break; |
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 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1039 m--; |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1040 } |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1041 |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1042 if (m <= p || m[5] == '-') { |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1043 return NGX_AGAIN; |
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 } |
d3e09aa03a7a
Mail: handle smtp multiline replies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5398
diff
changeset
|
1046 |
1136 | 1047 switch (state) { |
1048 | |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1049 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
|
1050 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { |
1166 | 1051 return NGX_OK; |
1052 } | |
1053 break; | |
1136 | 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_helo: |
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1056 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
|
1057 case ngx_smtp_helo_from: |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1058 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
|
1059 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
|
1060 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { |
2309 | 1061 return NGX_OK; |
1062 } | |
1063 break; | |
1064 | |
1136 | 1065 case ngx_smtp_xclient: |
2309 | 1066 case ngx_smtp_xclient_from: |
2497 | 1067 case ngx_smtp_xclient_helo: |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1068 case ngx_smtp_xclient_auth: |
2309 | 1069 if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') { |
1166 | 1070 return NGX_OK; |
1071 } | |
1072 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
|
1073 |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1074 case ngx_smtp_auth_plain: |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1075 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
|
1076 return NGX_OK; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1077 } |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1078 break; |
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1079 |
2311
6bad42a41dd8
do not close session if SMTP backend returned an error on RCPT TO
Igor Sysoev <igor@sysoev.ru>
parents:
2309
diff
changeset
|
1080 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
|
1081 return NGX_OK; |
1136 | 1082 } |
1083 | |
1166 | 1084 break; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1085 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1086 |
1136 | 1087 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
857 | 1088 |
1089 if (pcf->pass_error_message == 0) { | |
1090 *(b->last - 2) = '\0'; | |
1091 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | |
1092 "upstream sent invalid response: \"%s\"", p); | |
1093 return NGX_ERROR; | |
1094 } | |
1095 | |
1096 s->out.len = b->last - p - 2; | |
1097 s->out.data = p; | |
1098 | |
1099 ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, | |
1100 "upstream sent invalid response: \"%V\"", &s->out); | |
1101 | |
1102 s->out.len = b->last - b->pos; | |
1103 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
|
1104 |
571 | 1105 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
|
1106 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1107 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1108 |
521 | 1109 static void |
1136 | 1110 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
|
1111 { |
583 | 1112 char *action, *recv_action, *send_action; |
539 | 1113 size_t size; |
1114 ssize_t n; | |
1115 ngx_buf_t *b; | |
583 | 1116 ngx_uint_t do_write; |
539 | 1117 ngx_connection_t *c, *src, *dst; |
1136 | 1118 ngx_mail_session_t *s; |
1119 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
|
1120 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1121 c = ev->data; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1122 s = c->data; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1123 |
7156
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1124 if (ev->timedout || c->close) { |
583 | 1125 c->log->action = "proxying"; |
1126 | |
7156
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1127 if (c->close) { |
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1128 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
|
1129 |
9c29644f6d03
Fixed worker_shutdown_timeout in various cases.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
1130 } 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
|
1131 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
|
1132 "client timed out"); |
577 | 1133 c->timedout = 1; |
1134 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1135 } else { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1136 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
|
1137 "upstream timed out"); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1138 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1139 |
1136 | 1140 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
|
1141 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1142 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1143 |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1144 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
|
1145 if (ev->write) { |
583 | 1146 recv_action = "proxying and reading from upstream"; |
1147 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
|
1148 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
|
1149 dst = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1150 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
|
1151 |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1152 } else { |
583 | 1153 recv_action = "proxying and reading from client"; |
1154 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
|
1155 src = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1156 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
|
1157 b = s->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1158 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1159 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1160 } else { |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1161 if (ev->write) { |
589 | 1162 recv_action = "proxying and reading from client"; |
1163 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
|
1164 src = s->connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1165 dst = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1166 b = s->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1167 |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1168 } else { |
589 | 1169 recv_action = "proxying and reading from upstream"; |
1170 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
|
1171 src = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1172 dst = s->connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1173 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
|
1174 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1175 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1176 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1177 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
|
1178 |
1136 | 1179 ngx_log_debug3(NGX_LOG_DEBUG_MAIL, ev->log, 0, |
6480 | 1180 "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
|
1181 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
|
1182 |
583 | 1183 for ( ;; ) { |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1184 |
583 | 1185 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
|
1186 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1187 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
|
1188 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1189 if (size && dst->write->ready) { |
583 | 1190 c->log->action = send_action; |
1191 | |
539 | 1192 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
|
1193 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1194 if (n == NGX_ERROR) { |
1136 | 1195 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
|
1196 return; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1197 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1198 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1199 if (n > 0) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1200 b->pos += n; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1201 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1202 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
|
1203 b->pos = b->start; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1204 b->last = b->start; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1205 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1206 } |
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 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1209 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1210 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
|
1211 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
1212 if (size && src->read->ready) { |
583 | 1213 c->log->action = recv_action; |
1214 | |
539 | 1215 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
|
1216 |
583 | 1217 if (n == NGX_AGAIN || n == 0) { |
1218 break; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1219 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1220 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1221 if (n > 0) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1222 do_write = 1; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1223 b->last += n; |
583 | 1224 |
1225 continue; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1226 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1227 |
583 | 1228 if (n == NGX_ERROR) { |
1229 src->read->eof = 1; | |
539 | 1230 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1231 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1232 |
583 | 1233 break; |
1234 } | |
1235 | |
1236 c->log->action = "proxying"; | |
1237 | |
1342
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
1238 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
|
1239 || (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
|
1240 && 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
|
1241 || (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
|
1242 && s->proxy->upstream.connection->read->eof)) |
583 | 1243 { |
1244 action = c->log->action; | |
1245 c->log->action = NULL; | |
1246 ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxied session done"); | |
1247 c->log->action = action; | |
1248 | |
1136 | 1249 ngx_mail_proxy_close_session(s); |
583 | 1250 return; |
1251 } | |
1252 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1253 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { |
1136 | 1254 ngx_mail_proxy_close_session(s); |
583 | 1255 return; |
1256 } | |
1257 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1258 if (ngx_handle_read_event(dst->read, 0) != NGX_OK) { |
1136 | 1259 ngx_mail_proxy_close_session(s); |
583 | 1260 return; |
1261 } | |
1262 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1263 if (ngx_handle_write_event(src->write, 0) != NGX_OK) { |
1136 | 1264 ngx_mail_proxy_close_session(s); |
583 | 1265 return; |
1266 } | |
1267 | |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2311
diff
changeset
|
1268 if (ngx_handle_read_event(src->read, 0) != NGX_OK) { |
1136 | 1269 ngx_mail_proxy_close_session(s); |
583 | 1270 return; |
1271 } | |
1272 | |
1273 if (c == s->connection) { | |
1136 | 1274 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
583 | 1275 ngx_add_timer(c->read, pcf->timeout); |
1276 } | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1277 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1278 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1279 |
521 | 1280 static void |
1136 | 1281 ngx_mail_proxy_upstream_error(ngx_mail_session_t *s) |
857 | 1282 { |
1283 if (s->proxy->upstream.connection) { | |
1136 | 1284 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
1285 "close mail proxy connection: %d", | |
857 | 1286 s->proxy->upstream.connection->fd); |
1287 | |
1288 ngx_close_connection(s->proxy->upstream.connection); | |
1289 } | |
1290 | |
1291 if (s->out.len == 0) { | |
1136 | 1292 ngx_mail_session_internal_server_error(s); |
857 | 1293 return; |
1294 } | |
1295 | |
1296 s->quit = 1; | |
1136 | 1297 ngx_mail_send(s->connection->write); |
857 | 1298 } |
1299 | |
1300 | |
1301 static void | |
1136 | 1302 ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s) |
527 | 1303 { |
1304 if (s->proxy->upstream.connection) { | |
1136 | 1305 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
1306 "close mail proxy connection: %d", | |
527 | 1307 s->proxy->upstream.connection->fd); |
1308 | |
1309 ngx_close_connection(s->proxy->upstream.connection); | |
1310 } | |
1311 | |
1136 | 1312 ngx_mail_session_internal_server_error(s); |
527 | 1313 } |
1314 | |
1315 | |
1316 static void | |
1136 | 1317 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
|
1318 { |
521 | 1319 if (s->proxy->upstream.connection) { |
1136 | 1320 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
1321 "close mail proxy connection: %d", | |
521 | 1322 s->proxy->upstream.connection->fd); |
1323 | |
1324 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
|
1325 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
1326 |
1136 | 1327 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
|
1328 } |
521 | 1329 |
1330 | |
1331 static void * | |
1136 | 1332 ngx_mail_proxy_create_conf(ngx_conf_t *cf) |
577 | 1333 { |
1136 | 1334 ngx_mail_proxy_conf_t *pcf; |
577 | 1335 |
1136 | 1336 pcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_proxy_conf_t)); |
521 | 1337 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
|
1338 return NULL; |
521 | 1339 } |
1340 | |
1341 pcf->enable = NGX_CONF_UNSET; | |
857 | 1342 pcf->pass_error_message = NGX_CONF_UNSET; |
1136 | 1343 pcf->xclient = NGX_CONF_UNSET; |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1344 pcf->smtp_auth = NGX_CONF_UNSET; |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
1345 pcf->proxy_protocol = NGX_CONF_UNSET; |
539 | 1346 pcf->buffer_size = NGX_CONF_UNSET_SIZE; |
1347 pcf->timeout = NGX_CONF_UNSET_MSEC; | |
521 | 1348 |
1349 return pcf; | |
1350 } | |
1351 | |
1352 | |
1353 static char * | |
1136 | 1354 ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 1355 { |
1136 | 1356 ngx_mail_proxy_conf_t *prev = parent; |
1357 ngx_mail_proxy_conf_t *conf = child; | |
521 | 1358 |
539 | 1359 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
857 | 1360 ngx_conf_merge_value(conf->pass_error_message, prev->pass_error_message, 0); |
1136 | 1361 ngx_conf_merge_value(conf->xclient, prev->xclient, 1); |
8178
d63c5373b5ba
Mail: proxy_smtp_auth directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7156
diff
changeset
|
1362 ngx_conf_merge_value(conf->smtp_auth, prev->smtp_auth, 0); |
8345
4b8f23a36ebf
Mail: sending of the PROXY protocol to backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
1363 ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); |
539 | 1364 ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, |
1365 (size_t) ngx_pagesize); | |
1366 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 24 * 60 * 60000); | |
521 | 1367 |
1368 return NGX_CONF_OK; | |
1369 } |