mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Update KerberosAuth.php
enable reuse of apache ticket cache
This commit is contained in:
parent
c714475bf1
commit
c0ae9aa35f
1 changed files with 46 additions and 0 deletions
|
|
@ -27,6 +27,16 @@ use Icewind\SMB\Exception\Exception;
|
||||||
* Use existing kerberos ticket to authenticate
|
* Use existing kerberos ticket to authenticate
|
||||||
*/
|
*/
|
||||||
class KerberosAuth implements IAuth {
|
class KerberosAuth implements IAuth {
|
||||||
|
|
||||||
|
private $ticketPath = "";
|
||||||
|
|
||||||
|
//not working with nextcloud
|
||||||
|
private $saveTicketInMemory = false;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->registerApacheKerberosTicket();
|
||||||
|
}
|
||||||
|
|
||||||
public function getUsername(): ?string {
|
public function getUsername(): ?string {
|
||||||
return 'dummy';
|
return 'dummy';
|
||||||
}
|
}
|
||||||
|
|
@ -51,4 +61,40 @@ class KerberosAuth implements IAuth {
|
||||||
throw new Exception("Failed to set smbclient options for kerberos auth");
|
throw new Exception("Failed to set smbclient options for kerberos auth");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function registerApacheKerberosTicket() {
|
||||||
|
// inspired by https://git.typo3.org/TYPO3CMS/Extensions/fal_cifs.git
|
||||||
|
|
||||||
|
if (!extension_loaded("krb5")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//read apache kerberos ticket cache
|
||||||
|
$cacheFile = getenv("KRB5CCNAME");
|
||||||
|
if(!$cacheFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$krb5 = new \KRB5CCache();
|
||||||
|
$krb5->open($cacheFile);
|
||||||
|
if(!$krb5->isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if($this->saveTicketInMemory) {
|
||||||
|
putenv("KRB5CCNAME=" . $krb5->getName());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//workaround: smbclient is not working with the original apache ticket cache.
|
||||||
|
$tmpFilename = tempnam("/tmp", "krb5cc_php_");
|
||||||
|
$tmpCacheFile = "FILE:" . $tmpFilename;
|
||||||
|
$krb5->save($tmpCacheFile);
|
||||||
|
$this->ticketPath = $tmpFilename;
|
||||||
|
putenv("KRB5CCNAME=" . $tmpCacheFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct() {
|
||||||
|
if(!empty($this->ticketPath) && file_exists($this->ticketPath) && is_file($this->ticketPath)) {
|
||||||
|
unlink($this->ticketPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue