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
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public function read() {
|
||||
if (!$this->isValid()) {
|
||||
throw new ConnectionError();
|
||||
}
|
||||
$line = parent::read(); //first line is prompt
|
||||
$line = $this->readLine(); //first line is prompt
|
||||
$this->checkConnectionError($line);
|
||||
|
||||
$output = array();
|
||||
$line = parent::read();
|
||||
$line = $this->readLine();
|
||||
$length = strlen(self::DELIMITER);
|
||||
while (substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
||||
$output[] .= $line;
|
||||
|
|
@ -43,6 +43,15 @@ class Connection extends RawConnection {
|
|||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class RawConnection {
|
|||
/**
|
||||
* read a line of output
|
||||
*
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public function read() {
|
||||
return trim(fgets($this->pipes[1]));
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ class Server {
|
|||
|
||||
/**
|
||||
* @return Share[]
|
||||
* @throws \SMB\AuthenticationException
|
||||
* @throws \SMB\InvalidHostException
|
||||
*/
|
||||
public function listShares() {
|
||||
$user = escapeshellarg($this->getUser());
|
||||
|
|
@ -88,6 +90,11 @@ class Server {
|
|||
|
||||
$line = $output[0];
|
||||
|
||||
// disregard password prompt
|
||||
if (substr($line, 0, 6) == 'Enter ' and count($output) > 1) {
|
||||
$line = $output[1];
|
||||
}
|
||||
|
||||
$line = rtrim($line, ')');
|
||||
if (substr($line, -23) === ErrorCodes::LogonFailure) {
|
||||
throw new AuthenticationException();
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class Share {
|
|||
' //' . $this->server->getHost() . '/' . $this->name;
|
||||
$this->connection = new Connection($command);
|
||||
$this->connection->write($this->server->getPassword());
|
||||
$this->connection->readLine(); // discard password prompt
|
||||
if (!$this->connection->isValid()) {
|
||||
throw new ConnectionError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,6 @@ class Server extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
public function testGetTimeZone() {
|
||||
$timeZone = $this->server->getTimeZone();
|
||||
$this->assertEquals('+0200', $timeZone);
|
||||
$this->assertEquals('+0100', $timeZone);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue