From daa51d1659f00e1ec35274b7a7e41d718c2c0486 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 22 Mar 2017 20:17:52 +0100 Subject: [PATCH] new type API --- lam/lib/modules/posixAccount.inc | 60 +++++++++++--------------------- lam/lib/modules/windowsGroup.inc | 17 +++++---- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 1b592c2c..a701821b 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -1,10 +1,11 @@ getAccountContainer()->dn_orig) && ($this->getAccountContainer()->dn_orig != $this->getAccountContainer()->finalDN)) { // update owner/member/uniqueMember attributes - $types = $_SESSION['config']->get_ActiveTypes(); - if (in_array('gon', $types)) { - $gonTypes[] = 'gon'; - } - if (in_array('group', $types)) { - $gonTypes[] = 'group'; - } - $searchAttrs = array('member', 'uniqueMember', 'owner'); + $searchAttrs = array('member', 'uniquemember', 'owner'); foreach ($searchAttrs as $searchAttr) { - $ownerGroups = searchLDAPByAttribute($searchAttr, $this->getAccountContainer()->dn_orig, null, array('dn', $searchAttr), $gonTypes); + $ownerGroups = searchLDAPByAttribute($searchAttr, $this->getAccountContainer()->dn_orig, null, array('dn', $searchAttr), array('gon', 'group')); for ($i = 0; $i < sizeof($ownerGroups); $i++) { $found = false; $newOwners = $ownerGroups[$i][$searchAttr]; @@ -910,12 +904,7 @@ class posixAccount extends baseModule implements passwordService { } // remove from group of names $dn = $this->getAccountContainer()->dn_orig; - $gonTypes = array('group'); - $types = $_SESSION['config']->get_ActiveTypes(); - if (in_array('gon', $types)) { - $gonTypes[] = 'gon'; - } - $gons = searchLDAPByFilter('(|(member=' . $dn . ')(uniqueMember=' . $dn . '))', array('member', 'uniqueMember'), $gonTypes); + $gons = searchLDAPByFilter('(|(member=' . $dn . ')(uniqueMember=' . $dn . '))', array('member', 'uniqueMember'), array('group', 'gon')); for ($i = 0; $i < sizeof($gons); $i++) { if (isset($gons[$i]['member'])) { $return[$gons[$i]['dn']]['remove']['member'][] = $dn; @@ -1516,7 +1505,9 @@ class posixAccount extends baseModule implements passwordService { $return = new htmlTable(); $return->addElement(new htmlTableExtendedInputCheckbox('deletehomedir', true, _('Delete home directory'), 'deletehomedir'), true); } - if (($this->get_scope() == 'user') && in_array('sudo', $_SESSION['config']->get_ActiveTypes())) { + $typeManager = new TypeManager(); + $sudoTypes = $typeManager->getConfiguredTypesForScope('sudo'); + if (($this->get_scope() == 'user') && !empty($sudoTypes)) { if ($return == null) { $return = new htmlTable(); } @@ -3025,29 +3016,18 @@ class posixAccount extends baseModule implements passwordService { return $this->gonCache; } $return = array(); - $types = array(); - if (in_array('group', $_SESSION['config']->get_ActiveTypes())) { - $types[] = 'group'; - } - if (in_array('gon', $_SESSION['config']->get_ActiveTypes())) { - $types[] = 'gon'; - } - $typeSettings = $_SESSION['config']->get_typeSettings(); - if (sizeof($types) > 0) { - foreach ($types as $type) { - $filter = '(|(objectClass=groupOfNames)(objectClass=groupOfMembers)(objectClass=groupOfUniqueNames))'; - if (!empty($typeSettings['filter_' . $type])) { - $typeFilter = $typeSettings['filter_' . $type]; - if (strpos($typeFilter, '(') !== 0) { - $typeFilter = '(' . $typeFilter . ')'; - } - $filter = '(&' . $filter . $typeFilter . ')'; - } - $results = searchLDAPByFilter($filter, array('cn', 'dn', 'objectClass'), array($type)); - for ($i = 0; $i < sizeof($results); $i++) { - if (isset($results[$i]['cn'][0]) && isset($results[$i]['dn'])) { - $return[$results[$i]['dn']] = $results[$i]; - } + $typeManager = new TypeManager(); + $types = $typeManager->getConfiguredTypesForScopes(array('gon', 'group')); + foreach ($types as $type) { + $filter = '(|(objectClass=groupOfNames)(objectClass=groupOfMembers)(objectClass=groupOfUniqueNames))'; + $typeFilter = get_ldap_filter($type->getId()); + $results = searchLDAP($type->getSuffix(), $typeFilter, array('cn', 'dn', 'objectClass')); + for ($i = 0; $i < sizeof($results); $i++) { + if ((in_array('groupOfNames', $results[$i]['objectclass']) + || in_array('groupOfMembers', $results[$i]['objectclass']) + || in_array('groupOfUniqueNames', $results[$i]['objectclass'])) + && isset($results[$i]['cn'][0])) { + $return[$results[$i]['dn']] = $results[$i]; } } } diff --git a/lam/lib/modules/windowsGroup.inc b/lam/lib/modules/windowsGroup.inc index 2e7f14cb..d37d7b30 100644 --- a/lam/lib/modules/windowsGroup.inc +++ b/lam/lib/modules/windowsGroup.inc @@ -2,6 +2,7 @@ use \LAM\PDF\PDFTable; use \LAM\PDF\PDFTableCell; use \LAM\PDF\PDFTableRow; +use \LAM\TYPES\TypeManager; /* $Id$ @@ -652,8 +653,10 @@ class windowsGroup extends baseModule { */ function display_html_user() { $return = new htmlTable(); + $typeManager = new TypeManager(); // show list of possible new members if (isset($_POST['form_subpage_' . get_class($this) . '_user_select']) && isset($_POST['type'])) { + $type = $typeManager->getConfiguredType($_POST['type']); $filterGroup = new htmlGroup(); $filterGroup->addElement(new htmlOutputText(_('Filter') . ' ')); $filter = new htmlInputField('windows_filter'); @@ -663,8 +666,8 @@ class windowsGroup extends baseModule { $return->addElement($filterGroup, true); $options = array(); - $filter = get_ldap_filter($_POST['type']); - $entries = searchLDAPByFilter($filter, array('dn'), array($_POST['type'])); + $filter = get_ldap_filter($type->getId()); + $entries = searchLDAP($type->getSuffix(), $filter, array('dn')); for ($i = 0; $i < sizeof($entries); $i++) { $entries[$i] = $entries[$i]['dn']; } @@ -719,13 +722,13 @@ class windowsGroup extends baseModule { $return->addElement($removeButton, true); $return->addElement(new htmlOutputText(' ', false), true); } - $types = $_SESSION['config']->get_ActiveTypes(); + $types = $typeManager->getConfiguredTypes(); $options = array(); $optionsSelected = array(); - for ($i = 0; $i < sizeof($types); $i++) { - $options[LAM\TYPES\getTypeAlias($types[$i])] = $types[$i]; - if ($types[$i] == 'user') { - $optionsSelected[] = $types[$i]; + foreach ($types as $type) { + $options[$type->getAlias()] = $type->getId(); + if ($type->getScope() == 'user') { + $optionsSelected[] = $type->getId(); } } $typeTable = new htmlTable();