summaryrefslogtreecommitdiffhomepage
path: root/src/mail/ngx_mail_auth_http_module.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2007-09-15 16:51:16 +0000
committerIgor Sysoev <igor@sysoev.ru>2007-09-15 16:51:16 +0000
commit48714085dde4fe4c5b695dad23295e3f96fe1d2e (patch)
tree37b0109215ca08bb1103f03dd43f435392ebe36a /src/mail/ngx_mail_auth_http_module.c
parent05a75d0d9496d874fc22d7e8b3c44b7914a61509 (diff)
downloadnginx-48714085dde4fe4c5b695dad23295e3f96fe1d2e.tar.gz
nginx-48714085dde4fe4c5b695dad23295e3f96fe1d2e.tar.bz2
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Diffstat (limited to 'src/mail/ngx_mail_auth_http_module.c')
-rw-r--r--src/mail/ngx_mail_auth_http_module.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/mail/ngx_mail_auth_http_module.c b/src/mail/ngx_mail_auth_http_module.c
index f0f7257f5..9e74e6aec 100644
--- a/src/mail/ngx_mail_auth_http_module.c
+++ b/src/mail/ngx_mail_auth_http_module.c
@@ -111,6 +111,8 @@ static ngx_command_t ngx_mail_auth_http_commands[] = {
static ngx_mail_module_t ngx_mail_auth_http_module_ctx = {
+ NULL, /* protocol */
+
NULL, /* create main configuration */
NULL, /* init main configuration */
@@ -135,7 +137,6 @@ ngx_module_t ngx_mail_auth_http_module = {
};
-static char *ngx_mail_auth_http_protocol[] = { "pop3", "imap", "smtp" };
static ngx_str_t ngx_mail_auth_http_method[] = {
ngx_string("plain"),
ngx_string("plain"),
@@ -145,18 +146,6 @@ static ngx_str_t ngx_mail_auth_http_method[] = {
static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
-static ngx_uint_t ngx_mail_start_states[] = {
- ngx_pop3_start,
- ngx_imap_start,
- ngx_smtp_start
-};
-
-static ngx_mail_auth_state_pt ngx_mail_auth_states[] = {
- ngx_mail_pop3_auth_state,
- ngx_mail_imap_auth_state,
- ngx_mail_smtp_auth_state
-};
-
void
ngx_mail_auth_http_init(ngx_mail_session_t *s)
@@ -762,7 +751,8 @@ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
return;
}
- if (s->passwd.data == NULL && s->protocol != NGX_MAIL_SMTP_PROTOCOL)
+ if (s->passwd.data == NULL
+ && s->protocol != NGX_MAIL_SMTP_PROTOCOL)
{
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
"auth http server %V did not send password",
@@ -881,9 +871,11 @@ ngx_mail_auth_sleep_handler(ngx_event_t *rev)
return;
}
- s->mail_state = ngx_mail_start_states[s->protocol];
- rev->handler = ngx_mail_auth_states[s->protocol];
+ cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
+
+ rev->handler = cscf->protocol->auth_state;
+ s->mail_state = 0;
s->auth_method = NGX_MAIL_AUTH_PLAIN;
c->log->action = "in auth state";
@@ -894,8 +886,6 @@ ngx_mail_auth_sleep_handler(ngx_event_t *rev)
return;
}
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
ngx_add_timer(rev, cscf->timeout);
if (rev->ready) {
@@ -1145,9 +1135,10 @@ static ngx_buf_t *
ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool,
ngx_mail_auth_http_conf_t *ahcf)
{
- size_t len;
- ngx_buf_t *b;
- ngx_str_t login, passwd;
+ size_t len;
+ ngx_buf_t *b;
+ ngx_str_t login, passwd;
+ ngx_mail_core_srv_conf_t *cscf;
if (ngx_mail_auth_http_escape(pool, &s->login, &login) != NGX_OK) {
return NULL;
@@ -1157,6 +1148,8 @@ ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool,
return NULL;
}
+ cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
+
len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1
+ sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1
+ sizeof("Auth-Method: ") - 1
@@ -1165,7 +1158,8 @@ ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool,
+ sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1
+ sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1
+ sizeof("Auth-Salt: ") - 1 + s->salt.len
- + sizeof("Auth-Protocol: imap" CRLF) - 1
+ + sizeof("Auth-Protocol: ") - 1 + cscf->protocol->name.len
+ + sizeof(CRLF) - 1
+ sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN
+ sizeof(CRLF) - 1
+ sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
@@ -1212,8 +1206,8 @@ ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool,
b->last = ngx_cpymem(b->last, "Auth-Protocol: ",
sizeof("Auth-Protocol: ") - 1);
- b->last = ngx_cpymem(b->last, ngx_mail_auth_http_protocol[s->protocol],
- sizeof("imap") - 1);
+ b->last = ngx_cpymem(b->last, cscf->protocol->name.data,
+ cscf->protocol->name.len);
*b->last++ = CR; *b->last++ = LF;
b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF,