Mercurial > hg > nginx-mail
comparison src/mail/ngx_mail_auth_http_module.c @ 467:d67e93e97b4a
Merge with nginx 0.7.30.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 11 Jan 2009 17:17:57 +0300 |
parents | cd9cb7a3ff9e dac47e9ef0d5 |
children | 9773720b845e |
comparison
equal
deleted
inserted
replaced
444:4c92e29a7375 | 467:d67e93e97b4a |
---|---|
38 ngx_peer_connection_t peer; | 38 ngx_peer_connection_t peer; |
39 | 39 |
40 ngx_mail_auth_http_handler_pt handler; | 40 ngx_mail_auth_http_handler_pt handler; |
41 | 41 |
42 ngx_uint_t state; | 42 ngx_uint_t state; |
43 ngx_uint_t hash; /* no needed ? */ | |
44 | 43 |
45 u_char *header_name_start; | 44 u_char *header_name_start; |
46 u_char *header_name_end; | 45 u_char *header_name_end; |
47 u_char *header_start; | 46 u_char *header_start; |
48 u_char *header_end; | 47 u_char *header_end; |
267 | 266 |
268 if (wev->timer_set) { | 267 if (wev->timer_set) { |
269 ngx_del_timer(wev); | 268 ngx_del_timer(wev); |
270 } | 269 } |
271 | 270 |
272 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { | 271 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
273 ngx_close_connection(c); | 272 ngx_close_connection(c); |
274 ngx_destroy_pool(ctx->pool); | 273 ngx_destroy_pool(ctx->pool); |
275 ngx_mail_session_internal_server_error(s); | 274 ngx_mail_session_internal_server_error(s); |
276 } | 275 } |
277 | 276 |
893 if (rev->ready) { | 892 if (rev->ready) { |
894 rev->handler(rev); | 893 rev->handler(rev); |
895 return; | 894 return; |
896 } | 895 } |
897 | 896 |
898 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 897 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
899 ngx_mail_close_connection(c); | 898 ngx_mail_close_connection(c); |
900 } | 899 } |
901 | 900 |
902 return; | 901 return; |
903 } | 902 } |
904 | 903 |
905 if (rev->active) { | 904 if (rev->active) { |
906 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 905 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
907 ngx_mail_close_connection(c); | 906 ngx_mail_close_connection(c); |
908 } | 907 } |
909 } | 908 } |
910 } | 909 } |
911 | 910 |
913 static ngx_int_t | 912 static ngx_int_t |
914 ngx_mail_auth_http_parse_header_line(ngx_mail_session_t *s, | 913 ngx_mail_auth_http_parse_header_line(ngx_mail_session_t *s, |
915 ngx_mail_auth_http_ctx_t *ctx) | 914 ngx_mail_auth_http_ctx_t *ctx) |
916 { | 915 { |
917 u_char c, ch, *p; | 916 u_char c, ch, *p; |
918 ngx_uint_t hash; | |
919 enum { | 917 enum { |
920 sw_start = 0, | 918 sw_start = 0, |
921 sw_name, | 919 sw_name, |
922 sw_space_before_value, | 920 sw_space_before_value, |
923 sw_value, | 921 sw_value, |
925 sw_almost_done, | 923 sw_almost_done, |
926 sw_header_almost_done | 924 sw_header_almost_done |
927 } state; | 925 } state; |
928 | 926 |
929 state = ctx->state; | 927 state = ctx->state; |
930 hash = ctx->hash; | |
931 | 928 |
932 for (p = ctx->response->pos; p < ctx->response->last; p++) { | 929 for (p = ctx->response->pos; p < ctx->response->last; p++) { |
933 ch = *p; | 930 ch = *p; |
934 | 931 |
935 switch (state) { | 932 switch (state) { |
949 state = sw_name; | 946 state = sw_name; |
950 ctx->header_name_start = p; | 947 ctx->header_name_start = p; |
951 | 948 |
952 c = (u_char) (ch | 0x20); | 949 c = (u_char) (ch | 0x20); |
953 if (c >= 'a' && c <= 'z') { | 950 if (c >= 'a' && c <= 'z') { |
954 hash = c; | |
955 break; | 951 break; |
956 } | 952 } |
957 | 953 |
958 if (ch >= '0' && ch <= '9') { | 954 if (ch >= '0' && ch <= '9') { |
959 hash = ch; | |
960 break; | 955 break; |
961 } | 956 } |
962 | 957 |
963 return NGX_ERROR; | 958 return NGX_ERROR; |
964 } | 959 } |
966 | 961 |
967 /* header name */ | 962 /* header name */ |
968 case sw_name: | 963 case sw_name: |
969 c = (u_char) (ch | 0x20); | 964 c = (u_char) (ch | 0x20); |
970 if (c >= 'a' && c <= 'z') { | 965 if (c >= 'a' && c <= 'z') { |
971 hash += c; | |
972 break; | 966 break; |
973 } | 967 } |
974 | 968 |
975 if (ch == ':') { | 969 if (ch == ':') { |
976 ctx->header_name_end = p; | 970 ctx->header_name_end = p; |
977 state = sw_space_before_value; | 971 state = sw_space_before_value; |
978 break; | 972 break; |
979 } | 973 } |
980 | 974 |
981 if (ch == '-') { | 975 if (ch == '-') { |
982 hash += ch; | |
983 break; | 976 break; |
984 } | 977 } |
985 | 978 |
986 if (ch >= '0' && ch <= '9') { | 979 if (ch >= '0' && ch <= '9') { |
987 hash += ch; | |
988 break; | 980 break; |
989 } | 981 } |
990 | 982 |
991 if (ch == CR) { | 983 if (ch == CR) { |
992 ctx->header_name_end = p; | 984 ctx->header_name_end = p; |
1079 } | 1071 } |
1080 } | 1072 } |
1081 | 1073 |
1082 ctx->response->pos = p; | 1074 ctx->response->pos = p; |
1083 ctx->state = state; | 1075 ctx->state = state; |
1084 ctx->hash = hash; | |
1085 | 1076 |
1086 return NGX_AGAIN; | 1077 return NGX_AGAIN; |
1087 | 1078 |
1088 done: | 1079 done: |
1089 | 1080 |
1090 ctx->response->pos = p + 1; | 1081 ctx->response->pos = p + 1; |
1091 ctx->state = sw_start; | 1082 ctx->state = sw_start; |
1092 ctx->hash = hash; | |
1093 | 1083 |
1094 return NGX_OK; | 1084 return NGX_OK; |
1095 | 1085 |
1096 header_done: | 1086 header_done: |
1097 | 1087 |
1110 ngx_mail_auth_http_ctx_t *ctx; | 1100 ngx_mail_auth_http_ctx_t *ctx; |
1111 | 1101 |
1112 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | 1102 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
1113 "mail auth http block read"); | 1103 "mail auth http block read"); |
1114 | 1104 |
1115 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 1105 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
1116 c = rev->data; | 1106 c = rev->data; |
1117 s = c->data; | 1107 s = c->data; |
1118 | 1108 |
1119 ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module); | 1109 ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module); |
1120 | 1110 |
1164 + sizeof(CRLF) - 1 | 1154 + sizeof(CRLF) - 1 |
1165 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN | 1155 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN |
1166 + sizeof(CRLF) - 1 | 1156 + sizeof(CRLF) - 1 |
1167 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len | 1157 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len |
1168 + sizeof(CRLF) - 1 | 1158 + sizeof(CRLF) - 1 |
1159 + sizeof("Client-Host: ") - 1 + s->host.len + sizeof(CRLF) - 1 | |
1169 + sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len | 1160 + sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len |
1170 + sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len | 1161 + sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len |
1171 + sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len | 1162 + sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len |
1172 + ahcf->header.len | 1163 + ahcf->header.len |
1173 + sizeof(CRLF) - 1; | 1164 + sizeof(CRLF) - 1; |
1218 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF, | 1209 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF, |
1219 s->login_attempt); | 1210 s->login_attempt); |
1220 | 1211 |
1221 b->last = ngx_cpymem(b->last, "Client-IP: ", sizeof("Client-IP: ") - 1); | 1212 b->last = ngx_cpymem(b->last, "Client-IP: ", sizeof("Client-IP: ") - 1); |
1222 b->last = ngx_copy(b->last, s->connection->addr_text.data, | 1213 b->last = ngx_copy(b->last, s->connection->addr_text.data, |
1223 s->connection->addr_text.len); | 1214 s->connection->addr_text.len); |
1224 *b->last++ = CR; *b->last++ = LF; | 1215 *b->last++ = CR; *b->last++ = LF; |
1225 | 1216 |
1217 if (s->host.len) { | |
1218 b->last = ngx_cpymem(b->last, "Client-Host: ", | |
1219 sizeof("Client-Host: ") - 1); | |
1220 b->last = ngx_copy(b->last, s->host.data, s->host.len); | |
1221 *b->last++ = CR; *b->last++ = LF; | |
1222 } | |
1223 | |
1226 if (s->auth_method == NGX_MAIL_AUTH_NONE) { | 1224 if (s->auth_method == NGX_MAIL_AUTH_NONE) { |
1227 | 1225 |
1228 /* HELO / MAIL FROM / RCPT TO can't contain CRLF, no need to escape */ | 1226 /* HELO, MAIL FROM, and RCPT TO can't contain CRLF, no need to escape */ |
1229 | 1227 |
1230 b->last = ngx_cpymem(b->last, "Auth-SMTP-Helo: ", | 1228 b->last = ngx_cpymem(b->last, "Auth-SMTP-Helo: ", |
1231 sizeof("Auth-SMTP-Helo: ") - 1); | 1229 sizeof("Auth-SMTP-Helo: ") - 1); |
1232 b->last = ngx_copy(b->last, s->smtp_helo.data, s->smtp_helo.len); | 1230 b->last = ngx_copy(b->last, s->smtp_helo.data, s->smtp_helo.len); |
1233 *b->last++ = CR; *b->last++ = LF; | 1231 *b->last++ = CR; *b->last++ = LF; |