mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
improve support for workgroups/domains
This commit is contained in:
parent
25a76128d5
commit
33ab10cc4d
4 changed files with 43 additions and 19 deletions
|
|
@ -29,6 +29,11 @@ class Server {
|
|||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @var string $workgroup
|
||||
*/
|
||||
protected $workgroup;
|
||||
|
||||
/**
|
||||
* Check if the smbclient php extension is available
|
||||
*
|
||||
|
|
@ -45,10 +50,28 @@ class Server {
|
|||
*/
|
||||
public function __construct($host, $user, $password) {
|
||||
$this->host = $host;
|
||||
list($workgroup, $user) = $this->splitUser($user);
|
||||
$this->user = $user;
|
||||
$this->workgroup = $workgroup;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 [null, $user];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -77,6 +100,13 @@ class Server {
|
|||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWorkgroup() {
|
||||
return $this->workgroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Icewind\SMB\IShare[]
|
||||
*
|
||||
|
|
@ -84,7 +114,8 @@ class Server {
|
|||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function listShares() {
|
||||
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
|
||||
$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
|
||||
$command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' .
|
||||
' -gL ' . escapeshellarg($this->getHost());
|
||||
$connection = new RawConnection($command);
|
||||
$connection->writeAuthentication($this->getUser(), $this->getPassword());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue