mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Discard password prompts from smbclient's output
This commit is contained in:
parent
f8bc64f097
commit
bb92259b32
5 changed files with 23 additions and 6 deletions
|
|
@ -21,20 +21,20 @@ class Connection extends RawConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get all unprocessed output from smbclient untill the next prompt
|
* get all unprocessed output from smbclient until the next prompt
|
||||||
*
|
*
|
||||||
* @throws ConnectionError
|
* @throws ConnectionError
|
||||||
* @return array
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function read() {
|
public function read() {
|
||||||
if (!$this->isValid()) {
|
if (!$this->isValid()) {
|
||||||
throw new ConnectionError();
|
throw new ConnectionError();
|
||||||
}
|
}
|
||||||
$line = parent::read(); //first line is prompt
|
$line = $this->readLine(); //first line is prompt
|
||||||
$this->checkConnectionError($line);
|
$this->checkConnectionError($line);
|
||||||
|
|
||||||
$output = array();
|
$output = array();
|
||||||
$line = parent::read();
|
$line = $this->readLine();
|
||||||
$length = strlen(self::DELIMITER);
|
$length = strlen(self::DELIMITER);
|
||||||
while (substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
while (substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
||||||
$output[] .= $line;
|
$output[] .= $line;
|
||||||
|
|
@ -43,6 +43,15 @@ class Connection extends RawConnection {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read a single line of unprocessed output
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function readLine() {
|
||||||
|
return parent::read();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the first line holds a connection failure
|
* check if the first line holds a connection failure
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class RawConnection {
|
||||||
/**
|
/**
|
||||||
* read a line of output
|
* read a line of output
|
||||||
*
|
*
|
||||||
* @return array
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function read() {
|
public function read() {
|
||||||
return trim(fgets($this->pipes[1]));
|
return trim(fgets($this->pipes[1]));
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,8 @@ class Server {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Share[]
|
* @return Share[]
|
||||||
|
* @throws \SMB\AuthenticationException
|
||||||
|
* @throws \SMB\InvalidHostException
|
||||||
*/
|
*/
|
||||||
public function listShares() {
|
public function listShares() {
|
||||||
$user = escapeshellarg($this->getUser());
|
$user = escapeshellarg($this->getUser());
|
||||||
|
|
@ -88,6 +90,11 @@ class Server {
|
||||||
|
|
||||||
$line = $output[0];
|
$line = $output[0];
|
||||||
|
|
||||||
|
// disregard password prompt
|
||||||
|
if (substr($line, 0, 6) == 'Enter ' and count($output) > 1) {
|
||||||
|
$line = $output[1];
|
||||||
|
}
|
||||||
|
|
||||||
$line = rtrim($line, ')');
|
$line = rtrim($line, ')');
|
||||||
if (substr($line, -23) === ErrorCodes::LogonFailure) {
|
if (substr($line, -23) === ErrorCodes::LogonFailure) {
|
||||||
throw new AuthenticationException();
|
throw new AuthenticationException();
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ class Share {
|
||||||
' //' . $this->server->getHost() . '/' . $this->name;
|
' //' . $this->server->getHost() . '/' . $this->name;
|
||||||
$this->connection = new Connection($command);
|
$this->connection = new Connection($command);
|
||||||
$this->connection->write($this->server->getPassword());
|
$this->connection->write($this->server->getPassword());
|
||||||
|
$this->connection->readLine(); // discard password prompt
|
||||||
if (!$this->connection->isValid()) {
|
if (!$this->connection->isValid()) {
|
||||||
throw new ConnectionError();
|
throw new ConnectionError();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,6 @@ class Server extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
public function testGetTimeZone() {
|
public function testGetTimeZone() {
|
||||||
$timeZone = $this->server->getTimeZone();
|
$timeZone = $this->server->getTimeZone();
|
||||||
$this->assertEquals('+0200', $timeZone);
|
$this->assertEquals('+0100', $timeZone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue