Navigation Menu

Skip to content

Commit

Permalink
So long safe_mode mode.
Browse files Browse the repository at this point in the history
Also removed the magic_quotes configure option, no longer relevant since
the magic is gone :-).
  • Loading branch information
Ilia Alshanetsky committed Mar 8, 2006
1 parent 689eea9 commit 27e175e
Show file tree
Hide file tree
Showing 23 changed files with 42 additions and 280 deletions.
4 changes: 2 additions & 2 deletions Makefile.gcov
Expand Up @@ -13,13 +13,13 @@ lcov-test: all
TEST_PHP_EXECUTABLE=$(PHP_EXECUTABLE) \
TEST_PHP_SRCDIR=$(top_srcdir) \
CC="$(CC)" \
$(PHP_EXECUTABLE) -d 'open_basedir=' -d 'safe_mode=0' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -d 'extension_dir=modules/' -d `( . $(PHP_MODULES) ; echo extension=$$dlname)` tests/; \
$(PHP_EXECUTABLE) -d 'open_basedir=' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -d 'extension_dir=modules/' -d `( . $(PHP_MODULES) ; echo extension=$$dlname)` tests/; \
elif test ! -z "$(SAPI_CLI_PATH)" && test -x "$(SAPI_CLI_PATH)"; then \
NO_INTERACTION=1 \
TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
TEST_PHP_SRCDIR=$(top_srcdir) \
CC="$(CC)" \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'safe_mode=0' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php $(TESTS); \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php $(TESTS); \
else \
echo "ERROR: Cannot run tests without CLI sapi."; \
fi
Expand Down
8 changes: 4 additions & 4 deletions Makefile.global
Expand Up @@ -72,12 +72,12 @@ test: all
TEST_PHP_EXECUTABLE=$(PHP_EXECUTABLE) \
TEST_PHP_SRCDIR=$(top_srcdir) \
CC="$(CC)" \
$(PHP_EXECUTABLE) -d 'open_basedir=' -d 'safe_mode=0' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -d 'extension_dir=modules/' -d `( . $(PHP_MODULES) ; echo extension=$$dlname)` tests/; \
$(PHP_EXECUTABLE) -d 'open_basedir=' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -d 'extension_dir=modules/' -d `( . $(PHP_MODULES) ; echo extension=$$dlname)` tests/; \
elif test ! -z "$(SAPI_CLI_PATH)" && test -x "$(SAPI_CLI_PATH)"; then \
TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
TEST_PHP_SRCDIR=$(top_srcdir) \
CC="$(CC)" \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'safe_mode=0' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -U $(TESTS); \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -U $(TESTS); \
else \
echo "ERROR: Cannot run tests without CLI sapi."; \
fi
Expand All @@ -87,7 +87,7 @@ utest: all
TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
TEST_PHP_SRCDIR=$(top_srcdir) \
CC="$(CC)" \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'safe_mode=0' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -u $(TESTS); \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -u $(TESTS); \
else \
echo "ERROR: Cannot run tests without CLI sapi."; \
fi
Expand All @@ -97,7 +97,7 @@ ntest: all
TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
TEST_PHP_SRCDIR=$(top_srcdir) \
CC="$(CC)" \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'safe_mode=0' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -N $(TESTS); \
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'output_buffering=0' -d 'memory_limit=-1' $(top_srcdir)/run-tests.php -N $(TESTS); \
else \
echo "ERROR: Cannot run tests without CLI sapi."; \
fi
Expand Down
42 changes: 1 addition & 41 deletions configure.in
Expand Up @@ -713,37 +713,6 @@ fi

test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS"

PHP_ARG_ENABLE(safe-mode, whether to enable safe mode by default,
[ --enable-safe-mode Enable safe mode by default], no, no)

if test "$PHP_SAFE_MODE" = "yes"; then
AC_DEFINE(PHP_SAFE_MODE,1,[ ])
else
AC_DEFINE(PHP_SAFE_MODE,0,[ ])
fi

