annotate src/imap/ngx_imap_handler.c @ 190:3689cd4e3228 NGINX_0_3_42

nginx 0.3.42 *) Feature: the "bind" option of the "listen" directive in IMAP/POP3 proxy. *) Bugfix: if the same capture in the "rewrite" directive was used more then once. *) Bugfix: the $sent_http_content_type, $sent_http_content_length, $sent_http_last_modified, $sent_http_connection, $sent_http_keep_alive, and $sent_http_transfer_encoding variables were not written to access log. *) Bugfix: the $sent_http_cache_control returned value of the single "Cache-Control" response header line.
author Igor Sysoev <http://sysoev.ru>
date Wed, 26 Apr 2006 00:00:00 +0400
parents 91372f004adf
children fbf2b2f66c9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_event.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_imap.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
13 static void ngx_imap_init_session(ngx_connection_t *c);
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
14 static void ngx_imap_init_protocol(ngx_event_t *rev);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 static ngx_int_t ngx_imap_read_command(ngx_imap_session_t *s);
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
16 static u_char *ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
18 #if (NGX_IMAP_SSL)
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
19 static void ngx_imap_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
20 static void ngx_imap_ssl_handshake_handler(ngx_connection_t *c);
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
21 #endif
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
22
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 static ngx_str_t greetings[] = {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 ngx_string("+OK POP3 ready" CRLF),
78
9db7e0b5b27f nginx 0.1.39
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
26 ngx_string("* OK IMAP4 ready" CRLF)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 static ngx_str_t internal_server_errors[] = {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 ngx_string("-ERR internal server error" CRLF),
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 ngx_string("* BAD internal server error" CRLF),
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 static u_char pop3_ok[] = "+OK" CRLF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
37 static u_char imap_star[] = "* ";
78
9db7e0b5b27f nginx 0.1.39
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
38 static u_char imap_ok[] = "OK completed" CRLF;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 static u_char imap_next[] = "+ OK" CRLF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 static u_char imap_bye[] = "* BYE" CRLF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 static u_char imap_invalid_command[] = "BAD invalid command" CRLF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 ngx_imap_init_connection(ngx_connection_t *c)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 {
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
47 in_addr_t in_addr;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
48 socklen_t len;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
49 ngx_uint_t i;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
50 struct sockaddr_in sin;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
51 ngx_imap_log_ctx_t *ctx;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
52 ngx_imap_in_port_t *imip;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
53 ngx_imap_in_addr_t *imia;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
54 ngx_imap_session_t *s;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
55 #if (NGX_IMAP_SSL)
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
56 ngx_imap_ssl_conf_t *sslcf;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
57 #endif
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
58
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
59
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
60 /* find the server configuration for the address:port */
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
61
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
62 /* AF_INET only */
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
63
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
64 imip = c->listening->servers;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
65 imia = imip->addrs;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
66
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
67 i = 0;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
68
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
69 if (imip->naddrs > 1) {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
70
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
71 /*
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
72 * There are several addresses on this port and one of them
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
73 * is the "*:port" wildcard so getsockname() is needed to determine
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
74 * the server address.
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
75 *
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
76 * AcceptEx() already gave this address.
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
77 */
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
78
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
79 #if (NGX_WIN32)
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
80 if (c->local_sockaddr) {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
81 in_addr =
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
82 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
83
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
84 } else
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
85 #endif
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
86 {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
87 len = sizeof(struct sockaddr_in);
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
88 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
89 ngx_connection_error(c, ngx_socket_errno,
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
90 "getsockname() failed");
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
91 ngx_imap_close_connection(c);
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
92 return;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
93 }
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
94
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
95 in_addr = sin.sin_addr.s_addr;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
96 }
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
97
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
98 /* the last address is "*" */
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
99
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
100 for ( /* void */ ; i < imip->naddrs - 1; i++) {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
101 if (in_addr == imia[i].addr) {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
102 break;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
103 }
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
104 }
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
105 }
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
106
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
107
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
108 s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t));
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
109 if (s == NULL) {
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
110 ngx_imap_close_connection(c);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
111 return;
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
112 }
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
113
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
114 s->main_conf = imia[i].ctx->main_conf;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
115 s->srv_conf = imia[i].ctx->srv_conf;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
116
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
117 s->addr_text = &imia[i].addr_text;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
118
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
119 c->data = s;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
120 s->connection = c;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
121
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
122 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V",
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
123 c->number, &c->addr_text, s->addr_text);
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
124
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
125 ctx = ngx_palloc(c->pool, sizeof(ngx_imap_log_ctx_t));
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
126 if (ctx == NULL) {
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
127 ngx_imap_close_connection(c);
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
128 return;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
129 }
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
130
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
131 ctx->client = &c->addr_text;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
132 ctx->session = s;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
133
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
134 c->log->connection = c->number;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
135 c->log->handler = ngx_imap_log_error;
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
136 c->log->data = ctx;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
137 c->log->action = "sending client greeting line";
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
138
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
139 c->log_error = NGX_ERROR_INFO;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
140
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
141 #if (NGX_IMAP_SSL)
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
142
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
143 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module);
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
144
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
145 if (sslcf->enable) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
146 ngx_imap_ssl_init_connection(&sslcf->ssl, c);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
147 return;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
148 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
149
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
150 #endif
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
151
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
152 ngx_imap_init_session(c);
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
153 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
154
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
155
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
156 #if (NGX_IMAP_SSL)
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
157
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
158 static void
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
159 ngx_imap_starttls_handler(ngx_event_t *rev)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
160 {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
161 ngx_connection_t *c;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
162 ngx_imap_session_t *s;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
163 ngx_imap_ssl_conf_t *sslcf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
164
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
165 c = rev->data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
166 s = c->data;
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
167 s->starttls = 1;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
168
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
169 c->log->action = "in starttls state";
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
170
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
171 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
172
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
173 ngx_imap_ssl_init_connection(&sslcf->ssl, c);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
174 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
175
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
176
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
177 static void
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
178 ngx_imap_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
179 {
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
180 ngx_imap_session_t *s;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
181 ngx_imap_core_srv_conf_t *cscf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
182
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
183 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
184 ngx_imap_close_connection(c);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
185 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
186 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
187
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
188 if (ngx_ssl_handshake(c) == NGX_AGAIN) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
189
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
190 s = c->data;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
191
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
192 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
193
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
194 ngx_add_timer(c->read, cscf->timeout);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
195
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
196 c->ssl->handler = ngx_imap_ssl_handshake_handler;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
197
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
198 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
199 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
200
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
201 ngx_imap_ssl_handshake_handler(c);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
202 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
203
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
204
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
205 static void
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
206 ngx_imap_ssl_handshake_handler(ngx_connection_t *c)
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
207 {
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
208 ngx_imap_session_t *s;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
209
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
210 if (c->ssl->handshaked) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
211
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
212 s = c->data;
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
213
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
214 if (s->starttls) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
215 c->read->handler = ngx_imap_init_protocol;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
216 c->write->handler = ngx_imap_send;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
217
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
218 ngx_imap_init_protocol(c->read);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
219
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
220 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
221 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
222
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
223 ngx_imap_init_session(c);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
224 return;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
225 }
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
226
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
227 ngx_imap_close_connection(c);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
228 }
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
229
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
230 #endif
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
231
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
232
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
233 static void
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
234 ngx_imap_init_session(ngx_connection_t *c)
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
235 {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
236 ngx_imap_session_t *s;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
237 ngx_imap_core_srv_conf_t *cscf;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
239 c->read->handler = ngx_imap_init_protocol;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
240 c->write->handler = ngx_imap_send;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
241
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
242 s = c->data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
244 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
245
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
246 s->protocol = cscf->protocol;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
247
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
248 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_imap_max_module);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
249 if (s->ctx == NULL) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
250 ngx_imap_session_internal_server_error(s);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
251 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
252 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
253
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
254 s->out = greetings[s->protocol];
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
255
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
256 ngx_add_timer(c->read, cscf->timeout);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
258 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 }
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
261
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
262 ngx_imap_send(c->write);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
263 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
264
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
265
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
266 void
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
267 ngx_imap_send(ngx_event_t *wev)
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
268 {
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
269 ngx_int_t n;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
270 ngx_connection_t *c;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
271 ngx_imap_session_t *s;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
272 ngx_imap_core_srv_conf_t *cscf;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
273
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
274 c = wev->data;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
275 s = c->data;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
276
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
277 if (wev->timedout) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
278 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
279 c->timedout = 1;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
280 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
281 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
282 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
283
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
284 if (s->out.len == 0) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
285 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
286 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
287 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
288
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
289 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
290 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
291
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
292 n = c->send(c, s->out.data, s->out.len);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
293
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
294 if (n > 0) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
295 s->out.len -= n;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
296
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
297 if (wev->timer_set) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
298 ngx_del_timer(wev);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
299 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
300
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
301 if (s->quit) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
302 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
303 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
304 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
305
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
306 if (s->blocked) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
307 c->read->handler(c->read);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
308 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
309
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
310 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
311 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
312
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
313 if (n == NGX_ERROR) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
314 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
315 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
316 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
317
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
318 /* n == NGX_AGAIN */
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
319
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
320 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
321
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
322 ngx_add_timer(c->write, cscf->timeout);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
323
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
324 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
325 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
326 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
327 }
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 static void
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
332 ngx_imap_init_protocol(ngx_event_t *rev)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 size_t size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
336 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337 ngx_imap_core_srv_conf_t *cscf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
341 c->log->action = "in auth state";
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
342
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
345 c->timedout = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
347 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
350 s = c->data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
351
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
352 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
353 size = 128;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
354 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
355 c->read->handler = ngx_pop3_auth_state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
356
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
357 } else {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
358 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
359 size = cscf->imap_client_buffer_size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
360 s->imap_state = ngx_imap_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361 c->read->handler = ngx_imap_auth_state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 if (s->buffer == NULL) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
365 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t))
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
366 == NGX_ERROR)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
367 {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
368 ngx_imap_session_internal_server_error(s);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
369 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
370 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
371
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
372 s->buffer = ngx_create_temp_buf(c->pool, size);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
373 if (s->buffer == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
374 ngx_imap_session_internal_server_error(s);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
375 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
376 }
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
377 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
378
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
379 c->read->handler(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
382
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
383 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
384 ngx_imap_auth_state(ngx_event_t *rev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
385 {
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
386 u_char *text, *last, *p, *dst, *src, *end;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
387 ssize_t text_len, last_len;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 ngx_str_t *arg;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389 ngx_int_t rc;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
390 ngx_uint_t tag, i;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393 ngx_imap_core_srv_conf_t *cscf;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
394 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
395 ngx_imap_ssl_conf_t *sslcf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
396 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth state");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
405 c->timedout = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
410 if (s->out.len) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
411 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap send handler busy");
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
412 s->blocked = 1;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
413 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
414 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
415
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
416 s->blocked = 0;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
417
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418 rc = ngx_imap_read_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth: %i", rc);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422 if (rc == NGX_AGAIN || rc == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426 tag = 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
427
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428 text = NULL;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429 text_len = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
431 last = imap_ok;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432 last_len = sizeof(imap_ok) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 if (rc == NGX_OK) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
436 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth command: %i",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437 s->command);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
439 if (s->backslash) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
440
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
441 arg = s->args.elts;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
442
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
443 for (i = 0; i < s->args.nelts; i++) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
444 dst = arg[i].data;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
445 end = dst + arg[i].len;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
446
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
447 for (src = dst; src < end; dst++) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
448 *dst = *src;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
449 if (*src++ == '\\') {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
450 *dst = *src++;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
451 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
452 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
453
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
454 arg[i].len = dst - arg[i].data;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
455 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
456
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
457 s->backslash = 0;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
458 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
459
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
460 switch (s->command) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462 case NGX_IMAP_LOGIN:
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
463
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
464 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
465
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
466 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
467 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
468
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
469 if (sslcf->starttls == NGX_IMAP_STARTTLS_ONLY) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
470 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
471 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
472 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
473 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
474 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
475
118
644a7935144b nginx 0.3.6
Igor Sysoev <http://sysoev.ru>
parents: 116
diff changeset
476 arg = s->args.elts;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
477
118
644a7935144b nginx 0.3.6
Igor Sysoev <http://sysoev.ru>
parents: 116
diff changeset
478 if (s->args.nelts == 2 && arg[0].len) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
479
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
480 s->login.len = arg[0].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
481 s->login.data = ngx_palloc(c->pool, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
482 if (s->login.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
483 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
484 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
486
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
487 ngx_memcpy(s->login.data, arg[0].data, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
488
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
489 s->passwd.len = arg[1].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490 s->passwd.data = ngx_palloc(c->pool, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
491 if (s->passwd.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
492 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
494 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496 ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
498 #if (NGX_DEBUG_IMAP_PASSWD)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500 "imap login:\"%V\" passwd:\"%V\"",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
501 &s->login, &s->passwd);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
502 #else
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
503 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
504 "imap login:\"%V\"", &s->login);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
505 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
506
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
507 s->args.nelts = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
508 s->buffer->pos = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
509 s->buffer->last = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
510
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
511 if (rev->timer_set) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512 ngx_del_timer(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
513 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
514
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
515 s->login_attempt++;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
516
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
517 ngx_imap_auth_http_init(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
518
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
519 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
520
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
521 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
522 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
523 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
524
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
525 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
526
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
527 case NGX_IMAP_CAPABILITY:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
528 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
529
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
530 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
531
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
532 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
533 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
534
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
535 if (sslcf->starttls == NGX_IMAP_STARTTLS_ON) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
536 text_len = cscf->imap_starttls_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
537 text = cscf->imap_starttls_capability.data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
538 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
539 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
540
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
541 if (sslcf->starttls == NGX_IMAP_STARTTLS_ONLY) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
542 text_len = cscf->imap_starttls_only_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
543 text = cscf->imap_starttls_only_capability.data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
544 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
545 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
546 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
547 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
548
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
549 text_len = cscf->imap_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
550 text = cscf->imap_capability.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
551 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
552
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
553 case NGX_IMAP_LOGOUT:
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
554 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
555 text = imap_bye;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
556 text_len = sizeof(imap_bye) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
557 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
558
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
559 case NGX_IMAP_NOOP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
560 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
561
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
562 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
563
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
564 case NGX_IMAP_STARTTLS:
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
565 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
566 sslcf = ngx_imap_get_module_srv_conf(s, ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
567 if (sslcf->starttls) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
568 c->read->handler = ngx_imap_starttls_handler;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
569 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
570 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
571 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
572
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
573 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
574 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
575 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
576
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
577 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
578 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
580 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
581
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
582 } else if (rc == NGX_IMAP_NEXT) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
583 last = imap_next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
584 last_len = sizeof(imap_next) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
585 tag = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
588 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
589 last = imap_invalid_command;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
590 last_len = sizeof(imap_invalid_command) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
591 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
592
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
593 if (tag) {
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
594 if (s->tag.len == 0) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
595 s->tag.len = sizeof(imap_star) - 1;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
596 s->tag.data = (u_char *) imap_star;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
597 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
598
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
599 if (s->tagged_line.len < s->tag.len + text_len + last_len) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
600 s->tagged_line.len = s->tag.len + text_len + last_len;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
601 s->tagged_line.data = ngx_palloc(c->pool, s->tagged_line.len);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
602 if (s->tagged_line.data == NULL) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
603 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
604 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
605 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
606 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
607
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
608 s->out.data = s->tagged_line.data;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
609 s->out.len = s->tag.len + text_len + last_len;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
610
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
611 p = s->out.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
612
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
613 if (text) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
614 p = ngx_cpymem(p, text, text_len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
615 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
616 p = ngx_cpymem(p, s->tag.data, s->tag.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
617 ngx_memcpy(p, last, last_len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
618
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
619
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
620 } else {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
621 s->out.data = last;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
622 s->out.len = last_len;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
623 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
624
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
625 if (rc != NGX_IMAP_NEXT) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
626 s->args.nelts = 0;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
627 s->buffer->pos = s->buffer->start;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
628 s->buffer->last = s->buffer->start;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
629 s->tag.len = 0;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
631
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
632 ngx_imap_send(c->write);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
633 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
634
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
635
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
637 ngx_pop3_auth_state(ngx_event_t *rev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
638 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
639 u_char *text;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
640 ssize_t size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
641 ngx_int_t rc;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
642 ngx_str_t *arg;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
644 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
645 ngx_imap_core_srv_conf_t *cscf;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
646 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
647 ngx_imap_ssl_conf_t *sslcf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
648 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
649
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
651 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
652
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
653 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
654
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
655 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
656 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
657 c->timedout = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
658 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
659 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
660 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
661
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
662 if (s->out.len) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
663 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap send handler busy");
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
664 s->blocked = 1;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
665 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
666 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
667
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
668 s->blocked = 0;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
669
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
670 rc = ngx_imap_read_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
671
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
672 if (rc == NGX_AGAIN || rc == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
673 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
674 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
675
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
676 text = pop3_ok;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
677 size = sizeof(pop3_ok) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
678
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
679 if (rc == NGX_OK) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
680 switch (s->imap_state) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
681
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
682 case ngx_pop3_start:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
683
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
684 switch (s->command) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
685
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
686 case NGX_POP3_USER:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
687 if (s->args.nelts == 1) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
688 s->imap_state = ngx_pop3_user;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
689
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
690 arg = s->args.elts;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
691 s->login.len = arg[0].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
692 s->login.data = ngx_palloc(c->pool, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
693 if (s->login.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698 ngx_memcpy(s->login.data, arg[0].data, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
699
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
700 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
701 "pop3 login: \"%V\"", &s->login);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
702
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
703 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
704 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
705 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
706
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
707 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
708
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
709 case NGX_POP3_CAPA:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
710 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
711
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
712 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
713
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
714 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
715 sslcf = ngx_imap_get_module_srv_conf(s,
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
716 ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
717 if (sslcf->starttls) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
718 size = cscf->pop3_starttls_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
719 text = cscf->pop3_starttls_capability.data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
720 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
721 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
722 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
723 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
724
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
725 size = cscf->pop3_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
726 text = cscf->pop3_capability.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
728
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
729 case NGX_POP3_QUIT:
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
730 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
732
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
733 case NGX_POP3_NOOP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
734 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
735
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
736 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
737
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
738 case NGX_POP3_STLS:
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
739 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
740 sslcf = ngx_imap_get_module_srv_conf(s,
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
741 ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
742 if (sslcf->starttls) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
743 c->read->handler = ngx_imap_starttls_handler;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
744 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
745 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
746 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
747
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
748 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
749 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
750 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
751
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
752 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
753 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
754 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
755 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
756 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
757
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
758 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
759
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760 case ngx_pop3_user:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
761
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
762 switch (s->command) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
763
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
764 case NGX_POP3_PASS:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
765 if (s->args.nelts == 1) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
766 /* STUB */ s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
767
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
768 arg = s->args.elts;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
769 s->passwd.len = arg[0].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
770 s->passwd.data = ngx_palloc(c->pool, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
771 if (s->passwd.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
772 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
773 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
774 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
775
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
776 ngx_memcpy(s->passwd.data, arg[0].data, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
777
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
778 #if (NGX_DEBUG_IMAP_PASSWD)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
779 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
780 "pop3 passwd: \"%V\"", &s->passwd);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
781 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
782
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783 s->args.nelts = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784 s->buffer->pos = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
785 s->buffer->last = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
786
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
787 if (rev->timer_set) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
788 ngx_del_timer(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
791 ngx_imap_auth_http_init(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
792
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
793 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
794
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
795 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
796 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
797 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
798
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
799 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
800
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
801 case NGX_POP3_CAPA:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
803 size = cscf->pop3_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
804 text = cscf->pop3_capability.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
805 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
806
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807 case NGX_POP3_QUIT:
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
808 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
809 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
810
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
811 case NGX_POP3_NOOP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
812 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
813
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
816 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
817 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
818 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
819
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
820 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
821
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
822 /* suppress warinings */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
823 case ngx_pop3_passwd:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
825 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
826 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
827
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
828 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
829 text = pop3_invalid_command;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
830 size = sizeof(pop3_invalid_command) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
831 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
832
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
833 s->args.nelts = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834 s->buffer->pos = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
835 s->buffer->last = s->buffer->start;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
836
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
837 s->out.data = text;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
838 s->out.len = size;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
839
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
840 ngx_imap_send(c->write);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
841 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
842
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
843
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
844 static ngx_int_t
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
845 ngx_imap_read_command(ngx_imap_session_t *s)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
846 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847 ssize_t n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848 ngx_int_t rc;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
850 n = s->connection->recv(s->connection, s->buffer->last,
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
851 s->buffer->end - s->buffer->last);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
852
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
853 if (n == NGX_ERROR || n == 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
854 ngx_imap_close_connection(s->connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
855 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
856 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
857
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
858 if (n > 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
859 s->buffer->last += n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
860 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
861
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
862 if (n == NGX_AGAIN) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
863 if (ngx_handle_read_event(s->connection->read, 0) == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
864 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
865 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
866 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
867
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
868 return NGX_AGAIN;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
869 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
870
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
871 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
872 rc = ngx_pop3_parse_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
873 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
874 rc = ngx_imap_parse_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
875 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
876
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
877 if (rc == NGX_AGAIN
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
878 || rc == NGX_IMAP_NEXT
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
879 || rc == NGX_IMAP_PARSE_INVALID_COMMAND)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
880 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
881 return rc;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
882 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
883
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
884 if (rc == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
885 ngx_imap_close_connection(s->connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
886 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
887 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
888
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
889 return NGX_OK;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
890 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
891
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
892
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
893 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
894 ngx_imap_session_internal_server_error(ngx_imap_session_t *s)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
895 {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
896 s->out = internal_server_errors[s->protocol];
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
897 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
898
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
899 ngx_imap_send(s->connection->write);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
900 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
901
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
902
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
903 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
904 ngx_imap_close_connection(ngx_connection_t *c)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
905 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
906 ngx_pool_t *pool;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
907
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
908 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
909 "close imap connection: %d", c->fd);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
910
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
911 #if (NGX_IMAP_SSL)
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
912
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
913 if (c->ssl) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
914 if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
915 c->ssl->handler = ngx_imap_close_connection;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
916 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
917 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
918 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
919
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
920 #endif
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
921
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
922 c->destroyed = 1;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
923
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
924 pool = c->pool;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
925
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
926 ngx_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
927
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
928 ngx_destroy_pool(pool);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
929 }
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
930
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
931
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
932 static u_char *
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
933 ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len)
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
934 {
116
e38f51cd0905 nginx 0.3.5
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
935 u_char *p;
e38f51cd0905 nginx 0.3.5
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
936 ngx_imap_session_t *s;
e38f51cd0905 nginx 0.3.5
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
937 ngx_imap_log_ctx_t *ctx;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
938
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
939 if (log->action) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
940 p = ngx_snprintf(buf, len, " while %s", log->action);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
941 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
942 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
943 }
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
944
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
945 ctx = log->data;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
946
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
947 p = ngx_snprintf(buf, len, ", client: %V", ctx->client);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
948 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
949 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
950
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
951 s = ctx->session;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
952
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
953 if (s == NULL) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
954 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
955 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
956
190
3689cd4e3228 nginx 0.3.42
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
957 p = ngx_snprintf(buf, len, ", server: %V", s->addr_text);
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
958 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
959 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
960
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
961 if (s->login.len == 0) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
962 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
963 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
964
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
965 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
966 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
967 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
968
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
969 if (s->proxy == NULL) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
970 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
971 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
972
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
973 p = ngx_snprintf(buf, len, ", upstream: %V",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
974 &s->proxy->upstream.peers->peer[0].name);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
975
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
976 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
977 }