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