From 6c40ab33d74b1ff5b41cd518434278363038bdfe Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 15 Mar 2008 19:12:19 +0000 Subject: [PATCH] allow to add a user as memberuid in his primary group --- lam/lib/modules/posixAccount.inc | 67 ++++++++++++++++++++++++-------- lam/lib/modules/posixGroup.inc | 52 ++++++++++++++----------- 2 files changed, 79 insertions(+), 40 deletions(-) diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 9de91a55..72bfd23d 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -153,13 +153,13 @@ class posixAccount extends baseModule { ); // configuration options $return['config_options']['user'] = array( - array( - array('kind' => 'text', 'text' => '' . _("Users") . ':  ' . _('Minimum UID number') . "*: "), - array('kind' => 'input', 'name' => 'posixAccount_minUID', 'type' => 'text', 'size' => '10', 'maxlength' => '255'), - array('kind' => 'text', 'value' => ' '), - array('kind' => 'text', 'text' => _('Maximum UID number') . "*: "), - array('kind' => 'input', 'name' => 'posixAccount_maxUID', 'type' => 'text', 'size' => '10', 'maxlength' => '255'), - array('kind' => 'help', 'value' => 'minMaxUser')) + array( + array('kind' => 'text', 'text' => '' . _("Users") . ':  ' . _('Minimum UID number') . "*: "), + array('kind' => 'input', 'name' => 'posixAccount_minUID', 'type' => 'text', 'size' => '10', 'maxlength' => '255'), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'text', 'text' => _('Maximum UID number') . "*: "), + array('kind' => 'input', 'name' => 'posixAccount_maxUID', 'type' => 'text', 'size' => '10', 'maxlength' => '255'), + array('kind' => 'help', 'value' => 'minMaxUser')) ); $return['config_options']['host'] = array( array( @@ -171,14 +171,21 @@ class posixAccount extends baseModule { array('kind' => 'help', 'value' => 'minMaxHost')) ); $return['config_options']['all'] = array( - array( - array('kind' => 'text', 'text' => '' . _("Password hash type") . ':  '), - array('kind' => 'select', 'name' => 'posixAccount_pwdHash', 'size' => '1', - 'options' => array("CRYPT", "SHA", "SSHA", "MD5", "SMD5", "PLAIN"), 'options_selected' => array('SSHA')), - array('kind' => 'text', 'value' => ' '), - array('kind' => 'text', 'value' => ' '), - array('kind' => 'text', 'value' => ' '), - array('kind' => 'help', 'value' => 'pwdHash')) + array( + array('kind' => 'text', 'text' => '' . _("Password hash type") . ':  '), + array('kind' => 'select', 'name' => 'posixAccount_pwdHash', 'size' => '1', + 'options' => array("CRYPT", "SHA", "SSHA", "MD5", "SMD5", "PLAIN"), 'options_selected' => array('SSHA')), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'help', 'value' => 'pwdHash')), + array( + array('kind' => 'text', 'text' => '' . _('Set primary group as memberUid') . ": "), + array('kind' => 'input', 'name' => 'posixAccount_primaryGroupAsSecondary', 'type' => 'checkbox'), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'text', 'value' => ' '), + array('kind' => 'help', 'value' => 'primaryGroupAsSecondary')) ); // upload $return['upload_preDepends'] = array('inetOrgPerson'); @@ -320,6 +327,10 @@ class posixAccount extends baseModule { ); // help Entries $return['help'] = array( + 'primaryGroupAsSecondary' => array( + 'Headline' => _('Set primary group as memberUid'), + 'Text' => _('Usually, users are not added to groups as memberUid if they have this group as primary group. If your application ignores primary groups then you can select this option to override this behaviour.') + ), 'minMaxUser' => array( 'Headline' => _('UID number'), 'Text' => _('These are the minimum and maximum numbers to use for user IDs when creating new user accounts. The range should be different from that of machines. New user accounts will always get the highest number in use plus one.') @@ -488,8 +499,17 @@ class posixAccount extends baseModule { function save_attributes() { $return = $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig); // Remove primary group from additional groups - for ($i=0; $igroups); $i++) { - if ($this->groups[$i]==$_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0])) unset($this->groups[$i]); + if (!isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0]) + || ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] != 'true')) { + for ($i=0; $igroups); $i++) { + if ($this->groups[$i]==$_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0])) unset($this->groups[$i]); + } + } + else { + // add user as memberuid in primary group + if (!in_array($_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0]), $this->groups)) { + $this->groups[] = $_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0]); + } } // Set additional group memberships @@ -1540,6 +1560,19 @@ class posixAccount extends baseModule { if (in_array($i, $failed)) continue; // ignore failed accounts if ($data[$i][$col] != "") { $groups = explode(",", $data[$i][$col]); + if (isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0]) + && ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] == 'true')) { + if (get_preg($data[$i][$ids['posixAccount_group']], 'digit')) { + if (!in_array(getgrnam($data[$i][$ids['posixAccount_group']]), $groups)) { + $groups[] = getgrnam($data[$i][$ids['posixAccount_group']]); + } + } + else { + if (!in_array(getgrnam($data[$i][$ids['posixAccount_group']]), $groups)) { + $groups[] = $data[$i][$ids['posixAccount_group']]; + } + } + } for ($g = 0; $g < sizeof($groups); $g++) { if (!in_array($groups[$g], $temp['groups'])) $temp['groups'][] = $groups[$g]; $temp['members'][$groups[$g]][] = $data[$i][$ids['posixAccount_userName']]; diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index ede55582..1a7439c8 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -208,7 +208,7 @@ class posixGroup extends baseModule { * @return array meta HTML output */ function display_html_user() { - // load list with all users + // load list with all users $dn_users = $_SESSION['cache']->get_cache(array('uid', 'gidNumber'), 'posixAccount', 'user'); $users = array(); if (is_array($dn_users)) { @@ -217,35 +217,41 @@ class posixGroup extends baseModule { // users who can be added have a uid and gidNumber if (isset($dn_users[$DNs[$i]]['uid'][0]) && isset($dn_users[$DNs[$i]]['gidNumber'][0]) && // are not already member - (!isset($this->attributes['memberUid']) || !in_array($dn_users[$DNs[$i]]['uid'][0], $this->attributes['memberUid'])) && - // and do not have this group as their primary group - !($this->attributes['gidNumber'][0] == $dn_users[$DNs[$i]]['gidNumber'][0])) { + (!isset($this->attributes['memberUid']) || !in_array($dn_users[$DNs[$i]]['uid'][0], $this->attributes['memberUid']))) { + if ($this->attributes['gidNumber'][0] == $dn_users[$DNs[$i]]['gidNumber'][0]) { + if (isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0]) + && ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] == 'true')) { + $users[] = $dn_users[$DNs[$i]]['uid'][0]; + } + } + else { $users[] = $dn_users[$DNs[$i]]['uid'][0]; } } } - $return[] = array( - 0 => array('kind' => 'fieldset', 'legend' => _("Group members"), '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' => true, 'options' => $this->attributes['memberUid'])))), - 1 => array('kind' => 'table', 'value' => array( - 0 => array( - 0 => array('kind' => 'input', 'type' => 'submit', 'name' => 'addusers_button', 'value' => '<=', 'td' => array('align' => 'center'))), - 1 => array( - 0 => array('kind' => 'input', 'type' => 'submit', 'name' => 'removeusers_button', 'value' => '=>', 'td' => array('align' => 'center'))), - 2 => array( - 0 => array('kind' => 'help', 'value' => 'members', 'td' => array('align' => 'center'))))), - 2 => array('kind' => 'fieldset', 'td' => array('valign' => 'top'), 'legend' => _("Available users"), 'value' => array( - 0 => array( - 0 => array('kind' => 'select', 'name' => 'addusers', 'size' => '15', 'multiple' => true, 'options' => $users)))) + } + $return[] = array( + array('kind' => 'fieldset', 'legend' => _("Group members"), 'value' => array ( + array( + array('kind' => 'fieldset', 'td' => array ('valign' => 'top'), 'legend' => _("Selected users"), 'value' => array ( + array( + array ( 'kind' => 'select', 'name' => 'removeusers', 'size' => '15', 'multiple' => true, 'options' => $this->attributes['memberUid'])))), + array('kind' => 'table', 'value' => array( + array( + array('kind' => 'input', 'type' => 'submit', 'name' => 'addusers_button', 'value' => '<=', 'td' => array('align' => 'center'))), + array( + array('kind' => 'input', 'type' => 'submit', 'name' => 'removeusers_button', 'value' => '=>', 'td' => array('align' => 'center'))), + array( + array('kind' => 'help', 'value' => 'members', 'td' => array('align' => 'center'))))), + array('kind' => 'fieldset', 'td' => array('valign' => 'top'), 'legend' => _("Available users"), 'value' => array( + array( + array('kind' => 'select', 'name' => 'addusers', 'size' => '15', 'multiple' => true, 'options' => $users)))) )))); $return[] = array( - 0 => array('kind' => 'input', 'name' => 'form_subpage_posixGroup_attributes_back' ,'type' => 'submit', 'value' => _('Back') ), - 1 => array('kind' => 'text'), - 2 => array('kind' => 'text')); + array('kind' => 'input', 'name' => 'form_subpage_posixGroup_attributes_back' ,'type' => 'submit', 'value' => _('Back') ), + array('kind' => 'text'), + array('kind' => 'text')); return $return; }