AC_MSG_CHECKING([for safe mode exec dir])
AC_ARG_WITH(exec-dir,
[ --with-exec-dir[=DIR] Only allow executables in DIR under safe-mode
[/usr/local/php/bin]],
[
if test "$withval" != "no"; then
if test "$withval" = "yes"; then
AC_DEFINE(PHP_SAFE_MODE_EXEC_DIR,"/usr/local/php/bin", [ ])
AC_MSG_RESULT([/usr/local/php/bin])
else
AC_DEFINE_UNQUOTED(PHP_SAFE_MODE_EXEC_DIR,"$withval", [ ])
AC_MSG_RESULT([$withval])
fi
else
AC_DEFINE(PHP_SAFE_MODE_EXEC_DIR,"/usr/local/php/bin", [ ])
AC_MSG_RESULT([/usr/local/php/bin])
fi
],[
AC_DEFINE(PHP_SAFE_MODE_EXEC_DIR,"/usr/local/php/bin", [ ])
AC_MSG_RESULT([/usr/local/php/bin])
])

PHP_ARG_ENABLE(sigchild,whether to enable PHP's own SIGCHLD handler,
[ --enable-sigchild Enable PHP's own SIGCHLD handler], no, no)

Expand All @@ -753,15 +722,6 @@ else
AC_DEFINE(PHP_SIGCHILD, 0, [ ])
fi

PHP_ARG_ENABLE(magic-quotes,whether to enable magic quotes by default,
[ --enable-magic-quotes Enable magic quotes by default.], no, no)

if test "$PHP_MAGIC_QUOTES" = "yes"; then
AC_DEFINE(MAGIC_QUOTES, 1, [ ])
else
AC_DEFINE(MAGIC_QUOTES, 0, [ ])
fi

PHP_ARG_ENABLE(rpath, whether to enable runpaths,
[ --disable-rpath Disable passing additional runtime library
search paths], yes, no)
Expand Down Expand Up @@ -1262,7 +1222,7 @@ PHP_INSTALL_HEADERS([Zend/ TSRM/ include/ main/ main/streams/ regex/])
PHP_ADD_SOURCES(TSRM, TSRM.c tsrm_strtok_r.c tsrm_virtual_cwd.c)

PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
safe_mode.c fopen_wrappers.c alloca.c php_scandir.c \
fopen_wrappers.c alloca.c php_scandir.c \
php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
network.c php_open_temporary_file.c php_logos.c \
Expand Down
29 changes: 29 additions & 0 deletions ext/standard/basic_functions.c
Expand Up @@ -1961,6 +1961,35 @@ PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers T
return SUCCESS;
}

PHPAPI char *php_get_current_user()
{
struct passwd *pwd;
struct stat *pstat;
TSRMLS_FETCH();

if (SG(request_info).current_user) {
return SG(request_info).current_user;
}

/* FIXME: I need to have this somehow handled if
USE_SAPI is defined, because cgi will also be
interfaced in USE_SAPI */

pstat = sapi_get_stat(TSRMLS_C);

if (!pstat) {
return "";
}

if ((pwd=getpwuid(pstat->st_uid))==NULL) {
return "";
}
SG(request_info).current_user_length = strlen(pwd->pw_name);
SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);

return SG(request_info).current_user;
}

/* {{{ proto mixed call_user_func(string function_name [, mixed parmeter] [, mixed ...])
Call a user function which is the first parameter */
PHP_FUNCTION(call_user_func)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/basic_functions.h
Expand Up @@ -134,6 +134,7 @@ PHP_MINIT_FUNCTION(user_filters);
PHP_RSHUTDOWN_FUNCTION(user_filters);

PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC);
PHPAPI char *php_get_current_user();

#if SIZEOF_INT == 4
/* Most 32-bit and 64-bit systems have 32-bit ints */
Expand Down
1 change: 0 additions & 1 deletion ext/tidy/tidy.c
Expand Up @@ -29,7 +29,6 @@

