From 98074eff7f784e99ecf2adc834cdac1ae2a2bee8 Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Sun, 23 Aug 2015 18:27:27 +0200 Subject: [PATCH] RawConnection.php: add workgroup to auth file --- src/RawConnection.php | 18 ++++++++++++------ src/Server.php | 2 +- src/Share.php | 8 ++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/RawConnection.php b/src/RawConnection.php index 1547851..e87a340 100644 --- a/src/RawConnection.php +++ b/src/RawConnection.php @@ -131,12 +131,18 @@ class RawConnection { 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; } diff --git a/src/Server.php b/src/Server.php index bbc0475..832c589 100644 --- a/src/Server.php +++ b/src/Server.php @@ -118,7 +118,7 @@ class Server { $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]; diff --git a/src/Share.php b/src/Share.php index d9ab729..c77ce3f 100644 --- a/src/Share.php +++ b/src/Share.php @@ -61,7 +61,7 @@ class Share extends AbstractShare { 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(); } @@ -69,7 +69,7 @@ class Share extends AbstractShare { 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(); } @@ -263,7 +263,7 @@ class Share extends AbstractShare { 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(); @@ -291,7 +291,7 @@ class Share extends AbstractShare { 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);