comparison src/mail/ngx_mail_auth_http_module.c @ 420:ad0a34a8efa6 NGINX_0_7_22

nginx 0.7.22 *) Feature: the "none" parameter in the "smtp_auth" directive. Thanks to Maxim Dounin. *) Feature: the "$cookie_..." variables. *) Bugfix: the "directio" directive did not work in XFS filesystem. *) Bugfix: the resolver did not understand big DNS responses. Thanks to Zyb.
author Igor Sysoev <http://sysoev.ru>
date Thu, 20 Nov 2008 00:00:00 +0300
parents 12defd37f578
children dac47e9ef0d5
comparison
equal deleted inserted replaced
419:b986babf3f57 420:ad0a34a8efa6
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;
139 138
140 static ngx_str_t ngx_mail_auth_http_method[] = { 139 static ngx_str_t ngx_mail_auth_http_method[] = {
141 ngx_string("plain"), 140 ngx_string("plain"),
142 ngx_string("plain"), 141 ngx_string("plain"),
143 ngx_string("apop"), 142 ngx_string("apop"),
144 ngx_string("cram-md5") 143 ngx_string("cram-md5"),
144 ngx_string("none")
145 }; 145 };
146 146
147 static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0"); 147 static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
148 148
149 149
912 static ngx_int_t 912 static ngx_int_t
913 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,
914 ngx_mail_auth_http_ctx_t *ctx) 914 ngx_mail_auth_http_ctx_t *ctx)
915 { 915 {
916 u_char c, ch, *p; 916 u_char c, ch, *p;
917 ngx_uint_t hash;
918 enum { 917 enum {
919 sw_start = 0, 918 sw_start = 0,
920 sw_name, 919 sw_name,
921 sw_space_before_value, 920 sw_space_before_value,
922 sw_value, 921 sw_value,
924 sw_almost_done, 923 sw_almost_done,
925 sw_header_almost_done 924 sw_header_almost_done
926 } state; 925 } state;
927 926
928 state = ctx->state; 927 state = ctx->state;
929 hash = ctx->hash;
930 928
931 for (p = ctx->response->pos; p < ctx->response->last; p++) { 929 for (p = ctx->response->pos; p < ctx->response->last; p++) {
932 ch = *p; 930 ch = *p;
933 931
934 switch (state) { 932 switch (state) {
948 state = sw_name; 946 state = sw_name;
949 ctx->header_name_start = p; 947 ctx->header_name_start = p;
950 948
951 c = (u_char) (ch | 0x20); 949 c = (u_char) (ch | 0x20);
952 if (c >= 'a' && c <= 'z') { 950 if (c >= 'a' && c <= 'z') {
953 hash = c;
954 break; 951 break;
955 } 952 }
956 953
957 if (ch >= '0' && ch <= '9') { 954 if (ch >= '0' && ch <= '9') {
958 hash = ch;
959 break; 955 break;
960 } 956 }
961 957
962 return NGX_ERROR; 958 return NGX_ERROR;
963 } 959 }
965 961
966 /* header name */ 962 /* header name */
967 case sw_name: 963 case sw_name:
968 c = (u_char) (ch | 0x20); 964 c = (u_char) (ch | 0x20);
969 if (c >= 'a' && c <= 'z') { 965 if (c >= 'a' && c <= 'z') {
970 hash += c;
971 break; 966 break;
972 } 967 }
973 968
974 if (ch == ':') { 969 if (ch == ':') {
975 ctx->header_name_end = p; 970 ctx->header_name_end = p;
976 state = sw_space_before_value; 971 state = sw_space_before_value;
977 break; 972 break;
978 } 973 }
979 974
980 if (ch == '-') { 975 if (ch == '-') {
981 hash += ch;
982 break; 976 break;
983 } 977 }
984 978
985 if (ch >= '0' && ch <= '9') { 979 if (ch >= '0' && ch <= '9') {
986 hash += ch;
987 break; 980 break;
988 } 981 }
989 982
990 if (ch == CR) { 983 if (ch == CR) {
991 ctx->header_name_end = p; 984 ctx->header_name_end = p;
1078 } 1071 }
1079 } 1072 }
1080 1073
1081 ctx->response->pos = p; 1074 ctx->response->pos = p;
1082 ctx->state = state; 1075 ctx->state = state;
1083 ctx->hash = hash;
1084 1076
1085 return NGX_AGAIN; 1077 return NGX_AGAIN;
1086 1078
1087 done: 1079 done:
1088 1080
1089 ctx->response->pos = p + 1; 1081 ctx->response->pos = p + 1;
1090 ctx->state = sw_start; 1082 ctx->state = sw_start;
1091 ctx->hash = hash;
1092 1083
1093 return NGX_OK; 1084 return NGX_OK;
1094 1085
1095 header_done: 1086 header_done:
1096 1087
1163 + sizeof(CRLF) - 1 1154 + sizeof(CRLF) - 1
1164 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN 1155 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN
1165 + sizeof(CRLF) - 1 1156 + sizeof(CRLF) - 1
1166 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len 1157 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
1167 + sizeof(CRLF) - 1 1158 + sizeof(CRLF) - 1
1159 + sizeof("Client-Host: ") - 1 + s->host.len + sizeof(CRLF) - 1
1160 + sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len
1161 + sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len
1162 + sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len
1168 + ahcf->header.len 1163 + ahcf->header.len
1169 + sizeof(CRLF) - 1; 1164 + sizeof(CRLF) - 1;
1170 1165
1171 b = ngx_create_temp_buf(pool, len); 1166 b = ngx_create_temp_buf(pool, len);
1172 if (b == NULL) { 1167 if (b == NULL) {
1214 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF, 1209 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF,
1215 s->login_attempt); 1210 s->login_attempt);
1216 1211
1217 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);
1218 b->last = ngx_copy(b->last, s->connection->addr_text.data, 1213 b->last = ngx_copy(b->last, s->connection->addr_text.data,
1219 s->connection->addr_text.len); 1214 s->connection->addr_text.len);
1220 *b->last++ = CR; *b->last++ = LF; 1215 *b->last++ = CR; *b->last++ = LF;
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
1224 if (s->auth_method == NGX_MAIL_AUTH_NONE) {
1225
1226 /* HELO, MAIL FROM, and RCPT TO can't contain CRLF, no need to escape */
1227
1228 b->last = ngx_cpymem(b->last, "Auth-SMTP-Helo: ",
1229 sizeof("Auth-SMTP-Helo: ") - 1);
1230 b->last = ngx_copy(b->last, s->smtp_helo.data, s->smtp_helo.len);
1231 *b->last++ = CR; *b->last++ = LF;
1232
1233 b->last = ngx_cpymem(b->last, "Auth-SMTP-From: ",
1234 sizeof("Auth-SMTP-From: ") - 1);
1235 b->last = ngx_copy(b->last, s->smtp_from.data, s->smtp_from.len);
1236 *b->last++ = CR; *b->last++ = LF;
1237
1238 b->last = ngx_cpymem(b->last, "Auth-SMTP-To: ",
1239 sizeof("Auth-SMTP-To: ") - 1);
1240 b->last = ngx_copy(b->last, s->smtp_to.data, s->smtp_to.len);
1241 *b->last++ = CR; *b->last++ = LF;
1242
1243 }
1221 1244
1222 if (ahcf->header.len) { 1245 if (ahcf->header.len) {
1223 b->last = ngx_copy(b->last, ahcf->header.data, ahcf->header.len); 1246 b->last = ngx_copy(b->last, ahcf->header.data, ahcf->header.len);
1224 } 1247 }
1225 1248