diff options
| author | Stefan Esser | 2015-12-17 16:35:34 +0100 |
|---|---|---|
| committer | Stefan Esser | 2015-12-17 16:35:34 +0100 |
| commit | c4c9192839ba7842f5da58f5fd525056c77cfe54 (patch) | |
| tree | 810854ddb53e03d7320570ec8d634390a849d6b2 /suhosin7.c | |
| parent | aee7faf18880573b60606756a61faea32a1bb89a (diff) | |
Continue the actual porting work on GitHub
Diffstat (limited to 'suhosin7.c')
| -rw-r--r-- | suhosin7.c | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/suhosin7.c b/suhosin7.c new file mode 100644 index 0000000..ebea5ab --- /dev/null +++ b/suhosin7.c | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | /* | ||
| 2 | +----------------------------------------------------------------------+ | ||
| 3 | | PHP Version 7 | | ||
| 4 | +----------------------------------------------------------------------+ | ||
| 5 | | Copyright (c) 1997-2015 The PHP Group | | ||
| 6 | +----------------------------------------------------------------------+ | ||
| 7 | | This source file is subject to version 3.01 of the PHP license, | | ||
| 8 | | that is bundled with this package in the file LICENSE, and is | | ||
| 9 | | available through the world-wide-web at the following url: | | ||
| 10 | | http://www.php.net/license/3_01.txt | | ||
| 11 | | If you did not receive a copy of the PHP license and are unable to | | ||
| 12 | | obtain it through the world-wide-web, please send a note to | | ||
| 13 | | license@php.net so we can mail you a copy immediately. | | ||
| 14 | +----------------------------------------------------------------------+ | ||
| 15 | | Author: | | ||
| 16 | +----------------------------------------------------------------------+ | ||
| 17 | */ | ||
| 18 | |||
| 19 | /* $Id$ */ | ||
| 20 | |||
| 21 | #ifdef HAVE_CONFIG_H | ||
| 22 | #include "config.h" | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #include "php.h" | ||
| 26 | #include "php_ini.h" | ||
| 27 | #include "SAPI.h" | ||
| 28 | #include "php_suhosin7.h" | ||
| 29 | #include "suhosin7_logo.h" | ||
| 30 | #include "ext/standard/base64.h" | ||
| 31 | #include "ext/standard/info.h" | ||
| 32 | |||
| 33 | |||
| 34 | ZEND_DECLARE_MODULE_GLOBALS(suhosin7) | ||
| 35 | |||
| 36 | /* True global resources - no need for thread safety here */ | ||
| 37 | static int le_suhosin7; | ||
| 38 | |||
| 39 | /* {{{ PHP_INI | ||
| 40 | */ | ||
| 41 | PHP_INI_BEGIN() | ||
| 42 | STD_ZEND_INI_BOOLEAN("suhosin.protectkey", "1", ZEND_INI_SYSTEM, OnUpdateBool, protectkey, zend_suhosin7_globals, suhosin7_globals) | ||
| 43 | STD_ZEND_INI_BOOLEAN("suhosin.cookie.cryptkey", "1", ZEND_INI_SYSTEM, OnUpdateBool, protectkey, zend_suhosin7_globals, suhosin7_globals) | ||
| 44 | STD_PHP_INI_ENTRY("suhosin.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_suhosin7_globals, suhosin7_globals) | ||
| 45 | STD_PHP_INI_ENTRY("suhosin.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_suhosin7_globals, suhosin7_globals) | ||
| 46 | PHP_INI_END() | ||
| 47 | /* }}} */ | ||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | /* {{{ php_suhosin7_init_globals | ||
| 52 | */ | ||
| 53 | static void php_suhosin7_init_globals(zend_suhosin7_globals *suhosin7_globals) | ||
| 54 | { | ||
| 55 | memset(suhosin7_globals, 0, sizeof(zend_suhosin7_globals)); | ||
| 56 | } | ||
| 57 | /* }}} */ | ||
| 58 | |||
| 59 | |||
| 60 | /* {{{ PHP_MINIT_FUNCTION | ||
| 61 | */ | ||
| 62 | PHP_MINIT_FUNCTION(suhosin7) | ||
| 63 | { | ||
| 64 | REGISTER_INI_ENTRIES(); | ||
| 65 | return SUCCESS; | ||
| 66 | } | ||
| 67 | /* }}} */ | ||
| 68 | |||
| 69 | /* {{{ PHP_MSHUTDOWN_FUNCTION | ||
| 70 | */ | ||
| 71 | PHP_MSHUTDOWN_FUNCTION(suhosin7) | ||
| 72 | { | ||
| 73 | UNREGISTER_INI_ENTRIES(); | ||
| 74 | return SUCCESS; | ||
| 75 | } | ||
| 76 | /* }}} */ | ||
| 77 | |||
| 78 | /* Remove if there's nothing to do at request start */ | ||
| 79 | /* {{{ PHP_RINIT_FUNCTION | ||
| 80 | */ | ||
| 81 | PHP_RINIT_FUNCTION(suhosin7) | ||
| 82 | { | ||
| 83 | #if defined(COMPILE_DL_SUHOSIN7) && defined(ZTS) | ||
| 84 | ZEND_TSRMLS_CACHE_UPDATE(); | ||
| 85 | #endif | ||
| 86 | return SUCCESS; | ||
| 87 | } | ||
| 88 | /* }}} */ | ||
| 89 | |||
| 90 | /* Remove if there's nothing to do at request end */ | ||
| 91 | /* {{{ PHP_RSHUTDOWN_FUNCTION | ||
| 92 | */ | ||
| 93 | PHP_RSHUTDOWN_FUNCTION(suhosin7) | ||
| 94 | { | ||
| 95 | return SUCCESS; | ||
| 96 | } | ||
| 97 | /* }}} */ | ||
| 98 | |||
| 99 | /* {{{ suhosin_ini_displayer(zend_ini_entry *ini_entry, int type) | ||
| 100 | */ | ||
| 101 | static void suhosin_ini_displayer(zend_ini_entry *ini_entry, int type) | ||
| 102 | { | ||
| 103 | PHPWRITE("[ protected ]", strlen("[ protected ]")); | ||
| 104 | } | ||
| 105 | /* }}} */ | ||
| 106 | |||
| 107 | /* {{{ PHP_MINFO_FUNCTION | ||
| 108 | */ | ||
| 109 | PHP_MINFO_FUNCTION(suhosin7) | ||
| 110 | { | ||
| 111 | php_info_print_box_start(0); | ||
| 112 | if (!sapi_module.phpinfo_as_text) { | ||
| 113 | do { | ||
| 114 | zend_string *enc_logo; | ||
| 115 | |||
| 116 | PUTS("<a href=\"http://www.suhosin.org/\"><img border=\"0\" src=\"data:image/jpeg;base64,"); | ||
| 117 | enc_logo = php_base64_encode(suhosin_logo, sizeof(suhosin_logo)); | ||
| 118 | if (ZSTR_LEN(enc_logo)) { | ||
| 119 | PHPWRITE(ZSTR_VAL(enc_logo), ZSTR_LEN(enc_logo)); | ||
| 120 | } | ||
| 121 | zend_string_free(enc_logo); | ||
| 122 | PUTS("\" alt=\"Suhosin logo\" /></a>\n"); | ||
| 123 | } while(0); | ||
| 124 | } | ||
| 125 | PUTS("This server is protected with the Suhosin Extension " SUHOSIN7_EXT_VERSION); | ||
| 126 | PUTS(!sapi_module.phpinfo_as_text?"<br /><br />":"\n\n"); | ||
| 127 | if (sapi_module.phpinfo_as_text) { | ||
| 128 | PUTS("Copyright (c) 2006-2007 Hardened-PHP Project\n"); | ||
| 129 | PUTS("Copyright (c) 2007-2015 SektionEins GmbH\n"); | ||
| 130 | } else { | ||
| 131 | PUTS("Copyright (c) 2006-2007 <a href=\"http://www.hardened-php.net/\">Hardened-PHP Project</a><br />\n"); | ||
| 132 | PUTS("Copyright (c) 2007-2015 <a href=\"http://www.sektioneins.de/\">SektionEins GmbH</a>\n"); | ||
| 133 | } | ||
| 134 | php_info_print_box_end(); | ||
| 135 | |||
| 136 | if (SUHOSIN7_G(protectkey)) { | ||
| 137 | zend_ini_entry *i; | ||
| 138 | |||
| 139 | if ((i=zend_hash_str_find_ptr(EG(ini_directives), "suhosin.cookie.cryptkey", sizeof("suhosin.cookie.cryptkey")-1))) { | ||
| 140 | i->displayer = suhosin_ini_displayer; | ||
| 141 | } | ||
| 142 | if ((i=zend_hash_str_find_ptr(EG(ini_directives), "suhosin.session.cryptkey", sizeof("suhosin.session.cryptkey")-1))) { | ||
| 143 | i->displayer = suhosin_ini_displayer; | ||
| 144 | } | ||
| 145 | if ((i=zend_hash_str_find_ptr(EG(ini_directives), "suhosin.rand.seedingkey", sizeof("suhosin.rand.seedingkey")-1))) { | ||
| 146 | i->displayer = suhosin_ini_displayer; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | DISPLAY_INI_ENTRIES(); | ||
| 151 | |||
| 152 | if (SUHOSIN7_G(protectkey)) { | ||
| 153 | zend_ini_entry *i; | ||
| 154 | |||
| 155 | if ((i=zend_hash_str_find_ptr(EG(ini_directives), "suhosin.cookie.cryptkey", sizeof("suhosin.cookie.cryptkey")))) { | ||
| 156 | i->displayer = NULL; | ||
| 157 | } | ||
| 158 | if ((i=zend_hash_str_find_ptr(EG(ini_directives), "suhosin.session.cryptkey", sizeof("suhosin.session.cryptkey")-1))) { | ||
| 159 | i->displayer = NULL; | ||
| 160 | } | ||
| 161 | if ((i=zend_hash_str_find_ptr(EG(ini_directives), "suhosin.rand.seedingkey", sizeof("suhosin.rand.seedingkey")-1))) { | ||
| 162 | i->displayer = NULL; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | } | ||
| 167 | /* }}} */ | ||
| 168 | |||
| 169 | /* {{{ suhosin7_functions[] | ||
| 170 | * | ||
| 171 | * Every user visible function must have an entry in suhosin7_functions[]. | ||
| 172 | */ | ||
| 173 | const zend_function_entry suhosin7_functions[] = { | ||
| 174 | // PHP_FE(confirm_suhosin7_compiled, NULL) /* For testing, remove later. */ | ||
| 175 | PHP_FE_END | ||
| 176 | }; | ||
| 177 | /* }}} */ | ||
| 178 | |||
| 179 | /* {{{ suhosin7_module_entry | ||
| 180 | */ | ||
| 181 | zend_module_entry suhosin7_module_entry = { | ||
| 182 | STANDARD_MODULE_HEADER, | ||
| 183 | "suhosin7", | ||
| 184 | suhosin7_functions, | ||
| 185 | PHP_MINIT(suhosin7), | ||
| 186 | PHP_MSHUTDOWN(suhosin7), | ||
| 187 | PHP_RINIT(suhosin7), /* Replace with NULL if there's nothing to do at request start */ | ||
| 188 | PHP_RSHUTDOWN(suhosin7), /* Replace with NULL if there's nothing to do at request end */ | ||
| 189 | PHP_MINFO(suhosin7), | ||
| 190 | SUHOSIN7_EXT_VERSION, | ||
| 191 | STANDARD_MODULE_PROPERTIES | ||
| 192 | }; | ||
| 193 | /* }}} */ | ||
| 194 | |||
| 195 | #ifdef COMPILE_DL_SUHOSIN7 | ||
| 196 | #ifdef ZTS | ||
| 197 | ZEND_TSRMLS_CACHE_DEFINE(); | ||
| 198 | #endif | ||
| 199 | ZEND_GET_MODULE(suhosin7) | ||
| 200 | #endif | ||
| 201 | |||
| 202 | /* | ||
| 203 | * Local variables: | ||
| 204 | * tab-width: 4 | ||
| 205 | * c-basic-offset: 4 | ||
| 206 | * End: | ||
| 207 | * vim600: noet sw=4 ts=4 fdm=marker | ||
| 208 | * vim<600: noet sw=4 ts=4 | ||
| 209 | */ | ||
