Skip to content

Commit 4f02e4c

Browse files
committed
Improved LDAP logging
1 parent 56933ea commit 4f02e4c

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

crates/directory/src/backend/ldap/lookup.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
55
*/
66

7-
use ldap3::{Ldap, LdapConnAsync, Scope, SearchEntry};
7+
use ldap3::{Ldap, LdapConnAsync, ResultEntry, Scope, SearchEntry};
88
use mail_send::Credentials;
99
use trc::AddContext;
1010

@@ -237,10 +237,7 @@ impl LdapDirectory {
237237
trc::event!(
238238
Store(trc::StoreEvent::LdapQuery),
239239
Details = filter,
240-
Result = rs
241-
.iter()
242-
.map(|e| trc::Value::from(format!("{e:?}")))
243-
.collect::<Vec<_>>()
240+
Result = rs.iter().map(result_to_trace).collect::<Vec<_>>()
244241
);
245242

246243
for entry in rs {
@@ -288,7 +285,7 @@ impl LdapDirectory {
288285
trc::event!(
289286
Store(trc::StoreEvent::LdapQuery),
290287
Details = filter,
291-
Result = entry.map(|e| trc::Value::from(format!("{e:?}")))
288+
Result = entry.as_ref().map(result_to_trace).unwrap_or_default()
292289
);
293290

294291
result
@@ -340,10 +337,7 @@ impl LdapDirectory {
340337
trc::event!(
341338
Store(trc::StoreEvent::LdapQuery),
342339
Details = filter.to_string(),
343-
Result = rs
344-
.iter()
345-
.map(|e| trc::Value::from(format!("{e:?}")))
346-
.collect::<Vec<_>>()
340+
Result = rs.first().map(result_to_trace).unwrap_or_default()
347341
);
348342

349343
rs.into_iter().next().map(|entry| {
@@ -416,3 +410,12 @@ impl LdapMappings {
416410
principal.with_field(PrincipalField::Roles, role)
417411
}
418412
}
413+
414+
fn result_to_trace(rs: &ResultEntry) -> trc::Value {
415+
SearchEntry::construct(rs.clone())
416+
.attrs
417+
.into_iter()
418+
.map(|(k, v)| trc::Value::Array(vec![trc::Value::from(k), trc::Value::from(v.join(", "))]))
419+
.collect::<Vec<_>>()
420+
.into()
421+
}

0 commit comments

Comments
 (0)