Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_imap_handler.c @ 8463:4b15f1b92100
Mail: stricter checking of IMAP tags.
Only "A-Za-z0-9-._" characters now allowed (which is stricter than what
RFC 3501 requires, but expected to be enough for all known clients),
and tags shouldn't be longer than 32 characters.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 19 May 2021 03:13:26 +0300 |
parents | ccdf83bee8c1 |
children | b38728495e1a |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
6 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
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:
1486
diff
changeset
|
12 #include <ngx_mail_imap_module.h> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
13 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
14 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
15 static ngx_int_t ngx_mail_imap_login(ngx_mail_session_t *s, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
16 ngx_connection_t *c); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
17 static ngx_int_t ngx_mail_imap_authenticate(ngx_mail_session_t *s, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
18 ngx_connection_t *c); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
19 static ngx_int_t ngx_mail_imap_capability(ngx_mail_session_t *s, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
20 ngx_connection_t *c); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
21 static ngx_int_t ngx_mail_imap_starttls(ngx_mail_session_t *s, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
22 ngx_connection_t *c); |
539 | 23 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
25 static u_char imap_greeting[] = "* OK IMAP4 ready" CRLF; |
543 | 26 static u_char imap_star[] = "* "; |
529 | 27 static u_char imap_ok[] = "OK completed" CRLF; |
527 | 28 static u_char imap_next[] = "+ OK" CRLF; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
29 static u_char imap_plain_next[] = "+ " CRLF; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
30 static u_char imap_username[] = "+ VXNlcm5hbWU6" CRLF; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
31 static u_char imap_password[] = "+ UGFzc3dvcmQ6" CRLF; |
527 | 32 static u_char imap_bye[] = "* BYE" CRLF; |
33 static u_char imap_invalid_command[] = "BAD invalid command" CRLF; | |
34 | |
521 | 35 |
36 void | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
37 ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c) |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
39 ngx_mail_core_srv_conf_t *cscf; |
641 | 40 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
41 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
541 | 42 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
43 ngx_str_set(&s->out, imap_greeting); |
1480
a231e37a19ab
move event handling to protocol specific code,
Igor Sysoev <igor@sysoev.ru>
parents:
1479
diff
changeset
|
44 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
45 c->read->handler = ngx_mail_imap_init_protocol; |
583 | 46 |
1486
0e7074ef7303
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1485
diff
changeset
|
47 ngx_add_timer(c->read, cscf->timeout); |
1480
a231e37a19ab
move event handling to protocol specific code,
Igor Sysoev <igor@sysoev.ru>
parents:
1479
diff
changeset
|
48 |
2388
722b5aff05ae
use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
49 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
1480
a231e37a19ab
move event handling to protocol specific code,
Igor Sysoev <igor@sysoev.ru>
parents:
1479
diff
changeset
|
50 ngx_mail_close_connection(c); |
a231e37a19ab
move event handling to protocol specific code,
Igor Sysoev <igor@sysoev.ru>
parents:
1479
diff
changeset
|
51 } |
539 | 52 |
1136 | 53 ngx_mail_send(c->write); |
539 | 54 } |
55 | |
56 | |
57 void | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
58 ngx_mail_imap_init_protocol(ngx_event_t *rev) |
539 | 59 { |
521 | 60 ngx_connection_t *c; |
1136 | 61 ngx_mail_session_t *s; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
62 ngx_mail_imap_srv_conf_t *iscf; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
63 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
64 c = rev->data; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
65 |
541 | 66 c->log->action = "in auth state"; |
67 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
68 if (rev->timedout) { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
69 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
577 | 70 c->timedout = 1; |
1136 | 71 ngx_mail_close_connection(c); |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
72 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
73 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
74 |
539 | 75 s = c->data; |
521 | 76 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
77 if (s->buffer == NULL) { |
583 | 78 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) |
79 == NGX_ERROR) | |
80 { | |
1136 | 81 ngx_mail_session_internal_server_error(s); |
583 | 82 return; |
83 } | |
84 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
85 iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
86 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
87 s->buffer = ngx_create_temp_buf(c->pool, iscf->client_buffer_size); |
583 | 88 if (s->buffer == NULL) { |
1136 | 89 ngx_mail_session_internal_server_error(s); |
583 | 90 return; |
91 } | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
92 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
93 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
94 s->mail_state = ngx_imap_start; |
1477 | 95 c->read->handler = ngx_mail_imap_auth_state; |
1136 | 96 |
1477 | 97 ngx_mail_imap_auth_state(rev); |
1136 | 98 } |
99 | |
100 | |
101 void | |
1477 | 102 ngx_mail_imap_auth_state(ngx_event_t *rev) |
1136 | 103 { |
8462
ccdf83bee8c1
Mail: fixed backslash handling in IMAP literals.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
104 u_char *p; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
105 ngx_int_t rc; |
8462
ccdf83bee8c1
Mail: fixed backslash handling in IMAP literals.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8339
diff
changeset
|
106 ngx_uint_t tag; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
107 ngx_connection_t *c; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
108 ngx_mail_session_t *s; |
1136 | 109 |
110 c = rev->data; | |
111 s = c->data; | |
112 | |
113 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap auth state"); | |
114 | |
115 if (rev->timedout) { | |
116 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
117 c->timedout = 1; | |
118 ngx_mail_close_connection(c); | |
119 return; | |
120 } | |
121 | |
122 if (s->out.len) { | |
123 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap send handler busy"); | |
124 s->blocked = 1; | |
8338
ab6257dac2a8
Mail: added missing event handling after blocking events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6869
diff
changeset
|
125 |
ab6257dac2a8
Mail: added missing event handling after blocking events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6869
diff
changeset
|
126 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
ab6257dac2a8
Mail: added missing event handling after blocking events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6869
diff
changeset
|
127 ngx_mail_close_connection(c); |
ab6257dac2a8
Mail: added missing event handling after blocking events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6869
diff
changeset
|
128 return; |
ab6257dac2a8
Mail: added missing event handling after blocking events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6869
diff
changeset
|
129 } |
ab6257dac2a8
Mail: added missing event handling after blocking events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6869
diff
changeset
|
130 |
1136 | 131 return; |
132 } | |
133 | |
134 s->blocked = 0; | |
135 | |
1482 | 136 rc = ngx_mail_read_command(s, c); |
527 | 137 |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
138 if (rc == NGX_AGAIN) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
139 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
140 ngx_mail_session_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
141 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
142 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
143 |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
144 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
145 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
146 |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
147 if (rc == NGX_ERROR) { |
527 | 148 return; |
149 } | |
150 | |
151 tag = 1; | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
152 s->text.len = 0; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
153 ngx_str_set(&s->out, imap_ok); |
527 | 154 |
155 if (rc == NGX_OK) { | |
156 | |
1136 | 157 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap auth command: %i", |
527 | 158 s->command); |
159 | |
1323 | 160 switch (s->mail_state) { |
161 | |
162 case ngx_imap_start: | |
163 | |
164 switch (s->command) { | |
165 | |
166 case NGX_IMAP_LOGIN: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
167 rc = ngx_mail_imap_login(s, c); |
1323 | 168 break; |
169 | |
170 case NGX_IMAP_AUTHENTICATE: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
171 rc = ngx_mail_imap_authenticate(s, c); |
1479 | 172 tag = (rc != NGX_OK); |
1323 | 173 break; |
174 | |
175 case NGX_IMAP_CAPABILITY: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
176 rc = ngx_mail_imap_capability(s, c); |
1323 | 177 break; |
178 | |
179 case NGX_IMAP_LOGOUT: | |
180 s->quit = 1; | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
181 ngx_str_set(&s->text, imap_bye); |
1323 | 182 break; |
183 | |
184 case NGX_IMAP_NOOP: | |
185 break; | |
186 | |
187 case NGX_IMAP_STARTTLS: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
188 rc = ngx_mail_imap_starttls(s, c); |
1323 | 189 break; |
190 | |
191 default: | |
192 rc = NGX_MAIL_PARSE_INVALID_COMMAND; | |
193 break; | |
194 } | |
195 | |
196 break; | |
197 | |
198 case ngx_imap_auth_login_username: | |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
199 rc = ngx_mail_auth_login_username(s, c, 0); |
1323 | 200 |
201 tag = 0; | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
202 ngx_str_set(&s->out, imap_password); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
203 s->mail_state = ngx_imap_auth_login_password; |
1323 | 204 |
205 break; | |
206 | |
207 case ngx_imap_auth_login_password: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
208 rc = ngx_mail_auth_login_password(s, c); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
209 break; |
1323 | 210 |
211 case ngx_imap_auth_plain: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
212 rc = ngx_mail_auth_plain(s, c, 0); |
527 | 213 break; |
214 | |
1323 | 215 case ngx_imap_auth_cram_md5: |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
216 rc = ngx_mail_auth_cram_md5(s, c); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
217 break; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
218 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
219 case ngx_imap_auth_external: |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
220 rc = ngx_mail_auth_external(s, c, 0); |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
221 break; |
527 | 222 } |
223 | |
224 } else if (rc == NGX_IMAP_NEXT) { | |
225 tag = 0; | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
226 ngx_str_set(&s->out, imap_next); |
527 | 227 } |
228 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
229 switch (rc) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
230 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
231 case NGX_DONE: |
1482 | 232 ngx_mail_auth(s, c); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
233 return; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
234 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
235 case NGX_ERROR: |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
236 ngx_mail_session_internal_server_error(s); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
237 return; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
238 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
239 case NGX_MAIL_PARSE_INVALID_COMMAND: |
1323 | 240 s->state = 0; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
241 ngx_str_set(&s->out, imap_invalid_command); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
242 s->mail_state = ngx_imap_start; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
243 break; |
527 | 244 } |
245 | |
246 if (tag) { | |
543 | 247 if (s->tag.len == 0) { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
248 ngx_str_set(&s->tag, imap_star); |
543 | 249 } |
250 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
251 if (s->tagged_line.len < s->tag.len + s->text.len + s->out.len) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
252 s->tagged_line.len = s->tag.len + s->text.len + s->out.len; |
2049 | 253 s->tagged_line.data = ngx_pnalloc(c->pool, s->tagged_line.len); |
539 | 254 if (s->tagged_line.data == NULL) { |
1136 | 255 ngx_mail_close_connection(c); |
527 | 256 return; |
257 } | |
258 } | |
259 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
260 p = s->tagged_line.data; |
539 | 261 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
262 if (s->text.len) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
263 p = ngx_cpymem(p, s->text.data, s->text.len); |
527 | 264 } |
265 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
266 p = ngx_cpymem(p, s->tag.data, s->tag.len); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
267 ngx_memcpy(p, s->out.data, s->out.len); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
268 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
269 s->out.len = s->text.len + s->tag.len + s->out.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
270 s->out.data = s->tagged_line.data; |
527 | 271 } |
272 | |
539 | 273 if (rc != NGX_IMAP_NEXT) { |
274 s->args.nelts = 0; | |
1323 | 275 |
276 if (s->state) { | |
277 /* preserve tag */ | |
278 s->arg_start = s->buffer->start + s->tag.len; | |
279 s->buffer->pos = s->arg_start; | |
280 s->buffer->last = s->arg_start; | |
281 | |
282 } else { | |
283 s->buffer->pos = s->buffer->start; | |
284 s->buffer->last = s->buffer->start; | |
285 s->tag.len = 0; | |
286 } | |
527 | 287 } |
288 | |
8339
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
289 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
290 ngx_mail_session_internal_server_error(s); |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
291 return; |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
292 } |
da0a85e91587
Mail: added missing event handling after reading data.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8338
diff
changeset
|
293 |
1136 | 294 ngx_mail_send(c->write); |
521 | 295 } |
296 | |
297 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
298 static ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
299 ngx_mail_imap_login(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
300 { |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
301 ngx_str_t *arg; |
1479 | 302 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
303 #if (NGX_MAIL_SSL) |
1479 | 304 if (ngx_mail_starttls_only(s, c)) { |
305 return NGX_MAIL_PARSE_INVALID_COMMAND; | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
306 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
307 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
308 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
309 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
310 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
311 if (s->args.nelts != 2 || arg[0].len == 0) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
312 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
313 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
314 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
315 s->login.len = arg[0].len; |
2049 | 316 s->login.data = ngx_pnalloc(c->pool, s->login.len); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
317 if (s->login.data == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
318 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
319 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
320 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
321 ngx_memcpy(s->login.data, arg[0].data, s->login.len); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
322 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
323 s->passwd.len = arg[1].len; |
2049 | 324 s->passwd.data = ngx_pnalloc(c->pool, s->passwd.len); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
325 if (s->passwd.data == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
326 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
327 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
328 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
329 ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
330 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
331 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
332 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
333 "imap login:\"%V\" passwd:\"%V\"", |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
334 &s->login, &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
335 #else |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
336 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
337 "imap login:\"%V\"", &s->login); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
338 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
339 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
340 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
341 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
342 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
343 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
344 static ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
345 ngx_mail_imap_authenticate(ngx_mail_session_t *s, ngx_connection_t *c) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
346 { |
1479 | 347 ngx_int_t rc; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
348 ngx_mail_core_srv_conf_t *cscf; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
349 ngx_mail_imap_srv_conf_t *iscf; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
350 |
1479 | 351 #if (NGX_MAIL_SSL) |
352 if (ngx_mail_starttls_only(s, c)) { | |
353 return NGX_MAIL_PARSE_INVALID_COMMAND; | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
354 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
355 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
356 |
6869
b2915d99ee8d
Mail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
357 iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module); |
b2915d99ee8d
Mail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
358 |
1479 | 359 rc = ngx_mail_auth_parse(s, c); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
360 |
1479 | 361 switch (rc) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
362 |
1479 | 363 case NGX_MAIL_AUTH_LOGIN: |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
364 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
365 ngx_str_set(&s->out, imap_username); |
1479 | 366 s->mail_state = ngx_imap_auth_login_username; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
367 |
1479 | 368 return NGX_OK; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
369 |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
370 case NGX_MAIL_AUTH_LOGIN_USERNAME: |
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
371 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
372 ngx_str_set(&s->out, imap_password); |
2495
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
373 s->mail_state = ngx_imap_auth_login_password; |
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
374 |
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
375 return ngx_mail_auth_login_username(s, c, 1); |
a59b26eee816
compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents:
2388
diff
changeset
|
376 |
1479 | 377 case NGX_MAIL_AUTH_PLAIN: |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
378 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
2495
diff
changeset
|
379 ngx_str_set(&s->out, imap_plain_next); |
1479 | 380 s->mail_state = ngx_imap_auth_plain; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
381 |
1479 | 382 return NGX_OK; |
383 | |
384 case NGX_MAIL_AUTH_CRAM_MD5: | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
385 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
386 if (!(iscf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED)) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
387 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
388 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
389 |
1485
b3488fc2675a
create salt just before it will be used
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
390 if (s->salt.data == NULL) { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
391 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
392 |
1485
b3488fc2675a
create salt just before it will be used
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
393 if (ngx_mail_salt(s, c, cscf) != NGX_OK) { |
b3488fc2675a
create salt just before it will be used
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
394 return NGX_ERROR; |
b3488fc2675a
create salt just before it will be used
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
395 } |
b3488fc2675a
create salt just before it will be used
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
396 } |
b3488fc2675a
create salt just before it will be used
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
397 |
1479 | 398 if (ngx_mail_auth_cram_md5_salt(s, c, "+ ", 2) == NGX_OK) { |
399 s->mail_state = ngx_imap_auth_cram_md5; | |
400 return NGX_OK; | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
401 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
402 |
1479 | 403 return NGX_ERROR; |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
404 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
405 case NGX_MAIL_AUTH_EXTERNAL: |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
406 |
6869
b2915d99ee8d
Mail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
407 if (!(iscf->auth_methods & NGX_MAIL_AUTH_EXTERNAL_ENABLED)) { |
b2915d99ee8d
Mail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
408 return NGX_MAIL_PARSE_INVALID_COMMAND; |
b2915d99ee8d
Mail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
409 } |
b2915d99ee8d
Mail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6774
diff
changeset
|
410 |
6774
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
411 ngx_str_set(&s->out, imap_username); |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
412 s->mail_state = ngx_imap_auth_external; |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
413 |
bcb107bb89cd
Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents:
4412
diff
changeset
|
414 return NGX_OK; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
415 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
416 |
1479 | 417 return rc; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
418 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
419 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
420 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
421 static ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
422 ngx_mail_imap_capability(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
423 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
424 ngx_mail_imap_srv_conf_t *iscf; |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
425 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
426 iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module); |
809 | 427 |
1322 | 428 #if (NGX_MAIL_SSL) |
429 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
430 if (c->ssl == NULL) { |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
431 ngx_mail_ssl_conf_t *sslcf; |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
432 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
433 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
809 | 434 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
435 if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
436 s->text = iscf->starttls_capability; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
437 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
438 } |
1136 | 439 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
440 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
441 s->text = iscf->starttls_only_capability; |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
442 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
443 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
444 } |
1322 | 445 #endif |
446 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1486
diff
changeset
|
447 s->text = iscf->capability; |
894
4f7dca9c37f0
workaround for Eudora for Mac: it sends
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
448 |
4f7dca9c37f0
workaround for Eudora for Mac: it sends
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
449 return NGX_OK; |
4f7dca9c37f0
workaround for Eudora for Mac: it sends
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
450 } |
4f7dca9c37f0
workaround for Eudora for Mac: it sends
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
451 |
4f7dca9c37f0
workaround for Eudora for Mac: it sends
Igor Sysoev <igor@sysoev.ru>
parents:
884
diff
changeset
|
452 |
521 | 453 static ngx_int_t |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
454 ngx_mail_imap_starttls(ngx_mail_session_t *s, ngx_connection_t *c) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
455 { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
456 #if (NGX_MAIL_SSL) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
457 ngx_mail_ssl_conf_t *sslcf; |
1136 | 458 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
459 if (c->ssl == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
460 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
461 if (sslcf->starttls) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
462 c->read->handler = ngx_mail_starttls_handler; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
463 return NGX_OK; |
539 | 464 } |
465 } | |
466 | |
467 #endif | |
468 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
469 return NGX_MAIL_PARSE_INVALID_COMMAND; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
470 } |