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: 11 49 22.4 %
Date: 2014-04-16 Functions: 3 10 30.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-2014 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_qsort.h"
      37             : #include "zend_vm.h"
      38             : #include "main/php_streams.h"
      39             : #include "main/streams/php_stream_plain_wrapper.h"
      40             : #include "main/SAPI.h"
      41             : #include "main/php_main.h"
      42             : #include "main/php_open_temporary_file.h"
      43             : #include "ext/standard/info.h"
      44             : #include "ext/standard/basic_functions.h"
      45             : #include "ext/standard/file.h"
      46             : #include "ext/standard/php_string.h"
      47             : #include "ext/standard/url.h"
      48             : #include "ext/standard/crc32.h"
      49             : #include "ext/standard/md5.h"
      50             : #include "ext/standard/sha1.h"
      51             : #include "ext/standard/php_var.h"
      52             : #include "ext/standard/php_smart_str.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             : #       define PHAR_G(v) TSRMG(phar_globals_id, zend_phar_globals *, v)
     200             : #       define PHAR_GLOBALS ((zend_phar_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(phar_globals_id)])
     201             : #else
     202             : #       define PHAR_G(v) (phar_globals.v)
     203             : #       define PHAR_GLOBALS (&phar_globals)
     204             : #endif
     205             : 
     206             : #ifndef php_uint16
     207             : # if SIZEOF_SHORT == 2
     208             : #  define php_uint16 unsigned short
     209             : # else
     210             : #  define php_uint16 uint16_t
     211             : # endif
     212             : #endif
     213             : #include "pharzip.h"
     214             : 
     215             : #if HAVE_SPL
     216             : typedef union _phar_archive_object  phar_archive_object;
     217             : typedef union _phar_entry_object    phar_entry_object;
     218             : #endif
     219             : 
     220             : /*
     221             :  * used in phar_entry_info->fp_type to
     222             :  */
     223             : enum phar_fp_type {
     224             :         /* regular file pointer phar_archive_data->fp */
     225             :         PHAR_FP,
     226             :         /* uncompressed file pointer phar_archive_data->uncompressed_fp */
     227             :         PHAR_UFP,
     228             :         /* modified file pointer phar_entry_info->fp */
     229             :         PHAR_MOD,
     230             :         /* temporary manifest entry (file outside of the phar mapped to a location inside the phar)
     231             :            this entry stores the stream to open in link (normally used for tars, but we steal it here) */
     232             :         PHAR_TMP
     233             : };
     234             : 
     235             : /* entry for one file in a phar file */
     236             : typedef struct _phar_entry_info {
     237             :         /* first bytes are exactly as in file */
     238             :         php_uint32               uncompressed_filesize;
     239             :         php_uint32               timestamp;
     240             :         php_uint32               compressed_filesize;
     241             :         php_uint32               crc32;
     242             :         php_uint32               flags;
     243             :         /* remainder */
     244             :         /* when changing compression, save old flags in case fp is NULL */
     245             :         php_uint32               old_flags;
     246             :         zval                     *metadata;
     247             :         int                      metadata_len; /* only used for cached manifests */
     248             :         php_uint32               filename_len;
     249             :         char                     *filename;
     250             :         enum phar_fp_type        fp_type;
     251             :         /* offset within original phar file of the file contents */
     252             :         long                     offset_abs;
     253             :         /* offset within fp of the file contents */
     254             :         long                     offset;
     255             :         /* offset within original phar file of the file header (for zip-based/tar-based) */
     256             :         long                     header_offset;
     257             :         php_stream               *fp;
     258             :         php_stream               *cfp;
     259             :         int                      fp_refcount;
     260             :         char                     *tmp;
     261             :         phar_archive_data        *phar;
     262             :         smart_str                metadata_str;
     263             :         char                     *link; /* symbolic link to another file */
     264             :         char                     tar_type;
     265             :         /* position in the manifest */
     266             :         uint                     manifest_pos;
     267             :         /* for stat */
     268             :         unsigned short           inode;
     269             : 
     270             :         unsigned int             is_crc_checked:1;
     271             :         unsigned int             is_modified:1;
     272             :         unsigned int             is_deleted:1;
     273             :         unsigned int             is_dir:1;
     274             :         /* this flag is used for mounted entries (external files mapped to location
     275             :            inside a phar */
     276             :         unsigned int             is_mounted:1;
     277             :         /* used when iterating */
     278             :         unsigned int             is_temp_dir:1;
     279             :         /* tar-based phar file stuff */
     280             :         unsigned int             is_tar:1;
     281             :         /* zip-based phar file stuff */
     282             :         unsigned int             is_zip:1;
     283             :         /* for cached phar entries */
     284             :         unsigned int             is_persistent:1;
     285             : } phar_entry_info;
     286             : 
     287             : /* information about a phar file (the archive itself) */
     288             : struct _phar_archive_data {
     289             :         char                     *fname;
     290             :         int                      fname_len;
     291             :         /* for phar_detect_fname_ext, this stores the location of the file extension within fname */
     292             :         char                     *ext;
     293             :         int                      ext_len;
     294             :         char                     *alias;
     295             :         int                      alias_len;
     296             :         char                     version[12];
     297             :         size_t                   internal_file_start;
     298             :         size_t                   halt_offset;
     299             :         HashTable                manifest;
     300             :         /* hash of virtual directories, as in path/to/file.txt has path/to and path as virtual directories */
     301             :         HashTable                virtual_dirs;
     302             :         /* hash of mounted directory paths */
     303             :         HashTable                mounted_dirs;
     304             :         php_uint32               flags;
     305             :         php_uint32               min_timestamp;
     306             :         php_uint32               max_timestamp;
     307             :         php_stream               *fp;
     308             :         /* decompressed file contents are stored here */
     309             :         php_stream               *ufp;
     310             :         int                      refcount;
     311             :         php_uint32               sig_flags;
     312             :         int                      sig_len;
     313             :         char                     *signature;
     314             :         zval                     *metadata;
     315             :         int                      metadata_len; /* only used for cached manifests */
     316             :         uint                     phar_pos;
     317             :         /* if 1, then this alias was manually specified by the user and is not a permanent alias */
     318             :         unsigned int             is_temporary_alias:1;
     319             :         unsigned int             is_modified:1;
     320             :         unsigned int             is_writeable:1;
     321             :         unsigned int             is_brandnew:1;
     322             :         /* defer phar creation */
     323             :         unsigned int             donotflush:1;
     324             :         /* zip-based phar variables */
     325             :         unsigned int             is_zip:1;
     326             :         /* tar-based phar variables */
     327             :         unsigned int             is_tar:1;
     328             :         /* PharData variables       */
     329             :         unsigned int             is_data:1;
     330             :         /* for cached phar manifests */
     331             :         unsigned int             is_persistent:1;
     332             : };
     333             : 
     334             : typedef struct _phar_entry_fp_info {
     335             :         enum phar_fp_type        fp_type;
     336             :         /* offset within fp of the file contents */
     337             :         long                     offset;
     338             : } phar_entry_fp_info;
     339             : 
     340             : struct _phar_entry_fp {
     341             :         php_stream *fp;
     342             :         php_stream *ufp;
     343             :         phar_entry_fp_info *manifest;
     344             : };
     345             : 
     346           0 : static inline php_stream *phar_get_entrypfp(phar_entry_info *entry TSRMLS_DC)
     347             : {
     348           0 :         if (!entry->is_persistent) {
     349           0 :                 return entry->phar->fp;
     350             :         }
     351           0 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].fp;
     352             : }
     353             : 
     354           0 : static inline php_stream *phar_get_entrypufp(phar_entry_info *entry TSRMLS_DC)
     355             : {
     356           0 :         if (!entry->is_persistent) {
     357           0 :                 return entry->phar->ufp;
     358             :         }
     359           0 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].ufp;
     360             : }
     361             : 
     362             : static inline void phar_set_entrypfp(phar_entry_info *entry, php_stream *fp TSRMLS_DC)
     363             : {
     364             :         if (!entry->phar->is_persistent) {
     365             :                 entry->phar->fp =  fp;
     366             :                 return;
     367             :         }
     368             : 
     369             :         PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].fp = fp;
     370             : }
     371             : 
     372           0 : static inline void phar_set_entrypufp(phar_entry_info *entry, php_stream *fp TSRMLS_DC)
     373             : {
     374           0 :         if (!entry->phar->is_persistent) {
     375           0 :                 entry->phar->ufp =  fp;
     376           0 :                 return;
     377             :         }
     378             : 
     379           0 :         PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].ufp = fp;
     380             : }
     381             : 
     382           1 : static inline php_stream *phar_get_pharfp(phar_archive_data *phar TSRMLS_DC)
     383             : {
     384           1 :         if (!phar->is_persistent) {
     385           1 :                 return phar->fp;
     386             :         }
     387           0 :         return PHAR_GLOBALS->cached_fp[phar->phar_pos].fp;
     388             : }
     389             : 
     390             : static inline php_stream *phar_get_pharufp(phar_archive_data *phar TSRMLS_DC)
     391             : {
     392             :         if (!phar->is_persistent) {
     393             :                 return phar->ufp;
     394             :         }
     395             :         return PHAR_GLOBALS->cached_fp[phar->phar_pos].ufp;
     396             : }
     397             : 
     398           0 : static inline void phar_set_pharfp(phar_archive_data *phar, php_stream *fp TSRMLS_DC)
     399             : {
     400           0 :         if (!phar->is_persistent) {
     401           0 :                 phar->fp =  fp;
     402           0 :                 return;
     403             :         }
     404             : 
     405           0 :         PHAR_GLOBALS->cached_fp[phar->phar_pos].fp = fp;
     406             : }
     407             : 
     408             : static inline void phar_set_pharufp(phar_archive_data *phar, php_stream *fp TSRMLS_DC)
     409             : {
     410             :         if (!phar->is_persistent) {
     411             :                 phar->ufp =  fp;
     412             :                 return;
     413             :         }
     414             : 
     415             :         PHAR_GLOBALS->cached_fp[phar->phar_pos].ufp = fp;
     416             : }
     417             : 
     418           0 : static inline void phar_set_fp_type(phar_entry_info *entry, enum phar_fp_type type, off_t offset TSRMLS_DC)
     419             : {
     420             :         phar_entry_fp_info *data;
     421             : 
     422           0 :         if (!entry->is_persistent) {
     423           0 :                 entry->fp_type = type;
     424           0 :                 entry->offset = offset;
     425           0 :                 return;
     426             :         }
     427           0 :         data = &(PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos]);
     428           0 :         data->fp_type = type;
     429           0 :         data->offset = offset;
     430             : }
     431             : 
     432           0 : static inline enum phar_fp_type phar_get_fp_type(phar_entry_info *entry TSRMLS_DC)
     433             : {
     434           0 :         if (!entry->is_persistent) {
     435           0 :                 return entry->fp_type;
     436             :         }
     437           0 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type;
     438             : }
     439             : 
     440           0 : static inline off_t phar_get_fp_offset(phar_entry_info *entry TSRMLS_DC)
     441             : {
     442           0 :         if (!entry->is_persistent) {
     443           0 :                 return entry->offset;
     444             :         }
     445           0 :         if (PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type == PHAR_FP) {
     446           0 :                 if (!PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].offset) {
     447           0 :                         PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].offset = entry->offset;
     448             :                 }
     449             :         }
     450           0 :         return PHAR_GLOBALS->cached_fp[entry->phar->phar_pos].manifest[entry->manifest_pos].offset;
     451             : }
     452             : 
     453             : #define PHAR_MIME_PHP '\0'
     454             : #define PHAR_MIME_PHPS '\1'
     455             : #define PHAR_MIME_OTHER '\2'
     456             : 
     457             : typedef struct _phar_mime_type {
     458             :         char *mime;
     459             :         int len;
     460             :         /* one of PHAR_MIME_* */
     461             :         char type;
     462             : } phar_mime_type;
     463             : 
     464             : /* stream access data for one file entry in a phar file */
     465             : typedef struct _phar_entry_data {
     466             :         phar_archive_data        *phar;
     467             :         php_stream               *fp;
     468             :         /* stream position proxy, allows multiple open streams referring to the same fp */
     469             :         off_t                    position;
     470             :         /* for copies of the phar fp, defines where 0 is */
     471             :         off_t                    zero;
     472             :         unsigned int             for_write:1;
     473             :         unsigned int             is_zip:1;
     474             :         unsigned int             is_tar:1;
     475             :         phar_entry_info          *internal_file;
     476             : } phar_entry_data;
     477             : 
     478             : #if HAVE_SPL
     479             : /* archive php object */
     480             : union _phar_archive_object {
     481             :         zend_object              std;
     482             :         spl_filesystem_object    spl;
     483             :         struct {
     484             :                 zend_object          std;
     485             :                 phar_archive_data    *archive;
     486             :         } arc;
     487             : };
     488             : #endif
     489             : 
     490             : #if HAVE_SPL
     491             : /* entry php object */
     492             : union _phar_entry_object {
     493             :         zend_object              std;
     494             :         spl_filesystem_object    spl;
     495             :         struct {
     496             :                 zend_object          std;
     497             :                 phar_entry_info      *entry;
     498             :         } ent;
     499             : };
     500             : #endif
     501             : 
     502             : #ifndef PHAR_MAIN
     503             : extern char *(*phar_save_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
     504             : #endif
     505             : 
     506             : BEGIN_EXTERN_C()
     507             : 
     508             : #ifdef PHP_WIN32
     509             : char *tsrm_strtok_r(char *s, const char *delim, char **last);
     510             : 
     511             : static inline void phar_unixify_path_separators(char *path, int path_len)
     512             : {
     513             :         char *s;
     514             : 
     515             :         /* unixify win paths */
     516             :         for (s = path; s - path < path_len; ++s) {
     517             :                 if (*s == '\\') {
     518             :                         *s = '/';
     519             :                 }
     520             :         }
     521             : }
     522             : #endif
     523             : /**
     524             :  * validate an alias, returns 1 for success, 0 for failure
     525             :  */
     526          21 : static inline int phar_validate_alias(const char *alias, int alias_len) /* {{{ */
     527             : {
     528          21 :         return !(memchr(alias, '/', alias_len) || memchr(alias, '\\', alias_len) || memchr(alias, ':', alias_len) ||
     529             :                 memchr(alias, ';', alias_len) || memchr(alias, '\n', alias_len) || memchr(alias, '\r', alias_len));
     530             : }
     531             : /* }}} */
     532             : 
     533         518 : static inline void phar_set_inode(phar_entry_info *entry TSRMLS_DC) /* {{{ */
     534             : {
     535             :         char tmp[MAXPATHLEN];
     536             :         int tmp_len;
     537             : 
     538         518 :         tmp_len = entry->filename_len + entry->phar->fname_len;
     539         518 :         memcpy(tmp, entry->phar->fname, entry->phar->fname_len);
     540         518 :         memcpy(tmp + entry->phar->fname_len, entry->filename, entry->filename_len);
     541         518 :         entry->inode = (unsigned short)zend_get_hash_value(tmp, tmp_len);
     542         518 : }
     543             : /* }}} */
     544             : 
     545             : void phar_request_initialize(TSRMLS_D);
     546             : 
     547             : void phar_object_init(TSRMLS_D);
     548             : void phar_destroy_phar_data(phar_archive_data *phar TSRMLS_DC);
     549             : 
     550             : int phar_open_entry_file(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC);
     551             : int phar_postprocess_file(phar_entry_data *idata, php_uint32 crc32, char **error, int process_zip TSRMLS_DC);
     552             : int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error TSRMLS_DC);
     553             : 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 TSRMLS_DC);
     554             : 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 TSRMLS_DC);
     555             : int phar_open_executed_filename(char *alias, int alias_len, char **error TSRMLS_DC);
     556             : int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len TSRMLS_DC);
     557             : int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error TSRMLS_DC);
     558             : 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 TSRMLS_DC);
     559             : 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 TSRMLS_DC);
     560             : int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error TSRMLS_DC);
     561             : 
     562             : /* utility functions */
     563             : char *phar_create_default_stub(const char *index_php, const char *web_index, size_t *len, char **error TSRMLS_DC);
     564             : char *phar_decompress_filter(phar_entry_info * entry, int return_unknown);
     565             : char *phar_compress_filter(phar_entry_info * entry, int return_unknown);
     566             : 
     567             : void phar_remove_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len TSRMLS_DC);
     568             : void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len TSRMLS_DC);
     569             : int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len TSRMLS_DC);
     570             : char *phar_find_in_include_path(char *file, int file_len, phar_archive_data **pphar TSRMLS_DC);
     571             : char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC);
     572             : phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC);
     573             : int phar_parse_metadata(char **buffer, zval **metadata, int zip_metadata_len TSRMLS_DC);
     574             : void destroy_phar_manifest_entry(void *pDest);
     575             : int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t position, int follow_links TSRMLS_DC);
     576             : php_stream *phar_get_efp(phar_entry_info *entry, int follow_links TSRMLS_DC);
     577             : int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error TSRMLS_DC);
     578             : int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TSRMLS_DC);
     579             : phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC);
     580             : int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC);
     581             : int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC);
     582             : int phar_open_archive_fp(phar_archive_data *phar TSRMLS_DC);
     583             : int phar_copy_on_write(phar_archive_data **pphar TSRMLS_DC);
     584             : 
     585             : /* tar functions in tar.c */
     586             : int phar_is_tar(char *buf, char *fname);
     587             : 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 TSRMLS_DC);
     588             : 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 TSRMLS_DC);
     589             : int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, int defaultstub, char **error TSRMLS_DC);
     590             : 
     591             : /* zip functions in zip.c */
     592             : int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, char **error TSRMLS_DC);
     593             : 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 TSRMLS_DC);
     594             : int phar_zip_flush(phar_archive_data *archive, char *user_stub, long len, int defaultstub, char **error TSRMLS_DC);
     595             : 
     596             : #ifdef PHAR_MAIN
     597             : 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 TSRMLS_DC);
     598             : extern php_stream_wrapper php_stream_phar_wrapper;
     599             : #else
     600             : extern HashTable cached_phars;
     601             : extern HashTable cached_alias;
     602             : #endif
     603             : 
     604             : int phar_archive_delref(phar_archive_data *phar TSRMLS_DC);
     605             : int phar_entry_delref(phar_entry_data *idata TSRMLS_DC);
     606             : 
     607             : phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security TSRMLS_DC);
     608             : phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security TSRMLS_DC);
     609             : 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 TSRMLS_DC);
     610             : 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 TSRMLS_DC);
     611             : int phar_flush(phar_archive_data *archive, char *user_stub, long len, int convert, char **error TSRMLS_DC);
     612             : 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 TSRMLS_DC);
     613             : 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 TSRMLS_DC);
     614             : 
     615             : typedef enum {
     616             :         pcr_use_query,
     617             :         pcr_is_ok,
     618             :         pcr_err_double_slash,
     619             :         pcr_err_up_dir,
     620             :         pcr_err_curr_dir,
     621             :         pcr_err_back_slash,
     622             :         pcr_err_star,
     623             :         pcr_err_illegal_char,
     624             :         pcr_err_empty_entry
     625             : } phar_path_check_result;
     626             : 
     627             : phar_path_check_result phar_path_check(char **p, int *len, const char **error);
     628             : 
     629             : END_EXTERN_C()
     630             : 
     631             : /*
     632             :  * Local variables:
     633             :  * tab-width: 4
     634             :  * c-basic-offset: 4
     635             :  * End:
     636             :  * vim600: noet sw=4 ts=4 fdm=marker
     637             :  * vim<600: noet sw=4 ts=4
     638             :  */

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:54 +0000 (2 days ago)

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