mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 02:07:09 +00:00
Merge branch 'stat-cache-fix-1.0' into stat-cache-fix-2.0
Conflicts: tests/Functional/Net/SFTPUserStoryTest.php
This commit is contained in:
commit
4d82df3fc7
@ -268,6 +268,10 @@ class ASN1
|
|||||||
$current+= array('headerlength' => 2);
|
$current+= array('headerlength' => 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($length > strlen($encoded)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$content = $this->_string_shift($encoded, $length);
|
$content = $this->_string_shift($encoded, $length);
|
||||||
|
|
||||||
// at this point $length can be overwritten. it's only accurate for definite length things as is
|
// at this point $length can be overwritten. it's only accurate for definite length things as is
|
||||||
@ -296,14 +300,21 @@ class ASN1
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newcontent = array();
|
$newcontent = array();
|
||||||
if (strlen($content)) {
|
$remainingLength = $length;
|
||||||
$newcontent = $this->_decode_ber($content, $start);
|
while ($remainingLength > 0) {
|
||||||
$length = $newcontent['length'];
|
$temp = $this->_decode_ber($content, $start);
|
||||||
|
$length = $temp['length'];
|
||||||
|
// end-of-content octets - see paragraph 8.1.5
|
||||||
if (substr($content, $length, 2) == "\0\0") {
|
if (substr($content, $length, 2) == "\0\0") {
|
||||||
$length+= 2;
|
$length+= 2;
|
||||||
|
$start+= $length;
|
||||||
|
$newcontent[] = $temp;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$start+= $length;
|
$start+= $length;
|
||||||
$newcontent = array($newcontent);
|
$remainingLength-= $length;
|
||||||
|
$newcontent[] = $temp;
|
||||||
|
$this->_string_shift($content, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@ -862,7 +862,7 @@ class SFTP extends SSH2
|
|||||||
} else {
|
} else {
|
||||||
$temp = $dir . '/' . $shortname;
|
$temp = $dir . '/' . $shortname;
|
||||||
}
|
}
|
||||||
$this->_update_stat_cache($temp, (object) $attributes);
|
$this->_update_stat_cache($temp, (object) array('stat' => $attributes));
|
||||||
}
|
}
|
||||||
// SFTPv6 has an optional boolean end-of-list field, but we'll ignore that, since the
|
// SFTPv6 has an optional boolean end-of-list field, but we'll ignore that, since the
|
||||||
// final SSH_FXP_STATUS packet should tell us that, already.
|
// final SSH_FXP_STATUS packet should tell us that, already.
|
||||||
@ -1033,6 +1033,14 @@ class SFTP extends SSH2
|
|||||||
$temp[$dir] = array();
|
$temp[$dir] = array();
|
||||||
}
|
}
|
||||||
if ($i === $max) {
|
if ($i === $max) {
|
||||||
|
if (is_object($temp[$dir])) {
|
||||||
|
if (!isset($value->stat) && isset($temp[$dir]->stat)) {
|
||||||
|
$value->stat = $temp[$dir]->stat;
|
||||||
|
}
|
||||||
|
if (!isset($value->lstat) && isset($temp[$dir]->lstat)) {
|
||||||
|
$value->lstat = $temp[$dir]->lstat;
|
||||||
|
}
|
||||||
|
}
|
||||||
$temp[$dir] = $value;
|
$temp[$dir] = $value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1111,10 +1119,10 @@ class SFTP extends SSH2
|
|||||||
if ($this->use_stat_cache) {
|
if ($this->use_stat_cache) {
|
||||||
$result = $this->_query_stat_cache($filename);
|
$result = $this->_query_stat_cache($filename);
|
||||||
if (is_array($result) && isset($result['.'])) {
|
if (is_array($result) && isset($result['.'])) {
|
||||||
return (array) $result['.'];
|
return $result['.']->stat;
|
||||||
}
|
}
|
||||||
if (is_object($result)) {
|
if (is_object($result) && isset($result->stat)) {
|
||||||
return (array) $result;
|
return $result->stat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1127,7 +1135,7 @@ class SFTP extends SSH2
|
|||||||
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
||||||
$filename.= '/.';
|
$filename.= '/.';
|
||||||
}
|
}
|
||||||
$this->_update_stat_cache($filename, (object) $stat);
|
$this->_update_stat_cache($filename, (object) array('stat' => $stat));
|
||||||
return $stat;
|
return $stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1140,7 +1148,7 @@ class SFTP extends SSH2
|
|||||||
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
||||||
$filename.= '/.';
|
$filename.= '/.';
|
||||||
}
|
}
|
||||||
$this->_update_stat_cache($filename, (object) $stat);
|
$this->_update_stat_cache($filename, (object) array('stat' => $stat));
|
||||||
|
|
||||||
return $stat;
|
return $stat;
|
||||||
}
|
}
|
||||||
@ -1168,10 +1176,10 @@ class SFTP extends SSH2
|
|||||||
if ($this->use_stat_cache) {
|
if ($this->use_stat_cache) {
|
||||||
$result = $this->_query_stat_cache($filename);
|
$result = $this->_query_stat_cache($filename);
|
||||||
if (is_array($result) && isset($result['.'])) {
|
if (is_array($result) && isset($result['.'])) {
|
||||||
return (array) $result['.'];
|
return $result['.']->lstat;
|
||||||
}
|
}
|
||||||
if (is_object($result)) {
|
if (is_object($result) && isset($result->lstat)) {
|
||||||
return (array) $result;
|
return $result->lstat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1184,7 +1192,7 @@ class SFTP extends SSH2
|
|||||||
if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
||||||
$filename.= '/.';
|
$filename.= '/.';
|
||||||
}
|
}
|
||||||
$this->_update_stat_cache($filename, (object) $lstat);
|
$this->_update_stat_cache($filename, (object) array('lstat' => $lstat));
|
||||||
return $lstat;
|
return $lstat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1192,7 +1200,7 @@ class SFTP extends SSH2
|
|||||||
|
|
||||||
if ($lstat != $stat) {
|
if ($lstat != $stat) {
|
||||||
$lstat = array_merge($lstat, array('type' => NET_SFTP_TYPE_SYMLINK));
|
$lstat = array_merge($lstat, array('type' => NET_SFTP_TYPE_SYMLINK));
|
||||||
$this->_update_stat_cache($filename, (object) $lstat);
|
$this->_update_stat_cache($filename, (object) array('lstat' => $lstat));
|
||||||
return $stat;
|
return $stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1205,7 +1213,7 @@ class SFTP extends SSH2
|
|||||||
if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) {
|
||||||
$filename.= '/.';
|
$filename.= '/.';
|
||||||
}
|
}
|
||||||
$this->_update_stat_cache($filename, (object) $lstat);
|
$this->_update_stat_cache($filename, (object) array('lstat' => $lstat));
|
||||||
|
|
||||||
return $lstat;
|
return $lstat;
|
||||||
}
|
}
|
||||||
@ -2262,7 +2270,7 @@ class SFTP extends SSH2
|
|||||||
*/
|
*/
|
||||||
function is_link($path)
|
function is_link($path)
|
||||||
{
|
{
|
||||||
$result = $this->_get_stat_cache_prop($path, 'type');
|
$result = $this->_get_lstat_cache_prop($path, 'type');
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2377,18 +2385,48 @@ class SFTP extends SSH2
|
|||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _get_stat_cache_prop($path, $prop)
|
function _get_stat_cache_prop($path, $prop)
|
||||||
|
{
|
||||||
|
return $this->_get_xstat_cache_prop($path, $prop, 'stat');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an lstat properity
|
||||||
|
*
|
||||||
|
* Uses cache if appropriate.
|
||||||
|
*
|
||||||
|
* @param String $path
|
||||||
|
* @param String $prop
|
||||||
|
* @return Mixed
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _get_lstat_cache_prop($path, $prop)
|
||||||
|
{
|
||||||
|
return $this->_get_xstat_cache_prop($path, $prop, 'lstat');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a stat or lstat properity
|
||||||
|
*
|
||||||
|
* Uses cache if appropriate.
|
||||||
|
*
|
||||||
|
* @param String $path
|
||||||
|
* @param String $prop
|
||||||
|
* @return Mixed
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _get_xstat_cache_prop($path, $prop, $type)
|
||||||
{
|
{
|
||||||
if ($this->use_stat_cache) {
|
if ($this->use_stat_cache) {
|
||||||
$path = $this->_realpath($path);
|
$path = $this->_realpath($path);
|
||||||
|
|
||||||
$result = $this->_query_stat_cache($path);
|
$result = $this->_query_stat_cache($path);
|
||||||
|
|
||||||
if (is_object($result) && isset($result->$prop)) {
|
if (is_object($result) && isset($result->$type)) {
|
||||||
return $result->$prop;
|
return $result->{$type}[$prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->stat($path);
|
$result = $this->$type($path);
|
||||||
|
|
||||||
if ($result === false || !isset($result[$prop])) {
|
if ($result === false || !isset($result[$prop])) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -160,7 +160,6 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
|
|||||||
return $sftp;
|
return $sftp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function callback($length)
|
static function callback($length)
|
||||||
{
|
{
|
||||||
$r = substr(self::$buffer, 0, $length);
|
$r = substr(self::$buffer, 0, $length);
|
||||||
@ -384,6 +383,42 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
|
|||||||
/**
|
/**
|
||||||
* @depends testSymlink
|
* @depends testSymlink
|
||||||
*/
|
*/
|
||||||
|
public function testStatLstatCache($sftp)
|
||||||
|
{
|
||||||
|
$stat = $sftp->stat('symlink');
|
||||||
|
$lstat = $sftp->lstat('symlink');
|
||||||
|
$this->assertNotEquals(
|
||||||
|
$stat, $lstat,
|
||||||
|
'Failed asserting that stat and lstat returned different output for a symlink'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $sftp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testStatLstatCache
|
||||||
|
*/
|
||||||
|
public function testLinkFile($sftp)
|
||||||
|
{
|
||||||
|
$this->assertTrue(
|
||||||
|
$sftp->is_link('symlink'),
|
||||||
|
'Failed asserting that symlink is a link'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
$sftp->is_file('symlink'),
|
||||||
|
'Failed asserting that symlink is a file'
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$sftp->is_dir('symlink'),
|
||||||
|
'Failed asserting that symlink is not a directory'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $sftp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testLinkFile
|
||||||
|
*/
|
||||||
public function testReadlink($sftp)
|
public function testReadlink($sftp)
|
||||||
{
|
{
|
||||||
$this->assertInternalType('string', $sftp->readlink('symlink'),
|
$this->assertInternalType('string', $sftp->readlink('symlink'),
|
||||||
|
@ -28,4 +28,44 @@ v5RwaQHmQEzHofTzF7I+
|
|||||||
|
|
||||||
$this->assertInternalType('array', $spkac);
|
$this->assertInternalType('array', $spkac);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCSRWithAttributes()
|
||||||
|
{
|
||||||
|
$test = '-----BEGIN NEW CERTIFICATE REQUEST-----
|
||||||
|
MIIFGDCCAwACAQAwOjEWMBQGCgmSJomT8ixkARkWBnNlY3VyZTEgMB4GA1UEAxMX
|
||||||
|
LlNlY3VyZSBFbnRlcnByaXNlIENBIDEwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw
|
||||||
|
ggIKAoICAQCzgEpL+Za7a3y7YpURDrxlGIBlks25fD0tHaZIYkBTaXA5h+9MWoXn
|
||||||
|
FA7AlIUt8pbBvXdJbOCmGaeQmBfBH0Qy9vTbx/DR2IOwzqy2ZHuurI5bPL12ceE2
|
||||||
|
Mxa9xgY/i7U6MAUtoA3amEd7cKj2fz9EWZruRladOX0D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xwx1DLH+7hL/bERB1lUDu59Jx6fQfqJrFVOY2N8c0
|
||||||
|
MGvurfoHGmEoyCMIyvmIMu4+/wSNEE/sSDp4lZ6zuF6rf1m0GiLdTX2XJE+gfvep
|
||||||
|
JTFmp4S3WFqkszKvaxBIT+jV0XKTNDwnO+dpExwU4jZUh18CdEFkIUuQb0gFF8B7
|
||||||
|
WJFVpNdsRqZRPBz83BW1Kjo0yAmaoTrGNmG0p6Qf3K2zbk1+Jik3VZq4rvKoTi20
|
||||||
|
6RvLA2//cMNfkYPsuqvoHGe2e0GOLtIB63wJzloWROpb72ohEHsvCKullIJVSuiS
|
||||||
|
9sfTBAenHCyndgAEd4T3npTUdaiNumVEm5ilZId7LAYekJhkgFu3vlcl8blBJKjE
|
||||||
|
skVTp7JpBmdXCL/G/6H2SFjca4JMOAy3DxwlGdgneIaXazHs5nBK/BgKPIyPzZ4w
|
||||||
|
secxBTTCNgI48YezK3GDkn65cmlnkt6F6Mf0MwoDaXTuB88Jycbwb5ihKnHEJIsO
|
||||||
|
draiRBZruwMPwPIP
|
||||||
|
-----END NEW CERTIFICATE REQUEST-----';
|
||||||
|
|
||||||
|
$x509 = new File_X509();
|
||||||
|
|
||||||
|
$csr = $x509->loadCSR($test);
|
||||||
|
|
||||||
|
$this->assertInternalType('array', $csr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user