PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/phar - phar_internal.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 44 49 89.8 %
Date: 2015-04-14 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | phar php single-file executable PHP extension                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2015 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt.                                 |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Authors: Gregory Beaver <cellog@php.net>                             |
      16             :   |          Marcus Boerger <helly@php.net>                              |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include <time.h>
      27             : #include "php.h"
      28             : #include "tar.h"
      29             : #include "php_ini.h"
      30             : #include "zend_constants.h"
      31             : #include "zend_execute.h"
      32             : #include "zend_exceptions.h"
      33             : #include "zend_hash.h"
      34             : #include "zend_interfaces.h"
      35             : #include "zend_operators.h"
      36             : #include "zend_sort.h"
      37             : #include "zend_vm.h"
      38             : #include "zend_smart_str.h"
      39             : #include "main/php_streams.h"
      40             : #include "main/streams/php_stream_plain_wrapper.h"
      41             : #include "main/SAPI.h"
      42             : #include "main/php_main.h"
      43             : #include "main/php_open_temporary_file.h"
      44             : #include "ext/standard/info.h"
      45             : #include "ext/standard/basic_functions.h"
      46             : #include "ext/standard/file.h"
      47             : #include "ext/standard/php_string.h"
      48             : #include "ext/standard/url.h"
      49             : #include "ext/standard/crc32.h"
      50             : #include "ext/standard/md5.h"
      51             : #include "ext/standard/sha1.h"
      52             : #include "ext/standard/php_var.h"
      53             : #include "ext/standard/php_versioning.h"
      54             : #ifndef PHP_WIN32
      55             : #include "TSRM/tsrm_strtok_r.h"
      56             : #endif
      57             : #include "Zend/zend_virtual_cwd.h"
      58             : #if HAVE_SPL
      59             : #include "ext/spl/spl_array.h"
      60             : #include "ext/spl/spl_directory.h"
      61             : #include "ext/spl/spl_engine.h"
      62             : #include "ext/spl/spl_exceptions.h"
      63             : #include "ext/spl/spl_iterators.h"
      64             : #endif
      65             : #include "php_phar.h"
      66             : #ifdef PHAR_HASH_OK
      67             : #include "ext/hash/php_hash.h"
      68             : #include "ext/hash/php_hash_sha.h"
      69             : #endif
      70             : 
      71             : /* PHP_ because this is public information via MINFO */
      72             : #define PHP_PHAR_API_VERSION      "1.1.1"
      73             : /* x.y.z maps to 0xyz0 */
      74             : #define PHAR_API_VERSION          0x1110
      75             : /* if we bump PHAR_API_VERSION, change this from 0x1100 to PHAR_API_VERSION */
      76             : #define PHAR_API_VERSION_NODIR    0x1100
      77             : #define PHAR_API_MIN_DIR          0x1110
      78             : #define PHAR_API_MIN_READ         0x1000
      79             : #define PHAR_API_MAJORVERSION     0x1000
      80             : #define PHAR_API_MAJORVER_MASK    0xF000
      81             : #define PHAR_API_VER_MASK         0xFFF0
      82             : 
      83             : #define PHAR_HDR_COMPRESSION_MASK 0x0000F000
      84             : #define PHAR_HDR_COMPRESSED_NONE  0x00000000
      85             : #define PHAR_HDR_COMPRESSED_GZ    0x00001000
      86             : #define PHAR_HDR_COMPRESSED_BZ2   0x00002000
      87             : #define PHAR_HDR_SIGNATURE        0x00010000
      88             : 
      89             : /* flags for defining that the entire file should be compressed */
      90             : #define PHAR_FILE_COMPRESSION_MASK 0x00F00000
      91             : #define PHAR_FILE_COMPRESSED_NONE  0x00000000
      92             : #define PHAR_FILE_COMPRESSED_GZ    0x00100000
      93             : #define PHAR_FILE_COMPRESSED_BZ2   0x00200000
      94             : 
      95             : #define PHAR_SIG_MD5              0x0001
      96             : #define PHAR_SIG_SHA1             0x0002
      97             : #define PHAR_SIG_SHA256           0x0003
      98             : #define PHAR_SIG_SHA512           0x0004
      99             : #define PHAR_SIG_OPENSSL          0x0010
     100             : 
     101             : /* flags byte for each file adheres to these bitmasks.
     102             :    All unused values are reserved */
     103             : #define PHAR_ENT_COMPRESSION_MASK 0x0000F000
     104             : #define PHAR_ENT_COMPRESSED_NONE  0x00000000
     105             : #define PHAR_ENT_COMPRESSED_GZ    0x00001000
     106             : #define PHAR_ENT_COMPRESSED_BZ2   0x00002000
     107             : 
     108             : #define PHAR_ENT_PERM_MASK        0x000001FF
     109             : #define PHAR_ENT_PERM_MASK_USR    0x000001C0
     110             : #define PHAR_ENT_PERM_SHIFT_USR   6
     111             : #define PHAR_ENT_PERM_MASK_GRP    0x00000038
     112             : #define PHAR_ENT_PERM_SHIFT_GRP   3
     113             : #define PHAR_ENT_PERM_MASK_OTH    0x00000007
     114             : #define PHAR_ENT_PERM_DEF_FILE    0x000001B6
     115             : #define PHAR_ENT_PERM_DEF_DIR     0x000001FF
     116             : 
     117             : #define PHAR_FORMAT_SAME    0
     118             : #define PHAR_FORMAT_PHAR    1
     119             : #define PHAR_FORMAT_TAR     2
     120             : #define PHAR_FORMAT_ZIP     3
     121             : 
     122             : #define TAR_FILE    '0'
     123             : #define TAR_LINK    '1'
     124             : #define TAR_SYMLINK '2'
     125             : #define TAR_DIR     '5'
     126             : #define TAR_NEW     '8'
     127             : 
     128             : #define PHAR_MUNG_PHP_SELF                      (1<<0)
     129             : #define PHAR_MUNG_REQUEST_URI           (1<<1)
     130             : #define PHAR_MUNG_SCRIPT_NAME           (1<<2)
     131             : #define PHAR_MUNG_SCRIPT_FILENAME       (1<<3)
     132             : 
     133             : typedef struct _phar_entry_fp phar_entry_fp;
     134             : typedef struct _phar_archive_data phar_archive_data;
     135             : 
     136             : ZEND_BEGIN_MODULE_GLOBALS(phar)
     137             :         /* a list of phar_archive_data objects that reference a cached phar, so
     138             :            that if copy-on-write is performed, we can swap them out for the new value */
     139             :         HashTable   phar_persist_map;
     140             :         HashTable   phar_fname_map;
     141             :         /* for cached phars, this is a per-process store of fp/ufp */
     142             :         phar_entry_fp *cached_fp;
     143             :         HashTable   phar_alias_map;
     144             :         int         phar_SERVER_mung_list;
     145             :         int         readonly;
     146             :         char*       cache_list;
     147             :         int         manifest_cached;
     148             :         int         persist;
     149             :         int         has_zlib;
     150             :         int         has_bz2;
     151             :         zend_bool   readonly_orig;
     152             :         zend_bool   require_hash_orig;
     153             :         zend_bool   intercepted;
     154             :         int         request_init;
     155             :         int         require_hash;
     156             :         int         request_done;
     157             :         int         request_ends;
     158             :         void        (*orig_fopen)(INTERNAL_FUNCTION_PARAMETERS);
     159             :         void        (*orig_file_get_contents)(INTERNAL_FUNCTION_PARAMETERS);
     160             :         void        (*orig_is_file)(INTERNAL_FUNCTION_PARAMETERS);
     161             :         void        (*orig_is_link)(INTERNAL_FUNCTION_PARAMETERS);
     162             :         void        (*orig_is_dir)(INTERNAL_FUNCTION_PARAMETERS);
     163             :         void        (*orig_opendir)(INTERNAL_FUNCTION_PARAMETERS);
     164             :         void        (*orig_file_exists)(INTERNAL_FUNCTION_PARAMETERS);
     165             :         void        (*orig_fileperms)(INTERNAL_FUNCTION_PARAMETERS);
     166             :         void        (*orig_fileinode)(INTERNAL_FUNCTION_PARAMETERS);
     167             :         void        (*orig_filesize)(INTERNAL_FUNCTION_PARAMETERS);
     168             :         void        (*orig_fileowner)(INTERNAL_FUNCTION_PARAMETERS);
     169             :         void        (*orig_filegroup)(INTERNAL_FUNCTION_PARAMETERS);
     170             :         void        (*orig_fileatime)(INTERNAL_FUNCTION_PARAMETERS);
     171             :         void        (*orig_filemtime)(INTERNAL_FUNCTION_PARAMETERS);
     172             :         void        (*orig_filectime)(INTERNAL_FUNCTION_PARAMETERS);
     173             :         void        (*orig_filetype)(INTERNAL_FUNCTION_PARAMETERS);
     174             :         void        (*orig_is_writable)(INTERNAL_FUNCTION_PARAMETERS);
     175             :         void        (*orig_is_readable)(INTERNAL_FUNCTION_PARAMETERS);
     176             :         void        (*orig_is_executable)(INTERNAL_FUNCTION_PARAMETERS);
     177             :         void        (*orig_lstat)(INTERNAL_FUNCTION_PARAMETERS);
     178             :         void        (*orig_readfile)(INTERNAL_FUNCTION_PARAMETERS);
     179             :         void        (*orig_stat)(INTERNAL_FUNCTION_PARAMETERS);
     180             :         /* used for includes with . in them inside front controller */
     181             :         char*       cwd;
     182             :         int         cwd_len;
     183             :         int         cwd_init;
     184             :         char        *openssl_privatekey;
     185             :         int         openssl_privatekey_len;
     186             :         /* phar_get_archive cache */
     187             :         char*       last_phar_name;
     188             :         int         last_phar_name_len;
     189             :         char*       last_alias;
     190             :         int         last_alias_len;
     191             :         phar_archive_data* last_phar;
     192             :         HashTable mime_types;
     193             : ZEND_END_MODULE_GLOBALS(phar)
     194             : 
     195             : ZEND_EXTERN_MODULE_GLOBALS(phar)
     196             : 
     197             : #ifdef ZTS
     198             : #       include "TSRM.h"
     199             : #   ifdef COMPILE_DL_PHAR
     200             : ZEND_TSRMLS_CACHE_EXTERN;
     201             : #   endif
     202             : #       define PHAR_G(v) ZEND_TSRMG(phar_globals_id, zend_phar_globals *, v)
     203             : #       define PHAR_GLOBALS ((zend_phar_globals *) (*((void ***) ZEND_TSRMLS_CACHE))[TSRM_UNSHUFFLE_RSRC_ID(phar_globals_id)])
     204             : #else
     205             : #       define PHAR_G(v) (phar_globals.v)
     206             : #       define PHAR_GLOBALS (&phar_globals)
     207             : #endif
     208             : 
     209             : #ifndef php_uint16
     210             : # if SIZEOF_SHORT == 2
     211             : #  define php_uint16 unsigned short
     212             : # else
     213             : #  define php_uint16 uint16_t
     214             : # endif
     215             : #endif
     216             : #include "pharzip.h"
     217             : 
     218             : #if HAVE_SPL
     219             : typedef union _phar_archive_object  phar_archive_object;
     220             : typedef union _phar_entry_object    phar_entry_object;
     221             : #endif
     222             : 
     223             : /*
     224             :  * used in phar_entry_info->fp_type to
     225             :  */
     226             : enum phar_fp_type {
     227             :         /* regular file pointer phar_archive_data->fp */
     228             :         PHAR_FP,
     229             :         /* uncompressed file pointer phar_archive_data->uncompressed_fp */
     230             :         PHAR_UFP,
     231             :         /* modified file pointer phar_entry_info->fp */
     232             :         PHAR_MOD,
     233             :         /* temporary manifest entry (file outside of the phar mapped to a location inside the phar)
     234             :            this entry stores the stream to open in link (normally used for tars, but we steal it here) */
     235             :         PHAR_TMP
     236             : };
     237             : 
     238             : /* entry for one file in a phar file */
     239             : typedef struct _phar_entry_info {
     240             :         /* first bytes are exactly as in file */
     241             :         php_uint32               uncompressed_filesize;
     242             :         php_uint32               timestamp;
     243             :         php_uint32               compressed_filesize;
     244             :         php_uint32               crc32;
     245             :         php_uint32               flags;
     246             :         /* remainder */
     247             :         /* when changing compression, save old flags in case fp is NULL */
     248             :         php_uint32               old_flags;
     249             :         zval                     metadata;
     250             :         int                      metadata_len; /* only used for cached manifests */
     251             :         php_uint32               filename_len;
     252             :         char                     *filename;
     253             :         enum phar_fp_type        fp_type;
     254             :         /* offset within original phar file of the file contents */
     255             :         zend_long                     offset_abs;
     256             :         /* offset within fp of the file contents */
     257             :         zend_long                     offset;
     258             :         /* offset within original phar file of the file header (for zip-based/tar-based) */
     259             :         zend_long                     header_offset;
     260             :         php_stream               *fp;
     261             :         php_stream               *cfp;
     262             :         int                      fp_refcount;
     263             :         char                     *tmp;
     264             :         phar_archive_data        *phar;
     265             :         smart_str                metadata_str;
     266             :         char                     *link; /* symbolic link to another file */
     267             :         char                     tar_type;
     268             :         /* position in the manifest */
     269             :         uint                     manifest_pos;
     270             :         /* for stat */
     271             :         unsigned short           inode;
     272             : 
     273             :         unsigned int             is_crc_checked:1;
     274             :         unsigned int             is_modified:1;
     275             :         unsigned int             is_deleted:1;
     276             :         unsigned int             is_dir:1;
     277             :         /* this flag is used for mounted entries (external files mapped to location
     278             :            inside a phar */
     279             :         unsigned int             is_mounted:1;
     280             :         /* used when iterating */
     281             :         unsigned int             is_temp_dir:1;
     282             :         /* tar-based phar file stuff */
     283             :         unsigned int             is_tar:1;
     284             :         /* zip-based phar file stuff */
     285             :         unsigned int             is_zip:1;
     286             :         /* for cached phar entries */
     287             :         unsigned int             is_persistent:1;
     288             : } phar_entry_info;
     289             : 
     290             : /* information about a phar file (the archive itself) */
     291             : struct _phar_archive_data {
     292             :         char                     *fname;
     293             :         int                      fname_len;
     294             :         /* for phar_detect_fname_ext, this stores the location of the file extension within fname */
     295             :         char                     *ext;
     296             :         int                      ext_len;
     297             :         char                     *alias;
     298             :         int                      alias_len;
     299             :         char                     version[12];
     300             :         size_t                   internal_file_start;
     301             :         size_t                   halt_offset;
     302             :         HashTable                manifest;
     303             :         /* hash of virtual directories, as in path/to/file.txt has path/to and path as virtual directories */
     304             :         HashTable                virtual_dirs;
     305             :         /* hash of mounted directory paths */
     306             :         HashTable                mounted_dirs;
     307             :         php_uint32               flags;
     308             :         php_uint32               min_timestamp;
     309             :         php_uint32               max_timestamp;
     310             :         php_stream               *fp;
     311             :         /* decompressed file contents are stored here */
     312             :         php_stream               *ufp;
     313             :         int                      refcount;
     314             :         php_uint32               sig_flags;
     315             :         int                      sig_len;
     316             :         char                     *signature;
     317             :         zval                     metadata;
     318             :         int                      metadata_len; /* only used for cached manifests */
     319             :         uint                     phar_pos;
     320             :         /* if 1, then this alias was manually specified by the user and is not a permanent alias */
     321             :         unsigned int             is_temporary_alias:1;
     322             :         unsigned int             is_modified:1;
     323             :         unsigned int             is_writeable:1;
     324             :         unsigned int             is_brandnew:1;
     325             :         /* defer phar creation */
     326             :         unsigned int             donotflush:1;
     327             :         /* zip-based phar variables */
     328             :         unsigned int             is_zip:1;
     329             :         /* tar-based phar variables */
     330             :         unsigned int             is_tar:1;
     331             :         /* PharData variables       */
     332             :         unsigned int             is_data:1;
     333             :         /* for cached phar manifests */
     334             :         unsigned int             is_persistent:1;
     335             : };
     336             : 
     337             : typedef struct _phar_entry_fp_info {
     338             :         enum phar_fp_type        fp_type;
     339             :         /* offset within fp of the file contents */
     340             :         zend_long                     offset;
     341             : } phar_entry_fp_info;
     342             : 
     343             : struct _phar_entry_fp {
     344             :         php_stream *fp;
     345             :         php_stream *ufp;
     346             :         phar_entry_fp_info *manifest;
     347             : };
     348             : 
     349       32471 : static inline php_stream *phar_get_entrypfp(phar_entry_info *entry)
     350             : {
     351       32471 :         if (!entry->is_persistent) {
     352       32467 :                 return entry->phar->fp;
     353             :         }
     354           4 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].fp;
     355             : }
     356             : 
     357       15744 : static inline php_stream *phar_get_entrypufp(phar_entry_info *entry)
     358             : {
     359       15744 :         if (!entry->is_persistent) {
     360       15744 :                 return entry->phar->ufp;
     361             :         }
     362           0 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].ufp;
     363             : }
     364             : 
     365             : static inline void phar_set_entrypfp(phar_entry_info *entry, php_stream *fp)
     366             : {
     367             :         if (!entry->phar->is_persistent) {
     368             :                 entry->phar->fp =  fp;
     369             :                 return;
     370             :         }
     371             : 
     372             :         PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].fp = fp;
     373             : }
     374             : 
     375          24 : static inline void phar_set_entrypufp(phar_entry_info *entry, php_stream *fp)
     376             : {
     377          24 :         if (!entry->phar->is_persistent) {
     378          24 :                 entry->phar->ufp =  fp;
     379          24 :                 return;
     380             :         }
     381             : 
     382           0 :         PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].ufp = fp;
     383             : }
     384             : 
     385        2627 : static inline php_stream *phar_get_pharfp(phar_archive_data *phar)
     386             : {
     387        2627 :         if (!phar->is_persistent) {
     388        2623 :                 return phar->fp;
     389             :         }
     390           4 :         return PHAR_GLOBALS->cached_fp[phar->phar_pos].fp;
     391             : }
     392             : 
     393             : static inline php_stream *phar_get_pharufp(phar_archive_data *phar)
     394             : {
     395             :         if (!phar->is_persistent) {
     396             :                 return phar->ufp;
     397             :         }
     398             :         return PHAR_GLOBALS->cached_fp[phar->phar_pos].ufp;
     399             : }
     400             : 
     401         169 : static inline void phar_set_pharfp(phar_archive_data *phar, php_stream *fp)
     402             : {
     403         169 :         if (!phar->is_persistent) {
     404         168 :                 phar->fp =  fp;
     405         168 :                 return;
     406             :         }
     407             : 
     408           1 :         PHAR_GLOBALS->cached_fp[phar->phar_pos].fp = fp;
     409             : }
     410             : 
     411             : static inline void phar_set_pharufp(phar_archive_data *phar, php_stream *fp)
     412             : {
     413             :         if (!phar->is_persistent) {
     414             :                 phar->ufp =  fp;
     415             :                 return;
     416             :         }
     417             : 
     418             :         PHAR_GLOBALS->cached_fp[phar->phar_pos].ufp = fp;
     419             : }
     420             : 
     421          37 : static inline void phar_set_fp_type(phar_entry_info *entry, enum phar_fp_type type, zend_off_t offset)
     422             : {
     423             :         phar_entry_fp_info *data;
     424             : 
     425          37 :         if (!entry->is_persistent) {
     426          37 :                 entry->fp_type = type;
     427          37 :                 entry->offset = offset;
     428          37 :                 return;
     429             :         }
     430           0 :         data = &(PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos]);
     431           0 :         data->fp_type = type;
     432           0 :         data->offset = offset;
     433             : }
     434             : 
     435      103525 : static inline enum phar_fp_type phar_get_fp_type(phar_entry_info *entry)
     436             : {
     437      103525 :         if (!entry->is_persistent) {
     438      103523 :                 return entry->fp_type;
     439             :         }
     440           2 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type;
     441             : }
     442             : 
     443       28485 : static inline zend_off_t phar_get_fp_offset(phar_entry_info *entry)
     444             : {
     445       28485 :         if (!entry->is_persistent) {
     446       28484 :                 return entry->offset;
     447             :         }
     448           1 :         if (PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type == PHAR_FP) {
     449           1 :                 if (!PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].offset) {
     450           1 :                         PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].offset = entry->offset;
     451             :                 }
     452             :         }
     453           1 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].offset;
     454             : }
     455             : 
     456             : #define PHAR_MIME_PHP '\0'
     457             : #define PHAR_MIME_PHPS '\1'
     458             : #define PHAR_MIME_OTHER '\2'
     459             : 
     460             : typedef struct _phar_mime_type {
     461             :         char *mime;
     462             :         int len;
     463             :         /* one of PHAR_MIME_* */
     464             :         char type;
     465             : } phar_mime_type;
     466             : 
     467             : /* stream access data for one file entry in a phar file */
     468             : typedef struct _phar_entry_data {
     469             :         phar_archive_data        *phar;
     470             :         php_stream               *fp;
     471             :         /* stream position proxy, allows multiple open streams referring to the same fp */
     472             :         zend_off_t                    position;
     473             :         /* for copies of the phar fp, defines where 0 is */
     474             :         zend_off_t                    zero;
     475             :         unsigned int             for_write:1;
     476             :         unsigned int             is_zip:1;
     477             :         unsigned int             is_tar:1;
     478             :         phar_entry_info          *internal_file;
     479             : } phar_entry_data;
     480             : 
     481             : #if HAVE_SPL
     482             : /* archive php object */
     483             : union _phar_archive_object {
     484             :         spl_filesystem_object    spl;
     485             :         phar_archive_data        *archive;
     486             : };
     487             : #endif
     488             : 
     489             : #if HAVE_SPL
     490             : /* entry php object */
     491             : union _phar_entry_object {
     492             :         spl_filesystem_object    spl;
     493             :         phar_entry_info          *entry;
     494             : };
     495             : #endif
     496             : 
     497             : #ifndef PHAR_MAIN
     498             : extern char *(*phar_save_resolve_path)(const char *filename, int filename_len);
     499             : #endif
     500             : 
     501             : BEGIN_EXTERN_C()
     502             : 
     503             : #ifdef PHP_WIN32
     504             : char *tsrm_strtok_r(char *s, const char *delim, char **last);
     505             : 
     506             : static inline void phar_unixify_path_separators(char *path, int path_len)
     507             : {
     508             :         char *s;
     509             : 
     510             :         /* unixify win paths */
     511             :         for (s = path; s - path < path_len; ++s) {
     512             :                 if (*s == '\\') {
     513             :                         *s = '/';
     514             :                 }
     515             :         }
     516             : }
     517             : #endif
     518             : /**
     519             :  * validate an alias, returns 1 for success, 0 for failure
     520             :  */
     521         210 : static inline int phar_validate_alias(const char *alias, int alias_len) /* {{{ */
     522             : {
     523         210 :         return !(memchr(alias, '/', alias_len) || memchr(alias, '\\', alias_len) || memchr(alias, ':', alias_len) ||
     524             :                 memchr(alias, ';', alias_len) || memchr(alias, '\n', alias_len) || memchr(alias, '\r', alias_len));
     525             : }
     526             : /* }}} */
     527             : 
     528        1514 : static inline void phar_set_inode(phar_entry_info *entry) /* {{{ */
     529             : {
     530             :         char tmp[MAXPATHLEN];
     531             :         int tmp_len;
     532             : 
     533        1514 :         tmp_len = entry->filename_len + entry->phar->fname_len;
     534        1514 :         memcpy(tmp, entry->phar->fname, entry->phar->fname_len);
     535        1514 :         memcpy(tmp + entry->phar->fname_len, entry->filename, entry->filename_len);
     536        1514 :         entry->inode = (unsigned short)zend_hash_func(tmp, tmp_len);
     537        1514 : }
     538             : /* }}} */
     539             : 
     540             : void phar_request_initialize(void);
     541             : 
     542             : void phar_object_init(void);
     543             : void phar_destroy_phar_data(phar_archive_data *phar);
     544             : 
     545             : int phar_open_entry_file(phar_archive_data *phar, phar_entry_info *entry, char **error);
     546             : int phar_postprocess_file(phar_entry_data *idata, php_uint32 crc32, char **error, int process_zip);
     547             : int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error);
     548             : int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     549             : int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     550             : int phar_open_executed_filename(char *alias, int alias_len, char **error);
     551             : int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len);
     552             : int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error);
     553             : int phar_open_parsed_phar(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     554             : int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_type, char *sig, int sig_len, char *fname, char **signature, int *signature_len, char **error);
     555             : int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error);
     556             : 
     557             : /* utility functions */
     558             : char *phar_create_default_stub(const char *index_php, const char *web_index, size_t *len, char **error);
     559             : char *phar_decompress_filter(phar_entry_info * entry, int return_unknown);
     560             : char *phar_compress_filter(phar_entry_info * entry, int return_unknown);
     561             : 
     562             : void phar_remove_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
     563             : void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
     564             : int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len);
     565             : char *phar_find_in_include_path(char *file, int file_len, phar_archive_data **pphar);
     566             : char *phar_fix_filepath(char *path, int *new_len, int use_cwd);
     567             : phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error);
     568             : int phar_parse_metadata(char **buffer, zval *metadata, int zip_metadata_len);
     569             : void destroy_phar_manifest_entry(zval *zv);
     570             : int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, int follow_links);
     571             : php_stream *phar_get_efp(phar_entry_info *entry, int follow_links);
     572             : int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error);
     573             : int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links);
     574             : phar_entry_info *phar_get_link_source(phar_entry_info *entry);
     575             : int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error);
     576             : int phar_separate_entry_fp(phar_entry_info *entry, char **error);
     577             : int phar_open_archive_fp(phar_archive_data *phar);
     578             : int phar_copy_on_write(phar_archive_data **pphar);
     579             : 
     580             : /* tar functions in tar.c */
     581             : int phar_is_tar(char *buf, char *fname);
     582             : int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, int is_data, php_uint32 compression, char **error);
     583             : int phar_open_or_create_tar(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     584             : int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int defaultstub, char **error);
     585             : 
     586             : /* zip functions in zip.c */
     587             : int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, char **error);
     588             : int phar_open_or_create_zip(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error);
     589             : int phar_zip_flush(phar_archive_data *archive, char *user_stub, zend_long len, int defaultstub, char **error);
     590             : 
     591             : #ifdef PHAR_MAIN
     592             : static int phar_open_from_fp(php_stream* fp, char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, int is_data, char **error);
     593             : extern php_stream_wrapper php_stream_phar_wrapper;
     594             : #else
     595             : extern HashTable cached_phars;
     596             : extern HashTable cached_alias;
     597             : #endif
     598             : 
     599             : int phar_archive_delref(phar_archive_data *phar);
     600             : int phar_entry_delref(phar_entry_data *idata);
     601             : 
     602             : phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security);
     603             : phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security);
     604             : phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security);
     605             : int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char *path, int path_len, const char *mode, char allow_dir, char **error, int security);
     606             : int phar_flush(phar_archive_data *archive, char *user_stub, zend_long len, int convert, char **error);
     607             : int phar_detect_phar_fname_ext(const char *filename, int filename_len, const char **ext_str, int *ext_len, int executable, int for_create, int is_complete);
     608             : int phar_split_fname(const char *filename, int filename_len, char **arch, int *arch_len, char **entry, int *entry_len, int executable, int for_create);
     609             : 
     610             : typedef enum {
     611             :         pcr_use_query,
     612             :         pcr_is_ok,
     613             :         pcr_err_double_slash,
     614             :         pcr_err_up_dir,
     615             :         pcr_err_curr_dir,
     616             :         pcr_err_back_slash,
     617             :         pcr_err_star,
     618             :         pcr_err_illegal_char,
     619             :         pcr_err_empty_entry
     620             : } phar_path_check_result;
     621             : 
     622             : phar_path_check_result phar_path_check(char **p, int *len, const char **error);
     623             : 
     624             : END_EXTERN_C()
     625             : 
     626             : /*
     627             :  * Local variables:
     628             :  * tab-width: 4
     629             :  * c-basic-offset: 4
     630             :  * End:
     631             :  * vim600: noet sw=4 ts=4 fdm=marker
     632             :  * vim<600: noet sw=4 ts=4
     633             :  */

Generated by: LCOV version 1.10

Generated at Tue, 14 Apr 2015 11:48:49 +0000 (4 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.