mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
use authentication files
This commit is contained in:
parent
1a3640e25b
commit
d18b9db9c0
3 changed files with 28 additions and 21 deletions
|
|
@ -22,19 +22,21 @@ class RawConnection {
|
|||
*/
|
||||
private $process;
|
||||
|
||||
|
||||
public function __construct($command, $env = array()) {
|
||||
$descriptorSpec = array(
|
||||
0 => array("pipe", "r"),
|
||||
1 => array("pipe", "w"),
|
||||
2 => array('file', '/dev/null', 'w')
|
||||
0 => array('pipe', 'r'), // child reads from stdin
|
||||
1 => array('pipe', 'w'), // child writes to stdout
|
||||
2 => array('pipe', 'w'), // child writes to stderr
|
||||
3 => array('pipe', 'r'), // child reads from fd#3
|
||||
4 => array('pipe', 'r'), // child reads from fd#4
|
||||
5 => array('pipe', 'w') // child writes to fd#5
|
||||
);
|
||||
setlocale(LC_ALL, Server::LOCALE);
|
||||
$env = array_merge($env, array(
|
||||
'CLI_FORCE_INTERACTIVE' => 'y', // Needed or the prompt isn't displayed!!
|
||||
'LC_ALL' => Server::LOCALE
|
||||
));
|
||||
$this->process = proc_open($command, $descriptorSpec, $this->pipes, null, $env);
|
||||
$this->process = proc_open($command, $descriptorSpec, $this->pipes, '/', $env);
|
||||
if (!$this->isValid()) {
|
||||
throw new ConnectionError();
|
||||
}
|
||||
|
|
@ -94,6 +96,19 @@ class RawConnection {
|
|||
return $this->pipes[0];
|
||||
}
|
||||
|
||||
public function writeAuthentication($user, $password) {
|
||||
$auth = ($password === false)
|
||||
? "username=$user"
|
||||
: "username=$user\npassword=$password";
|
||||
|
||||
if (fwrite($this->pipes[3], $auth) === false) {
|
||||
fclose($this->pipes[3]);
|
||||
return false;
|
||||
}
|
||||
fclose($this->pipes[3]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
proc_terminate($this->process);
|
||||
proc_close($this->process);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue