mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
escape host name
This commit is contained in:
parent
c36739bdc5
commit
6e1f693ad5
3 changed files with 26 additions and 9 deletions
|
|
@ -58,11 +58,10 @@ class Share implements IShare {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
||||||
$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 //%s/%s',
|
$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 %s',
|
||||||
Server::CLIENT,
|
Server::CLIENT,
|
||||||
$workgroupArgument,
|
$workgroupArgument,
|
||||||
$this->server->getHost(),
|
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
|
||||||
$this->name
|
|
||||||
);
|
);
|
||||||
$this->connection = new Connection($command);
|
$this->connection = new Connection($command);
|
||||||
$this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
$this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
||||||
|
|
@ -261,11 +260,10 @@ class Share implements IShare {
|
||||||
// since returned stream is closed by the caller we need to create a new instance
|
// since returned stream is closed by the caller we need to create a new instance
|
||||||
// since we can't re-use the same file descriptor over multiple calls
|
// since we can't re-use the same file descriptor over multiple calls
|
||||||
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
||||||
$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 //%s/%s',
|
$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 %s',
|
||||||
Server::CLIENT,
|
Server::CLIENT,
|
||||||
$workgroupArgument,
|
$workgroupArgument,
|
||||||
$this->server->getHost(),
|
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
|
||||||
$this->name
|
|
||||||
);
|
);
|
||||||
$connection = new Connection($command);
|
$connection = new Connection($command);
|
||||||
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
||||||
|
|
@ -290,11 +288,10 @@ class Share implements IShare {
|
||||||
// since returned stream is closed by the caller we need to create a new instance
|
// since returned stream is closed by the caller we need to create a new instance
|
||||||
// since we can't re-use the same file descriptor over multiple calls
|
// since we can't re-use the same file descriptor over multiple calls
|
||||||
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
||||||
$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 //%s/%s',
|
$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 %s',
|
||||||
Server::CLIENT,
|
Server::CLIENT,
|
||||||
$workgroupArgument,
|
$workgroupArgument,
|
||||||
$this->server->getHost(),
|
escapeshellarg('//' . $this->server->getHost() . '/' . $this->name)
|
||||||
$this->name
|
|
||||||
);
|
);
|
||||||
$connection = new Connection($command);
|
$connection = new Connection($command);
|
||||||
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
||||||
|
|
|
||||||
|
|
@ -55,4 +55,13 @@ class Server extends TestCase {
|
||||||
$server = new \Icewind\SMB\Server(uniqid(), $this->config->user, $this->config->password);
|
$server = new \Icewind\SMB\Server(uniqid(), $this->config->user, $this->config->password);
|
||||||
$server->listShares();
|
$server->listShares();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Icewind\SMB\Exception\InvalidHostException
|
||||||
|
*/
|
||||||
|
public function testHostEscape() {
|
||||||
|
$server = new \Icewind\SMB\Server($this->config->host . ';asd', $this->config->user, $this->config->password);
|
||||||
|
$server->listShares();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,15 @@ class Share extends AbstractShare {
|
||||||
}
|
}
|
||||||
$this->share->mkdir($this->root);
|
$this->share->mkdir($this->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Icewind\SMB\Exception\InvalidHostException
|
||||||
|
*/
|
||||||
|
public function testHostEscape() {
|
||||||
|
$this->requireBackendEnv('smbclient');
|
||||||
|
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||||
|
$this->server = new NormalServer($this->config->host . ';asd', $this->config->user, $this->config->password);
|
||||||
|
$share = $this->server->getShare($this->config->share);
|
||||||
|
$share->dir($this->root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue