|
4 | 4 | * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -use ldap3::{Ldap, LdapConnAsync, Scope, SearchEntry}; |
| 7 | +use ldap3::{Ldap, LdapConnAsync, ResultEntry, Scope, SearchEntry}; |
8 | 8 | use mail_send::Credentials;
|
9 | 9 | use trc::AddContext;
|
10 | 10 |
|
@@ -237,10 +237,7 @@ impl LdapDirectory {
|
237 | 237 | trc::event!(
|
238 | 238 | Store(trc::StoreEvent::LdapQuery),
|
239 | 239 | 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<_>>() |
244 | 241 | );
|
245 | 242 |
|
246 | 243 | for entry in rs {
|
@@ -288,7 +285,7 @@ impl LdapDirectory {
|
288 | 285 | trc::event!(
|
289 | 286 | Store(trc::StoreEvent::LdapQuery),
|
290 | 287 | Details = filter,
|
291 |
| - Result = entry.map(|e| trc::Value::from(format!("{e:?}"))) |
| 288 | + Result = entry.as_ref().map(result_to_trace).unwrap_or_default() |
292 | 289 | );
|
293 | 290 |
|
294 | 291 | result
|
@@ -340,10 +337,7 @@ impl LdapDirectory {
|
340 | 337 | trc::event!(
|
341 | 338 | Store(trc::StoreEvent::LdapQuery),
|
342 | 339 | 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() |
347 | 341 | );
|
348 | 342 |
|
349 | 343 | rs.into_iter().next().map(|entry| {
|
@@ -416,3 +410,12 @@ impl LdapMappings {
|
416 | 410 | principal.with_field(PrincipalField::Roles, role)
|
417 | 411 | }
|
418 | 412 | }
|
| 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