Mercurial > hg > nginx
annotate src/mail/ngx_mail_smtp_module.c @ 8801:2029a30863e2 quic
QUIC: using compile time block/iv length for tokens.
Reference values can be found in RFC 3602, 2.1, 2.4.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 16 Jun 2021 18:03:33 +0300 |
parents | f18c285c2e59 |
children | dc955d274130 |
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"), |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
42 { 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
|
43 NGX_MAIL_SMTP_PROTOCOL, |
809 | 44 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 ngx_mail_smtp_auth_state, |
809 | 49 |
5989
ec01b1d1fff1
Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5400
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 }; |
809 | 54 |
55 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
56 static ngx_command_t ngx_mail_smtp_commands[] = { |
521 | 57 |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
58 { ngx_string("smtp_client_buffer"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
59 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
|
60 ngx_conf_set_size_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
61 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
|
62 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
|
63 NULL }, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
64 |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
65 { ngx_string("smtp_greeting_delay"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
66 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
|
67 ngx_conf_set_msec_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
68 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
|
69 offsetof(ngx_mail_smtp_srv_conf_t, greeting_delay), |
1136 | 70 NULL }, |
71 | |
72 { ngx_string("smtp_capabilities"), | |
73 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
|
74 ngx_mail_capabilities, |
1136 | 75 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
|
76 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
|
77 NULL }, |
1323 | 78 |
1136 | 79 { ngx_string("smtp_auth"), |
80 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, | |
81 ngx_conf_set_bitmask_slot, | |
82 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
|
83 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
|
84 &ngx_mail_smtp_auth_methods }, |
800 | 85 |
521 | 86 ngx_null_command |
87 }; | |
88 | |
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 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
|
91 &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
|
92 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
93 NULL, /* create main configuration */ |
521 | 94 NULL, /* init main configuration */ |
95 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
96 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
|
97 ngx_mail_smtp_merge_srv_conf /* merge server configuration */ |
521 | 98 }; |
99 | |
100 | |
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_module_t ngx_mail_smtp_module = { |
521 | 102 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
|
103 &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
|
104 ngx_mail_smtp_commands, /* module directives */ |
1136 | 105 NGX_MAIL_MODULE, /* module type */ |
541 | 106 NULL, /* init master */ |
521 | 107 NULL, /* init module */ |
541 | 108 NULL, /* init process */ |
109 NULL, /* init thread */ | |
110 NULL, /* exit thread */ | |
111 NULL, /* exit process */ | |
112 NULL, /* exit master */ | |
113 NGX_MODULE_V1_PADDING | |
521 | 114 }; |
115 | |
116 | |
117 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
|
118 ngx_mail_smtp_create_srv_conf(ngx_conf_t *cf) |
577 | 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 ngx_mail_smtp_srv_conf_t *sscf; |
641 | 121 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
122 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
|
123 if (sscf == NULL) { |
527 | 124 return NULL; |
521 | 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 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
|
128 sscf->greeting_delay = NGX_CONF_UNSET_MSEC; |
521 | 129 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
130 if (ngx_array_init(&sscf->capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
1136 | 131 != NGX_OK) |
132 { | |
133 return NULL; | |
134 } | |
135 | |
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 return sscf; |
521 | 137 } |
138 | |
139 | |
140 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
|
141 ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 142 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
143 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
|
144 ngx_mail_smtp_srv_conf_t *conf = child; |
521 | 145 |
2309 | 146 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
|
147 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
|
148 ngx_str_t *c; |
2309 | 149 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
|
150 ngx_mail_core_srv_conf_t *cscf; |
527 | 151 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
152 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
|
153 prev->client_buffer_size, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
154 (size_t) ngx_pagesize); |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
155 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
156 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
|
157 prev->greeting_delay, 0); |
521 | 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 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
|
160 prev->auth_methods, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
161 (NGX_CONF_BITMASK_SET |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
162 |NGX_MAIL_AUTH_PLAIN_ENABLED |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
163 |NGX_MAIL_AUTH_LOGIN_ENABLED)); |
800 | 164 |
165 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
166 cscf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_core_module); |
527 | 167 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
168 size = sizeof("220 ESMTP ready" CRLF) - 1 + cscf->server_name.len; |
809 | 169 |
2049 | 170 p = ngx_pnalloc(cf->pool, size); |
583 | 171 if (p == NULL) { |
527 | 172 return NGX_CONF_ERROR; |
173 } | |
174 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
175 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
|
176 conf->greeting.data = p; |
527 | 177 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
178 *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
|
179 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
|
180 ngx_memcpy(p, " ESMTP ready" CRLF, sizeof(" ESMTP ready" CRLF) - 1); |
583 | 181 |
182 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
183 size = sizeof("250 " CRLF) - 1 + cscf->server_name.len; |
527 | 184 |
2049 | 185 p = ngx_pnalloc(cf->pool, size); |
583 | 186 if (p == NULL) { |
187 return NGX_CONF_ERROR; | |
188 } | |
189 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
190 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
|
191 conf->server_name.data = p; |
583 | 192 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
193 *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
|
194 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
|
195 *p++ = CR; *p = LF; |
527 | 196 |
197 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
198 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
|
199 conf->capabilities = prev->capabilities; |
1136 | 200 } |
201 | |
2309 | 202 size = sizeof("250-") - 1 + cscf->server_name.len + sizeof(CRLF) - 1; |
1136 | 203 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
204 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
|
205 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
|
206 size += sizeof("250 ") - 1 + c[i].len + sizeof(CRLF) - 1; |
527 | 207 } |
208 | |
2309 | 209 auth_enabled = 0; |
210 | |
1323 | 211 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
|
212 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
1323 | 213 m <<= 1, i++) |
214 { | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
215 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
|
216 size += 1 + ngx_mail_smtp_auth_methods_names[i].len; |
2309 | 217 auth_enabled = 1; |
1323 | 218 } |
219 } | |
220 | |
2309 | 221 if (auth_enabled) { |
222 size += sizeof("250 AUTH") - 1 + sizeof(CRLF) - 1; | |
223 } | |
224 | |
2049 | 225 p = ngx_pnalloc(cf->pool, size); |
583 | 226 if (p == NULL) { |
227 return NGX_CONF_ERROR; | |
228 } | |
229 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
230 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
|
231 conf->capability.data = p; |
1136 | 232 |
2309 | 233 last = p; |
234 | |
1136 | 235 *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
|
236 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
1136 | 237 *p++ = CR; *p++ = LF; |
238 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
239 for (i = 0; i < conf->capabilities.nelts; i++) { |
2309 | 240 last = p; |
1136 | 241 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-'; |
242 p = ngx_cpymem(p, c[i].data, c[i].len); | |
243 *p++ = CR; *p++ = LF; | |
244 } | |
245 | |
1322 | 246 auth = p; |
247 | |
2309 | 248 if (auth_enabled) { |
249 last = p; | |
250 | |
251 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' '; | |
252 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H'; | |
1136 | 253 |
2309 | 254 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
|
255 m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED; |
2309 | 256 m <<= 1, i++) |
257 { | |
258 if (m & conf->auth_methods) { | |
259 *p++ = ' '; | |
260 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data, | |
261 ngx_mail_smtp_auth_methods_names[i].len); | |
262 } | |
1136 | 263 } |
2309 | 264 |
265 *p++ = CR; *p = LF; | |
1136 | 266 |
2309 | 267 } else { |
268 last[3] = ' '; | |
269 } | |
1136 | 270 |
1322 | 271 size += sizeof("250 STARTTLS" CRLF) - 1; |
272 | |
2049 | 273 p = ngx_pnalloc(cf->pool, size); |
1322 | 274 if (p == NULL) { |
275 return NGX_CONF_ERROR; | |
276 } | |
277 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
278 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
|
279 conf->starttls_capability.data = p; |
1322 | 280 |
2309 | 281 p = ngx_cpymem(p, conf->capability.data, conf->capability.len); |
1322 | 282 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6774
diff
changeset
|
283 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); |
1322 | 284 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
285 p = conf->starttls_capability.data |
2309 | 286 + (last - conf->capability.data) + 3; |
1322 | 287 *p = '-'; |
288 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
289 size = (auth - conf->capability.data) |
1322 | 290 + sizeof("250 STARTTLS" CRLF) - 1; |
291 | |
2049 | 292 p = ngx_pnalloc(cf->pool, size); |
1322 | 293 if (p == NULL) { |
294 return NGX_CONF_ERROR; | |
295 } | |
296 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
297 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
|
298 conf->starttls_only_capability.data = p; |
1322 | 299 |
2309 | 300 p = ngx_cpymem(p, conf->capability.data, auth - conf->capability.data); |
1322 | 301 |
302 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); | |
303 | |
2309 | 304 if (last < auth) { |
305 p = conf->starttls_only_capability.data | |
306 + (last - conf->capability.data) + 3; | |
307 *p = '-'; | |
308 } | |
309 | |
521 | 310 return NGX_CONF_OK; |
311 } |