Skip to content

Commit

Permalink
Rename everything to realpath_turbo
Browse files Browse the repository at this point in the history
Closes: #7
  • Loading branch information
Whissi committed Oct 5, 2016
1 parent 12154ff commit c4c610f
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 159 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ workaround:
## How *realpath_turbo* works

1. Instead of setting `open_basedir` you will set
`realpath_cache_basedir`.
`realpath_turbo.open_basedir`.

Because now `open_basedir` isn't set, PHP will **not** deactivate the
realpath cache.
Expand All @@ -45,28 +45,29 @@ workaround:
# make install
```

3. Adjust your `php.ini` to load and configure *turbo_realpath* extension.
3. Adjust your `php.ini` to load and configure *realpath_turbo* extension.


## Configuration

```ini
; you have to load the extension first
extension=turbo_realpath.so
extension=realpath_turbo.so
; realpath_turbo security mode
; Disable dangerous functions (see the warning in the README file for
; details).
; Possible values:
; 0 - Ignore potential security issues
; 1 - Disable dangerous PHP functions (link,symlink)
realpath_cache_security = 1
realpath_turbo.disable_dangerous_functions = 1
; Set realpath_cache_basedir to whatever you want to set open_basedir to
realpath_cache_basedir = "/var/www/html/drupal:/usr/share/php"
; Set realpath_turbo.open_basedir to whatever you want to set open_basedir to
realpath_turbo.open_basedir = "/var/www/html/drupal:/usr/share/php"
; Disable PHP's open_basedir directive so that the realpath cache won't be
; disabled.
; Remember, turbo_realpath will set this option later to the
; realpath_cache_basedir value.
; Remember, realpath_turbo will set this option later to the
; realpath_turbo.open_basedir value.
open_basedir = ""
```

Expand Down
10 changes: 5 additions & 5 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PHP_ARG_ENABLE(turbo_realpath, whether to enable turbo realpath module,
[ --enable-turbo-realpath Enable turbo realpath module])
PHP_ARG_ENABLE(realpath_turbo, whether to enable realpath_turbo module,
[ --enable-realpath_turbo Enable realpath_turbo module])

if test "$PHP_TURBO_REALPATH" = "yes"; then
AC_DEFINE(HAVE_TURBO_REALPATH, 1, [Whether you have turbo realpath module])
PHP_NEW_EXTENSION(turbo_realpath, turbo_realpath.c, $ext_shared)
if test "$PHP_REALPATH_TURBO" = "yes"; then
AC_DEFINE(HAVE_REALPATH_TURBO, 1, [Whether you have realpath_turbo module])
PHP_NEW_EXTENSION(realpath_turbo, realpath_turbo.c, $ext_shared)
fi
116 changes: 116 additions & 0 deletions realpath_turbo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "realpath_turbo.h"
#include "php_ini.h"
#include "ext/standard/info.h"

static zend_function_entry realpath_turbo_functions[] = {
{NULL, NULL, NULL}
};

zend_module_entry realpath_turbo_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_REALPATH_TURBO_EXTNAME,
realpath_turbo_functions,
PHP_MINIT(realpath_turbo),
PHP_MSHUTDOWN(realpath_turbo),
PHP_RINIT(realpath_turbo),
NULL,
PHP_MINFO(realpath_turbo),
#if ZEND_MODULE_API_NO >= 20010901
PHP_REALPATH_TURBO_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(realpath_turbo)

PHP_INI_BEGIN()
PHP_INI_ENTRY("realpath_turbo.open_basedir", "", PHP_INI_SYSTEM, NULL)
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
PHP_INI_ENTRY("realpath_turbo.safe_mode", "", PHP_INI_SYSTEM, NULL)
#endif
PHP_INI_ENTRY("realpath_turbo.disable_dangerous_functions", "1", PHP_INI_SYSTEM, NULL)
PHP_INI_END()

PHP_RINIT_FUNCTION(realpath_turbo)
{
char *basedir = INI_STR("realpath_turbo.open_basedir");
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
char *safe_mode = INI_STR("realpath_turbo.safe_mode");
#endif
char *disabled_functions = INI_STR("disable_functions");
char *risky_functions = "link,symlink";
char *new_functions;
int security = INI_INT("realpath_turbo.disable_dangerous_functions");
#if PHP_MAJOR_VERSION >= 7
zend_string *ini_name, *ini_value;
#endif

if(strlen(basedir) > 0) {
#if PHP_MAJOR_VERSION < 7
zend_alter_ini_entry("open_basedir", sizeof("open_basedir"), basedir, strlen(basedir), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
#else
ini_name = zend_string_init(ZEND_STRL("open_basedir"), 0);
ini_value = zend_string_init(basedir, strlen(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(strlen(safe_mode) > 0) {
zend_alter_ini_entry("safe_mode", sizeof("safe_mode"), safe_mode, strlen(safe_mode), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
}
#endif

if (security) {
// check disabled functions for symlink and link entries
if(strlen(disabled_functions) > 0) {
new_functions = emalloc(strlen(disabled_functions) + strlen(risky_functions) + 2);
strcpy(new_functions, risky_functions);
strcat(new_functions, ",");
strcat(new_functions, disabled_functions);
} else {
new_functions = emalloc(strlen(risky_functions) + 1);
strcpy(new_functions, risky_functions);
}
#if PHP_MAJOR_VERSION < 7
zend_alter_ini_entry("disable_functions", sizeof("disable_functions"), new_functions, strlen(new_functions), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
#else
ini_name = zend_string_init(ZEND_STRL("disable_functions"), 0);
ini_value = zend_string_init(new_functions, strlen(new_functions), 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(new_functions);
}
}

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", PHP_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();
}
25 changes: 25 additions & 0 deletions realpath_turbo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef PHP_REALPATH_TURBO_H
#define PHP_REALPATH_TURBO_H

#include "php.h"
#include "main/php_config.h"

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#define PHP_REALPATH_TURBO_VERSION "2.0.0 Beta 1"
#define PHP_REALPATH_TURBO_EXTNAME "realpath_turbo"

PHP_RINIT_FUNCTION(realpath_turbo);
PHP_MINIT_FUNCTION(realpath_turbo);

PHP_MINFO_FUNCTION(realpath_turbo);
PHP_MSHUTDOWN_FUNCTION(realpath_turbo);

PHP_FUNCTION(realpath_turbo);

extern zend_module_entry realpath_turbo_module_entry;
#define phpext_realpath_turbo_ptr &realpath_turbo_module_entry

#endif
120 changes: 0 additions & 120 deletions turbo_realpath.c

This file was deleted.

25 changes: 0 additions & 25 deletions turbo_realpath.h

This file was deleted.

0 comments on commit c4c610f

Please sign in to comment.