62 static void ngx_mail_auth_http_write_handler(
ngx_event_t *wev);
63 static void ngx_mail_auth_http_read_handler(
ngx_event_t *rev);
68 static void ngx_mail_auth_sleep_handler(
ngx_event_t *rev);
71 static void ngx_mail_auth_http_block_read(
ngx_event_t *rev);
72 static void ngx_mail_auth_http_dummy_handler(
ngx_event_t *ev);
78 static void *ngx_mail_auth_http_create_conf(
ngx_conf_t *cf);
79 static char *ngx_mail_auth_http_merge_conf(
ngx_conf_t *cf,
void *parent,
104 ngx_mail_auth_http_header,
119 ngx_mail_auth_http_create_conf,
120 ngx_mail_auth_http_merge_conf
126 &ngx_mail_auth_http_module_ctx,
127 ngx_mail_auth_http_commands,
140 static ngx_str_t ngx_mail_auth_http_method[] = {
179 ctx->
request = ngx_mail_auth_http_create_request(s, pool, ahcf);
214 ctx->
handler = ngx_mail_auth_http_ignore_status_line;
241 "mail auth http write handler");
245 "auth http server %V timed out", ctx->
peer.
name);
267 wev->
handler = ngx_mail_auth_http_dummy_handler;
302 "mail auth http read handler");
308 "auth http server %V timed out", ctx->
peer.
name);
362 "mail auth http process status line");
366 for (p = ctx->
response->
pos; p < ctx->response->last; p++) {
411 state = sw_almost_done;
426 "auth http server &V sent invalid response",
448 ctx->
handler = ngx_mail_auth_http_process_headers;
462 struct sockaddr_in *sin;
464 struct sockaddr_in6 *sin6;
468 "mail auth http process headers");
471 rc = ngx_mail_auth_http_parse_header_line(s, ctx);
485 "mail auth http header: \"%V: %V\"",
492 if (len ==
sizeof(
"Auth-Status") - 1
494 (u_char *)
"Auth-Status",
495 sizeof(
"Auth-Status") - 1)
523 size =
sizeof(
"-ERR ") - 1 + len +
sizeof(
CRLF) - 1;
527 size = s->
tag.
len +
sizeof(
"NO ") - 1 + len
549 *p++ =
'-'; *p++ =
'E'; *p++ =
'R'; *p++ =
'R'; *p++ =
' ';
554 *p++ =
'N'; *p++ =
'O'; *p++ =
' ';
562 *p++ =
CR; *p++ =
LF;
569 if (len ==
sizeof(
"Auth-Server") - 1
571 (u_char *)
"Auth-Server",
572 sizeof(
"Auth-Server") - 1)
581 if (len ==
sizeof(
"Auth-Port") - 1
583 (u_char *)
"Auth-Port",
584 sizeof(
"Auth-Port") - 1)
593 if (len ==
sizeof(
"Auth-User") - 1
595 (u_char *)
"Auth-User",
596 sizeof(
"Auth-User") - 1)
614 if (len ==
sizeof(
"Auth-Pass") - 1
616 (u_char *)
"Auth-Pass",
617 sizeof(
"Auth-Pass") - 1)
636 if (len ==
sizeof(
"Auth-Wait") - 1
638 (u_char *)
"Auth-Wait",
639 sizeof(
"Auth-Wait") - 1)
652 if (len ==
sizeof(
"Auth-Error-Code") - 1
654 (u_char *)
"Auth-Error-Code",
655 sizeof(
"Auth-Error-Code") - 1)
682 "mail auth http header done");
689 "client login failed: \"%V\"", &ctx->
errmsg);
694 ctx->
errcode = ngx_mail_smtp_errcode;
698 +
sizeof(
" " CRLF) - 1;
753 "auth http server %V did not send server or port",
764 "auth http server %V did not send password",
787 "auth http server %V sent invalid server "
799 if (port ==
NGX_ERROR || port < 1 || port > 65535) {
801 "auth http server %V sent invalid server "
809 switch (peer->
sockaddr->sa_family) {
813 sin6 = (
struct sockaddr_in6 *) peer->
sockaddr;
814 sin6->sin6_port = htons((in_port_t) port);
819 sin = (
struct sockaddr_in *) peer->
sockaddr;
820 sin->sin_port = htons((in_port_t) port);
856 "auth http server %V sent invalid header in response",
934 sw_space_before_value,
936 sw_space_after_value,
938 sw_header_almost_done
943 for (p = ctx->
response->
pos; p < ctx->response->last; p++) {
954 state = sw_header_almost_done;
963 c = (u_char) (ch | 0x20);
964 if (c >=
'a' && c <=
'z') {
968 if (ch >=
'0' && ch <=
'9') {
978 c = (u_char) (ch | 0x20);
979 if (c >=
'a' && c <=
'z') {
985 state = sw_space_before_value;
993 if (ch >=
'0' && ch <=
'9') {
1001 state = sw_almost_done;
1015 case sw_space_before_value:
1022 state = sw_almost_done;
1040 state = sw_space_after_value;
1044 state = sw_almost_done;
1053 case sw_space_after_value:
1058 state = sw_almost_done;
1069 case sw_almost_done:
1078 case sw_header_almost_done:
1096 ctx->
state = sw_start;
1103 ctx->
state = sw_start;
1117 "mail auth http block read");
1136 "mail auth http dummy handler");
1149 if (ngx_mail_auth_http_escape(pool, &s->
login, &login) !=
NGX_OK) {
1153 if (ngx_mail_auth_http_escape(pool, &s->
passwd, &passwd) !=
NGX_OK) {
1159 len =
sizeof(
"GET ") - 1 + ahcf->
uri.
len +
sizeof(
" HTTP/1.0" CRLF) - 1
1161 +
sizeof(
"Auth-Method: ") - 1
1164 +
sizeof(
"Auth-User: ") - 1 + login.
len +
sizeof(
CRLF) - 1
1165 +
sizeof(
"Auth-Pass: ") - 1 + passwd.
len +
sizeof(
CRLF) - 1
1166 +
sizeof(
"Auth-Salt: ") - 1 + s->
salt.
len
1173 +
sizeof(
"Client-Host: ") - 1 + s->
host.
len +
sizeof(
CRLF) - 1
1176 +
sizeof(
"Auth-SMTP-To: ") - 1 + s->
smtp_to.
len
1188 sizeof(
" HTTP/1.0" CRLF) - 1);
1196 sizeof(
"Auth-Method: ") - 1);
1218 sizeof(
"Auth-Protocol: ") - 1);
1233 sizeof(
"Client-Host: ") - 1);
1243 sizeof(
"Auth-SMTP-Helo: ") - 1);
1248 sizeof(
"Auth-SMTP-From: ") - 1);
1253 sizeof(
"Auth-SMTP-To: ") - 1);
1266 #if (NGX_DEBUG_MAIL_PASSWD)
1273 "mail auth http header:\n\"%V\"", &l);
1294 escaped->
len = text->
len + n * 2;
1310 ngx_mail_auth_http_create_conf(
ngx_conf_t *cf)
1329 ngx_mail_auth_http_merge_conf(
ngx_conf_t *cf,
void *parent,
void *child)
1339 if (conf->
peer == NULL) {
1344 if (conf->
peer == NULL) {
1346 "no \"auth_http\" is defined for server in %s:%ui",
1377 *p++ =
':'; *p++ =
' ';
1379 *p++ =
CR; *p++ =
LF;
1411 "%s in auth_http \"%V\"", u.
err, &u.
url);
1419 if (u.
family != AF_UNIX) {
1428 if (ahcf->
uri.
len == 0) {
1452 if (header == NULL) {
1458 header->
key = value[1];
1459 header->
value = value[2];