annotate src/imap/ngx_imap_auth_http_module.c @ 104:146eff53ab60 NGINX_0_2_6

nginx 0.2.6 *) Change: while using load-balancing the time before the failed backend retry was decreased from 60 to 10 seconds. *) Change: the "proxy_pass_unparsed_uri" was canceled, the original URI now passed, if the URI part is omitted in "proxy_pass" directive. *) Feature: the "error_page" directive supports redirects and allows more flexible to change an error code. *) Change: the charset in the "Content-Type" header line now is ignored in proxied subrequests. *) Bugfix: if the URI was changed in the "if" block and request did not found new configuration, then the ngx_http_rewrite_module rules ran again. *) Bugfix: if the "set" directive set the ngx_http_geo_module variable in some configuration part, the this variable was not available in other configuration parts and the "using uninitialized variable" error was occurred; bug appeared in 0.2.2.
author Igor Sysoev <http://sysoev.ru>
date Wed, 05 Oct 2005 00:00:00 +0400
parents ca4f70b3ccc6
children cf3d6edb3ad6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_event.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_event_connect.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11 #include <ngx_imap.h>
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 typedef struct {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 ngx_peers_t *peers;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 ngx_msec_t timeout;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 ngx_str_t host_header;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 ngx_str_t uri;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 } ngx_imap_auth_http_conf_t;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 typedef struct ngx_imap_auth_http_ctx_s ngx_imap_auth_http_ctx_t;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 typedef void (*ngx_imap_auth_http_handler_pt)(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 ngx_imap_auth_http_ctx_t *ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 struct ngx_imap_auth_http_ctx_s {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 ngx_buf_t *request;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 ngx_buf_t *response;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 ngx_peer_connection_t peer;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 ngx_imap_auth_http_handler_pt handler;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 ngx_uint_t state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 ngx_uint_t hash; /* no needed ? */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 u_char *header_name_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 u_char *header_name_end;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41 u_char *header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 u_char *header_end;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 ngx_str_t addr;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 ngx_str_t port;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 ngx_str_t err;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
48 time_t sleep;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
50 ngx_pool_t *pool;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51 };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 static void ngx_imap_auth_http_write_handler(ngx_event_t *wev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 static void ngx_imap_auth_http_read_handler(ngx_event_t *rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 static void ngx_imap_auth_http_ignore_status_line(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 ngx_imap_auth_http_ctx_t *ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 static void ngx_imap_auth_http_process_headers(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 ngx_imap_auth_http_ctx_t *ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 static void ngx_imap_auth_sleep_handler(ngx_event_t *rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 static ngx_int_t ngx_imap_auth_http_parse_header_line(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 ngx_imap_auth_http_ctx_t *ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63 static void ngx_imap_auth_http_block_read(ngx_event_t *rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 static void ngx_imap_auth_http_dummy_handler(ngx_event_t *ev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 static ngx_buf_t *ngx_imap_auth_http_create_request(ngx_imap_session_t *s,
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
66 ngx_pool_t *pool, ngx_imap_auth_http_conf_t *ahcf);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 static void *ngx_imap_auth_http_create_conf(ngx_conf_t *cf);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 static char *ngx_imap_auth_http_merge_conf(ngx_conf_t *cf, void *parent,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 void *child);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 static char *ngx_imap_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 static ngx_command_t ngx_imap_auth_http_commands[] = {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 { ngx_string("auth_http"),
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 ngx_imap_auth_http,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 NGX_IMAP_SRV_CONF_OFFSET,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 NULL },
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 { ngx_string("auth_http_timeout"),
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 ngx_conf_set_msec_slot,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 NGX_IMAP_SRV_CONF_OFFSET,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 offsetof(ngx_imap_auth_http_conf_t, timeout),
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 NULL },
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90 ngx_null_command
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 static ngx_imap_module_t ngx_imap_auth_http_module_ctx = {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 NULL, /* create main configuration */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 NULL, /* init main configuration */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 ngx_imap_auth_http_create_conf, /* create server configuration */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 ngx_imap_auth_http_merge_conf /* merge server configuration */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 ngx_module_t ngx_imap_auth_http_module = {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 NGX_MODULE_V1,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 &ngx_imap_auth_http_module_ctx, /* module context */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 ngx_imap_auth_http_commands, /* module directives */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107 NGX_IMAP_MODULE, /* module type */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
108 NULL, /* init master */
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 NULL, /* init module */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
110 NULL, /* init process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
111 NULL, /* init thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
112 NULL, /* exit thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
113 NULL, /* exit process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
114 NULL, /* exit master */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
115 NGX_MODULE_V1_PADDING
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 static char *ngx_imap_auth_http_protocol[] = { "pop3", "imap" };
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 ngx_imap_auth_http_init(ngx_imap_session_t *s)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 ngx_int_t rc;
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
126 ngx_pool_t *pool;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 ngx_imap_auth_http_ctx_t *ctx;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 ngx_imap_auth_http_conf_t *ahcf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
130 s->connection->log->action = "in http auth state";
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
131
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
132 pool = ngx_create_pool(2048, s->connection->log);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
133 if (pool == NULL) {
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
138 ctx = ngx_pcalloc(pool, sizeof(ngx_imap_auth_http_ctx_t));
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
139 if (ctx == NULL) {
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
140 ngx_destroy_pool(pool);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
141 ngx_imap_session_internal_server_error(s);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
142 return;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
143 }
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
144
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
145 ctx->pool = pool;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
146
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 ahcf = ngx_imap_get_module_srv_conf(s, ngx_imap_auth_http_module);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
149 ctx->request = ngx_imap_auth_http_create_request(s, pool, ahcf);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 if (ctx->request == NULL) {
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
151 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 ngx_imap_set_ctx(s, ctx, ngx_imap_auth_http_module);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 ctx->peer.peers = ahcf->peers;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159 ctx->peer.log = s->connection->log;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 ctx->peer.log_error = NGX_ERROR_ERR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162 rc = ngx_event_connect_peer(&ctx->peer);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
164 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
165 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
166 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 ctx->peer.connection->data = s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 ctx->peer.connection->pool = s->connection->pool;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174 s->connection->read->handler = ngx_imap_auth_http_block_read;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175 ctx->peer.connection->read->handler = ngx_imap_auth_http_read_handler;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176 ctx->peer.connection->write->handler = ngx_imap_auth_http_write_handler;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178 ctx->handler = ngx_imap_auth_http_ignore_status_line;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
180 ngx_add_timer(ctx->peer.connection->read, ahcf->timeout);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
181 ngx_add_timer(ctx->peer.connection->write, ahcf->timeout);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
182
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 if (rc == NGX_OK) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 ngx_imap_auth_http_write_handler(ctx->peer.connection->write);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
187 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 ngx_imap_auth_http_write_handler(ngx_event_t *wev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 ssize_t n, size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196 ngx_imap_auth_http_ctx_t *ctx;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197 ngx_imap_auth_http_conf_t *ahcf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199 c = wev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, wev->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205 "imap auth http write handler");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 if (wev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208 ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
209 "auth http server %V timed out",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
210 &ctx->peer.peers->peer[0].name);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
212 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
217 size = ctx->request->last - ctx->request->pos;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 n = ngx_send(c, ctx->request->pos, size);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 if (n == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
223 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 if (n > 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 ctx->request->pos += n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231 if (n == size) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 wev->handler = ngx_imap_auth_http_dummy_handler;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 if (wev->timer_set) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 ngx_del_timer(wev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
242 if (!wev->timer_set) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243 ahcf = ngx_imap_get_module_srv_conf(s, ngx_imap_auth_http_module);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 ngx_add_timer(wev, ahcf->timeout);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 ngx_imap_auth_http_read_handler(ngx_event_t *rev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 ssize_t n, size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 ngx_imap_auth_http_ctx_t *ctx;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261 "imap auth http read handler");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266 ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
267 "auth http server %V timed out",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
268 &ctx->peer.peers->peer[0].name);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
270 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 if (ctx->response == NULL) {
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
276 ctx->response = ngx_create_temp_buf(ctx->pool, 1024);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 if (ctx->response == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
279 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 size = ctx->response->end - ctx->response->last;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 n = ngx_recv(c, ctx->response->pos, size);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289 if (n > 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 ctx->response->last += n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292 ctx->handler(s, ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 if (n == NGX_AGAIN) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
301 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307 ngx_imap_auth_http_ignore_status_line(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
308 ngx_imap_auth_http_ctx_t *ctx)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
310 u_char *p, ch;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311 enum {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312 sw_start = 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313 sw_H,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314 sw_HT,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315 sw_HTT,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316 sw_HTTP,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 sw_skip,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
318 sw_almost_done
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319 } state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, s->connection->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 "imap auth http process status line");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
324 state = ctx->state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326 for (p = ctx->response->pos; p < ctx->response->last; p++) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 ch = *p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329 switch (state) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 /* "HTTP/" */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 case sw_start:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333 if (ch == 'H') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 state = sw_H;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
336 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337 goto next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 case sw_H:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340 if (ch == 'T') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341 state = sw_HT;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
342 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344 goto next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
345
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346 case sw_HT:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
347 if (ch == 'T') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348 state = sw_HTT;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
350 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
351 goto next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
352
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
353 case sw_HTT:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
354 if (ch == 'P') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
355 state = sw_HTTP;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
356 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
357 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
358 goto next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
359
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
360 case sw_HTTP:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361 if (ch == '/') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 state = sw_skip;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365 goto next;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 /* any text until end of line */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368 case sw_skip:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
370 case CR:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
371 state = sw_almost_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
376 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
377 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
378
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
379 /* end of status line */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380 case sw_almost_done:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381 if (ch == LF) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
382 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
383 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
384
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
385 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
386 "auth http server &V sent invalid response",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
387 &ctx->peer.peers->peer[0].name);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
389 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
390 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
394
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
395 ctx->response->pos = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
396 ctx->state = state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400 next:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402 p = ctx->response->start - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 done:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
405
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406 ctx->response->pos = p + 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407 ctx->state = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 ctx->handler = ngx_imap_auth_http_process_headers;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409 ctx->handler(s, ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
411
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414 ngx_imap_auth_http_process_headers(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415 ngx_imap_auth_http_ctx_t *ctx)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
416 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417 u_char *p;
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
418 time_t timer;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419 size_t len, size;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420 ngx_int_t rc, port, n;
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
421 ngx_peers_t *peers;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422 struct sockaddr_in *sin;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, s->connection->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425 "imap auth http process headers");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
427 for ( ;; ) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428 rc = ngx_imap_auth_http_parse_header_line(s, ctx);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430 if (rc == NGX_OK) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
431
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432 #if (NGX_DEBUG)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 ngx_str_t key, value;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
436 key.len = ctx->header_name_end - ctx->header_name_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437 key.data = ctx->header_name_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438 value.len = ctx->header_end - ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
439 value.data = ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
440
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, s->connection->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442 "auth http header: \"%V: %V\"",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443 &key, &value);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
444 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
445 #endif
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
446
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
447 len = ctx->header_name_end - ctx->header_name_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 if (len == sizeof("Auth-Status") - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450 && ngx_strncasecmp(ctx->header_name_start, "Auth-Status",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
451 sizeof("Auth-Status") - 1) == 0)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
452 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
453 len = ctx->header_end - ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
455 if (len == 2
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
456 && ctx->header_start[0] == 'O'
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
457 && ctx->header_start[1] == 'K')
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
458 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
459 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
460 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 size = sizeof("-ERR") - 1 + len + sizeof(CRLF) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
464
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466 size = s->tag.len + sizeof("NO") - 1 + len
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
467 + sizeof(CRLF) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
468 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
469
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470 p = ngx_pcalloc(s->connection->pool, size);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
471 if (p == NULL) {
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
472 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
473 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
474 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
475 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
476 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
477
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
478 ctx->err.data = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
479
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
480 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
481 *p++ = '-'; *p++ = 'E'; *p++ = 'R'; *p++ = 'R';
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
482
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
483 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
484 p = ngx_cpymem(p, s->tag.data, s->tag.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485 *p++ = 'N'; *p++ = 'O';
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
486 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
487
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
488 *p++ = ' ';
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
489 p = ngx_cpymem(p, ctx->header_start, len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490 *p++ = CR; *p++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
491
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
492 ctx->err.len = p - ctx->err.data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
494 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497 if (len == sizeof("Auth-Server") - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498 && ngx_strncasecmp(ctx->header_name_start, "Auth-Server",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499 sizeof("Auth-Server") - 1) == 0)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
501 ctx->addr.len = ctx->header_end - ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
502 ctx->addr.data = ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
503
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
504 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
505 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
506
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
507 if (len == sizeof("Auth-Port") - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
508 && ngx_strncasecmp(ctx->header_name_start, "Auth-Port",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
509 sizeof("Auth-Port") - 1) == 0)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
510 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
511 ctx->port.len = ctx->header_end - ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512 ctx->port.data = ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
513
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
514 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
515 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
516
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
517 if (len == sizeof("Auth-User") - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
518 && ngx_strncasecmp(ctx->header_name_start, "Auth-User",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
519 sizeof("Auth-User") - 1) == 0)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
520 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
521 s->login.len = ctx->header_end - ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
522 s->login.data = ctx->header_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
523
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
524 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
525 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
526
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
527 if (len == sizeof("Auth-Wait") - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
528 && ngx_strncasecmp(ctx->header_name_start, "Auth-Wait",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
529 sizeof("Auth-Wait") - 1) == 0)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
530 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
531 n = ngx_atoi(ctx->header_start,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
532 ctx->header_end - ctx->header_start);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
533
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
534 if (n != NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
535 ctx->sleep = n;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
536 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
537
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
538 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
539 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
540
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
541 /* ignore other headers */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
542
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
543 continue;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
544 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546 if (rc == NGX_DONE) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, s->connection->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
548 "auth http header done");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
549
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
550 ngx_close_connection(ctx->peer.connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
551
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
552 if (ctx->err.len) {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
553 s->out = ctx->err;
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
554 timer = ctx->sleep;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
555
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
556 ngx_destroy_pool(ctx->pool);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
557
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
558 ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
559 "client login failed");
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
560
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
561 if (timer == 0) {
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
562 s->quit = 1;
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
563 ngx_imap_send(s->connection->write);
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
564 return;
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
565 }
88
e916a291e9aa nginx 0.1.44
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
566
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
567 ngx_add_timer(s->connection->read, timer * 1000);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
568
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
569 s->connection->read->handler = ngx_imap_auth_sleep_handler;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
570
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
571 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
572 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
573
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
574 if (ctx->addr.len == 0 || ctx->port.len == 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
575 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
576 "auth http server %V did not send server or port",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
577 &ctx->peer.peers->peer[0].name);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
578 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
580 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
581 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
582
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
583 peers = ngx_pcalloc(s->connection->pool, sizeof(ngx_peers_t));
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
584 if (peers == NULL) {
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
585 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
588 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
589
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
590 sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in));
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
591 if (sin == NULL) {
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
592 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
593 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
594 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
595 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
596
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
597 sin->sin_family = AF_INET;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
598
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
599 port = ngx_atoi(ctx->port.data, ctx->port.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
600 if (port == NGX_ERROR || port < 1 || port > 65536) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
601 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
602 "auth http server %V sent invalid server "
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
603 "port:\"%V\"",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
604 &ctx->peer.peers->peer[0].name, &ctx->port);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
605 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
606 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
607 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
608 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
609
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
610 sin->sin_port = htons((in_port_t) port);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
611
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
612 ctx->addr.data[ctx->addr.len] = '\0';
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
613 sin->sin_addr.s_addr = inet_addr((char *) ctx->addr.data);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
614 if (sin->sin_addr.s_addr == INADDR_NONE) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
615 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
616 "auth http server %V sent invalid server "
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
617 "address:\"%V\"",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
618 &ctx->peer.peers->peer[0].name, &ctx->addr);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
619 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
620 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
621 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
622 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
623
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
624 peers->number = 1;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
625
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
626 peers->peer[0].sockaddr = (struct sockaddr *) sin;
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
627 peers->peer[0].socklen = sizeof(struct sockaddr_in);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
628
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
629 len = ctx->addr.len + 1 + ctx->port.len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
631 peers->peer[0].name.len = len;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
632
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
633 peers->peer[0].name.data = ngx_palloc(s->connection->pool, len);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
634 if (peers->peer[0].name.data == NULL) {
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
635 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
637 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
638 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
639
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
640 len = ctx->addr.len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
641
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
642 ngx_memcpy(peers->peer[0].name.data, ctx->addr.data, len);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
644 peers->peer[0].name.data[len++] = ':';
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
645
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
646 ngx_memcpy(peers->peer[0].name.data + len,
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
647 ctx->port.data, ctx->port.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
648
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
649 peers->peer[0].uri_separator = "";
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
651 ngx_destroy_pool(ctx->pool);
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
652 ngx_imap_proxy_init(s, peers);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
653
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
654 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
655 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
656
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
657 if (rc == NGX_AGAIN ) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
658 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
659 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
660
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
661 /* rc == NGX_ERROR */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
662
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
663 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
664 "auth http server %V sent invalid header in response",
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 88
diff changeset
665 &ctx->peer.peers->peer[0].name);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
666 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
667 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
668 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
669
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
670 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
671 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
672 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
673
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
674
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
675 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
676 ngx_imap_auth_sleep_handler(ngx_event_t *rev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
677 {
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
678 ngx_connection_t *c;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
679 ngx_imap_session_t *s;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
680 ngx_imap_core_srv_conf_t *cscf;
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
681
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
682 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap auth sleep handler");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
683
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
684 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
685 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
686
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
687 if (rev->timedout) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
688
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
689 rev->timedout = 0;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
690
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
691 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
692 s->imap_state = ngx_pop3_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
693 s->connection->read->handler = ngx_pop3_auth_state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 s->imap_state = ngx_imap_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697 s->connection->read->handler = ngx_imap_auth_state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
699
92
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
700 c->log->action = "in auth state";
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
701
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
702 ngx_imap_send(s->connection->write);
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
703
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
704 if (c->closed) {
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
705 return;
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
706 }
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
707
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
708 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
709
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
710 ngx_add_timer(rev, cscf->timeout);
45945fa8b8ba nginx 0.2.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
711
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
712 if (rev->ready) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
713 s->connection->read->handler(rev);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
714 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
715 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
716
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
717 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
718 ngx_imap_close_connection(s->connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
719 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
720
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
721 return;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
722 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
723
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
724 if (rev->active) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
725 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
726 ngx_imap_close_connection(s->connection);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
728 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
729 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
730
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
732 static ngx_int_t
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
733 ngx_imap_auth_http_parse_header_line(ngx_imap_session_t *s,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
734 ngx_imap_auth_http_ctx_t *ctx)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
735 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
736 u_char c, ch, *p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
737 ngx_uint_t hash;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
738 enum {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
739 sw_start = 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
740 sw_name,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
741 sw_space_before_value,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
742 sw_value,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
743 sw_space_after_value,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
744 sw_almost_done,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
745 sw_header_almost_done
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
746 } state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
747
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
748 state = ctx->state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
749 hash = ctx->hash;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
750
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
751 for (p = ctx->response->pos; p < ctx->response->last; p++) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
752 ch = *p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
753
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
754 switch (state) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
755
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
756 /* first char */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
757 case sw_start:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
758
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
759 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760 case CR:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
761 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
762 state = sw_header_almost_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
763 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
764 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
765 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
766 goto header_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
767 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
768 state = sw_name;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
769 ctx->header_name_start = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
770
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
771 c = (u_char) (ch | 0x20);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
772 if (c >= 'a' && c <= 'z') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
773 hash = c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
774 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
775 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
776
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
777 if (ch >= '0' && ch <= '9') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
778 hash = ch;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
779 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
780 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
781
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
782 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
785
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
786 /* header name */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
787 case sw_name:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
788 c = (u_char) (ch | 0x20);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 if (c >= 'a' && c <= 'z') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790 hash += c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
791 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
792 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
793
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
794 if (ch == ':') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
795 ctx->header_name_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
796 state = sw_space_before_value;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
797 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
798 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
799
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
800 if (ch == '-') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
801 hash += ch;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
803 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
804
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
805 if (ch >= '0' && ch <= '9') {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
806 hash += ch;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
808 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
809
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
810 if (ch == CR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
811 ctx->header_name_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
812 ctx->header_start = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
813 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814 state = sw_almost_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
816 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
817
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
818 if (ch == LF) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
819 ctx->header_name_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
820 ctx->header_start = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
821 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
822 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
823 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
825 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
826
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
827 /* space* before header value */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
828 case sw_space_before_value:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
829 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
830 case ' ':
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
831 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
832 case CR:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
833 ctx->header_start = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
835 state = sw_almost_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
836 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
837 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
838 ctx->header_start = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
839 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
840 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
841 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
842 ctx->header_start = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
843 state = sw_value;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
844 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
845 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
846 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848 /* header value */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849 case sw_value:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
850 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
851 case ' ':
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
852 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
853 state = sw_space_after_value;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
854 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
855 case CR:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
856 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
857 state = sw_almost_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
858 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
859 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
860 ctx->header_end = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
861 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
862 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
863 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
864
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
865 /* space* before end of header line */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
866 case sw_space_after_value:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
867 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
868 case ' ':
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
869 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
870 case CR:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
871 state = sw_almost_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
872 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
873 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
874 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
875 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
876 state = sw_value;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
877 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
878 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
879 break;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
880
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
881 /* end of header line */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
882 case sw_almost_done:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
883 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
884 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
885 goto done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
886 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
887 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
888 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
889
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
890 /* end of header */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
891 case sw_header_almost_done:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
892 switch (ch) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
893 case LF:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
894 goto header_done;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
895 default:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
896 return NGX_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
897 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
898 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
899 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
900
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
901 ctx->response->pos = p;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
902 ctx->state = state;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
903 ctx->hash = hash;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
904
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
905 return NGX_AGAIN;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
906
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
907 done:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
908
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
909 ctx->response->pos = p + 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
910 ctx->state = sw_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
911 ctx->hash = hash;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
912
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
913 return NGX_OK;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
914
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
915 header_done:
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
916
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
917 ctx->response->pos = p + 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
918 ctx->state = sw_start;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
919
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
920 return NGX_DONE;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
921 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
922
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
923
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
924 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
925 ngx_imap_auth_http_block_read(ngx_event_t *rev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
926 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
927 ngx_connection_t *c;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
928 ngx_imap_session_t *s;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
929 ngx_imap_auth_http_ctx_t *ctx;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
930
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
931 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
932 "imap auth http block read");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
933
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
934 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
935 c = rev->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
936 s = c->data;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
937
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
938 ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
939
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
940 ngx_close_connection(ctx->peer.connection);
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
941 ngx_destroy_pool(ctx->pool);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
942 ngx_imap_session_internal_server_error(s);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
943 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
944 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
945
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
946
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
947 static void
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
948 ngx_imap_auth_http_dummy_handler(ngx_event_t *ev)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
949 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
950 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, ev->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
951 "imap auth http dummy handler");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
952 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
953
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
954
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
955 static ngx_buf_t *
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
956 ngx_imap_auth_http_create_request(ngx_imap_session_t *s, ngx_pool_t *pool,
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
957 ngx_imap_auth_http_conf_t *ahcf)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
958 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
959 size_t len;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
960 ngx_buf_t *b;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
961
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
962 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
963 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
964 + sizeof("Auth-Method: plain" CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
965 + sizeof("Auth-User: ") - 1 + s->login.len + sizeof(CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
966 + sizeof("Auth-Pass: ") - 1 + s->passwd.len + sizeof(CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
967 + sizeof("Auth-Protocol: imap" CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
968 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
969 + sizeof(CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
970 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
971 + sizeof(CRLF) - 1
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
972 + sizeof(CRLF) - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
973
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
974 b = ngx_create_temp_buf(pool, len);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
975 if (b == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
976 return NULL;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
977 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
978
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
979 b->last = ngx_cpymem(b->last, "GET ", sizeof("GET ") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
980 b->last = ngx_cpymem(b->last, ahcf->uri.data, ahcf->uri.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
981 b->last = ngx_cpymem(b->last, " HTTP/1.0" CRLF,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
982 sizeof(" HTTP/1.0" CRLF) - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
983
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
984 b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
985 b->last = ngx_cpymem(b->last, ahcf->host_header.data,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
986 ahcf->host_header.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
987 *b->last++ = CR; *b->last++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
988
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
989 b->last = ngx_cpymem(b->last, "Auth-Method: plain" CRLF,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
990 sizeof("Auth-Method: plain" CRLF) - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
991
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
992 b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
993 b->last = ngx_cpymem(b->last, s->login.data, s->login.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
994 *b->last++ = CR; *b->last++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
995
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
996 b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
997 b->last = ngx_cpymem(b->last, s->passwd.data, s->passwd.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
998 *b->last++ = CR; *b->last++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
999
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1000 b->last = ngx_cpymem(b->last, "Auth-Protocol: ",
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1001 sizeof("Auth-Protocol: ") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1002 b->last = ngx_cpymem(b->last, ngx_imap_auth_http_protocol[s->protocol],
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1003 sizeof("imap") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1004 *b->last++ = CR; *b->last++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1005
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1006 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1007 s->login_attempt);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1008
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1009 b->last = ngx_cpymem(b->last, "Client-IP: ", sizeof("Client-IP: ") - 1);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1010 b->last = ngx_cpymem(b->last, s->connection->addr_text.data,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1011 s->connection->addr_text.len);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1012 *b->last++ = CR; *b->last++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1013
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1014 /* add "\r\n" at the header end */
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1015 *b->last++ = CR; *b->last++ = LF;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1016
96
ca4f70b3ccc6 nginx 0.2.2
Igor Sysoev <http://sysoev.ru>
parents: 92
diff changeset
1017 #if (NGX_DEBUG_IMAP_PASSWD)
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1018 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1019 ngx_str_t l;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1020
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1021 l.len = b->last - b->pos;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1022 l.data = b->pos;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1023 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, s->connection->log, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1024 "imap auth http header:\n\"%V\"", &l);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1025 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1026 #endif
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1027
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1028 return b;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1029 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1030
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1031
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1032 static void *
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1033 ngx_imap_auth_http_create_conf(ngx_conf_t *cf)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1034 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1035 ngx_imap_auth_http_conf_t *ahcf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1036
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1037 ahcf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_auth_http_conf_t));
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1038 if (ahcf == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1039 return NGX_CONF_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1040 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1041
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1042 ahcf->timeout = NGX_CONF_UNSET_MSEC;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1043
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1044 return ahcf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1045 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1046
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1047
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1048 static char *
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1049 ngx_imap_auth_http_merge_conf(ngx_conf_t *cf, void *parent, void *child)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1050 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1051 ngx_imap_auth_http_conf_t *prev = parent;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1052 ngx_imap_auth_http_conf_t *conf = child;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1053
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1054 if (conf->peers == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1055 conf->peers = prev->peers;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1056 conf->host_header = prev->host_header;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1057 conf->uri = prev->uri;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1058 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1059
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1060 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1061
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1062 return NGX_CONF_OK;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1063 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1064
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1065
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1066 static char *
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1067 ngx_imap_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1068 {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1069 ngx_imap_auth_http_conf_t *ahcf = conf;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1070
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1071 ngx_str_t *value, *url;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1072 ngx_inet_upstream_t inet_upstream;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1073 #if (NGX_HAVE_UNIX_DOMAIN)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1074 ngx_unix_domain_upstream_t unix_upstream;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1075 #endif
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1076
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1077 value = cf->args->elts;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1078
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1079 url = &value[1];
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1080
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1081 if (ngx_strncasecmp(url->data, "unix:", 5) == 0) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1082
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1083 #if (NGX_HAVE_UNIX_DOMAIN)
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1084
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1085 ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t));
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1086
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1087 unix_upstream.name = *url;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1088 unix_upstream.url = *url;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1089 unix_upstream.uri_part = 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1090
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1091 ahcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1092 if (ahcf->peers == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1093 return NGX_CONF_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1094 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1095
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1096 ahcf->host_header.len = sizeof("localhost") - 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1097 ahcf->host_header.data = (u_char *) "localhost";
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1098 ahcf->uri = unix_upstream.uri;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1099
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1100 #else
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1101 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1102 "the unix domain sockets are not supported "
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1103 "on this platform");
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1104 return NGX_CONF_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1105
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1106 #endif
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1107
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1108 } else {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1109 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1110
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1111 inet_upstream.name = *url;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1112 inet_upstream.url = *url;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1113 inet_upstream.default_port_value = 80;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1114 inet_upstream.uri_part = 1;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1115
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1116 ahcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1117 if (ahcf->peers == NULL) {
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1118 return NGX_CONF_ERROR;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1119 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1120
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1121 ahcf->host_header = inet_upstream.host_header;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1122 ahcf->uri = inet_upstream.uri;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1123 }
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1124
104
146eff53ab60 nginx 0.2.6
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
1125 if (ahcf->uri.len) {
146eff53ab60 nginx 0.2.6
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
1126 ahcf->uri.len = sizeof("/") - 1;
146eff53ab60 nginx 0.2.6
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
1127 ahcf->uri.data = (u_char *) "/";
146eff53ab60 nginx 0.2.6
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
1128 }
146eff53ab60 nginx 0.2.6
Igor Sysoev <http://sysoev.ru>
parents: 96
diff changeset
1129
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1130 return NGX_CONF_OK;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1131 }