From 93339150d73c8e0d881934cf4792310d7a783bd2 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 1 May 2006 16:13:10 +0000 Subject: [PATCH] added alias handling --- lam/docs/devel/mod_general.htm | 69 ++++++++++++------- lam/docs/devel/modules-specification.htm | 84 ++++++++++++++++-------- lam/lib/baseModule.inc | 11 ++++ lam/lib/modules.inc | 28 +++++++- lam/lib/modules/inetOrgPerson.inc | 70 +++++++++++++++----- lam/lib/modules/posixAccount.inc | 2 + lam/lib/modules/posixGroup.inc | 2 + 7 files changed, 192 insertions(+), 74 deletions(-) diff --git a/lam/docs/devel/mod_general.htm b/lam/docs/devel/mod_general.htm index c28cac1c..a3d71b4b 100644 --- a/lam/docs/devel/mod_general.htm +++ b/lam/docs/devel/mod_general.htm @@ -128,11 +128,7 @@ class
    function get_metaData() {
        $return = array();
-        // manages host accounts
-     -    $return["account_types"] = array("host");
-        // alias name
+         // alias name
        $return["alias"] = _("MAC address");
@@ -172,14 +168,7 @@ class
    function get_metaData() {
        $return = array();
-        // manages host accounts
-     -    $return["account_types"] = array("host");
-        // alias name
-        $return["alias"] = _("MAC -address");
-        // module dependencies
+         // module dependencies
        $return['dependencies'] = array('depends' => array('account'), 'conflicts' => array());
    function get_metaData() {
        $return = array();
-        // manages host accounts
-     -    $return["account_types"] = array("host");
-        // alias name
-        $return["alias"] = _("MAC -address");
-        // module dependencies
-    -    $return['dependencies'] = array('depends' => -array('account'), 'conflicts' => array());
-        // managed object classes
+         // managed object classes
        $return['objectClasses'] = array('ieee802Device');
        return $return;
@@ -277,6 +255,47 @@ array('account'), 'conflicts' => array());


+

7. Known LDAP aliases
+

+LDAP attributes can have several names (e.g. "cn" and "commonName" are +the same). If you manage such attributes then tell LAM about the alias +names.
+LAM will then convert all alias names to the given attribute names +automatically.
+
+Example:
+
+The posixGroup module manages +the "cn" attribute. This attribute is also known under the alias +"commonName".
+This way the module will never see attributes called "commonName" +because LAM renames them as soon as the LDAP entry is loaded.
+
+ + + + + + +
    /**
+    * Returns meta data that is interpreted by parent +class
+    *
+    * @return array array with meta data
+    */
+    function +get_metaData() {
+        $return = array();
+        // LDAP aliases
+     +    $return['LDAPaliases'] = array('commonName' => +'cn');
+        return $return;
+    }
+
+
+

diff --git a/lam/docs/devel/modules-specification.htm b/lam/docs/devel/modules-specification.htm index d7fa132d..e23f0f6c 100644 --- a/lam/docs/devel/modules-specification.htm +++ b/lam/docs/devel/modules-specification.htm @@ -143,7 +143,24 @@ This is used to fix spelling errors in LDAP-Entries (e.g. if Example: return "('posixAccount')"

-

2.1.6. get_RDNAttributes*

+

2.1.6. getLDAPAliases*

+
+ + + + + + +
function getLDAPAliases()
+
+
+This function returns a list of LDAP attribute alias names.
+
+return array(<alias name> => +<attribute name>)
+
+

2.1.7. get_RDNAttributes*


@@ -168,7 +185,7 @@ for the RDN selection.
'normal', 'cn' => 'low')"

-

2.1.7. get_dependencies*

+

2.1.8. get_dependencies*


@@ -198,7 +215,7 @@ your module depends on one of these modules.
=> array("exim"));

-

2.1.8. get_metaData()

+

2.1.9. get_metaData()


@@ -215,7 +232,7 @@ Returns an hash array including meta data for the baseModule.
Example: return array("is_base" => true);

-

2.1.9. get_configOptions()*

+

2.1.10. get_configOptions()*


@@ -244,7 +261,7 @@ as keywords to load and save settings. We recommend to use the module name as prefix for them (e.g. posixAccount_homeDirectory) to avoid naming confilcts.

-

2.1.10. get_configDescriptions()*

+

2.1.11. get_configDescriptions()*


@@ -269,7 +286,7 @@ array with this format:
       'descriptions' => array('option1' => 'description1', ...))

-

2.1.11. check_configOptions*

+

2.1.12. check_configOptions*


@@ -297,7 +314,7 @@ If no errors occured the function returns an empty array.

-

2.1.12. get_scope()

+

2.1.13. get_scope()


@@ -314,7 +331,7 @@ Returns the account type (user/group/host) of this module object.
This function is provided by the baseModule and should not be overwritten.

-

2.1.13. get_uploadColumns*

+

2.1.14. get_uploadColumns*


@@ -359,7 +376,7 @@ all values of this column must be different values
-

2.1.14. get_uploadPreDepends*

+

2.1.15. get_uploadPreDepends*


@@ -375,7 +392,7 @@ Returns a list of module names which must be processed before this module at builing accounts.
The named modules may not be active, LAM will check this automatically.

-

2.1.15. build_uploadAccounts

+

2.1.16. build_uploadAccounts


@@ -402,7 +419,7 @@ format is the same as used for ldap_add().
Returns an array which contains sub arrays to generate StatusMessages if any errors occured.

-

2.1.16. do_uploadPostActions

+

2.1.17. do_uploadPostActions


@@ -448,7 +465,7 @@ array()   // List of arrays which are used to generate StatusMessages
    )

-

2.1.17. get_profileOptions*

+

2.1.18. get_profileOptions*


@@ -472,7 +489,7 @@ as keywords to load and save profiles. We recommend to use the module name as prefix for them (e.g. posixAccount_homeDirectory) to avoid naming confilcts.

-

2.1.18. check_profileOptions*

+

2.1.19. check_profileOptions*


@@ -496,7 +513,7 @@ head, 2 => message text, 3 => additional variables).
If no errors occured the function returns an empty array.

-

2.1.19. load_profile*

+

2.1.20. load_profile*


@@ -515,7 +532,7 @@ internal data structures.
is an hash array (identifier => array(values))  with all values of an account profile.

-

2.1.20. getRequiredExtensions*

+

2.1.21. getRequiredExtensions*


@@ -530,9 +547,9 @@ of an account profile.
This function returns a list of PHP extensions (e.g. mhash) which are needed by this module.

+

-
-
+

2.2. Functions which are called inside of an account container

2.2.1. init

@@ -1288,8 +1305,19 @@ array("user", "host")
style="font-style: italic; font-weight: bold;"> array('posixAccount')

+

6.5 getLDAPaliases()
+

+"LDAPaliases" => array()
+
+
Example: array('commonName' +=> 'cn')
+
+
+
-

6.5 get_RDNAttributes()

+

6.6 get_RDNAttributes()

    "RDN" => array

   Example:

-

6.6 get_dependencies()
+

6.7 get_dependencies()

    "dependencies" => array

@@ -1310,7 +1338,7 @@ array("user", "host")
=> array("exim"))

-

6.7 get_profileOptions()
+

6.8 get_profileOptions()

    "profile_options" => array

@@ -1319,7 +1347,7 @@ array("user", "host")
return value of get_profileOptions().

-

6.8 check_profileOptions()
+

6.9 check_profileOptions()

    "profile_checks" => array

@@ -1394,7 +1422,7 @@ head, 2 => message text, 3 => additional variables)
-

6.9 load_profile()
+

6.10 load_profile()

    "profile_mappings" => array('profile_identifier1' => 'LDAP_attribute1', 'profile_identifier2' => 'LDAP_attribute2')
@@ -1403,7 +1431,7 @@ head, 2 => message text, 3 => additional variables) $this->attributes.

-

6.10 get_configOptions()
+

6.11 get_configOptions()

    "config_options" => array('user' => array, 'host' => array, 'all' => array)
@@ -1419,7 +1447,7 @@ the return value of get_configOptions().

-

6.11 get_configDescriptions()
+

6.12 get_configDescriptions()

    "config_descriptions" => array

@@ -1428,7 +1456,7 @@ return value of get_configOptions().
return value of get_configDescriptions().

-

6.12 check_configOptions()
+

