| 1050 | | /* {{{ xcache_op */ |
| | 1051 | static int xcache_admin_auth_check(TSRMLS_C) /* {{{ */ |
| | 1052 | { |
| | 1053 | zval **server = NULL; |
| | 1054 | zval **user = NULL; |
| | 1055 | zval **pass = NULL; |
| | 1056 | char *admin_user = NULL; |
| | 1057 | char *admin_pass = NULL; |
| | 1058 | HashTable *ht; |
| | 1059 | |
| | 1060 | if (cfg_get_string("xcache.admin.user", &admin_user) == FAILURE || !admin_user[0]) { |
| | 1061 | admin_user = NULL; |
| | 1062 | } |
| | 1063 | if (cfg_get_string("xcache.admin.pass", &admin_pass) == FAILURE || !admin_pass[0]) { |
| | 1064 | admin_pass = NULL; |
| | 1065 | } |
| | 1066 | |
| | 1067 | if (admin_user == NULL || admin_pass == NULL) { |
| | 1068 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "xcache.admin.user and xcache.admin.pass is required"); |
| | 1069 | zend_bailout(); |
| | 1070 | } |
| | 1071 | if (strlen(admin_pass) != 32) { |
| | 1072 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "unexpect %d bytes of xcache.admin.pass, expected 32 bytes, the password after md5()", strlen(admin_pass)); |
| | 1073 | zend_bailout(); |
| | 1074 | } |
| | 1075 | |
| | 1076 | if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &server) != SUCCESS || Z_TYPE_PP(server) != IS_ARRAY) { |
| | 1077 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "_SERVER is corrupted"); |
| | 1078 | zend_bailout(); |
| | 1079 | } |
| | 1080 | ht = HASH_OF((*server)); |
| | 1081 | |
| | 1082 | if (zend_hash_find(ht, "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &user) == FAILURE) { |
| | 1083 | user = NULL; |
| | 1084 | } |
| | 1085 | else if (Z_TYPE_PP(user) != IS_STRING) { |
| | 1086 | user = NULL; |
| | 1087 | } |
| | 1088 | |
| | 1089 | if (zend_hash_find(ht, "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &pass) == FAILURE) { |
| | 1090 | pass = NULL; |
| | 1091 | } |
| | 1092 | else if (Z_TYPE_PP(pass) != IS_STRING) { |
| | 1093 | pass = NULL; |
| | 1094 | } |
| | 1095 | |
| | 1096 | if (user != NULL && pass != NULL && strcmp(admin_user, Z_STRVAL_PP(user)) == 0) { |
| | 1097 | PHP_MD5_CTX context; |
| | 1098 | char md5str[33]; |
| | 1099 | unsigned char digest[16]; |
| | 1100 | |
| | 1101 | PHP_MD5Init(&context); |
| | 1102 | PHP_MD5Update(&context, Z_STRVAL_PP(pass), Z_STRLEN_PP(pass)); |
| | 1103 | PHP_MD5Final(digest, &context); |
| | 1104 | |
| | 1105 | md5str[0] = '\0'; |
| | 1106 | make_digest(md5str, digest); |
| | 1107 | if (strcmp(admin_pass, md5str) == 0) { |
| | 1108 | return 1; |
| | 1109 | } |
| | 1110 | } |
| | 1111 | |
| | 1112 | #define STR "WWW-authenticate: basic realm='XCache Administration'" |
| | 1113 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
| | 1114 | #undef STR |
| | 1115 | #define STR "HTTP/1.0 401 Unauthorized" |
| | 1116 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
| | 1117 | #undef STR |
| | 1118 | ZEND_PUTS("XCache Auth Failed. User and Password is case sense\n"); |
| | 1119 | |
| | 1120 | zend_bailout(); |
| | 1121 | return 0; |
| | 1122 | } |
| | 1123 | /* }}} */ |
| | 1124 | /* {{{ xcache_admin_operate */ |