Skip to content

Commit d8fbb82

Browse files
committed
Add LDAP attribute to indicate password change (#1156)
1 parent 83cf1fa commit d8fbb82

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ impl LdapDirectory {
7272
.values((&prefix, "attributes.secret"))
7373
.map(|(_, v)| v.to_string())
7474
.collect(),
75+
attr_secret_changed: config
76+
.values((&prefix, "attributes.secret-changed"))
77+
.map(|(_, v)| v.to_string())
78+
.collect(),
7579
attr_email_address: config
7680
.values((&prefix, "attributes.email"))
7781
.map(|(_, v)| v.to_string())

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ldap3::{Ldap, LdapConnAsync, ResultEntry, Scope, SearchEntry};
88
use mail_send::Credentials;
9+
use store::xxhash_rust;
910
use trc::AddContext;
1011

1112
use crate::{
@@ -373,6 +374,15 @@ impl LdapMappings {
373374
for item in value {
374375
principal.append_str(PrincipalField::Secrets, item);
375376
}
377+
} else if self.attr_secret_changed.contains(&attr) {
378+
// Create a disabled AppPassword, used to indicate that the password has been changed
379+
// but cannot be used for authentication.
380+
for item in value {
381+
principal.append_str(
382+
PrincipalField::Secrets,
383+
format!("$app${}$", xxhash_rust::xxh3::xxh3_64(item.as_bytes())),
384+
);
385+
}
376386
} else if self.attr_email_address.contains(&attr) {
377387
for item in value {
378388
principal.prepend_str(PrincipalField::Emails, item.to_lowercase());

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct LdapMappings {
2929
attr_groups: Vec<String>,
3030
attr_description: Vec<String>,
3131
attr_secret: Vec<String>,
32+
attr_secret_changed: Vec<String>,
3233
attr_email_address: Vec<String>,
3334
attr_email_alias: Vec<String>,
3435
attr_quota: Vec<String>,

crates/directory/src/core/secret.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ pub async fn verify_secret_hash(hashed_secret: &str, secret: &str) -> trc::Resul
264264
.into_err()
265265
.details(hashed_secret.to_string()))
266266
}
267-
} else {
267+
} else if !hashed_secret.is_empty() {
268268
Ok(hashed_secret == secret)
269+
} else {
270+
Ok(false)
269271
}
270272
}

crates/store/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub use rand;
2222
pub use roaring;
2323
use utils::config::cron::SimpleCron;
2424
use write::{BitmapClass, ValueClass};
25+
pub use xxhash_rust;
2526

2627
#[cfg(feature = "s3")]
2728
use backend::s3::S3Store;

0 commit comments

Comments
 (0)