fix new psalm issues

This commit is contained in:
Robin Appelman 2021-04-19 15:53:08 +02:00
commit 9dba42ab2a
5 changed files with 26 additions and 11 deletions

View file

@ -21,6 +21,8 @@
namespace Icewind\SMB;
use Icewind\SMB\Exception\Exception;
class AnonymousAuth implements IAuth {
public function getUsername(): ?string {
return null;
@ -39,6 +41,8 @@ class AnonymousAuth implements IAuth {
}
public function setExtraSmbClientOptions($smbClientState): void {
smbclient_option_set($smbClientState, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, true);
if (smbclient_option_set($smbClientState, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, true) === false) {
throw new Exception("Failed to set smbclient options for anonymous auth");
}
}
}

View file

@ -21,6 +21,8 @@
namespace Icewind\SMB;
use Icewind\SMB\Exception\Exception;
/**
* Use existing kerberos ticket to authenticate
*/
@ -42,7 +44,11 @@ class KerberosAuth implements IAuth {
}
public function setExtraSmbClientOptions($smbClientState): void {
smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true);
smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false);
$success = (bool)smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true);
$success = $success && smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false);
if (!$success) {
throw new Exception("Failed to set smbclient options for kerberos auth");
}
}
}

View file

@ -97,14 +97,13 @@ class NativeState {
/** @var resource $state */
$state = smbclient_state_new();
$this->state = $state;
/** @psalm-suppress UnusedFunctionCall */
smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false);
/** @psalm-suppress UnusedFunctionCall */
smbclient_option_set($this->state, SMBCLIENT_OPT_TIMEOUT, $options->getTimeout() * 1000);
if (function_exists('smbclient_client_protocols')) {
$maxProtocol = $options->getMaxProtocol();
$minProtocol = $options->getMinProtocol();
smbclient_client_protocols($this->state, $minProtocol, $maxProtocol);
smbclient_client_protocols($this->state, $options->getMinProtocol(), $options->getMaxProtocol());
}
$auth->setExtraSmbClientOptions($this->state);
@ -357,7 +356,9 @@ class NativeState {
public function __destruct() {
if ($this->connected) {
smbclient_state_free($this->state);
if (smbclient_state_free($this->state) === false) {
throw new Exception("Failed to free smb state");
}
}
}
}

View file

@ -52,7 +52,9 @@ abstract class NativeStream implements File {
* @return resource
*/
protected static function wrapClass(NativeState $state, $smbStream, string $mode, string $url, string $class) {
stream_wrapper_register('nativesmb', $class);
if (stream_wrapper_register('nativesmb', $class) === false) {
throw new Exception("Failed to register stream wrapper");
}
$context = stream_context_create([
'nativesmb' => [
'state' => $state,
@ -61,7 +63,9 @@ abstract class NativeStream implements File {
]
]);
$fh = fopen('nativesmb://', $mode, false, $context);
stream_wrapper_unregister('nativesmb');
if (stream_wrapper_unregister('nativesmb') === false) {
throw new Exception("Failed to unregister stream wrapper");
}
return $fh;
}

View file

@ -88,7 +88,7 @@ class Server extends AbstractServer {
$shareNames = $parser->parseListShares($output);
$shares = [];
foreach ($shareNames as $name => $description) {
foreach ($shareNames as $name => $_description) {
$shares[] = $this->getShare($name);
}
return $shares;