Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_smtp_module.c @ 9082:c6db94ec3841 quic
QUIC: separated path validation retransmit backoff.
Path validation packets containing PATH_CHALLENGE frames are sent separately
from regular frame queue, because of the need to use a decicated path and pad
the packets. The packets are sent periodically, separately from the regular
probe/lost detection mechanism. A path validation packet is resent up to 3
times, each time after PTO expiration, with increasing per-path PTO backoff.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 09 May 2023 19:42:39 +0400 |
parents | dc955d274130 |
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_smtp_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_smtp_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_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
17 void *child); |
527 | 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_conf_bitmask_t ngx_mail_smtp_auth_methods[] = { |
1323 | 21 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED }, |
22 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED }, | |
23 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED }, | |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
5989
diff
changeset
|
24 { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED }, |
2309 | 25 { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED }, |
1323 | 26 { ngx_null_string, 0 } |
27 }; | |
28 | |
29 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
30 static ngx_str_t ngx_mail_smtp_auth_methods_names[] = { |
1174
6be5ee17d80b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1136
diff
changeset
|
31 ngx_string("PLAIN"), |
1136 | 32 ngx_string("LOGIN"), |
33 ngx_null_string, /* APOP */ | |
2309 | 34 ngx_string("CRAM-MD5"), |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
5989
diff
changeset
|
35 ngx_string("EXTERNAL"), |
2309 | 36 ngx_null_string /* NONE */ |
1136 | 37 }; |
38 | |
39 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
40 static ngx_mail_protocol_t ngx_mail_smtp_protocol = { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
41 ngx_string("smtp"), |
8662
dc955d274130
Mail: connections with wrong ALPN protocols are now rejected.
Vladimir Homutov <vl@nginx.com>
parents:
6860
diff
changeset
|
42 ngx_string("\x04smtp"), |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
43 { 25, 465, 587, 0 }, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
44 NGX_MAIL_SMTP_PROTOCOL, |
809 | 45 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
46 ngx_mail_smtp_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
|
47 ngx_mail_smtp_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
|
48 ngx_mail_smtp_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
|
49 ngx_mail_smtp_auth_state, |
809 | 50 |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5400
diff
changeset
|
51 ngx_string("451 4.3.2 Internal server error" CRLF), |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5400
diff
changeset
|
52 ngx_string("421 4.7.1 SSL certificate error" CRLF), |
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5400
diff
changeset
|
53 ngx_string("421 4.7.1 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
|
54 }; |
809 | 55 |
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 static ngx_command_t ngx_mail_smtp_commands[] = { |
521 | 58 |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
59 { ngx_string("smtp_client_buffer"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
60 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
61 ngx_conf_set_size_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
62 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
|
63 offsetof(ngx_mail_smtp_srv_conf_t, client_buffer_size), |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
64 NULL }, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
65 |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
66 { ngx_string("smtp_greeting_delay"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
67 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
68 ngx_conf_set_msec_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
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_smtp_srv_conf_t, greeting_delay), |
1136 | 71 NULL }, |
72 | |
73 { ngx_string("smtp_capabilities"), | |
74 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
|
75 ngx_mail_capabilities, |
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_smtp_srv_conf_t, capabilities), |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
78 NULL }, |
1323 | 79 |
1136 | 80 { ngx_string("smtp_auth"), |
81 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, | |
82 ngx_conf_set_bitmask_slot, | |
83 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
|
84 offsetof(ngx_mail_smtp_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
|
85 &ngx_mail_smtp_auth_methods }, |
800 | 86 |
521 | 87 ngx_null_command |
88 }; | |
89 | |
90 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
91 static ngx_mail_module_t ngx_mail_smtp_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
|
92 &ngx_mail_smtp_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
|
93 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
94 NULL, /* create main configuration */ |
521 | 95 NULL, /* init main configuration */ |
96 | |
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_smtp_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
|
98 ngx_mail_smtp_merge_srv_conf /* merge server configuration */ |
521 | 99 }; |
100 | |
101 | |
1487
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_module_t ngx_mail_smtp_module = { |
521 | 103 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
|
104 &ngx_mail_smtp_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
|
105 ngx_mail_smtp_commands, /* module directives */ |
1136 | 106 NGX_MAIL_MODULE, /* module type */ |
541 | 107 NULL, /* init master */ |
521 | 108 NULL, /* init module */ |
541 | 109 NULL, /* init process */ |
110 NULL, /* init thread */ | |
111 NULL, /* exit thread */ | |
112 NULL, /* exit process */ | |
113 NULL, /* exit master */ | |
114 NGX_MODULE_V1_PADDING | |
521 | 115 }; |
116 | |
117 | |
118 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
|
119 ngx_mail_smtp_create_srv_conf(ngx_conf_t *cf) |
577 | 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 ngx_mail_smtp_srv_conf_t *sscf; |
641 | 122 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
123 sscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_smtp_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
|
124 if (sscf == NULL) { |
527 | 125 return NULL; |
521 | 126 } |
127 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
128 sscf->client_buffer_size = NGX_CONF_UNSET_SIZE; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
129 sscf->greeting_delay = NGX_CONF_UNSET_MSEC; |
521 | 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 if (ngx_array_init(&sscf->capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
1136 | 132 != NGX_OK) |
133 { | |
134 return NULL; | |
135 } | |
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 return sscf; |
521 | 138 } |
139 | |
140 | |
141 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
|
142 ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 143 { |
1487
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_mail_smtp_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
|
145 ngx_mail_smtp_srv_conf_t *conf = child; |
521 | 146 |
2309 | 147 u_char *p, *auth, *last; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
148 size_t size; |
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_str_t *c; |
2309 | 150 ngx_uint_t i, m, auth_enabled; |
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 ngx_mail_core_srv_conf_t *cscf; |
527 | 152 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
153 ngx_conf_merge_size_value(conf->client_buffer_size, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
154 prev->client_buffer_size, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
155 (size_t) ngx_pagesize); |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
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 ngx_conf_merge_msec_value(conf->greeting_delay, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
158 prev->greeting_delay, 0); |
521 | 159 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
160 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
|
161 prev->auth_methods, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
162 (NGX_CONF_BITMASK_SET |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
163 |NGX_MAIL_AUTH_PLAIN_ENABLED |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
164 |NGX_MAIL_AUTH_LOGIN_ENABLED)); |
800 | 165 |
166 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
167 cscf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_core_module); |
527 | 168 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
169 size = sizeof("220 ESMTP ready" CRLF) - 1 + cscf->server_name.len; |
809 | 170 |
2049 | 171 p = ngx_pnalloc(cf->pool, size); |
583 | 172 if (p == NULL) { |
527 | 173 return NGX_CONF_ERROR; |
174 } | |
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 conf->greeting.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
|
177 conf->greeting.data = p; |
527 | 178 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
179 *p++ = '2'; *p++ = '2'; *p++ = '0'; *p++ = ' '; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
180 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
181 ngx_memcpy(p, " ESMTP ready" CRLF, sizeof(" ESMTP ready" CRLF) - 1); |
583 | 182 |
183 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
184 size = sizeof("250 " CRLF) - 1 + cscf->server_name.len; |
527 | 185 |
2049 | 186 p = ngx_pnalloc(cf->pool, size); |
583 | 187 if (p == NULL) { |
188 return NGX_CONF_ERROR; | |
189 } | |
190 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
191 conf->server_name.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
|
192 conf->server_name.data = p; |
583 | 193 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
194 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' '; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
195 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
196 *p++ = CR; *p = LF; |
527 | 197 |
198 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
199 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
|
200 conf->capabilities = prev->capabilities; |
1136 | 201 } |
202 | |
2309 | 203 size = sizeof("250-") - 1 + cscf->server_name.len + sizeof(CRLF) - 1; |
1136 | 204 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
205 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
|
206 for (i = 0; i < conf->capabilities.nelts; i++) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
207 size += sizeof("250 ") - 1 + c[i].len + sizeof(CRLF) - 1; |
527 | 208 } |
209 | |
2309 | 210 auth_enabled = 0; |
211 | |
1323 | 212 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
5989
diff
changeset
|
213 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
1323 | 214 m <<= 1, i++) |
215 { | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
216 if (m & 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
|
217 size += 1 + ngx_mail_smtp_auth_methods_names[i].len; |
2309 | 218 auth_enabled = 1; |
1323 | 219 } |
220 } | |
221 | |
2309 | 222 if (auth_enabled) { |
223 size += sizeof("250 AUTH") - 1 + sizeof(CRLF) - 1; | |
224 } | |
225 | |
2049 | 226 p = ngx_pnalloc(cf->pool, size); |
583 | 227 if (p == NULL) { |
228 return NGX_CONF_ERROR; | |
229 } | |
230 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
231 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
|
232 conf->capability.data = p; |
1136 | 233 |
2309 | 234 last = p; |
235 | |
1136 | 236 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-'; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
237 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
1136 | 238 *p++ = CR; *p++ = LF; |
239 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
240 for (i = 0; i < conf->capabilities.nelts; i++) { |
2309 | 241 last = p; |
1136 | 242 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-'; |
243 p = ngx_cpymem(p, c[i].data, c[i].len); | |
244 *p++ = CR; *p++ = LF; | |
245 } | |
246 | |
1322 | 247 auth = p; |
248 | |
2309 | 249 if (auth_enabled) { |
250 last = p; | |
251 | |
252 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' '; | |
253 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H'; | |
1136 | 254 |
2309 | 255 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
5989
diff
changeset
|
256 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
2309 | 257 m <<= 1, i++) |
258 { | |
259 if (m & conf->auth_methods) { | |
260 *p++ = ' '; | |
261 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data, | |
262 ngx_mail_smtp_auth_methods_names[i].len); | |
263 } | |
1136 | 264 } |
2309 | 265 |
266 *p++ = CR; *p = LF; | |
1136 | 267 |
2309 | 268 } else { |
269 last[3] = ' '; | |
270 } | |
1136 | 271 |
1322 | 272 size += sizeof("250 STARTTLS" CRLF) - 1; |
273 | |
2049 | 274 p = ngx_pnalloc(cf->pool, size); |
1322 | 275 if (p == NULL) { |
276 return NGX_CONF_ERROR; | |
277 } | |
278 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
279 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
|
280 conf->starttls_capability.data = p; |
1322 | 281 |
2309 | 282 p = ngx_cpymem(p, conf->capability.data, conf->capability.len); |
1322 | 283 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6774
diff
changeset
|
284 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); |
1322 | 285 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
286 p = conf->starttls_capability.data |
2309 | 287 + (last - conf->capability.data) + 3; |
1322 | 288 *p = '-'; |
289 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
290 size = (auth - conf->capability.data) |
1322 | 291 + sizeof("250 STARTTLS" CRLF) - 1; |
292 | |
2049 | 293 p = ngx_pnalloc(cf->pool, size); |
1322 | 294 if (p == NULL) { |
295 return NGX_CONF_ERROR; | |
296 } | |
297 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
298 conf->starttls_only_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
|
299 conf->starttls_only_capability.data = p; |
1322 | 300 |
2309 | 301 p = ngx_cpymem(p, conf->capability.data, auth - conf->capability.data); |
1322 | 302 |
303 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); | |
304 | |
2309 | 305 if (last < auth) { |
306 p = conf->starttls_only_capability.data | |
307 + (last - conf->capability.data) + 3; | |
308 *p = '-'; | |
309 } | |
310 | |
521 | 311 return NGX_CONF_OK; |
312 } |