annotate src/mail/ngx_mail_smtp_module.c @ 7938:dc955d274130

Mail: connections with wrong ALPN protocols are now rejected. This is a recommended behavior by RFC 7301 and is useful for mitigation of protocol confusion attacks [1]. For POP3 and IMAP protocols IANA-assigned ALPN IDs are used [2]. For the SMTP protocol "smtp" is used. [1] https://alpaca-attack.com/ [2] https://www.iana.org/assignments/tls-extensiontype-values/
author Vladimir Homutov <vl@nginx.com>
date Wed, 20 Oct 2021 09:45:34 +0300
parents f18c285c2e59
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 2309
diff changeset
4 * Copyright (C) Nginx, Inc.
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_event.h>
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
18
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
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
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
21 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
22 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED },
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
25 { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED },
1323
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
26 { ngx_null_string, 0 }
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
27 };
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
28
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
32 ngx_string("LOGIN"),
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
33 ngx_null_string, /* APOP */
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
36 ngx_null_string /* NONE */
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
37 };
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
38
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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"),
7938
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
da9c1521319d AUTH PLAIN LOGIN CRAM-MD5
Igor Sysoev <igor@sysoev.ru>
parents: 804
diff changeset
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
da9c1521319d AUTH PLAIN LOGIN CRAM-MD5
Igor Sysoev <igor@sysoev.ru>
parents: 804
diff changeset
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
da9c1521319d AUTH PLAIN LOGIN CRAM-MD5
Igor Sysoev <igor@sysoev.ru>
parents: 804
diff changeset
55
da9c1521319d AUTH PLAIN LOGIN CRAM-MD5
Igor Sysoev <igor@sysoev.ru>
parents: 804
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
71 NULL },
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
72
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
73 { ngx_string("smtp_capabilities"),
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
79
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
80 { ngx_string("smtp_auth"),
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
81 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
82 ngx_conf_set_bitmask_slot,
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
86
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 ngx_null_command
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 };
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 NULL, /* init main configuration */
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 };
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
106 NGX_MAIL_MODULE, /* module type */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
107 NULL, /* init master */
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
109 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
110 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
111 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
112 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
113 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
114 NGX_MODULE_V1_PADDING
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 };
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
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
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 619
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
125 return NULL;
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 }
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
132 != NGX_OK)
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
133 {
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
134 return NULL;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
135 }
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 }
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
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
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
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
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
165
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
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
da9c1521319d AUTH PLAIN LOGIN CRAM-MD5
Igor Sysoev <igor@sysoev.ru>
parents: 804
diff changeset
170
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1896
diff changeset
171 p = ngx_pnalloc(cf->pool, size);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
172 if (p == NULL) {
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
173 return NGX_CONF_ERROR;
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
174 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
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
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
182
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
185
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1896
diff changeset
186 p = ngx_pnalloc(cf->pool, size);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
187 if (p == NULL) {
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
188 return NGX_CONF_ERROR;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
189 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
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
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
197
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
201 }
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
202
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
203 size = sizeof("250-") - 1 + cscf->server_name.len + sizeof(CRLF) - 1;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
208 }
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
209
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
210 auth_enabled = 0;
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
211
1323
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
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
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
214 m <<= 1, i++)
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
218 auth_enabled = 1;
1323
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
219 }
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
220 }
c4b2c893989d IMAP AUTHENTICATE
Igor Sysoev <igor@sysoev.ru>
parents: 1322
diff changeset
221
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
222 if (auth_enabled) {
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
223 size += sizeof("250 AUTH") - 1 + sizeof(CRLF) - 1;
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
224 }
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
225
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1896
diff changeset
226 p = ngx_pnalloc(cf->pool, size);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
227 if (p == NULL) {
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
228 return NGX_CONF_ERROR;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
229 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
233
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
234 last = p;
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
235
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
238 *p++ = CR; *p++ = LF;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
241 last = p;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
242 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-';
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
243 p = ngx_cpymem(p, c[i].data, c[i].len);
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
244 *p++ = CR; *p++ = LF;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
245 }
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
246
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
247 auth = p;
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
248
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
249 if (auth_enabled) {
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
250 last = p;
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
251
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
252 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' ';
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
253 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H';
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
254
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
257 m <<= 1, i++)
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
258 {
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
259 if (m & conf->auth_methods) {
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
260 *p++ = ' ';
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
261 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data,
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
262 ngx_mail_smtp_auth_methods_names[i].len);
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
263 }
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
264 }
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
265
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
266 *p++ = CR; *p = LF;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
267
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
268 } else {
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
269 last[3] = ' ';
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
270 }
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 906
diff changeset
271
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
272 size += sizeof("250 STARTTLS" CRLF) - 1;
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
273
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1896
diff changeset
274 p = ngx_pnalloc(cf->pool, size);
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
275 if (p == NULL) {
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
276 return NGX_CONF_ERROR;
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
277 }
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
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
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
281
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
282 p = ngx_cpymem(p, conf->capability.data, conf->capability.len);
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
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
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
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
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
287 + (last - conf->capability.data) + 3;
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
288 *p = '-';
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
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
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
291 + sizeof("250 STARTTLS" CRLF) - 1;
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
292
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1896
diff changeset
293 p = ngx_pnalloc(cf->pool, size);
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
294 if (p == NULL) {
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
295 return NGX_CONF_ERROR;
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
296 }
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
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
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
300
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
301 p = ngx_cpymem(p, conf->capability.data, auth - conf->capability.data);
1322
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
302
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
303 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1);
27f2299e0d80 SMTP STARTTLS
Igor Sysoev <igor@sysoev.ru>
parents: 1174
diff changeset
304
2309
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
305 if (last < auth) {
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
306 p = conf->starttls_only_capability.data
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
307 + (last - conf->capability.data) + 3;
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
308 *p = '-';
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
309 }
8156bc03982a smtp_auth none
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
310
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311 return NGX_CONF_OK;
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
312 }