Merge pull request #9578 from nextcloud/smb-3.0.0

update icewind/smb to 3.0.0
This commit is contained in:
Morris Jobke 2018-06-21 23:21:43 +02:00 committed by GitHub
commit 1bedfce928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 845 additions and 439 deletions

View File

@ -9,6 +9,6 @@
}, },
"require": { "require": {
"icewind/streams": "0.5.2", "icewind/streams": "0.5.2",
"icewind/smb": "2.0.5" "icewind/smb": "3.0.0"
} }
} }

View File

@ -1,31 +1,31 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "53a1e7ab19e98c20c720cab0340bc56a", "content-hash": "0235b6f1a4131c9312afef7a58f3a80e",
"packages": [ "packages": [
{ {
"name": "icewind/smb", "name": "icewind/smb",
"version": "v2.0.5", "version": "v3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/icewind1991/SMB.git", "url": "https://github.com/icewind1991/SMB.git",
"reference": "b888dd81bd05532677e1469849d9065011256a33" "reference": "0d31da4757a37d322e1e181f2286e8a4c89fbc0c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/icewind1991/SMB/zipball/b888dd81bd05532677e1469849d9065011256a33", "url": "https://api.github.com/repos/icewind1991/SMB/zipball/0d31da4757a37d322e1e181f2286e8a4c89fbc0c",
"reference": "b888dd81bd05532677e1469849d9065011256a33", "reference": "0d31da4757a37d322e1e181f2286e8a4c89fbc0c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"icewind/streams": ">=0.2.0", "icewind/streams": ">=0.2.0",
"php": ">=5.4" "php": ">=5.6"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8" "phpunit/phpunit": "^5.7"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -45,7 +45,7 @@
} }
], ],
"description": "php wrapper for smbclient and libsmbclient-php", "description": "php wrapper for smbclient and libsmbclient-php",
"time": "2018-03-28T13:51:31+00:00" "time": "2018-05-24T09:48:51+00:00"
}, },
{ {
"name": "icewind/streams", "name": "icewind/streams",

View File

@ -6,10 +6,11 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = $vendorDir; $baseDir = $vendorDir;
return array( return array(
'Icewind\\SMB\\AbstractServer' => $vendorDir . '/icewind/smb/src/AbstractServer.php',
'Icewind\\SMB\\AbstractShare' => $vendorDir . '/icewind/smb/src/AbstractShare.php', 'Icewind\\SMB\\AbstractShare' => $vendorDir . '/icewind/smb/src/AbstractShare.php',
'Icewind\\SMB\\AnonymousAuth' => $vendorDir . '/icewind/smb/src/AnonymousAuth.php',
'Icewind\\SMB\\BasicAuth' => $vendorDir . '/icewind/smb/src/BasicAuth.php',
'Icewind\\SMB\\Change' => $vendorDir . '/icewind/smb/src/Change.php', 'Icewind\\SMB\\Change' => $vendorDir . '/icewind/smb/src/Change.php',
'Icewind\\SMB\\Connection' => $vendorDir . '/icewind/smb/src/Connection.php',
'Icewind\\SMB\\ErrorCodes' => $vendorDir . '/icewind/smb/src/ErrorCodes.php',
'Icewind\\SMB\\Exception\\AccessDeniedException' => $vendorDir . '/icewind/smb/src/Exception/AccessDeniedException.php', 'Icewind\\SMB\\Exception\\AccessDeniedException' => $vendorDir . '/icewind/smb/src/Exception/AccessDeniedException.php',
'Icewind\\SMB\\Exception\\AlreadyExistsException' => $vendorDir . '/icewind/smb/src/Exception/AlreadyExistsException.php', 'Icewind\\SMB\\Exception\\AlreadyExistsException' => $vendorDir . '/icewind/smb/src/Exception/AlreadyExistsException.php',
'Icewind\\SMB\\Exception\\AuthenticationException' => $vendorDir . '/icewind/smb/src/Exception/AuthenticationException.php', 'Icewind\\SMB\\Exception\\AuthenticationException' => $vendorDir . '/icewind/smb/src/Exception/AuthenticationException.php',
@ -35,32 +36,38 @@ return array(
'Icewind\\SMB\\Exception\\OutOfSpaceException' => $vendorDir . '/icewind/smb/src/Exception/OutOfSpaceException.php', 'Icewind\\SMB\\Exception\\OutOfSpaceException' => $vendorDir . '/icewind/smb/src/Exception/OutOfSpaceException.php',
'Icewind\\SMB\\Exception\\RevisionMismatchException' => $vendorDir . '/icewind/smb/src/Exception/RevisionMismatchException.php', 'Icewind\\SMB\\Exception\\RevisionMismatchException' => $vendorDir . '/icewind/smb/src/Exception/RevisionMismatchException.php',
'Icewind\\SMB\\Exception\\TimedOutException' => $vendorDir . '/icewind/smb/src/Exception/TimedOutException.php', 'Icewind\\SMB\\Exception\\TimedOutException' => $vendorDir . '/icewind/smb/src/Exception/TimedOutException.php',
'Icewind\\SMB\\FileInfo' => $vendorDir . '/icewind/smb/src/FileInfo.php', 'Icewind\\SMB\\IAuth' => $vendorDir . '/icewind/smb/src/IAuth.php',
'Icewind\\SMB\\IFileInfo' => $vendorDir . '/icewind/smb/src/IFileInfo.php', 'Icewind\\SMB\\IFileInfo' => $vendorDir . '/icewind/smb/src/IFileInfo.php',
'Icewind\\SMB\\INotifyHandler' => $vendorDir . '/icewind/smb/src/INotifyHandler.php', 'Icewind\\SMB\\INotifyHandler' => $vendorDir . '/icewind/smb/src/INotifyHandler.php',
'Icewind\\SMB\\IServer' => $vendorDir . '/icewind/smb/src/IServer.php',
'Icewind\\SMB\\IShare' => $vendorDir . '/icewind/smb/src/IShare.php', 'Icewind\\SMB\\IShare' => $vendorDir . '/icewind/smb/src/IShare.php',
'Icewind\\SMB\\NativeFileInfo' => $vendorDir . '/icewind/smb/src/NativeFileInfo.php', 'Icewind\\SMB\\KerberosAuth' => $vendorDir . '/icewind/smb/src/KerberosAuth.php',
'Icewind\\SMB\\NativeReadStream' => $vendorDir . '/icewind/smb/src/NativeReadStream.php', 'Icewind\\SMB\\Native\\NativeFileInfo' => $vendorDir . '/icewind/smb/src/Native/NativeFileInfo.php',
'Icewind\\SMB\\NativeServer' => $vendorDir . '/icewind/smb/src/NativeServer.php', 'Icewind\\SMB\\Native\\NativeReadStream' => $vendorDir . '/icewind/smb/src/Native/NativeReadStream.php',
'Icewind\\SMB\\NativeShare' => $vendorDir . '/icewind/smb/src/NativeShare.php', 'Icewind\\SMB\\Native\\NativeServer' => $vendorDir . '/icewind/smb/src/Native/NativeServer.php',
'Icewind\\SMB\\NativeState' => $vendorDir . '/icewind/smb/src/NativeState.php', 'Icewind\\SMB\\Native\\NativeShare' => $vendorDir . '/icewind/smb/src/Native/NativeShare.php',
'Icewind\\SMB\\NativeStream' => $vendorDir . '/icewind/smb/src/NativeStream.php', 'Icewind\\SMB\\Native\\NativeState' => $vendorDir . '/icewind/smb/src/Native/NativeState.php',
'Icewind\\SMB\\NativeWriteStream' => $vendorDir . '/icewind/smb/src/NativeWriteStream.php', 'Icewind\\SMB\\Native\\NativeStream' => $vendorDir . '/icewind/smb/src/Native/NativeStream.php',
'Icewind\\SMB\\NotifyHandler' => $vendorDir . '/icewind/smb/src/NotifyHandler.php', 'Icewind\\SMB\\Native\\NativeWriteStream' => $vendorDir . '/icewind/smb/src/Native/NativeWriteStream.php',
'Icewind\\SMB\\Parser' => $vendorDir . '/icewind/smb/src/Parser.php', 'Icewind\\SMB\\ServerFactory' => $vendorDir . '/icewind/smb/src/ServerFactory.php',
'Icewind\\SMB\\RawConnection' => $vendorDir . '/icewind/smb/src/RawConnection.php',
'Icewind\\SMB\\Server' => $vendorDir . '/icewind/smb/src/Server.php',
'Icewind\\SMB\\Share' => $vendorDir . '/icewind/smb/src/Share.php',
'Icewind\\SMB\\System' => $vendorDir . '/icewind/smb/src/System.php', 'Icewind\\SMB\\System' => $vendorDir . '/icewind/smb/src/System.php',
'Icewind\\SMB\\Test\\AbstractShareTest' => $vendorDir . '/icewind/smb/tests/AbstractShareTest.php', 'Icewind\\SMB\\Test\\AbstractShareTest' => $vendorDir . '/icewind/smb/tests/AbstractShareTest.php',
'Icewind\\SMB\\Test\\NativeShareTestTest' => $vendorDir . '/icewind/smb/tests/NativeShareTestTest.php', 'Icewind\\SMB\\Test\\NativeShareTest' => $vendorDir . '/icewind/smb/tests/NativeShareTest.php',
'Icewind\\SMB\\Test\\NativeStreamTest' => $vendorDir . '/icewind/smb/tests/NativeStreamTest.php', 'Icewind\\SMB\\Test\\NativeStreamTest' => $vendorDir . '/icewind/smb/tests/NativeStreamTest.php',
'Icewind\\SMB\\Test\\NotifyHandlerTest' => $vendorDir . '/icewind/smb/tests/NotifyHandlerTest.php', 'Icewind\\SMB\\Test\\NotifyHandlerTest' => $vendorDir . '/icewind/smb/tests/NotifyHandlerTest.php',
'Icewind\\SMB\\Test\\ParserTest' => $vendorDir . '/icewind/smb/tests/ParserTest.php', 'Icewind\\SMB\\Test\\ParserTest' => $vendorDir . '/icewind/smb/tests/ParserTest.php',
'Icewind\\SMB\\Test\\ServerTest' => $vendorDir . '/icewind/smb/tests/ServerTest.php', 'Icewind\\SMB\\Test\\ServerTest' => $vendorDir . '/icewind/smb/tests/ServerTest.php',
'Icewind\\SMB\\Test\\ShareTestTest' => $vendorDir . '/icewind/smb/tests/ShareTestTest.php', 'Icewind\\SMB\\Test\\ShareTest' => $vendorDir . '/icewind/smb/tests/ShareTest.php',
'Icewind\\SMB\\Test\\TestCase' => $vendorDir . '/icewind/smb/tests/TestCase.php', 'Icewind\\SMB\\Test\\TestCase' => $vendorDir . '/icewind/smb/tests/TestCase.php',
'Icewind\\SMB\\TimeZoneProvider' => $vendorDir . '/icewind/smb/src/TimeZoneProvider.php', 'Icewind\\SMB\\TimeZoneProvider' => $vendorDir . '/icewind/smb/src/TimeZoneProvider.php',
'Icewind\\SMB\\Wrapped\\Connection' => $vendorDir . '/icewind/smb/src/Wrapped/Connection.php',
'Icewind\\SMB\\Wrapped\\ErrorCodes' => $vendorDir . '/icewind/smb/src/Wrapped/ErrorCodes.php',
'Icewind\\SMB\\Wrapped\\FileInfo' => $vendorDir . '/icewind/smb/src/Wrapped/FileInfo.php',
'Icewind\\SMB\\Wrapped\\NotifyHandler' => $vendorDir . '/icewind/smb/src/Wrapped/NotifyHandler.php',
'Icewind\\SMB\\Wrapped\\Parser' => $vendorDir . '/icewind/smb/src/Wrapped/Parser.php',
'Icewind\\SMB\\Wrapped\\RawConnection' => $vendorDir . '/icewind/smb/src/Wrapped/RawConnection.php',
'Icewind\\SMB\\Wrapped\\Server' => $vendorDir . '/icewind/smb/src/Wrapped/Server.php',
'Icewind\\SMB\\Wrapped\\Share' => $vendorDir . '/icewind/smb/src/Wrapped/Share.php',
'Icewind\\Streams\\CallbackWrapper' => $vendorDir . '/icewind/streams/src/CallbackWrapper.php', 'Icewind\\Streams\\CallbackWrapper' => $vendorDir . '/icewind/streams/src/CallbackWrapper.php',
'Icewind\\Streams\\Directory' => $vendorDir . '/icewind/streams/src/Directory.php', 'Icewind\\Streams\\Directory' => $vendorDir . '/icewind/streams/src/Directory.php',
'Icewind\\Streams\\DirectoryFilter' => $vendorDir . '/icewind/streams/src/DirectoryFilter.php', 'Icewind\\Streams\\DirectoryFilter' => $vendorDir . '/icewind/streams/src/DirectoryFilter.php',

View File

@ -36,10 +36,11 @@ class ComposerStaticInit98fe9b281934250b3a93f69a5ce843b3
); );
public static $classMap = array ( public static $classMap = array (
'Icewind\\SMB\\AbstractServer' => __DIR__ . '/..' . '/icewind/smb/src/AbstractServer.php',
'Icewind\\SMB\\AbstractShare' => __DIR__ . '/..' . '/icewind/smb/src/AbstractShare.php', 'Icewind\\SMB\\AbstractShare' => __DIR__ . '/..' . '/icewind/smb/src/AbstractShare.php',
'Icewind\\SMB\\AnonymousAuth' => __DIR__ . '/..' . '/icewind/smb/src/AnonymousAuth.php',
'Icewind\\SMB\\BasicAuth' => __DIR__ . '/..' . '/icewind/smb/src/BasicAuth.php',
'Icewind\\SMB\\Change' => __DIR__ . '/..' . '/icewind/smb/src/Change.php', 'Icewind\\SMB\\Change' => __DIR__ . '/..' . '/icewind/smb/src/Change.php',
'Icewind\\SMB\\Connection' => __DIR__ . '/..' . '/icewind/smb/src/Connection.php',
'Icewind\\SMB\\ErrorCodes' => __DIR__ . '/..' . '/icewind/smb/src/ErrorCodes.php',
'Icewind\\SMB\\Exception\\AccessDeniedException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/AccessDeniedException.php', 'Icewind\\SMB\\Exception\\AccessDeniedException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/AccessDeniedException.php',
'Icewind\\SMB\\Exception\\AlreadyExistsException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/AlreadyExistsException.php', 'Icewind\\SMB\\Exception\\AlreadyExistsException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/AlreadyExistsException.php',
'Icewind\\SMB\\Exception\\AuthenticationException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/AuthenticationException.php', 'Icewind\\SMB\\Exception\\AuthenticationException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/AuthenticationException.php',
@ -65,32 +66,38 @@ class ComposerStaticInit98fe9b281934250b3a93f69a5ce843b3
'Icewind\\SMB\\Exception\\OutOfSpaceException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/OutOfSpaceException.php', 'Icewind\\SMB\\Exception\\OutOfSpaceException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/OutOfSpaceException.php',
'Icewind\\SMB\\Exception\\RevisionMismatchException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/RevisionMismatchException.php', 'Icewind\\SMB\\Exception\\RevisionMismatchException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/RevisionMismatchException.php',
'Icewind\\SMB\\Exception\\TimedOutException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/TimedOutException.php', 'Icewind\\SMB\\Exception\\TimedOutException' => __DIR__ . '/..' . '/icewind/smb/src/Exception/TimedOutException.php',
'Icewind\\SMB\\FileInfo' => __DIR__ . '/..' . '/icewind/smb/src/FileInfo.php', 'Icewind\\SMB\\IAuth' => __DIR__ . '/..' . '/icewind/smb/src/IAuth.php',
'Icewind\\SMB\\IFileInfo' => __DIR__ . '/..' . '/icewind/smb/src/IFileInfo.php', 'Icewind\\SMB\\IFileInfo' => __DIR__ . '/..' . '/icewind/smb/src/IFileInfo.php',
'Icewind\\SMB\\INotifyHandler' => __DIR__ . '/..' . '/icewind/smb/src/INotifyHandler.php', 'Icewind\\SMB\\INotifyHandler' => __DIR__ . '/..' . '/icewind/smb/src/INotifyHandler.php',
'Icewind\\SMB\\IServer' => __DIR__ . '/..' . '/icewind/smb/src/IServer.php',
'Icewind\\SMB\\IShare' => __DIR__ . '/..' . '/icewind/smb/src/IShare.php', 'Icewind\\SMB\\IShare' => __DIR__ . '/..' . '/icewind/smb/src/IShare.php',
'Icewind\\SMB\\NativeFileInfo' => __DIR__ . '/..' . '/icewind/smb/src/NativeFileInfo.php', 'Icewind\\SMB\\KerberosAuth' => __DIR__ . '/..' . '/icewind/smb/src/KerberosAuth.php',
'Icewind\\SMB\\NativeReadStream' => __DIR__ . '/..' . '/icewind/smb/src/NativeReadStream.php', 'Icewind\\SMB\\Native\\NativeFileInfo' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeFileInfo.php',
'Icewind\\SMB\\NativeServer' => __DIR__ . '/..' . '/icewind/smb/src/NativeServer.php', 'Icewind\\SMB\\Native\\NativeReadStream' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeReadStream.php',
'Icewind\\SMB\\NativeShare' => __DIR__ . '/..' . '/icewind/smb/src/NativeShare.php', 'Icewind\\SMB\\Native\\NativeServer' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeServer.php',
'Icewind\\SMB\\NativeState' => __DIR__ . '/..' . '/icewind/smb/src/NativeState.php', 'Icewind\\SMB\\Native\\NativeShare' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeShare.php',
'Icewind\\SMB\\NativeStream' => __DIR__ . '/..' . '/icewind/smb/src/NativeStream.php', 'Icewind\\SMB\\Native\\NativeState' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeState.php',
'Icewind\\SMB\\NativeWriteStream' => __DIR__ . '/..' . '/icewind/smb/src/NativeWriteStream.php', 'Icewind\\SMB\\Native\\NativeStream' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeStream.php',
'Icewind\\SMB\\NotifyHandler' => __DIR__ . '/..' . '/icewind/smb/src/NotifyHandler.php', 'Icewind\\SMB\\Native\\NativeWriteStream' => __DIR__ . '/..' . '/icewind/smb/src/Native/NativeWriteStream.php',
'Icewind\\SMB\\Parser' => __DIR__ . '/..' . '/icewind/smb/src/Parser.php', 'Icewind\\SMB\\ServerFactory' => __DIR__ . '/..' . '/icewind/smb/src/ServerFactory.php',
'Icewind\\SMB\\RawConnection' => __DIR__ . '/..' . '/icewind/smb/src/RawConnection.php',
'Icewind\\SMB\\Server' => __DIR__ . '/..' . '/icewind/smb/src/Server.php',
'Icewind\\SMB\\Share' => __DIR__ . '/..' . '/icewind/smb/src/Share.php',
'Icewind\\SMB\\System' => __DIR__ . '/..' . '/icewind/smb/src/System.php', 'Icewind\\SMB\\System' => __DIR__ . '/..' . '/icewind/smb/src/System.php',
'Icewind\\SMB\\Test\\AbstractShareTest' => __DIR__ . '/..' . '/icewind/smb/tests/AbstractShareTest.php', 'Icewind\\SMB\\Test\\AbstractShareTest' => __DIR__ . '/..' . '/icewind/smb/tests/AbstractShareTest.php',
'Icewind\\SMB\\Test\\NativeShareTestTest' => __DIR__ . '/..' . '/icewind/smb/tests/NativeShareTestTest.php', 'Icewind\\SMB\\Test\\NativeShareTest' => __DIR__ . '/..' . '/icewind/smb/tests/NativeShareTest.php',
'Icewind\\SMB\\Test\\NativeStreamTest' => __DIR__ . '/..' . '/icewind/smb/tests/NativeStreamTest.php', 'Icewind\\SMB\\Test\\NativeStreamTest' => __DIR__ . '/..' . '/icewind/smb/tests/NativeStreamTest.php',
'Icewind\\SMB\\Test\\NotifyHandlerTest' => __DIR__ . '/..' . '/icewind/smb/tests/NotifyHandlerTest.php', 'Icewind\\SMB\\Test\\NotifyHandlerTest' => __DIR__ . '/..' . '/icewind/smb/tests/NotifyHandlerTest.php',
'Icewind\\SMB\\Test\\ParserTest' => __DIR__ . '/..' . '/icewind/smb/tests/ParserTest.php', 'Icewind\\SMB\\Test\\ParserTest' => __DIR__ . '/..' . '/icewind/smb/tests/ParserTest.php',
'Icewind\\SMB\\Test\\ServerTest' => __DIR__ . '/..' . '/icewind/smb/tests/ServerTest.php', 'Icewind\\SMB\\Test\\ServerTest' => __DIR__ . '/..' . '/icewind/smb/tests/ServerTest.php',
'Icewind\\SMB\\Test\\ShareTestTest' => __DIR__ . '/..' . '/icewind/smb/tests/ShareTestTest.php', 'Icewind\\SMB\\Test\\ShareTest' => __DIR__ . '/..' . '/icewind/smb/tests/ShareTest.php',
'Icewind\\SMB\\Test\\TestCase' => __DIR__ . '/..' . '/icewind/smb/tests/TestCase.php', 'Icewind\\SMB\\Test\\TestCase' => __DIR__ . '/..' . '/icewind/smb/tests/TestCase.php',
'Icewind\\SMB\\TimeZoneProvider' => __DIR__ . '/..' . '/icewind/smb/src/TimeZoneProvider.php', 'Icewind\\SMB\\TimeZoneProvider' => __DIR__ . '/..' . '/icewind/smb/src/TimeZoneProvider.php',
'Icewind\\SMB\\Wrapped\\Connection' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/Connection.php',
'Icewind\\SMB\\Wrapped\\ErrorCodes' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/ErrorCodes.php',
'Icewind\\SMB\\Wrapped\\FileInfo' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/FileInfo.php',
'Icewind\\SMB\\Wrapped\\NotifyHandler' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/NotifyHandler.php',
'Icewind\\SMB\\Wrapped\\Parser' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/Parser.php',
'Icewind\\SMB\\Wrapped\\RawConnection' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/RawConnection.php',
'Icewind\\SMB\\Wrapped\\Server' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/Server.php',
'Icewind\\SMB\\Wrapped\\Share' => __DIR__ . '/..' . '/icewind/smb/src/Wrapped/Share.php',
'Icewind\\Streams\\CallbackWrapper' => __DIR__ . '/..' . '/icewind/streams/src/CallbackWrapper.php', 'Icewind\\Streams\\CallbackWrapper' => __DIR__ . '/..' . '/icewind/streams/src/CallbackWrapper.php',
'Icewind\\Streams\\Directory' => __DIR__ . '/..' . '/icewind/streams/src/Directory.php', 'Icewind\\Streams\\Directory' => __DIR__ . '/..' . '/icewind/streams/src/Directory.php',
'Icewind\\Streams\\DirectoryFilter' => __DIR__ . '/..' . '/icewind/streams/src/DirectoryFilter.php', 'Icewind\\Streams\\DirectoryFilter' => __DIR__ . '/..' . '/icewind/streams/src/DirectoryFilter.php',

View File

@ -1,27 +1,27 @@
[ [
{ {
"name": "icewind/smb", "name": "icewind/smb",
"version": "v2.0.5", "version": "v3.0.0",
"version_normalized": "2.0.5.0", "version_normalized": "3.0.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/icewind1991/SMB.git", "url": "https://github.com/icewind1991/SMB.git",
"reference": "b888dd81bd05532677e1469849d9065011256a33" "reference": "0d31da4757a37d322e1e181f2286e8a4c89fbc0c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/icewind1991/SMB/zipball/b888dd81bd05532677e1469849d9065011256a33", "url": "https://api.github.com/repos/icewind1991/SMB/zipball/0d31da4757a37d322e1e181f2286e8a4c89fbc0c",
"reference": "b888dd81bd05532677e1469849d9065011256a33", "reference": "0d31da4757a37d322e1e181f2286e8a4c89fbc0c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"icewind/streams": ">=0.2.0", "icewind/streams": ">=0.2.0",
"php": ">=5.4" "php": ">=5.6"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8" "phpunit/phpunit": "^5.7"
}, },
"time": "2018-03-28T13:51:31+00:00", "time": "2018-05-24T09:48:51+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {

View File

@ -16,45 +16,58 @@ PHP wrapper for `smbclient` and [`libsmbclient-php`](https://github.com/eduardok
Examples Examples
---- ----
### Upload a file ### ### Connect to a share ###
```php ```php
<?php <?php
use Icewind\SMB\Server; use Icewind\SMB\ServerFactory;
use Icewind\SMB\BasicAuth;
require('vendor/autoload.php'); require('vendor/autoload.php');
$fileToUpload = __FILE__; $serverFactory = new ServerFactory();
$auth = new BasicAuth('test', 'workgroup', 'test');
$server = $serverFactory->createServer('localhost', $auth);
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test'); $share = $server->getShare('test');
```
The server factory will automatically pick between the `smbclient` and `libsmbclient-php`
based backend depending on what is available.
### Using anonymous authentication ###
```php
$serverFactory = new ServerFactory();
$auth = new AnonymousAuth();
$server = $serverFactory->createServer('localhost', $auth);
```
### Using kerberos authentication ###
```php
$serverFactory = new ServerFactory();
$auth = new KerberosAuth();
$server = $serverFactory->createServer('localhost', $auth);
```
Note that this requires a valid kerberos ticket to already be available for php
### Upload a file ###
```php
$share->put($fileToUpload, 'example.txt'); $share->put($fileToUpload, 'example.txt');
``` ```
### Download a file ### ### Download a file ###
```php ```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$target = __DIR__ . '/target.txt';
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$share->get('example.txt', $target); $share->get('example.txt', $target);
``` ```
### List shares on the remote server ### ### List shares on the remote server ###
```php ```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$shares = $server->listShares(); $shares = $server->listShares();
foreach ($shares as $share) { foreach ($shares as $share) {
@ -65,13 +78,6 @@ foreach ($shares as $share) {
### List the content of a folder ### ### List the content of a folder ###
```php ```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$content = $share->dir('test'); $content = $share->dir('test');
foreach ($content as $info) { foreach ($content as $info) {
@ -83,14 +89,6 @@ foreach ($content as $info) {
### Using read streams ### Using read streams
```php ```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$fh = $share->read('test.txt'); $fh = $share->read('test.txt');
echo fread($fh, 4086); echo fread($fh, 4086);
fclose($fh); fclose($fh);
@ -99,54 +97,27 @@ fclose($fh);
### Using write streams ### Using write streams
```php ```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$fh = $share->write('test.txt'); $fh = $share->write('test.txt');
fwrite($fh, 'bar'); fwrite($fh, 'bar');
fclose($fh); fclose($fh);
``` ```
### Using libsmbclient-php ###
Install [libsmbclient-php](https://github.com/eduardok/libsmbclient-php)
```php
<?php
use Icewind\SMB\Server;
use Icewind\SMB\NativeServer;
require('vendor/autoload.php');
$fileToUpload = __FILE__;
if (Server::NativeAvailable()) {
$server = new NativeServer('localhost', 'test', 'test');
} else {
echo 'libsmbclient-php not available, falling back to wrapping smbclient';
$server = new Server('localhost', 'test', 'test');
}
$share = $server->getShare('test');
$share->put($fileToUpload, 'example.txt');
```
### Using notify ### Using notify
```php ```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$share->notify('')->listen(function (\Icewind\SMB\Change $change) { $share->notify('')->listen(function (\Icewind\SMB\Change $change) {
echo $change->getCode() . ': ' . $change->getPath() . "\n"; echo $change->getCode() . ': ' . $change->getPath() . "\n";
}); });
``` ```
## Testing SMB
Use the following steps to check if the library can connect to your SMB share.
1. Clone this repository or download the source as [zip](https://github.com/icewind1991/SMB/archive/master.zip)
2. Make sure [composer](https://getcomposer.org/) is installed
3. Run `composer install` in the root of the repository
4. Edit `example.php` with the relevant settings for your share.
5. Run `php example.php`
If everything works correctly then the contents of the share should be outputted.

View File

@ -9,11 +9,11 @@
} }
], ],
"require" : { "require" : {
"php": ">=5.4", "php": ">=5.6",
"icewind/streams": ">=0.2.0" "icewind/streams": ">=0.2.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8" "phpunit/phpunit": "^5.7"
}, },
"autoload" : { "autoload" : {
"psr-4": { "psr-4": {

View File

@ -0,0 +1,85 @@
<?php
/**
* @copyright Copyright (c) 2018 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;
abstract class AbstractServer implements IServer {
const LOCALE = 'en_US.UTF-8';
/**
* @var string $host
*/
protected $host;
/**
* @var IAuth $user
*/
protected $auth;
/**
* @var \Icewind\SMB\System
*/
protected $system;
/**
* @var TimeZoneProvider
*/
protected $timezoneProvider;
/**
* @param string $host
* @param IAuth $auth
* @param System $system
* @param TimeZoneProvider $timeZoneProvider
*/
public function __construct($host, IAuth $auth, System $system, TimeZoneProvider $timeZoneProvider) {
$this->host = $host;
$this->auth = $auth;
$this->system = $system;
$this->timezoneProvider = $timeZoneProvider;
}
/**
* @return IAuth
*/
public function getAuth() {
return $this->auth;
}
/**
* return string
*/
public function getHost() {
return $this->host;
}
/**
* @return string
*/
public function getTimeZone() {
return $this->timezoneProvider->get();
}
public function getSystem() {
return $this->system;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @copyright Copyright (c) 2018 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 AnonymousAuth implements IAuth {
public function getUsername() {
return null;
}
public function getWorkgroup() {
return 'dummy';
}
public function getPassword() {
return null;
}
public function getExtraCommandLineArguments() {
return '-N';
}
public function setExtraSmbClientOptions($smbClientState) {
smbclient_option_set($smbClientState, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, true);
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* @copyright Copyright (c) 2018 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 BasicAuth implements IAuth {
/** @var string */
private $username;
/** @var string */
private $workgroup;
/** @var string */
private $password;
/**
* BasicAuth constructor.
*
* @param string $username
* @param string $workgroup
* @param string $password
*/
public function __construct($username, $workgroup, $password) {
$this->username = $username;
$this->workgroup = $workgroup;
$this->password = $password;
}
public function getUsername() {
return $this->username;
}
public function getWorkgroup() {
return $this->workgroup;
}
public function getPassword() {
return $this->password;
}
public function getExtraCommandLineArguments() {
return ($this->workgroup) ? '-W ' . escapeshellarg($this->workgroup) : '';
}
public function setExtraSmbClientOptions($smbClientState) {
// noop
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (c) 2018 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;
interface IAuth {
/**
* @return string|null
*/
public function getUsername();
/**
* @return string|null
*/
public function getWorkgroup();
/**
* @return string|null
*/
public function getPassword();
/**
* Any extra command line option for smbclient that are required
*
* @return string
*/
public function getExtraCommandLineArguments();
/**
* Set any extra options for libsmbclient that are required
*
* @param resource $smbClientState
*/
public function setExtraSmbClientOptions($smbClientState);
}

View File

@ -8,6 +8,19 @@
namespace Icewind\SMB; namespace Icewind\SMB;
interface IFileInfo { interface IFileInfo {
/*
* Mappings of the DOS mode bits, as returned by smbc_getxattr() when the
* attribute name "system.dos_attr.mode" (or "system.dos_attr.*" or
* "system.*") is specified.
*/
const MODE_READONLY = 0x01;
const MODE_HIDDEN = 0x02;
const MODE_SYSTEM = 0x04;
const MODE_VOLUME_ID = 0x08;
const MODE_DIRECTORY = 0x10;
const MODE_ARCHIVE = 0x20;
const MODE_NORMAL = 0x80;
/** /**
* @return string * @return string
*/ */

View File

@ -0,0 +1,64 @@
<?php
/**
* @copyright Copyright (c) 2018 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;
interface IServer {
/**
* @return IAuth
*/
public function getAuth();
/**
* @return string
*/
public function getHost();
/**
* @return \Icewind\SMB\IShare[]
*
* @throws \Icewind\SMB\Exception\AuthenticationException
* @throws \Icewind\SMB\Exception\InvalidHostException
*/
public function listShares();
/**
* @param string $name
* @return \Icewind\SMB\IShare
*/
public function getShare($name);
/**
* @return string
*/
public function getTimeZone();
/**
* @return System
*/
public function getSystem();
/**
* @param System $system
* @return bool
*/
public static function available(System $system);
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @copyright Copyright (c) 2018 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;
/**
* Use existing kerberos ticket to authenticate
*/
class KerberosAuth implements IAuth {
public function getUsername() {
return 'dummy';
}
public function getWorkgroup() {
return 'dummy';
}
public function getPassword() {
return null;
}
public function getExtraCommandLineArguments() {
return '-k';
}
public function setExtraSmbClientOptions($smbClientState) {
smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true);
smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false);
}
}

View File

@ -5,7 +5,9 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
use Icewind\SMB\IFileInfo;
class NativeFileInfo implements IFileInfo { class NativeFileInfo implements IFileInfo {
const MODE_FILE = 0100000; const MODE_FILE = 0100000;
@ -21,7 +23,7 @@ class NativeFileInfo implements IFileInfo {
protected $name; protected $name;
/** /**
* @var \Icewind\SMB\NativeShare * @var NativeShare
*/ */
protected $share; protected $share;
@ -36,7 +38,7 @@ class NativeFileInfo implements IFileInfo {
protected $modeCache; protected $modeCache;
/** /**
* @param \Icewind\SMB\NativeShare $share * @param NativeShare $share
* @param string $path * @param string $path
* @param string $name * @param string $name
* @param array $stat * @param array $stat
@ -113,7 +115,7 @@ class NativeFileInfo implements IFileInfo {
*/ */
public function isReadOnly() { public function isReadOnly() {
$mode = $this->getMode(); $mode = $this->getMode();
return (bool)($mode & FileInfo::MODE_READONLY); return (bool)($mode & IFileInfo::MODE_READONLY);
} }
/** /**
@ -121,7 +123,7 @@ class NativeFileInfo implements IFileInfo {
*/ */
public function isHidden() { public function isHidden() {
$mode = $this->getMode(); $mode = $this->getMode();
return (bool)($mode & FileInfo::MODE_HIDDEN); return (bool)($mode & IFileInfo::MODE_HIDDEN);
} }
/** /**
@ -129,7 +131,7 @@ class NativeFileInfo implements IFileInfo {
*/ */
public function isSystem() { public function isSystem() {
$mode = $this->getMode(); $mode = $this->getMode();
return (bool)($mode & FileInfo::MODE_SYSTEM); return (bool)($mode & IFileInfo::MODE_SYSTEM);
} }
/** /**
@ -137,6 +139,6 @@ class NativeFileInfo implements IFileInfo {
*/ */
public function isArchived() { public function isArchived() {
$mode = $this->getMode(); $mode = $this->getMode();
return (bool)($mode & FileInfo::MODE_ARCHIVE); return (bool)($mode & IFileInfo::MODE_ARCHIVE);
} }
} }

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
/** /**
* Stream optimized for read only usage * Stream optimized for read only usage
@ -38,7 +38,7 @@ class NativeReadStream extends NativeStream {
* @return resource * @return resource
*/ */
public static function wrap($state, $smbStream, $mode, $url) { public static function wrap($state, $smbStream, $mode, $url) {
stream_wrapper_register('nativesmb', '\Icewind\SMB\NativeReadStream'); stream_wrapper_register('nativesmb', NativeReadStream::class);
$context = stream_context_create(array( $context = stream_context_create(array(
'nativesmb' => array( 'nativesmb' => array(
'state' => $state, 'state' => $state,

View File

@ -5,26 +5,32 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
class NativeServer extends Server { use Icewind\SMB\AbstractServer;
use Icewind\SMB\IAuth;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
class NativeServer extends AbstractServer {
/** /**
* @var \Icewind\SMB\NativeState * @var NativeState
*/ */
protected $state; protected $state;
/** /**
* @param string $host * @param string $host
* @param string $user * @param IAuth $auth
* @param string $password * @param System $system
* @param TimeZoneProvider $timeZoneProvider
*/ */
public function __construct($host, $user, $password) { public function __construct($host, IAuth $auth, System $system, TimeZoneProvider $timeZoneProvider) {
parent::__construct($host, $user, $password); parent::__construct($host, $auth, $system, $timeZoneProvider);
$this->state = new NativeState(); $this->state = new NativeState();
} }
protected function connect() { protected function connect() {
$this->state->init($this->getWorkgroup(), $this->getUser(), $this->getPassword()); $this->state->init($this->getAuth());
} }
/** /**
@ -52,4 +58,14 @@ class NativeServer extends Server {
public function getShare($name) { public function getShare($name) {
return new NativeShare($this, $name); return new NativeShare($this, $name);
} }
/**
* Check if the smbclient php extension is available
*
* @param System $system
* @return bool
*/
public static function available(System $system) {
return function_exists('smbclient_state_new');
}
} }

View File

@ -5,14 +5,20 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
use Icewind\SMB\AbstractShare;
use Icewind\SMB\Exception\DependencyException;
use Icewind\SMB\Exception\InvalidPathException; use Icewind\SMB\Exception\InvalidPathException;
use Icewind\SMB\Exception\InvalidResourceException; use Icewind\SMB\Exception\InvalidResourceException;
use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IServer;
use Icewind\SMB\Wrapped\Server;
use Icewind\SMB\Wrapped\Share;
class NativeShare extends AbstractShare { class NativeShare extends AbstractShare {
/** /**
* @var Server $server * @var IServer $server
*/ */
private $server; private $server;
@ -22,12 +28,12 @@ class NativeShare extends AbstractShare {
private $name; private $name;
/** /**
* @var \Icewind\SMB\NativeState $state * @var NativeState $state
*/ */
private $state; private $state;
/** /**
* @param Server $server * @param IServer $server
* @param string $name * @param string $name
*/ */
public function __construct($server, $name) { public function __construct($server, $name) {
@ -47,7 +53,7 @@ class NativeShare extends AbstractShare {
} }
$this->state = new NativeState(); $this->state = new NativeState();
$this->state->init($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword()); $this->state->init($this->server->getAuth());
return $this->state; return $this->state;
} }
@ -295,6 +301,9 @@ class NativeShare extends AbstractShare {
public function notify($path) { public function notify($path) {
// php-smbclient does support notify (https://github.com/eduardok/libsmbclient-php/issues/29) // php-smbclient does support notify (https://github.com/eduardok/libsmbclient-php/issues/29)
// so we use the smbclient based backend for this // so we use the smbclient based backend for this
if (!Server::available($this->server->getSystem())) {
throw new DependencyException('smbclient not found in path for notify command');
}
$share = new Share($this->server, $this->getName()); $share = new Share($this->server, $this->getName());
return $share->notify($path); return $share->notify($path);
} }

View File

@ -5,9 +5,22 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\ConnectionRefusedException;
use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\ForbiddenException;
use Icewind\SMB\Exception\HostDownException;
use Icewind\SMB\Exception\InvalidArgumentException;
use Icewind\SMB\Exception\InvalidTypeException;
use Icewind\SMB\Exception\NoRouteToHostException;
use Icewind\SMB\Exception\NotEmptyException;
use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\Exception\OutOfSpaceException;
use Icewind\SMB\Exception\TimedOutException;
use Icewind\SMB\IAuth;
/** /**
* Low level wrapper for libsmbclient-php with error handling * Low level wrapper for libsmbclient-php with error handling
@ -22,23 +35,22 @@ class NativeState {
protected $connected = false; protected $connected = false;
// todo replace with static once <5.6 support is dropped
// see error.h // see error.h
private static $exceptionMap = [ const EXCEPTION_MAP = [
1 => '\Icewind\SMB\Exception\ForbiddenException', 1 => ForbiddenException::class,
2 => '\Icewind\SMB\Exception\NotFoundException', 2 => NotFoundException::class,
13 => '\Icewind\SMB\Exception\ForbiddenException', 13 => ForbiddenException::class,
16 => '\Icewind\SMB\Exception\FileInUseException', 16 => FileInUseException::class,
17 => '\Icewind\SMB\Exception\AlreadyExistsException', 17 => AlreadyExistsException::class,
20 => '\Icewind\SMB\Exception\InvalidTypeException', 20 => InvalidTypeException::class,
21 => '\Icewind\SMB\Exception\InvalidTypeException', 21 => InvalidTypeException::class,
22 => '\Icewind\SMB\Exception\InvalidArgumentException', 22 => InvalidArgumentException::class,
28 => '\Icewind\SMB\Exception\OutOfSpaceException', 28 => OutOfSpaceException::class,
39 => '\Icewind\SMB\Exception\NotEmptyException', 39 => NotEmptyException::class,
110 => '\Icewind\SMB\Exception\TimedOutException', 110 => TimedOutException::class,
111 => '\Icewind\SMB\Exception\ConnectionRefusedException', 111 => ConnectionRefusedException::class,
112 => '\Icewind\SMB\Exception\HostDownException', 112 => HostDownException::class,
113 => '\Icewind\SMB\Exception\NoRouteToHostException' 113 => NoRouteToHostException::class
]; ];
protected function handleError($path) { protected function handleError($path) {
@ -46,13 +58,13 @@ class NativeState {
if ($error === 0) { if ($error === 0) {
return; return;
} }
throw Exception::fromMap(self::$exceptionMap, $error, $path); throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path);
} }
protected function testResult($result, $uri) { protected function testResult($result, $uri) {
if ($result === false or $result === null) { if ($result === false or $result === null) {
// smb://host/share/path // smb://host/share/path
if (is_string($uri)) { if (is_string($uri) && count(explode('/', $uri, 5)) > 4) {
list(, , , , $path) = explode('/', $uri, 5); list(, , , , $path) = explode('/', $uri, 5);
$path = '/' . $path; $path = '/' . $path;
} else { } else {
@ -63,18 +75,17 @@ class NativeState {
} }
/** /**
* @param string $workGroup * @param IAuth $auth
* @param string $user
* @param string $password
* @return bool * @return bool
*/ */
public function init($workGroup, $user, $password) { public function init(IAuth $auth) {
if ($this->connected) { if ($this->connected) {
return true; return true;
} }
$this->state = smbclient_state_new(); $this->state = smbclient_state_new();
smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false); smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false);
$result = @smbclient_state_init($this->state, $workGroup, $user, $password); $auth->setExtraSmbClientOptions($this->state);
$result = @smbclient_state_init($this->state, $auth->getWorkgroup(), $auth->getUsername(), $auth->getPassword());
$this->testResult($result, ''); $this->testResult($result, '');
$this->connected = true; $this->connected = true;

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\InvalidRequestException; use Icewind\SMB\Exception\InvalidRequestException;
@ -18,7 +18,7 @@ class NativeStream implements File {
public $context; public $context;
/** /**
* @var \Icewind\SMB\NativeState * @var NativeState
*/ */
protected $state; protected $state;
@ -47,7 +47,7 @@ class NativeStream implements File {
* @return resource * @return resource
*/ */
public static function wrap($state, $smbStream, $mode, $url) { public static function wrap($state, $smbStream, $mode, $url) {
stream_wrapper_register('nativesmb', '\Icewind\SMB\NativeStream'); stream_wrapper_register('nativesmb', NativeStream::class);
$context = stream_context_create(array( $context = stream_context_create(array(
'nativesmb' => array( 'nativesmb' => array(
'state' => $state, 'state' => $state,

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Native;
/** /**
* Stream optimized for write only usage * Stream optimized for write only usage
@ -38,7 +38,7 @@ class NativeWriteStream extends NativeStream {
* @return resource * @return resource
*/ */
public static function wrap($state, $smbStream, $mode, $url) { public static function wrap($state, $smbStream, $mode, $url) {
stream_wrapper_register('nativesmb', '\Icewind\SMB\NativeWriteStream'); stream_wrapper_register('nativesmb', NativeWriteStream::class);
$context = stream_context_create(array( $context = stream_context_create(array(
'nativesmb' => array( 'nativesmb' => array(
'state' => $state, 'state' => $state,

View File

@ -1,166 +0,0 @@
<?php
/**
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Licensed under the MIT license:
* http://opensource.org/licenses/MIT
*/
namespace Icewind\SMB;
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\InvalidHostException;
class Server {
const LOCALE = 'en_US.UTF-8';
/**
* @var string $host
*/
protected $host;
/**
* @var string $user
*/
protected $user;
/**
* @var string $password
*/
protected $password;
/**
* @var string $workgroup
*/
protected $workgroup;
/**
* @var \Icewind\SMB\System
*/
private $system;
/**
* @var TimeZoneProvider
*/
private $timezoneProvider;
/**
* Check if the smbclient php extension is available
*
* @return bool
*/
public static function NativeAvailable() {
return function_exists('smbclient_state_new');
}
/**
* @param string $host
* @param string $user
* @param string $password
*/
public function __construct($host, $user, $password) {
$this->host = $host;
list($workgroup, $user) = $this->splitUser($user);
$this->user = $user;
$this->workgroup = $workgroup;
$this->password = $password;
$this->system = new System();
$this->timezoneProvider = new TimeZoneProvider($host, $this->system);
}
/**
* Split workgroup from username
*
* @param $user
* @return string[] [$workgroup, $user]
*/
public function splitUser($user) {
if (strpos($user, '/')) {
return explode('/', $user, 2);
} elseif (strpos($user, '\\')) {
return explode('\\', $user);
} else {
return array(null, $user);
}
}
/**
* @return string
*/
public function getAuthString() {
return $this->user . '%' . $this->password;
}
/**
* @return string
*/
public function getUser() {
return $this->user;
}
/**
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* return string
*/
public function getHost() {
return $this->host;
}
/**
* @return string
*/
public function getWorkgroup() {
return $this->workgroup;
}
/**
* @return \Icewind\SMB\IShare[]
*
* @throws \Icewind\SMB\Exception\AuthenticationException
* @throws \Icewind\SMB\Exception\InvalidHostException
*/
public function listShares() {
$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
$command = sprintf('%s %s --authentication-file=%s -gL %s',
$this->system->getSmbclientPath(),
$workgroupArgument,
System::getFD(3),
escapeshellarg($this->getHost())
);
$connection = new RawConnection($command);
$connection->writeAuthentication($this->getUser(), $this->getPassword());
$connection->connect();
$output = $connection->readAll();
$parser = new Parser($this->timezoneProvider);
$parser->checkConnectionError($output[0]);
$shareNames = $parser->parseListShares($output);
$shares = array();
foreach ($shareNames as $name => $description) {
$shares[] = $this->getShare($name);
}
return $shares;
}
/**
* @param string $name
* @return \Icewind\SMB\IShare
*/
public function getShare($name) {
return new Share($this, $name, $this->system);
}
/**
* @return string
*/
public function getTimeZone() {
return $this->timezoneProvider->get();
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* @copyright Copyright (c) 2018 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;
use Icewind\SMB\Exception\DependencyException;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Wrapped\Server;
class ServerFactory {
const BACKENDS = [
NativeServer::class,
Server::class
];
/** @var System|null */
private $system = null;
/**
* @param $host
* @param IAuth $credentials
* @return IServer
* @throws DependencyException
*/
public function createServer($host, IAuth $credentials) {
foreach (self::BACKENDS as $backend) {
if (call_user_func("$backend::available", $this->getSystem())) {
return new $backend($host, $credentials, $this->getSystem(), new TimeZoneProvider($host, $this->getSystem()));
}
}
throw new DependencyException('No valid backend available, ensure smbclient is in the path or php-smbclient is installed');
}
/**
* @return System
*/
private function getSystem() {
if (is_null($this->system)) {
$this->system = new System();
}
return $this->system;
}
}

View File

@ -17,10 +17,10 @@ class System {
private $stdbuf; private $stdbuf;
public static function getFD($num) { public static function getFD($num) {
$folders = array( $folders = [
'/proc/self/fd', '/proc/self/fd',
'/dev/fd' '/dev/fd'
); ];
foreach ($folders as $folder) { foreach ($folders as $folder) {
if (file_exists($folder)) { if (file_exists($folder)) {
return $folder . '/' . $num; return $folder . '/' . $num;

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
use Icewind\SMB\Exception\AuthenticationException; use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\ConnectException;

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
class ErrorCodes { class ErrorCodes {
/** /**

View File

@ -5,22 +5,11 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
use Icewind\SMB\IFileInfo;
class FileInfo implements IFileInfo { class FileInfo implements IFileInfo {
/*
* Mappings of the DOS mode bits, as returned by smbc_getxattr() when the
* attribute name "system.dos_attr.mode" (or "system.dos_attr.*" or
* "system.*") is specified.
*/
const MODE_READONLY = 0x01;
const MODE_HIDDEN = 0x02;
const MODE_SYSTEM = 0x04;
const MODE_VOLUME_ID = 0x08;
const MODE_DIRECTORY = 0x10;
const MODE_ARCHIVE = 0x20;
const MODE_NORMAL = 0x80;
/** /**
* @var string * @var string
*/ */
@ -93,34 +82,34 @@ class FileInfo implements IFileInfo {
* @return bool * @return bool
*/ */
public function isDirectory() { public function isDirectory() {
return (bool)($this->mode & self::MODE_DIRECTORY); return (bool)($this->mode & IFileInfo::MODE_DIRECTORY);
} }
/** /**
* @return bool * @return bool
*/ */
public function isReadOnly() { public function isReadOnly() {
return (bool)($this->mode & self::MODE_READONLY); return (bool)($this->mode & IFileInfo::MODE_READONLY);
} }
/** /**
* @return bool * @return bool
*/ */
public function isHidden() { public function isHidden() {
return (bool)($this->mode & self::MODE_HIDDEN); return (bool)($this->mode & IFileInfo::MODE_HIDDEN);
} }
/** /**
* @return bool * @return bool
*/ */
public function isSystem() { public function isSystem() {
return (bool)($this->mode & self::MODE_SYSTEM); return (bool)($this->mode & IFileInfo::MODE_SYSTEM);
} }
/** /**
* @return bool * @return bool
*/ */
public function isArchived() { public function isArchived() {
return (bool)($this->mode & self::MODE_ARCHIVE); return (bool)($this->mode & IFileInfo::MODE_ARCHIVE);
} }
} }

View File

@ -6,10 +6,13 @@
* *
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
use Icewind\SMB\Change;
use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\RevisionMismatchException;
use Icewind\SMB\INotifyHandler;
class NotifyHandler implements INotifyHandler { class NotifyHandler implements INotifyHandler {
/** /**
@ -24,10 +27,9 @@ class NotifyHandler implements INotifyHandler {
private $listening = true; private $listening = true;
// todo replace with static once <5.6 support is dropped
// see error.h // see error.h
private static $exceptionMap = [ const EXCEPTION_MAP = [
ErrorCodes::RevisionMismatch => '\Icewind\SMB\Exception\RevisionMismatchException', ErrorCodes::RevisionMismatch => RevisionMismatchException::class,
]; ];
/** /**
@ -93,7 +95,7 @@ class NotifyHandler implements INotifyHandler {
private function checkForError($line) { private function checkForError($line) {
if (substr($line, 0, 16) === 'notify returned ') { if (substr($line, 0, 16) === 'notify returned ') {
$error = substr($line, 16); $error = substr($line, 16);
throw Exception::fromMap(self::$exceptionMap, $error, 'Notify is not supported with the used smb version'); throw Exception::fromMap(array_merge(self::EXCEPTION_MAP, Parser::EXCEPTION_MAP), $error, 'Notify is not supported with the used smb version');
} }
} }

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
use Icewind\SMB\Exception\AccessDeniedException; use Icewind\SMB\Exception\AccessDeniedException;
use Icewind\SMB\Exception\AlreadyExistsException; use Icewind\SMB\Exception\AlreadyExistsException;
@ -13,11 +13,13 @@ use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\FileInUseException; use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\InvalidHostException; use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\Exception\InvalidParameterException;
use Icewind\SMB\Exception\InvalidResourceException; use Icewind\SMB\Exception\InvalidResourceException;
use Icewind\SMB\Exception\InvalidTypeException; use Icewind\SMB\Exception\InvalidTypeException;
use Icewind\SMB\Exception\NoLoginServerException; use Icewind\SMB\Exception\NoLoginServerException;
use Icewind\SMB\Exception\NotEmptyException; use Icewind\SMB\Exception\NotEmptyException;
use Icewind\SMB\Exception\NotFoundException; use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\TimeZoneProvider;
class Parser { class Parser {
const MSG_NOT_FOUND = 'Error opening local file '; const MSG_NOT_FOUND = 'Error opening local file ';
@ -29,22 +31,31 @@ class Parser {
// todo replace with static once <5.6 support is dropped // todo replace with static once <5.6 support is dropped
// see error.h // see error.h
private static $exceptionMap = [ const EXCEPTION_MAP = [
ErrorCodes::LogonFailure => '\Icewind\SMB\Exception\AuthenticationException', ErrorCodes::LogonFailure => AuthenticationException::class,
ErrorCodes::PathNotFound => '\Icewind\SMB\Exception\NotFoundException', ErrorCodes::PathNotFound => NotFoundException::class,
ErrorCodes::ObjectNotFound => '\Icewind\SMB\Exception\NotFoundException', ErrorCodes::ObjectNotFound => NotFoundException::class,
ErrorCodes::NoSuchFile => '\Icewind\SMB\Exception\NotFoundException', ErrorCodes::NoSuchFile => NotFoundException::class,
ErrorCodes::NameCollision => '\Icewind\SMB\Exception\AlreadyExistsException', ErrorCodes::NameCollision => AlreadyExistsException::class,
ErrorCodes::AccessDenied => '\Icewind\SMB\Exception\AccessDeniedException', ErrorCodes::AccessDenied => AccessDeniedException::class,
ErrorCodes::DirectoryNotEmpty => '\Icewind\SMB\Exception\NotEmptyException', ErrorCodes::DirectoryNotEmpty => NotEmptyException::class,
ErrorCodes::FileIsADirectory => '\Icewind\SMB\Exception\InvalidTypeException', ErrorCodes::FileIsADirectory => InvalidTypeException::class,
ErrorCodes::NotADirectory => '\Icewind\SMB\Exception\InvalidTypeException', ErrorCodes::NotADirectory => InvalidTypeException::class,
ErrorCodes::SharingViolation => '\Icewind\SMB\Exception\FileInUseException', ErrorCodes::SharingViolation => FileInUseException::class,
ErrorCodes::InvalidParameter => '\Icewind\SMB\Exception\InvalidParameterException' ErrorCodes::InvalidParameter => InvalidParameterException::class
];
const MODE_STRINGS = [
'R' => FileInfo::MODE_READONLY,
'H' => FileInfo::MODE_HIDDEN,
'S' => FileInfo::MODE_SYSTEM,
'D' => FileInfo::MODE_DIRECTORY,
'A' => FileInfo::MODE_ARCHIVE,
'N' => FileInfo::MODE_NORMAL
]; ];
/** /**
* @param \Icewind\SMB\TimeZoneProvider $timeZoneProvider * @param TimeZoneProvider $timeZoneProvider
*/ */
public function __construct(TimeZoneProvider $timeZoneProvider) { public function __construct(TimeZoneProvider $timeZoneProvider) {
$this->timeZoneProvider = $timeZoneProvider; $this->timeZoneProvider = $timeZoneProvider;
@ -71,7 +82,7 @@ class Parser {
throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing'); throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing');
} }
throw Exception::fromMap(self::$exceptionMap, $error, $path); throw Exception::fromMap(self::EXCEPTION_MAP, $error, $path);
} }
/** /**
@ -107,15 +118,7 @@ class Parser {
public function parseMode($mode) { public function parseMode($mode) {
$result = 0; $result = 0;
$modeStrings = array( foreach (self::MODE_STRINGS as $char => $val) {
'R' => FileInfo::MODE_READONLY,
'H' => FileInfo::MODE_HIDDEN,
'S' => FileInfo::MODE_SYSTEM,
'D' => FileInfo::MODE_DIRECTORY,
'A' => FileInfo::MODE_ARCHIVE,
'N' => FileInfo::MODE_NORMAL
);
foreach ($modeStrings as $char => $val) {
if (strpos($mode, $char) !== false) { if (strpos($mode, $char) !== false) {
$result |= $val; $result |= $val;
} }
@ -168,6 +171,10 @@ class Parser {
if (strtolower($type) === 'disk') { if (strtolower($type) === 'disk') {
$shareNames[$name] = $description; $shareNames[$name] = $description;
} }
} else if (strpos($line, 'Disk')) {
// new output format
list($name, $description) = explode('Disk', $line);
$shareNames[trim($name)] = trim($description);
} }
} }
return $shareNames; return $shareNames;

View File

@ -5,7 +5,7 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException; use Icewind\SMB\Exception\ConnectionException;
@ -49,6 +49,9 @@ class RawConnection {
$this->env = $env; $this->env = $env;
} }
/**
* @throws ConnectException
*/
public function connect() { public function connect() {
if (is_null($this->getAuthStream())) { if (is_null($this->getAuthStream())) {
throw new ConnectException('Authentication not set before connecting'); throw new ConnectException('Authentication not set before connecting');
@ -125,7 +128,7 @@ class RawConnection {
* @return array * @return array
*/ */
public function readAll() { public function readAll() {
$output = array(); $output = [];
while ($line = $this->readLine()) { while ($line = $this->readLine()) {
$output[] = $line; $output[] = $line;
} }

View File

@ -0,0 +1,90 @@
<?php
/**
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Licensed under the MIT license:
* http://opensource.org/licenses/MIT
*/
namespace Icewind\SMB\Wrapped;
use Icewind\SMB\AbstractServer;
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\IShare;
use Icewind\SMB\System;
class Server extends AbstractServer {
/**
* Check if the smbclient php extension is available
*
* @param System $system
* @return bool
*/
public static function available(System $system) {
return $system->getSmbclientPath();
}
private function getAuthFileArgument() {
if ($this->getAuth()->getUsername()) {
return '--authentication-file=' . System::getFD(3);
} else {
return '';
}
}
/**
* @return IShare[]
*
* @throws AuthenticationException
* @throws InvalidHostException
* @throws ConnectException
*/
public function listShares() {
$command = sprintf('%s %s %s -L %s',
$this->system->getSmbclientPath(),
$this->getAuthFileArgument(),
$this->getAuth()->getExtraCommandLineArguments(),
escapeshellarg('//' . $this->getHost())
);
$connection = new RawConnection($command);
$connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword());
$connection->connect();
if (!$connection->isValid()) {
throw new ConnectionException($connection->readLine());
}
$parser = new Parser($this->timezoneProvider);
$output = $connection->readAll();
if (isset($output[0])) {
$parser->checkConnectionError($output[0]);
}
// sometimes we get an empty line first
if (count($output) < 2) {
$output = $connection->readAll();
}
if (isset($output[0])) {
$parser->checkConnectionError($output[0]);
}
$shareNames = $parser->parseListShares($output);
$shares = array();
foreach ($shareNames as $name => $description) {
$shares[] = $this->getShare($name);
}
return $shares;
}
/**
* @param string $name
* @return IShare
*/
public function getShare($name) {
return new Share($this, $name, $this->system);
}
}

View File

@ -5,18 +5,23 @@
* http://opensource.org/licenses/MIT * http://opensource.org/licenses/MIT
*/ */
namespace Icewind\SMB; namespace Icewind\SMB\Wrapped;
use Icewind\SMB\AbstractShare;
use Icewind\SMB\Exception\ConnectionException; use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\DependencyException; use Icewind\SMB\Exception\DependencyException;
use Icewind\SMB\Exception\FileInUseException; use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\InvalidTypeException; use Icewind\SMB\Exception\InvalidTypeException;
use Icewind\SMB\Exception\NotFoundException; use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IServer;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CallbackWrapper;
class Share extends AbstractShare { class Share extends AbstractShare {
/** /**
* @var Server $server * @var IServer $server
*/ */
private $server; private $server;
@ -31,21 +36,28 @@ class Share extends AbstractShare {
public $connection; public $connection;
/** /**
* @var \Icewind\SMB\Parser * @var Parser
*/ */
protected $parser; protected $parser;
/** /**
* @var \Icewind\SMB\System * @var System
*/ */
private $system; private $system;
const MODE_MAP = [
FileInfo::MODE_READONLY => 'r',
FileInfo::MODE_HIDDEN => 'h',
FileInfo::MODE_ARCHIVE => 'a',
FileInfo::MODE_SYSTEM => 's'
];
/** /**
* @param Server $server * @param IServer $server
* @param string $name * @param string $name
* @param System $system * @param System $system
*/ */
public function __construct($server, $name, System $system = null) { public function __construct(IServer $server, $name, System $system = null) {
parent::__construct(); parent::__construct();
$this->server = $server; $this->server = $server;
$this->name = $name; $this->name = $name;
@ -53,21 +65,24 @@ class Share extends AbstractShare {
$this->parser = new Parser(new TimeZoneProvider($this->server->getHost(), $this->system)); $this->parser = new Parser(new TimeZoneProvider($this->server->getHost(), $this->system));
} }
protected function getConnection() { private function getAuthFileArgument() {
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : ''; if ($this->server->getAuth()->getUsername()) {
$smbClientPath = $this->system->getSmbclientPath(); return '--authentication-file=' . System::getFD(3);
if (!$smbClientPath) { } else {
throw new DependencyException('Can\'t find smbclient binary in path'); return '';
} }
$command = sprintf('%s%s %s --authentication-file=%s %s', }
protected function getConnection() {
$command = sprintf('%s%s %s %s %s',
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '', $this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
$this->system->getSmbclientPath(), $this->system->getSmbclientPath(),
$workgroupArgument, $this->getAuthFileArgument(),
System::getFD(3), $this->server->getAuth()->getExtraCommandLineArguments(),
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name) escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
); );
$connection = new Connection($command, $this->parser); $connection = new Connection($command, $this->parser);
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword()); $connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword());
$connection->connect(); $connection->connect();
if (!$connection->isValid()) { if (!$connection->isValid()) {
throw new ConnectionException($connection->readLine()); throw new ConnectionException($connection->readLine());
@ -319,13 +334,7 @@ class Share extends AbstractShare {
*/ */
public function setMode($path, $mode) { public function setMode($path, $mode) {
$modeString = ''; $modeString = '';
$modeMap = array( foreach (self::MODE_MAP as $modeByte => $string) {
FileInfo::MODE_READONLY => 'r',
FileInfo::MODE_HIDDEN => 'h',
FileInfo::MODE_ARCHIVE => 'a',
FileInfo::MODE_SYSTEM => 's'
);
foreach ($modeMap as $modeByte => $string) {
if ($mode & $modeByte) { if ($mode & $modeByte) {
$modeString .= $string; $modeString .= $string;
} }

View File

@ -34,14 +34,16 @@
namespace OCA\Files_External\Lib\Storage; namespace OCA\Files_External\Lib\Storage;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Exception\AlreadyExistsException; use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\ForbiddenException; use Icewind\SMB\Exception\ForbiddenException;
use Icewind\SMB\Exception\NotFoundException; use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\IFileInfo; use Icewind\SMB\IFileInfo;
use Icewind\SMB\NativeServer; use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Server; use Icewind\SMB\ServerFactory;
use Icewind\SMB\System;
use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory; use Icewind\Streams\IteratorDirectory;
use OC\Cache\CappedMemoryCache; use OC\Cache\CappedMemoryCache;
@ -53,16 +55,15 @@ use OCP\Files\Notify\IRenameChange;
use OCP\Files\Storage\INotifyStorage; use OCP\Files\Storage\INotifyStorage;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\ILogger; use OCP\ILogger;
use OCP\Util;
class SMB extends Common implements INotifyStorage { class SMB extends Common implements INotifyStorage {
/** /**
* @var \Icewind\SMB\Server * @var \Icewind\SMB\IServer
*/ */
protected $server; protected $server;
/** /**
* @var \Icewind\SMB\Share * @var \Icewind\SMB\IShare
*/ */
protected $share; protected $share;
@ -72,17 +73,16 @@ class SMB extends Common implements INotifyStorage {
protected $root; protected $root;
/** /**
* @var \Icewind\SMB\FileInfo[] * @var \Icewind\SMB\IFileInfo[]
*/ */
protected $statCache; protected $statCache;
public function __construct($params) { public function __construct($params) {
if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) { if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) {
if (Server::NativeAvailable()) { list($workgroup, $user) = $this->splitUser($params['user']);
$this->server = new NativeServer($params['host'], $params['user'], $params['password']); $auth = new BasicAuth($user, $workgroup, $params['password']);
} else { $serverFactory = new ServerFactory();
$this->server = new Server($params['host'], $params['user'], $params['password']); $this->server = $serverFactory->createServer($params['host'], $auth);
}
$this->share = $this->server->getShare(trim($params['share'], '/')); $this->share = $this->server->getShare(trim($params['share'], '/'));
$this->root = $params['root'] ?? '/'; $this->root = $params['root'] ?? '/';
@ -95,6 +95,16 @@ class SMB extends Common implements INotifyStorage {
parent::__construct($params); parent::__construct($params);
} }
private function splitUser($user) {
if (strpos($user, '/')) {
return explode('/', $user, 2);
} elseif (strpos($user, '\\')) {
return explode('\\', $user);
} else {
return [null, $user];
}
}
/** /**
* @return string * @return string
*/ */
@ -102,7 +112,7 @@ class SMB extends Common implements INotifyStorage {
// FIXME: double slash to keep compatible with the old storage ids, // FIXME: double slash to keep compatible with the old storage ids,
// failure to do so will lead to creation of a new storage id and // failure to do so will lead to creation of a new storage id and
// loss of shares from the storage // loss of shares from the storage
return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root; return 'smb::' . $this->server->getAuth()->getUsername() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
} }
/** /**
@ -504,7 +514,7 @@ class SMB extends Common implements INotifyStorage {
public static function checkDependencies() { public static function checkDependencies() {
return ( return (
(bool)\OC_Helper::findBinaryPath('smbclient') (bool)\OC_Helper::findBinaryPath('smbclient')
|| Server::NativeAvailable() || NativeServer::available(new System())
) ? true : ['smbclient']; ) ? true : ['smbclient'];
} }

View File

@ -134,6 +134,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$sftpBackend = $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OCA\Files_External\Lib\Storage\SFTP'); $sftpBackend = $this->getBackendMock('\OCA\Files_External\Lib\Backend\SFTP', '\OCA\Files_External\Lib\Storage\SFTP');
$backends = [ $backends = [
'identifier:\OCA\Files_External\Lib\Backend\DAV' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\DAV', '\OC\Files\Storage\DAV'),
'identifier:\OCA\Files_External\Lib\Backend\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OCA\Files_External\Lib\Storage\SMB'), 'identifier:\OCA\Files_External\Lib\Backend\SMB' => $this->getBackendMock('\OCA\Files_External\Lib\Backend\SMB', '\OCA\Files_External\Lib\Storage\SMB'),
'identifier:\OCA\Files_External\Lib\Backend\SFTP' => $sftpBackend, 'identifier:\OCA\Files_External\Lib\Backend\SFTP' => $sftpBackend,
'identifier:sftp_alias' => $sftpBackend, 'identifier:sftp_alias' => $sftpBackend,
@ -269,25 +270,23 @@ abstract class StoragesServiceTest extends \Test\TestCase {
// regular case, can properly delete the oc_storages entry // regular case, can properly delete the oc_storages entry
[ [
[ [
'share' => 'share',
'host' => 'example.com', 'host' => 'example.com',
'user' => 'test', 'user' => 'test',
'password' => 'testPassword', 'password' => 'testPassword',
'root' => 'someroot', 'root' => 'someroot',
], ],
'smb::test@example.com//share//someroot/', 'webdav::test@example.com//someroot/',
0 0
], ],
// special case with $user vars, cannot auto-remove the oc_storages entry // special case with $user vars, cannot auto-remove the oc_storages entry
[ [
[ [
'share' => 'share',
'host' => 'example.com', 'host' => 'example.com',
'user' => '$user', 'user' => '$user',
'password' => 'testPassword', 'password' => 'testPassword',
'root' => 'someroot', 'root' => 'someroot',
], ],
'smb::someone@example.com//share//someroot/', 'webdav::someone@example.com//someroot/',
1 1
], ],
]; ];
@ -297,7 +296,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
* @dataProvider deleteStorageDataProvider * @dataProvider deleteStorageDataProvider
*/ */
public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) { public function testDeleteStorage($backendOptions, $rustyStorageId, $expectedCountAfterDeletion) {
$backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\SMB'); $backend = $this->backendService->getBackend('identifier:\OCA\Files_External\Lib\Backend\DAV');
$authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism'); $authMechanism = $this->backendService->getAuthMechanism('identifier:\Auth\Mechanism');
$storage = new StorageConfig(255); $storage = new StorageConfig(255);
$storage->setMountPoint('mountpoint'); $storage->setMountPoint('mountpoint');
@ -331,7 +330,8 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$storageCheckQuery = $qb->select('*') $storageCheckQuery = $qb->select('*')
->from('storages') ->from('storages')
->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId))); ->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId)));
$this->assertCount($expectedCountAfterDeletion, $storageCheckQuery->execute()->fetchAll()); $storages = $storageCheckQuery->execute()->fetchAll();
$this->assertCount($expectedCountAfterDeletion, $storages, "expected $expectedCountAfterDeletion storages, got " . json_encode($storages));
} }
/** /**