Skip to content

Commit

Permalink
only intialize kerberos apache auth when used
Browse files Browse the repository at this point in the history
this allows checking if there is a valid ticket without throwing exceptions
  • Loading branch information
icewind1991 committed Nov 4, 2021
1 parent 9132f32 commit c1ce4fb
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/KerberosApacheAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,38 @@ class KerberosApacheAuth extends KerberosAuth implements IAuth {
/** @var bool */
private $saveTicketInMemory = false;

/** @var bool */
private $init = false;

/**
* @param bool $saveTicketInMemory
*/
public function __construct(bool $saveTicketInMemory = false) {
$this->saveTicketInMemory = $saveTicketInMemory;
$this->registerApacheKerberosTicket();
}

private function registerApacheKerberosTicket(): void {
/**
* Check if a valid kerberos ticket is present
*
* @return bool
*/
public function checkTicket(): bool {
//read apache kerberos ticket cache
$cacheFile = getenv("KRB5CCNAME");
if (!$cacheFile) {
return false;
}

$krb5 = new \KRB5CCache();
$krb5->open($cacheFile);
return (bool)$krb5->isValid();
}

private function init(): void {
if ($this->init) {
return;
}
$this->init = true;
// inspired by https://git.typo3.org/TYPO3CMS/Extensions/fal_cifs.git

if (!extension_loaded("krb5")) {
Expand Down Expand Up @@ -76,6 +99,15 @@ private function registerApacheKerberosTicket(): void {
}
}

public function getExtraCommandLineArguments(): string {
$this->init();
return parent::getExtraCommandLineArguments();
}

public function setExtraSmbClientOptions($smbClientState): void {
$this->init();
parent::setExtraSmbClientOptions($smbClientState);
}

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

0 comments on commit c1ce4fb

Please sign in to comment.