cvs: php4 /ext/bz2 bz2.c /ext/curl streams.c /ext/standard file.c ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c /ext/zlib
zlib_fopen_wrapper.c /main php_streams.h /main/streams plain_wrapper.c userspace.c

From: Date: Wed, 14 May 2003 06:10:05 +0000
Subject: cvs: php4 /ext/bz2 bz2.c /ext/curl streams.c /ext/standard file.c ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c /ext/zlib
zlib_fopen_wrapper.c /main php_streams.h /main/streams plain_wrapper.c userspace.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-20886@lists.php.net to get a copy of this message
pollita Wed May 14 02:10:05 2003 EDT Modified files: /php4/ext/bz2 bz2.c /php4/ext/curl streams.c /php4/ext/standard file.c ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c /php4/ext/zlib zlib_fopen_wrapper.c /php4/main php_streams.h /php4/main/streams plain_wrapper.c userspace.c Log: Setup unlink() method in wrapper_ops structure, implement unlink in plainfiles wrapper, explicitly set method NULL in other wrappers (for now), and rewrite unlink userland function to call into wrapper_ops

Index: php4/ext/bz2/bz2.c diff -u php4/ext/bz2/bz2.c:1.67 php4/ext/bz2/bz2.c:1.68 --- php4/ext/bz2/bz2.c:1.67 Wed Mar 19 19:32:16 2003 +++ php4/ext/bz2/bz2.c Wed May 14 02:10:04 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: bz2.c,v 1.67 2003/03/20 00:32:16 sniper Exp $ */ +/* $Id: bz2.c,v 1.68 2003/05/14 06:10:04 pollita Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -216,7 +216,8 @@ NULL, /* fstat */ NULL, /* stat */ NULL, /* opendir */ - "BZip2" + "BZip2", + NULL /* unlink */ }; php_stream_wrapper php_stream_bzip2_wrapper = { Index: php4/ext/curl/streams.c diff -u php4/ext/curl/streams.c:1.5 php4/ext/curl/streams.c:1.6 --- php4/ext/curl/streams.c:1.5 Mon Mar 17 10:06:11 2003 +++ php4/ext/curl/streams.c Wed May 14 02:10:04 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.5 2003/03/17 15:06:11 sniper Exp $ */ +/* $Id: streams.c,v 1.6 2003/05/14 06:10:04 pollita Exp $ */ /* This file implements cURL based wrappers. * NOTE: If you are implementing your own streams that are intended to @@ -358,7 +358,9 @@ NULL, /* stream_close: curl streams know how to clean themselves up */ NULL, /* stream_stat: curl streams know how to stat themselves */ NULL, /* stat url */ - NULL /* opendir */ + NULL, /* opendir */ + NULL, /* label */ + NULL /* unlink */ }; php_stream_wrapper php_curl_wrapper = { Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.337 php4/ext/standard/file.c:1.338 --- php4/ext/standard/file.c:1.337 Mon May 5 08:36:35 2003 +++ php4/ext/standard/file.c Wed May 14 02:10:04 2003 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.337 2003/05/05 12:36:35 hholzgra Exp $ */ +/* $Id: file.c,v 1.338 2003/05/14 06:10:04 pollita Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1403,34 +1403,36 @@ } /* }}} */ -/* {{{ proto bool unlink(string filename) +/* {{{ proto bool unlink(string filename[, context context]) Delete a file */ PHP_FUNCTION(unlink) { - zval **filename; - int ret; + char *filename; + int filename_len; + php_stream_wrapper *wrapper; + zval *zcontext = NULL; + php_stream_context *context = NULL; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &filename, &filename_len, &zcontext) == FAILURE) { + RETURN_FALSE; } - convert_to_string_ex(filename); - if (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; + if (zcontext) { + context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); } - if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { + wrapper = php_stream_locate_url_wrapper(filename, NULL, 0 TSRMLS_CC); + + if (!wrapper || !wrapper->wops) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to locate stream wrapper"); RETURN_FALSE; } - ret = VCWD_UNLINK(Z_STRVAL_PP(filename)); - if (ret == -1) { - php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_PP(filename), E_WARNING, "%s", strerror(errno)); + if (!wrapper->wops->unlink) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s does not allow unlinking", wrapper->wops->label ? wrapper->wops->label : "Wrapper"); RETURN_FALSE; } - /* Clear stat cache */ - PHP_FN(clearstatcache)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - RETURN_TRUE; + RETURN_BOOL(wrapper->wops->unlink(wrapper, filename, context TSRMLS_CC)); } /* }}} */ Index: php4/ext/standard/ftp_fopen_wrapper.c diff -u php4/ext/standard/ftp_fopen_wrapper.c:1.53 php4/ext/standard/ftp_fopen_wrapper.c:1.54 --- php4/ext/standard/ftp_fopen_wrapper.c:1.53 Mon May 5 09:46:14 2003 +++ php4/ext/standard/ftp_fopen_wrapper.c Wed May 14 02:10:04 2003 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: ftp_fopen_wrapper.c,v 1.53 2003/05/05 13:46:14 hholzgra Exp $ */ +/* $Id: ftp_fopen_wrapper.c,v 1.54 2003/05/14 06:10:04 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -756,7 +756,8 @@ php_stream_ftp_stream_stat, php_stream_ftp_url_stat, /* stat_url */ php_stream_ftp_opendir, /* opendir */ - "FTP" + "FTP", + NULL /* unlink */ }; PHPAPI php_stream_wrapper php_stream_ftp_wrapper = { Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.72 php4/ext/standard/http_fopen_wrapper.c:1.73 --- php4/ext/standard/http_fopen_wrapper.c:1.72 Mon Apr 28 10:41:36 2003 +++ php4/ext/standard/http_fopen_wrapper.c Wed May 14 02:10:04 2003 @@ -18,7 +18,7 @@ | Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: http_fopen_wrapper.c,v 1.72 2003/04/28 14:41:36 wez Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.73 2003/05/14 06:10:04 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -528,7 +528,8 @@ php_stream_http_stream_stat, NULL, /* stat_url */ NULL, /* opendir */ - "HTTP" + "HTTP", + NULL /* unlink */ }; PHPAPI php_stream_wrapper php_stream_http_wrapper = { Index: php4/ext/standard/php_fopen_wrapper.c diff -u php4/ext/standard/php_fopen_wrapper.c:1.38 php4/ext/standard/php_fopen_wrapper.c:1.39 --- php4/ext/standard/php_fopen_wrapper.c:1.38 Wed Apr 16 10:30:25 2003 +++ php4/ext/standard/php_fopen_wrapper.c Wed May 14 02:10:04 2003 @@ -17,7 +17,7 @@ | Hartmut Holzgraefe <hholzgra@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_fopen_wrapper.c,v 1.38 2003/04/16 14:30:25 moriyoshi Exp $ */ +/* $Id: php_fopen_wrapper.c,v 1.39 2003/05/14 06:10:04 pollita Exp $ */ #include <stdio.h> #include <stdlib.h> @@ -232,7 +232,8 @@ NULL, /* fstat */ NULL, /* stat */ NULL, /* opendir */ - "PHP" + "PHP", + NULL /* unlink */ }; php_stream_wrapper php_stream_php_wrapper = { Index: php4/ext/zlib/zlib_fopen_wrapper.c diff -u php4/ext/zlib/zlib_fopen_wrapper.c:1.38 php4/ext/zlib/zlib_fopen_wrapper.c:1.39 --- php4/ext/zlib/zlib_fopen_wrapper.c:1.38 Mon Mar 17 09:45:07 2003 +++ php4/ext/zlib/zlib_fopen_wrapper.c Wed May 14 02:10:04 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zlib_fopen_wrapper.c,v 1.38 2003/03/17 14:45:07 sniper Exp $ */ +/* $Id: zlib_fopen_wrapper.c,v 1.39 2003/05/14 06:10:04 pollita Exp $ */ #define _GNU_SOURCE @@ -161,7 +161,8 @@ NULL, /* stat */ NULL, /* stat_url */ NULL, /* opendir */ - "ZLIB" + "ZLIB", + NULL /* unlink */ }; php_stream_wrapper php_stream_gzip_wrapper = { Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.78 php4/main/php_streams.h:1.79 --- php4/main/php_streams.h:1.78 Wed Apr 16 20:00:34 2003 +++ php4/main/php_streams.h Wed May 14 02:10:04 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams.h,v 1.78 2003/04/17 00:00:34 pollita Exp $ */ +/* $Id: php_streams.h,v 1.79 2003/05/14 06:10:04 pollita Exp $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -145,6 +145,9 @@ int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); const char *label; + + /* delete a file */ + int (*unlink)(php_stream_wrapper *wrapper, char *url, php_stream_context *context TSRMLS_DC); } php_stream_wrapper_ops; struct _php_stream_wrapper { Index: php4/main/streams/plain_wrapper.c diff -u php4/main/streams/plain_wrapper.c:1.12 php4/main/streams/plain_wrapper.c:1.13 --- php4/main/streams/plain_wrapper.c:1.12 Tue Mar 18 18:37:54 2003 +++ php4/main/streams/plain_wrapper.c Wed May 14 02:10:04 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: plain_wrapper.c,v 1.12 2003/03/18 23:37:54 wez Exp $ */ +/* $Id: plain_wrapper.c,v 1.13 2003/05/14 06:10:04 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -889,13 +889,47 @@ return VCWD_STAT(url, &ssb->sb); } +static int php_plain_files_unlink(php_stream_wrapper *wrapper, char *url, php_stream_context *context TSRMLS_DC) +{ + char *p; + int ret; + zval funcname; + zval *retval = NULL; + + if (p = strstr(url, "://")) { + url = p + 3; + } + + if (PG(safe_mode) && !php_checkuid(url, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { + return 0; + } + + if (php_check_open_basedir(url TSRMLS_CC)) { + return 0; + } + + ret = VCWD_UNLINK(url); + if (ret == -1) { + php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(errno)); + return 0; + } + /* Clear stat cache */ + ZVAL_STRINGL(&funcname, "clearstatcache", sizeof("clearstatcache")-1, 0); + call_user_function_ex(CG(function_table), NULL, &funcname, &retval, 0, NULL, 0, NULL TSRMLS_CC); + if (retval) { + zval_dtor(retval); + } + return 1; +} + static php_stream_wrapper_ops php_plain_files_wrapper_ops = { php_plain_files_stream_opener, NULL, NULL, php_plain_files_url_stater, php_plain_files_dir_opener, - "plainfile" + "plainfile", + php_plain_files_unlink }; php_stream_wrapper php_plain_files_wrapper = { Index: php4/main/streams/userspace.c diff -u php4/main/streams/userspace.c:1.2 php4/main/streams/userspace.c:1.3 --- php4/main/streams/userspace.c:1.2 Wed Feb 19 03:40:19 2003 +++ php4/main/streams/userspace.c Wed May 14 02:10:04 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: userspace.c,v 1.2 2003/02/19 08:40:19 sniper Exp $ */ +/* $Id: userspace.c,v 1.3 2003/05/14 06:10:04 pollita Exp $ */ #include "php.h" #include "php_globals.h" @@ -42,7 +42,8 @@ NULL, /* stat - the streams themselves know how */ user_wrapper_stat_url, user_wrapper_opendir, - "user-space" + "user-space", + NULL /* unlink */ };
« previous php.cvs (#20886) next »