Skip to content
Snippets Groups Projects
Commit 85ad231e authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Refactor SimpleSAML_Utilities::getTempDir() to SimpleSAML_Utils_System::getTempDir().

Schedule SimpleSAML_Utilities::getTempDir() for removal.
parent 943ba8ae
No related branches found
No related tags found
No related merge requests found
......@@ -137,7 +137,7 @@ class SimpleSAML_Bindings_Shib13_Artifact {
"-----END CERTIFICATE-----\n";
}
$file = SimpleSAML_Utilities::getTempDir() . '/' . sha1($certData) . '.crt';
$file = SimpleSAML_Utils_System::getTempDir() . DIRECTORY_SEPARATOR . sha1($certData) . '.crt';
if (!file_exists($file)) {
SimpleSAML_Utilities::writeFile($file, $certData);
}
......
......@@ -1966,6 +1966,7 @@ class SimpleSAML_Utilities {
* temporary files can be saved.
*
* @return string Path to temp directory, without a trailing '/'.
* @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Utils_System::getTempDir instead.
*/
public static function getTempDir() {
......
......@@ -54,4 +54,35 @@ class SimpleSAML_Utils_System
}
return false;
}
/**
* This function retrieves the path to a directory where temporary files can be saved.
*
* @return string Path to a temporary directory, without a trailing directory separator.
* @throws SimpleSAML_Error_Exception If the temporary directory cannot be created or it exists and does not belong
* to the current user.
*/
public static function getTempDir()
{
$globalConfig = SimpleSAML_Configuration::getInstance();
$tempDir = rtrim($globalConfig->getString('tempdir', sys_get_temp_dir().DIRECTORY_SEPARATOR.'simplesaml'),
DIRECTORY_SEPARATOR);
if (!is_dir($tempDir)) {
if (!mkdir($tempDir, 0700, true)) {
throw new SimpleSAML_Error_Exception('Error creating temporary directory "'.$tempDir.
'": '.SimpleSAML_Utilities::getLastError());
}
} elseif (function_exists('posix_getuid')) {
// check that the owner of the temp directory is the current user
$stat = lstat($tempDir);
if ($stat['uid'] !== posix_getuid()) {
throw new SimpleSAML_Error_Exception('Temporary directory "'.$tempDir.
'" does not belong to the current user.');
}
}
return $tempDir;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment