From 943ba8aeaf4c59291ab9d92397ee5900c28bb47b Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Wed, 15 Apr 2015 11:17:01 +0200
Subject: [PATCH] Refactor SimpleSAML_Utilities::isWindowsOS() to
 SimpleSAML_Utilities::getOS(). Reimplemented to support most operating
 systems.

Schedule SimpleSAML_Utilities::isWindowsOS() for removal.
---
 .../Logger/LoggingHandlerSyslog.php           |  2 +-
 lib/SimpleSAML/Utilities.php                  |  4 +-
 lib/SimpleSAML/Utils/System.php               | 57 +++++++++++++++++++
 3 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 lib/SimpleSAML/Utils/System.php

diff --git a/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php b/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php
index f6d58b164..04c3711ac 100644
--- a/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php
+++ b/lib/SimpleSAML/Logger/LoggingHandlerSyslog.php
@@ -27,7 +27,7 @@ class SimpleSAML_Logger_LoggingHandlerSyslog implements SimpleSAML_Logger_Loggin
         $processname = $config->getString('logging.processname', 'simpleSAMLphp');
 
         // Setting facility to LOG_USER (only valid in Windows), enable log level rewrite on windows systems.
-        if (SimpleSAML_Utilities::isWindowsOS()) {
+        if (SimpleSAML_Utils_System::getOS() === SimpleSAML_Utils_System::WINDOWS) {
             $this->isWindows = TRUE;
             $facility = LOG_USER;
         }
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index a79613c29..e38e0b16e 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -506,7 +506,7 @@ class SimpleSAML_Utilities {
 
 	/**
 	 * Check whether an IP address is part of an CIDR.
-	 * @deprecated This method will be removed in version 2.0.
+	 * @deprecated This method will be removed in version 2.0. Use SimpleSAML_Utils_Net::ipCIDRcheck() instead.
 	 */
 	static function ipCIDRcheck($cidr, $ip = null) {
 		if ($ip == null) $ip = $_SERVER['REMOTE_ADDR'];
@@ -2305,6 +2305,8 @@ class SimpleSAML_Utilities {
 	 * This function checks if we are running on Windows OS.
 	 *
 	 * @return TRUE if we are on Windows OS, FALSE otherwise.
+	 *
+	 * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML_Utils_System::getOS() instead.
 	 */
 	public static function isWindowsOS() {
 		return substr(strtoupper(PHP_OS),0,3) == 'WIN';
diff --git a/lib/SimpleSAML/Utils/System.php b/lib/SimpleSAML/Utils/System.php
new file mode 100644
index 000000000..558645520
--- /dev/null
+++ b/lib/SimpleSAML/Utils/System.php
@@ -0,0 +1,57 @@
+<?php
+
+
+/**
+ * System-related utility classes.
+ *
+ * @package SimpleSAMLphp
+ */
+class SimpleSAML_Utils_System
+{
+
+    const WINDOWS = 1;
+    const LINUX = 2;
+    const OSX = 3;
+    const HPUX = 4;
+    const UNIX = 5;
+    const BSD = 6;
+    const IRIX = 7;
+    const SUNOS = 8;
+
+
+    /**
+     * This function returns the Operating System we are running on.
+     *
+     * @return mixed A predefined constant identifying the OS we are running on. False if we are unable to determine it.
+     *
+     * @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no>
+     */
+    public static function getOS()
+    {
+        if (stristr(PHP_OS, 'LINUX')) {
+            return self::LINUX;
+        }
+        if (stristr(PHP_OS, 'WIN')) {
+            return self::WINDOWS;
+        }
+        if (stristr(PHP_OS, 'DARWIN')) {
+            return self::OSX;
+        }
+        if (stristr(PHP_OS, 'BSD')) {
+            return self::BSD;
+        }
+        if (stristr(PHP_OS, 'UNIX')) {
+            return self::UNIX;
+        }
+        if (stristr(PHP_OS, 'HP-UX')) {
+            return self::HPUX;
+        }
+        if (stristr(PHP_OS, 'IRIX')) {
+            return self::IRIX;
+        }
+        if (stristr(PHP_OS, 'SUNOS')) {
+            return self::SUNOS;
+        }
+        return false;
+    }
+}
\ No newline at end of file
-- 
GitLab