comparison src/imap/ngx_imap_handler.c @ 258:6ae1357b7b7c NGINX_0_4_14

nginx 0.4.14 *) Feature: the "proxy_pass_error_message" directive in IMAP/POP3 proxy. *) Feature: now configure detects system PCRE library on FreeBSD, Linux, and NetBSD. *) Bugfix: ngx_http_perl_module did not work with perl built with the threads support; bug appeared in 0.3.38. *) Bugfix: ngx_http_perl_module did not work if perl was called recursively. *) Bugfix: nginx ignored a host name in an request line. *) Bugfix: a worker process may got caught in an endless loop, if a FastCGI server sent too many data to the stderr. *) Bugfix: the $upstream_response_time variable may be negative if the system time was changed backward. *) Bugfix: the "Auth-Login-Attempt" parameter was not sent to IMAP/POP3 proxy authentication server when POP3 was used. *) Bugfix: a segmentation fault might occur if connect to IMAP/POP3 proxy authentication server failed.
author Igor Sysoev <http://sysoev.ru>
date Mon, 27 Nov 2006 00:00:00 +0300
parents 644510700914
children 0effe91f6083
comparison
equal deleted inserted replaced
257:0e566ee1bcd5 258:6ae1357b7b7c
10 #include <ngx_imap.h> 10 #include <ngx_imap.h>
11 11
12 12
13 static void ngx_imap_init_session(ngx_connection_t *c); 13 static void ngx_imap_init_session(ngx_connection_t *c);
14 static void ngx_imap_init_protocol(ngx_event_t *rev); 14 static void ngx_imap_init_protocol(ngx_event_t *rev);
15 static void ngx_imap_do_auth(ngx_imap_session_t *s);
15 static ngx_int_t ngx_imap_read_command(ngx_imap_session_t *s); 16 static ngx_int_t ngx_imap_read_command(ngx_imap_session_t *s);
16 static u_char *ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len); 17 static u_char *ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len);
17 18
18 #if (NGX_IMAP_SSL) 19 #if (NGX_IMAP_SSL)
19 static void ngx_imap_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); 20 static void ngx_imap_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
535 #else 536 #else
536 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, 537 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
537 "imap login:\"%V\"", &s->login); 538 "imap login:\"%V\"", &s->login);
538 #endif 539 #endif
539 540
540 s->args.nelts = 0; 541 ngx_imap_do_auth(s);
541 s->buffer->pos = s->buffer->start;
542 s->buffer->last = s->buffer->start;
543
544 if (rev->timer_set) {
545 ngx_del_timer(rev);
546 }
547
548 s->login_attempt++;
549
550 ngx_imap_auth_http_init(s);
551
552 return; 542 return;
553 } 543 }
554 544
555 rc = NGX_IMAP_PARSE_INVALID_COMMAND; 545 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
556 break; 546 break;
787 "pop3 apop: \"%V\" \"%V\"", 777 "pop3 apop: \"%V\" \"%V\"",
788 &s->login, &s->passwd); 778 &s->login, &s->passwd);
789 779
790 s->auth_method = NGX_IMAP_AUTH_APOP; 780 s->auth_method = NGX_IMAP_AUTH_APOP;
791 781
792 s->args.nelts = 0; 782 ngx_imap_do_auth(s);
793 s->buffer->pos = s->buffer->start;
794 s->buffer->last = s->buffer->start;
795
796 if (rev->timer_set) {
797 ngx_del_timer(rev);
798 }
799
800 ngx_imap_auth_http_init(s);
801
802 return; 783 return;
803 } 784 }
804 785
805 rc = NGX_IMAP_PARSE_INVALID_COMMAND; 786 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
806 break; 787 break;
920 #if (NGX_DEBUG_IMAP_PASSWD) 901 #if (NGX_DEBUG_IMAP_PASSWD)
921 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, 902 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
922 "pop3 passwd: \"%V\"", &s->passwd); 903 "pop3 passwd: \"%V\"", &s->passwd);
923 #endif 904 #endif
924 905
925 s->args.nelts = 0; 906 ngx_imap_do_auth(s);
926 s->buffer->pos = s->buffer->start;
927 s->buffer->last = s->buffer->start;
928
929 if (rev->timer_set) {
930 ngx_del_timer(rev);
931 }
932
933 ngx_imap_auth_http_init(s);
934
935 return; 907 return;
936 } 908 }
937 909
938 rc = NGX_IMAP_PARSE_INVALID_COMMAND; 910 rc = NGX_IMAP_PARSE_INVALID_COMMAND;
939 break; 911 break;
1019 #if (NGX_DEBUG_IMAP_PASSWD) 991 #if (NGX_DEBUG_IMAP_PASSWD)
1020 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, 992 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
1021 "pop3 auth login password: \"%V\"", &s->passwd); 993 "pop3 auth login password: \"%V\"", &s->passwd);
1022 #endif 994 #endif
1023 995
1024 s->args.nelts = 0; 996 ngx_imap_do_auth(s);
1025 s->buffer->pos = s->buffer->start;
1026 s->buffer->last = s->buffer->start;
1027
1028 if (rev->timer_set) {
1029 ngx_del_timer(rev);
1030 }
1031
1032 ngx_imap_auth_http_init(s);
1033
1034 return; 997 return;
1035 998
1036 case ngx_pop3_auth_plain: 999 case ngx_pop3_auth_plain:
1037 arg = s->args.elts; 1000 arg = s->args.elts;
1038 1001
1090 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0, 1053 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0,
1091 "pop3 auth plain: \"%V\" \"%V\"", 1054 "pop3 auth plain: \"%V\" \"%V\"",
1092 &s->login, &s->passwd); 1055 &s->login, &s->passwd);
1093 #endif 1056 #endif
1094 1057
1095 s->args.nelts = 0; 1058 ngx_imap_do_auth(s);
1096 s->buffer->pos = s->buffer->start;
1097 s->buffer->last = s->buffer->start;
1098
1099 if (rev->timer_set) {
1100 ngx_del_timer(rev);
1101 }
1102
1103 ngx_imap_auth_http_init(s);
1104
1105 return; 1059 return;
1106 1060
1107 case ngx_pop3_auth_cram_md5: 1061 case ngx_pop3_auth_cram_md5:
1108 arg = s->args.elts; 1062 arg = s->args.elts;
1109 1063
1149 "pop3 auth cram-md5: \"%V\" \"%V\"", 1103 "pop3 auth cram-md5: \"%V\" \"%V\"",
1150 &s->login, &s->passwd); 1104 &s->login, &s->passwd);
1151 1105
1152 s->auth_method = NGX_IMAP_AUTH_CRAM_MD5; 1106 s->auth_method = NGX_IMAP_AUTH_CRAM_MD5;
1153 1107
1154 s->args.nelts = 0; 1108 ngx_imap_do_auth(s);
1155 s->buffer->pos = s->buffer->start;
1156 s->buffer->last = s->buffer->start;
1157
1158 if (rev->timer_set) {
1159 ngx_del_timer(rev);
1160 }
1161
1162 ngx_imap_auth_http_init(s);
1163
1164 return; 1109 return;
1165 } 1110 }
1166 } 1111 }
1167 1112
1168 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) { 1113 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) {
1185 1130
1186 ngx_imap_send(c->write); 1131 ngx_imap_send(c->write);
1187 } 1132 }
1188 1133
1189 1134
1135 static void
1136 ngx_imap_do_auth(ngx_imap_session_t *s)
1137 {
1138 s->args.nelts = 0;
1139 s->buffer->pos = s->buffer->start;
1140 s->buffer->last = s->buffer->start;
1141 s->state = 0;
1142
1143 if (s->connection->read->timer_set) {
1144 ngx_del_timer(s->connection->read);
1145 }
1146
1147 s->login_attempt++;
1148
1149 ngx_imap_auth_http_init(s);
1150 }
1151
1152
1190 static ngx_int_t 1153 static ngx_int_t
1191 ngx_imap_read_command(ngx_imap_session_t *s) 1154 ngx_imap_read_command(ngx_imap_session_t *s)
1192 { 1155 {
1193 ssize_t n; 1156 ssize_t n;
1194 ngx_int_t rc; 1157 ngx_int_t rc;