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