reduced memory usage in cache by removing scope "*", removed update_cache() function
This commit is contained in:
parent
fcfbdec26a
commit
d9fc93c39c
|
@ -8,6 +8,7 @@
|
|||
-> Samba 3: fixed logon hours (patch 1311915)
|
||||
-> Samba 3: loading of domain setting from profile did not work
|
||||
-> Quota: profile settings fixed
|
||||
-> reduced memory usage
|
||||
|
||||
|
||||
28.09.2005 0.5.0
|
||||
|
|
|
@ -51,8 +51,6 @@ class cache {
|
|||
* syntax of $attributes is array( scope1 => array ( attributes ), scope2 => array ( attributes ), ...)
|
||||
*/
|
||||
function add_cache($attributes) {
|
||||
// Check input variable
|
||||
$allowed_types = array ( 'user', 'group', 'host', 'domain', '*' );
|
||||
if (!is_array($attributes)) trigger_error('Argument of add_cache must be : array ( scope => array(attribute1(string), attribute2(string), ..), scope => ... ).', E_USER_ERROR);
|
||||
foreach ($attributes as $attribute) {
|
||||
if (!is_array($attribute)) trigger_error('Argument of add_cache must be : array ( scope => array(attribute1(string), attribute2(string), ..), scope => ... ).', E_USER_ERROR);
|
||||
|
@ -61,10 +59,6 @@ class cache {
|
|||
}
|
||||
}
|
||||
$scopes = array_keys($attributes);
|
||||
foreach ($scopes as $scope) {
|
||||
if (!@in_array($scope, $allowed_types)) trigger_error(sprintf('Invalid scope. Valid scopes are %s.', implode(" ", $allowed_types)), E_USER_ERROR);
|
||||
}
|
||||
// Everything seems to be OK, start processing data
|
||||
foreach ($scopes as $scope) {
|
||||
for ($i=0; $i<count($attributes[$scope]); $i++ ) {
|
||||
if (!@in_array($attributes[$scope][$i] ,$this->attributes[$scope])) $this->attributes[$scope][] = $attributes[$scope][$i];
|
||||
|
@ -79,20 +73,16 @@ class cache {
|
|||
*
|
||||
* @param mixed $attributes One (string) or many (array) attribute names.
|
||||
* @param string $objectClass The resulting entries need to contain this object class.
|
||||
* @param string $singlescope The account type or "*" if all.
|
||||
* @param mixed $scope the account type(s) as string or array
|
||||
* @return array The found LDAP entries.
|
||||
* <br>Format: array(dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) if $attributes is of type string
|
||||
* <br>or array(dn1 => array(uid => array(myuid), uidNumber => array(1234)), ... ) if $attributes is an array
|
||||
*
|
||||
*/
|
||||
function get_cache($attributes, $objectClass, $singlescope) {
|
||||
function get_cache($attributes, $objectClass, $scopelist) {
|
||||
$this->refresh_cache();
|
||||
// Check input variables
|
||||
$allowed_types = array ( 'user', 'group', 'host', 'domain', '*' );
|
||||
if (!in_array($singlescope, $allowed_types)) trigger_error(sprintf('Invalid scope. Valid scopes are %s.', implode(" ", $allowed_types)), E_USER_ERROR);
|
||||
$this->refresh_cache();
|
||||
if ($singlescope == '*') $scopes = $allowed_types;
|
||||
else $scopes = array ( $singlescope );
|
||||
if (is_array($scopelist)) $scopes = $scopelist;
|
||||
else $scopes = array($scopelist);
|
||||
// Add cache entry dynamic
|
||||
if (!is_array($attributes)) $attributes = array($attributes);
|
||||
foreach ($scopes as $scope) {
|
||||
|
@ -126,16 +116,12 @@ class cache {
|
|||
|
||||
/* This functions returns the dn if a dn with $attribute=$value is found
|
||||
* $values is the value $attribute is set to
|
||||
* $scope is the scope where to search
|
||||
* $scopelist mixed the account type(s) as string or array
|
||||
*/
|
||||
function in_cache($value, $attribute, $singlescope) {
|
||||
function in_cache($value, $attribute, $scopelist) {
|
||||
$this->refresh_cache();
|
||||
// Check input variables
|
||||
$allowed_types = array ( 'user', 'group', 'host', 'domain', '*' );
|
||||
if (!in_array($singlescope, $allowed_types)) trigger_error(sprintf('Invalid scope. Valid scopes are %s.', implode(" ", $allowed_types)), E_USER_ERROR);
|
||||
$this->refresh_cache();
|
||||
if ($singlescope == '*') $scopes = $allowed_types;
|
||||
else $scopes = array ( $singlescope );
|
||||
if (is_array($scopelist)) $scopes = $scopelist;
|
||||
else $scopes = array($scopelist);
|
||||
// Add cache entry dynamic
|
||||
foreach ($scopes as $scope) {
|
||||
if (!@in_array($attribute ,$this->attributes[$scope])) $add[$scope][] = $attribute;
|
||||
|
@ -168,10 +154,8 @@ class cache {
|
|||
unset ($this->ldapcache);
|
||||
$scopes = array_keys($this->attributes);
|
||||
foreach ($scopes as $scope) {
|
||||
// Get Scope
|
||||
If ($scope != '*')
|
||||
// Get suffix
|
||||
$suffix = $_SESSION['config']->get_Suffix($scope);
|
||||
else $suffix = '';
|
||||
// Get Data from ldap
|
||||
$search = $this->attributes[$scope];
|
||||
$search[] = 'objectClass';
|
||||
|
@ -202,62 +186,6 @@ class cache {
|
|||
}
|
||||
}
|
||||
|
||||
/* This function update the cache when changes were
|
||||
* made without refrehing the complete cache
|
||||
*/
|
||||
function update_cache($dn, $mode, $attributes=false) {
|
||||
$allowed_modes = array ( 'add', 'remove', 'modify', 'delete_dn' );
|
||||
$allowed_types = array ( 'user', 'group', 'host', '*' );
|
||||
for ($i=0; $i<count($allowed_types); $i++) {
|
||||
if ($allowed_types[$i]!='*') {
|
||||
If ($mode != '*')
|
||||
$suffix = $_SESSION['config']->get_Suffix($allowed_types[$i]);
|
||||
else $suffix = '';
|
||||
if (substr($suffix, $dn)) $singlescope = $allowed_types[$i];
|
||||
}
|
||||
}
|
||||
if (!in_array($singlescope, $allowed_types)) trigger_error(sprintf('Invalid scope. Valid scopes are %s.', implode(" ", $allowed_types)), E_USER_ERROR);
|
||||
if (!in_array($mode, $allowed_modes)) trigger_error(sprintf('Invalid mode. Valid modes are %s.', implode(" ", $allowed_modes)), E_USER_ERROR);
|
||||
// Everything seems to be OK, start processing data
|
||||
// Get Scope
|
||||
foreach ($allowed_types as $scope) {
|
||||
if ($scope!='*') {
|
||||
$suffix = $_SESSION['config']->get_Suffix($scope);
|
||||
if (strpos($dn, $suffix)) $singlescope = $scope;
|
||||
}
|
||||
}
|
||||
if (!isset($singlescope)) trigger_error(sprintf('Invalid dn: %s. DN not covered by any suffix.', $dn), E_USER_WARN);
|
||||
// Refresh Cache
|
||||
$this->refresh_cache();
|
||||
if (is_array($attributes))
|
||||
switch ($mode) {
|
||||
case 'add':
|
||||
$list = array_keys($attributes);
|
||||
for ($i=0; $i<count($list); $i++)
|
||||
foreach ($attributes[$list[$i]] as $attribute)
|
||||
$this->ldapcache[$singlescope][$dn][$list[$i]][] = $attributes[$list[$i]];
|
||||
break;
|
||||
case 'remove':
|
||||
$list = array_keys($attributes);
|
||||
for ($i=0; $i<count($list); $i++)
|
||||
foreach ($attributes[$list[$i]] as $attribute)
|
||||
if (isset($this->ldapcache[$singlescope][$dn][$list[$i]][$attributes[$list[$i]]]))
|
||||
unset($this->ldapcache[$singlescope][$dn][$list[$i]][$attributes[$list[$i]]]);
|
||||
break;
|
||||
case 'modify':
|
||||
$list = array_keys($attributes);
|
||||
for ($i=0; $i<count($list); $i++) {
|
||||
if (isset($this->ldapcache[$singlescope][$dn][$list[$i]])) unset($this->ldapcache[$singlescope][$dn][$list[$i]]);
|
||||
foreach ($attributes[$list[$i]] as $attribute)
|
||||
$this->ldapcache[$singlescope][$dn][$list[$i]][] = $attributes[$list[$i]];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($mode=='delete_dn')
|
||||
if (isset($this->ldapcache[$singlescope][$dn])) unset($this->ldapcache[$singlescope][$dn]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function will return the GID number to an existing group name (using the cache).
|
||||
|
|
|
@ -1480,7 +1480,6 @@ class accountContainer {
|
|||
if ($singleerror[0] == 'ERROR') $stopprocessing = true;
|
||||
}
|
||||
}
|
||||
// fixme *** ad update_cache after every ldap-change
|
||||
if (!$stopprocessing) {
|
||||
if ($this->dn != $this->dn_orig) {
|
||||
// move existing DN
|
||||
|
@ -1503,14 +1502,11 @@ class accountContainer {
|
|||
}
|
||||
$success = ldap_add($_SESSION['ldap']->server(), $this->dn, $attr);
|
||||
if ($success) {
|
||||
//$_SESSION['cache']->update_cache($this->dn, 'add', $attr); TODO: reactivate
|
||||
$success = ldap_delete($_SESSION['ldap']->server(), $this->dn_orig);
|
||||
if (!$success) {
|
||||
$errors[] = array('ERROR', sprintf(_('Was unable to delete DN: %s.'), $this->dn_orig), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//if ($success) TODO: reactivate
|
||||
//$_SESSION['cache']->update_cache($this->dn, 'delete_dn'); TODO: reactivate
|
||||
}
|
||||
if (!$success) {
|
||||
$errors[] = array('ERROR', sprintf(_('Was unable to create DN: %s.'), $this->dn), ldap_error($_SESSION['ldap']->server()));
|
||||
|
@ -1528,8 +1524,6 @@ class accountContainer {
|
|||
$errors[] = array('ERROR', sprintf(_('Was unable to create DN: %s.'), $this->dn), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else TODO: reactivate
|
||||
//$_SESSION['cache']->update_cache($this->dn, 'add', $attr); TODO: reactivate
|
||||
}
|
||||
unset($attributes[$this->dn]);
|
||||
}
|
||||
|
@ -1544,8 +1538,6 @@ class accountContainer {
|
|||
$errors[] = array('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else TODO: reactivate
|
||||
//$_SESSION['cache']->update_cache($this->dn, 'modify', $attributes[$this->dn]['modify']); TODO: reactivate
|
||||
}
|
||||
// add attributes
|
||||
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
|
||||
|
@ -1554,8 +1546,6 @@ class accountContainer {
|
|||
$errors[] = array('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else TODO: reactivate
|
||||
//$_SESSION['cache']->update_cache($this->dn, 'add', $attributes[$this->dn]['add']); TODO: reactivate
|
||||
}
|
||||
// removce attributes
|
||||
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
|
||||
|
@ -1564,8 +1554,6 @@ class accountContainer {
|
|||
$errors[] = array('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else TODO: reactivate
|
||||
//$_SESSION['cache']->update_cache($this->dn, 'remove', $attributes[$this->dn]['remove']); TODO: reactivate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1574,7 +1562,7 @@ class accountContainer {
|
|||
foreach ($attributes as $DN) {
|
||||
if (is_array($DN['lamdaemon']['command'])) $result = lamdaemon($DN['lamdaemon']['command']);
|
||||
// Error somewhere in lamdaemon
|
||||
if (is_array($result))
|
||||
if (is_array($result)) {
|
||||
foreach ($result as $singleresult) {
|
||||
if (is_array($singleresult)) {
|
||||
if ($singleresult[0] == 'ERROR') $stopprocessing = true;
|
||||
|
@ -1586,7 +1574,8 @@ class accountContainer {
|
|||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['cache']->refresh_cache(true); // TODO: remove when update_cache is fixed
|
||||
}
|
||||
$_SESSION['cache']->refresh_cache(true);
|
||||
if (count($errors)!=0) return $errors;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -890,7 +890,7 @@ class inetOrgPerson extends baseModule {
|
|||
}
|
||||
// uid
|
||||
// get list of existing users
|
||||
$dnUsers = $_SESSION['cache']->get_cache('uid', 'inetOrgPerson', '*');
|
||||
$dnUsers = $_SESSION['cache']->get_cache('uid', 'inetOrgPerson', 'user');
|
||||
$existingUsers = array();
|
||||
foreach ($dnUsers as $dn) {
|
||||
$existingUsers[] = $dn[0];
|
||||
|
|
|
@ -645,7 +645,7 @@ class posixAccount extends baseModule {
|
|||
$minID = intval($this->moduleSettings['posixAccount_minMachine'][0]);
|
||||
$maxID = intval($this->moduleSettings['posixAccount_maxMachine'][0]);
|
||||
}
|
||||
$dn_uids = $_SESSION['cache']->get_cache('uidNumber', 'posixAccount', '*');
|
||||
$dn_uids = $_SESSION['cache']->get_cache('uidNumber', 'posixAccount', array('user', 'host'));
|
||||
// get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... )
|
||||
if(is_array($dn_uids)) {
|
||||
foreach ($dn_uids as $uid) $uids[] = $uid[0];
|
||||
|
@ -745,11 +745,11 @@ class posixAccount extends baseModule {
|
|||
// Create automatic useraccount with number if original user already exists
|
||||
// Reset name to original name if new name is in use
|
||||
// Set username back to original name if new username is in use
|
||||
if ($_SESSION['cache']->in_cache($this->attributes['uid'][0],'uid', '*') && ($this->orig['uid'][0]!=''))
|
||||
if ($_SESSION['cache']->in_cache($this->attributes['uid'][0],'uid', array('user', 'host')) && ($this->orig['uid'][0]!=''))
|
||||
$this->attributes['uid'][0] = $this->orig['uid'][0];
|
||||
// Change uid to a new uid until a free uid is found
|
||||
else
|
||||
while ($_SESSION['cache']->in_cache($this->attributes['uid'][0], 'uid', '*')) {
|
||||
while ($_SESSION['cache']->in_cache($this->attributes['uid'][0], 'uid', array('user', 'host'))) {
|
||||
if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = substr($this->attributes['uid'][0], 0, -1);
|
||||
// get last character of username
|
||||
$lastchar = substr($this->attributes['uid'][0], strlen($this->attributes['uid'][0])-1, 1);
|
||||
|
@ -1203,7 +1203,7 @@ class posixAccount extends baseModule {
|
|||
$triggered_messages = array();
|
||||
$needAutoUID = array();
|
||||
// get list of existing users
|
||||
$dnUsers = $_SESSION['cache']->get_cache('uid', 'posixAccount', '*');
|
||||
$dnUsers = $_SESSION['cache']->get_cache('uid', 'posixAccount', array('user', 'host'));
|
||||
$existingUsers = array();
|
||||
foreach ($dnUsers as $dn) {
|
||||
$existingUsers[] = $dn[0];
|
||||
|
@ -1534,7 +1534,7 @@ class posixAccount extends baseModule {
|
|||
$minID = intval($this->moduleSettings['posixAccount_minMachine'][0]);
|
||||
$maxID = intval($this->moduleSettings['posixAccount_maxMachine'][0]);
|
||||
}
|
||||
$dn_uids = $_SESSION['cache']->get_cache('uidNumber', 'posixAccount', '*');
|
||||
$dn_uids = $_SESSION['cache']->get_cache('uidNumber', 'posixAccount', array('user', 'host'));
|
||||
// get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... )
|
||||
$uids = array();
|
||||
if(is_array($dn_uids)) {
|
||||
|
|
|
@ -795,7 +795,7 @@ class posixGroup extends baseModule {
|
|||
if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME 'posixAccount'")) $line = $i;
|
||||
}
|
||||
if ($line!=-1) {
|
||||
$result = $_SESSION['cache']->get_cache('gidNumber', 'posixAccount', '*');
|
||||
$result = $_SESSION['cache']->get_cache('gidNumber', 'posixAccount', array('user', 'host'));
|
||||
if (is_array($result)) {
|
||||
$DNs = array_keys($result);
|
||||
for ($i=0; $i<count($DNs); $i++)
|
||||
|
@ -808,7 +808,7 @@ class posixGroup extends baseModule {
|
|||
if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME 'sambaAccount'")) $line = $i;
|
||||
}
|
||||
if ($line!=-1) {
|
||||
$result = $_SESSION['cache']->get_cache('primaryGroupID', 'sambaAccount', '*');
|
||||
$result = $_SESSION['cache']->get_cache('primaryGroupID', 'sambaAccount', array('user', 'host'));
|
||||
if (is_array($result)) {
|
||||
$DNs = array_keys($result);
|
||||
for ($i=0; $i<count($DNs); $i++) {
|
||||
|
@ -822,7 +822,7 @@ class posixGroup extends baseModule {
|
|||
if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME 'sambaSamAccount'")) $line = $i;
|
||||
}
|
||||
if ($line!=-1) {
|
||||
$result = $_SESSION['cache']->get_cache('sambaPrimaryGroupSID', 'sambaSamAccount', '*');
|
||||
$result = $_SESSION['cache']->get_cache('sambaPrimaryGroupSID', 'sambaSamAccount', array('user', 'host'));
|
||||
if (is_array($result)) {
|
||||
$DNs = array_keys($result);
|
||||
for ($i=0; $i<count($DNs); $i++) {
|
||||
|
@ -853,7 +853,7 @@ class posixGroup extends baseModule {
|
|||
$ret = array();
|
||||
$minID = intval($this->moduleSettings['posixGroup_minGID'][0]);
|
||||
$maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]);
|
||||
$dn_gids = $_SESSION['cache']->get_cache('gidNumber', 'posixGroup', '*');
|
||||
$dn_gids = $_SESSION['cache']->get_cache('gidNumber', 'posixGroup', 'group');
|
||||
// get_cache will return an array ( dn1 => array(gidnumber1), dn2 => array(gidnumber2), ... )
|
||||
$gids = array();
|
||||
if(is_array($dn_gids)) {
|
||||
|
|
|
@ -175,7 +175,6 @@ if ($_POST['delete']) {
|
|||
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else $_SESSION['cache']->update_cache($DNs[$i], 'modify', $attributes[$DNs[$i]]['modify']); TODO: reactivate
|
||||
}
|
||||
// add attributes
|
||||
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
|
||||
|
@ -184,7 +183,6 @@ if ($_POST['delete']) {
|
|||
$errors[] = array ('ERROR', sprintf(_('Was unable to add attribtues to DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else $_SESSION['cache']->update_cache($DNs[$i], 'add', $attributes[$DNs[$i]]['add']); TODO: reactivate
|
||||
}
|
||||
// removce attributes
|
||||
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
|
||||
|
@ -193,7 +191,6 @@ if ($_POST['delete']) {
|
|||
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $DNs[$i]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else $_SESSION['cache']->update_cache($DNs[$i], 'remove', $attributes[$DNs[$i]]['remove']); TODO: reactivate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,8 +218,6 @@ if ($_POST['delete']) {
|
|||
$errors[] = array ('ERROR', sprintf(_('Was unable to delete DN: %s.'), $_SESSION['delete_dn'][$m]), ldap_error($_SESSION['ldap']->server()));
|
||||
$stopprocessing = true;
|
||||
}
|
||||
//else TODO: reactivate
|
||||
//$_SESSION['cache']->update_cache($_SESSION['delete_dn'][$m], 'delete_dn'); TODO: reactivate
|
||||
}
|
||||
if (!$stopprocessing) {
|
||||
echo sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "<br>\n";
|
||||
|
@ -235,7 +230,7 @@ if ($_POST['delete']) {
|
|||
echo "<br>\n";
|
||||
}
|
||||
}
|
||||
$_SESSION['cache']->refresh_cache(true); // TODO: remove when update_cache is fixed
|
||||
$_SESSION['cache']->refresh_cache(true);
|
||||
echo "<br>\n";
|
||||
echo "<br><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\">\n";
|
||||
echo "</fieldset>\n";
|
||||
|
|
Loading…
Reference in New Issue