/**
* Get temp directory path.
*
* This function retrieves the path to a directory where
* temporary files can be saved.
*
* @return string Path to temp directory, without a trailing '/'.
*/
public static function getTempDir()
{
$globalConfig = SimpleSAML_Configuration::getInstance();
$tempDir = $globalConfig->getString('tempdir', '/tmp/simplesaml');
while (substr($tempDir, -1) === '/') {
$tempDir = substr($tempDir, 0, -1);
}
if (!is_dir($tempDir)) {
$ret = mkdir($tempDir, 0700, TRUE);
if (!$ret) {
throw new SimpleSAML_Error_Exception('Error creating temp dir ' . var_export($tempDir, TRUE) . ': ' . SimpleSAML_Utilities::getLastError());
}
} elseif (function_exists('posix_getuid')) {
/* Check that the owner of the temp diretory is the current user. */
$stat = lstat($tempDir);
if ($stat['uid'] !== posix_getuid()) {
throw new SimpleSAML_Error_Exception('Temp directory (' . var_export($tempDir, TRUE) . ') not owned by current user.');
}
}
return $tempDir;
}