comparison src/http/ngx_http_core_module.c @ 88:e916a291e9aa NGINX_0_1_44

nginx 0.1.44 *) Feature: the IMAP/POP3 proxy supports SSL. *) Feature: the "proxy_timeout" directive of the ngx_imap_proxy_module. *) Feature: the "userid_mark" directive. *) Feature: the $remote_user variable value is determined independently of authorization use.
author Igor Sysoev <http://sysoev.ru>
date Tue, 06 Sep 2005 00:00:00 +0400
parents 991c6e4c7654
children 71c46860eb55
comparison
equal deleted inserted replaced
87:5b7ec80c3c40 88:e916a291e9aa
923 break; 923 break;
924 } 924 }
925 } 925 }
926 926
927 r->low_case_exten = 0; 927 r->low_case_exten = 0;
928
929 return NGX_OK;
930 }
931
932
933 ngx_int_t
934 ngx_http_auth_basic_user(ngx_http_request_t *r)
935 {
936 ngx_str_t auth, encoded;
937 ngx_uint_t len;
938
939 if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
940 return NGX_DECLINED;
941 }
942
943 if (r->headers_in.authorization == NULL) {
944 r->headers_in.user.data = (u_char *) "";
945 return NGX_DECLINED;
946 }
947
948 encoded = r->headers_in.authorization->value;
949
950 if (encoded.len < sizeof("Basic ") - 1
951 || ngx_strncasecmp(encoded.data, "Basic ", sizeof("Basic ") - 1) != 0)
952 {
953 r->headers_in.user.data = (u_char *) "";
954 return NGX_DECLINED;
955 }
956
957 encoded.len -= sizeof("Basic ") - 1;
958 encoded.data += sizeof("Basic ") - 1;
959
960 while (encoded.len && encoded.data[0] == ' ') {
961 encoded.len--;
962 encoded.data++;
963 }
964
965 if (encoded.len == 0) {
966 r->headers_in.user.data = (u_char *) "";
967 return NGX_DECLINED;
968 }
969
970 auth.len = ngx_base64_decoded_length(encoded.len);
971 auth.data = ngx_palloc(r->pool, auth.len + 1);
972 if (auth.data == NULL) {
973 return NGX_ERROR;
974 }
975
976 if (ngx_decode_base64(&auth, &encoded) != NGX_OK) {
977 r->headers_in.user.data = (u_char *) "";
978 return NGX_DECLINED;
979 }
980
981 auth.data[auth.len] = '\0';
982
983 for (len = 0; len < auth.len; len++) {
984 if (auth.data[len] == ':') {
985 break;
986 }
987 }
988
989 if (len == auth.len) {
990 r->headers_in.user.data = (u_char *) "";
991 return NGX_DECLINED;
992 }
993
994 r->headers_in.user.len = len;
995 r->headers_in.user.data = auth.data;
996 r->headers_in.passwd.len = auth.len - len - 1;
997 r->headers_in.passwd.data = &auth.data[len + 1];
928 998
929 return NGX_OK; 999 return NGX_OK;
930 } 1000 }
931 1001
932 1002