Commit 40c1e468 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Various optimisations to gain speed (avoid useless preg_* and getDN)

parent 981b4e72
......@@ -590,7 +590,7 @@ class config {
continue;
}
$dn = $ldap->getDN();
$dn = $attrs['dn'];
$data = objects::infos($oc);
$this->department_info[$dn] = array(
'img' => $data['icon'],
......
......@@ -148,9 +148,7 @@ class filterLDAP
/* Crawl through result entries and perform the migration to the
result array */
while ($attrs = $ldap->fetch()) {
$dn = $ldap->getDN();
$attrs['dn'] = $dn;
$dn = $attrs['dn'];
/* Skip ACL checks if we are forced to skip those checks */
if (!$checkAcl) {
......@@ -160,7 +158,7 @@ class filterLDAP
$obj = $parent->headpage->getObjectTypeInfos($dn, $attrs);
if (isset($obj['category'])) {
$o = $obj['category'].'/'.$obj['class'];
if (preg_match('/r/', $ui->get_permissions($dn, $o))) {
if (strpos($ui->get_permissions($dn, $o), 'r')) {
$result[] = $attrs;
}
} else {
......
......@@ -922,10 +922,9 @@ class LDAP
$delarray = array();
/* Get sorted list of dn's to delete */
$this->search ($srp, "(objectClass=*)");
while ($this->fetch($srp)) {
$deldn = $this->getDN($srp);
$delarray[$deldn] = strlen($deldn);
$this->search($srp, '(objectClass=*)');
while ($attrs = $this->fetch($srp)) {
$delarray[$attrs['dn']] = strlen($attrs['dn']);
}
arsort($delarray);
reset($delarray);
......
......@@ -60,7 +60,7 @@ class ldapMultiplexer {
public function __call($methodName, $parameters)
{
/* Add resource pointer if the mentioned methods are used */
if (preg_match('/^(search|ls|cat|fetch|clearResult|resetResult|count|getDN|recursive_remove|rmdir_recursive|create_missing_trees|import_single_entry|import_complete_ldif)$/', $methodName)) {
if (in_array($methodName, array('search','ls','cat','fetch','clearResult','resetResult','count','getDN','recursive_remove','rmdir_recursive','create_missing_trees','import_single_entry','import_complete_ldif'))) {
array_unshift($parameters, $this->sr);
}
......
......@@ -442,8 +442,8 @@ class listing
// Save rendered column
$sort = preg_replace('/.*>([^<]+)<.*$/', '$1', $renderedCell);
$sort = preg_replace('/&nbsp;/', '', $sort);
if (preg_match('/</', $sort)) {
$sort = str_replace('&nbsp;', '', $sort);
if (strpos($sort, '<')) {
$sort = '';
}
$this->entries[$row]['_sort'.$index] = $sort;
......@@ -719,32 +719,30 @@ class listing
$classes = "";
$components = explode(';', $cfg);
foreach ($components as $part) {
if (preg_match("/^r$/", $part)) {
$res .= "text-align:right;";
continue;
}
if (preg_match("/^l$/", $part)) {
$res .= "text-align:left;";
continue;
}
if (preg_match("/^c$/", $part)) {
$res .= "text-align:center;";
continue;
}
if (preg_match("/^o$/", $part)) {
$classes .= "optional ";
continue;
}
if (preg_match("/^[0-9]+(|px|%)(-d)?$/", $part)) {
if (!preg_match('/-d$/', $part)) {
/* d suffix means dynamic, ie no fixed width */
$res .= "width:$part;";
} else {
/* Remove the -d suffix */
$part = preg_replace('/-d$/', '', $part);
}
$res .= "min-width:$part;";
continue;
switch ($part) {
case 'r':
$res .= 'text-align:right;';
break;
case 'l':
$res .= 'text-align:left;';
break;
case 'c':
$res .= 'text-align:center;';
break;
case 'o':
$classes .= 'optional ';
break;
default:
if (preg_match('/^[0-9]+(|px|%)(-d)?$/', $part)) {
if (!preg_match('/-d$/', $part)) {
/* d suffix means dynamic, ie no fixed width */
$res .= "width:$part;";
} else {
/* Remove the -d suffix */
$part = preg_replace('/-d$/', '', $part);
}
$res .= "min-width:$part;";
}
}
}
......@@ -1062,16 +1060,14 @@ class listing
}
}
// Render normal entries as usual
if ($action['type'] == 'entry') {
// Render normal entries as usual
$label = $this->processElementFilter('label', $action['name'], $action['label'], $this->entries[$row], $row);
$image = $this->processElementFilter('image', $action['name'], $action['image'], $this->entries[$row], $row);
$result .= '<input class="center" type="image" src="'.htmlentities($image, ENT_COMPAT, 'UTF-8').'" title="'.$label.'" alt="'.$label.'" '.
'name="listing_'.$action['name'].'_'.$row.'"/>';
}
// Handle special types
if (($action['type'] == 'copypaste') || ($action['type'] == 'snapshot')) {
} elseif (($action['type'] == 'copypaste') || ($action['type'] == 'snapshot')) {
// Handle special types
$objectType = $this->getObjectTypeInfos($dn, $this->entries[$row]);
$category = $class = NULL;
if ($objectType) {
......@@ -1128,11 +1124,9 @@ class listing
*/
function filterLink()
{
$result = "&nbsp;";
$row = func_get_arg(0);
$pid = $this->pid;
$dn = LDAP::fix(func_get_arg(1));
$row = func_get_arg(0);
$pid = $this->pid;
$dn = LDAP::fix(func_get_arg(1));
$params = array(func_get_arg(2));
// Collect sprintf params
......@@ -1146,7 +1140,7 @@ class listing
}
}
$result = "&nbsp;";
$result = '&nbsp;';
if (count($params) > 1) {
$trans = call_user_func_array('sprintf', $params);
if ($trans != '') {
......@@ -1632,8 +1626,8 @@ class listing
// Switch flags to on if there's at least one category which allows read/paste
foreach ($this->categories as $category) {
$read = $read || preg_match('/r/', $ui->get_category_permissions($this->base, $category));
$paste = $paste || $ui->is_pasteable($this->base, $category) == 1;
$read = $read || strpos($ui->get_category_permissions($this->base, $category), 'r');
$paste = $paste || ($ui->is_pasteable($this->base, $category) == 1);
}
// Draw entries that allow copy and cut
......
......@@ -276,7 +276,7 @@ class objects
$ldap->search('(objectClass=fdTemplate)', array('cn'));
if ($ldap->count() != 0) {
while ($attrs = $ldap->fetch()) {
$dn = $ldap->getDN();
$dn = $attrs['dn'];
if ($requiredPermissions != '') {
if (!preg_match('/'.$requiredPermissions.'/', $ui->get_permissions($dn, $infos['aclCategory'].'/'.'template'))) {
continue;
......
......@@ -310,7 +310,7 @@ class userinfo
*/
function is_copyable($dn, $object)
{
return preg_match('/r/', $this->get_complete_category_acls($dn, $object));
return strpos($this->get_complete_category_acls($dn, $object), 'r');
}
......@@ -327,8 +327,8 @@ class userinfo
*/
function is_cutable($dn, $object, $class)
{
$remove = preg_match('/d/', $this->get_permissions($dn, $object.'/'.$class));
$read = preg_match('/r/', $this->get_complete_category_acls($dn, $object));
$remove = strpos($this->get_permissions($dn, $object.'/'.$class), 'd');
$read = strpos($this->get_complete_category_acls($dn, $object), 'r');
return ($remove && $read);
}
......@@ -344,7 +344,7 @@ class userinfo
*/
function is_pasteable($dn, $object)
{
return preg_match("/w/", $this->get_complete_category_acls($dn, $object));
return strpos($this->get_complete_category_acls($dn, $object), 'w');
}
......@@ -364,8 +364,8 @@ class userinfo
}
$r = $w = TRUE;
foreach ($object as $category) {
$w &= preg_match("/w/", $this->get_complete_category_acls($dn, $category));
$r &= preg_match("/r/", $this->get_complete_category_acls($dn, $category));
$w &= strpos($this->get_complete_category_acls($dn, $category), 'w');
$r &= strpos($this->get_complete_category_acls($dn, $category), 'r');
}
return ($r && $w);
}
......@@ -385,11 +385,12 @@ class userinfo
if (!is_array($object)) {
$object = array($object);
}
$r = TRUE;
foreach ($object as $category) {
$r &= preg_match("/r/", $this->get_complete_category_acls($dn, $category));
if (!strpos($this->get_complete_category_acls($dn, $category), 'r')) {
return FALSE;
}
}
return $r;
return TRUE;
}
/*!
......@@ -412,9 +413,9 @@ class userinfo
*/
if ($this->ignore_acl_for_current_user()) {
if ($skip_write) {
return "rcdm";
return 'rcdm';
}
return "rwcdm";
return 'rwcdm';
}
/* Push cache answer? */
......@@ -430,14 +431,14 @@ class userinfo
/* Detect the set of ACLs we have to check for this object
*/
$adn = $dn;
while (!isset($this->ACLperPath[$adn]) && (strpos($adn, ",") !== FALSE)) {
while (!isset($this->ACLperPath[$adn]) && (strpos($adn, ',') !== FALSE)) {
$adn = preg_replace("/^[^,]*+,/", "", $adn);
}
if (isset($this->ACLperPath[$adn])) {
$ACL = $this->ACLperPath[$adn];
} else {
$ACL_CACHE["$dn+$object+$attribute"] = "";
return "";
$ACL_CACHE["$dn+$object+$attribute"] = '';
return '';
}
/* If we do not need to respect any user-filter settings
......@@ -449,7 +450,7 @@ class userinfo
if (isset($ACL_CACHE["$dn+$object+$attribute"])) {
$ret = $ACL_CACHE["$dn+$object+$attribute"];
if (!isset($ACL_CACHE["$orig_dn+$object+$attribute"])) {
$ACL_CACHE["$orig_dn+$object+$attribute"] = $ACL_CACHE["$dn+$object+$attribute"];
$ACL_CACHE["$orig_dn+$object+$attribute"] = $ret;
}
if ($skip_write) {
$ret = str_replace('w', '', $ret);
......@@ -458,18 +459,17 @@ class userinfo
}
}
/* Get ldap object, for later filter checks
*/
/* Get ldap object, for later filter checks */
$ldap = $config->get_ldap_link();
$acl = array("r" => "", "w" => "", "c" => "", "d" => "", "m" => "", "a" => "");
$acl = array('r' => '', 'w' => '', 'c' => '', 'd' => '', 'm' => '', 'a' => '');
/* Build dn array */
$path = explode(',', $dn);
$path = array_reverse($path);
/* Walk along the path to evaluate the acl */
$cpath = "";
$cpath = '';
foreach ($path as $element) {
/* Clean potential ACLs for each level */
......@@ -513,7 +513,7 @@ class userinfo
/* If attribute is "", we want to know, if we've *any* permissions here...
Merge global class ACLs [0] with attributes specific ACLs [attribute].
*/
if ($attribute == "" && isset($subacl['acl'][$object])) {
if (($attribute == '') && isset($subacl['acl'][$object])) {
foreach ($subacl['acl'][$object] as $attr => $dummy) {
$acl = $this->mergeACL($acl, $subacl['type'], $subacl['acl'][$object][$attr]);
}
......@@ -540,7 +540,7 @@ class userinfo
/* Category ACLs (e.g. $object = "user/0")
*/
if (strstr($object, "/0")) {
if (strstr($object, '/0')) {
$ocs = preg_replace("/\/0$/", "", $object);
if (isset($config->data['CATEGORIES'][$ocs])) {
......@@ -804,8 +804,8 @@ class userinfo
$tmp = $this->get_permissions($dn, $category.'/'.$oc);
$types = $acl;
for ($i = 0, $l = strlen($types); $i < $l; $i++) {
if (!preg_match('/'.$types[$i].'/', $tmp)) {
$acl = preg_replace('/'.$types[$i].'/', '', $acl);
if (!strpos($tmp, $types[$i])) {
$acl = str_replace($types[$i], '', $acl);
}
}
}
......
......@@ -569,7 +569,7 @@ function ldap_login_user ($username, $password)
}
/* got user dn, fill acl's */
$ui = new userinfo($ldap->getDN());
$ui = new userinfo($attrs['dn']);
/* password check, bind as user with supplied password */
$ldap->disconnect();
......@@ -711,12 +711,12 @@ function del_lock ($object)
$ldap = $config->get_ldap_link();
$ldap->cd(get_ou('lockRDN').get_ou('fusiondirectoryRDN').$config->current['BASE']);
$ldap->search('(&(objectClass=fdLockEntry)(fdObjectDn='.base64_encode($object).'))', array('fdObjectDn'));
$ldap->fetch();
$attrs = $ldap->fetch();
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $ldap->getDN(), LDAP_DEL, ERROR_DIALOG));
return;
} elseif ($ldap->getDN() != '') {
$ldap->rmdir($ldap->getDN());
} elseif ($attrs['dn'] != '') {
$ldap->rmdir($attrs['dn']);
}
}
......@@ -2845,10 +2845,10 @@ function get_next_id_pool($attrib)
}
/* Store old attrib and generate new */
$attrs = $ldap->fetch();
$dn = $ldap->getDN();
$oldAttr = $attrs[$attrib][0];
$newAttr = $oldAttr + 1;
$attrs = $ldap->fetch();
$dn = $attrs['dn'];
$oldAttr = $attrs[$attrib][0];
$newAttr = $oldAttr + 1;
/* Sanity check */
if ($newAttr >= $max) {
......
......@@ -351,7 +351,7 @@ class posixAccount extends simplePlugin
} else {
$entry = $attrs['cn'][0].' ['.$attrs['description'][0].']';
}
$groupMembership[$ldap->getDN()] = $entry;
$groupMembership[$attrs['dn']] = $entry;
}
asort($groupMembership);
reset($groupMembership);
......@@ -678,7 +678,7 @@ class posixAccount extends simplePlugin
if ($ldap->count() != 0) {
$attrs = $ldap->fetch();
if ($attrs['cn'][0] == $this->getUid() && !isset($this->attrs['memberUid'])) {
$ldap->rmDir($ldap->getDN());
$ldap->rmDir($attrs['dn']);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment