Improve locating file descriptors and smbclient/net commands

This commit is contained in:
Robin Appelman 2015-12-31 20:38:39 +01:00
commit b865f430d6
5 changed files with 100 additions and 18 deletions

View file

@ -11,7 +11,6 @@ use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\InvalidHostException;
class Server {
const CLIENT = 'smbclient';
const LOCALE = 'en_US.UTF-8';
/**
@ -34,6 +33,16 @@ class Server {
*/
protected $workgroup;
/**
* @var \Icewind\SMB\System
*/
private $system;
/**
* @var TimeZoneProvider
*/
private $timezoneProvider;
/**
* Check if the smbclient php extension is available
*
@ -54,6 +63,8 @@ class Server {
$this->user = $user;
$this->workgroup = $workgroup;
$this->password = $password;
$this->system = new System();
$this->timezoneProvider = new TimeZoneProvider($host, $this->system);
}
/**
@ -115,8 +126,12 @@ class Server {
*/
public function listShares() {
$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
$command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' .
' -gL ' . escapeshellarg($this->getHost());
$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());
$output = $connection->readAll();
@ -166,7 +181,6 @@ class Server {
* @return string
*/
public function getTimeZone() {
$command = 'net time zone -S ' . escapeshellarg($this->getHost());
return exec($command);
return $this->timezoneProvider->get();
}
}