Mercurial > hg > nginx
annotate src/mail/ngx_mail_pop3_module.c @ 8122:106328a70f4e
Added warning about redefinition of listen socket protocol options.
The "listen" directive in the http module can be used multiple times
in different server blocks. Originally, it was supposed to be specified
once with various socket options, and without any parameters in virtual
server blocks. For example:
server { listen 80 backlog=1024; server_name foo; ... }
server { listen 80; server_name bar; ... }
server { listen 80; server_name bazz; ... }
The address part of the syntax ("address[:port]" / "port" / "unix:path")
uniquely identifies the listening socket, and therefore is enough for
name-based virtual servers (to let nginx know that the virtual server
accepts requests on the listening socket in question).
To ensure that listening options do not conflict between virtual servers,
they were allowed only once. For example, the following configuration
will be rejected ("duplicate listen options for 0.0.0.0:80 in ..."):
server { listen 80 backlog=1024; server_name foo; ... }
server { listen 80 backlog=512; server_name bar; ... }
At some point it was, however, noticed, that it is sometimes convenient
to repeat some options for clarity. In nginx 0.8.51 the "ssl" parameter
was allowed to be specified multiple times, e.g.:
server { listen 443 ssl backlog=1024; server_name foo; ... }
server { listen 443 ssl; server_name bar; ... }
server { listen 443 ssl; server_name bazz; ... }
This approach makes configuration more readable, since SSL sockets are
immediately visible in the configuration. If this is not needed, just the
address can still be used.
Later, additional protocol-specific options similar to "ssl" were
introduced, notably "http2" and "proxy_protocol". With these options,
one can write:
server { listen 443 ssl backlog=1024; server_name foo; ... }
server { listen 443 http2; server_name bar; ... }
server { listen 443 proxy_protocol; server_name bazz; ... }
The resulting socket will use ssl, http2, and proxy_protocol, but this
is not really obvious from the configuration.
To emphasize such misleading configurations are discouraged, nginx now
warns as long as the "listen" directive is used with options different
from the options previously used if this is potentially confusing.
In particular, the following configurations are allowed:
server { listen 8401 ssl backlog=1024; server_name foo; }
server { listen 8401 ssl; server_name bar; }
server { listen 8401 ssl; server_name bazz; }
server { listen 8402 ssl http2 backlog=1024; server_name foo; }
server { listen 8402 ssl; server_name bar; }
server { listen 8402 ssl; server_name bazz; }
server { listen 8403 ssl; server_name bar; }
server { listen 8403 ssl; server_name bazz; }
server { listen 8403 ssl http2; server_name foo; }
server { listen 8404 ssl http2 backlog=1024; server_name foo; }
server { listen 8404 http2; server_name bar; }
server { listen 8404 http2; server_name bazz; }
server { listen 8405 ssl http2 backlog=1024; server_name foo; }
server { listen 8405 ssl http2; server_name bar; }
server { listen 8405 ssl http2; server_name bazz; }
server { listen 8406 ssl; server_name foo; }
server { listen 8406; server_name bar; }
server { listen 8406; server_name bazz; }
And the following configurations will generate warnings:
server { listen 8501 ssl http2 backlog=1024; server_name foo; }
server { listen 8501 http2; server_name bar; }
server { listen 8501 ssl; server_name bazz; }
server { listen 8502 backlog=1024; server_name foo; }
server { listen 8502 ssl; server_name bar; }
server { listen 8503 ssl; server_name foo; }
server { listen 8503 http2; server_name bar; }
server { listen 8504 ssl; server_name foo; }
server { listen 8504 http2; server_name bar; }
server { listen 8504 proxy_protocol; server_name bazz; }
server { listen 8505 ssl http2 proxy_protocol; server_name foo; }
server { listen 8505 ssl http2; server_name bar; }
server { listen 8505 ssl; server_name bazz; }
server { listen 8506 ssl http2; server_name foo; }
server { listen 8506 ssl; server_name bar; }
server { listen 8506; server_name bazz; }
server { listen 8507 ssl; server_name bar; }
server { listen 8507; server_name bazz; }
server { listen 8507 ssl http2; server_name foo; }
server { listen 8508 ssl; server_name bar; }
server { listen 8508; server_name bazz; }
server { listen 8508 ssl backlog=1024; server_name foo; }
server { listen 8509; server_name bazz; }
server { listen 8509 ssl; server_name bar; }
server { listen 8509 ssl backlog=1024; server_name foo; }
The basic idea is that at most two sets of protocol options are allowed:
the main one (with socket options, if any), and a shorter one, with options
being a subset of the main options, repeated for clarity. As long as the
shorter set of protocol options is used, all listen directives except the
main one should use it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 28 Jan 2023 01:29:45 +0300 |
parents | dc955d274130 |
children | 4538c1ffb0f8 |
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 }, |
800 | 33 { ngx_null_string, 0 } |
34 }; | |
35 | |
36 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
37 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
|
38 ngx_string("PLAIN"), |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
39 ngx_string("LOGIN"), |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
40 ngx_null_string, /* APOP */ |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
41 ngx_string("CRAM-MD5"), |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
42 ngx_string("EXTERNAL"), |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
43 ngx_null_string /* NONE */ |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
44 }; |
809 | 45 |
46 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
47 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
|
48 ngx_string("pop3"), |
7938
dc955d274130
Mail: connections with wrong ALPN protocols are now rejected.
Vladimir Homutov <vl@nginx.com>
parents:
6924
diff
changeset
|
49 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
|
50 { 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
|
51 NGX_MAIL_POP3_PROTOCOL, |
521 | 52 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 ngx_mail_pop3_auth_state, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
57 |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
58 ngx_string("-ERR internal server error" CRLF), |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
59 ngx_string("-ERR SSL certificate error" CRLF), |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
60 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
|
61 }; |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
62 |
587 | 63 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
64 static ngx_command_t ngx_mail_pop3_commands[] = { |
521 | 65 |
527 | 66 { ngx_string("pop3_capabilities"), |
1136 | 67 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
|
68 ngx_mail_capabilities, |
1136 | 69 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
|
70 offsetof(ngx_mail_pop3_srv_conf_t, capabilities), |
527 | 71 NULL }, |
72 | |
1136 | 73 { ngx_string("pop3_auth"), |
74 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, | |
800 | 75 ngx_conf_set_bitmask_slot, |
1136 | 76 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
|
77 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
|
78 &ngx_mail_pop3_auth_methods }, |
800 | 79 |
521 | 80 ngx_null_command |
81 }; | |
82 | |
83 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
84 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
|
85 &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
|
86 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
87 NULL, /* create main configuration */ |
521 | 88 NULL, /* init main configuration */ |
89 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
90 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
|
91 ngx_mail_pop3_merge_srv_conf /* merge server configuration */ |
521 | 92 }; |
93 | |
94 | |
1487
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_module_t ngx_mail_pop3_module = { |
521 | 96 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
|
97 &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
|
98 ngx_mail_pop3_commands, /* module directives */ |
1136 | 99 NGX_MAIL_MODULE, /* module type */ |
541 | 100 NULL, /* init master */ |
521 | 101 NULL, /* init module */ |
541 | 102 NULL, /* init process */ |
103 NULL, /* init thread */ | |
104 NULL, /* exit thread */ | |
105 NULL, /* exit process */ | |
106 NULL, /* exit master */ | |
107 NGX_MODULE_V1_PADDING | |
521 | 108 }; |
109 | |
110 | |
111 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
|
112 ngx_mail_pop3_create_srv_conf(ngx_conf_t *cf) |
577 | 113 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
114 ngx_mail_pop3_srv_conf_t *pscf; |
641 | 115 |
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 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
|
117 if (pscf == NULL) { |
527 | 118 return NULL; |
521 | 119 } |
120 | |
1487
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 (ngx_array_init(&pscf->capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
1136 | 122 != NGX_OK) |
123 { | |
124 return NULL; | |
125 } | |
126 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
127 return pscf; |
521 | 128 } |
129 | |
130 | |
131 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
|
132 ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 133 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
134 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
|
135 ngx_mail_pop3_srv_conf_t *conf = child; |
521 | 136 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
137 u_char *p; |
1136 | 138 size_t size, stls_only_size; |
527 | 139 ngx_str_t *c, *d; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
140 ngx_uint_t i, m; |
1136 | 141 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
142 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
|
143 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
|
144 (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
|
145 |NGX_MAIL_AUTH_PLAIN_ENABLED)); |
800 | 146 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
147 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
|
148 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
|
149 } |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
150 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
151 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
|
152 conf->capabilities = prev->capabilities; |
800 | 153 } |
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) { |
527 | 156 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
157 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
|
158 c = ngx_array_push(&conf->capabilities); |
527 | 159 if (c == NULL) { |
160 return NGX_CONF_ERROR; | |
161 } | |
162 | |
163 *c = *d; | |
164 } | |
165 } | |
166 | |
167 size = sizeof("+OK Capability list follows" CRLF) - 1 | |
168 + sizeof("." CRLF) - 1; | |
169 | |
1136 | 170 stls_only_size = size + sizeof("STLS" CRLF) - 1; |
171 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
172 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
|
173 for (i = 0; i < conf->capabilities.nelts; i++) { |
527 | 174 size += c[i].len + sizeof(CRLF) - 1; |
1136 | 175 |
176 if (ngx_strcasecmp(c[i].data, (u_char *) "USER") == 0) { | |
177 continue; | |
178 } | |
179 | |
180 stls_only_size += c[i].len + sizeof(CRLF) - 1; | |
527 | 181 } |
182 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
183 size += sizeof("SASL") - 1 + sizeof(CRLF) - 1; |
809 | 184 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
185 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
186 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
187 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
188 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
189 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
|
190 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
191 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
192 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
193 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
194 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
|
195 } |
809 | 196 } |
197 | |
2049 | 198 p = ngx_pnalloc(cf->pool, size); |
583 | 199 if (p == NULL) { |
527 | 200 return NGX_CONF_ERROR; |
201 } | |
202 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
203 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
|
204 conf->capability.data = p; |
583 | 205 |
206 p = ngx_cpymem(p, "+OK Capability list follows" CRLF, | |
207 sizeof("+OK Capability list follows" CRLF) - 1); | |
527 | 208 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
209 for (i = 0; i < conf->capabilities.nelts; i++) { |
583 | 210 p = ngx_cpymem(p, c[i].data, c[i].len); |
211 *p++ = CR; *p++ = LF; | |
527 | 212 } |
213 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
214 p = ngx_cpymem(p, "SASL", sizeof("SASL") - 1); |
809 | 215 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
216 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
217 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
218 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
219 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
220 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
|
221 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
222 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
223 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
224 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
225 *p++ = ' '; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
226 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
|
227 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
|
228 } |
809 | 229 } |
230 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
231 *p++ = CR; *p++ = LF; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
232 |
583 | 233 *p++ = '.'; *p++ = CR; *p = LF; |
234 | |
235 | |
236 size += sizeof("STLS" CRLF) - 1; | |
527 | 237 |
2049 | 238 p = ngx_pnalloc(cf->pool, size); |
583 | 239 if (p == NULL) { |
240 return NGX_CONF_ERROR; | |
241 } | |
242 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
243 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
|
244 conf->starttls_capability.data = p; |
583 | 245 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
246 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
|
247 conf->capability.len - (sizeof("." CRLF) - 1)); |
583 | 248 |
249 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); | |
250 *p++ = '.'; *p++ = CR; *p = LF; | |
527 | 251 |
252 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
253 size = sizeof("+OK methods supported:" CRLF) - 1 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
254 + sizeof("." CRLF) - 1; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
255 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
256 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
257 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
258 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
259 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
260 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
|
261 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
262 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
263 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
264 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
265 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
|
266 + sizeof(CRLF) - 1; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
267 } |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
268 } |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
269 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
270 p = ngx_pnalloc(cf->pool, size); |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
271 if (p == NULL) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
272 return NGX_CONF_ERROR; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
273 } |
809 | 274 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
275 conf->auth_capability.data = p; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
276 conf->auth_capability.len = size; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
277 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
278 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
|
279 sizeof("+OK methods supported:" CRLF) - 1); |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
280 |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
281 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
6773
diff
changeset
|
282 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
283 m <<= 1, i++) |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
284 { |
6924
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
285 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
|
286 continue; |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
287 } |
03735fef08da
Mail: don't emit separator in capability lists for APOP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
288 |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
289 if (m & conf->auth_methods) { |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
290 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
|
291 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
|
292 *p++ = CR; *p++ = LF; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
293 } |
809 | 294 } |
295 | |
6773
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
296 *p++ = '.'; *p++ = CR; *p = LF; |
73b451d304c0
Mail: extensible auth methods in pop3 module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5989
diff
changeset
|
297 |
809 | 298 |
2049 | 299 p = ngx_pnalloc(cf->pool, stls_only_size); |
1136 | 300 if (p == NULL) { |
301 return NGX_CONF_ERROR; | |
302 } | |
303 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
304 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
|
305 conf->starttls_only_capability.data = p; |
1136 | 306 |
307 p = ngx_cpymem(p, "+OK Capability list follows" CRLF, | |
308 sizeof("+OK Capability list follows" CRLF) - 1); | |
309 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
310 for (i = 0; i < conf->capabilities.nelts; i++) { |
1136 | 311 if (ngx_strcasecmp(c[i].data, (u_char *) "USER") == 0) { |
312 continue; | |
313 } | |
314 | |
315 p = ngx_cpymem(p, c[i].data, c[i].len); | |
316 *p++ = CR; *p++ = LF; | |
317 } | |
318 | |
319 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); | |
320 *p++ = '.'; *p++ = CR; *p = LF; | |
321 | |
521 | 322 return NGX_CONF_OK; |
323 } |