diff --git a/lam/HISTORY b/lam/HISTORY
index 67c64281..1af13e75 100644
--- a/lam/HISTORY
+++ b/lam/HISTORY
@@ -2,6 +2,7 @@ December 2010 3.3.0
- additional usability enhancements
- new IMAP module ("Mailbox (imapAccess)") allows to create/delete user mailboxes
- PDF export: higher resolution for logos
+ - reduced number of LDAP queries
- fixed bugs:
-> ignore comment lines in shells file (3107124)
diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc
index bb8262da..b0a5a79a 100644
--- a/lam/lib/modules/sambaGroupMapping.inc
+++ b/lam/lib/modules/sambaGroupMapping.inc
@@ -44,6 +44,8 @@ class sambaGroupMapping extends baseModule {
private $rids;
/** Array of sambaGroupTypes */
private $sambaGroupTypes;
+ /** cache for domain list */
+ private $cachedDomainList = null;
/**
* Creates a new module for Samba 3 groups.
@@ -113,6 +115,46 @@ class sambaGroupMapping extends baseModule {
return null;
}
+ /**
+ * Returns an array containing all input columns for the file upload.
+ *
+ * Calling this method does not require the existence of an enclosing {@link accountContainer}.
+ *
+ * This funtion returns an array which contains subarrays which represent an upload column.
+ * Syntax of column arrays:
+ *
+ *
array(
+ *
string: name, // fixed non-translated name which is used as column name (should be of format: _)
+ *
string: description, // short descriptive name
+ *
string: help, // help ID
+ *
string: example, // example value
+ *
string: values, // possible input values (optional)
+ *
string: default, // default value (optional)
+ *
boolean: required // true, if user must set a value for this column
+ *
boolean: unique // true if all values of this column must be different values (optional, default: "false")
+ *
)
+ *
+ * @param array $selectedModules list of selected account modules
+ * @return array column list
+ *
+ * @see baseModule::get_metaData()
+ */
+ public function get_uploadColumns($selectedModules) {
+ $return = parent::get_uploadColumns($selectedModules);
+ $domains = $this->getDomains();
+ $domainNames = array();
+ for ($i = 0; $i < sizeof($domains); $i++) $domainNames[] = $domains[$i]->name;
+ $return[] = array(
+ 'name' => 'sambaGroupMapping_domain',
+ 'description' => _('Samba domain name'),
+ 'help' => 'sambaDomainName',
+ 'example' => $domainNames[0],
+ 'values' => implode(", ", $domainNames),
+ 'required' => true
+ );
+ return $return;
+ }
+
/**
* In this function the LDAP account is built up.
*
@@ -124,7 +166,7 @@ class sambaGroupMapping extends baseModule {
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
// search existing Samba 3 domains
- $domains = search_domains();
+ $domains = $this->getDomains();
$nameToSID = array();
// get domain SIDs
for ($i = 0; $i < sizeof($domains); $i++) {
@@ -198,7 +240,7 @@ class sambaGroupMapping extends baseModule {
}
$return = new htmlTable();
if (in_array('sambaGroupMapping', $this->attributes['objectClass'])) {
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
if (sizeof($sambaDomains) == 0) {
StatusMessage("ERROR", _('No Samba 3 domains found in LDAP! Please create one first.'), '');
return array();
@@ -285,18 +327,7 @@ class sambaGroupMapping extends baseModule {
// upload fields
// search existing Samba 3 domains
if (isset($_SESSION['loggedIn']) && ($_SESSION['loggedIn'] === true)) {
- $domains = search_domains();
- $domainNames = array();
- for ($i = 0; $i < sizeof($domains); $i++) $domainNames[] = $domains[$i]->name;
$return['upload_columns'] = array(
- array(
- 'name' => 'sambaGroupMapping_domain',
- 'description' => _('Samba domain name'),
- 'help' => 'sambaDomainName',
- 'example' => $domainNames[0],
- 'values' => implode(", ", $domainNames),
- 'required' => true
- ),
array(
'name' => 'sambaGroupMapping_name',
'description' => _('Samba display name'),
@@ -373,7 +404,7 @@ class sambaGroupMapping extends baseModule {
function get_profileOptions() {
$return = new htmlTable();
// get list of domains
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
$sambaDomainNames = array();
for ($i = 0; $i < count($sambaDomains); $i++ ) {
// extract names
@@ -393,7 +424,7 @@ class sambaGroupMapping extends baseModule {
function load_profile($profile) {
if (isset($profile['sambaGroupMapping_sambaDomainName'][0])) {
// get list of domains
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
for ($i = 0; $i < sizeof($sambaDomains); $i++) {
if ($sambaDomains[$i]->name == $profile['sambaGroupMapping_sambaDomainName'][0]) {
$this->attributes['sambaSID'][0] = $sambaDomains[$i]->SID . "-0";
@@ -453,7 +484,7 @@ class sambaGroupMapping extends baseModule {
return array();
}
$errors = array();
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
if (sizeof($sambaDomains) == 0) {
return array();
}
@@ -514,6 +545,19 @@ class sambaGroupMapping extends baseModule {
}
return $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig);
}
+
+ /**
+ * Returns a list of existing Samba 3 domains.
+ *
+ * @return array list of samba3domain objects
+ */
+ private function getDomains() {
+ if ($this->cachedDomainList != null) {
+ return $this->cachedDomainList;
+ }
+ $this->cachedDomainList = search_domains();
+ return $this->cachedDomainList;
+ }
}
diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc
index 742e5714..d10f1d23 100644
--- a/lam/lib/modules/sambaSamAccount.inc
+++ b/lam/lib/modules/sambaSamAccount.inc
@@ -59,6 +59,8 @@ class sambaSamAccount extends baseModule implements passwordService {
/* cache to reduce LDAP queries */
private $cachedHostList = null;
private $cachedGroupSIDList = null;
+ /** cache for domain list */
+ private $cachedDomainList = null;
/**
@@ -711,7 +713,7 @@ class sambaSamAccount extends baseModule implements passwordService {
}
}
$errors = array();
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
if (sizeof($sambaDomains) == 0) {
return array();
}
@@ -1025,7 +1027,7 @@ class sambaSamAccount extends baseModule implements passwordService {
}
}
// Get Domain SID from user SID
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
if (sizeof($sambaDomains) == 0) {
$return->addElement(new htmlStatusMessage("ERROR", _('No Samba 3 domains found in LDAP! Please create one first.')), true);
return $return;
@@ -1497,7 +1499,7 @@ class sambaSamAccount extends baseModule implements passwordService {
$return->addElement(new htmlTableExtendedInputField(_('Samba workstations'), 'sambaSamAccount_userWorkstations', '', 'workstations'), true);
}
// domains
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
$sambaDomainNames = array();
for ($i = 0; $i < count($sambaDomains); $i++) {
$sambaDomainNames[] = $sambaDomains[$i]->name;
@@ -1519,7 +1521,7 @@ class sambaSamAccount extends baseModule implements passwordService {
}
elseif ($this->get_scope() == 'host') {
// domains
- $sambaDomains = search_domains();
+ $sambaDomains = $this->getDomains();
$sambaDomainNames = array();
for ($i = 0; $i < count($sambaDomains); $i++) {
$sambaDomainNames[] = $sambaDomains[$i]->name;
@@ -1582,7 +1584,7 @@ class sambaSamAccount extends baseModule implements passwordService {
// domain -> change SID
if (isset($this->attributes['sambaSID'][0])) {
if (isset($profile['sambaSamAccount_sambaDomainName'][0]) && ($profile['sambaSamAccount_sambaDomainName'][0] != "")) {
- $domains = search_domains();
+ $domains = $this->getDomains();
$domSID = '';
// find domain SID
for ($i = 0; $i < sizeof($domains); $i++) {
@@ -1602,7 +1604,7 @@ class sambaSamAccount extends baseModule implements passwordService {
}
// primary group
if (isset($profile['sambaSamAccount_sambaDomainName'][0])) {
- $domains = search_domains();
+ $domains = $this->getDomains();
$domSID = '';
// find domain SID
for ($i = 0; $i < sizeof($domains); $i++) {
@@ -1731,7 +1733,7 @@ class sambaSamAccount extends baseModule implements passwordService {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$errors = array();
// get list of Samba 3 domains
- $domains = search_domains();
+ $domains = $this->getDomains();
// get list of Unix groups and their sambaSID + gidNumber
$groupList = searchLDAPByFilter('objectClass=posixGroup', array('cn', 'sambaSID', 'gidNumber'), array('group'));
$groups_cn = array();
@@ -2222,6 +2224,19 @@ class sambaSamAccount extends baseModule implements passwordService {
return $this->cachedGroupSIDList;
}
+ /**
+ * Returns a list of existing Samba 3 domains.
+ *
+ * @return array list of samba3domain objects
+ */
+ private function getDomains() {
+ if ($this->cachedDomainList != null) {
+ return $this->cachedDomainList;
+ }
+ $this->cachedDomainList = search_domains();
+ return $this->cachedDomainList;
+ }
+
}
?>