diff --git a/lib/SimpleSAML/Bindings/Shib13/Artifact.php b/lib/SimpleSAML/Bindings/Shib13/Artifact.php index 4eda10bb3908f1010fdc6f8dae9e51eeb6967916..d06d715926321a9c335cee3e7b6b9142de7d1b2e 100644 --- a/lib/SimpleSAML/Bindings/Shib13/Artifact.php +++ b/lib/SimpleSAML/Bindings/Shib13/Artifact.php @@ -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); } diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index e38e0b16eef3bc78613947f1f8d6703a1e7725d9..79d93e0cd38c31a6e236a5d5c23dbbefc2195999 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -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() { diff --git a/lib/SimpleSAML/Utils/System.php b/lib/SimpleSAML/Utils/System.php index 5586455208a6d86933357a1ec90b49600a73ec41..3445af03810dc34e6adcd5f6cb70ec58145d474d 100644 --- a/lib/SimpleSAML/Utils/System.php +++ b/lib/SimpleSAML/Utils/System.php @@ -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