phar_internal.h 22 KB

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