44 size_t arch_len, entry_len;
65 if (entry[0] ==
'/') {
93 size_t arch_len, entry_len;
118 if (using_include_path) {
127 if (entry[0] ==
'/') {
128 if (!zend_hash_str_exists(&(phar->
manifest), entry + 1, entry_len - 1)) {
136 if (!zend_hash_str_exists(&(phar->
manifest), entry, entry_len)) {
141 if (entry[0] ==
'/') {
144 "phar://",
strlen(
"phar://"),
264 if (stream ==
NULL) {
311 if (stream ==
NULL) {
326#define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT)
327#define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK)
328#define IS_ABLE_CHECK(__t) ((__t) == FS_IS_R || (__t) == FS_IS_W || (__t) == FS_IS_X)
329#define IS_ACCESS_CHECK(__t) (IS_ABLE_CHECK(type) || (__t) == FS_EXISTS)
334 zval stat_dev, stat_ino, stat_mode, stat_nlink, stat_uid, stat_gid, stat_rdev,
335 stat_size, stat_atime, stat_mtime, stat_ctime, stat_blksize, stat_blocks;
336 int rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH;
337 char *stat_sb_names[13] = {
338 "dev",
"ino",
"mode",
"nlink",
"uid",
"gid",
"rdev",
339 "size",
"atime",
"mtime",
"ctime",
"blksize",
"blocks"
343 if(stat_sb->st_uid==getuid()) {
347 }
else if(stat_sb->st_gid==getgid()) {
355 groups = getgroups(0,
NULL);
358 n=getgroups(groups, gids);
360 if(stat_sb->st_gid==gids[i]) {
390 if (
S_ISLNK(stat_sb->st_mode)) {
393 switch(stat_sb->st_mode & S_IFMT) {
421 ZVAL_LONG(&stat_nlink, stat_sb->st_nlink);
424#ifdef HAVE_STRUCT_STAT_ST_RDEV
430 ZVAL_LONG(&stat_atime, stat_sb->st_atime);
431 ZVAL_LONG(&stat_mtime, stat_sb->st_mtime);
432 ZVAL_LONG(&stat_ctime, stat_sb->st_ctime);
433#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
434 ZVAL_LONG(&stat_blksize, stat_sb->st_blksize);
438#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
439 ZVAL_LONG(&stat_blocks, stat_sb->st_blocks);
483 if (!filename_length) {
489 size_t arch_len, entry_len;
506 entry =
estrndup(filename, filename_length);
508 entry_len = filename_length;
515 entry =
estrndup(filename, filename_length);
517 entry_len = filename_length;
525 if (entry[0] ==
'/') {
526 if (
NULL != (
data = zend_hash_str_find_ptr(&(phar->
manifest), entry + 1, entry_len - 1))) {
532 if (
NULL != (
data = zend_hash_str_find_ptr(&(phar->
manifest), entry, entry_len))) {
536 if (zend_hash_str_exists(&(phar->
virtual_dirs), entry, entry_len)) {
544 sb.st_mode |= S_IFDIR;
558 entry =
estrndup(filename, filename_length);
559 entry_len = filename_length;
564 if (
NULL != (
data = zend_hash_str_find_ptr(&(phar->
manifest), entry + 1, entry_len - 1))) {
574 if (zend_hash_str_exists(&(phar->
virtual_dirs), entry + 1, entry_len - 1)) {
584 sb.st_mode |= S_IFDIR;
603 sb.st_size =
data->uncompressed_filesize;
608 sb.st_mode |= S_IFREG;
611 sb.st_mtime =
data->timestamp;
612 sb.st_atime =
data->timestamp;
613 sb.st_ctime =
data->timestamp;
617 sb.st_mode |= S_IFDIR;
622 sb.st_mtime =
data->timestamp;
623 sb.st_atime =
data->timestamp;
624 sb.st_ctime =
data->timestamp;
629 sb.st_mode = (sb.st_mode & 0555) | (sb.st_mode & ~0777);
638 sb.st_ino =
data->inode;
654#define PharFileFunction(fname, funcnum, orig) \
655PHP_FUNCTION(fname) { \
656 if (!PHAR_G(intercepted)) { \
657 PHAR_G(orig)(INTERNAL_FUNCTION_PARAM_PASSTHRU); \
660 size_t filename_len; \
662 if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { \
666 phar_file_stat(filename, filename_len, funcnum, PHAR_G(orig), INTERNAL_FUNCTION_PARAM_PASSTHRU); \
745 size_t arch_len, entry_len;
766 if (entry[0] ==
'/') {
767 if (
NULL != (etemp = zend_hash_str_find_ptr(&(phar->
manifest), entry + 1, entry_len - 1))) {
775 if (
NULL != (etemp = zend_hash_str_find_ptr(&(phar->
manifest), entry, entry_len))) {
780 if (entry != filename) {
811 size_t arch_len, entry_len;
832 if (entry[0] ==
'/') {
833 if (
NULL != (etemp = zend_hash_str_find_ptr(&(phar->
manifest), entry + 1, entry_len - 1))) {
841 if (
NULL != (etemp = zend_hash_str_find_ptr(&(phar->
manifest), entry, entry_len))) {
884#define PHAR_INTERCEPT(func) \
885 PHAR_G(orig_##func) = NULL; \
886 if (NULL != (orig = zend_hash_str_find_ptr(CG(function_table), #func, sizeof(#func)-1))) { \
887 PHAR_G(orig_##func) = orig->internal_function.handler; \
888 orig->internal_function.handler = PHP_FN(phar_##func); \
922#define PHAR_RELEASE(func) \
923 if (PHAR_G(orig_##func) && NULL != (orig = zend_hash_str_find_ptr(CG(function_table), #func, sizeof(#func)-1))) { \
924 orig->internal_function.handler = PHAR_G(orig_##func); \
926 PHAR_G(orig_##func) = NULL;
957static struct _phar_orig_functions {
980} phar_orig_functions = {0};
986 phar_orig_functions.orig_is_file =
PHAR_G(orig_is_file);
990 phar_orig_functions.orig_file_exists =
PHAR_G(orig_file_exists);
1001 phar_orig_functions.orig_is_readable =
PHAR_G(orig_is_readable);
1013 PHAR_G(orig_is_file) = phar_orig_functions.orig_is_file;
1017 PHAR_G(orig_file_exists) = phar_orig_functions.orig_file_exists;
1028 PHAR_G(orig_is_readable) = phar_orig_functions.orig_is_readable;
is_executable(string $filename)
filegroup(string $filename)
readfile(string $filename, bool $use_include_path=false, $context=null)
fileowner(string $filename)
filemtime(string $filename)
is_link(string $filename)
file_exists(string $filename)
file_get_contents(string $filename, bool $use_include_path=false, $context=null, int $offset=0, ?int $length=null)
is_readable(string $filename)
fileatime(string $filename)
opendir(string $directory, $context=null)
is_writable(string $filename)
is_file(string $filename)
fileperms(string $filename)
fopen(string $filename, string $mode, bool $use_include_path=false, $context=null)
filectime(string $filename)
fileinode(string $filename)
strstr(string $haystack, string $needle, bool $before_needle=false)
filetype(string $filename)
filesize(string $filename)
void phar_intercept_functions_shutdown(void)
void phar_restore_orig_functions(void)
#define PHAR_INTERCEPT(func)
#define IS_LINK_OPERATION(__t)
void phar_release_functions(void)
#define PHAR_RELEASE(func)
#define PharFileFunction(fname, funcnum, orig)
void phar_intercept_functions_init(void)
#define IS_EXISTS_CHECK(__t)
void phar_save_orig_functions(void)
void phar_intercept_functions(void)
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
char * phar_fix_filepath(char *path, size_t *new_len, int use_cwd)
zend_result phar_split_fname(const char *filename, size_t filename_len, char **arch, size_t *arch_len, char **entry, size_t *entry_len, int executable, int for_create)
zif_handler orig_filectime
zif_handler orig_is_writable
#define PHAR_ENT_PERM_MASK
phar_archive_data * last_phar
zif_handler orig_fileperms
zif_handler orig_filegroup
zif_handler orig_fileinode
uint32_t last_phar_name_len
zif_handler orig_filetype
struct _phar_archive_data phar_archive_data
zif_handler orig_file_get_contents
struct _phar_entry_info phar_entry_info
zend_string * phar_find_in_include_path(zend_string *file, phar_archive_data **pphar)
zif_handler orig_readfile
zif_handler orig_fileowner
zif_handler orig_filesize
zif_handler orig_is_executable
zend_result phar_get_archive(phar_archive_data **archive, char *fname, size_t fname_len, char *alias, size_t alias_len, char **error)
zif_handler orig_filemtime
zif_handler orig_fileatime
#define php_stream_context_from_zval(zcontext, nocontext)
struct _php_stream php_stream
struct _php_stream_context php_stream_context
#define PHP_STREAM_COPY_ALL
#define php_stream_seek(stream, offset, whence)
#define php_stream_to_zval(stream, zval)
#define php_stream_opendir(path, options, context)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context)
#define php_stream_close(stream)
#define php_stream_copy_to_mem(src, maxlen, persistent)
#define php_stream_passthru(stream)
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API zend_result zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec,...)
#define ZEND_PARSE_PARAMS_QUIET
#define RETVAL_EMPTY_STRING()
#define estrndup(s, length)
#define safe_emalloc(nmemb, size, offset)
zend_string_release_ex(func->internal_function.function_name, 0)
void(ZEND_FASTCALL * zif_handler)(INTERNAL_FUNCTION_PARAMETERS)
ZEND_API zend_string * zend_get_executed_filename_ex(void)
union _zend_function zend_function
ZEND_API zval *ZEND_FASTCALL zend_hash_next_index_insert(HashTable *ht, zval *pData)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
#define HT_IS_INITIALIZED(ht)
struct _zend_string zend_string
ZEND_API zend_string * zend_string_concat3(const char *str1, size_t str1_len, const char *str2, size_t str2_len, const char *str3, size_t str3_len)
#define zend_string_starts_with_literal_ci(str, prefix)
#define Z_ARRVAL_P(zval_p)
#define IS_ABSOLUTE_PATH(path, len)