github ci

This commit is contained in:
Robin Appelman 2021-03-02 17:58:35 +01:00
commit 80a4edf0ef
9 changed files with 144 additions and 6 deletions

50
src/ProtocolLevel.php Normal file
View file

@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Icewind\SMB;
class ProtocolLevel {
/** @var string */
private $level;
private function __construct(string $level) {
$this->level = $level;
}
public function getLevel(): string {
return $this->level;
}
public static function NT1(): self {
return new ProtocolLevel("NT1");
}
public static function SMB2(): self {
return new ProtocolLevel("SMB2");
}
public static function SMB3(): self {
return new ProtocolLevel("SMB3");
}
}

View file

@ -82,7 +82,7 @@ class Connection extends RawConnection {
break;
}
} else {
$output[] .= $line;
$output[] = $line;
}
$line = $this->readLine();
}

View file

@ -9,6 +9,7 @@ namespace Icewind\SMB\Wrapped;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\ConnectionResetException;
class RawConnection {
/**
@ -100,7 +101,13 @@ class RawConnection {
* @param string $input
*/
public function write($input) {
fwrite($this->getInputStream(), $input);
if (@fwrite($this->getInputStream(), $input) === false) {
$error = error_get_last();
if ($error && strpos($error['message'], "errno=32")) {
error_clear_last();
throw new ConnectionResetException();
}
}
fflush($this->getInputStream());
}

View file

@ -11,6 +11,7 @@ use Icewind\SMB\AbstractServer;
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\ConnectionRefusedException;
use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\IShare;
use Icewind\SMB\ISystem;
@ -62,6 +63,9 @@ class Server extends AbstractServer {
if (isset($output[0])) {
$parser->checkConnectionError($output[0]);
}
// if (count($output) === 0) {
// throw new ConnectionRefusedException();
// }
// sometimes we get an empty line first
if (count($output) < 2) {

View file

@ -348,7 +348,7 @@ class Share extends AbstractShare {
// use a close callback to ensure the upload is finished before continuing
// this also serves as a way to keep the connection in scope
return CallbackWrapper::wrap($fh, null, null, function () use ($connection, $target) {
return CallbackWrapper::wrap($fh, null, null, function () use ($connection) {
$connection->close(false); // dont terminate, give the upload some time
});
}