From 91274868943fccff2ba43d171598c70d2f64ca18 Mon Sep 17 00:00:00 2001 From: katagia Date: Wed, 8 Sep 2004 10:58:56 +0000 Subject: [PATCH] it's no possible again to create a group. But something strange is going on when trying to edit a group --- lam/lib/cache.inc | 25 +++++----- lam/lib/modules.inc | 36 +++++++------- lam/lib/modules/posixGroup.inc | 68 +++++++++++++++------------ lam/lib/modules/sambaGroupMapping.inc | 2 + 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/lam/lib/cache.inc b/lam/lib/cache.inc index 64f4b98e..2514cdee 100644 --- a/lam/lib/cache.inc +++ b/lam/lib/cache.inc @@ -241,11 +241,9 @@ class cache { for ($i=0; $i"; // *** fixme, where is get_DomainSuffix If ($scope != '*') //eval($function); - $suffix = call_user_func(array($$this->config, 'get_'.ucfirst($allowed_types[$i]).'Suffix')); + $suffix = call_user_func(array($this->config, 'get_'.ucfirst($allowed_types[$i]).'Suffix')); else $suffix = ''; if (substr($suffix, $dn)) $singlescope = $allowed_types[$i]; } @@ -255,10 +253,12 @@ class cache { // Everything seems to be OK, start processing data // Get Scope foreach ($allowed_types as $scope) { - $function = '$suffix = $this->config->get_'.ucfirst($scope).'Suffix();'; + //$function = '$suffix = $this->config->get_'.ucfirst($scope).'Suffix();'; //eval($function); - $suffix = call_user_func(array($$this->config, 'get_'.ucfirst($scope).'Suffix')); - if (strpos($dn, $suffix)) $singlescope = $scope; + if ($scope!='*') { + $suffix = call_user_func(array($this->config, 'get_'.ucfirst($scope).'Suffix')); + 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 @@ -326,12 +326,15 @@ class cache { */ function getgrnam($gidNumber) { $dn_groups = $_SESSION['cache']->get_cache('gidNumber', 'posixGroup', 'group'); - $DNs = array_keys($dn_groups); - foreach ($DNs as $DN) { - if ($dn_groups[$DN][0]==$gidNumber) - $return = substr($DN, 3, strpos($DN, ',')-3); + if (is_array($dn_groups)) { + $DNs = array_keys($dn_groups); + foreach ($DNs as $DN) { + if ($dn_groups[$DN][0]==$gidNumber) + $return = substr($DN, 3, strpos($DN, ',')-3); + } + return $return; } - return $return; + else return -1; } } diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 210d1d0f..8a89159b 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -338,7 +338,7 @@ function getAvailablePDFFields($scope) { * @return array Available scopes */ function getAvailableScopes() { - return array('user','group','host'); + return array('user','group','host', 'domain'); } /** @@ -356,8 +356,7 @@ class accountContainer { if (!is_string($type)) trigger_error(_('Argument of accountContainer must be string.'), E_USER_ERROR); if (!is_string($base)) trigger_error(_('Argument of accountContainer must be string.'), E_USER_ERROR); // *** fixme use global variable to determine allowed types - $allowed_types = array ( 'user', 'group', 'host', 'domain' ); - if (!in_array($type, $allowed_types)) trigger_error(_('Account type not recognized.'), E_USER_ERROR); + if (!in_array($type, getAvailableScopes())) trigger_error(_('Account type not recognized.'), E_USER_ERROR); $this->type = $type; $this->base = $base; // Name of variables in session @@ -1156,9 +1155,6 @@ class accountContainer { } } } - print $this->dn; - print $this->dn_orig; - print_r($attributes); // Complete dn with uid or cn= if ($this->type=='group') $search = 'cn'; else $search = 'uid'; @@ -1200,16 +1196,17 @@ class accountContainer { } // fixme *** ad update_cache after every ldap-change + print_r($attributes); if (!$stopprocessing) { if ($this->dn != $this->dn_orig) { // move existing DN if ($this->dn_orig!='') { // merge attributes together $attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); - $success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr); + $success = ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr); if ($success) { $_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attr); - $success = @ldap_delete($_SESSION[$this->ldap]->server(), $this->dn_orig); + $success = ldap_delete($_SESSION[$this->ldap]->server(), $this->dn_orig); if (!$success) { $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to delete dn: %s.'), $this->dn_orig)); $stopprocessing = true; @@ -1224,16 +1221,14 @@ class accountContainer { } // create complete new dn else { - print "XXXXXXXX"; $attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); - print_r($attribtues); - $success = ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attributes[$this->dn]['add']); + $success = ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr); if (!$success) { $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn)); $stopprocessing = true; } else - $_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attributes[$this->dn]['add']); + $_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attr); } unset($attributes[$this->dn]); } @@ -1278,15 +1273,16 @@ class accountContainer { foreach ($attributes as $DN) { if (is_array($DN['lamdaemon']['command'])) $result = $this->lamdaemon($DN['lamdaemon']['command']); // Error somewhere in lamdaemon - foreach ($result as $singleresult) { - if (is_array($singleresult)) { - if ($singleresult[0] = 'ERROR') $stopprocessing = true; - $temparray[0] = $singleresult[0]; - $temparray[1] = _($singleresult[1]); - $temparray[2] = _($singleresult[2]); - $errors[] = $temparray; + if (is_array($result)) + foreach ($result as $singleresult) { + if (is_array($singleresult)) { + if ($singleresult[0] = 'ERROR') $stopprocessing = true; + $temparray[0] = $singleresult[0]; + $temparray[1] = _($singleresult[1]); + $temparray[2] = _($singleresult[2]); + $errors[] = $temparray; + } } - } } } if (count($errors)!=0) return $errors; diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index d5db31b5..c8366e11 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -343,18 +343,20 @@ class posixGroup extends baseModule { // Remove primary group from users from memberUid $users_dn = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('gidNumber', 'posixAccount', 'user'); - $DNs = array_keys($users_dn); - for ($i=0; $iattributes['gidNumber'][0]) { - $thisuser = substr($DNs[$i], 4, strpos($DNs[$i], ",")-4); - if (@in_array($thisuser, $this->attribtues['memberUid'])) { - $this->attribtues['memberUid'] = @array_flip($this->attribtues['memberUid']); - unset($this->attribtues['memberUid'][$thisuser]); - $this->attribtues['memberUid'] = @array_flip($this->attribtues['memberUid']); + if (is_array($users_dn)) { + $DNs = array_keys($users_dn); + for ($i=0; $iattributes['gidNumber'][0]) { + $thisuser = substr($DNs[$i], 4, strpos($DNs[$i], ",")-4); + if (@in_array($thisuser, $this->attribtues['memberUid'])) { + $this->attribtues['memberUid'] = @array_flip($this->attribtues['memberUid']); + unset($this->attribtues['memberUid'][$thisuser]); + $this->attribtues['memberUid'] = @array_flip($this->attribtues['memberUid']); + } } } } - + // Change gids of users and hosts? if ($this->changegids) { // get gidNumber @@ -401,6 +403,8 @@ class posixGroup extends baseModule { } } + // Add ObjectClass + $return[$_SESSION[$this->base]->dn]['notchanged']['objectClass'][0] = 'posixGroup'; return $return; } @@ -443,8 +447,10 @@ class posixGroup extends baseModule { $maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]); $dn_gids = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('gidNumber', 'posixGroup', '*'); // get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) - foreach ($dn_gids as $gid) $gids[] = $gid[0]; - if(is_array($gids)) sort ($gids, SORT_NUMERIC); + if(is_array($dn_gids)) { + foreach ($dn_gids as $gid) $gids[] = $gid[0]; + sort ($gids, SORT_NUMERIC); + } if ($this->attributes['gidNumber'][0]=='') { // No id-number given if ($this->orig['gidNumber'][0]=='') { @@ -628,29 +634,31 @@ class posixGroup extends baseModule { function display_html_user($post, $profile=false) { // load list with all groups $dn_users = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('uid', 'posixAccount', 'user'); - foreach ($dn_users as $user) $users[] = $user[0]; - // sort groups - sort($users, SORT_STRING); - // remove groups the user is member of from grouplist - $users = array_delete($this->attributes['memberUid'], $users); - // Remove primary group from grouplist - $users_dn = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('gidNumber', 'posixAccount', 'user'); - $DNs = array_keys($users_dn); - for ($i=0; $iattributes['gidNumber'][0]) { - $thisuser = substr($DNs[$i], 4, strpos($DNs[$i], ",")-4); - if (in_array($thisuser, $users)) { - $users = @array_flip($users); - unset($users[$thisuser]); - $users = @array_flip($users); + if (is_array($dn_users)) { + foreach ($dn_users as $user) $users[] = $user[0]; + // sort groups + sort($users, SORT_STRING); + // remove groups the user is member of from grouplist + $users = array_delete($this->attributes['memberUid'], $users); + // Remove primary group from grouplist + $users_dn = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('gidNumber', 'posixAccount', 'user'); + $DNs = array_keys($users_dn); + for ($i=0; $iattributes['gidNumber'][0]) { + $thisuser = substr($DNs[$i], 4, strpos($DNs[$i], ",")-4); + if (in_array($thisuser, $users)) { + $users = @array_flip($users); + unset($users[$thisuser]); + $users = @array_flip($users); + } } } + // sort users + sort($users); } - // sort users - sort($users); - + $return[] = array ( 0 => array ( 'kind' => 'fieldset', 'legend' => _("Group members"), 'value' => - array ( 0 => array ( 0 => array ('kind' => 'fieldset', 'td' => array ('valign' => 'top'), 'legend' => _("Selected userss"), 'value' => + array ( 0 => array ( 0 => array ('kind' => 'fieldset', 'td' => array ('valign' => 'top'), 'legend' => _("Selected users"), 'value' => array ( 0 => array ( 0 => array ( 'kind' => 'select', 'name' => 'removeusers[]', 'size' => '15', 'multiple', 'options' => $this->attributes['memberUid'])))), 1 => array ( 'kind' => 'table', 'value' => array ( 0 => array ( 0 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'addusers_button', 'value' => '<=')), 1 => array ( 0 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'removeusers_button', 'value' => '=>' )), diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc index 0448fe5d..f1fefde2 100644 --- a/lam/lib/modules/sambaGroupMapping.inc +++ b/lam/lib/modules/sambaGroupMapping.inc @@ -229,6 +229,8 @@ class sambaGroupMapping extends baseModule { if (!$wrid) $this->attributes['sambaSID'][0] == $SID."-".($_SESSION[$this->base]->module['posixGroup']->attributes['gidNumber'][0]*2+1+$RIDbase); $return = $_SESSION[$this->base]->save_module_attributes($this->attributes, $this->orig); + // Add ObjectClass + $return[$_SESSION[$this->base]->dn]['notchanged']['objectClass'][0] = 'sambaGroupMapping'; return $return; }