php_url_free(resource);
return NULL;
} else if (entry && entry->is_dir) {
+ /*if (entry->is_mounted) {
+ external directory, TODO: construct an internal dirstream based on this actual dir's dirstream
+ php_url_free(resource);
+ return php_stream_opendir(entry->link, options, context);
+ }*/
internal_file = estrdup(internal_file);
php_url_free(resource);
return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
/* uncompressed file pointer phar_archive_data->uncompressed_fp */
PHAR_UFP,
/* modified file pointer phar_entry_info->fp */
- PHAR_MOD
+ PHAR_MOD,
+ /* temporary manifest entry (file outside of the phar mapped to a location inside the phar)
+ this entry stores the stream to open in link (normally used for tars, but we steal it here) */
+ PHAR_TMP
};
typedef struct _phar_archive_data phar_archive_data;
int is_modified:1;
int is_deleted:1;
int is_dir:1;
+ /* this flag is used for mounted entries (external files mapped to location
+ inside a phar */
+ int is_mounted:1;
/* used when iterating */
int is_temp_dir:1;
phar_archive_data *phar;
return entry->phar->fp;
} else if (entry->fp_type == PHAR_UFP) {
return entry->phar->ufp;
+ } else if (entry->fp_type == PHAR_MOD) {
+ return entry->fp;
} else {
+ /* temporary manifest entry */
+ if (!entry->fp) {
+ entry->fp = php_stream_open_wrapper(entry->link, "rb", STREAM_MUST_SEEK|0, NULL);
+ }
return entry->fp;
}
}
return php_stream_seek(fp, temp, SEEK_SET);
}
+/* mount an absolute path or uri to a path internal to the phar archive */
+int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len, int is_dir TSRMLS_DC)
+{
+ phar_entry_info entry = {0};
+
+#if PHP_MAJOR_VERSION < 6
+ if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_ALLOW_ONLY_FILE))) {
+ return FAILURE;
+ }
+#endif
+
+ /* only check openbasedir for files, not for phar streams */
+ if (!strstr(filename, "phar://") && php_check_open_basedir(filename TSRMLS_CC)) {
+ return FAILURE;
+ }
+
+ entry.phar = phar;
+ entry.filename = estrndup(path, path_len);
+ entry.filename_len = path_len;
+ entry.link = estrndup(filename, filename_len);
+ entry.is_mounted = 1;
+ entry.is_crc_checked = 1;
+ entry.fp_type = PHAR_TMP;
+ entry.is_dir = is_dir;
+ return zend_hash_add(&phar->manifest, path, path_len, (void*)&entry, sizeof(phar_entry_info), NULL);
+}
+
char *phar_find_in_include_path(char *file, char *entry, phar_archive_data *phar TSRMLS_DC) /* {{{ */
{
char *path = PG(include_path), *pathbuf, *ptr, *end;