Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit c1ce4fb

Browse files
committed
only intialize kerberos apache auth when used
this allows checking if there is a valid ticket without throwing exceptions
1 parent 9132f32 commit c1ce4fb

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/KerberosApacheAuth.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,38 @@ class KerberosApacheAuth extends KerberosAuth implements IAuth {
3535
/** @var bool */
3636
private $saveTicketInMemory = false;
3737

38+
/** @var bool */
39+
private $init = false;
40+
3841
/**
3942
* @param bool $saveTicketInMemory
4043
*/
4144
public function __construct(bool $saveTicketInMemory = false) {
4245
$this->saveTicketInMemory = $saveTicketInMemory;
43-
$this->registerApacheKerberosTicket();
4446
}
4547

46-
private function registerApacheKerberosTicket(): void {
48+
/**
49+
* Check if a valid kerberos ticket is present
50+
*
51+
* @return bool
52+
*/
53+
public function checkTicket(): bool {
54+
//read apache kerberos ticket cache
55+
$cacheFile = getenv("KRB5CCNAME");
56+
if (!$cacheFile) {
57+
return false;
58+
}
59+
60+
$krb5 = new \KRB5CCache();
61+
$krb5->open($cacheFile);
62+
return (bool)$krb5->isValid();
63+
}
64+
65+
private function init(): void {
66+
if ($this->init) {
67+
return;
68+
}
69+
$this->init = true;
4770
// inspired by https://git.typo3.org/TYPO3CMS/Extensions/fal_cifs.git
4871

4972
if (!extension_loaded("krb5")) {
@@ -76,6 +99,15 @@ private function registerApacheKerberosTicket(): void {
7699
}
77100
}
78101

102+
public function getExtraCommandLineArguments(): string {
103+
$this->init();
104+
return parent::getExtraCommandLineArguments();
105+
}
106+
107+
public function setExtraSmbClientOptions($smbClientState): void {
108+
$this->init();
109+
parent::setExtraSmbClientOptions($smbClientState);
110+
}
79111

80112
public function __destruct() {
81113
if (!empty($this->ticketPath) && file_exists($this->ticketPath) && is_file($this->ticketPath)) {

0 commit comments

Comments
 (0)