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