-
Notifications
You must be signed in to change notification settings - Fork 13
/
realpath_turbo.c
134 lines (117 loc) · 4.88 KB
/
realpath_turbo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "realpath_turbo.h"
#include "realpath_turbo_private.h"
static zend_function_entry realpath_turbo_functions[] = {
{NULL, NULL, NULL}
};
zend_module_entry realpath_turbo_module_entry = {
STANDARD_MODULE_HEADER,
REALPATH_TURBO_EXTNAME,
realpath_turbo_functions,
PHP_MINIT(realpath_turbo),
PHP_MSHUTDOWN(realpath_turbo),
PHP_RINIT(realpath_turbo),
NULL,
PHP_MINFO(realpath_turbo),
REALPATH_TURBO_VERSION,
PHP_MODULE_GLOBALS(realpath_turbo),
NULL,
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
ZEND_DECLARE_MODULE_GLOBALS(realpath_turbo)
#ifdef COMPILE_DL_REALPATH_TURBO
ZEND_GET_MODULE(realpath_turbo)
#endif
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("realpath_turbo.open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateString, open_basedir, zend_realpath_turbo_globals, realpath_turbo_globals)
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
STD_PHP_INI_BOOLEAN("realpath_turbo.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, zend_realpath_turbo_globals, realpath_turbo_globals)
#endif
STD_PHP_INI_BOOLEAN("realpath_turbo.disable_dangerous_functions", "1", PHP_INI_SYSTEM, OnUpdateBool, disable_dangerous_functions, zend_realpath_turbo_globals, realpath_turbo_globals)
PHP_INI_END()
PHP_RINIT_FUNCTION(realpath_turbo)
{
char *rpt_open_basedir = INI_STR("realpath_turbo.open_basedir");
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
zend_bool *do_safe_mode = INI_BOOL("realpath_turbo.safe_mode");
#endif
char *disabled_functions = INI_STR("disable_functions");
char *disabled_functions_new;
char *risky_functions = "link,symlink";
zend_bool do_disable_dangerous_functions = INI_BOOL("realpath_turbo.disable_dangerous_functions");
#if PHP_MAJOR_VERSION >= 7
zend_string *ini_name, *ini_value;
#endif
if (rpt_open_basedir && *rpt_open_basedir) {
if (PG(open_basedir) && *PG(open_basedir)) {
#if PHP_MAJOR_VERSION >= 7
php_error_docref(NULL, E_WARNING, "open_basedir already set! Please unset open_basedir and only use realpath_turbo.open_basedir option. realpath_turbo will not have any effect when open_basedir is already set.");
#else
php_error_docref(NULL TSRMLS_CC, E_WARNING, "open_basedir already set! Please unset open_basedir and only use realpath_turbo.open_basedir option. realpath_turbo will not have any effect when open_basedir is already set.");
#endif
return FAILURE;
}
#if PHP_MAJOR_VERSION < 7
zend_alter_ini_entry("open_basedir", sizeof("open_basedir"), rpt_open_basedir, strlen(rpt_open_basedir), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
#else
ini_name = zend_string_init(ZEND_STRL("open_basedir"), 0);
ini_value = zend_string_init(rpt_open_basedir, strlen(rpt_open_basedir), 0);
zend_alter_ini_entry(ini_name, ini_value, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
zend_string_release(ini_name);
zend_string_release(ini_value);
#endif
}
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
if (do_safe_mode) {
if (PG(safe_mode) && *PG(safe_mode)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "safe_mode already set! Please disable safe_mode and only use realpath_turbo.safe_mode option. realpath_turbo will not have any effect when safe_mode is already enabled.");
return FAILURE;
}
zend_alter_ini_entry("safe_mode", sizeof("safe_mode"), "1", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}
#endif
if (do_disable_dangerous_functions) {
// check disabled functions for symlink and link entries
if(strlen(disabled_functions) > 0) {
disabled_functions_new = emalloc(strlen(disabled_functions) + strlen(risky_functions) + 2);
strcpy(disabled_functions_new, risky_functions);
strcat(disabled_functions_new, ",");
strcat(disabled_functions_new, disabled_functions);
} else {
disabled_functions_new = emalloc(strlen(risky_functions) + 1);
strcpy(disabled_functions_new, risky_functions);
}
#if PHP_MAJOR_VERSION < 7
zend_alter_ini_entry("disable_functions", sizeof("disable_functions"), disabled_functions_new, strlen(disabled_functions_new), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
#else
ini_name = zend_string_init(ZEND_STRL("disable_functions"), 0);
ini_value = zend_string_init(disabled_functions_new, strlen(disabled_functions_new), 0);
zend_alter_ini_entry(ini_name, ini_value, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
zend_string_release(ini_name);
zend_string_release(ini_value);
#endif
efree(disabled_functions_new);
}
return SUCCESS;
}
PHP_MINIT_FUNCTION(realpath_turbo)
{
REGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(realpath_turbo)
{
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MINFO_FUNCTION(realpath_turbo)
{
php_info_print_table_start();
php_info_print_table_header(2, "realpath_turbo support", "enabled");
php_info_print_table_row(2, "Version", REALPATH_TURBO_VERSION);
php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
php_info_print_table_row(2, "Creator", "Artur Graniszewski");
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}