From ea2f96f6e03db4e950794accfed053864e465ef5 Mon Sep 17 00:00:00 2001 From: Andjelko Horvat <comel@vingd.com> Date: Fri, 13 Jan 2012 10:47:13 +0000 Subject: [PATCH] Add SimpleSAML_Utilities::isWindowsOS and chmod file in SimpleSAML_Utilities::writeFile() (issue #469). git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3015 44740490-163a-0410-bde0-09ae8108e29a --- .../Logger/LoggingHandlerSyslog.php | 2 +- lib/SimpleSAML/Utilities.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php b/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php index 562ca1213..6c7ddfadd 100644 --- a/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php +++ b/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php @@ -23,7 +23,7 @@ class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_Loggin * OS Check * Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems. */ - if (substr(strtoupper(PHP_OS),0,3) == 'WIN') { + if (SimpleSAML_Utilities::isWindowsOS()) { $this->isWindows = true; $facility = LOG_USER; } diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 56ae886f1..cb0170c5c 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -1937,6 +1937,15 @@ class SimpleSAML_Utilities { ': ' . SimpleSAML_Utilities::getLastError()); } + if (!self::isWindowsOS()) { + $res = chmod($tmpFile, 0600); + if ($res === FALSE) { + unlink($tmpFile); + throw new SimpleSAML_Error_Exception('Error changing file mode ' . $tmpFile . + ': ' . SimpleSAML_Utilities::getLastError()); + } + } + $res = rename($tmpFile, $filename); if ($res === FALSE) { unlink($tmpFile); @@ -2258,4 +2267,14 @@ class SimpleSAML_Utilities { return $clear; } + + /** + * This function checks if we are running on Windows OS. + * + * @return TRUE if we are on Windows OS, FALSE otherwise. + */ + public static function isWindowsOS() { + return substr(strtoupper(PHP_OS),0,3) == 'WIN'; + } + } -- GitLab