diff options
Diffstat (limited to 'ext/posix')
| -rw-r--r-- | ext/posix/posix.c | 135 | ||||
| -rw-r--r-- | ext/posix/tests/posix_access.phpt | 52 | ||||
| -rw-r--r-- | ext/posix/tests/posix_access_error_modes.phpt | 46 | ||||
| -rw-r--r-- | ext/posix/tests/posix_access_error_wrongparams.phpt | 44 | ||||
| -rw-r--r-- | ext/posix/tests/posix_access_safemode.phpt | 25 | ||||
| -rw-r--r-- | ext/posix/tests/posix_getuid_error.phpt | 2 | ||||
| -rw-r--r-- | ext/posix/tests/posix_mkfifo_safemode.phpt | 45 | ||||
| -rw-r--r-- | ext/posix/tests/posix_setegid_basic.phpt | 12 | ||||
| -rw-r--r-- | ext/posix/tests/posix_times_error.phpt | 2 | ||||
| -rw-r--r-- | ext/posix/tests/posix_uname_error.phpt | 2 |
10 files changed, 89 insertions, 276 deletions
diff --git a/ext/posix/posix.c b/ext/posix/posix.c index e3a2bc739d..0a764bab33 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -445,7 +445,9 @@ ZEND_GET_MODULE(posix) #define PHP_POSIX_SINGLE_ARG_FUNC(func_name) \ zend_long val; \ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) RETURN_FALSE; \ + ZEND_PARSE_PARAMETERS_START(1, 1) \ + Z_PARAM_LONG(val) \ + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); \ if (func_name(val) < 0) { \ POSIX_G(last_error) = errno; \ RETURN_FALSE; \ @@ -459,9 +461,10 @@ PHP_FUNCTION(posix_kill) { zend_long pid, sig; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &pid, &sig) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_LONG(pid) + Z_PARAM_LONG(sig) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (kill(pid, sig) < 0) { POSIX_G(last_error) = errno; @@ -624,9 +627,10 @@ PHP_FUNCTION(posix_setpgid) { zend_long pid, pgid; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &pid, &pgid) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_LONG(pid) + Z_PARAM_LONG(pgid) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (setpgid(pid, pgid) < 0) { POSIX_G(last_error) = errno; @@ -643,9 +647,10 @@ PHP_FUNCTION(posix_setpgid) PHP_FUNCTION(posix_getpgid) { zend_long val; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) { - RETURN_FALSE; - } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(val) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if ((val = getpgid(val)) < 0) { POSIX_G(last_error) = errno; @@ -662,9 +667,10 @@ PHP_FUNCTION(posix_getpgid) PHP_FUNCTION(posix_getsid) { zend_long val; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &val) == FAILURE) { - RETURN_FALSE; - } + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(val) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if ((val = getsid(val)) < 0) { POSIX_G(last_error) = errno; @@ -791,9 +797,9 @@ PHP_FUNCTION(posix_ttyname) zend_long buflen; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &z_fd) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(z_fd) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); switch (Z_TYPE_P(z_fd)) { case IS_RESOURCE: @@ -836,9 +842,9 @@ PHP_FUNCTION(posix_isatty) zval *z_fd; int fd; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &z_fd) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(z_fd) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); switch (Z_TYPE_P(z_fd)) { case IS_RESOURCE: @@ -898,20 +904,20 @@ PHP_FUNCTION(posix_getcwd) #ifdef HAVE_MKFIFO PHP_FUNCTION(posix_mkfifo) { - char *path; - size_t path_len; + zend_string *path; zend_long mode; int result; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pl", &path, &path_len, &mode) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_PATH_STR(path) + Z_PARAM_LONG(mode) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if (php_check_open_basedir_ex(path, 0)) { + if (php_check_open_basedir_ex(ZSTR_VAL(path), 0)) { RETURN_FALSE; } - result = mkfifo(path, mode); + result = mkfifo(ZSTR_VAL(path), mode); if (result < 0) { POSIX_G(last_error) = errno; RETURN_FALSE; @@ -927,21 +933,21 @@ PHP_FUNCTION(posix_mkfifo) #ifdef HAVE_MKNOD PHP_FUNCTION(posix_mknod) { - char *path; - size_t path_len; + zend_string *path; zend_long mode; zend_long major = 0, minor = 0; int result; - dev_t php_dev; + dev_t php_dev = 0; - php_dev = 0; + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_PATH_STR(path) + Z_PARAM_LONG(mode) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(major) + Z_PARAM_LONG(minor) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pl|ll", &path, &path_len, - &mode, &major, &minor) == FAILURE) { - RETURN_FALSE; - } - - if (php_check_open_basedir_ex(path, 0)) { + if (php_check_open_basedir_ex(ZSTR_VAL(path), 0)) { RETURN_FALSE; } @@ -963,7 +969,7 @@ PHP_FUNCTION(posix_mknod) } } - result = mknod(path, mode, php_dev); + result = mknod(ZSTR_VAL(path), mode, php_dev); if (result < 0) { POSIX_G(last_error) = errno; RETURN_FALSE; @@ -1019,9 +1025,11 @@ PHP_FUNCTION(posix_access) size_t filename_len, ret; char *filename, *path; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &filename, &filename_len, &mode) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(mode) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); path = expand_filepath(filename, NULL); if (!path) { @@ -1067,9 +1075,9 @@ PHP_FUNCTION(posix_getgrnam) char *buf; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(name, name_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX) buflen = sysconf(_SC_GETGR_R_SIZE_MAX); @@ -1123,9 +1131,10 @@ PHP_FUNCTION(posix_getgrgid) #endif struct group *g; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &gid) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(gid) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + #if defined(ZTS) && defined(HAVE_GETGRGID_R) && defined(_SC_GETGR_R_SIZE_MAX) grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX); @@ -1192,9 +1201,9 @@ PHP_FUNCTION(posix_getpwnam) char *buf; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(name, name_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) buflen = sysconf(_SC_GETPW_R_SIZE_MAX); @@ -1242,9 +1251,10 @@ PHP_FUNCTION(posix_getpwuid) #endif struct passwd *pw; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &uid) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(uid) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + #if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R) pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX); if (pwbuflen < 1) { @@ -1404,9 +1414,11 @@ PHP_FUNCTION(posix_setrlimit) struct rlimit rl; zend_long res, cur, max; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &res, &cur, &max) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_LONG(res) + Z_PARAM_LONG(cur) + Z_PARAM_LONG(max) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); rl.rlim_cur = cur; rl.rlim_max = max; @@ -1439,9 +1451,9 @@ PHP_FUNCTION(posix_strerror) { zend_long error; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &error) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(error) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); RETURN_STRING(strerror(error)); } @@ -1458,9 +1470,10 @@ PHP_FUNCTION(posix_initgroups) char *name; size_t name_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &name, &name_len, &basegid) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STRING(name, name_len) + Z_PARAM_LONG(basegid) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (name_len == 0) { RETURN_FALSE; diff --git a/ext/posix/tests/posix_access.phpt b/ext/posix/tests/posix_access.phpt deleted file mode 100644 index 47b5e15f0b..0000000000 --- a/ext/posix/tests/posix_access.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -Test posix_access() function test ---DESCRIPTION-- -checks for existence, read-access, write-access, execute-access ---CREDITS-- -Moritz Neuhaeuser, info@xcompile.net -PHP Testfest Berlin 2009-05-10 ---SKIPIF-- -<?php -if (!extension_loaded('posix')) { - die('SKIP The posix extension is not loaded.'); -} -if (posix_geteuid() == 0) { - die('SKIP Cannot run test as root.'); -} -if (PHP_VERSION_ID < 503099) { - die('SKIP Safe mode is no longer available.'); -} -?> ---FILE-- -<?php -$filename = dirname(__FILE__) . '/foo.test'; -$fp = fopen($filename,"w"); -fwrite($fp,"foo"); -fclose($fp); - -chmod ($filename, 0000); -var_dump(posix_access($filename, POSIX_F_OK)); - -chmod ($filename, 0400); -var_dump(posix_access($filename, POSIX_R_OK)); - -chmod ($filename, 0600); -var_dump(posix_access($filename, POSIX_W_OK)); - -chmod ($filename, 0700); -var_dump(posix_access($filename, POSIX_X_OK)); -?> -===DONE=== ---CLEAN-- -<?php -$filename = dirname(__FILE__) . '/foo.test'; -chmod ($filename, 0700); -unlink($filename); -?> ---EXPECTF-- -Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d -bool(true) -bool(true) -bool(true) -bool(true) -===DONE=== diff --git a/ext/posix/tests/posix_access_error_modes.phpt b/ext/posix/tests/posix_access_error_modes.phpt deleted file mode 100644 index fb04e34683..0000000000 --- a/ext/posix/tests/posix_access_error_modes.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -Test posix_access() function test error conditions ---DESCRIPTION-- -checks if posix_access() failes for wrong permissions ---CREDITS-- -Moritz Neuhaeuser, info@xcompile.net -PHP Testfest Berlin 2009-05-10 ---SKIPIF-- -<?php -if (!extension_loaded('posix')) { - die('SKIP The posix extension is not loaded.'); -} -if (posix_geteuid() == 0) { - die('SKIP Cannot run test as root.'); -} -if (PHP_VERSION_ID < 503099) { - die('SKIP Safe mode is no longer available.'); -} -?> ---FILE-- -<?php -$filename = dirname(__FILE__) . '/foo.test'; -var_dump(posix_access($filename, POSIX_F_OK)); -$fp = fopen($filename,"w"); -fwrite($fp,"foo"); -fclose($fp); - -chmod ($filename, 0000); -var_dump(posix_access($filename, POSIX_R_OK)); -var_dump(posix_access($filename, POSIX_W_OK)); -var_dump(posix_access($filename, POSIX_X_OK)); -?> -===DONE=== ---CLEAN-- -<?php -$filename = dirname(__FILE__) . '/foo.test'; -chmod ($filename, 0700); -unlink($filename); -?> ---EXPECTF-- -WDeprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line %d -bool(false) -bool(false) -bool(false) -bool(false) -===DONE=== diff --git a/ext/posix/tests/posix_access_error_wrongparams.phpt b/ext/posix/tests/posix_access_error_wrongparams.phpt deleted file mode 100644 index dcab33c4a7..0000000000 --- a/ext/posix/tests/posix_access_error_wrongparams.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Test posix_access() function : parameter validation ---DESCRIPTION-- -cases: no params, wrong param1, wrong param2, null directory, wrong directory, ---CREDITS-- -Moritz Neuhaeuser, info@xcompile.net -PHP Testfest Berlin 2009-05-10 ---SKIPIF-- -<?php -if (!extension_loaded('posix')) { - die('SKIP The posix extension is not loaded.'); -} -if (posix_geteuid() == 0) { - die('SKIP Cannot run test as root.'); -} -if (PHP_VERSION_ID < 503099) { - die('SKIP Safe mode is no longer available.'); -} -?> ---FILE-- -<?php - -var_dump( posix_access() ); -var_dump( posix_access(array()) ); -var_dump( posix_access('foo',array()) ); -var_dump( posix_access(null) ); - -var_dump(posix_access('./foobar')); -?> -===DONE=== ---EXPECTF-- -Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 - -Warning: posix_access() expects at least 1 parameter, 0 given in %s on line %d -bool(false) - -Warning: posix_access() expects parameter 1 to be string, array given in %s on line %d -bool(false) - -Warning: posix_access() expects parameter 2 to be integer, array given in %s on line %d -bool(false) -bool(false) -bool(false) -===DONE=== diff --git a/ext/posix/tests/posix_access_safemode.phpt b/ext/posix/tests/posix_access_safemode.phpt deleted file mode 100644 index b726b4fdbb..0000000000 --- a/ext/posix/tests/posix_access_safemode.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test posix_access() with safe_mode enabled. ---CREDITS-- -Till Klampaeckel, till@php.net -TestFest Berlin 2009 ---SKIPIF-- -<?php -if (!extension_loaded('posix')) { - die('SKIP The posix extension is not loaded.'); -} -if (posix_geteuid() == 0) { - die('SKIP Cannot run test as root.'); -} -if (PHP_VERSION_ID < 503099) { - die('SKIP Safe mode is no longer available.'); -} ---FILE-- -<?php -var_dump(posix_access('/tmp', POSIX_W_OK)); -?> -===DONE=== ---EXPECTF-- -Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d -bool(false) -===DONE=== diff --git a/ext/posix/tests/posix_getuid_error.phpt b/ext/posix/tests/posix_getuid_error.phpt index e759e68bf5..42a35512a0 100644 --- a/ext/posix/tests/posix_getuid_error.phpt +++ b/ext/posix/tests/posix_getuid_error.phpt @@ -16,7 +16,7 @@ echo "*** Testing posix_getuid() : error conditions ***\n"; // One argument echo "\n-- Testing posix_getuid() function with one argument --\n"; -$extra_arg = 10;; +$extra_arg = 10; var_dump( posix_getuid($extra_arg) ); echo "Done"; diff --git a/ext/posix/tests/posix_mkfifo_safemode.phpt b/ext/posix/tests/posix_mkfifo_safemode.phpt deleted file mode 100644 index 1126c00df0..0000000000 --- a/ext/posix/tests/posix_mkfifo_safemode.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -Test posix_mkfifo() with safe_mode. ---DESCRIPTION-- -The test attempts to enable safe_mode, catches all the relevant E_WARNING's and tries to create a fifo in /tmp. - -The first attempt (writing to /tmp) should effectively fail because /tmp is owned by root. - -The second attempt (writing to a local created file) works. ---CREDITS-- -Till Klampaeckel, till@php.net -TestFest Berlin 2009 ---SKIPIF-- -<?php -if (!extension_loaded('posix')) { - die('SKIP The posix extension is not loaded.'); -} -if (posix_geteuid() == 0) { - die('SKIP Cannot run test as root.'); -} -if (PHP_VERSION_ID < 503099) { - die('SKIP Safe mode is no longer available.'); -} -?> ---FILE-- -<?php -var_dump(posix_mkfifo('/tmp/foobar', 0644)); - -$dir = dirname(__FILE__) . '/foo'; -mkdir ($dir); -var_dump(posix_mkfifo($dir . '/bar', 0644)); -?> -===DONE=== ---CLEAN-- -<?php -$dir = dirname(__FILE__) . '/foo'; -unlink($dir . '/bar'); -rmdir($dir); -?> ---EXPECTF-- -Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d - -Warning: posix_mkfifo(): SAFE MODE Restriction in effect. The script whose uid is %d is not allowed to access /tmp owned by uid %d in %s on line %d -bool(false) -bool(true) -===DONE=== diff --git a/ext/posix/tests/posix_setegid_basic.phpt b/ext/posix/tests/posix_setegid_basic.phpt new file mode 100644 index 0000000000..729abc5f54 --- /dev/null +++ b/ext/posix/tests/posix_setegid_basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test function posix_setegid() by calling it with its expected arguments +--SKIPIF-- +<?php + if(!extension_loaded("posix")) die("skip - POSIX extension not loaded"); +?> +--FILE-- +<?php +var_dump(posix_setegid(posix_getegid())); +?> +--EXPECTF-- +bool(true)
\ No newline at end of file diff --git a/ext/posix/tests/posix_times_error.phpt b/ext/posix/tests/posix_times_error.phpt index 2766bc9483..b705047358 100644 --- a/ext/posix/tests/posix_times_error.phpt +++ b/ext/posix/tests/posix_times_error.phpt @@ -16,7 +16,7 @@ echo "*** Testing posix_times() : error conditions ***\n"; // One argument echo "\n-- Testing posix_times() function with one argument --\n"; -$extra_arg = 10;; +$extra_arg = 10; var_dump( posix_times($extra_arg) ); echo "Done"; diff --git a/ext/posix/tests/posix_uname_error.phpt b/ext/posix/tests/posix_uname_error.phpt index 4c753feae4..b44f4ae8ca 100644 --- a/ext/posix/tests/posix_uname_error.phpt +++ b/ext/posix/tests/posix_uname_error.phpt @@ -16,7 +16,7 @@ echo "*** Testing posix_uname() : error conditions ***\n"; // One argument echo "\n-- Testing posix_uname() function with one argument --\n"; -$extra_arg = 10;; +$extra_arg = 10; var_dump( posix_uname($extra_arg) ); echo "Done"; |
