HEX
Server: LiteSpeed
System: Linux d8 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: wbwebdes (3015)
PHP: 8.1.31
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/wbwebdes/domains/files.wb-cloud.nl/public_html/3rdparty/icewind/smb/src/System.php
<?php
/**
 * SPDX-FileCopyrightText: 2014 Robin Appelman <[email protected]>
 * SPDX-License-Identifier: MIT
 */

namespace Icewind\SMB;

use Icewind\SMB\Exception\Exception;

class System implements ISystem {
	/** @var (string|null)[] */
	private $paths = [];

	/**
	 * Get the path to a file descriptor of the current process
	 *
	 * @param int $num the file descriptor id
	 * @return string
	 * @throws Exception
	 */
	public function getFD(int $num): string {
		$folders = [
			'/proc/self/fd',
			'/dev/fd'
		];
		foreach ($folders as $folder) {
			if (file_exists($folder)) {
				return $folder . '/' . $num;
			}
		}
		throw new Exception('Cant find file descriptor path');
	}

	public function getSmbclientPath(): ?string {
		return $this->getBinaryPath('smbclient');
	}

	public function getNetPath(): ?string {
		return $this->getBinaryPath('net');
	}

	public function getSmbcAclsPath(): ?string {
		return $this->getBinaryPath('smbcacls');
	}

	public function getStdBufPath(): ?string {
		return $this->getBinaryPath('stdbuf');
	}

	public function getDatePath(): ?string {
		return $this->getBinaryPath('date');
	}

	public function libSmbclientAvailable(): bool {
		return function_exists('smbclient_state_new');
	}

	protected function getBinaryPath(string $binary): ?string {
		if (!isset($this->paths[$binary])) {
			$result = null;
			$output = [];
			exec("which $binary 2>&1", $output, $result);

			if ($result === 0 && isset($output[0])) {
				$this->paths[$binary] = (string)$output[0];
			} elseif (is_executable("/usr/bin/$binary")) {
				$this->paths[$binary] = "/usr/bin/$binary";
			} else {
				$this->paths[$binary] = null;
			}
		}
		return $this->paths[$binary];
	}
}