diff options
Diffstat (limited to 'server/src')
| -rw-r--r-- | server/src/auth.rs | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/server/src/auth.rs b/server/src/auth.rs index d74ec27..c76bd82 100644 --- a/server/src/auth.rs +++ b/server/src/auth.rs @@ -12,6 +12,7 @@ use rocket::serde::{Deserialize, Serialize}; use rocket::{Build, Rocket, State}; use rocket_db_pools::{sqlx, Connection, Database}; use std::borrow::Cow; +use std::cmp::Ordering; use std::collections::BTreeMap; use std::sync::Mutex; use std::sync::OnceLock; @@ -309,7 +310,7 @@ async fn sync_ldap( db: &Db, ) -> Result<(), LdapOrSqlError> { let mut ldap = setup_ldap(ldap_state, config) - .map_err(|e| LdapOrSqlError::LdapError(e)) + .map_err(LdapOrSqlError::LdapError) .await?; let (entries, _) = ldap .search( @@ -318,10 +319,10 @@ async fn sync_ldap( &config.ldap_filter, vec!["uid"], ) - .map_err(|e| LdapOrSqlError::LdapError(e)) + .map_err(LdapOrSqlError::LdapError) .await? .success() - .map_err(|e| LdapOrSqlError::LdapError(e))?; + .map_err(LdapOrSqlError::LdapError)?; let mut tx = db.begin().await.unwrap(); @@ -342,19 +343,23 @@ async fn sync_ldap( for entry in entries { let se = ldap3::SearchEntry::construct(entry); - let uid = se.attrs.get("uid").unwrap().get(0).unwrap(); + let uid = se.attrs.get("uid").unwrap().first().unwrap(); loop { if let Some(du) = db_user.peek() { - if du.1 == *uid { - if du.2.as_ref().is_none_or(|x| *x != se.dn) { - updated_users.push((du.0, se.dn)); + match du.1.cmp(uid) { + Ordering::Equal => { + if du.2.as_ref().is_none_or(|x| *x != se.dn) { + updated_users.push((du.0, se.dn)); + } + db_user.next(); + break; } - db_user.next(); - break; - } else if du.1 < *uid { - old_users.push(du.0); - db_user.next(); - continue; + Ordering::Less => { + old_users.push(du.0); + db_user.next(); + continue; + } + Ordering::Greater => (), } } new_users.push((uid.to_string(), se.dn)); @@ -383,14 +388,14 @@ async fn sync_ldap( query_builder .build() .execute(&mut *tx) - .map_err(|e| LdapOrSqlError::SqlError(e)) + .map_err(LdapOrSqlError::SqlError) .await?; } for pair in updated_users { sqlx::query!("UPDATE users SET dn=? WHERE id=?", pair.1, pair.0) .execute(&mut *tx) - .map_err(|e| LdapOrSqlError::SqlError(e)) + .map_err(LdapOrSqlError::SqlError) .await?; } @@ -405,11 +410,11 @@ async fn sync_ldap( query .execute(&mut *tx) - .map_err(|e| LdapOrSqlError::SqlError(e)) + .map_err(LdapOrSqlError::SqlError) .await?; } - tx.commit().map_err(|e| LdapOrSqlError::SqlError(e)).await?; + tx.commit().map_err(LdapOrSqlError::SqlError).await?; Ok(()) } |
