2015-08-17 17:31:29 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Licensed under the MIT license:
|
|
|
|
* http://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Icewind\SMB;
|
|
|
|
|
|
|
|
use Icewind\SMB\Exception\InvalidPathException;
|
|
|
|
|
|
|
|
abstract class AbstractShare implements IShare {
|
2021-03-10 17:31:09 +03:00
|
|
|
/** @var string[] */
|
2015-08-17 17:31:29 +03:00
|
|
|
private $forbiddenCharacters;
|
|
|
|
|
|
|
|
public function __construct() {
|
2019-02-06 17:36:06 +03:00
|
|
|
$this->forbiddenCharacters = ['?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"];
|
2015-08-17 17:31:29 +03:00
|
|
|
}
|
|
|
|
|
2021-03-10 17:31:09 +03:00
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @throws InvalidPathException
|
|
|
|
*/
|
|
|
|
protected function verifyPath(string $path): void {
|
2015-08-17 17:31:29 +03:00
|
|
|
foreach ($this->forbiddenCharacters as $char) {
|
|
|
|
if (strpos($path, $char) !== false) {
|
|
|
|
throw new InvalidPathException('Invalid path, "' . $char . '" is not allowed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-19 18:22:36 +03:00
|
|
|
|
2021-03-10 17:31:09 +03:00
|
|
|
/**
|
|
|
|
* @param string[] $charList
|
|
|
|
*/
|
|
|
|
public function setForbiddenChars(array $charList): void {
|
2018-01-19 18:22:36 +03:00
|
|
|
$this->forbiddenCharacters = $charList;
|
|
|
|
}
|
2015-08-17 17:31:29 +03:00
|
|
|
}
|