#include "php_ini.h"
#include "ext/standard/info.h"
#include "safe_mode.h"

#include "Zend/zend_exceptions.h"
#include "Zend/zend_object_handlers.h"
Expand Down
1 change: 0 additions & 1 deletion ext/zlib/zlib.c
Expand Up @@ -42,7 +42,6 @@
/* #include <sys/uio.h> */
#endif
#include "ext/standard/head.h"
#include "safe_mode.h"
#include "ext/standard/php_standard.h"
#include "ext/standard/info.h"
#include "php_zlib.h"
Expand Down
71 changes: 3 additions & 68 deletions main/SAPI.c
Expand Up @@ -665,74 +665,9 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)

sapi_update_response_code(401 TSRMLS_CC); /* authentication-required */

if(PG(safe_mode))
#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
{
zval *repl_temp;
char *ptr = colon_offset+1, *result, *newheader;
int ptr_len=0, result_len = 0, newlen = 0;

/* skip white space */
while (isspace(*ptr)) {
ptr++;
}

myuid = php_getuid();

ptr_len = strlen(ptr);
MAKE_STD_ZVAL(repl_temp);
Z_TYPE_P(repl_temp) = IS_STRING;
Z_STRVAL_P(repl_temp) = emalloc(32);
Z_STRLEN_P(repl_temp) = sprintf(Z_STRVAL_P(repl_temp), "realm=\"\\1-%ld\"", myuid);
/* Modify quoted realm value */
result = php_pcre_replace("/realm=\"(.*?)\"/i", 16,
ptr, ptr_len,
repl_temp,
0, &result_len, -1, NULL TSRMLS_CC);
if(result_len==ptr_len) {
efree(result);
sprintf(Z_STRVAL_P(repl_temp), "realm=\\1-%ld\\2", myuid);
/* modify unquoted realm value */
result = php_pcre_replace("/realm=([^\\s]+)(.*)/i", 21,
ptr, ptr_len,
repl_temp,
0, &result_len, -1, NULL TSRMLS_CC);
if(result_len==ptr_len) {
char *lower_temp = estrdup(ptr);
char conv_temp[32];
int conv_len;

php_strtolower(lower_temp,strlen(lower_temp));
/* If there is no realm string at all, append one */
if(!strstr(lower_temp,"realm")) {
efree(result);
conv_len = sprintf(conv_temp, " realm=\"%ld\"",myuid);
result = emalloc(ptr_len+conv_len+1);
result_len = ptr_len+conv_len;
memcpy(result, ptr, ptr_len);
memcpy(result+ptr_len, conv_temp, conv_len);
*(result+ptr_len+conv_len) = '\0';
}
efree(lower_temp);
}
}
newlen = sizeof("WWW-Authenticate: ") - 1 + result_len;
newheader = emalloc(newlen+1);
sprintf(newheader,"WWW-Authenticate: %s", result);
efree(header_line);
sapi_header.header = newheader;
sapi_header.header_len = newlen;
efree(result);
efree(Z_STRVAL_P(repl_temp));
efree(repl_temp);
}
#else
{
myuid = php_getuid();
efree(header_line);
sapi_header.header_len = spprintf(&sapi_header.header, 0, "WWW-Authenticate: Basic realm=\"%ld\"", myuid);
}
#endif
myuid = php_getuid();
efree(header_line);
sapi_header.header_len = spprintf(&sapi_header.header, 0, "WWW-Authenticate: Basic realm=\"%ld\"", myuid);
}
if (sapi_header.header==header_line) {
*colon_offset = ':';
Expand Down
2 changes: 0 additions & 2 deletions main/config.w32.h
Expand Up @@ -82,8 +82,6 @@
/* PHP Runtime Configuration */
#define FORCE_CGI_REDIRECT 1
#define PHP_URL_FOPEN 1
#define PHP_SAFE_MODE 0
#define MAGIC_QUOTES 0
#define USE_CONFIG_FILE 1
#define DEFAULT_SHORT_OPEN_TAG "1"
#define ENABLE_PATHINFO_CHECK 1
Expand Down
6 changes: 0 additions & 6 deletions main/fopen_wrappers.c
Expand Up @@ -39,7 +39,6 @@
#include <sys/param.h>
#endif

#include "safe_mode.h"
#include "ext/standard/head.h"
#include "ext/standard/php_standard.h"
#include "zend_compile.h"
Expand Down Expand Up @@ -332,11 +331,6 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char **
return php_fopen_and_set_opened_path(filename, mode, opened_path TSRMLS_CC);
}

