Mercurial > hg > nginx
annotate src/mail/ngx_mail_smtp_module.c @ 1937:c46432b9dbb7
fix case when errors are not cached,
and a file was not used often enough to keep open
and it has been removed before it was kept open
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 13 Mar 2008 12:59:25 +0000 |
parents | 4c060e30476b |
children | 2a92804f4109 |
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 }, | |
23 { ngx_null_string, 0 } | |
24 }; | |
25 | |
26 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
27 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
|
28 ngx_string("PLAIN"), |
1136 | 29 ngx_string("LOGIN"), |
30 ngx_null_string, /* APOP */ | |
31 ngx_string("CRAM-MD5") | |
32 }; | |
33 | |
34 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
35 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
|
36 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
|
37 { 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
|
38 NGX_MAIL_SMTP_PROTOCOL, |
809 | 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 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
|
41 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
|
42 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
|
43 ngx_mail_smtp_auth_state, |
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_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
|
46 }; |
809 | 47 |
48 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
49 static ngx_command_t ngx_mail_smtp_commands[] = { |
521 | 50 |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
51 { ngx_string("smtp_client_buffer"), |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
52 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
|
53 ngx_conf_set_size_slot, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
54 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
|
55 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
|
56 NULL }, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
57 |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
58 { ngx_string("smtp_greeting_delay"), |
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_msec_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, greeting_delay), |
1136 | 63 NULL }, |
64 | |
65 { ngx_string("smtp_capabilities"), | |
66 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
|
67 ngx_mail_capabilities, |
1136 | 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, capabilities), |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
70 NULL }, |
1323 | 71 |
1136 | 72 { ngx_string("smtp_auth"), |
73 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE, | |
74 ngx_conf_set_bitmask_slot, | |
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, 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
|
77 &ngx_mail_smtp_auth_methods }, |
800 | 78 |
521 | 79 ngx_null_command |
80 }; | |
81 | |
82 | |
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 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
|
84 &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
|
85 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
86 NULL, /* create main configuration */ |
521 | 87 NULL, /* init main configuration */ |
88 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
89 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
|
90 ngx_mail_smtp_merge_srv_conf /* merge server configuration */ |
521 | 91 }; |
92 | |
93 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
94 ngx_module_t ngx_mail_smtp_module = { |
521 | 95 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
|
96 &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
|
97 ngx_mail_smtp_commands, /* module directives */ |
1136 | 98 NGX_MAIL_MODULE, /* module type */ |
541 | 99 NULL, /* init master */ |
521 | 100 NULL, /* init module */ |
541 | 101 NULL, /* init process */ |
102 NULL, /* init thread */ | |
103 NULL, /* exit thread */ | |
104 NULL, /* exit process */ | |
105 NULL, /* exit master */ | |
106 NGX_MODULE_V1_PADDING | |
521 | 107 }; |
108 | |
109 | |
110 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
|
111 ngx_mail_smtp_create_srv_conf(ngx_conf_t *cf) |
577 | 112 { |
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_srv_conf_t *sscf; |
641 | 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 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
|
116 if (sscf == NULL) { |
527 | 117 return NULL; |
521 | 118 } |
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 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
|
121 sscf->greeting_delay = NGX_CONF_UNSET_MSEC; |
521 | 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 if (ngx_array_init(&sscf->capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
1136 | 124 != NGX_OK) |
125 { | |
126 return NULL; | |
127 } | |
128 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
129 return sscf; |
521 | 130 } |
131 | |
132 | |
133 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
|
134 ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 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 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
|
137 ngx_mail_smtp_srv_conf_t *conf = child; |
521 | 138 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
139 u_char *p, *auth; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
140 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
|
141 ngx_str_t *c; |
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_uint_t i, m; |
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_core_srv_conf_t *cscf; |
527 | 144 |
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_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
|
146 prev->client_buffer_size, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
147 (size_t) ngx_pagesize); |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
148 |
1487
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_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
|
150 prev->greeting_delay, 0); |
521 | 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_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
|
153 prev->auth_methods, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
154 (NGX_CONF_BITMASK_SET |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
155 |NGX_MAIL_AUTH_PLAIN_ENABLED |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
156 |NGX_MAIL_AUTH_LOGIN_ENABLED)); |
800 | 157 |
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 cscf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_core_module); |
527 | 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 size = sizeof("220 ESMTP ready" CRLF) - 1 + cscf->server_name.len; |
809 | 162 |
583 | 163 p = ngx_palloc(cf->pool, size); |
164 if (p == NULL) { | |
527 | 165 return NGX_CONF_ERROR; |
166 } | |
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 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
|
169 conf->greeting.data = p; |
527 | 170 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
171 *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
|
172 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
|
173 ngx_memcpy(p, " ESMTP ready" CRLF, sizeof(" ESMTP ready" CRLF) - 1); |
583 | 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 size = sizeof("250 " CRLF) - 1 + cscf->server_name.len; |
527 | 177 |
583 | 178 p = ngx_palloc(cf->pool, size); |
179 if (p == NULL) { | |
180 return NGX_CONF_ERROR; | |
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 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
|
184 conf->server_name.data = p; |
583 | 185 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
186 *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
|
187 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
|
188 *p++ = CR; *p = LF; |
527 | 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 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
|
192 conf->capabilities = prev->capabilities; |
1136 | 193 } |
194 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
195 size = sizeof("250-") - 1 + cscf->server_name.len + sizeof(CRLF) - 1 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
196 + sizeof("250 AUTH") - 1 + sizeof(CRLF) - 1; |
1136 | 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 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
|
199 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
|
200 size += sizeof("250 ") - 1 + c[i].len + sizeof(CRLF) - 1; |
527 | 201 } |
202 | |
1323 | 203 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; |
204 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; | |
205 m <<= 1, i++) | |
206 { | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
207 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
|
208 size += 1 + ngx_mail_smtp_auth_methods_names[i].len; |
1323 | 209 } |
210 } | |
211 | |
583 | 212 p = ngx_palloc(cf->pool, size); |
213 if (p == NULL) { | |
214 return NGX_CONF_ERROR; | |
215 } | |
216 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
217 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
|
218 conf->capability.data = p; |
1136 | 219 |
220 *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
|
221 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
1136 | 222 *p++ = CR; *p++ = LF; |
223 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
224 for (i = 0; i < conf->capabilities.nelts; i++) { |
1136 | 225 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-'; |
226 p = ngx_cpymem(p, c[i].data, c[i].len); | |
227 *p++ = CR; *p++ = LF; | |
228 } | |
229 | |
1322 | 230 auth = p; |
231 | |
1136 | 232 *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' '; |
233 *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H'; | |
234 | |
235 for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0; | |
236 m <= NGX_MAIL_AUTH_CRAM_MD5_ENABLED; | |
237 m <<= 1, i++) | |
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 if (m & conf->auth_methods) { |
1136 | 240 *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
|
241 p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
242 ngx_mail_smtp_auth_methods_names[i].len); |
1136 | 243 } |
244 } | |
245 | |
246 *p++ = CR; *p = LF; | |
247 | |
1322 | 248 size += sizeof("250 STARTTLS" CRLF) - 1; |
249 | |
250 p = ngx_palloc(cf->pool, size); | |
251 if (p == NULL) { | |
252 return NGX_CONF_ERROR; | |
253 } | |
254 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
255 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
|
256 conf->starttls_capability.data = p; |
1322 | 257 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
258 p = ngx_cpymem(p, conf->capability.data, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
259 conf->capability.len); |
1322 | 260 |
261 p = ngx_cpymem(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); | |
262 *p++ = CR; *p = LF; | |
263 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
264 p = conf->starttls_capability.data |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
265 + (auth - conf->capability.data) + 3; |
1322 | 266 *p = '-'; |
267 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
268 size = (auth - conf->capability.data) |
1322 | 269 + sizeof("250 STARTTLS" CRLF) - 1; |
270 | |
271 p = ngx_palloc(cf->pool, size); | |
272 if (p == NULL) { | |
273 return NGX_CONF_ERROR; | |
274 } | |
275 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
276 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
|
277 conf->starttls_only_capability.data = p; |
1322 | 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 p = ngx_cpymem(p, conf->capability.data, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
280 auth - conf->capability.data); |
1322 | 281 |
282 ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1); | |
283 | |
521 | 284 return NGX_CONF_OK; |
285 } |