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