Mercurial > hg > nginx
annotate src/mail/ngx_mail_pop3_module.c @ 9300:5be23505292b default tip
SSI: fixed incorrect or duplicate stub output.
Following 3518:eb3aaf8bd2a9 (0.8.37), r->request_output is only set
if there are data in the first buffer sent in the subrequest. As a
result, following the change mentioned this flag cannot be used to
prevent duplicate ngx_http_ssi_stub_output() calls, since it is not
set if there was already some output, but the first buffer was empty.
Still, when there are multiple subrequests, even an empty subrequest
response might be delayed by the postpone filter, leading to a second
call of ngx_http_ssi_stub_output() during finalization from
ngx_http_writer() the subreqest buffers are released by the postpone
filter. Since r->request_output is not set after the first call, this
resulted in duplicate stub output.
Additionally, checking only the first buffer might be wrong in some
unusual cases. For example, the first buffer might be empty if
$r->flush() is called before printing any data in the embedded Perl
module.
Depending on the postpone_output value and corresponding sizes, this
issue can result in either duplicate or unexpected stub output, or
"zero size buf in writer" alerts.
Following 8124:f5515e727656 (1.23.4), it became slightly easier to
reproduce the issue, as empty static files and empty cache items now
result in a response with an empty buffer. Before the change, an empty
proxied response can be used to reproduce the issue.
Fix is check all buffers and set r->request_output if any non-empty
buffers are sent. This ensures that all unusual cases of non-empty
responses are covered, and also that r->request_output will be set
after the first stub output, preventing duplicate output.
Reported by Jan Gassen.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:41:28 +0300 |
parents | 4538c1ffb0f8 |
children |
rev | line source |
---|---|
521 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
521 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_event.h> | |
1136 | 11 #include <ngx_mail.h> |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
12 #include <ngx_mail_pop3_module.h> |
521 | 13 |
14 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
15 static void *ngx_mail_pop3_create_srv_conf(ngx_conf_t *cf); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
16 static char *ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, |
521 | 17 void *child); |
18 | |
19 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
20 static ngx_str_t ngx_mail_pop3_default_capabilities[] = { |
527 | 21 ngx_string("TOP"), |
22 ngx_string("USER"), | |
23 ngx_string("UIDL"), | |
24 ngx_null_string | |
25 }; | |
26 | |
27 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
28 static ngx_conf_bitmask_t ngx_mail_pop3_auth_methods[] = { |
1136 | 29 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED }, |
30 { ngx_string("apop"), NGX_MAIL_AUTH_APOP_ENABLED }, | |
31 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED }, | |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
32 { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED }, |
9290
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
33 { ngx_string("xoauth2"), NGX_MAIL_AUTH_XOAUTH2_ENABLED }, |
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
34 { ngx_string("oauthbearer"), NGX_MAIL_AUTH_OAUTHBEARER_ENABLED }, |
800 | 35 { ngx_null_string, 0 } |
36 }; | |
37 | |
38 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
39 static ngx_str_t ngx_mail_pop3_auth_methods_names[] = { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
40 ngx_string("PLAIN"), |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
41 ngx_string("LOGIN"), |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
42 ngx_null_string, /* APOP */ |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
43 ngx_string("CRAM-MD5"), |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
44 ngx_string("EXTERNAL"), |
9290
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
45 ngx_string("XOAUTH2"), |
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
46 ngx_string("OAUTHBEARER"), |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
47 ngx_null_string /* NONE */ |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
48 }; |
809 | 49 |
50 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
51 static ngx_mail_protocol_t ngx_mail_pop3_protocol = { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
52 ngx_string("pop3"), |
7938
dc955d274130
Mail: connections with wrong ALPN protocols are now rejected.
Vladimir Homutov <vl@nginx.com>
parents:
6924
diff
changeset
|
53 ngx_string("\x04pop3"), |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
54 { 110, 995, 0, 0 }, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
55 NGX_MAIL_POP3_PROTOCOL, |
521 | 56 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
57 ngx_mail_pop3_init_session, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
58 ngx_mail_pop3_init_protocol, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
59 ngx_mail_pop3_parse_command, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
60 ngx_mail_pop3_auth_state, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
61 |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
62 ngx_string("-ERR internal server error" CRLF), |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
63 ngx_string("-ERR SSL certificate error" CRLF), |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
64 ngx_string("-ERR No required SSL certificate" CRLF) |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
65 }; |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
66 |
587 | 67 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
68 static ngx_command_t ngx_mail_pop3_commands[] = { |
521 | 69 |
527 | 70 { ngx_string("pop3_capabilities"), |
1136 | 71 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
72 ngx_mail_capabilities, |
1136 | 73 NGX_MAIL_SRV_CONF_OFFSET, |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
74 offsetof(ngx_mail_pop3_srv_conf_t, capabilities), |
527 | 75 NULL }, |
76 | |
1136 | 77 { ngx_string("pop3_auth"), |
78 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, | |
800 | 79 ngx_conf_set_bitmask_slot, |
1136 | 80 NGX_MAIL_SRV_CONF_OFFSET, |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
81 offsetof(ngx_mail_pop3_srv_conf_t, auth_methods), |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
82 &ngx_mail_pop3_auth_methods }, |
800 | 83 |
521 | 84 ngx_null_command |
85 }; | |
86 | |
87 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
88 static ngx_mail_module_t ngx_mail_pop3_module_ctx = { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
89 &ngx_mail_pop3_protocol, /* protocol */ |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
90 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
91 NULL, /* create main configuration */ |
521 | 92 NULL, /* init main configuration */ |
93 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
94 ngx_mail_pop3_create_srv_conf, /* create server configuration */ |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
95 ngx_mail_pop3_merge_srv_conf /* merge server configuration */ |
521 | 96 }; |
97 | |
98 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
99 ngx_module_t ngx_mail_pop3_module = { |
521 | 100 NGX_MODULE_V1, |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
101 &ngx_mail_pop3_module_ctx, /* module context */ |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
102 ngx_mail_pop3_commands, /* module directives */ |
1136 | 103 NGX_MAIL_MODULE, /* module type */ |
541 | 104 NULL, /* init master */ |
521 | 105 NULL, /* init module */ |
541 | 106 NULL, /* init process */ |
107 NULL, /* init thread */ | |
108 NULL, /* exit thread */ | |
109 NULL, /* exit process */ | |
110 NULL, /* exit master */ | |
111 NGX_MODULE_V1_PADDING | |
521 | 112 }; |
113 | |
114 | |
115 static void * | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
116 ngx_mail_pop3_create_srv_conf(ngx_conf_t *cf) |
577 | 117 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
118 ngx_mail_pop3_srv_conf_t *pscf; |
641 | 119 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
120 pscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_pop3_srv_conf_t)); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
121 if (pscf == NULL) { |
527 | 122 return NULL; |
521 | 123 } |
124 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
125 if (ngx_array_init(&pscf->capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
1136 | 126 != NGX_OK) |
127 { | |
128 return NULL; | |
129 } | |
130 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
131 return pscf; |
521 | 132 } |
133 | |
134 | |
135 static char * | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
136 ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 137 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
138 ngx_mail_pop3_srv_conf_t *prev = parent; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
139 ngx_mail_pop3_srv_conf_t *conf = child; |
521 | 140 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
141 u_char *p; |
1136 | 142 size_t size, stls_only_size; |
527 | 143 ngx_str_t *c, *d; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
144 ngx_uint_t i, m; |
1136 | 145 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
146 ngx_conf_merge_bitmask_value(conf->auth_methods, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
147 prev->auth_methods, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
148 (NGX_CONF_BITMASK_SET |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
149 |NGX_MAIL_AUTH_PLAIN_ENABLED)); |
800 | 150 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
151 if (conf->auth_methods & NGX_MAIL_AUTH_PLAIN_ENABLED) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
152 conf->auth_methods |= NGX_MAIL_AUTH_LOGIN_ENABLED; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
153 } |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
154 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
155 if (conf->capabilities.nelts == 0) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
156 conf->capabilities = prev->capabilities; |
800 | 157 } |
158 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
159 if (conf->capabilities.nelts == 0) { |
527 | 160 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
161 for (d = ngx_mail_pop3_default_capabilities; d->len; d++) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
162 c = ngx_array_push(&conf->capabilities); |
527 | 163 if (c == NULL) { |
164 return NGX_CONF_ERROR; | |
165 } | |
166 | |
167 *c = *d; | |
168 } | |
169 } | |
170 | |
171 size = sizeof("+OK Capability list follows" CRLF) - 1 | |
172 + sizeof("." CRLF) - 1; | |
173 | |
1136 | 174 stls_only_size = size + sizeof("STLS" CRLF) - 1; |
175 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
176 c = conf->capabilities.elts; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
177 for (i = 0; i < conf->capabilities.nelts; i++) { |
527 | 178 size += c[i].len + sizeof(CRLF) - 1; |
1136 | 179 |
180 if (ngx_strcasecmp(c[i].data, (u_char *) "USER") == 0) { | |
181 continue; | |
182 } | |
183 | |
184 stls_only_size += c[i].len + sizeof(CRLF) - 1; | |
527 | 185 } |
186 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
187 size += sizeof("SASL") - 1 + sizeof(CRLF) - 1; |
809 | 188 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
189 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
9290
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
190 m < NGX_MAIL_AUTH_NONE_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
191 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
192 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
193 if (ngx_mail_pop3_auth_methods_names[i].len == 0) { |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
194 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
195 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
196 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
197 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
198 size += 1 + ngx_mail_pop3_auth_methods_names[i].len; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
199 } |
809 | 200 } |
201 | |
2049 | 202 p = ngx_pnalloc(cf->pool, size); |
583 | 203 if (p == NULL) { |
527 | 204 return NGX_CONF_ERROR; |
205 } | |
206 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
207 conf->capability.len = size; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
208 conf->capability.data = p; |
583 | 209 |
210 p = ngx_cpymem(p, "+OK Capability list follows" CRLF, | |
211 sizeof("+OK Capability list follows" CRLF) - 1); | |
527 | 212 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
213 for (i = 0; i < conf->capabilities.nelts; i++) { |
583 | 214 p = ngx_cpymem(p, c[i].data, c[i].len); |
215 *p++ = CR; *p++ = LF; | |
527 | 216 } |
217 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
218 p = ngx_cpymem(p, "SASL", sizeof("SASL") - 1); |
809 | 219 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
220 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
9290
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
221 m < NGX_MAIL_AUTH_NONE_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
222 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
223 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
224 if (ngx_mail_pop3_auth_methods_names[i].len == 0) { |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
225 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
226 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
227 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
228 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
229 *p++ = ' '; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
230 p = ngx_cpymem(p, ngx_mail_pop3_auth_methods_names[i].data, |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
231 ngx_mail_pop3_auth_methods_names[i].len); |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
232 } |
809 | 233 } |
234 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
235 *p++ = CR; *p++ = LF; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
236 |
583 | 237 *p++ = '.'; *p++ = CR; *p = LF; |
238 | |
239 | |
240 size += sizeof("STLS" CRLF) - 1; | |
527 | 241 |
2049 | 242 p = ngx_pnalloc(cf->pool, size); |
583 | 243 if (p == NULL) { |
244 return NGX_CONF_ERROR; | |
245 } | |
246 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
247 conf->starttls_capability.len = size; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
248 conf->starttls_capability.data = p; |
583 | 249 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
250 p = ngx_cpymem(p, conf->capability.data, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
251 conf->capability.len - (sizeof("." CRLF) - 1)); |
583 | 252 |
253 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); | |
254 *p++ = '.'; *p++ = CR; *p = LF; | |
527 | 255 |
256 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
257 size = sizeof("+OK methods supported:" CRLF) - 1 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
258 + sizeof("." CRLF) - 1; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
259 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
260 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
9290
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
261 m < NGX_MAIL_AUTH_NONE_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
262 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
263 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
264 if (ngx_mail_pop3_auth_methods_names[i].len == 0) { |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
265 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
266 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
267 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
268 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
269 size += ngx_mail_pop3_auth_methods_names[i].len |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
270 + sizeof(CRLF) - 1; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
271 } |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
272 } |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
273 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
274 p = ngx_pnalloc(cf->pool, size); |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
275 if (p == NULL) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
276 return NGX_CONF_ERROR; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
277 } |
809 | 278 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
279 conf->auth_capability.data = p; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
280 conf->auth_capability.len = size; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
281 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
282 p = ngx_cpymem(p, "+OK methods supported:" CRLF, |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
283 sizeof("+OK methods supported:" CRLF) - 1); |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
284 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
285 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
9290
4538c1ffb0f8
Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7938
diff
changeset
|
286 m < NGX_MAIL_AUTH_NONE_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
287 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
288 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
289 if (ngx_mail_pop3_auth_methods_names[i].len == 0) { |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
290 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
291 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
292 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
293 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
294 p = ngx_cpymem(p, ngx_mail_pop3_auth_methods_names[i].data, |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
295 ngx_mail_pop3_auth_methods_names[i].len); |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
296 *p++ = CR; *p++ = LF; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
297 } |
809 | 298 } |
299 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
300 *p++ = '.'; *p++ = CR; *p = LF; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
301 |
809 | 302 |
2049 | 303 p = ngx_pnalloc(cf->pool, stls_only_size); |
1136 | 304 if (p == NULL) { |
305 return NGX_CONF_ERROR; | |
306 } | |
307 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
308 conf->starttls_only_capability.len = stls_only_size; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
309 conf->starttls_only_capability.data = p; |
1136 | 310 |
311 p = ngx_cpymem(p, "+OK Capability list follows" CRLF, | |
312 sizeof("+OK Capability list follows" CRLF) - 1); | |
313 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
314 for (i = 0; i < conf->capabilities.nelts; i++) { |
1136 | 315 if (ngx_strcasecmp(c[i].data, (u_char *) "USER") == 0) { |
316 continue; | |
317 } | |
318 | |
319 p = ngx_cpymem(p, c[i].data, c[i].len); | |
320 *p++ = CR; *p++ = LF; | |
321 } | |
322 | |
323 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); | |
324 *p++ = '.'; *p++ = CR; *p = LF; | |
325 | |
521 | 326 return NGX_CONF_OK; |
327 } |