Mercurial > hg > nginx
annotate src/mail/ngx_mail_smtp_module.c @ 3672:4f021d4ceb88
fix building by owc12: GetLongPathName() is available since Win2K only
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 05 Jul 2010 12:47:35 +0000 |
parents | 8156bc03982a |
children | d620f497c50f |
rev | line source |
---|---|
521 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
1136 | 10 #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
|
11 #include <ngx_mail_smtp_module.h> |
521 | 12 |
13 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
14 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
|
15 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
|
16 void *child); |
527 | 17 |
18 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
19 static ngx_conf_bitmask_t ngx_mail_smtp_auth_methods[] = { |
1323 | 20 { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED }, |
21 { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED }, | |
22 { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED }, | |
2309 | 23 { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED }, |
1323 | 24 { ngx_null_string, 0 } |
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_str_t ngx_mail_smtp_auth_methods_names[] = { |
1174
6be5ee17d80b
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1136
diff
changeset
|
29 ngx_string("PLAIN"), |
1136 | 30 ngx_string("LOGIN"), |
31 ngx_null_string, /* APOP */ | |
2309 | 32 ngx_string("CRAM-MD5"), |
33 ngx_null_string /* NONE */ | |
1136 | 34 }; |
35 | |
36 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
37 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
|
38 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
|
39 { 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
|
40 NGX_MAIL_SMTP_PROTOCOL, |
809 | 41 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 ngx_mail_smtp_auth_state, |
809 | 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 ngx_string("451 4.3.2 Internal server error" CRLF) |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
48 }; |
809 | 49 |
50 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
51 static ngx_command_t ngx_mail_smtp_commands[] = { |
521 | 52 |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
53 { ngx_string("smtp_client_buffer"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
54 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
|
55 ngx_conf_set_size_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
56 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
|
57 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
|
58 NULL }, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
59 |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
60 { ngx_string("smtp_greeting_delay"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
61 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
|
62 ngx_conf_set_msec_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
63 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
|
64 offsetof(ngx_mail_smtp_srv_conf_t, greeting_delay), |
1136 | 65 NULL }, |
66 | |
67 { ngx_string("smtp_capabilities"), | |
68 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
|
69 ngx_mail_capabilities, |
1136 | 70 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
|
71 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
|
72 NULL }, |
1323 | 73 |
1136 | 74 { ngx_string("smtp_auth"), |
75 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, | |
76 ngx_conf_set_bitmask_slot, | |
77 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
|
78 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
|
79 &ngx_mail_smtp_auth_methods }, |
800 | 80 |
521 | 81 ngx_null_command |
82 }; | |
83 | |
84 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
85 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
|
86 &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
|
87 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
88 NULL, /* create main configuration */ |
521 | 89 NULL, /* init main configuration */ |
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 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
|
92 ngx_mail_smtp_merge_srv_conf /* merge server configuration */ |
521 | 93 }; |
94 | |
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_module_t ngx_mail_smtp_module = { |
521 | 97 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
|
98 &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
|
99 ngx_mail_smtp_commands, /* module directives */ |
1136 | 100 NGX_MAIL_MODULE, /* module type */ |
541 | 101 NULL, /* init master */ |
521 | 102 NULL, /* init module */ |
541 | 103 NULL, /* init process */ |
104 NULL, /* init thread */ | |
105 NULL, /* exit thread */ | |
106 NULL, /* exit process */ | |
107 NULL, /* exit master */ | |
108 NGX_MODULE_V1_PADDING | |
521 | 109 }; |
110 | |
111 | |
112 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
|
113 ngx_mail_smtp_create_srv_conf(ngx_conf_t *cf) |
577 | 114 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
115 ngx_mail_smtp_srv_conf_t *sscf; |
641 | 116 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
117 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
|
118 if (sscf == NULL) { |
527 | 119 return NULL; |
521 | 120 } |
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->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
|
123 sscf->greeting_delay = NGX_CONF_UNSET_MSEC; |
521 | 124 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
125 if (ngx_array_init(&sscf->capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
1136 | 126 != NGX_OK) |
127 { | |
128 return NULL; | |
129 } | |
130 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
131 return sscf; |
521 | 132 } |
133 | |
134 | |
135 static char * | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
136 ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 137 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
138 ngx_mail_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
|
139 ngx_mail_smtp_srv_conf_t *conf = child; |
521 | 140 |
2309 | 141 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
|
142 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
|
143 ngx_str_t *c; |
2309 | 144 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
|
145 ngx_mail_core_srv_conf_t *cscf; |
527 | 146 |
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 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
|
148 prev->client_buffer_size, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
149 (size_t) ngx_pagesize); |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
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 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
|
152 prev->greeting_delay, 0); |
521 | 153 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
154 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
|
155 prev->auth_methods, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
156 (NGX_CONF_BITMASK_SET |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
157 |NGX_MAIL_AUTH_PLAIN_ENABLED |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
158 |NGX_MAIL_AUTH_LOGIN_ENABLED)); |
800 | 159 |
160 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
161 cscf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_core_module); |
527 | 162 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
163 size = sizeof("220 ESMTP ready" CRLF) - 1 + cscf->server_name.len; |
809 | 164 |
2049 | 165 p = ngx_pnalloc(cf->pool, size); |
583 | 166 if (p == NULL) { |
527 | 167 return NGX_CONF_ERROR; |
168 } | |
169 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
170 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
|
171 conf->greeting.data = p; |
527 | 172 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
173 *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
|
174 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
|
175 ngx_memcpy(p, " ESMTP ready" CRLF, sizeof(" ESMTP ready" CRLF) - 1); |
583 | 176 |
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 size = sizeof("250 " CRLF) - 1 + cscf->server_name.len; |
527 | 179 |
2049 | 180 p = ngx_pnalloc(cf->pool, size); |
583 | 181 if (p == NULL) { |
182 return NGX_CONF_ERROR; | |
183 } | |
184 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
185 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
|
186 conf->server_name.data = p; |
583 | 187 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
188 *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
|
189 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
|
190 *p++ = CR; *p = LF; |
527 | 191 |
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 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
|
194 conf->capabilities = prev->capabilities; |
1136 | 195 } |
196 | |
2309 | 197 size = sizeof("250-") - 1 + cscf->server_name.len + sizeof(CRLF) - 1; |
1136 | 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 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
|
200 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
|
201 size += sizeof("250 ") - 1 + c[i].len + sizeof(CRLF) - 1; |
527 | 202 } |
203 | |
2309 | 204 auth_enabled = 0; |
205 | |
1323 | 206 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
207 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; | |
208 m <<= 1, i++) | |
209 { | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
210 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
|
211 size += 1 + ngx_mail_smtp_auth_methods_names[i].len; |
2309 | 212 auth_enabled = 1; |
1323 | 213 } |
214 } | |
215 | |
2309 | 216 if (auth_enabled) { |
217 size += sizeof("250 AUTH") - 1 + sizeof(CRLF) - 1; | |
218 } | |
219 | |
2049 | 220 p = ngx_pnalloc(cf->pool, size); |
583 | 221 if (p == NULL) { |
222 return NGX_CONF_ERROR; | |
223 } | |
224 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
225 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
|
226 conf->capability.data = p; |
1136 | 227 |
2309 | 228 last = p; |
229 | |
1136 | 230 *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
|
231 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
1136 | 232 *p++ = CR; *p++ = LF; |
233 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
234 for (i = 0; i < conf->capabilities.nelts; i++) { |
2309 | 235 last = p; |
1136 | 236 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-'; |
237 p = ngx_cpymem(p, c[i].data, c[i].len); | |
238 *p++ = CR; *p++ = LF; | |
239 } | |
240 | |
1322 | 241 auth = p; |
242 | |
2309 | 243 if (auth_enabled) { |
244 last = p; | |
245 | |
246 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' '; | |
247 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H'; | |
1136 | 248 |
2309 | 249 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
250 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; | |
251 m <<= 1, i++) | |
252 { | |
253 if (m & conf->auth_methods) { | |
254 *p++ = ' '; | |
255 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data, | |
256 ngx_mail_smtp_auth_methods_names[i].len); | |
257 } | |
1136 | 258 } |
2309 | 259 |
260 *p++ = CR; *p = LF; | |
1136 | 261 |
2309 | 262 } else { |
263 last[3] = ' '; | |
264 } | |
1136 | 265 |
1322 | 266 size += sizeof("250 STARTTLS" CRLF) - 1; |
267 | |
2049 | 268 p = ngx_pnalloc(cf->pool, size); |
1322 | 269 if (p == NULL) { |
270 return NGX_CONF_ERROR; | |
271 } | |
272 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
273 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
|
274 conf->starttls_capability.data = p; |
1322 | 275 |
2309 | 276 p = ngx_cpymem(p, conf->capability.data, conf->capability.len); |
1322 | 277 |
278 p = ngx_cpymem(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); | |
279 *p++ = CR; *p = LF; | |
280 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
281 p = conf->starttls_capability.data |
2309 | 282 + (last - conf->capability.data) + 3; |
1322 | 283 *p = '-'; |
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 size = (auth - conf->capability.data) |
1322 | 286 + sizeof("250 STARTTLS" CRLF) - 1; |
287 | |
2049 | 288 p = ngx_pnalloc(cf->pool, size); |
1322 | 289 if (p == NULL) { |
290 return NGX_CONF_ERROR; | |
291 } | |
292 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
293 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
|
294 conf->starttls_only_capability.data = p; |
1322 | 295 |
2309 | 296 p = ngx_cpymem(p, conf->capability.data, auth - conf->capability.data); |
1322 | 297 |
298 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); | |
299 | |
2309 | 300 if (last < auth) { |
301 p = conf->starttls_only_capability.data | |
302 + (last - conf->capability.data) + 3; | |
303 *p = '-'; | |
304 } | |
305 | |
521 | 306 return NGX_CONF_OK; |
307 } |