},
"require": {
"icewind/streams": "0.7.4",
- "icewind/smb": "3.5.1"
+ "icewind/smb": "3.5.2"
}
}
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "ed821b15824934fd2d245faca1f35aad",
+ "content-hash": "524c99fd87297e01d004eb5a4e53b04c",
"packages": [
{
"name": "icewind/smb",
- "version": "v3.5.1",
+ "version": "v3.5.2",
"source": {
"type": "git",
"url": "https://github.com/icewind1991/SMB.git",
- "reference": "c1ce4fbb2ff1786846d9d0b3850b395ca94cf563"
+ "reference": "0a425bd21acf7ae112b135dca34640e1b1a825c3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/icewind1991/SMB/zipball/c1ce4fbb2ff1786846d9d0b3850b395ca94cf563",
- "reference": "c1ce4fbb2ff1786846d9d0b3850b395ca94cf563",
+ "url": "https://api.github.com/repos/icewind1991/SMB/zipball/0a425bd21acf7ae112b135dca34640e1b1a825c3",
+ "reference": "0a425bd21acf7ae112b135dca34640e1b1a825c3",
"shasum": ""
},
"require": {
"description": "php wrapper for smbclient and libsmbclient-php",
"support": {
"issues": "https://github.com/icewind1991/SMB/issues",
- "source": "https://github.com/icewind1991/SMB/tree/v3.5.1"
+ "source": "https://github.com/icewind1991/SMB/tree/v3.5.2"
},
- "time": "2021-11-04T14:28:18+00:00"
+ "time": "2022-01-20T14:51:51+00:00"
},
{
"name": "icewind/streams",
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.2.0"
}
/**
* @return string[] Array of classname => path
- * @psalm-var array<string, string>
+ * @psalm-return array<string, string>
*/
public function getClassMap()
{
"packages": [
{
"name": "icewind/smb",
- "version": "v3.5.1",
- "version_normalized": "3.5.1.0",
+ "version": "v3.5.2",
+ "version_normalized": "3.5.2.0",
"source": {
"type": "git",
"url": "https://github.com/icewind1991/SMB.git",
- "reference": "c1ce4fbb2ff1786846d9d0b3850b395ca94cf563"
+ "reference": "0a425bd21acf7ae112b135dca34640e1b1a825c3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/icewind1991/SMB/zipball/c1ce4fbb2ff1786846d9d0b3850b395ca94cf563",
- "reference": "c1ce4fbb2ff1786846d9d0b3850b395ca94cf563",
+ "url": "https://api.github.com/repos/icewind1991/SMB/zipball/0a425bd21acf7ae112b135dca34640e1b1a825c3",
+ "reference": "0a425bd21acf7ae112b135dca34640e1b1a825c3",
"shasum": ""
},
"require": {
"phpunit/phpunit": "^8.5|^9.3.8",
"psalm/phar": "^4.3"
},
- "time": "2021-11-04T14:28:18+00:00",
+ "time": "2022-01-20T14:51:51+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"description": "php wrapper for smbclient and libsmbclient-php",
"support": {
"issues": "https://github.com/icewind1991/SMB/issues",
- "source": "https://github.com/icewind1991/SMB/tree/v3.5.1"
+ "source": "https://github.com/icewind1991/SMB/tree/v3.5.2"
},
"install-path": "../icewind/smb"
},
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
- 'reference' => 'cd72330b8f669e3dc81388be5a92171404f36fec',
+ 'reference' => '0bed61f949bc7a8c69cd154919e78b704e28c99e',
'name' => 'files_external/3rdparty',
'dev' => true,
),
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
- 'reference' => 'cd72330b8f669e3dc81388be5a92171404f36fec',
+ 'reference' => '0bed61f949bc7a8c69cd154919e78b704e28c99e',
'dev_requirement' => false,
),
'icewind/smb' => array(
- 'pretty_version' => 'v3.5.1',
- 'version' => '3.5.1.0',
+ 'pretty_version' => 'v3.5.2',
+ 'version' => '3.5.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../icewind/smb',
'aliases' => array(),
- 'reference' => 'c1ce4fbb2ff1786846d9d0b3850b395ca94cf563',
+ 'reference' => '0a425bd21acf7ae112b135dca34640e1b1a825c3',
'dev_requirement' => false,
),
'icewind/streams' => array(
/** @var string */
private $ticketPath = "";
- // only working with specific library (mod_auth_kerb, krb5, smbclient) versions
- /** @var bool */
- private $saveTicketInMemory = false;
-
/** @var bool */
private $init = false;
+ /** @var string|false */
+ private $ticketName;
+
+ public function __construct() {
+ $this->ticketName = getenv("KRB5CCNAME");
+ }
+
+
+ /**
+ * Copy the ticket to a temporary location and use that ticket for authentication
+ *
+ * @return void
+ */
+ public function copyTicket(): void {
+ if (!$this->checkTicket()) {
+ return;
+ }
+ $krb5 = new \KRB5CCache();
+ $krb5->open($this->ticketName);
+ $tmpFilename = tempnam("/tmp", "krb5cc_php_");
+ $tmpCacheFile = "FILE:" . $tmpFilename;
+ $krb5->save($tmpCacheFile);
+ $this->ticketPath = $tmpFilename;
+ $this->ticketName = $tmpCacheFile;
+ }
+
/**
- * @param bool $saveTicketInMemory
+ * Pass the ticket to smbclient by memory instead of path
+ *
+ * @return void
*/
- public function __construct(bool $saveTicketInMemory = false) {
- $this->saveTicketInMemory = $saveTicketInMemory;
+ public function passTicketFromMemory(): void {
+ if (!$this->checkTicket()) {
+ return;
+ }
+ $krb5 = new \KRB5CCache();
+ $krb5->open($this->ticketName);
+ $this->ticketName = (string)$krb5->getName();
}
/**
* Check if a valid kerberos ticket is present
*
* @return bool
+ * @psalm-assert-if-true string $this->ticketName
*/
public function checkTicket(): bool {
//read apache kerberos ticket cache
- $cacheFile = getenv("KRB5CCNAME");
- if (!$cacheFile) {
+ if (!$this->ticketName) {
return false;
}
$krb5 = new \KRB5CCache();
- $krb5->open($cacheFile);
- return (bool)$krb5->isValid();
+ $krb5->open($this->ticketName);
+ /** @psalm-suppress MixedArgument */
+ return count($krb5->getEntries()) > 0;
}
private function init(): void {
}
//read apache kerberos ticket cache
- $cacheFile = getenv("KRB5CCNAME");
- if (!$cacheFile) {
+ if (!$this->checkTicket()) {
throw new Exception('No kerberos ticket cache environment variable (KRB5CCNAME) found.');
}
- $krb5 = new \KRB5CCache();
- $krb5->open($cacheFile);
- if (!$krb5->isValid()) {
- throw new Exception('Kerberos ticket cache is not valid.');
- }
-
-
- if ($this->saveTicketInMemory) {
- putenv("KRB5CCNAME=" . (string)$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);
- }
+ // note that even if the ticketname 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=" . $this->ticketName);
}
public function getExtraCommandLineArguments(): string {
public function setExtraSmbClientOptions($smbClientState): void {
$this->init();
- parent::setExtraSmbClientOptions($smbClientState);
+ try {
+ parent::setExtraSmbClientOptions($smbClientState);
+ } catch (Exception $e) {
+ // suppress
+ }
}
public function __destruct() {