| 1 |
<?php |
<?php |
| 2 |
// $Id: singlesignon.module,v 1.21.2.11 2008/05/03 11:35:50 wayland76 Exp $ |
// $Id $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
/** |
/** |
| 48 |
* @endverbatim |
* @endverbatim |
| 49 |
* |
* |
| 50 |
* @link http://drupal.org/project/singlesignon |
* @link http://drupal.org/project/singlesignon |
| 51 |
* @author Daniel Convissor <danielc@analysisandsolutions.com> |
* @author Primary Author: Daniel Convissor <danielc@analysisandsolutions.com> |
| 52 |
* @version $Revision: 1.21.2.11 $ (HEAD) |
* @author Maintainer: Tim Nelson <wayland@wayland.id.au> |
| 53 |
|
* @version $Revision: $ |
| 54 |
*/ |
*/ |
| 55 |
|
|
| 56 |
// {{{ core functions |
// {{{ core functions |
| 57 |
|
|
| 58 |
|
include_once('sessions_extra.inc'); |
| 59 |
|
|
| 60 |
/** |
/** |
| 61 |
* Implementation of hook_init(). |
* Implementation of hook_init(). |
| 62 |
* |
* |
| 118 |
|
|
| 119 |
switch ($arg0) { |
switch ($arg0) { |
| 120 |
case 'logout': |
case 'logout': |
|
// User is in the middle of logging out. Delete all other session |
|
|
// records belonging to the current user. |
|
|
// Don't delete the user's session on the present website because this |
|
|
// session is needed for Drupal's regular logout process which takes |
|
|
// place after the singlesignon module is executed. |
|
| 121 |
if ($user->uid) { |
if ($user->uid) { |
| 122 |
db_query("DELETE FROM {sessions} WHERE uid = %d AND sid <> '%s'", $user->uid, session_id()); |
_singlesignon_session_logout($user->uid); |
| 123 |
} |
} |
| 124 |
return; |
return; |
| 125 |
|
|
| 150 |
} |
} |
| 151 |
// User just logged into the master server. Update the slave sessions' |
// User just logged into the master server. Update the slave sessions' |
| 152 |
// user ID's to be the user ID they have on the master server. |
// user ID's to be the user ID they have on the master server. |
| 153 |
_singlesignon_get_sql($user); |
_singlesignon_session_update_all_uids($user->uid); |
| 154 |
return; |
return; |
| 155 |
} |
} |
| 156 |
else if ($user->uid) { |
else if ($user->uid) { |
| 184 |
if ($user->uid) { |
if ($user->uid) { |
| 185 |
// User is already logged into the master server. Update the slave |
// User is already logged into the master server. Update the slave |
| 186 |
// session's user ID to be the user ID they have on the master server. |
// session's user ID to be the user ID they have on the master server. |
| 187 |
db_query("UPDATE {sessions} AS sess_slave LEFT JOIN {sessions} AS sess_master ON (sess_master.sid = '%s' AND sess_slave.sid = '%s') SET sess_slave.uid = sess_master.uid WHERE sess_slave.sid = '%s'", session_id(), $_GET['slave_session'], $_GET['slave_session']); |
_singlesignon_session_update_user(); |
| 188 |
} |
} |
| 189 |
_singlesignon_goto($_GET['singlesignon_dest']); |
_singlesignon_goto($_GET['singlesignon_dest']); |
| 190 |
break; |
break; |
| 192 |
case 'login': |
case 'login': |
| 193 |
// User is coming to the master site to say they just logged on to a |
// User is coming to the master site to say they just logged on to a |
| 194 |
// slave. Set master site's user ID to be their one from the slave. |
// slave. Set master site's user ID to be their one from the slave. |
| 195 |
$result = db_query("SELECT uid FROM {sessions} WHERE sid = '%s'", $_GET['slave_session']); |
_singlesignon_session_login($user); |
|
$row = db_fetch_array($result); |
|
|
$user->uid = $row['uid']; |
|
|
|
|
|
// Update all sessions' user IDs to the current one. |
|
|
_singlesignon_get_sql($user); |
|
| 196 |
_singlesignon_goto($_GET['singlesignon_dest']); |
_singlesignon_goto($_GET['singlesignon_dest']); |
| 197 |
} |
} |
| 198 |
} |
} |
| 213 |
} |
} |
| 214 |
|
|
| 215 |
/** |
/** |
|
* Gets the SQL to update the sessions a bit -- can equivalent code be found somewhere else? |
|
|
*/ |
|
|
function _singlesignon_get_sql($user) { |
|
|
$in = substr(str_repeat("'%s',", count($_SESSION['singlesignon_slave_sessions'])), 0, -1); |
|
|
$sql = "UPDATE {sessions} SET uid = %d WHERE sid IN ($in)"; // I know the coder module complains about this, but it appears to be necessary in this case |
|
|
$args = array_merge(array($sql), array($user->uid), $_SESSION['singlesignon_slave_sessions']); |
|
|
call_user_func_array('db_query', $args); |
|
|
} |
|
|
|
|
|
/** |
|
| 216 |
* Gets the base url and fixess it up a bit |
* Gets the base url and fixess it up a bit |
| 217 |
*/ |
*/ |
| 218 |
function _singlesignon_base_url() { |
function _singlesignon_base_url() { |