Lowercase LDAP attribute comparison - credits to @pdf (fixes #2363 closes #2378)

This commit is contained in:
mdecimus
2025-12-18 15:12:41 +01:00
parent a5dbfd5e6d
commit c59cc8c9d3
2 changed files with 16 additions and 16 deletions

View File

@@ -56,41 +56,41 @@ impl LdapDirectory {
filter_email: LdapFilter::from_config(config, (&prefix, "filter.email")), filter_email: LdapFilter::from_config(config, (&prefix, "filter.email")),
attr_name: config attr_name: config
.values((&prefix, "attributes.name")) .values((&prefix, "attributes.name"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_groups: config attr_groups: config
.values((&prefix, "attributes.groups")) .values((&prefix, "attributes.groups"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_type: config attr_type: config
.values((&prefix, "attributes.class")) .values((&prefix, "attributes.class"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_description: config attr_description: config
.values((&prefix, "attributes.description")) .values((&prefix, "attributes.description"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_secret: config attr_secret: config
.values((&prefix, "attributes.secret")) .values((&prefix, "attributes.secret"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_secret_changed: config attr_secret_changed: config
.values((&prefix, "attributes.secret-changed")) .values((&prefix, "attributes.secret-changed"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_email_address: config attr_email_address: config
.values((&prefix, "attributes.email")) .values((&prefix, "attributes.email"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_quota: config attr_quota: config
.values((&prefix, "attributes.quota")) .values((&prefix, "attributes.quota"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attr_email_alias: config attr_email_alias: config
.values((&prefix, "attributes.email-alias")) .values((&prefix, "attributes.email-alias"))
.map(|(_, v)| v.to_string()) .map(|(_, v)| v.to_lowercase())
.collect(), .collect(),
attrs_principal: vec!["objectClass".to_string()], attrs_principal: vec!["objectClass".to_lowercase()],
}; };
for attr in [ for attr in [

View File

@@ -228,7 +228,7 @@ impl LdapDirectory {
.map_err(|err| err.into_error().caused_by(trc::location!()))?; .map_err(|err| err.into_error().caused_by(trc::location!()))?;
for entry in rs { for entry in rs {
'outer: for (attr, value) in SearchEntry::construct(entry).attrs { 'outer: for (attr, value) in SearchEntry::construct(entry).attrs {
if self.mappings.attr_name.contains(&attr) if self.mappings.attr_name.contains(&attr.to_lowercase())
&& let Some(group) = value.into_iter().next() && let Some(group) = value.into_iter().next()
&& !group.is_empty() && !group.is_empty()
{ {
@@ -310,14 +310,13 @@ impl LdapDirectory {
); );
for entry in rs { for entry in rs {
let entry = SearchEntry::construct(entry); for (attr, value) in SearchEntry::construct(entry).attrs {
for attr in &self.mappings.attr_name { if self.mappings.attr_name.contains(&attr.to_lowercase())
if let Some(name) = entry.attrs.get(attr).and_then(|v| v.first()) && let Some(name) = value.into_iter().find(|name| !name.is_empty())
&& !name.is_empty()
{ {
return self return self
.data_store .data_store
.get_or_create_principal_id(name, Type::Individual) .get_or_create_principal_id(&name, Type::Individual)
.await .await
.map(Some); .map(Some);
} }
@@ -436,6 +435,7 @@ impl LdapMappings {
let mut email_aliases = Vec::new(); let mut email_aliases = Vec::new();
for (attr, value) in entry.attrs { for (attr, value) in entry.attrs {
let attr = attr.to_lowercase();
if self.attr_name.contains(&attr) { if self.attr_name.contains(&attr) {
if !self.attr_email_address.contains(&attr) { if !self.attr_email_address.contains(&attr) {
principal.name = value.into_iter().next().unwrap_or_default(); principal.name = value.into_iter().next().unwrap_or_default();