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/private_html/3rdparty/icewind/smb/src/KerberosAuth.php
<?php
/**
 * SPDX-FileCopyrightText: 2018 Robin Appelman <[email protected]>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace Icewind\SMB;

use Icewind\SMB\Exception\Exception;

/**
 * Use existing kerberos ticket to authenticate
 */
class KerberosAuth implements IAuth {
	/** @var ?KerberosTicket */
	protected $ticket = null;

	public function getTicket(): ?KerberosTicket {
		return $this->ticket;
	}

	public function setTicket(?KerberosTicket $ticket): void {
		$this->ticket = $ticket;
	}

	public function getUsername(): ?string {
		return 'dummy';
	}

	public function getWorkgroup(): ?string {
		return 'dummy';
	}

	public function getPassword(): ?string {
		return null;
	}

	private function setEnv():void {
		$ticket = $this->getTicket();
		if ($ticket) {
			$ticket->validate();

			// note that even if the ticket name is the value we got from `getenv("KRB5CCNAME")` we still need to set the env variable ourselves
			// this is because `getenv` also reads the variables passed from the SAPI (apache-php) and we need to set the variable in the OS's env
			putenv("KRB5CCNAME=" . $ticket->getCacheName());
		}
	}

	public function getExtraCommandLineArguments(): string {
		$this->setEnv();
		return '-k';
	}

	public function setExtraSmbClientOptions($smbClientState): void {
		$this->setEnv();

		$success = (bool)smbclient_option_set($smbClientState, SMBCLIENT_OPT_USE_KERBEROS, true);
		$success = $success && smbclient_option_set($smbClientState, SMBCLIENT_OPT_FALLBACK_AFTER_KERBEROS, false);

		if (!$success) {
			throw new Exception("Failed to set smbclient options for kerberos auth");
		}
	}
}