diff --git a/auth/cas/auth.php b/auth/cas/auth.php index ee9610a..8fcdb36 100644 --- a/auth/cas/auth.php +++ b/auth/cas/auth.php @@ -625,7 +625,7 @@ if ( !is_object($PHPCAS_CLIENT) ) { $droptablesql[] = 'DROP TEMPORARY TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later echo "Creating temp table $temptable\n"; - execute_sql('CREATE TEMPORARY TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username)) TYPE=MyISAM', false); + execute_sql('CREATE TEMPORARY TABLE ' . $temptable . ' (username VARCHAR(100), mnethostid BIGINT(10), PRIMARY KEY (username, mnethostid)) TYPE=MyISAM COLLATE utf8_general_ci', false); break; case 'postgres': $temptable = $CFG->prefix . 'extuser'; @@ -633,7 +633,7 @@ if ( !is_object($PHPCAS_CLIENT) ) { execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later echo "Creating temp table $temptable\n"; $bulk_insert_records = 1; // no support for multiple sets of values - execute_sql('CREATE TEMPORARY TABLE '. $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))', false); + execute_sql('CREATE TEMPORARY TABLE '. $temptable . ' (username VARCHAR(100), mnethostid BIGINT, PRIMARY KEY (username, mnethostid))', false); break; case 'mssql': $temptable = '#'.$CFG->prefix . 'extuser'; /// MSSQL temp tables begin with # @@ -641,7 +641,7 @@ if ( !is_object($PHPCAS_CLIENT) ) { execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later echo "Creating temp table $temptable\n"; $bulk_insert_records = 1; // no support for multiple sets of values - execute_sql('CREATE TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))', false); + execute_sql('CREATE TABLE ' . $temptable . ' (username VARCHAR(100), mnethostid BIGINT, PRIMARY KEY (username, mnethostid))', false); break; case 'oracle': $temptable = $CFG->prefix . 'extuser'; @@ -650,7 +650,7 @@ if ( !is_object($PHPCAS_CLIENT) ) { execute_sql_arr($droptablesql, true, false); /// Drop temp table to avoid persistence problems later echo "Creating temp table $temptable\n"; $bulk_insert_records = 1; // no support for multiple sets of values - execute_sql('CREATE GLOBAL TEMPORARY TABLE '.$temptable.' (username VARCHAR(64), PRIMARY KEY (username)) ON COMMIT PRESERVE ROWS', false); + execute_sql('CREATE GLOBAL TEMPORARY TABLE '.$temptable.' (username VARCHAR(100), mnethostid NUMBER(10), PRIMARY KEY (username, mnethostid)) ON COMMIT PRESERVE ROWS', false); break; } print "Connecting to ldap...\n"; @@ -723,7 +723,8 @@ if ( !is_object($PHPCAS_CLIENT) ) { if (!empty($this->config->removeuser)) { $sql = "SELECT u.id, u.username, u.email, u.auth FROM {$CFG->prefix}user u - LEFT JOIN $temptable e ON u.username = e.username + LEFT JOIN $temptable e ON u.username = e.username + AND u.mnethostid = e.mnethostid WHERE u.auth='cas' AND u.deleted=0 AND e.username IS NULL"; @@ -758,6 +759,7 @@ if ( !is_object($PHPCAS_CLIENT) ) { $sql = "SELECT u.id, u.username FROM $temptable e, {$CFG->prefix}user u WHERE e.username=u.username + AND e.mnethostid=u.mnethostid AND u.auth='nologin'"; $revive_users = get_records_sql($sql); if (!empty($revive_users)) { @@ -850,6 +852,7 @@ if ( !is_object($PHPCAS_CLIENT) ) { // note: we do not care about deleted accounts anymore, this feature was replaced by suspending to nologin auth plugin $sql = "SELECT e.username, e.username FROM $temptable e LEFT JOIN {$CFG->prefix}user u ON e.username = u.username + AND e.mnethostid = u.mnethostid WHERE u.id IS NULL"; $add_users = get_records_sql($sql); // get rid of the fat if (!empty($add_users)) { @@ -945,12 +948,14 @@ if ( !is_object($PHPCAS_CLIENT) ) { * @param array $users is an array of usernames */ function ldap_bulk_insert($users, $temptable) { + global $CFG; + // bulk insert -- superfast with $bulk_insert_records - $sql = 'INSERT INTO ' . $temptable . ' (username) VALUES '; + $sql = 'INSERT INTO ' . $temptable . ' (username, mnethostid) VALUES '; // make those values safe $users = addslashes_recursive($users); // join and quote the whole lot - $sql = $sql . "('" . implode("'),('", $users) . "')"; + $sql = $sql . "('" . implode("', $CFG->mnet_localhost_id),('", $users) . "', $CFG->mnet_localhost_id)"; print "\t+ " . count($users) . " users\n"; execute_sql($sql, false); } diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 15ec0bc..89b1a37 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -563,24 +563,24 @@ class auth_plugin_ldap extends auth_plugin_base { switch (strtolower($CFG->dbfamily)) { case 'mysql': $droptablesql[] = 'DROP TEMPORARY TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) - $createtemptablesql = 'CREATE TEMPORARY TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username)) TYPE=MyISAM'; + $createtemptablesql = 'CREATE TEMPORARY TABLE ' . $temptable . ' (username VARCHAR(100), mnethostid BIGINT(10), PRIMARY KEY (username, mnethostid)) TYPE=MyISAM COLLATE utf8_general_ci'; break; case 'postgres': $droptablesql[] = 'DROP TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) $bulk_insert_records = 1; // no support for multiple sets of values - $createtemptablesql = 'CREATE TEMPORARY TABLE '. $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))'; + $createtemptablesql = 'CREATE TEMPORARY TABLE '. $temptable . ' (username VARCHAR(100), mnethostid BIGINT, PRIMARY KEY (username, mnethostid))'; break; case 'mssql': $temptable = '#'. $temptable; /// MSSQL temp tables begin with # $droptablesql[] = 'DROP TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) $bulk_insert_records = 1; // no support for multiple sets of values - $createtemptablesql = 'CREATE TABLE ' . $temptable . ' (username VARCHAR(64), PRIMARY KEY (username))'; + $createtemptablesql = 'CREATE TABLE ' . $temptable . ' (username VARCHAR(100), mnethostid BIGINT, PRIMARY KEY (username, mnethostid))'; break; case 'oracle': $droptablesql[] = 'TRUNCATE TABLE ' . $temptable; // oracle requires truncate before being able to drop a temp table $droptablesql[] = 'DROP TABLE ' . $temptable; // sql command to drop the table (because session scope could be a problem) $bulk_insert_records = 1; // no support for multiple sets of values - $createtemptablesql = 'CREATE GLOBAL TEMPORARY TABLE '.$temptable.' (username VARCHAR(64), PRIMARY KEY (username)) ON COMMIT PRESERVE ROWS'; + $createtemptablesql = 'CREATE GLOBAL TEMPORARY TABLE '.$temptable.' (username VARCHAR(100), mnethostid NUMBER(10), PRIMARY KEY (username, mnethostid)) ON COMMIT PRESERVE ROWS'; break; } @@ -673,7 +673,8 @@ class auth_plugin_ldap extends auth_plugin_base { if (!empty($this->config->removeuser)) { $sql = "SELECT u.id, u.username, u.email, u.auth FROM {$CFG->prefix}user u - LEFT JOIN $temptable e ON u.username = e.username + LEFT JOIN $temptable e ON u.username = e.username + AND u.mnethostid = e.mnethostid WHERE u.auth='ldap' AND u.deleted=0 AND e.username IS NULL"; @@ -711,6 +712,7 @@ class auth_plugin_ldap extends auth_plugin_base { $sql = "SELECT u.id, u.username FROM $temptable e, {$CFG->prefix}user u WHERE e.username=u.username + AND e.mnethostid=u.mnethostid AND u.auth='nologin'"; $revive_users = get_records_sql($sql); @@ -815,6 +817,7 @@ class auth_plugin_ldap extends auth_plugin_base { // note: we do not care about deleted accounts anymore, this feature was replaced by suspending to nologin auth plugin $sql = "SELECT e.username, e.username FROM $temptable e LEFT JOIN {$CFG->prefix}user u ON e.username = u.username + AND e.mnethostid = u.mnethostid WHERE u.id IS NULL"; $add_users = get_records_sql($sql); // get rid of the fat @@ -929,13 +932,14 @@ class auth_plugin_ldap extends auth_plugin_base { * @param array $users is an array of usernames */ function ldap_bulk_insert($users, $temptable) { + global $CFG; // bulk insert -- superfast with $bulk_insert_records - $sql = 'INSERT INTO ' . $temptable . ' (username) VALUES '; + $sql = 'INSERT INTO ' . $temptable . ' (username, mnethostid) VALUES '; // make those values safe $users = addslashes_recursive($users); // join and quote the whole lot - $sql = $sql . "('" . implode("'),('", $users) . "')"; + $sql = $sql . "('" . implode("', $CFG->mnet_localhost_id),('", $users) . "', $CFG->mnet_localhost_id)"; print "\t+ " . count($users) . " users\n"; execute_sql($sql, false); }