1 /*
2 +----------------------------------------------------------------------+
3 | phar php single-file executable PHP extension |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2006-2017 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 #define TAR_GLOBAL_HDR 'g'
128 #define TAR_FILE_HDR 'x'
129
130 #define PHAR_MUNG_PHP_SELF (1<<0)
131 #define PHAR_MUNG_REQUEST_URI (1<<1)
132 #define PHAR_MUNG_SCRIPT_NAME (1<<2)
133 #define PHAR_MUNG_SCRIPT_FILENAME (1<<3)
134
135 typedef struct _phar_entry_fp phar_entry_fp;
136 typedef struct _phar_archive_data phar_archive_data;
137
138 ZEND_BEGIN_MODULE_GLOBALS(phar)
139 /* a list of phar_archive_data objects that reference a cached phar, so
140 that if copy-on-write is performed, we can swap them out for the new value */
141 HashTable phar_persist_map;
142 HashTable phar_fname_map;
143 /* for cached phars, this is a per-process store of fp/ufp */
144 phar_entry_fp *cached_fp;
145 HashTable phar_alias_map;
146 int phar_SERVER_mung_list;
147 int readonly;
148 char* cache_list;
149 int manifest_cached;
150 int persist;
151 int has_zlib;
152 int has_bz2;
153 zend_bool readonly_orig;
154 zend_bool require_hash_orig;
155 zend_bool intercepted;
156 int request_init;
157 int require_hash;
158 int request_done;
159 int request_ends;
160 void (*orig_fopen)(INTERNAL_FUNCTION_PARAMETERS);
161 void (*orig_file_get_contents)(INTERNAL_FUNCTION_PARAMETERS);
162 void (*orig_is_file)(INTERNAL_FUNCTION_PARAMETERS);
163 void (*orig_is_link)(INTERNAL_FUNCTION_PARAMETERS);
164 void (*orig_is_dir)(INTERNAL_FUNCTION_PARAMETERS);
165 void (*orig_opendir)(INTERNAL_FUNCTION_PARAMETERS);
166 void (*orig_file_exists)(INTERNAL_FUNCTION_PARAMETERS);
167 void (*orig_fileperms)(INTERNAL_FUNCTION_PARAMETERS);
168 void (*orig_fileinode)(INTERNAL_FUNCTION_PARAMETERS);
169 void (*orig_filesize)(INTERNAL_FUNCTION_PARAMETERS);
170 void (*orig_fileowner)(INTERNAL_FUNCTION_PARAMETERS);
171 void (*orig_filegroup)(INTERNAL_FUNCTION_PARAMETERS);
172 void (*orig_fileatime)(INTERNAL_FUNCTION_PARAMETERS);
173 void (*orig_filemtime)(INTERNAL_FUNCTION_PARAMETERS);
174 void (*orig_filectime)(INTERNAL_FUNCTION_PARAMETERS);
175 void (*orig_filetype)(INTERNAL_FUNCTION_PARAMETERS);
176 void (*orig_is_writable)(INTERNAL_FUNCTION_PARAMETERS);
177 void (*orig_is_readable)(INTERNAL_FUNCTION_PARAMETERS);
178 void (*orig_is_executable)(INTERNAL_FUNCTION_PARAMETERS);
179 void (*orig_lstat)(INTERNAL_FUNCTION_PARAMETERS);
180 void (*orig_readfile)(INTERNAL_FUNCTION_PARAMETERS);
181 void (*orig_stat)(INTERNAL_FUNCTION_PARAMETERS);
182 /* used for includes with . in them inside front controller */
183 char* cwd;
184 int cwd_len;
185 int cwd_init;
186 char *openssl_privatekey;
187 int openssl_privatekey_len;
188 /* phar_get_archive cache */
189 char* last_phar_name;
190 int last_phar_name_len;
191 char* last_alias;
192 int last_alias_len;
193 phar_archive_data* last_phar;
194 HashTable mime_types;
195 ZEND_END_MODULE_GLOBALS(phar)
196
197 ZEND_EXTERN_MODULE_GLOBALS(phar)
198 #define PHAR_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(phar, v)
199
200 #if defined(ZTS) && defined(COMPILE_DL_PHAR)
201 ZEND_TSRMLS_CACHE_EXTERN()
202 #endif
203
204 #ifndef php_uint16
205 # if SIZEOF_SHORT == 2
206 # define php_uint16 unsigned short
207 # else
208 # define php_uint16 uint16_t
209 # endif
210 #endif
211 #include "pharzip.h"
212
213 #if HAVE_SPL
214 typedef union _phar_archive_object phar_archive_object;
215 typedef union _phar_entry_object phar_entry_object;
216 #endif
217
218 /*
219 * used in phar_entry_info->fp_type to
220 */
221 enum phar_fp_type {
222 /* regular file pointer phar_archive_data->fp */
223 PHAR_FP,
224 /* uncompressed file pointer phar_archive_data->uncompressed_fp */
225 PHAR_UFP,
226 /* modified file pointer phar_entry_info->fp */
227 PHAR_MOD,
228 /* temporary manifest entry (file outside of the phar mapped to a location inside the phar)
229 this entry stores the stream to open in link (normally used for tars, but we steal it here) */
230 PHAR_TMP
231 };
232
233 /* entry for one file in a phar file */
234 typedef struct _phar_entry_info {
235 /* first bytes are exactly as in file */
236 php_uint32 uncompressed_filesize;
237 php_uint32 timestamp;
238 php_uint32 compressed_filesize;
239 php_uint32 crc32;
240 php_uint32 flags;
241 /* remainder */
242 /* when changing compression, save old flags in case fp is NULL */
243 php_uint32 old_flags;
244 zval metadata;
245 int metadata_len; /* only used for cached manifests */
246 php_uint32 filename_len;
247 char *filename;
248 enum phar_fp_type fp_type;
249 /* offset within original phar file of the file contents */
250 zend_long offset_abs;
251 /* offset within fp of the file contents */
252 zend_long offset;
253 /* offset within original phar file of the file header (for zip-based/tar-based) */
254 zend_long header_offset;
255 php_stream *fp;
256 php_stream *cfp;
257 int fp_refcount;
258 char *tmp;
259 phar_archive_data *phar;
260 smart_str metadata_str;
261 char *link; /* symbolic link to another file */
262 char tar_type;
263 /* position in the manifest */
264 uint manifest_pos;
265 /* for stat */
266 unsigned short inode;
267
268 unsigned int is_crc_checked:1;
269 unsigned int is_modified:1;
270 unsigned int is_deleted:1;
271 unsigned int is_dir:1;
272 /* this flag is used for mounted entries (external files mapped to location
273 inside a phar */
274 unsigned int is_mounted:1;
275 /* used when iterating */
276 unsigned int is_temp_dir:1;
277 /* tar-based phar file stuff */
278 unsigned int is_tar:1;
279 /* zip-based phar file stuff */
280 unsigned int is_zip:1;
281 /* for cached phar entries */
282 unsigned int is_persistent:1;
283 } phar_entry_info;
284
285 /* information about a phar file (the archive itself) */
286 struct _phar_archive_data {
287 char *fname;
288 int fname_len;
289 /* for phar_detect_fname_ext, this stores the location of the file extension within fname */
290 char *ext;
291 int ext_len;
292 char *alias;
293 int alias_len;
294 char version[12];
295 size_t internal_file_start;
296 size_t halt_offset;
297 HashTable manifest;
298 /* hash of virtual directories, as in path/to/file.txt has path/to and path as virtual directories */
299 HashTable virtual_dirs;
300 /* hash of mounted directory paths */
301 HashTable mounted_dirs;
302 php_uint32 flags;
303 php_uint32 min_timestamp;
304 php_uint32 max_timestamp;
305 php_stream *fp;
306 /* decompressed file contents are stored here */
307 php_stream *ufp;
308 int refcount;
309 php_uint32 sig_flags;
310 int sig_len;
311 char *signature;
312 zval metadata;
313 int metadata_len; /* only used for cached manifests */
314 uint phar_pos;
315 /* if 1, then this alias was manually specified by the user and is not a permanent alias */
316 unsigned int is_temporary_alias:1;
317 unsigned int is_modified:1;
318 unsigned int is_writeable:1;
319 unsigned int is_brandnew:1;
320 /* defer phar creation */
321 unsigned int donotflush:1;
322 /* zip-based phar variables */
323 unsigned int is_zip:1;
324 /* tar-based phar variables */
325 unsigned int is_tar:1;
326 /* PharData variables */
327 unsigned int is_data:1;
328 /* for cached phar manifests */
329 unsigned int is_persistent:1;
330 };
331
332 typedef struct _phar_entry_fp_info {
333 enum phar_fp_type fp_type;
334 /* offset within fp of the file contents */
335 zend_long offset;
336 } phar_entry_fp_info;
337
338 struct _phar_entry_fp {
339 php_stream *fp;
340 php_stream *ufp;
341 phar_entry_fp_info *manifest;
342 };
343
phar_get_entrypfp(phar_entry_info * entry)344 static inline php_stream *phar_get_entrypfp(phar_entry_info *entry)
345 {
346 if (!entry->is_persistent) {
347 return entry->phar->fp;
348 }
349 return PHAR_G(cached_fp)[entry->phar->phar_pos].fp;
350 }
351
phar_get_entrypufp(phar_entry_info * entry)352 static inline php_stream *phar_get_entrypufp(phar_entry_info *entry)
353 {
354 if (!entry->is_persistent) {
355 return entry->phar->ufp;
356 }
357 return PHAR_G(cached_fp)[entry->phar->phar_pos].ufp;
358 }
359
phar_set_entrypfp(phar_entry_info * entry,php_stream * fp)360 static inline void phar_set_entrypfp(phar_entry_info *entry, php_stream *fp)
361 {
362 if (!entry->phar->is_persistent) {
363 entry->phar->fp = fp;
364 return;
365 }
366
367 PHAR_G(cached_fp)[entry->phar->phar_pos].fp = fp;
368 }
369
phar_set_entrypufp(phar_entry_info * entry,php_stream * fp)370 static inline void phar_set_entrypufp(phar_entry_info *entry, php_stream *fp)
371 {
372 if (!entry->phar->is_persistent) {
373 entry->phar->ufp = fp;
374 return;
375 }
376
377 PHAR_G(cached_fp)[entry->phar->phar_pos].ufp = fp;
378 }
379
phar_get_pharfp(phar_archive_data * phar)380 static inline php_stream *phar_get_pharfp(phar_archive_data *phar)
381 {
382 if (!phar->is_persistent) {
383 return phar->fp;
384 }
385 return PHAR_G(cached_fp)[phar->phar_pos].fp;
386 }
387
phar_get_pharufp(phar_archive_data * phar)388 static inline php_stream *phar_get_pharufp(phar_archive_data *phar)
389 {
390 if (!phar->is_persistent) {
391 return phar->ufp;
392 }
393 return PHAR_G(cached_fp)[phar->phar_pos].ufp;
394 }
395
phar_set_pharfp(phar_archive_data * phar,php_stream * fp)396 static inline void phar_set_pharfp(phar_archive_data *phar, php_stream *fp)
397 {
398 if (!phar->is_persistent) {
399 phar->fp = fp;
400 return;
401 }
402
403 PHAR_G(cached_fp)[phar->phar_pos].fp = fp;
404 }
405
phar_set_pharufp(phar_archive_data * phar,php_stream * fp)406 static inline void phar_set_pharufp(phar_archive_data *phar, php_stream *fp)
407 {
408 if (!phar->is_persistent) {
409 phar->ufp = fp;
410 return;
411 }
412
413 PHAR_G(cached_fp)[phar->phar_pos].ufp = fp;
414 }
415
phar_set_fp_type(phar_entry_info * entry,enum phar_fp_type type,zend_off_t offset)416 static inline void phar_set_fp_type(phar_entry_info *entry, enum phar_fp_type type, zend_off_t offset)
417 {
418 phar_entry_fp_info *data;
419
420 if (!entry->is_persistent) {
421 entry->fp_type = type;
422 entry->offset = offset;
423 return;
424 }
425 data = &(PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos]);
426 data->fp_type = type;
427 data->offset = offset;
428 }
429
phar_get_fp_type(phar_entry_info * entry)430 static inline enum phar_fp_type phar_get_fp_type(phar_entry_info *entry)
431 {
432 if (!entry->is_persistent) {
433 return entry->fp_type;
434 }
435 return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type;
436 }
437
phar_get_fp_offset(phar_entry_info * entry)438 static inline zend_off_t phar_get_fp_offset(phar_entry_info *entry)
439 {
440 if (!entry->is_persistent) {
441 return entry->offset;
442 }
443 if (PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].fp_type == PHAR_FP) {
444 if (!PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset) {
445 PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset = entry->offset;
446 }
447 }
448 return PHAR_G(cached_fp)[entry->phar->phar_pos].manifest[entry->manifest_pos].offset;
449 }
450
451 #define PHAR_MIME_PHP '\0'
452 #define PHAR_MIME_PHPS '\1'
453 #define PHAR_MIME_OTHER '\2'
454
455 typedef struct _phar_mime_type {
456 char *mime;
457 int len;
458 /* one of PHAR_MIME_* */
459 char type;
460 } phar_mime_type;
461
462 /* stream access data for one file entry in a phar file */
463 typedef struct _phar_entry_data {
464 phar_archive_data *phar;
465 php_stream *fp;
466 /* stream position proxy, allows multiple open streams referring to the same fp */
467 zend_off_t position;
468 /* for copies of the phar fp, defines where 0 is */
469 zend_off_t zero;
470 unsigned int for_write:1;
471 unsigned int is_zip:1;
472 unsigned int is_tar:1;
473 phar_entry_info *internal_file;
474 } phar_entry_data;
475
476 #if HAVE_SPL
477 /* archive php object */
478 union _phar_archive_object {
479 spl_filesystem_object spl;
480 phar_archive_data *archive;
481 };
482 #endif
483
484 #if HAVE_SPL
485 /* entry php object */
486 union _phar_entry_object {
487 spl_filesystem_object spl;
488 phar_entry_info *entry;
489 };
490 #endif
491
492 #ifndef PHAR_MAIN
493 extern zend_string *(*phar_save_resolve_path)(const char *filename, int filename_len);
494 #endif
495
496 BEGIN_EXTERN_C()
497
498 #ifdef PHP_WIN32
499 char *tsrm_strtok_r(char *s, const char *delim, char **last);
500
phar_unixify_path_separators(char * path,int path_len)501 static inline void phar_unixify_path_separators(char *path, int path_len)
502 {
503 char *s;
504
505 /* unixify win paths */
506 for (s = path; s - path < path_len; ++s) {
507 if (*s == '\\') {
508 *s = '/';
509 }
510 }
511 }
512 #endif
513 /**
514 * validate an alias, returns 1 for success, 0 for failure
515 */
phar_validate_alias(const char * alias,int alias_len)516 static inline int phar_validate_alias(const char *alias, int alias_len) /* {{{ */
517 {
518 return !(memchr(alias, '/', alias_len) || memchr(alias, '\\', alias_len) || memchr(alias, ':', alias_len) ||
519 memchr(alias, ';', alias_len) || memchr(alias, '\n', alias_len) || memchr(alias, '\r', alias_len));
520 }
521 /* }}} */
522
phar_set_inode(phar_entry_info * entry)523 static inline void phar_set_inode(phar_entry_info *entry) /* {{{ */
524 {
525 char tmp[MAXPATHLEN];
526 int tmp_len;
527 size_t len1, len2;
528
529 tmp_len = MIN(MAXPATHLEN, entry->filename_len + entry->phar->fname_len);
530
531 len1 = MIN(entry->phar->fname_len, tmp_len);
532 memcpy(tmp, entry->phar->fname, len1);
533
534 len2 = MIN(tmp_len - len1, entry->filename_len);
535 memcpy(tmp + len1, entry->filename, len2);
536
537 entry->inode = (unsigned short) zend_hash_func(tmp, tmp_len);
538 }
539 /* }}} */
540
541 void phar_request_initialize(void);
542
543 void phar_object_init(void);
544 void phar_destroy_phar_data(phar_archive_data *phar);
545
546 int phar_open_entry_file(phar_archive_data *phar, phar_entry_info *entry, char **error);
547 int phar_postprocess_file(phar_entry_data *idata, php_uint32 crc32, char **error, int process_zip);
548 int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error);
549 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);
550 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);
551 int phar_open_executed_filename(char *alias, int alias_len, char **error);
552 int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len);
553 int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error);
554 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);
555 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);
556 int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error);
557
558 /* utility functions */
559 zend_string *phar_create_default_stub(const char *index_php, const char *web_index, char **error);
560 char *phar_decompress_filter(phar_entry_info * entry, int return_unknown);
561 char *phar_compress_filter(phar_entry_info * entry, int return_unknown);
562
563 void phar_remove_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
564 void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len);
565 int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len);
566 zend_string *phar_find_in_include_path(char *file, int file_len, phar_archive_data **pphar);
567 char *phar_fix_filepath(char *path, int *new_len, int use_cwd);
568 phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error);
569 int phar_parse_metadata(char **buffer, zval *metadata, php_uint32 zip_metadata_len);
570 void destroy_phar_manifest_entry(zval *zv);
571 int phar_seek_efp(phar_entry_info *entry, zend_off_t offset, int whence, zend_off_t position, int follow_links);
572 php_stream *phar_get_efp(phar_entry_info *entry, int follow_links);
573 int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error);
574 int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links);
575 phar_entry_info *phar_get_link_source(phar_entry_info *entry);
576 int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error);
577 int phar_separate_entry_fp(phar_entry_info *entry, char **error);
578 int phar_open_archive_fp(phar_archive_data *phar);
579 int phar_copy_on_write(phar_archive_data **pphar);
580
581 /* tar functions in tar.c */
582 int phar_is_tar(char *buf, char *fname);
583 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);
584 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);
585 int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int defaultstub, char **error);
586
587 /* zip functions in zip.c */
588 int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, int alias_len, phar_archive_data** pphar, char **error);
589 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);
590 int phar_zip_flush(phar_archive_data *archive, char *user_stub, zend_long len, int defaultstub, char **error);
591
592 #ifdef PHAR_MAIN
593 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);
594 extern php_stream_wrapper php_stream_phar_wrapper;
595 #else
596 extern HashTable cached_phars;
597 extern HashTable cached_alias;
598 #endif
599
600 int phar_archive_delref(phar_archive_data *phar);
601 int phar_entry_delref(phar_entry_data *idata);
602
603 phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security);
604 phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security);
605 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);
606 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);
607 int phar_flush(phar_archive_data *archive, char *user_stub, zend_long len, int convert, char **error);
608 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);
609 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);
610
611 typedef enum {
612 pcr_use_query,
613 pcr_is_ok,
614 pcr_err_double_slash,
615 pcr_err_up_dir,
616 pcr_err_curr_dir,
617 pcr_err_back_slash,
618 pcr_err_star,
619 pcr_err_illegal_char,
620 pcr_err_empty_entry
621 } phar_path_check_result;
622
623 phar_path_check_result phar_path_check(char **p, int *len, const char **error);
624
625 END_EXTERN_C()
626
627 /*
628 * Local variables:
629 * tab-width: 4
630 * c-basic-offset: 4
631 * End:
632 * vim600: noet sw=4 ts=4 fdm=marker
633 * vim<600: noet sw=4 ts=4
634 */
635