mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
allow saving/loading of kerberos tickets
This commit is contained in:
parent
f944fae8b1
commit
a103d9d79e
7 changed files with 186 additions and 89 deletions
|
|
@ -27,6 +27,17 @@ 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';
|
||||
}
|
||||
|
|
@ -39,11 +50,25 @@ class KerberosAuth implements IAuth {
|
|||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue