From 56d7d22d8660838e76487782a64613a4b777a54b Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 3 Feb 2024 20:41:30 +1300 Subject: [PATCH] Rename mapping_field to user_mapping_field This is to be consistent with group_mapping_field. The code is backwards compatible with mapping_field. In sync_LDAP_groups assign user_mapping once, not for every group. --- config/example-config.php | 2 +- inc/drivers_ldap.php | 23 ++++++++++++++++++----- testing/regression-conf.php.example | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/config/example-config.php b/config/example-config.php index 4175c22e..4a4cccdd 100644 --- a/config/example-config.php +++ b/config/example-config.php @@ -704,7 +704,7 @@ $c->admin_email = 'calendar-admin@example.com'; // 'filterGroups' => 'objectClass=groupOfUniqueNames', /* /!\ "username" should be set and "modified" must be set * used to create the user based on their ldap properties */ -// 'mapping_field' => array( +// 'user_mapping_field' => array( // "username" => "uid", // "modified" => "modifyTimestamp", // "fullname" => "cn", diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index 05c4055a..b855fe21 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -643,6 +643,14 @@ function sync_LDAP_groups(){ if ( sizeof ( $groups_to_update ) ){ $c->messages[] = sprintf(i18n('- updating groups : %s'),join(', ',$groups_to_update)); + // Support the old name of user_mapping_field.. + $user_mapping = NULL; + if (isset($c->authenticate_hook['config']['user_mapping_field'])) { + $user_mapping = $c->authenticate_hook['config']['user_mapping_field']; + } else if (isset($c->authenticate_hook['config']['mapping_field'])) { + $user_mapping = $c->authenticate_hook['config']['mapping_field']; + } + foreach ( $groups_to_update as $group ){ $db_members = is_array( $db_group_members[$group] ) ? array_values( $db_group_members[$group] ) @@ -651,12 +659,10 @@ function sync_LDAP_groups(){ ? array_values ( $ldap_groups_info[$group][$member_field] ) : array(); - $mapping_field = $c->authenticate_hook['config']['mapping_field']; - if (isset($c->authenticate_hook['config']['group_match_username_attr']) - && isset($mapping_field['username'])) { + && isset($user_mapping['username'])) { $query = $ldapDriver->ldap_query_one; - $username_ldap_attribute = $mapping_field['username']; + $username_ldap_attribute = $user_mapping['username']; $filter = "(objectCategory=person)"; $ldap_members_tmp = array(); @@ -757,7 +763,14 @@ function sync_LDAP(){ $ldapDriver = getStaticLdap(); if ( ! $ldapDriver->valid ) return; - $mapping = $c->authenticate_hook['config']['mapping_field']; + // Support the old name of user_mapping_field. + $mapping = NULL; + if (isset($c->authenticate_hook['config']['user_mapping_field'])) { + $mapping = $c->authenticate_hook['config']['user_mapping_field']; + } else if (isset($c->authenticate_hook['config']['mapping_field'])) { + $mapping = $c->authenticate_hook['config']['mapping_field']; + } + $attributes = array_values_mapping($mapping); $ldap_users_tmp = $ldapDriver->getAllUsers($attributes); diff --git a/testing/regression-conf.php.example b/testing/regression-conf.php.example index d14c7b89..0e5cc921 100644 --- a/testing/regression-conf.php.example +++ b/testing/regression-conf.php.example @@ -32,6 +32,7 @@ //ldap 'protocolVersion' => 3, //ldap 'baseDNUsers' => 'ou=users,dc=example,dc=com', //ldap 'baseDNGroups' => 'ou=groups,dc=example,dc=com', + // Test with the old name, new name is "user_mapping_field". //ldap 'mapping_field' => array( //ldap "username" => "uid", //ldap "modified" => "modifyTimestamp",