annotate src/imap/ngx_imap_handler.c @ 132:91372f004adf NGINX_0_3_13

nginx 0.3.13 *) Feature: the IMAP/POP3 proxy supports STARTTLS and STLS. *) Bugfix: the IMAP/POP3 proxy did not work with the select, poll, and /dev/poll methods. *) Bugfix: in SSI handling. *) Bugfix: now Solaris sendfilev() is not used to transfer the client request body to FastCGI-server via the unix domain socket. *) Bugfix: the "auth_basic" directive did not disable the authorization; bug appeared in 0.3.11.
author Igor Sysoev <http://sysoev.ru>
date Mon, 05 Dec 2005 00:00:00 +0300
parents df17fbafec8f
children 3689cd4e3228
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 {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
47 ngx_imap_log_ctx_t *lctx;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
48 #if (NGX_IMAP_SSL)
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
49 ngx_imap_conf_ctx_t *ctx;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
50 ngx_imap_ssl_conf_t *sslcf;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
51 #endif
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
52
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
53 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V",
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
54 c->number, &c->addr_text, &c->listening->addr_text);
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
55
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
56 lctx = ngx_palloc(c->pool, sizeof(ngx_imap_log_ctx_t));
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
57 if (lctx == NULL) {
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
58 ngx_imap_close_connection(c);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
59 return;
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
60 }
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
61
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
62 lctx->client = &c->addr_text;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
63 lctx->session = NULL;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
64
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
65 c->log->connection = c->number;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
66 c->log->handler = ngx_imap_log_error;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
67 c->log->data = lctx;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
68 c->log->action = "sending client greeting line";
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
69
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
70 c->log_error = NGX_ERROR_INFO;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
71
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
72 #if (NGX_IMAP_SSL)
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
73
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
74 ctx = c->ctx;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
75 sslcf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_ssl_module);
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
76
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
77 if (sslcf->enable) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
78 ngx_imap_ssl_init_connection(&sslcf->ssl, c);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
79 return;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
80 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
81
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
82 #endif
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
83
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
84 ngx_imap_init_session(c);
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
85 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
86
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
87
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
88 #if (NGX_IMAP_SSL)
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
89
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
90 static void
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
91 ngx_imap_starttls_handler(ngx_event_t *rev)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
92 {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
93 ngx_connection_t *c;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
94 ngx_imap_session_t *s;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
95 ngx_imap_ssl_conf_t *sslcf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
96
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
97 c = rev->data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
98 s = c->data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
99
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
100 c->log->action = "in starttls state";
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
101
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
102 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
103
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
104 ngx_imap_ssl_init_connection(&sslcf->ssl, c);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
105 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
106
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
107
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
108 static void
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
109 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
110 {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
111 ngx_imap_conf_ctx_t *ctx;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
112 ngx_imap_core_srv_conf_t *cscf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
113
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
114 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
115 ngx_imap_close_connection(c);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
116 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
117 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
118
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
119 if (ngx_ssl_handshake(c) == NGX_AGAIN) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
120
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
121 ctx = c->ctx;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
122 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
123
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
124 ngx_add_timer(c->read, cscf->timeout);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
125
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
126 c->ssl->handler = ngx_imap_ssl_handshake_handler;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
127
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
128 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
129 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
130
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
131 ngx_imap_ssl_handshake_handler(c);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
132 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
133
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
134
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
135 static void
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
136 ngx_imap_ssl_handshake_handler(ngx_connection_t *c)
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
137 {
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
138 if (c->ssl->handshaked) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
139
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
140 if (c->data) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
141 c->read->handler = ngx_imap_init_protocol;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
142 c->write->handler = ngx_imap_send;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
143
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
144 ngx_imap_init_protocol(c->read);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
145
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
146 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
147 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
148
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
149 ngx_imap_init_session(c);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
150 return;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
151 }
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
152
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
153 ngx_imap_close_connection(c);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
154 }
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
155
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
156 #endif
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
157
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
158
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
159 static void
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
160 ngx_imap_init_session(ngx_connection_t *c)
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
161 {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
162 ngx_imap_session_t *s;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
163 ngx_imap_log_ctx_t *lctx;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 ngx_imap_conf_ctx_t *ctx;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
165 ngx_imap_core_srv_conf_t *cscf;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
167 c->read->handler = ngx_imap_init_protocol;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
168 c->write->handler = ngx_imap_send;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
169
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
170 s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t));
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
171 if (s == NULL) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
176 ctx = c->ctx;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
177 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
178
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
179 c->data = s;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
180 s->connection = c;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
181
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
182 s->protocol = cscf->protocol;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
183
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
184 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
185 if (s->ctx == NULL) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
186 ngx_imap_session_internal_server_error(s);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
187 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
188 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
189
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
190 s->main_conf = ctx->main_conf;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
191 s->srv_conf = ctx->srv_conf;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
192
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
193 s->out = greetings[s->protocol];
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
194
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
195 lctx = c->log->data;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
196 lctx->session = s;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
197
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
198 ngx_add_timer(c->read, cscf->timeout);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
200 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 }
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
203
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
204 ngx_imap_send(c->write);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
205 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
206
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
207
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
208 void
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
209 ngx_imap_send(ngx_event_t *wev)
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
210 {
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
211 ngx_int_t n;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
212 ngx_connection_t *c;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
213 ngx_imap_session_t *s;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
214 ngx_imap_core_srv_conf_t *cscf;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
215
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
216 c = wev->data;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
217 s = c->data;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
218
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
219 if (wev->timedout) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
220 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
221 c->timedout = 1;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
222 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
223 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
224 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
225
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
226 if (s->out.len == 0) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
227 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
228 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
229 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
230
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
231 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
232 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
233
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
234 n = c->send(c, s->out.data, s->out.len);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
235
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
236 if (n > 0) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
237 s->out.len -= n;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
238
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
239 if (wev->timer_set) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
240 ngx_del_timer(wev);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
241 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
242
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
243 if (s->quit) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
244 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
245 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
246 }
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 if (s->blocked) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
249 c->read->handler(c->read);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
250 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
251
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
252 return;
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
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
255 if (n == NGX_ERROR) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
256 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
257 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
258 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
259
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
260 /* n == NGX_AGAIN */
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
261
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
262 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
263
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
264 ngx_add_timer(c->write, cscf->timeout);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
265
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
266 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
267 ngx_imap_close_connection(c);
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
268 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
269 }
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 static void
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
274 ngx_imap_init_protocol(ngx_event_t *rev)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 size_t size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279 ngx_imap_core_srv_conf_t *cscf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
283 c->log->action = "in auth state";
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
284
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 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
287 c->timedout = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
292 s = c->data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
294 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295 size = 128;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 c->read->handler = ngx_pop3_auth_state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299 } else {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
300 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
301 size = cscf->imap_client_buffer_size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 s->imap_state = ngx_imap_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 c->read->handler = ngx_imap_auth_state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 if (s->buffer == NULL) {
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
307 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
308 == NGX_ERROR)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
309 {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
310 ngx_imap_session_internal_server_error(s);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
311 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
312 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
313
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
314 s->buffer = ngx_create_temp_buf(c->pool, size);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
315 if (s->buffer == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
316 ngx_imap_session_internal_server_error(s);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
317 return;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
318 }
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 c->read->handler(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
324
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326 ngx_imap_auth_state(ngx_event_t *rev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 {
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
328 u_char *text, *last, *p, *dst, *src, *end;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
329 ssize_t text_len, last_len;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330 ngx_str_t *arg;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 ngx_int_t rc;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
332 ngx_uint_t tag, i;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335 ngx_imap_core_srv_conf_t *cscf;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
336 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
337 ngx_imap_ssl_conf_t *sslcf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
338 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
342
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 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
344
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
345 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346 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
347 c->timedout = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
350 }
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->out.len) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
353 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
354 s->blocked = 1;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
355 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
356 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
357
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
358 s->blocked = 0;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
359
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
360 rc = ngx_imap_read_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 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
363
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 if (rc == NGX_AGAIN || rc == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368 tag = 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
370 text = NULL;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
371 text_len = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 last = imap_ok;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374 last_len = sizeof(imap_ok) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
376 if (rc == NGX_OK) {
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 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
379 s->command);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
381 if (s->backslash) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
382
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
383 arg = s->args.elts;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
384
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
385 for (i = 0; i < s->args.nelts; i++) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
386 dst = arg[i].data;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
387 end = dst + arg[i].len;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
388
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
389 for (src = dst; src < end; dst++) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
390 *dst = *src;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
391 if (*src++ == '\\') {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
392 *dst = *src++;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
393 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
394 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
395
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
396 arg[i].len = dst - arg[i].data;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
397 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
398
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
399 s->backslash = 0;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
400 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
401
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402 switch (s->command) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 case NGX_IMAP_LOGIN:
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
405
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
406 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
407
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
408 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
409 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
410
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
411 if (sslcf->starttls == NGX_IMAP_STARTTLS_ONLY) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
412 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
413 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
414 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
415 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
416 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
417
118
644a7935144b nginx 0.3.6
Igor Sysoev <http://sysoev.ru>
parents: 116
diff changeset
418 arg = s->args.elts;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419
118
644a7935144b nginx 0.3.6
Igor Sysoev <http://sysoev.ru>
parents: 116
diff changeset
420 if (s->args.nelts == 2 && arg[0].len) {
76
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 s->login.len = arg[0].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423 s->login.data = ngx_palloc(c->pool, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424 if (s->login.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426 return;
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
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429 ngx_memcpy(s->login.data, arg[0].data, s->login.len);
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 s->passwd.len = arg[1].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432 s->passwd.data = ngx_palloc(c->pool, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433 if (s->passwd.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
436 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438 ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
439
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
440 #if (NGX_DEBUG_IMAP_PASSWD)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442 "imap login:\"%V\" passwd:\"%V\"",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443 &s->login, &s->passwd);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
444 #else
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
445 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
446 "imap login:\"%V\"", &s->login);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
447 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 s->args.nelts = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450 s->buffer->pos = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
451 s->buffer->last = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
452
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
453 if (rev->timer_set) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454 ngx_del_timer(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
455 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
456
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
457 s->login_attempt++;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
458
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
459 ngx_imap_auth_http_init(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
460
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
464 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
467 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
468
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
469 case NGX_IMAP_CAPABILITY:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470 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
471
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
472 #if (NGX_IMAP_SSL)
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 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
475 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
476
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
477 if (sslcf->starttls == NGX_IMAP_STARTTLS_ON) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
478 text_len = cscf->imap_starttls_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
479 text = cscf->imap_starttls_capability.data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
480 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
481 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
482
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
483 if (sslcf->starttls == NGX_IMAP_STARTTLS_ONLY) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
484 text_len = cscf->imap_starttls_only_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
485 text = cscf->imap_starttls_only_capability.data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
486 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
487 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
488 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
489 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
490
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
491 text_len = cscf->imap_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
492 text = cscf->imap_capability.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493 break;
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 case NGX_IMAP_LOGOUT:
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
496 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497 text = imap_bye;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498 text_len = sizeof(imap_bye) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
501 case NGX_IMAP_NOOP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
502 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
503
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
504 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
505
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
506 case NGX_IMAP_STARTTLS:
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
507 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
508 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
509 if (sslcf->starttls) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
510 c->read->handler = ngx_imap_starttls_handler;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
511 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
512 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
513 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
514
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
515 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
516 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
517 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
518
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
519 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
520 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
521 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
522 }
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 } else if (rc == NGX_IMAP_NEXT) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
525 last = imap_next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
526 last_len = sizeof(imap_next) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
527 tag = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
528 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
529
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
530 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
531 last = imap_invalid_command;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
532 last_len = sizeof(imap_invalid_command) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
533 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
534
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
535 if (tag) {
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
536 if (s->tag.len == 0) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
537 s->tag.len = sizeof(imap_star) - 1;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
538 s->tag.data = (u_char *) imap_star;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
539 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
540
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
541 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
542 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
543 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
544 if (s->tagged_line.data == NULL) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
548 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
549
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
550 s->out.data = s->tagged_line.data;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
551 s->out.len = s->tag.len + text_len + last_len;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
552
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
553 p = s->out.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
554
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
555 if (text) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
556 p = ngx_cpymem(p, text, text_len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
557 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
558 p = ngx_cpymem(p, s->tag.data, s->tag.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
559 ngx_memcpy(p, last, last_len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
560
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
561
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
562 } else {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
563 s->out.data = last;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
564 s->out.len = last_len;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
565 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
566
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
567 if (rc != NGX_IMAP_NEXT) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
568 s->args.nelts = 0;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
569 s->buffer->pos = s->buffer->start;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
570 s->buffer->last = s->buffer->start;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
571 s->tag.len = 0;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
572 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
573
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
574 ngx_imap_send(c->write);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
575 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
576
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
577
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
578 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 ngx_pop3_auth_state(ngx_event_t *rev)
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 u_char *text;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
582 ssize_t size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
583 ngx_int_t rc;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
584 ngx_str_t *arg;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
585 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587 ngx_imap_core_srv_conf_t *cscf;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
588 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
589 ngx_imap_ssl_conf_t *sslcf;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
590 #endif
76
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 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
593 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
594
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
595 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
596
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
597 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
598 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
599 c->timedout = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
600 ngx_imap_close_connection(c);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
601 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
602 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
603
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
604 if (s->out.len) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
605 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
606 s->blocked = 1;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
607 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
608 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
609
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
610 s->blocked = 0;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
611
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
612 rc = ngx_imap_read_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
613
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
614 if (rc == NGX_AGAIN || rc == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
615 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
616 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
617
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
618 text = pop3_ok;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
619 size = sizeof(pop3_ok) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
620
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
621 if (rc == NGX_OK) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
622 switch (s->imap_state) {
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 case ngx_pop3_start:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
625
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
626 switch (s->command) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
627
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
628 case NGX_POP3_USER:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
629 if (s->args.nelts == 1) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630 s->imap_state = ngx_pop3_user;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
631
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
632 arg = s->args.elts;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
633 s->login.len = arg[0].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
634 s->login.data = ngx_palloc(c->pool, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
635 if (s->login.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
637 return;
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
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
640 ngx_memcpy(s->login.data, arg[0].data, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
641
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
642 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643 "pop3 login: \"%V\"", &s->login);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
644
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
645 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
646 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
647 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
648
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
649 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
651 case NGX_POP3_CAPA:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
652 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
653
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
654 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
655
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
656 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
657 sslcf = ngx_imap_get_module_srv_conf(s,
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
658 ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
659 if (sslcf->starttls) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
660 size = cscf->pop3_starttls_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
661 text = cscf->pop3_starttls_capability.data;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
662 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
663 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
664 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
665 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
666
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
667 size = cscf->pop3_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
668 text = cscf->pop3_capability.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
669 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
670
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
671 case NGX_POP3_QUIT:
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
672 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
673 break;
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 case NGX_POP3_NOOP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
676 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
677
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
678 #if (NGX_IMAP_SSL)
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
679
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
680 case NGX_POP3_STLS:
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
681 if (c->ssl == NULL) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
682 sslcf = ngx_imap_get_module_srv_conf(s,
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
683 ngx_imap_ssl_module);
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
684 if (sslcf->starttls) {
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
685 c->read->handler = ngx_imap_starttls_handler;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
686 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
687 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
688 }
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
689
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
690 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
691 break;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
692 #endif
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
693
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698 }
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 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
701
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
702 case ngx_pop3_user:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
703
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
704 switch (s->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 case NGX_POP3_PASS:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
707 if (s->args.nelts == 1) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
708 /* STUB */ s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
709
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
710 arg = s->args.elts;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
711 s->passwd.len = arg[0].len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
712 s->passwd.data = ngx_palloc(c->pool, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
713 if (s->passwd.data == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
714 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
715 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
716 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
717
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
718 ngx_memcpy(s->passwd.data, arg[0].data, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
719
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
720 #if (NGX_DEBUG_IMAP_PASSWD)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
721 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
722 "pop3 passwd: \"%V\"", &s->passwd);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
723 #endif
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
724
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
725 s->args.nelts = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
726 s->buffer->pos = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727 s->buffer->last = s->buffer->start;
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 if (rev->timer_set) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
730 ngx_del_timer(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731 }
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 ngx_imap_auth_http_init(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
734
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
735 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
736
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
737 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
738 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
739 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
740
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
741 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
742
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
743 case NGX_POP3_CAPA:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
744 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
745 size = cscf->pop3_capability.len;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
746 text = cscf->pop3_capability.data;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
747 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
748
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
749 case NGX_POP3_QUIT:
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
750 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
751 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
752
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
753 case NGX_POP3_NOOP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
754 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
755
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
756 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
757 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
758 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
759 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760 }
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 break;
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 /* suppress warinings */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
765 case ngx_pop3_passwd:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
766 break;
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 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
769
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
770 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
771 text = pop3_invalid_command;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
772 size = sizeof(pop3_invalid_command) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
773 }
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 s->args.nelts = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
776 s->buffer->pos = s->buffer->start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
777 s->buffer->last = s->buffer->start;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
778
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
779 s->out.data = text;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
780 s->out.len = size;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
781
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
782 ngx_imap_send(c->write);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
785
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
786 static ngx_int_t
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
787 ngx_imap_read_command(ngx_imap_session_t *s)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
788 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 ssize_t n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790 ngx_int_t rc;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
791
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
792 n = s->connection->recv(s->connection, s->buffer->last,
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
793 s->buffer->end - s->buffer->last);
76
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 if (n == NGX_ERROR || n == 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
796 ngx_imap_close_connection(s->connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
797 return NGX_ERROR;
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
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
800 if (n > 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
801 s->buffer->last += n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
803
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
804 if (n == NGX_AGAIN) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
805 if (ngx_handle_read_event(s->connection->read, 0) == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
806 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
808 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
809
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
810 return NGX_AGAIN;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
811 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
812
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
813 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814 rc = ngx_pop3_parse_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
816 rc = ngx_imap_parse_command(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
817 }
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 if (rc == NGX_AGAIN
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
820 || rc == NGX_IMAP_NEXT
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
821 || rc == NGX_IMAP_PARSE_INVALID_COMMAND)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
822 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
823 return rc;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824 }
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 if (rc == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
827 ngx_imap_close_connection(s->connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
828 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
829 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
830
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
831 return NGX_OK;
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
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
835 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
836 ngx_imap_session_internal_server_error(ngx_imap_session_t *s)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
837 {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
838 s->out = internal_server_errors[s->protocol];
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
839 s->quit = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
840
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
841 ngx_imap_send(s->connection->write);
76
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
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
845 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
846 ngx_imap_close_connection(ngx_connection_t *c)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848 ngx_pool_t *pool;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
850 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
851 "close imap connection: %d", c->fd);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
852
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
853 #if (NGX_IMAP_SSL)
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
854
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
855 if (c->ssl) {
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
856 if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
857 c->ssl->handler = ngx_imap_close_connection;
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
858 return;
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
859 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
860 }
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
861
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
862 #endif
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
863
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
864 c->destroyed = 1;
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
865
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
866 pool = c->pool;
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 ngx_close_connection(c);
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 ngx_destroy_pool(pool);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
871 }
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
872
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
873
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
874 static u_char *
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
875 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
876 {
116
e38f51cd0905 nginx 0.3.5
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
877 u_char *p;
e38f51cd0905 nginx 0.3.5
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
878 ngx_imap_session_t *s;
e38f51cd0905 nginx 0.3.5
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
879 ngx_imap_log_ctx_t *ctx;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
880
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
881 if (log->action) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
882 p = ngx_snprintf(buf, len, " while %s", log->action);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
883 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
884 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
885 }
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 118
diff changeset
886
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
887 ctx = log->data;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
888
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
889 p = ngx_snprintf(buf, len, ", client: %V", ctx->client);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
890 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
891 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
892
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
893 s = ctx->session;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
894
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
895 if (s == NULL) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
896 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
897 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
898
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
899 p = ngx_snprintf(buf, len, ", server: %V",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
900 &s->connection->listening->addr_text);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
901 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
902 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
903
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
904 if (s->login.len == 0) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
905 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
906 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
907
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
908 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
909 len -= p - buf;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
910 buf = p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
911
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
912 if (s->proxy == NULL) {
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
913 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
914 }
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
915
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
916 p = ngx_snprintf(buf, len, ", upstream: %V",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
917 &s->proxy->upstream.peers->peer[0].name);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
918
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
919 return p;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
920 }