| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (c) 2014 Robin Appelman <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is licensed under the Licensed under the MIT license: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * http://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace Icewind\SMB\Wrapped; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Icewind\SMB\AbstractShare; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Icewind\SMB\ACL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Icewind\SMB\Exception\ConnectionException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Icewind\SMB\Exception\DependencyException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Icewind\SMB\Exception\FileInUseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Icewind\SMB\Exception\InvalidTypeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Icewind\SMB\Exception\NotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Icewind\SMB\Exception\InvalidRequestException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Icewind\SMB\IFileInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Icewind\SMB\INotifyHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Icewind\SMB\IServer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Icewind\SMB\ISystem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Icewind\Streams\CallbackWrapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Icewind\SMB\Native\NativeShare; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Icewind\SMB\Native\NativeServer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class Share extends AbstractShare { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * @var IServer $server | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	private $server; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * @var string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	private $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * @var Connection $connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	public $connection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 * @var Parser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	protected $parser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * @var ISystem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	private $system; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	const MODE_MAP = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		FileInfo::MODE_READONLY => 'r', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		FileInfo::MODE_HIDDEN   => 'h', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		FileInfo::MODE_ARCHIVE  => 'a', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		FileInfo::MODE_SYSTEM   => 's' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	const EXEC_CMD = 'exec'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	 * @param IServer $server | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @param ISystem $system | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 771 |  | 	public function __construct(IServer $server, $name, ISystem $system) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 771 |  | 		parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 771 |  | 		$this->server = $server; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 771 |  | 		$this->name = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 771 |  | 		$this->system = $system; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 771 |  | 		$this->parser = new Parser($server->getTimeZone()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 771 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 768 |  | 	private function getAuthFileArgument() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 768 |  | 		if ($this->server->getAuth()->getUsername()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 768 |  | 			return '--authentication-file=' . $this->system->getFD(3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 768 |  | 	protected function getConnection() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 768 |  | 		$command = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 768 |  | 			'%s %s%s -t %s %s %s %s', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 768 |  | 			self::EXEC_CMD, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 768 |  | 			$this->system->getStdBufPath() ? $this->system->getStdBufPath() . ' -o0 ' : '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 768 |  | 			$this->system->getSmbclientPath(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 768 |  | 			$this->server->getOptions()->getTimeout(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 768 |  | 			$this->getAuthFileArgument(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 768 |  | 			$this->server->getAuth()->getExtraCommandLineArguments(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 768 |  | 			escapeshellarg('//' . $this->server->getHost() . '/' . $this->name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 768 |  | 		$connection = new Connection($command, $this->parser); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 768 |  | 		$connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 768 |  | 		$connection->connect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 768 |  | 		if (!$connection->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			throw new ConnectionException($connection->readLine()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		// some versions of smbclient add a help message in first of the first prompt | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 768 |  | 		$connection->clearTillPrompt(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 768 |  | 		return $connection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	 * @throws \Icewind\SMB\Exception\ConnectionException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	 * @throws \Icewind\SMB\Exception\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidHostException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 765 |  | 	protected function connect() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 765 |  | 		if ($this->connection and $this->connection->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 765 |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 765 |  | 		$this->connection = $this->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 765 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 3 |  | 	protected function reconnect() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 3 |  | 		$this->connection->reconnect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 3 |  | 		if (!$this->connection->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 			throw new ConnectionException(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 3 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	 * Get the name of the share | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 6 |  | 	public function getName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 6 |  | 		return $this->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 765 |  | 	protected function simpleCommand($command, $path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 765 |  | 		$escapedPath = $this->escapePath($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 765 |  | 		$cmd = $command . ' ' . $escapedPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 765 |  | 		$output = $this->execute($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 765 |  | 		return $this->parseOutput($output, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	 * List the content of a remote folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	 * @param $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	 * @return \Icewind\SMB\IFileInfo[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 753 |  | 	public function dir($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 753 |  | 		$escapedPath = $this->escapePath($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 753 |  | 		$output = $this->execute('cd ' . $escapedPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		//check output for errors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 753 |  | 		$this->parseOutput($output, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 753 |  | 		$output = $this->execute('dir'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 753 |  | 		$this->execute('cd /'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 753 |  | 		return $this->parser->parseDir($output, $path, function ($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 			return $this->getAcls($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 753 |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 	 * @return \Icewind\SMB\IFileInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 | 99 |  | 	public function stat($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		// some windows server setups don't seem to like the allinfo command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		// use the dir command instead to get the file info where possible | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 | 99 |  | 		if ($path !== "" && $path !== "/") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 | 96 |  | 			$parent = dirname($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 96 |  | 			$dir = $this->dir($parent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 96 |  | 			$file = array_values(array_filter($dir, function (IFileInfo $info) use ($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 93 |  | 				return $info->getPath() === $path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 | 96 |  | 			})); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 96 |  | 			if ($file) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 | 66 |  | 				return $file[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 33 |  | 		$escapedPath = $this->escapePath($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 6 |  | 		$output = $this->execute('allinfo ' . $escapedPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 		// Windows and non Windows Fileserver may respond different | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 		// to the allinfo command for directories. If the result is a single | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 		// line = error line, redo it with a different allinfo parameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 6 |  | 		if ($escapedPath == '""' && count($output) < 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 			$output = $this->execute('allinfo ' . '"."'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 | 6 |  | 		if (count($output) < 3) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 | 3 |  | 			$this->parseOutput($output, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 3 |  | 		$stat = $this->parser->parseStat($output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 3 |  | 		return new FileInfo($path, basename($path), $stat['size'], $stat['mtime'], $stat['mode'], function () use ($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 			return $this->getAcls($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 | 3 |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 	 * Create a folder on the share | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 	 * @throws \Icewind\SMB\Exception\AlreadyExistsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 | 756 |  | 	public function mkdir($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 | 756 |  | 		return $this->simpleCommand('mkdir', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 	 * Remove a folder on the share | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 | 756 |  | 	public function rmdir($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 756 |  | 		return $this->simpleCommand('rmdir', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 	 * Delete a file on the share | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 	 * @param bool $secondTry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 	 * @throws InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 	 * @throws NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 	 * @throws \Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 | 393 |  | 	public function del($path, $secondTry = false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 		//del return a file not found error when trying to delete a folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 		//we catch it so we can check if $path doesn't exist or is of invalid type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 393 |  | 			return $this->simpleCommand('del', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 36 |  | 		} catch (NotFoundException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 			//no need to do anything with the result, we just check if this throws the not found error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 			try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 6 |  | 				$this->simpleCommand('ls', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 | 6 |  | 			} catch (NotFoundException $e2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 | 3 |  | 				throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 | 3 |  | 			} catch (\Exception $e2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 | 3 |  | 				throw new InvalidTypeException($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 | 30 |  | 		} catch (FileInUseException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 | 3 |  | 			if ($secondTry) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 				throw $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 | 3 |  | 			$this->reconnect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 | 3 |  | 			return $this->del($path, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 	 * Rename a remote file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 	 * @param string $from | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 	 * @param string $to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 	 * @throws \Icewind\SMB\Exception\AlreadyExistsException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 266 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 267 | 90 |  | 	public function rename($from, $to) { | 
            
                                                                        
                            
            
                                    
            
            
                | 268 | 90 |  | 		$path1 = $this->escapePath($from); | 
            
                                                                        
                            
            
                                    
            
            
                | 269 | 63 |  | 		$path2 = $this->escapePath($to); | 
            
                                                                        
                            
            
                                    
            
            
                | 270 | 63 |  | 		$output = $this->execute('rename ' . $path1 . ' ' . $path2); | 
            
                                                                        
                            
            
                                    
            
            
                | 271 | 63 |  | 		return $this->parseOutput($output, $to); | 
            
                                                                        
                            
            
                                    
            
            
                | 272 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 	 * Upload a local file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 	 * @param string $source local file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 	 * @param string $target remove file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 | 345 |  | 	public function put($source, $target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 | 345 |  | 		$path1 = $this->escapeLocalPath($source); //first path is local, needs different escaping | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 | 345 |  | 		$path2 = $this->escapePath($target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 | 318 |  | 		$output = $this->execute('put ' . $path1 . ' ' . $path2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 | 318 |  | 		return $this->parseOutput($output, $target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  | 	 * Download a remote file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 	 * @param string $source remove file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | 	 * @param string $target local file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 | 132 |  | 	public function get($source, $target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 | 132 |  | 		$path1 = $this->escapePath($source); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 | 105 |  | 		$path2 = $this->escapeLocalPath($target); //second path is local, needs different escaping | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 | 105 |  | 		$output = $this->execute('get ' . $path1 . ' ' . $path2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 | 105 |  | 		return $this->parseOutput($output, $source); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 	 * Open a readable stream to a remote file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  | 	 * @param string $source | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  | 	 * @return resource a read only stream with the contents of the remote file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 | 75 |  | 	public function read($source) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 | 75 |  | 		$source = $this->escapePath($source); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  | 		// since returned stream is closed by the caller we need to create a new instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | 		// since we can't re-use the same file descriptor over multiple calls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 | 48 |  | 		$connection = $this->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 | 48 |  | 		$connection->write('get ' . $source . ' ' . $this->system->getFD(5)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 | 48 |  | 		$connection->write('exit'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 | 48 |  | 		$fh = $connection->getFileOutputStream(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 | 48 |  | 		stream_context_set_option($fh, 'file', 'connection', $connection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 | 48 |  | 		return $fh; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  | 	 * Open a writable stream to a remote file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  | 	 * @param string $target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  | 	 * @return resource a write only stream to upload a remote file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | 	 * @throws \Icewind\SMB\Exception\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 | 75 |  | 	public function write($target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 | 75 |  | 		$target = $this->escapePath($target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 		// since returned stream is closed by the caller we need to create a new instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | 		// since we can't re-use the same file descriptor over multiple calls | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 | 48 |  | 		$connection = $this->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 | 48 |  | 		$fh = $connection->getFileInputStream(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 | 48 |  | 		$connection->write('put ' . $this->system->getFD(4) . ' ' . $target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 | 48 |  | 		$connection->write('exit'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  | 		// use a close callback to ensure the upload is finished before continuing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  | 		// this also serves as a way to keep the connection in scope | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 | 48 |  | 		return CallbackWrapper::wrap($fh, null, null, function () use ($connection, $target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 | 48 |  | 			$connection->close(false); // dont terminate, give the upload some time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 | 48 |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  | 	 * Append to stream | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  | 	 * Note: smbclient does not support this (Use php-libsmbclient) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  | 	 * @param string $target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  | 	 * @throws \Icewind\SMB\Exception\DependencyException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 | 3 |  | 	public function append($target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 | 3 |  | 		throw new DependencyException('php-libsmbclient is required for append'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  | 	 * @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  | 	 * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 | 24 |  | 	public function setMode($path, $mode) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 | 24 |  | 		$modeString = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 | 24 |  | 		foreach (self::MODE_MAP as $modeByte => $string) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 | 24 |  | 			if ($mode & $modeByte) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 | 24 |  | 				$modeString .= $string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 | 24 |  | 		$path = $this->escapePath($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  | 		// first reset the mode to normal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 | 24 |  | 		$cmd = 'setmode ' . $path . ' -rsha'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 | 24 |  | 		$output = $this->execute($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 | 24 |  | 		$this->parseOutput($output, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 | 24 |  | 		if ($mode !== FileInfo::MODE_NORMAL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  | 			// then set the modes we want | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 | 24 |  | 			$cmd = 'setmode ' . $path . ' ' . $modeString; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 | 24 |  | 			$output = $this->execute($cmd); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 | 24 |  | 			return $this->parseOutput($output, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 | 24 |  | 			return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  | 	 * @return INotifyHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  | 	 * @throws ConnectionException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  | 	 * @throws DependencyException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 | 15 |  | 	public function notify($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 | 15 |  | 		if (!$this->system->getStdBufPath()) { //stdbuf is required to disable smbclient's output buffering | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  | 			throw new DependencyException('stdbuf is required for usage of the notify command'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 | 15 |  | 		$connection = $this->getConnection(); // use a fresh connection since the notify command blocks the process | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 | 15 |  | 		$command = 'notify ' . $this->escapePath($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 | 15 |  | 		$connection->write($command . PHP_EOL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 | 15 |  | 		return new NotifyHandler($connection, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  | 	 * @param string $command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 | 765 |  | 	protected function execute($command) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 | 765 |  | 		$this->connect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 | 765 |  | 		$this->connection->write($command . PHP_EOL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 | 765 |  | 		return $this->connection->read(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  | 	 * check output for errors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  | 	 * @param string[] $lines | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  | 	 * @throws \Icewind\SMB\Exception\AlreadyExistsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  | 	 * @throws \Icewind\SMB\Exception\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  | 	 * @throws \Icewind\SMB\Exception\NotEmptyException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  | 	 * @throws \Icewind\SMB\Exception\InvalidTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  | 	 * @throws \Icewind\SMB\Exception\Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  | 	 * @throws NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 | 765 |  | 	protected function parseOutput($lines, $path = '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 | 765 |  | 		if (count($lines) === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 | 765 |  | 			return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 | 60 |  | 			$this->parser->checkForError($lines, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  | 	 * @param string $string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  | 	protected function escape($string) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  | 		return escapeshellarg($string); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 | 768 |  | 	protected function escapePath($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 | 768 |  | 		$this->verifyPath($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 | 768 |  | 		if ($path === '/') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 | 3 |  | 			$path = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 | 768 |  | 		$path = str_replace('/', '\\', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 | 768 |  | 		$path = str_replace('"', '^"', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 | 768 |  | 		$path = ltrim($path, '\\'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 | 768 |  | 		return '"' . $path . '"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 | 399 |  | 	protected function escapeLocalPath($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 | 399 |  | 		$path = str_replace('"', '\"', $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 | 399 |  | 		return '"' . $path . '"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  | 	protected function getAcls($path) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  | 		$commandPath = $this->system->getSmbcAclsPath(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  | 		if (!$commandPath) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  | 			return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  | 		$command = sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  | 			'%s %s %s %s/%s %s', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  | 			$commandPath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  | 			$this->getAuthFileArgument(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  | 			$this->server->getAuth()->getExtraCommandLineArguments(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  | 			escapeshellarg('//' . $this->server->getHost()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  | 			escapeshellarg($this->name), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  | 			escapeshellarg($path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  | 		$connection = new RawConnection($command); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  | 		$connection->writeAuthentication($this->server->getAuth()->getUsername(), $this->server->getAuth()->getPassword()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  | 		$connection->connect(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  | 		if (!$connection->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  | 			throw new ConnectionException($connection->readLine()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  | 		$rawAcls = $connection->readAll(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  | 		var_dump($rawAcls); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  | 		$acls = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  | 		foreach ($rawAcls as $acl) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  | 			[$type, $acl] = explode(':', $acl, 2); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  | 			if ($type !== 'ACL') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  | 				continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  | 			[$user, $permissions] = explode(':', $acl, 2); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  | 			[$type, $flags, $mask] = explode('/', $permissions); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  | 			$type = $type === 'ALLOWED' ? ACL::TYPE_ALLOW : ACL::TYPE_DENY; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  | 			$flagsInt = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  | 			foreach (explode('|', $flags) as $flagString) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  | 				if ($flagString === 'OI') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  | 					$flagsInt += ACL::FLAG_OBJECT_INHERIT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  | 				} elseif ($flagString === 'CI') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  | 					$flagsInt += ACL::FLAG_CONTAINER_INHERIT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  | 			if (substr($mask, 0, 2) === '0x') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  | 				$maskInt = hexdec($mask); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  | 				$maskInt = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  | 				foreach (explode('|', $mask) as $maskString) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  | 					if ($maskString === 'R') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  | 						$maskInt += ACL::MASK_READ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  | 					} elseif ($maskString === 'W') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  | 						$maskInt += ACL::MASK_WRITE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  | 					} elseif ($maskString === 'X') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  | 						$maskInt += ACL::MASK_EXECUTE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  | 					} elseif ($maskString === 'D') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  | 						$maskInt += ACL::MASK_DELETE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  | 					} elseif ($maskString === 'READ') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  | 						$maskInt += ACL::MASK_READ + ACL::MASK_EXECUTE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  | 					} elseif ($maskString === 'CHANGE') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  | 						$maskInt += ACL::MASK_READ + ACL::MASK_EXECUTE + ACL::MASK_WRITE + ACL::MASK_DELETE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  | 					} elseif ($maskString === 'FULL') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  | 						$maskInt += ACL::MASK_READ + ACL::MASK_EXECUTE + ACL::MASK_WRITE + ACL::MASK_DELETE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  | 			if (isset($acls[$user])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  | 				$existing = $acls[$user]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  | 				$maskInt += $existing->getMask(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  | 			$acls[$user] = new ACL($type, $flagsInt, $maskInt); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  | 		return $acls; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 | 771 |  | 	public function __destruct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 | 771 |  | 		unset($this->connection); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 | 771 |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 559 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 560 |  |  |  | 
            
                        
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: