public function import($id1_) { Logger::debug('main', "UserGroupDB::ldap_memberof::import (id = {$id1_})"); if (is_base64url($id1_)) { $id_ = base64url_decode($id1_); } else { $id_ = $id1_; } $prefs = Preferences::getInstance(); if (!$prefs) { die_error('get Preferences failed', __FILE__, __LINE__); } $config_ldap = $prefs->get('UserDB', 'ldap'); $config_ldap['match'] = array(); if (array_key_exists('match', $this->preferences)) { $config_ldap['match'] = $this->preferences['match']; } if (str_endswith(strtolower($id_), strtolower($config_ldap['suffix'])) === true) { $id2 = substr($id_, 0, -1 * strlen($config_ldap['suffix']) - 1); } else { $id2 = $id_; } $expl = explode(',', $id2, 2); if (count($expl) == 1) { $expl = array($id2, ''); } $config_ldap['userbranch'] = $expl[1]; $buf = $config_ldap['match']; $buf['id'] = $id_; $ldap = new LDAP($config_ldap); $sr = $ldap->search($expl[0], array_keys($config_ldap['match'])); if ($sr === false) { Logger::error('main', "UserGroupDB::ldap_memberof::import search failed for ({$id_})"); return NULL; } $infos = $ldap->get_entries($sr); if ($infos === array()) { Logger::error('main', "UserGroupDB::ldap_memberof::import get_entries failed for ({$id_})"); return NULL; } $keys = array_keys($infos); $dn = $keys[0]; $info = $infos[$dn]; foreach ($config_ldap['match'] as $attribut => $match_ldap) { if (isset($info[$match_ldap][0])) { $buf[$attribut] = $info[$match_ldap][0]; } } $ug = new UsersGroup($buf['id'], $buf['name'], $buf['description'], true); return $ug; }
public function import($id_) { if (is_base64url($id_)) { $id_ = base64url_decode($id_); } Logger::debug('main', 'UserGroupDB::import(' . $id_ . ')'); foreach ($this->instance_type as $key => $value) { if (str_startswith($id_, $key . '_')) { return $value->import(substr($id_, strlen($key) + 1)); } } return NULL; // not found }
public function import($id1_) { Logger::debug('main', "UserGroupDB::ldap::import (id = {$id1_})"); if (is_base64url($id1_)) { $id = base64url_decode($id1_); } else { $id = $id1_; } if (array_key_exists($id, $this->cache_import)) { return $this->cache_import[$id]; } else { $ug = $this->import_nocache($id); $this->cache_import[$id] = $ug; return $ug; } }
public static function loadElements($type_, $group_) { Logger::debug('main', "Abstract_Liaison_ldap_memberof::loadElements ({$type_},{$group_})"); $prefs = Preferences::getInstance(); if (!$prefs) { die_error('get Preferences failed', __FILE__, __LINE__); } $userGroupDB = UserGroupDB::getInstance(); $group = $userGroupDB->import($group_); if (!is_object($group)) { Logger::error('main', "Abstract_Liaison_ldap_memberof::loadElements load group ({$group_}) failed"); return NULL; } $userGroupDB_ldap_memberof = new UserGroupDB_ldap_memberof(); $use_child_group = false; ${$userGroupDB_ldap_memberof_preferences} = $userGroupDB_ldap_memberof->preferences; if (array_key_exists('use_child_group', ${$userGroupDB_ldap_memberof_preferences})) { if (${$userGroupDB_ldap_memberof_preferences}['use_child_group'] == 1 || ${$userGroupDB_ldap_memberof_preferences}['use_child_group'] == '1') { $use_child_group = true; } } $elements = array(); if (is_base64url($group->id)) { $id_ = base64url_decode($group->id); } else { $id_ = $group->id; } $userDBldap = new UserDB_ldap(); $userDBldap2 = UserDB::getInstance(); if (get_class($userDBldap) == get_class($userDBldap2)) { $userDBldap = $userDBldap2; // for cache } $config_ldap = $prefs->get('UserDB', 'ldap'); $config_ldap['match'] = array('description' => 'description', 'name' => 'name', 'member' => 'member'); if (str_endswith(strtolower($id_), strtolower($config_ldap['suffix'])) === true) { $id2 = substr($id_, 0, -1 * strlen($config_ldap['suffix']) - 1); } else { $id2 = $id_; } $expl = explode(',', $id2, 2); $config_ldap['userbranch'] = $expl[1]; $buf = array(); $buf['id'] = $id_; $ldap = new LDAP($config_ldap); $sr = $ldap->search($expl[0], array_keys($config_ldap['match'])); if ($sr === false) { Logger::error('main', "Abstract_Liaison_ldap_memberof::loadElements search failed for ({$id_})"); return NULL; } $infos = $ldap->get_entries($sr); if ($infos === array()) { return $elements; } $keys = array_keys($infos); $dn = $keys[0]; $info = $infos[$dn]; foreach ($config_ldap['match'] as $attribut => $match_ldap) { if (isset($info[$match_ldap])) { unset($info[$match_ldap]['count']); $buf[$attribut] = $info[$match_ldap]; } } if (isset($buf['member']) && is_array($buf['member'])) { foreach ($buf['member'] as $member) { $u = $userDBldap->importFromDN($member); if (is_object($u) == false) { Logger::error('main', "Abstract_Liaison_ldap_memberof::loadElements ({$type_},{$group_}) failed to import " . $member); continue; } else { if ($u->hasAttribute('objectclass')) { if (in_array('user', $u->getAttribute('objectclass'))) { $l = new Liaison($u->getAttribute('login'), $group_); $elements[$l->element] = $l; } else { if (in_array('group', $u->getAttribute('objectclass')) && $use_child_group == true) { $ret1 = self::loadElements($type_, 'static_' . $member); if (is_array($ret1)) { foreach ($ret1 as $element1 => $liaison1) { $elements[$element1] = $liaison1; } } } } } else { $l = new Liaison($u->getAttribute('login'), $group_); $elements[$l->element] = $l; } } } } return $elements; }