version 1.1, 2012/02/21 23:47:59
|
version 1.1.1.3, 2013/07/22 01:31:59
|
Line 3
|
Line 3
|
| phar php single-file executable PHP extension | |
| phar php single-file executable PHP extension | |
| utility functions | |
| utility functions | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 2005-2012 The PHP Group | | | Copyright (c) 2005-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 156 int phar_seek_efp(phar_entry_info *entry, off_t offset
|
Line 156 int phar_seek_efp(phar_entry_info *entry, off_t offset
|
break; |
break; |
default: |
default: |
temp = 0; |
temp = 0; |
break; |
|
} |
} |
|
|
if (temp > eoffset + (off_t) entry->uncompressed_filesize) { |
if (temp > eoffset + (off_t) entry->uncompressed_filesize) { |
Line 211 int phar_mount_entry(phar_archive_data *phar, char *fi
|
Line 210 int phar_mount_entry(phar_archive_data *phar, char *fi
|
return FAILURE; |
return FAILURE; |
} |
} |
#endif |
#endif |
|
|
filename_len = strlen(entry.tmp); |
|
filename = entry.tmp; |
filename = entry.tmp; |
|
|
/* only check openbasedir for files, not for phar streams */ |
/* only check openbasedir for files, not for phar streams */ |
Line 274 char *phar_find_in_include_path(char *filename, int fi
|
Line 271 char *phar_find_in_include_path(char *filename, int fi
|
return phar_save_resolve_path(filename, filename_len TSRMLS_CC); |
return phar_save_resolve_path(filename, filename_len TSRMLS_CC); |
} |
} |
|
|
fname = zend_get_executed_filename(TSRMLS_C); | fname = (char*)zend_get_executed_filename(TSRMLS_C); |
fname_len = strlen(fname); |
fname_len = strlen(fname); |
|
|
if (PHAR_G(last_phar) && !memcmp(fname, "phar://", 7) && fname_len - 7 >= PHAR_G(last_phar_name_len) && !memcmp(fname + 7, PHAR_G(last_phar_name), PHAR_G(last_phar_name_len))) { |
if (PHAR_G(last_phar) && !memcmp(fname, "phar://", 7) && fname_len - 7 >= PHAR_G(last_phar_name_len) && !memcmp(fname + 7, PHAR_G(last_phar_name), PHAR_G(last_phar_name_len))) { |
Line 366 splitted:
|
Line 363 splitted:
|
goto doit; |
goto doit; |
} |
} |
|
|
fname = zend_get_executed_filename(TSRMLS_C); | fname = (char*)zend_get_executed_filename(TSRMLS_C); |
|
|
if (SUCCESS != phar_split_fname(fname, strlen(fname), &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) { |
if (SUCCESS != phar_split_fname(fname, strlen(fname), &arch, &arch_len, &entry, &entry_len, 1, 0 TSRMLS_CC)) { |
goto doit; |
goto doit; |
Line 524 not_stream:
|
Line 521 not_stream:
|
|
|
/* check in calling scripts' current working directory as a fall back case */ |
/* check in calling scripts' current working directory as a fall back case */ |
if (zend_is_executing(TSRMLS_C)) { |
if (zend_is_executing(TSRMLS_C)) { |
char *exec_fname = zend_get_executed_filename(TSRMLS_C); | char *exec_fname = (char*)zend_get_executed_filename(TSRMLS_C); |
int exec_fname_length = strlen(exec_fname); |
int exec_fname_length = strlen(exec_fname); |
const char *p; |
const char *p; |
int n = 0; |
int n = 0; |
Line 892 int phar_copy_entry_fp(phar_entry_info *source, phar_e
|
Line 889 int phar_copy_entry_fp(phar_entry_info *source, phar_e
|
dest->offset = 0; |
dest->offset = 0; |
dest->is_modified = 1; |
dest->is_modified = 1; |
dest->fp = php_stream_fopen_tmpfile(); |
dest->fp = php_stream_fopen_tmpfile(); |
|
if (dest->fp == NULL) { |
|
spprintf(error, 0, "phar error: unable to create temporary file"); |
|
return EOF; |
|
} |
phar_seek_efp(source, 0, SEEK_SET, 0, 1 TSRMLS_CC); |
phar_seek_efp(source, 0, SEEK_SET, 0, 1 TSRMLS_CC); |
link = phar_get_link_source(source TSRMLS_CC); |
link = phar_get_link_source(source TSRMLS_CC); |
|
|
Line 1132 int phar_separate_entry_fp(phar_entry_info *entry, cha
|
Line 1133 int phar_separate_entry_fp(phar_entry_info *entry, cha
|
} |
} |
|
|
fp = php_stream_fopen_tmpfile(); |
fp = php_stream_fopen_tmpfile(); |
|
if (fp == NULL) { |
|
spprintf(error, 0, "phar error: unable to create temporary file"); |
|
return FAILURE; |
|
} |
phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC); |
phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC); |
link = phar_get_link_source(entry TSRMLS_CC); |
link = phar_get_link_source(entry TSRMLS_CC); |
|
|
Line 2121 int phar_create_signature(phar_archive_data *phar, php
|
Line 2126 int phar_create_signature(phar_archive_data *phar, php
|
#ifdef PHAR_HAVE_OPENSSL |
#ifdef PHAR_HAVE_OPENSSL |
BIO *in; |
BIO *in; |
EVP_PKEY *key; |
EVP_PKEY *key; |
EVP_MD *mdtype = (EVP_MD *) EVP_sha1(); | EVP_MD_CTX *md_ctx; |
EVP_MD_CTX md_ctx; | |
|
|
in = BIO_new_mem_buf(PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len)); |
in = BIO_new_mem_buf(PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len)); |
|
|
Line 2143 int phar_create_signature(phar_archive_data *phar, php
|
Line 2147 int phar_create_signature(phar_archive_data *phar, php
|
return FAILURE; |
return FAILURE; |
} |
} |
|
|
|
md_ctx = EVP_MD_CTX_create(); |
|
|
siglen = EVP_PKEY_size(key); |
siglen = EVP_PKEY_size(key); |
sigbuf = emalloc(siglen + 1); |
sigbuf = emalloc(siglen + 1); |
EVP_SignInit(&md_ctx, mdtype); |
|
|
|
|
if (!EVP_SignInit(md_ctx, EVP_sha1())) { |
|
efree(sigbuf); |
|
if (error) { |
|
spprintf(error, 0, "unable to initialize openssl signature for phar \"%s\"", phar->fname); |
|
} |
|
return FAILURE; |
|
} |
|
|
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) { |
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) { |
EVP_SignUpdate(&md_ctx, buf, sig_len); | if (!EVP_SignUpdate(md_ctx, buf, sig_len)) { |
| efree(sigbuf); |
| if (error) { |
| spprintf(error, 0, "unable to update the openssl signature for phar \"%s\"", phar->fname); |
| } |
| return FAILURE; |
| } |
} |
} |
|
|
if (!EVP_SignFinal (&md_ctx, sigbuf,(unsigned int *)&siglen, key)) { | if (!EVP_SignFinal (md_ctx, sigbuf,(unsigned int *)&siglen, key)) { |
efree(sigbuf); |
efree(sigbuf); |
if (error) { |
if (error) { |
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname); |
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname); |
Line 2160 int phar_create_signature(phar_archive_data *phar, php
|
Line 2179 int phar_create_signature(phar_archive_data *phar, php
|
} |
} |
|
|
sigbuf[siglen] = '\0'; |
sigbuf[siglen] = '\0'; |
EVP_MD_CTX_cleanup(&md_ctx); | EVP_MD_CTX_destroy(md_ctx); |
#else |
#else |
sigbuf = NULL; |
sigbuf = NULL; |
siglen = 0; |
siglen = 0; |
Line 2218 int phar_create_signature(phar_archive_data *phar, php
|
Line 2237 int phar_create_signature(phar_archive_data *phar, php
|
|
|
void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len TSRMLS_DC) /* {{{ */ |
void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename_len TSRMLS_DC) /* {{{ */ |
{ |
{ |
char *s; | const char *s; |
|
|
while ((s = zend_memrchr(filename, '/', filename_len))) { |
while ((s = zend_memrchr(filename, '/', filename_len))) { |
filename_len = s - filename; |
filename_len = s - filename; |