Fix SUID.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 5 Oct 2010 20:36:11 +0000 (22:36 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 5 Oct 2010 20:36:11 +0000 (22:36 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/plsession.php
classes/s.php

index 9b6f90e..7a243be 100644 (file)
@@ -189,8 +189,7 @@ abstract class PlSession
         if (S::suid()) {
             return false;
         }
-        $backup   = $_SESSION;
-        $_SESSION = array();
+        $backup = S::changeSession(array());
         $this->fillSession();
         S::set('suid', $backup);
         if (!$this->startSessionAs($user, AUTH_SUID)) {
@@ -211,7 +210,7 @@ abstract class PlSession
         if (!S::suid()) {
             return false;
         }
-        $_SESSION = $_SESSION['suid'];
+        S::changeSession(S::v('suid'));
         return true;
     }
 
index 9f71872..d436bf1 100644 (file)
@@ -117,9 +117,9 @@ class S
      * move into the php session (and data it helds should be removed from
      * the php session). */
     private static $user = null;
-    public static function &user()
+    public static function &user($forceFetch = false)
     {
-        if (self::$user == null && class_exists('User')) {
+        if (($forceFetch || self::$user == null) && class_exists('User')) {
             if (S::has('user') && S::v('user') instanceof User) {
                 self::$user = S::v('user');
             } else {
@@ -129,6 +129,14 @@ class S
         return self::$user;
     }
 
+    public static function changeSession(array $newSession)
+    {
+        $oldSession = $_SESSION;
+        $_SESSION = $newSession;
+        self::$user = null;
+        return $oldSession;
+    }
+
     public static function logged()
     {
         return S::i('auth', AUTH_PUBLIC) >= Platal::session()->loggedLevel();