/*
* files in safe_mode_include_dir (or subdir) are excluded from
* safe mode GID/UID checks
*/

/* Absolute path open */
/* FIXME: Andi - Do we actually need the if()? */
if (IS_ABSOLUTE_PATH(filename, filename_length) || (!path || (path && !*path))) {
Expand Down
21 changes: 1 addition & 20 deletions main/main.c
Expand Up @@ -324,9 +324,7 @@ static PHP_INI_MH(OnUpdateDefaultMimetype)
}
/* }}} */

/* Need to convert to strings and make use of:
* PHP_SAFE_MODE
*
/*
* Need to be read from the environment (?):
* PHP_AUTO_PREPEND_FILE
* PHP_AUTO_APPEND_FILE
Expand All @@ -335,10 +333,6 @@ static PHP_INI_MH(OnUpdateDefaultMimetype)
* PHP_INCLUDE_PATH
*/

#ifndef PHP_SAFE_MODE_EXEC_DIR
# define PHP_SAFE_MODE_EXEC_DIR ""
#endif

#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)
# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
#else
Expand Down Expand Up @@ -380,13 +374,6 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("register_long_arrays", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_long_arrays, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
#if PHP_SAFE_MODE
STD_PHP_INI_BOOLEAN("safe_mode", "1", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
#else
STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
#endif
STD_PHP_INI_ENTRY("safe_mode_include_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, safe_mode_include_dir, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("safe_mode_gid", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode_gid, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, short_tags, zend_compiler_globals, compiler_globals)
STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
Expand All @@ -408,7 +395,6 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateString, open_basedir, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("safe_mode_exec_dir", PHP_SAFE_MODE_EXEC_DIR, PHP_INI_SYSTEM, OnUpdateString, safe_mode_exec_dir, php_core_globals, core_globals)

STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
Expand Down Expand Up @@ -973,11 +959,6 @@ PHP_FUNCTION(set_time_limit)
{
zval **new_timeout;

if (PG(safe_mode)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode");
RETURN_FALSE;
}

if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_timeout) == FAILURE) {
WRONG_PARAM_COUNT;
}
Expand Down
2 changes: 0 additions & 2 deletions main/php.h
Expand Up @@ -189,8 +189,6 @@ typedef zval pval;
# endif
#endif

#include "safe_mode.h"

#ifndef HAVE_STRERROR
char *strerror(int);
#endif
Expand Down
6 changes: 0 additions & 6 deletions main/php_globals.h
Expand Up @@ -50,15 +50,11 @@ typedef struct _arg_separators {
} arg_separators;

struct _php_core_globals {
zend_bool safe_mode;

zend_bool allow_call_time_pass_reference;
zend_bool implicit_flush;

long output_buffering;

char *safe_mode_include_dir;
zend_bool safe_mode_gid;
zend_bool sql_safe_mode;
zend_bool enable_dl;

Expand All @@ -67,8 +63,6 @@ struct _php_core_globals {
char *unserialize_callback_func;
long serialize_precision;

char *safe_mode_exec_dir;

long memory_limit;
long max_input_time;

Expand Down

0 comments on commit 27e175e

Please sign in to comment.