6.13 check_configOptions()

    "config_checks" => array('user' => array, 'host' => 'array', 'all' => array)
@@ -1442,21 +1470,21 @@ the other values only if they are inside the
-

6.13 get_uploadColumns()

+

6.14 get_uploadColumns()

"upload_columns" => array()

Syntax for array is the same as for the return value of get_uploadColumns().

-

6.14 get_uploadPreDepends()

+

6.15 get_uploadPreDepends()

"upload_preDepends" => array()

Syntax for array is the same as for the return value of get_uploadPreDepends().

-

6.15 getRequiredExtensions()
+

6.16 getRequiredExtensions()

"extensions" => array()

diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index bb76ed4a..177c4ad0 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -679,6 +679,17 @@ class baseModule { else return array(); } + /** + * Returns a list of aliases for LDAP attributes. + * All alias attributes will be renamed to the given attribute names. + * + * @return array list of aliases (alias name => attribute name) + */ + function getLDAPAliases() { + if (isset($this->meta['LDAPaliases']) && is_array($this->meta['LDAPaliases'])) return $this->meta['LDAPaliases']; + else return array(); + } + /** * Returns a list of required PHP extensions. * diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index d50fa8af..bd75bf08 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1323,6 +1323,10 @@ class accountContainer { * @return array an array which can be passed to $this->saveAccount() */ function save_module_attributes($attributes, $orig) { + $toadd = array(); + $tomodify = array(); + $torem = array(); + $notchanged = array(); // Get list of all "easy" attributes $attr_names = array_keys($attributes); // Get attributes which should be added @@ -1436,14 +1440,26 @@ class accountContainer { function fixLDAPAttributes($attributes, $modules) { if (!is_array($attributes)) return $attributes; $keys = array_keys($attributes); - // get correct object class names + // get correct object class names, aliases and attributes $objectClasses = array(); + $aliases = array(); foreach ($modules as $module) { $moduleObj = new $module($this->type); $objectClasses = array_merge($objectClasses, $moduleObj->getManagedObjectClasses()); + $aliases = array_merge($aliases, $moduleObj->getLDAPAliases()); } - // check object classes + // convert alias names to lower case (for easier comparison) + $aliasKeys = array_keys($aliases); + for ($i = 0; $i < sizeof($aliasKeys); $i++) { + if ($aliasKeys[$i] != strtolower($aliasKeys[$i])) { + $aliases[strtolower($aliasKeys[$i])] = $aliases[$aliasKeys[$i]]; + unset($aliases[$aliasKeys[$i]]); + $aliasKeys[$i] = strtolower($aliasKeys[$i]); + } + } + // fix object classes and attributes for ($i = 0; $i < sizeof($keys); $i++) { + // check object classes if (strtolower($keys[$i]) == 'objectclass') { // fix object class attribute if ($keys[$i] != 'objectClass') { @@ -1463,7 +1479,13 @@ class accountContainer { } } } - break; + } + else { + // fix aliases + if (in_array(strtolower($keys[$i]), $aliasKeys)) { + $attributes[$aliases[strtolower($keys[$i])]] = $attributes[$keys[$i]]; + unset($attributes[$keys[$i]]); + } } } return $attributes; diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index c2b2b0ac..96e96015 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -98,6 +98,10 @@ class inetOrgPerson extends baseModule { $return['dependencies'] = array('depends' => array(), 'conflicts' => array()); // managed object classes $return['objectClasses'] = array('inetOrgPerson'); + // LDAP aliases + $return['LDAPaliases'] = array('commonName' => 'cn', 'surname' => 'sn', 'streetAddress' => 'street', + 'fax' => 'facsimileTelephoneNumber', 'gn' => 'givenName', 'userid' => 'uid', 'rfc822Mailbox' => 'mail', + 'mobileTelephoneNumber' => 'mobile'); // profile elements $return['profile_options'] = array( array( @@ -364,7 +368,7 @@ class inetOrgPerson extends baseModule { return true; } } - if ($this->attributes['sn'][0] == '') return false; + if (!isset($this->attributes['sn'][0]) || ($this->attributes['sn'][0] == '')) return false; return true; } @@ -499,7 +503,7 @@ class inetOrgPerson extends baseModule { if (($this->attributes['mail'][0] != '') && !get_preg($this->attributes['mail'][0], 'email')) $triggered_messages['mail'][] = $this->messages['email'][0]; if ( !get_preg($this->attributes['street'][0], 'street')) $triggered_messages['street'][] = $this->messages['street'][0]; if ( !get_preg($this->attributes['postalAddress'][0], 'postalAddress')) $triggered_messages['postalAdress'][] = $this->messages['postalAddress'][0]; - if ( !get_preg($this->attributes['personal_postalCode'][0], 'postalCode')) $triggered_messages['personal_postalCode'][] = $this->messages['postalCode'][0]; + if ( !get_preg($this->attributes['postalCode'][0], 'postalCode')) $triggered_messages['personal_postalCode'][] = $this->messages['postalCode'][0]; if ( !get_preg($this->attributes['title'][0], 'title')) $triggered_messages['title'][] = $this->messages['title'][0]; if ( !get_preg($this->attributes['employeeType'][0], 'employeeType')) $triggered_messages['employeeType'][] = $this->messages['employeeType'][0]; if ($post['userPassword']) { @@ -527,28 +531,38 @@ class inetOrgPerson extends baseModule { function display_html_attributes(&$post) { $modules = $_SESSION['config']->get_AccountModules($this->get_scope()); if (!in_array('posixAccount', $modules)) { + $uid = ''; + if (isset($this->attributes['uid'][0])) $uid = $this->attributes['uid'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('User name') . '*' ), 1 => array ( 'kind' => 'input', 'name' => 'userName', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['uid'][0] ), + 'maxlength' => '255', 'value' => $uid), 2 => array ('kind' => 'help', 'value' => 'uid')); } + $firstName = ''; + if (isset($this->attributes['givenName'][0])) $firstName = $this->attributes['givenName'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('First name') ), 1 => array ( 'kind' => 'input', 'name' => 'givenName', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['givenName'][0] ), + 'maxlength' => '255', 'value' => $firstName), 2 => array ('kind' => 'help', 'value' => 'givenName')); + $lastName = ''; + if (isset($this->attributes['sn'][0])) $lastName = $this->attributes['sn'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Last name').'*' ), 1 => array ( 'kind' => 'input', 'name' => 'sn', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['sn'][0] ), + 'maxlength' => '255', 'value' => $lastName), 2 => array ('kind' => 'help', 'value' => 'sn')); if (!in_array('posixAccount', $modules)) { + $cn = ''; + if (isset($this->attributes['cn'][0])) $cn = $this->attributes['cn'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Common name') . '*' ), 1 => array ( 'kind' => 'input', 'name' => 'cn', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['cn'][0] ), + 'maxlength' => '255', 'value' => $cn), 2 => array ('kind' => 'help', 'value' => 'cn')); } + $description = ''; + if (isset($this->attributes['description'][0])) $description = $this->attributes['description'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Description') ), 1 => array ( 'kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['description'][0] ), + 'maxlength' => '255', 'value' => $description), 2 => array ('kind' => 'help', 'value' => 'description')); $return[] = array(0 => array('kind' => 'text', 'td' => array('colspan' => 3))); @@ -576,48 +590,68 @@ class inetOrgPerson extends baseModule { $return[] = array(0 => array('kind' => 'text', 'td' => array('colspan' => 3))); } + $street = ''; + if (isset($this->attributes['street'][0])) $street = $this->attributes['street'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Street') ), 1 => array ( 'kind' => 'input', 'name' => 'street', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['street'][0] ), + 'maxlength' => '255', 'value' => $street), 2 => array ('kind' => 'help', 'value' => 'street')); + $postOffice = ''; + if (isset($this->attributes['postOfficeBox'][0])) $postOffice = $this->attributes['postOfficeBox'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Post office box') ), 1 => array ( 'kind' => 'input', 'name' => 'postOfficeBox', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['postOfficeBox'][0] ), + 'maxlength' => '255', 'value' => $postOffice), 2 => array ('kind' => 'help', 'value' => 'postOfficeBox')); + $postalCode = ''; + if (isset($this->attributes['postalCode'][0])) $postalCode = $this->attributes['postalCode'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Postal code') ), 1 => array ( 'kind' => 'input', 'name' => 'postalCode', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['postalCode'][0] ), + 'maxlength' => '255', 'value' => $postalCode), 2 => array ('kind' => 'help', 'value' => 'postalCode')); + $postalAddress = ''; + if (isset($this->attributes['postalAddress'][0])) $postalAddress = $this->attributes['postalAddress'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Postal address') ), 1 => array ( 'kind' => 'input', 'name' => 'postalAddress', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['postalAddress'][0] ), + 'maxlength' => '255', 'value' => $postalAddress), 2 => array ('kind' => 'help', 'value' => 'postalAddress')); + $telephone = ''; + if (isset($this->attributes['telephoneNumber'][0])) $telephone = $this->attributes['telephoneNumber'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Telephone number') ), 1 => array ( 'kind' => 'input', 'name' => 'telephoneNumber', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['telephoneNumber'][0] ), + 'maxlength' => '255', 'value' => $telephone), 2 => array ('kind' => 'help', 'value' => 'telephoneNumber')); + $mobile = ''; + if (isset($this->attributes['mobile'][0])) $mobile = $this->attributes['mobile'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Mobile number') ), 1 => array ( 'kind' => 'input', 'name' => 'mobileTelephoneNumber', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['mobile'][0] ), + 'maxlength' => '255', 'value' => $mobile), 2 => array ('kind' => 'help', 'value' => 'mobileTelephoneNumber')); + $fax = ''; + if (isset($this->attributes['facsimileTelephoneNumber'][0])) $fax = $this->attributes['facsimileTelephoneNumber'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Fax number') ), 1 => array ( 'kind' => 'input', 'name' => 'facsimileTelephoneNumber', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['facsimileTelephoneNumber'][0] ), + 'maxlength' => '255', 'value' => $fax), 2 => array ('kind' => 'help', 'value' => 'facsimileTelephoneNumber')); + $email = ''; + if (isset($this->attributes['mail'][0])) $email = $this->attributes['mail'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('eMail address') ), 1 => array ( 'kind' => 'input', 'name' => 'mail', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['mail'][0] ), + 'maxlength' => '255', 'value' => $email), 2 => array ('kind' => 'help', 'value' => 'mail')); $return[] = array(0 => array('kind' => 'text', 'td' => array('colspan' => 3))); + $title = ''; + if (isset($this->attributes['title'][0])) $title = $this->attributes['title'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Job title') ), 1 => array ( 'kind' => 'input', 'name' => 'title', 'type' => 'text', 'size' => '30', - 'value' => $this->attributes['title'][0] ), + 'value' => $title), 2 => array ('kind' => 'help', 'value' => 'title')); + $employeeType = ''; + if (isset($this->attributes['employeeType'][0])) $employeeType = $this->attributes['employeeType'][0]; $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Employee type') ), 1 => array ( 'kind' => 'input', 'name' => 'employeeType', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['employeeType'][0] ), + 'maxlength' => '255', 'value' => $employeeType), 2 => array ('kind' => 'help', 'value' => 'employeeType')); if (isset($this->attributes['host'])) { $hostvalue = ""; @@ -636,7 +670,7 @@ class inetOrgPerson extends baseModule { usort($dnUsers, array($_SESSION['ldap'], 'cmp_array')); array_unshift($dnUsers, '-'); $optionsSelected = array(); - if ($this->attributes['manager'][0]) { + if (isset($this->attributes['manager'][0])) { $optionsSelected[] = $this->attributes['manager'][0]; } else { diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index f933c944..2a1987b6 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -125,6 +125,8 @@ class posixAccount extends baseModule { $return["RDN"] = array("uid" => "normal", "cn" => "low"); // managed object classes $return['objectClasses'] = array('posixAccount'); + // LDAP aliases + $return['LDAPaliases'] = array('commonName' => 'cn'); // PHP extensions $return['extensions'] = array('mhash'); // profile checks diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index d5fa097d..cd435599 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -309,6 +309,8 @@ class posixGroup extends baseModule { $return['dependencies'] = array('depends' => array(), 'conflicts' => array()); // managed object classes $return['objectClasses'] = array('posixGroup'); + // LDAP aliases + $return['LDAPaliases'] = array('commonName' => 'cn'); // configuration options $return['config_options']['group'] = array( array(