annotate src/mail/ngx_mail_handler.c @ 9292:7654ad1366ef default tip

release-1.27.1 tag
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 04 Jun 2024 16:55:54 +0300
parents 4538c1ffb0f8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 423
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 423
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 3642
diff changeset
4 * Copyright (C) Nginx, Inc.
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 423
diff changeset
5 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 423
diff changeset
6
413
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_event.h>
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
11 #include <ngx_mail.h>
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
12
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
13
7794
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
14 static void ngx_mail_proxy_protocol_handler(ngx_event_t *rev);
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
15 static void ngx_mail_init_session_handler(ngx_event_t *rev);
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
16 static void ngx_mail_init_session(ngx_connection_t *c);
413
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
18 #if (NGX_MAIL_SSL)
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
19 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
20 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c);
5989
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
21 static ngx_int_t ngx_mail_verify_cert(ngx_mail_session_t *s,
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
22 ngx_connection_t *c);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
23 #endif
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
24
413
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
26 void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
27 ngx_mail_init_connection(ngx_connection_t *c)
413
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 {
6130
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
29 size_t len;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
30 ngx_uint_t i;
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
31 ngx_event_t *rev;
6130
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
32 ngx_mail_port_t *port;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
33 struct sockaddr *sa;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
34 struct sockaddr_in *sin;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
35 ngx_mail_log_ctx_t *ctx;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
36 ngx_mail_in_addr_t *addr;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
37 ngx_mail_session_t *s;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
38 ngx_mail_addr_conf_t *addr_conf;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
39 ngx_mail_core_srv_conf_t *cscf;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
40 u_char text[NGX_SOCKADDR_STRLEN];
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
41 #if (NGX_HAVE_INET6)
6130
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
42 struct sockaddr_in6 *sin6;
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
43 ngx_mail_in6_addr_t *addr6;
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
44 #endif
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
45
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
46
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
47 /* find the server configuration for the address:port */
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
48
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
49 port = c->listening->servers;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
50
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
51 if (port->naddrs > 1) {
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
52
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
53 /*
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
54 * There are several addresses on this port and one of them
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
55 * is the "*:port" wildcard so getsockname() is needed to determine
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
56 * the server address.
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
57 *
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
58 * AcceptEx() already gave this address.
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
59 */
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
60
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
61 if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
62 ngx_mail_close_connection(c);
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
63 return;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
64 }
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
65
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
66 sa = c->local_sockaddr;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
67
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
68 switch (sa->sa_family) {
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
69
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
70 #if (NGX_HAVE_INET6)
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
71 case AF_INET6:
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
72 sin6 = (struct sockaddr_in6 *) sa;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
73
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
74 addr6 = port->addrs;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
75
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
76 /* the last address is "*" */
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
77
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
78 for (i = 0; i < port->naddrs - 1; i++) {
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
79 if (ngx_memcmp(&addr6[i].addr6, &sin6->sin6_addr, 16) == 0) {
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
80 break;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
81 }
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
82 }
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
83
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
84 addr_conf = &addr6[i].conf;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
85
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
86 break;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
87 #endif
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
88
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
89 default: /* AF_INET */
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
90 sin = (struct sockaddr_in *) sa;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
91
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
92 addr = port->addrs;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
93
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
94 /* the last address is "*" */
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
95
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
96 for (i = 0; i < port->naddrs - 1; i++) {
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
97 if (addr[i].addr == sin->sin_addr.s_addr) {
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
98 break;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
99 }
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
100 }
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
101
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
102 addr_conf = &addr[i].conf;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
103
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
104 break;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
105 }
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
106
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
107 } else {
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
108 switch (c->local_sockaddr->sa_family) {
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
109
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
110 #if (NGX_HAVE_INET6)
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
111 case AF_INET6:
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
112 addr6 = port->addrs;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
113 addr_conf = &addr6[0].conf;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
114 break;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
115 #endif
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
116
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
117 default: /* AF_INET */
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
118 addr = port->addrs;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
119 addr_conf = &addr[0].conf;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
120 break;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
121 }
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
122 }
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
123
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
124 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t));
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
125 if (s == NULL) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
126 ngx_mail_close_connection(c);
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
127 return;
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
128 }
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
129
5819
8e7ee4c70a3c Mail: initialize the "signature" field of ngx_mail_session_t.
Valentin Bartenev <vbart@nginx.com>
parents: 5705
diff changeset
130 s->signature = NGX_MAIL_MODULE;
8e7ee4c70a3c Mail: initialize the "signature" field of ngx_mail_session_t.
Valentin Bartenev <vbart@nginx.com>
parents: 5705
diff changeset
131
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
132 s->main_conf = addr_conf->ctx->main_conf;
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
133 s->srv_conf = addr_conf->ctx->srv_conf;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
134
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
135 #if (NGX_MAIL_SSL)
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
136 s->ssl = addr_conf->ssl;
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
137 #endif
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
138
2855
a96a8c916b0c mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents: 2798
diff changeset
139 s->addr_text = &addr_conf->addr_text;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
140
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
141 c->data = s;
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
142 s->connection = c;
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
143
6130
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
144 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
145
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
146 ngx_set_connection_log(c, cscf->error_log);
fc99323a3d79 Mail: error_log support.
Vladimir Homutov <vl@nginx.com>
parents: 5989
diff changeset
147
5705
d5b8ee9f2201 Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents: 5632
diff changeset
148 len = ngx_sock_ntop(c->sockaddr, c->socklen, text, NGX_SOCKADDR_STRLEN, 1);
d5b8ee9f2201 Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents: 5632
diff changeset
149
d5b8ee9f2201 Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents: 5632
diff changeset
150 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %*s connected to %V",
d5b8ee9f2201 Mail: output client port number on client connects (ticket #531).
Ruslan Ermilov <ru@nginx.com>
parents: 5632
diff changeset
151 c->number, len, text, s->addr_text);
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
152
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
153 ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t));
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
154 if (ctx == NULL) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
155 ngx_mail_close_connection(c);
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
156 return;
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
157 }
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
158
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
159 ctx->client = &c->addr_text;
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
160 ctx->session = s;
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
161
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
162 c->log->connection = c->number;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
163 c->log->handler = ngx_mail_log_error;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
164 c->log->data = ctx;
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
165 c->log->action = "sending client greeting line";
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
166
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
167 c->log_error = NGX_ERROR_INFO;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
168
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
169 rev = c->read;
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
170 rev->handler = ngx_mail_init_session_handler;
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
171
7794
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
172 if (addr_conf->proxy_protocol) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
173 c->log->action = "reading PROXY protocol";
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
174
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
175 rev->handler = ngx_mail_proxy_protocol_handler;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
176
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
177 if (!rev->ready) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
178 ngx_add_timer(rev, cscf->timeout);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
179
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
180 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
181 ngx_mail_close_connection(c);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
182 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
183
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
184 return;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
185 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
186 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
187
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
188 if (ngx_use_accept_mutex) {
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
189 ngx_post_event(rev, &ngx_posted_events);
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
190 return;
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
191 }
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
192
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
193 rev->handler(rev);
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
194 }
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
195
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
196
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
197 static void
7794
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
198 ngx_mail_proxy_protocol_handler(ngx_event_t *rev)
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
199 {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
200 u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER];
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
201 size_t size;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
202 ssize_t n;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
203 ngx_err_t err;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
204 ngx_connection_t *c;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
205 ngx_mail_session_t *s;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
206 ngx_mail_core_srv_conf_t *cscf;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
207
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
208 c = rev->data;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
209 s = c->data;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
210
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
211 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0,
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
212 "mail PROXY protocol handler");
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
213
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
214 if (rev->timedout) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
215 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
216 c->timedout = 1;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
217 ngx_mail_close_connection(c);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
218 return;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
219 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
220
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
221 n = recv(c->fd, (char *) buf, sizeof(buf), MSG_PEEK);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
222
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
223 err = ngx_socket_errno;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
224
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
225 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "recv(): %z", n);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
226
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
227 if (n == -1) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
228 if (err == NGX_EAGAIN) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
229 rev->ready = 0;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
230
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
231 if (!rev->timer_set) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
232 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
233 ngx_add_timer(rev, cscf->timeout);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
234 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
235
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
236 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
237 ngx_mail_close_connection(c);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
238 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
239
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
240 return;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
241 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
242
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
243 ngx_connection_error(c, err, "recv() failed");
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
244
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
245 ngx_mail_close_connection(c);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
246 return;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
247 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
248
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
249 p = ngx_proxy_protocol_read(c, buf, buf + n);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
250
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
251 if (p == NULL) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
252 ngx_mail_close_connection(c);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
253 return;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
254 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
255
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
256 size = p - buf;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
257
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
258 if (c->recv(c, buf, size) != (ssize_t) size) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
259 ngx_mail_close_connection(c);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
260 return;
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
261 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
262
7795
ef4bdbbce57e Mail: realip module.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7794
diff changeset
263 if (ngx_mail_realip_handler(s) != NGX_OK) {
ef4bdbbce57e Mail: realip module.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7794
diff changeset
264 ngx_mail_close_connection(c);
ef4bdbbce57e Mail: realip module.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7794
diff changeset
265 return;
ef4bdbbce57e Mail: realip module.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7794
diff changeset
266 }
ef4bdbbce57e Mail: realip module.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7794
diff changeset
267
7794
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
268 ngx_mail_init_session_handler(rev);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
269 }
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
270
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
271
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
272 static void
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
273 ngx_mail_init_session_handler(ngx_event_t *rev)
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
274 {
7801
777373b5a169 Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7795
diff changeset
275 ngx_connection_t *c;
7791
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
276
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
277 c = rev->data;
d84f13618277 Mail: postponed session initialization under accept mutex.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7790
diff changeset
278
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
279 #if (NGX_MAIL_SSL)
1704
e584e946e198 move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents: 1494
diff changeset
280 {
7801
777373b5a169 Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7795
diff changeset
281 ngx_mail_session_t *s;
1704
e584e946e198 move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents: 1494
diff changeset
282 ngx_mail_ssl_conf_t *sslcf;
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
283
7801
777373b5a169 Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7795
diff changeset
284 s = c->data;
777373b5a169 Mail: fixed build without SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7795
diff changeset
285
9120
0aaa09927703 SSL: removed the "ssl" directive.
Roman Arutyunyan <arut@nginx.com>
parents: 7844
diff changeset
286 if (s->ssl) {
0aaa09927703 SSL: removed the "ssl" directive.
Roman Arutyunyan <arut@nginx.com>
parents: 7844
diff changeset
287 c->log->action = "SSL handshaking";
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
288
9120
0aaa09927703 SSL: removed the "ssl" directive.
Roman Arutyunyan <arut@nginx.com>
parents: 7844
diff changeset
289 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
2224
109849282793 *) listen ssl
Igor Sysoev <igor@sysoev.ru>
parents: 2165
diff changeset
290
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
291 ngx_mail_ssl_init_connection(&sslcf->ssl, c);
547
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
292 return;
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
293 }
2224
109849282793 *) listen ssl
Igor Sysoev <igor@sysoev.ru>
parents: 2165
diff changeset
294
1704
e584e946e198 move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents: 1494
diff changeset
295 }
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
296 #endif
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
297
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
298 ngx_mail_init_session(c);
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
299 }
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
300
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
301
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
302 #if (NGX_MAIL_SSL)
547
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
303
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
304 void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
305 ngx_mail_starttls_handler(ngx_event_t *rev)
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
306 {
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
307 ngx_connection_t *c;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
308 ngx_mail_session_t *s;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
309 ngx_mail_ssl_conf_t *sslcf;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
310
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
311 c = rev->data;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
312 s = c->data;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
313 s->starttls = 1;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
314
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
315 c->log->action = "in starttls state";
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
316
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
317 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
318
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
319 ngx_mail_ssl_init_connection(&sslcf->ssl, c);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
320 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
321
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
322
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
323 static void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
324 ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c)
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
325 {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
326 ngx_mail_session_t *s;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
327 ngx_mail_core_srv_conf_t *cscf;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
328
7009
03444167a3bb Style: changed checks of ngx_ssl_create_connection() to != NGX_OK.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6774
diff changeset
329 if (ngx_ssl_create_connection(ssl, c, 0) != NGX_OK) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
330 ngx_mail_close_connection(c);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
331 return;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
332 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
333
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
334 if (ngx_ssl_handshake(c) == NGX_AGAIN) {
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
335
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
336 s = c->data;
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
337
7794
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
338 if (!c->read->timer_set) {
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
339 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
340 ngx_add_timer(c->read, cscf->timeout);
12ea1de7d87c Mail: parsing of the PROXY protocol from clients.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7792
diff changeset
341 }
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
342
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
343 c->ssl->handler = ngx_mail_ssl_handshake_handler;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
344
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
345 return;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
346 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
347
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
348 ngx_mail_ssl_handshake_handler(c);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
349 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
350
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
351
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
352 static void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
353 ngx_mail_ssl_handshake_handler(ngx_connection_t *c)
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
354 {
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
355 ngx_mail_session_t *s;
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
356 ngx_mail_core_srv_conf_t *cscf;
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
357
547
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
358 if (c->ssl->handshaked) {
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
359
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
360 s = c->data;
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
361
5989
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
362 if (ngx_mail_verify_cert(s, c) != NGX_OK) {
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
363 return;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
364 }
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
365
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
366 if (s->starttls) {
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
367 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
368
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
369 c->read->handler = cscf->protocol->init_protocol;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
370 c->write->handler = ngx_mail_send;
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
371
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
372 cscf->protocol->init_protocol(c->read);
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
373
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
374 return;
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
375 }
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
376
2165
cbf6f2eb57ad backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
377 c->read->ready = 0;
cbf6f2eb57ad backout both r2162 and r2128 and implement a new fix
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
378
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
379 ngx_mail_init_session(c);
547
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
380 return;
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
381 }
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
382
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
383 ngx_mail_close_connection(c);
547
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
384 }
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
385
5989
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
386
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
387 static ngx_int_t
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
388 ngx_mail_verify_cert(ngx_mail_session_t *s, ngx_connection_t *c)
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
389 {
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
390 long rc;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
391 X509 *cert;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
392 ngx_mail_ssl_conf_t *sslcf;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
393 ngx_mail_core_srv_conf_t *cscf;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
394
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
395 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
396
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
397 if (!sslcf->verify) {
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
398 return NGX_OK;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
399 }
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
400
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
401 rc = SSL_get_verify_result(c->ssl->connection);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
402
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
403 if (rc != X509_V_OK
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
404 && (sslcf->verify != 3 || !ngx_ssl_verify_error_optional(rc)))
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
405 {
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
406 ngx_log_error(NGX_LOG_INFO, c->log, 0,
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
407 "client SSL certificate verify error: (%l:%s)",
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
408 rc, X509_verify_cert_error_string(rc));
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
409
7193
9d14931cec8c SSL: using default server context in session remove (closes #1464).
Sergey Kandaurov <pluknet@nginx.com>
parents: 7009
diff changeset
410 ngx_ssl_remove_cached_session(c->ssl->session_ctx,
5989
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
411 (SSL_get0_session(c->ssl->connection)));
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
412
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
413 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
414
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
415 s->out = cscf->protocol->cert_error;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
416 s->quit = 1;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
417
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
418 c->write->handler = ngx_mail_send;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
419
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
420 ngx_mail_send(s->connection->write);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
421 return NGX_ERROR;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
422 }
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
423
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
424 if (sslcf->verify == 1) {
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
425 cert = SSL_get_peer_certificate(c->ssl->connection);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
426
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
427 if (cert == NULL) {
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
428 ngx_log_error(NGX_LOG_INFO, c->log, 0,
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
429 "client sent no required SSL certificate");
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
430
7193
9d14931cec8c SSL: using default server context in session remove (closes #1464).
Sergey Kandaurov <pluknet@nginx.com>
parents: 7009
diff changeset
431 ngx_ssl_remove_cached_session(c->ssl->session_ctx,
5989
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
432 (SSL_get0_session(c->ssl->connection)));
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
433
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
434 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
435
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
436 s->out = cscf->protocol->no_cert;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
437 s->quit = 1;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
438
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
439 c->write->handler = ngx_mail_send;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
440
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
441 ngx_mail_send(s->connection->write);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
442 return NGX_ERROR;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
443 }
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
444
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
445 X509_free(cert);
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
446 }
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
447
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
448 return NGX_OK;
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
449 }
ec01b1d1fff1 Mail: client SSL certificates support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5819
diff changeset
450
547
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
451 #endif
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
452
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
453
818fbd4750b9 nginx-0.2.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
454 static void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
455 ngx_mail_init_session(ngx_connection_t *c)
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
456 {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
457 ngx_mail_session_t *s;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
458 ngx_mail_core_srv_conf_t *cscf;
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
459
641
5e8fb59c18c1 nginx-0.3.42-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 583
diff changeset
460 s = c->data;
413
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461
7792
adee10c7fac8 Mail: fixed log action after SSL handshake.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7791
diff changeset
462 c->log->action = "sending client greeting line";
adee10c7fac8 Mail: fixed log action after SSL handshake.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7791
diff changeset
463
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
464 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
465
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
466 s->protocol = cscf->protocol->type;
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
467
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
468 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
469 if (s->ctx == NULL) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
470 ngx_mail_session_internal_server_error(s);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
471 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
472 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
473
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
474 c->write->handler = ngx_mail_send;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
475
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
476 cscf->protocol->init_session(s, c);
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
477 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
478
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
479
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
480 ngx_int_t
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
481 ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
482 ngx_mail_core_srv_conf_t *cscf)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
483 {
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
484 s->salt.data = ngx_pnalloc(c->pool,
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
485 sizeof(" <18446744073709551616.@>" CRLF) - 1
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
486 + NGX_TIME_T_LEN
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
487 + cscf->server_name.len);
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
488 if (s->salt.data == NULL) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
489 return NGX_ERROR;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
490 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
491
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
492 s->salt.len = ngx_sprintf(s->salt.data, "<%ul.%T@%V>" CRLF,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
493 ngx_random(), ngx_time(), &cscf->server_name)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
494 - s->salt.data;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
495
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
496 return NGX_OK;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
497 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
498
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
499
1479
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
500 #if (NGX_MAIL_SSL)
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
501
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
502 ngx_int_t
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
503 ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c)
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
504 {
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
505 ngx_mail_ssl_conf_t *sslcf;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
506
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
507 if (c->ssl) {
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
508 return 0;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
509 }
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
510
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
511 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
512
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
513 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) {
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
514 return 1;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
515 }
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
516
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
517 return 0;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
518 }
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
519
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
520 #endif
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
521
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
522
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
523 ngx_int_t
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
524 ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
525 {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
526 u_char *p, *last;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
527 ngx_str_t *arg, plain;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
528
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
529 arg = s->args.elts;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
530
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
531 #if (NGX_DEBUG_MAIL_PASSWD)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
532 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
533 "mail auth plain: \"%V\"", &arg[n]);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
534 #endif
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
535
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
536 plain.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
3642
ac33852faaac style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2951
diff changeset
537 if (plain.data == NULL) {
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
538 return NGX_ERROR;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
539 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
540
1494
6535fb51976a fix "AUTH PLAIN [initial-response]" bug introduced in r1477
Igor Sysoev <igor@sysoev.ru>
parents: 1491
diff changeset
541 if (ngx_decode_base64(&plain, &arg[n]) != NGX_OK) {
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
542 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
543 "client sent invalid base64 encoding in AUTH PLAIN command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
544 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
545 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
546
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
547 p = plain.data;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
548 last = p + plain.len;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
549
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
550 while (p < last && *p++) { /* void */ }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
551
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
552 if (p == last) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
553 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
554 "client sent invalid login in AUTH PLAIN command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
555 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
556 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
557
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
558 s->login.data = p;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
559
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
560 while (p < last && *p) { p++; }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
561
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
562 if (p == last) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
563 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
564 "client sent invalid password in AUTH PLAIN command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
565 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
566 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
567
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
568 s->login.len = p++ - s->login.data;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
569
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
570 s->passwd.len = last - p;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
571 s->passwd.data = p;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
572
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
573 #if (NGX_DEBUG_MAIL_PASSWD)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
574 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
575 "mail auth plain: \"%V\" \"%V\"", &s->login, &s->passwd);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
576 #endif
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
577
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
578 return NGX_DONE;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
579 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
580
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
581
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
582 ngx_int_t
2495
a59b26eee816 compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
583 ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c,
a59b26eee816 compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
584 ngx_uint_t n)
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
585 {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
586 ngx_str_t *arg;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
587
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
588 arg = s->args.elts;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
589
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
590 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
2495
a59b26eee816 compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
591 "mail auth login username: \"%V\"", &arg[n]);
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
592
2495
a59b26eee816 compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
593 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
3642
ac33852faaac style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2951
diff changeset
594 if (s->login.data == NULL) {
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
595 return NGX_ERROR;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
596 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
597
2495
a59b26eee816 compatibility with Microsoft's
Igor Sysoev <igor@sysoev.ru>
parents: 2388
diff changeset
598 if (ngx_decode_base64(&s->login, &arg[n]) != NGX_OK) {
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
599 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
600 "client sent invalid base64 encoding in AUTH LOGIN command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
601 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
602 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
603
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
604 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
605 "mail auth login username: \"%V\"", &s->login);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
606
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
607 return NGX_OK;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
608 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
609
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
610
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
611 ngx_int_t
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
612 ngx_mail_auth_login_password(ngx_mail_session_t *s, ngx_connection_t *c)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
613 {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
614 ngx_str_t *arg;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
615
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
616 arg = s->args.elts;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
617
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
618 #if (NGX_DEBUG_MAIL_PASSWD)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
619 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
620 "mail auth login password: \"%V\"", &arg[0]);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
621 #endif
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
622
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
623 s->passwd.data = ngx_pnalloc(c->pool,
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
624 ngx_base64_decoded_length(arg[0].len));
3642
ac33852faaac style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2951
diff changeset
625 if (s->passwd.data == NULL) {
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
626 return NGX_ERROR;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
627 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
628
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
629 if (ngx_decode_base64(&s->passwd, &arg[0]) != NGX_OK) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
630 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
631 "client sent invalid base64 encoding in AUTH LOGIN command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
632 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
633 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
634
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
635 #if (NGX_DEBUG_MAIL_PASSWD)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
636 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
637 "mail auth login password: \"%V\"", &s->passwd);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
638 #endif
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
639
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
640 return NGX_DONE;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
641 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
642
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
643
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
644 ngx_int_t
1479
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
645 ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, ngx_connection_t *c,
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
646 char *prefix, size_t len)
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
647 {
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
648 u_char *p;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
649 ngx_str_t salt;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
650 ngx_uint_t n;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
651
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
652 p = ngx_pnalloc(c->pool, len + ngx_base64_encoded_length(s->salt.len) + 2);
1479
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
653 if (p == NULL) {
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
654 return NGX_ERROR;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
655 }
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
656
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
657 salt.data = ngx_cpymem(p, prefix, len);
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
658 s->salt.len -= 2;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
659
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
660 ngx_encode_base64(&salt, &s->salt);
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
661
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
662 s->salt.len += 2;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
663 n = len + salt.len;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
664 p[n++] = CR; p[n++] = LF;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
665
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
666 s->out.len = n;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
667 s->out.data = p;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
668
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
669 return NGX_OK;
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
670 }
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
671
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
672
2647950e047f optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1477
diff changeset
673 ngx_int_t
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
674 ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c)
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
675 {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
676 u_char *p, *last;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
677 ngx_str_t *arg;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
678
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
679 arg = s->args.elts;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
680
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
681 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
682 "mail auth cram-md5: \"%V\"", &arg[0]);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
683
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1704
diff changeset
684 s->login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len));
3642
ac33852faaac style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2951
diff changeset
685 if (s->login.data == NULL) {
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
686 return NGX_ERROR;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
687 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
688
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
689 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
690 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
691 "client sent invalid base64 encoding in AUTH CRAM-MD5 command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
692 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
693 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
694
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
695 p = s->login.data;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
696 last = p + s->login.len;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
697
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
698 while (p < last) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
699 if (*p++ == ' ') {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
700 s->login.len = p - s->login.data - 1;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
701 s->passwd.len = last - p;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
702 s->passwd.data = p;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
703 break;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
704 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
705 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
706
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
707 if (s->passwd.len != 32) {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
708 ngx_log_error(NGX_LOG_INFO, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
709 "client sent invalid CRAM-MD5 hash in AUTH CRAM-MD5 command");
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
710 return NGX_MAIL_PARSE_INVALID_COMMAND;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
711 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
712
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
713 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
714 "mail auth cram-md5: \"%V\" \"%V\"", &s->login, &s->passwd);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
715
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
716 s->auth_method = NGX_MAIL_AUTH_CRAM_MD5;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
717
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
718 return NGX_DONE;
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
719 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
720
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
721
6774
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
722 ngx_int_t
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
723 ngx_mail_auth_external(ngx_mail_session_t *s, ngx_connection_t *c,
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
724 ngx_uint_t n)
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
725 {
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
726 ngx_str_t *arg, external;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
727
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
728 arg = s->args.elts;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
729
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
730 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
731 "mail auth external: \"%V\"", &arg[n]);
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
732
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
733 external.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
734 if (external.data == NULL) {
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
735 return NGX_ERROR;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
736 }
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
737
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
738 if (ngx_decode_base64(&external, &arg[n]) != NGX_OK) {
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
739 ngx_log_error(NGX_LOG_INFO, c->log, 0,
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
740 "client sent invalid base64 encoding in AUTH EXTERNAL command");
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
741 return NGX_MAIL_PARSE_INVALID_COMMAND;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
742 }
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
743
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
744 s->login.len = external.len;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
745 s->login.data = external.data;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
746
9288
f83cb031a4a4 Mail: fixed EXTERNAL auth to clear s->passwd.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9236
diff changeset
747 ngx_str_null(&s->passwd);
f83cb031a4a4 Mail: fixed EXTERNAL auth to clear s->passwd.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9236
diff changeset
748
6774
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
749 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
750 "mail auth external: \"%V\"", &s->login);
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
751
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
752 s->auth_method = NGX_MAIL_AUTH_EXTERNAL;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
753
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
754 return NGX_DONE;
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
755 }
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
756
bcb107bb89cd Mail: support SASL EXTERNAL (RFC 4422).
Rob N ★ <robn@fastmail.com>
parents: 6130
diff changeset
757
9290
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
758 ngx_int_t
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
759 ngx_mail_auth_xoauth2(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
760 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
761 u_char *p, *last;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
762 ngx_str_t *arg, oauth;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
763
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
764 arg = s->args.elts;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
765
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
766 if (s->auth_err.len) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
767 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
768 "mail auth xoauth2 cancel");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
769
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
770 if (s->args.nelts == 1 && arg[0].len == 0) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
771 s->out = s->auth_err;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
772 s->quit = s->auth_quit;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
773 s->state = 0;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
774 s->mail_state = 0;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
775 ngx_str_null(&s->auth_err);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
776 return NGX_OK;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
777 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
778
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
779 s->quit = s->auth_quit;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
780 ngx_str_null(&s->auth_err);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
781
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
782 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
783 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
784
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
785 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
786 "mail auth xoauth2: \"%V\"", &arg[n]);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
787
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
788 oauth.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
789 if (oauth.data == NULL) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
790 return NGX_ERROR;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
791 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
792
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
793 if (ngx_decode_base64(&oauth, &arg[n]) != NGX_OK) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
794 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
795 "client sent invalid base64 encoding in "
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
796 "AUTH XOAUTH2 command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
797 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
798 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
799
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
800 /*
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
801 * https://developers.google.com/gmail/imap/xoauth2-protocol
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
802 * "user=" {User} "^Aauth=Bearer " {token} "^A^A"
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
803 */
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
804
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
805 p = oauth.data;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
806 last = p + oauth.len;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
807
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
808 while (p < last) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
809 if (*p++ == '\1') {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
810 s->login.len = p - oauth.data - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
811 s->login.data = oauth.data;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
812 s->passwd.len = last - p;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
813 s->passwd.data = p;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
814 break;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
815 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
816 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
817
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
818 if (s->login.len < sizeof("user=") - 1
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
819 || ngx_strncasecmp(s->login.data, (u_char *) "user=",
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
820 sizeof("user=") - 1)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
821 != 0)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
822 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
823 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
824 "client sent invalid login in AUTH XOAUTH2 command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
825 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
826 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
827
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
828 s->login.len -= sizeof("user=") - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
829 s->login.data += sizeof("user=") - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
830
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
831 if (s->passwd.len < sizeof("auth=Bearer ") - 1
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
832 || ngx_strncasecmp(s->passwd.data, (u_char *) "auth=Bearer ",
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
833 sizeof("auth=Bearer ") - 1)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
834 != 0)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
835 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
836 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
837 "client sent invalid token in AUTH XOAUTH2 command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
838 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
839 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
840
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
841 s->passwd.len -= sizeof("auth=Bearer ") - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
842 s->passwd.data += sizeof("auth=Bearer ") - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
843
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
844 if (s->passwd.len < 2
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
845 || s->passwd.data[s->passwd.len - 2] != '\1'
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
846 || s->passwd.data[s->passwd.len - 1] != '\1')
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
847 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
848 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
849 "client sent invalid token in AUTH XOAUTH2 command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
850 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
851 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
852
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
853 s->passwd.len -= 2;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
854
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
855 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
856 "mail auth xoauth2: \"%V\" \"%V\"", &s->login, &s->passwd);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
857
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
858 s->auth_method = NGX_MAIL_AUTH_XOAUTH2;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
859
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
860 return NGX_DONE;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
861 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
862
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
863
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
864 ngx_int_t
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
865 ngx_mail_auth_oauthbearer(ngx_mail_session_t *s, ngx_connection_t *c,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
866 ngx_uint_t n)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
867 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
868 u_char *p, *d, *last, *prev;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
869 ngx_str_t *arg, oauth;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
870
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
871 arg = s->args.elts;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
872
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
873 if (s->auth_err.len) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
874 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
875 "mail auth oauthbearer cancel");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
876
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
877 if (s->args.nelts == 1
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
878 && ngx_strncmp(arg[0].data, (u_char *) "AQ==", 4) == 0)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
879 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
880 s->out = s->auth_err;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
881 s->quit = s->auth_quit;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
882 s->state = 0;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
883 s->mail_state = 0;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
884 ngx_str_null(&s->auth_err);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
885 return NGX_OK;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
886 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
887
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
888 s->quit = s->auth_quit;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
889 ngx_str_null(&s->auth_err);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
890
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
891 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
892 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
893
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
894 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
895 "mail auth oauthbearer: \"%V\"", &arg[n]);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
896
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
897 oauth.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
898 if (oauth.data == NULL) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
899 return NGX_ERROR;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
900 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
901
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
902 if (ngx_decode_base64(&oauth, &arg[n]) != NGX_OK) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
903 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
904 "client sent invalid base64 encoding in "
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
905 "AUTH OAUTHBEARER command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
906 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
907 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
908
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
909 /*
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
910 * RFC 7628
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
911 * "n,a=user@example.com,^A...^Aauth=Bearer <token>^A^A"
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
912 */
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
913
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
914 p = oauth.data;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
915 last = p + oauth.len;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
916
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
917 s->login.len = 0;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
918 prev = NULL;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
919
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
920 while (p < last) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
921 if (*p == ',') {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
922 if (prev
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
923 && (size_t) (p - prev) > sizeof("a=") - 1
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
924 && ngx_strncasecmp(prev, (u_char *) "a=", sizeof("a=") - 1)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
925 == 0)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
926 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
927 s->login.len = p - prev - (sizeof("a=") - 1);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
928 s->login.data = prev + sizeof("a=") - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
929 break;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
930 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
931
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
932 p++;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
933 prev = p;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
934 continue;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
935 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
936
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
937 if (*p == '\1') {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
938 break;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
939 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
940
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
941 p++;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
942 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
943
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
944 if (s->login.len == 0) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
945 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
946 "client sent invalid login in AUTH OAUTHBEARER command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
947 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
948 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
949
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
950 s->passwd.len = 0;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
951 prev = NULL;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
952
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
953 while (p < last) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
954 if (*p == '\1') {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
955 if (prev
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
956 && (size_t) (p - prev) > sizeof("auth=Bearer ") - 1
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
957 && ngx_strncasecmp(prev, (u_char *) "auth=Bearer ",
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
958 sizeof("auth=Bearer ") - 1)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
959 == 0)
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
960 {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
961 s->passwd.len = p - prev - (sizeof("auth=Bearer ") - 1);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
962 s->passwd.data = prev + sizeof("auth=Bearer ") - 1;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
963 break;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
964 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
965
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
966 p++;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
967 prev = p;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
968 continue;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
969 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
970
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
971 p++;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
972 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
973
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
974 if (s->passwd.len == 0) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
975 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
976 "client sent invalid token in AUTH OAUTHBEARER command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
977 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
978 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
979
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
980 /* decode =2C =3D in login */
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
981
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
982 p = s->login.data;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
983 d = s->login.data;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
984 last = s->login.data + s->login.len;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
985
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
986 while (p < last) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
987 if (*p == '=') {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
988
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
989 /*
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
990 * login is always followed by other data,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
991 * so p[1] and p[2] can be checked directly
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
992 */
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
993
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
994 if (p[1] == '2' && (p[2] == 'C' || p[2] == 'c')) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
995 *d++ = ',';
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
996
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
997 } else if (p[1] == '3' && (p[2] == 'D' || p[2] == 'd')) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
998 *d++ = '=';
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
999
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1000 } else {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1001 ngx_log_error(NGX_LOG_INFO, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1002 "client sent invalid login in "
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1003 "AUTH OAUTHBEARER command");
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1004 return NGX_MAIL_PARSE_INVALID_COMMAND;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1005 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1006
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1007 p += 3;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1008 continue;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1009 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1010
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1011 *d++ = *p++;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1012 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1013
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1014 s->login.len = d - s->login.data;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1015
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1016 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1017 "mail auth oauthbearer: \"%V\" \"%V\"",
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1018 &s->login, &s->passwd);
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1019
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1020 s->auth_method = NGX_MAIL_AUTH_OAUTHBEARER;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1021
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1022 return NGX_DONE;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1023 }
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1024
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1025
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1026 void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1027 ngx_mail_send(ngx_event_t *wev)
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1028 {
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1029 ngx_int_t n;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1030 ngx_connection_t *c;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1031 ngx_mail_session_t *s;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1032 ngx_mail_core_srv_conf_t *cscf;
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1033
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1034 c = wev->data;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1035 s = c->data;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1036
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1037 if (wev->timedout) {
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1038 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1039 c->timedout = 1;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1040 ngx_mail_close_connection(c);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1041 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1042 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1043
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1044 if (s->out.len == 0) {
2388
722b5aff05ae use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents: 2224
diff changeset
1045 if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1046 ngx_mail_close_connection(c);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1047 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1048
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1049 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1050 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1051
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1052 n = c->send(c, s->out.data, s->out.len);
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1053
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1054 if (n > 0) {
5632
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1055 s->out.data += n;
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1056 s->out.len -= n;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1057
5632
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1058 if (s->out.len != 0) {
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1059 goto again;
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1060 }
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1061
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1062 if (wev->timer_set) {
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1063 ngx_del_timer(wev);
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1064 }
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1065
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1066 if (s->quit) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1067 ngx_mail_close_connection(c);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1068 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1069 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1070
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1071 if (s->blocked) {
9233
9ca12c957304 Mail: switched to posted events when resuming reading.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9120
diff changeset
1072 ngx_post_event(c->read, &ngx_posted_events);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1073 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1074
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1075 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1076 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1077
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1078 if (n == NGX_ERROR) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1079 ngx_mail_close_connection(c);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1080 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1081 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1082
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1083 /* n == NGX_AGAIN */
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1084
5632
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1085 again:
b42e7c790b81 Mail: fixed ngx_mail_send() (ticket #519).
Maxim Dounin <mdounin@mdounin.ru>
parents: 5600
diff changeset
1086
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1087 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1088
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1089 ngx_add_timer(c->write, cscf->timeout);
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1090
2388
722b5aff05ae use "!= NGX_OK" instead of "== NGX_ERROR"
Igor Sysoev <igor@sysoev.ru>
parents: 2224
diff changeset
1091 if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1092 ngx_mail_close_connection(c);
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1093 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1094 }
413
de9d4726e28a nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1095 }
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
1096
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
1097
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1098 ngx_int_t
1482
4606dce4f416 optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1480
diff changeset
1099 ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c)
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1100 {
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1101 ssize_t n;
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1102 ngx_int_t rc;
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1103 ngx_str_t l;
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1104 ngx_mail_core_srv_conf_t *cscf;
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1105
7829
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1106 if (s->buffer->last < s->buffer->end) {
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1107
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1108 n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1109
7829
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1110 if (n == NGX_ERROR || n == 0) {
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1111 ngx_mail_close_connection(c);
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1112 return NGX_ERROR;
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1113 }
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1114
7829
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1115 if (n > 0) {
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1116 s->buffer->last += n;
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1117 }
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1118
7829
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1119 if (n == NGX_AGAIN) {
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1120 if (s->buffer->pos == s->buffer->last) {
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1121 return NGX_AGAIN;
2851e4c7de03 Mail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin <mdounin@mdounin.ru>
parents: 7801
diff changeset
1122 }
5398
04e43d03e153 Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4818
diff changeset
1123 }
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1124 }
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1125
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1126 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1127
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1128 rc = cscf->protocol->parse_command(s);
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1129
1108
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1130 if (rc == NGX_AGAIN) {
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1131
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1132 if (s->buffer->last < s->buffer->end) {
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1133 return rc;
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1134 }
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1135
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1136 l.len = s->buffer->last - s->buffer->start;
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1137 l.data = s->buffer->start;
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1138
1482
4606dce4f416 optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1480
diff changeset
1139 ngx_log_error(NGX_LOG_INFO, c->log, 0,
1108
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1140 "client sent too long command \"%V\"", &l);
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1141
1111
b0fc4af1f196 close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1108
diff changeset
1142 s->quit = 1;
b0fc4af1f196 close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1108
diff changeset
1143
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1144 return NGX_MAIL_PARSE_INVALID_COMMAND;
1108
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1145 }
109e8c7d7cc1 return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents: 1107
diff changeset
1146
7844
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1147 if (rc == NGX_MAIL_PARSE_INVALID_COMMAND) {
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1148
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1149 s->errors++;
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1150
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1151 if (s->errors >= cscf->max_errors) {
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1152 ngx_log_error(NGX_LOG_INFO, c->log, 0,
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1153 "client sent too many invalid commands");
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1154 s->quit = 1;
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1155 }
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1156
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1157 return rc;
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1158 }
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1159
ec1071830799 Mail: max_errors directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7829
diff changeset
1160 if (rc == NGX_IMAP_NEXT) {
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1161 return rc;
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1162 }
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1163
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1164 if (rc == NGX_ERROR) {
1482
4606dce4f416 optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1480
diff changeset
1165 ngx_mail_close_connection(c);
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1166 return NGX_ERROR;
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1167 }
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1168
9236
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1169 s->commands++;
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1170
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1171 if (s->commands > cscf->max_commands) {
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1172
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1173 ngx_log_error(NGX_LOG_INFO, c->log, 0,
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1174 "client sent too many commands");
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1175
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1176 s->quit = 1;
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1177
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1178 return NGX_MAIL_PARSE_INVALID_COMMAND;
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1179 }
d9a52ebb9b00 Mail: max_commands directive.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9233
diff changeset
1180
420
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1181 return NGX_OK;
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1182 }
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1183
33a8253115b4 nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
1184
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
1185 void
1482
4606dce4f416 optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1480
diff changeset
1186 ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c)
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1187 {
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1188 s->args.nelts = 0;
5398
04e43d03e153 Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4818
diff changeset
1189
9290
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1190 if (s->state) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1191 /* preserve tag */
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1192 s->arg_start = s->buffer->pos;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1193
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1194 } else {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1195 if (s->buffer->pos == s->buffer->last) {
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1196 s->buffer->pos = s->buffer->start;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1197 s->buffer->last = s->buffer->start;
4538c1ffb0f8 Mail: added support for XOAUTH2 and OAUTHBEARER authentication.
Maxim Dounin <mdounin@mdounin.ru>
parents: 9288
diff changeset
1198 }
5398
04e43d03e153 Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4818
diff changeset
1199 }
04e43d03e153 Mail: smtp pipelining support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4818
diff changeset
1200
1482
4606dce4f416 optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1480
diff changeset
1201 if (c->read->timer_set) {
4606dce4f416 optimizations
Igor Sysoev <igor@sysoev.ru>
parents: 1480
diff changeset
1202 ngx_del_timer(c->read);
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1203 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1204
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1205 s->login_attempt++;
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1206
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1207 ngx_mail_auth_http_init(s);
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1208 }
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1209
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1210
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1211 void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1212 ngx_mail_session_internal_server_error(ngx_mail_session_t *s)
525
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
1213 {
1487
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1214 ngx_mail_core_srv_conf_t *cscf;
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1215
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1216 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1217
f69493e8faab ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents: 1482
diff changeset
1218 s->out = cscf->protocol->internal_server_error;
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1219 s->quit = 1;
525
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
1220
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1221 ngx_mail_send(s->connection->write);
525
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
1222 }
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
1223
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
1224
09b42134ac0c nginx-0.1.37-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
1225 void
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1226 ngx_mail_close_connection(ngx_connection_t *c)
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
1227 {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
1228 ngx_pool_t *pool;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
1229
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1230 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1231 "close mail connection: %d", c->fd);
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
1232
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1233 #if (NGX_MAIL_SSL)
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1234
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1235 if (c->ssl) {
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1236 if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1237 c->ssl->handler = ngx_mail_close_connection;
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1238 return;
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1239 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1240 }
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1241
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1242 #endif
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1243
1472
32450a2bbdf4 decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents: 1323
diff changeset
1244 #if (NGX_STAT_STUB)
2951
5acd98486a33 ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents: 2855
diff changeset
1245 (void) ngx_atomic_fetch_add(ngx_stat_active, -1);
1472
32450a2bbdf4 decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents: 1323
diff changeset
1246 #endif
32450a2bbdf4 decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents: 1323
diff changeset
1247
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
1248 c->destroyed = 1;
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
1249
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
1250 pool = c->pool;
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
1251
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
1252 ngx_close_connection(c);
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
1253
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
1254 ngx_destroy_pool(pool);
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 415
diff changeset
1255 }
539
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1256
371c1cee100d nginx-0.1.44-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
1257
1476
67578e966dcc split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents: 1472
diff changeset
1258 u_char *
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1259 ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len)
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1260 {
567
1af2fcb3be8a nginx-0.3.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 547
diff changeset
1261 u_char *p;
1136
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1262 ngx_mail_session_t *s;
68f30ab68bb7 Many changes:
Igor Sysoev <igor@sysoev.ru>
parents: 1111
diff changeset
1263 ngx_mail_log_ctx_t *ctx;
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1264
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1265 if (log->action) {
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1266 p = ngx_snprintf(buf, len, " while %s", log->action);
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1267 len -= p - buf;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1268 buf = p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1269 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
1270
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1271 ctx = log->data;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1272
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1273 p = ngx_snprintf(buf, len, ", client: %V", ctx->client);
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1274 len -= p - buf;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1275 buf = p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1276
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1277 s = ctx->session;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1278
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1279 if (s == NULL) {
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1280 return p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1281 }
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1282
1491
93ff27726d2e log starttls
Igor Sysoev <igor@sysoev.ru>
parents: 1487
diff changeset
1283 p = ngx_snprintf(buf, len, "%s, server: %V",
93ff27726d2e log starttls
Igor Sysoev <igor@sysoev.ru>
parents: 1487
diff changeset
1284 s->starttls ? " using starttls" : "",
93ff27726d2e log starttls
Igor Sysoev <igor@sysoev.ru>
parents: 1487
diff changeset
1285 s->addr_text);
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1286 len -= p - buf;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1287 buf = p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1288
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1289 if (s->login.len == 0) {
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1290 return p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1291 }
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1292
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1293 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login);
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1294 len -= p - buf;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1295 buf = p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1296
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1297 if (s->proxy == NULL) {
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1298 return p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1299 }
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1300
884
4d68c486fcb0 upstream choice modules
Igor Sysoev <igor@sysoev.ru>
parents: 855
diff changeset
1301 p = ngx_snprintf(buf, len, ", upstream: %V", s->proxy->upstream.name);
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1302
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1303 return p;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 539
diff changeset
1304 }