Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/RawConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,18 @@ public function getFileOutputStream() {
return $this->pipes[5];
}

public function writeAuthentication($user, $password) {
$auth = ($password === false)
? "username=$user"
: "username=$user\npassword=$password";

if (fwrite($this->getAuthStream(), $auth) === false) {
public function writeAuthentication($workgroup, $user, $password) {
$auth = array();
if (is_string($workgroup)) {
$auth[] = "domain=$workgroup";
}
if (is_string($user)) {
$auth[] = "username=$user";
}
if (is_string($password)) {
$auth[] = "password=$password";
}
if (fwrite($this->getAuthStream(), implode("\n", $auth)) === false) {
fclose($this->getAuthStream());
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function listShares() {
$command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' .
' -gL ' . escapeshellarg($this->getHost());
$connection = new RawConnection($command);
$connection->writeAuthentication($this->getUser(), $this->getPassword());
$connection->writeAuthentication($this->getWorkgroup(), $this->getUser(), $this->getPassword());
$output = $connection->readAll();

$line = $output[0];
Expand Down
8 changes: 4 additions & 4 deletions src/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ protected function connect() {
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
);
$this->connection = new Connection($command);
$this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
$this->connection->writeAuthentication($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword());
if (!$this->connection->isValid()) {
throw new ConnectionException();
}
}

protected function reconnect() {
$this->connection->reconnect();
$this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
$this->connection->writeAuthentication($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword());
if (!$this->connection->isValid()) {
throw new ConnectionException();
}
Expand Down Expand Up @@ -263,7 +263,7 @@ public function read($source) {
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
);
$connection = new Connection($command);
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
$connection->writeAuthentication($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword());
$connection->write('get ' . $source . ' /proc/self/fd/5');
$connection->write('exit');
$fh = $connection->getFileOutputStream();
Expand Down Expand Up @@ -291,7 +291,7 @@ public function write($target) {
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
);
$connection = new Connection($command);
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
$connection->writeAuthentication($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword());
$fh = $connection->getFileInputStream();

$connection->write('put /proc/self/fd/4 ' . $target);
Expand Down