31 if (stristr(PHP_OS,
'LINUX')) {
34 if (stristr(PHP_OS,
'DARWIN')) {
37 if (stristr(PHP_OS,
'WIN')) {
40 if (stristr(PHP_OS,
'BSD')) {
43 if (stristr(PHP_OS,
'UNIX')) {
46 if (stristr(PHP_OS,
'HP-UX')) {
49 if (stristr(PHP_OS,
'IRIX')) {
52 if (stristr(PHP_OS,
'SUNOS')) {
77 sys_get_temp_dir().DIRECTORY_SEPARATOR.
'simplesaml' 82 if (!is_dir($tempDir)) {
83 if (!mkdir($tempDir, 0700,
true)) {
84 $error = error_get_last();
85 throw new \SimpleSAML_Error_Exception(
86 'Error creating temporary directory "'.$tempDir.
'": '.
87 (is_array($error) ? $error[
'message'] :
'no error available')
90 } elseif (function_exists(
'posix_getuid')) {
92 $stat = lstat($tempDir);
93 if ($stat[
'uid'] !== posix_getuid()) {
94 throw new \SimpleSAML_Error_Exception(
95 'Temporary directory "'.$tempDir.
'" does not belong to the current user.' 120 if (
$base === null) {
134 if (substr(
$path, 0, 1) ===
'/') {
137 } elseif (static::pathContainsDriveLetter(
$path)) {
148 } elseif ($d ===
'..') {
151 if (
$ret && substr(
$ret, -1) !==
'/') {
185 if (!is_string(
$filename) || !is_string(
$data) || !is_numeric($mode)) {
186 throw new \InvalidArgumentException(
'Invalid input parameters');
189 $tmpFile = self::getTempDir().DIRECTORY_SEPARATOR.rand();
191 $res = @file_put_contents($tmpFile,
$data);
192 if (
$res ===
false) {
193 $error = error_get_last();
194 throw new \SimpleSAML_Error_Exception(
195 'Error saving file "'.$tmpFile.
'": '.
196 (is_array($error) ? $error[
'message'] :
'no error available')
200 if (self::getOS() !== self::WINDOWS) {
201 if (!chmod($tmpFile, $mode)) {
203 $error = error_get_last();
205 throw new \SimpleSAML_Error_Exception(
206 'Error changing file mode of "'.$tmpFile.
'": '.
207 (is_array($error) ? $error[
'message'] :
'no error available')
214 $error = error_get_last();
215 throw new \SimpleSAML_Error_Exception(
216 'Error moving "'.$tmpFile.
'" to "'.
$filename.
'": '.
217 (is_array($error) ? $error[
'message'] :
'no error available')
221 if (function_exists(
'opcache_invalidate')) {
235 $letterAsciiValue = ord(strtoupper(substr(
$path, 0, 1)));
236 return substr(
$path, 1, 1) ===
':' 237 && $letterAsciiValue >= 65 && $letterAsciiValue <= 90;
static writeFile($filename, $data, $mode=0600)
Atomically write a file.
static pathContainsDriveLetter($path)
Check if the supplied path contains a Windows-style drive letter.
static getTempDir()
This function retrieves the path to a directory where temporary files can be saved.
static getOS()
This function returns the Operating System we are running on.
foreach($_POST as $key=> $value) $res
static resolvePath($path, $base=null)
Resolve a (possibly) relative path from the given base path.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d