|
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; |
|
9
|
|
|
|
|
10
|
|
|
use Icewind\SMB\Exception\Exception; |
|
11
|
|
|
|
|
12
|
|
|
class System implements ISystem { |
|
13
|
|
|
/** @var (string|bool)[] */ |
|
14
|
|
|
private $paths = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the path to a file descriptor of the current process |
|
18
|
|
|
* |
|
19
|
|
|
* @param int $num the file descriptor id |
|
20
|
|
|
* @return string |
|
21
|
|
|
* @throws Exception |
|
22
|
|
|
*/ |
|
23
|
780 |
|
public function getFD($num) { |
|
24
|
|
|
$folders = [ |
|
25
|
780 |
|
'/proc/self/fd', |
|
26
|
|
|
'/dev/fd' |
|
27
|
|
|
]; |
|
28
|
780 |
|
foreach ($folders as $folder) { |
|
29
|
780 |
|
if (file_exists($folder)) { |
|
30
|
780 |
|
return $folder . '/' . $num; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
throw new Exception('Cant find file descriptor path'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
783 |
|
public function getSmbclientPath() { |
|
37
|
783 |
|
return $this->getBinaryPath('smbclient'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
771 |
|
public function getNetPath() { |
|
41
|
771 |
|
return $this->getBinaryPath('net'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getSmbcAclsPath() { |
|
45
|
|
|
return $this->getBinaryPath('smbcacls'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
768 |
|
public function getStdBufPath() { |
|
49
|
768 |
|
return $this->getBinaryPath('stdbuf'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
771 |
|
public function getDatePath() { |
|
53
|
771 |
|
return $this->getBinaryPath('date'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
public function libSmbclientAvailable() { |
|
57
|
1 |
|
return function_exists('smbclient_state_new'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
783 |
|
protected function getBinaryPath($binary) { |
|
61
|
783 |
|
if (!isset($this->paths[$binary])) { |
|
62
|
783 |
|
$result = null; |
|
63
|
783 |
|
$output = []; |
|
64
|
783 |
|
exec("which $binary 2>&1", $output, $result); |
|
65
|
783 |
|
$this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : false; |
|
66
|
|
|
} |
|
67
|
783 |
|
return $this->paths[$binary]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|