diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 15ec0bc..609d0e1 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -549,6 +549,7 @@ class auth_plugin_ldap extends auth_plugin_base { function sync_users ($bulk_insert_records = 1000, $do_updates = true) { global $CFG; + global $db; $textlib = textlib_get_instance(); @@ -563,24 +564,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 +674,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 +713,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 +818,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 +933,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); }