mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
fix support for smbclient compiled without readline support
This commit is contained in:
parent
9f6b8f1c3f
commit
a8dc9ca75b
6 changed files with 60 additions and 43 deletions
|
|
@ -47,7 +47,7 @@ class Connection extends RawConnection {
|
|||
public function clearTillPrompt(): void {
|
||||
$this->write('');
|
||||
do {
|
||||
$promptLine = $this->readLine();
|
||||
$promptLine = $this->readTillPrompt();
|
||||
if ($promptLine === false) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -56,13 +56,12 @@ class Connection extends RawConnection {
|
|||
if ($this->write('') === false) {
|
||||
throw new ConnectionRefusedException();
|
||||
}
|
||||
$this->readLine();
|
||||
$this->readTillPrompt();
|
||||
}
|
||||
|
||||
/**
|
||||
* get all unprocessed output from smbclient until the next prompt
|
||||
*
|
||||
* @param (callable(string):bool)|null $callback (optional) callback to call for every line read
|
||||
* @return string[]
|
||||
* @throws AuthenticationException
|
||||
* @throws ConnectException
|
||||
|
|
@ -71,42 +70,22 @@ class Connection extends RawConnection {
|
|||
* @throws NoLoginServerException
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
public function read(callable $callback = null): array {
|
||||
public function read(): array {
|
||||
if (!$this->isValid()) {
|
||||
throw new ConnectionException('Connection not valid');
|
||||
}
|
||||
$promptLine = $this->readLine(); //first line is prompt
|
||||
if ($promptLine === false) {
|
||||
$this->unknownError($promptLine);
|
||||
}
|
||||
$this->parser->checkConnectionError($promptLine);
|
||||
|
||||
$output = [];
|
||||
if (!$this->isPrompt($promptLine)) {
|
||||
$line = $promptLine;
|
||||
} else {
|
||||
$line = $this->readLine();
|
||||
}
|
||||
if ($line === false) {
|
||||
$this->unknownError($promptLine);
|
||||
}
|
||||
while ($line !== false && !$this->isPrompt($line)) { //next prompt functions as delimiter
|
||||
if (is_callable($callback)) {
|
||||
$result = $callback($line);
|
||||
if ($result === false) { // allow the callback to close the connection for infinite running commands
|
||||
$this->close(true);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$output[] = $line;
|
||||
}
|
||||
$line = $this->readLine();
|
||||
$output = $this->readTillPrompt();
|
||||
if ($output === false) {
|
||||
$this->unknownError(false);
|
||||
}
|
||||
$output = explode("\n", $output);
|
||||
// last line contains the prompt
|
||||
array_pop($output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function isPrompt(string $line): bool {
|
||||
return mb_substr($line, 0, self::DELIMITER_LENGTH) === self::DELIMITER;
|
||||
return substr($line, 0, self::DELIMITER_LENGTH) === self::DELIMITER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue