diff --git a/Cargo.lock b/Cargo.lock index bd10531..0b55b38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,17 +39,6 @@ dependencies = [ "serde", ] -[[package]] -name = "async-trait" -version = "0.1.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.4", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -180,9 +169,6 @@ name = "camino" version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1307f12aa967b5a58416e87b3653360e0fd614a016b6e970db08fecbb1b80d" -dependencies = [ - "serde_core", -] [[package]] name = "cc" @@ -534,7 +520,6 @@ name = "llldap" version = "0.1.0" dependencies = [ "argh", - "async-trait", "axum", "axum-extra", "camino", @@ -545,7 +530,6 @@ dependencies = [ "minijinja", "minijinja-embed", "serde", - "serde_json", "static-serve", "tokio", "tokio-util", diff --git a/Cargo.toml b/Cargo.toml index 07c7928..2a473bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,9 @@ edition = "2024" [dependencies] argh = "0.1.19" -async-trait = "0.1.92" axum = { version = "0.8.9", optional = true, features = ["macros"] } axum-extra = { version = "0.12.6", features = ["cookie"], optional = true } -camino = { version = "1.2.5", features = ["serde1"] } +camino = "1.2.5" dn_escape = { path = "vendor/dn_escape" } futures-util = { version = "0.3.34", features = ["sink"] } http = { version = "1.5.0", optional = true } @@ -16,7 +15,6 @@ ldap3_proto = "0.8.1" minijinja = { version = "2.24.0", optional = true } minijinja-embed = { version = "2.24.0", optional = true } serde = { version = "1.0.229", features = ["derive"] } -serde_json = "1.0.151" static-serve = { version = "0.6.3", optional = true } tokio = { version = "1.53.1", features = ["macros", "net", "rt", "time", "sync"] } tokio-util = { version = "0.7.19", features = ["codec"] } diff --git a/src/cli.rs b/src/cli.rs index d70e141..6867704 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,13 +1,8 @@ use argh::FromArgs; -use camino::Utf8PathBuf; /// Run the llldap server #[derive(FromArgs)] pub struct CliArgs { - /// path to the JSON file for the database - #[argh(option)] - pub db: Option, - /// address or socket to listen on for LDAP connections #[argh(option, default = "String::from(\"127.0.0.1:3389\")")] pub listen_ldap: String, diff --git a/src/db/common.rs b/src/db/common.rs index 3a5f655..f7408c6 100644 --- a/src/db/common.rs +++ b/src/db/common.rs @@ -6,19 +6,19 @@ use crate::db::error::BoxedError; use crate::db::{DatabaseInterface, Domain, User, UserRef}; #[derive(Clone, Debug)] -pub struct Database { - pub inner: Arc>>, +pub struct Database { + pub inner: Arc>, } -impl Database { - pub fn new(db: impl DatabaseInterface) -> Self { +impl Database { + pub fn new(db: D) -> Self { Self { - inner: Arc::new(RwLock::new(Box::new(db))), + inner: Arc::new(RwLock::new(db)), } } } -impl Database { +impl Database { /// Return false if the user doesn't exist, or the password is wrong. /// /// TODO: should we return something else when the account doesn't exist? diff --git a/src/db/domain.rs b/src/db/domain.rs index 9c7d7e6..59a1a94 100644 --- a/src/db/domain.rs +++ b/src/db/domain.rs @@ -1,6 +1,6 @@ -use serde::{Deserialize, Serialize}; +use serde::Serialize; -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Serialize)] pub struct Domain { pub name: String, } diff --git a/src/db/filesystem.rs b/src/db/filesystem.rs deleted file mode 100644 index 9074822..0000000 --- a/src/db/filesystem.rs +++ /dev/null @@ -1,156 +0,0 @@ -use camino::{Utf8Path, Utf8PathBuf}; -use serde::{Deserialize, Serialize}; -use serde_json::Error as JsonError; - -use std::fmt; -use std::io::Error as IOError; - -use crate::db::error::{BoxedError, DomainCreationError, UserCreationError}; -use crate::db::{Database, DatabaseInterface, Domain, MemoryDatabase, User, UserRef}; - -#[derive(Debug)] -pub enum FilesystemDatabaseError { - ReadFileIO(Utf8PathBuf, IOError), - ReadFileJson(Utf8PathBuf, JsonError), - WriteFileIO(Utf8PathBuf, IOError), - WriteFileJson(Utf8PathBuf, JsonError), -} - -impl fmt::Display for FilesystemDatabaseError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - match self { - Self::ReadFileIO(path, e) => format!("Failed to read database file {path}: {e}"), - Self::ReadFileJson(path, e) => - format!("Failed to parse database JSON file {path}: {e}"), - Self::WriteFileIO(path, e) => format!("Failed to write database file {path}: {e}"), - Self::WriteFileJson(path, e) => - format!("Failed to convert database to JSON file {path}: {e}"), - } - ) - } -} - -impl std::error::Error for FilesystemDatabaseError {} - -#[derive(Clone, Debug, Default, Deserialize, Serialize)] -pub struct FilesystemDatabase { - // TODO: Once we have common validation steps in place across DB backends, we can reduce cloning. - // For now, we clone the DB on every write operation, and update it when saving to disk - // succeeds. - pub inner: MemoryDatabase, - pub path: Utf8PathBuf, -} - -impl FilesystemDatabase { - pub async fn from_path(path: impl AsRef) -> Result { - let path = path.as_ref(); - - if !tokio::fs::try_exists(path) - .await - .map_err(|e| Box::new(FilesystemDatabaseError::ReadFileIO(path.to_path_buf(), e)))? - { - // The database doesn't exist yet, we create an empty one and try to write it - // to make sure the permissions are correct and the destination folder exists. - let mut db = Self { - inner: MemoryDatabase::default(), - path: path.to_path_buf(), - }; - - db.save().await?; - return Ok(Database::new(db)); - } - - let s = tokio::fs::read(path) - .await - .map_err(|e| Box::new(FilesystemDatabaseError::ReadFileIO(path.to_path_buf(), e)))?; - let inner: MemoryDatabase = serde_json::from_slice(&s) - .map_err(|e| Box::new(FilesystemDatabaseError::ReadFileJson(path.to_path_buf(), e)))?; - Ok(Database::new(Self { - inner, - path: path.to_path_buf(), - })) - } - - pub async fn save(&mut self) -> Result<(), BoxedError> { - let s = serde_json::to_string(&self) - .map_err(|e| Box::new(FilesystemDatabaseError::WriteFileJson(self.path.clone(), e)))?; - Ok(tokio::fs::write(&self.path, &s) - .await - .map_err(|e| Box::new(FilesystemDatabaseError::WriteFileIO(self.path.clone(), e)))?) - } -} - -#[async_trait::async_trait] -impl DatabaseInterface for FilesystemDatabase { - async fn create_domain( - &mut self, - domain: &str, - ) -> Result, BoxedError> { - let mut new_db = self.inner.clone(); - - if let Err(e) = new_db.create_domain(domain).await? { - return Ok(Err(e)); - } - - self.save().await?; - self.inner = new_db; - - Ok(Ok(())) - } - - async fn get_domain(&self, domain: &str) -> Result, BoxedError> { - self.inner.get_domain(domain).await - } - - async fn get_user(&self, req_user: &UserRef) -> Result, BoxedError> { - self.inner.get_user(req_user).await - } - - async fn create_user( - &mut self, - user: User, - ) -> Result, BoxedError> { - let mut new_db = self.inner.clone(); - - if let Err(e) = new_db.create_user(user).await? { - return Ok(Err(e)); - } - - self.save().await?; - self.inner = new_db; - - Ok(Ok(())) - } - - async fn try_create_user( - &mut self, - new_user: User, - current_user: &User, - ) -> Result, BoxedError> { - let mut new_db = self.inner.clone(); - - if let Err(e) = new_db.try_create_user(new_user, current_user).await? { - return Ok(Err(e)); - } - - self.save().await?; - self.inner = new_db; - - Ok(Ok(())) - } - - async fn list_all_domains(&self) -> Result, BoxedError> { - self.inner.list_all_domains().await - } - - async fn list_all_users(&self) -> Result, BoxedError> { - self.inner.list_all_users().await - } - - async fn list_domain_users(&self, domain: Option) -> Result, BoxedError> { - self.inner.list_domain_users(domain).await - } -} diff --git a/src/db/group.rs b/src/db/group.rs index 6a2793f..c07a891 100644 --- a/src/db/group.rs +++ b/src/db/group.rs @@ -1,7 +1,7 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug)] pub struct Group { + #[expect(unused)] name: String, + #[expect(unused)] domain: String, } diff --git a/src/db/interface.rs b/src/db/interface.rs index 6115f39..ca84fd9 100644 --- a/src/db/interface.rs +++ b/src/db/interface.rs @@ -1,8 +1,7 @@ use crate::db::error::{BoxedError, DomainCreationError, UserCreationError}; use crate::db::{Database, Domain, User, UserRef}; -#[async_trait::async_trait] -impl DatabaseInterface for Database { +impl DatabaseInterface for Database { async fn create_domain( &mut self, domain: &str, @@ -50,31 +49,39 @@ impl DatabaseInterface for Database { } } -#[async_trait::async_trait] -pub trait DatabaseInterface: std::fmt::Debug + Send + Sync + 'static { - async fn create_domain( +pub trait DatabaseInterface: Clone + Send + Sync + 'static { + fn create_domain( &mut self, domain: &str, - ) -> Result, BoxedError>; - async fn get_domain(&self, domain: &str) -> Result, BoxedError>; + ) -> impl Future, BoxedError>> + Send; + fn get_domain( + &self, + domain: &str, + ) -> impl Future, BoxedError>> + Send; - async fn get_user(&self, user: &UserRef) -> Result, BoxedError>; + fn get_user( + &self, + user: &UserRef, + ) -> impl std::future::Future, BoxedError>> + Send; async fn create_user( &mut self, user: User, ) -> Result, BoxedError>; - async fn try_create_user( + fn try_create_user( &mut self, new_user: User, current_user: &User, - ) -> Result, BoxedError>; + ) -> impl Future, BoxedError>> + Send; - async fn list_all_domains(&self) -> Result, BoxedError>; + fn list_all_domains(&self) -> impl Future, BoxedError>> + Send; #[expect(unused)] - async fn list_all_users(&self) -> Result, BoxedError>; + fn list_all_users(&self) -> impl Future, BoxedError>> + Send; /// List users on a specific domain. /// /// A `None` domain requested lists global service users. - async fn list_domain_users(&self, domain: Option) -> Result, BoxedError>; + fn list_domain_users( + &self, + domain: Option, + ) -> impl std::future::Future, BoxedError>> + Send; } diff --git a/src/db/memory.rs b/src/db/memory.rs index bae3c8e..e170db0 100644 --- a/src/db/memory.rs +++ b/src/db/memory.rs @@ -1,60 +1,64 @@ -use serde::{Deserialize, Serialize}; +use std::future::{Future, ready}; use crate::db::error::{BoxedError, DomainCreationError, UserCreationError}; use crate::db::{Database, DatabaseInterface, Domain, Group, Operation, User, UserRef}; -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default)] pub struct MemoryDatabase { // We store data in tables like in SQL pub domains: Vec, + #[expect(unused)] pub groups: Vec, pub users: Vec, } impl MemoryDatabase { - #[allow(clippy::new_ret_no_self)] - pub fn new() -> Database { + pub fn new() -> Database { Database::new(Self::default()) } } -#[async_trait::async_trait] impl DatabaseInterface for MemoryDatabase { - async fn create_domain( + fn create_domain( &mut self, domain: &str, - ) -> Result, BoxedError> { + ) -> impl Future, BoxedError>> { if domain.is_empty() { - return Ok(Err(DomainCreationError::InvalidDomain(domain.to_string()))); + return ready(Ok(Err(DomainCreationError::InvalidDomain( + domain.to_string(), + )))); } if self.domains.iter().find(|d| d.name == domain).is_some() { - return Ok(Err(DomainCreationError::DomainAlreadyExists( + return ready(Ok(Err(DomainCreationError::DomainAlreadyExists( domain.to_string(), - ))); + )))); } self.domains.push(Domain { name: domain.to_string(), }); - Ok(Ok(())) + ready(Ok(Ok(()))) } - async fn get_domain(&self, domain: &str) -> Result, BoxedError> { + fn get_domain(&self, domain: &str) -> impl Future, BoxedError>> { let Some(domain) = self.domains.iter().find(|d| d.name == domain) else { - return Ok(None); + return ready(Ok(None)); }; - Ok(Some(domain.clone())) + ready(Ok(Some(domain.clone()))) } - async fn get_user(&self, req_user: &UserRef) -> Result, BoxedError> { - Ok(self + fn get_user( + &self, + req_user: &UserRef, + ) -> impl Future, BoxedError>> { + ready(Ok(self .users .iter() .find(|u| u.username == req_user.username && u.domain == req_user.domain) - .cloned()) + .cloned())) } async fn create_user( @@ -99,20 +103,23 @@ impl DatabaseInterface for MemoryDatabase { self.create_user(new_user).await } - async fn list_all_domains(&self) -> Result, BoxedError> { - Ok(self.domains.clone()) + fn list_all_domains(&self) -> impl Future, BoxedError>> { + ready(Ok(self.domains.clone())) } - async fn list_all_users(&self) -> Result, BoxedError> { - Ok(self.users.clone()) + fn list_all_users(&self) -> impl Future, BoxedError>> { + ready(Ok(self.users.clone())) } - async fn list_domain_users(&self, domain: Option) -> Result, BoxedError> { - Ok(self + fn list_domain_users( + &self, + domain: Option, + ) -> impl Future, BoxedError>> { + ready(Ok(self .users .iter() .filter(|u| u.domain == domain) .cloned() - .collect()) + .collect())) } } diff --git a/src/db/mod.rs b/src/db/mod.rs index 902e89c..c2544e0 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -3,8 +3,6 @@ pub use common::Database; mod domain; pub use domain::Domain; pub mod error; -mod filesystem; -pub use filesystem::FilesystemDatabase; mod group; pub use group::Group; mod interface; diff --git a/src/db/role.rs b/src/db/role.rs index 37f6b51..102933b 100644 --- a/src/db/role.rs +++ b/src/db/role.rs @@ -1,4 +1,4 @@ -use serde::{Deserialize, Serialize}; +use serde::Serialize; #[derive(Clone, Debug)] pub enum Operation { @@ -7,11 +7,12 @@ pub enum Operation { ListUsers(Option), } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Serialize)] pub enum Role { /// Can do anything Admin, /// Can only read data across all vhosts + #[expect(unused)] ReadonlyAdmin, /// Can do anything on a domain, except removing /// oneself as a domain admin. @@ -19,6 +20,7 @@ pub enum Role { /// Can not give away roles other than DomainModerator/User DomainAdmin(String), /// Can create users and reset passwords on a domain + #[expect(unused)] DomainModerator(String), /// Can only edit own profile User, diff --git a/src/db/user.rs b/src/db/user.rs index ba9e986..b7c8bcd 100644 --- a/src/db/user.rs +++ b/src/db/user.rs @@ -1,4 +1,4 @@ -use serde::{Deserialize, Serialize}; +use serde::Serialize; use std::fmt; @@ -54,7 +54,7 @@ impl fmt::Display for UserRef { } } -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Serialize)] pub struct User { /// Username, without the domain part. Once set, cannot be edited. pub username: String, diff --git a/src/http/domain.rs b/src/http/domain.rs index 4c05af0..1acfdbb 100644 --- a/src/http/domain.rs +++ b/src/http/domain.rs @@ -7,8 +7,8 @@ use serde::Deserialize; use crate::db::{DatabaseInterface, Operation}; use crate::http::{HttpSession, HttpState}; -pub async fn get_domain( - State(state): State, +pub async fn get_domain( + State(state): State>, session: HttpSession, Path(domain): Path, ) -> Response { @@ -53,8 +53,8 @@ pub struct DomainCreationForm { domainname: String, } -pub async fn create_domain( - State(mut state): State, +pub async fn create_domain( + State(mut state): State>, session: HttpSession, Form(form): Form, ) -> Response { diff --git a/src/http/home.rs b/src/http/home.rs index 32802b0..febb6b0 100644 --- a/src/http/home.rs +++ b/src/http/home.rs @@ -6,8 +6,8 @@ use minijinja::context; use crate::db::{DatabaseInterface, Operation}; use crate::http::{HttpSession, HttpState}; -pub async fn home( - State(state): State, +pub async fn home( + State(state): State>, // Only logged in users are allowed here session: HttpSession, ) -> Response { diff --git a/src/http/login.rs b/src/http/login.rs index 578b5ff..8b4a26d 100644 --- a/src/http/login.rs +++ b/src/http/login.rs @@ -20,8 +20,8 @@ pub enum LoginError { SessionInvalidated, } -pub async fn login_page( - State(state): State, +pub async fn login_page( + State(state): State>, login_error: Option, ) -> Response { let page = state @@ -33,8 +33,8 @@ pub async fn login_page( (StatusCode::OK, Html(page)).into_response() } -pub async fn get_login( - State(state): State, +pub async fn get_login( + State(state): State>, maybe_session: Option, ) -> Response { if maybe_session.is_some() { @@ -44,8 +44,8 @@ pub async fn get_login( login_page(State(state), None).await } -pub async fn post_login( - State(state): State, +pub async fn post_login( + State(state): State>, session: Option, cookies: CookieJar, Form(form): Form, diff --git a/src/http/logout.rs b/src/http/logout.rs index 3dc5151..c742074 100644 --- a/src/http/logout.rs +++ b/src/http/logout.rs @@ -2,11 +2,12 @@ use axum::extract::State; use axum::response::{IntoResponse, Redirect, Response}; use axum_extra::extract::cookie::CookieJar; +use crate::db::DatabaseInterface; use crate::http::login::{LoginError, login_page}; use crate::http::{HttpState, OptionalHttpSession}; -pub async fn logout( - State(state): State, +pub async fn logout( + State(state): State>, session: Option, cookies: CookieJar, ) -> Response { diff --git a/src/http/mod.rs b/src/http/mod.rs index daf1507..17c9448 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -9,7 +9,7 @@ use static_serve::embed_assets; #[cfg(not(feature = "embed"))] use tower_http::services::ServeDir; -use crate::db::Database; +use crate::db::{Database, DatabaseInterface}; use crate::listener::{Listener, ListenerKind}; use crate::stream::{AbstractSocketAddr, AbstractStreamKind}; @@ -62,14 +62,14 @@ impl AxumListener for Listener { } #[derive(Clone)] -pub struct HttpState { - pub db: Database, +pub struct HttpState { + pub db: Database, pub sessions: HttpSessionManager, pub templates: Environment<'static>, } -impl HttpState { - pub fn new(db: Database) -> Self { +impl HttpState { + pub fn new(db: Database) -> Self { let mut templates = Environment::new(); #[cfg(feature = "embed")] minijinja_embed::load_templates!(&mut templates); @@ -83,7 +83,7 @@ impl HttpState { } } -pub async fn http_listen(listener: Listener, db: Database) { +pub async fn http_listen(listener: Listener, db: Database) { #[cfg(all(feature = "embed", feature = "noembed"))] compile_error!("You cannot have `embed` and `noembed` features enabled at the same time."); #[cfg(not(any(feature = "embed", feature = "noembed")))] diff --git a/src/http/session.rs b/src/http/session.rs index 1f88874..5005b8c 100644 --- a/src/http/session.rs +++ b/src/http/session.rs @@ -6,7 +6,7 @@ use uuid::Uuid; use std::sync::{Arc, RwLock}; -use crate::db::User; +use crate::db::{DatabaseInterface, User}; use crate::http::HttpState; pub const COOKIE_NAME: &str = "lldap_session"; @@ -83,12 +83,12 @@ impl PartialEq for HttpSession { } } -impl FromRequestParts for HttpSession { +impl FromRequestParts> for HttpSession { type Rejection = Redirect; async fn from_request_parts( parts: &mut Parts, - state: &HttpState, + state: &HttpState, ) -> Result { let cookies = CookieJar::from_request_parts(parts, state).await.unwrap(); state @@ -108,12 +108,12 @@ impl std::ops::Deref for OptionalHttpSession { } } -impl OptionalFromRequestParts for OptionalHttpSession { +impl OptionalFromRequestParts> for OptionalHttpSession { type Rejection = Redirect; async fn from_request_parts( parts: &mut Parts, - state: &HttpState, + state: &HttpState, ) -> Result, Self::Rejection> { let maybe_session = HttpSession::from_request_parts(parts, state) .await diff --git a/src/http/user.rs b/src/http/user.rs index 00fd976..2d0d385 100644 --- a/src/http/user.rs +++ b/src/http/user.rs @@ -12,8 +12,8 @@ pub struct UserCreationForm { pub password: String, } -pub async fn create_user( - State(mut state): State, +pub async fn create_user( + State(mut state): State>, session: HttpSession, Form(form): Form, ) -> Response { diff --git a/src/ldap/handler.rs b/src/ldap/handler.rs index 084cfa5..32d2ac0 100644 --- a/src/ldap/handler.rs +++ b/src/ldap/handler.rs @@ -1,13 +1,13 @@ use ldap3_proto::LdapMsg; use ldap3_proto::proto::LdapOp; -use crate::db::Database; +use crate::db::{Database, DatabaseInterface}; use crate::ldap::{ LdapClientState, LdapStream, LdapStreamError, op_bind, op_ext, search_by_mail_filter, }; #[tracing::instrument(name = "ldap", skip(stream, db), fields(session = %stream.session))] -pub async fn ldap_handler(mut stream: LdapStream, mut db: Database) { +pub async fn ldap_handler(mut stream: LdapStream, mut db: Database) { tracing::info! { remote_addr = ?stream.remote_addr, "New client connection" @@ -45,11 +45,11 @@ pub async fn ldap_handler(mut stream: LdapStream, mut db: Database) { /// Return true to keep the connection going, false to close it. #[tracing::instrument(name = "ldap-handler", skip(client_state, db, stream))] -pub async fn ldap_handler_inner( +pub async fn ldap_handler_inner( stream: &mut LdapStream, msg: LdapMsg, client_state: &mut LdapClientState, - db: &mut Database, + db: &mut Database, ) -> Result { tracing::debug!(msg = ?msg, "Received LDAP message"); match msg { diff --git a/src/ldap/op/bind.rs b/src/ldap/op/bind.rs index 144efaa..fabdfa6 100644 --- a/src/ldap/op/bind.rs +++ b/src/ldap/op/bind.rs @@ -2,7 +2,7 @@ use ldap3_proto::proto::{LdapBindCred, LdapBindRequest, LdapBindResponse, LdapOp use ldap3_proto::{LdapMsg, LdapResultCode}; use crate::db::error::BoxedError; -use crate::db::{Database, UserRef}; +use crate::db::{Database, DatabaseInterface, UserRef}; use crate::ldap::{Dn, LdapReturnError, LdapStream, LdapStreamError, MalformedDn}; #[derive(Debug)] @@ -165,9 +165,9 @@ pub async fn bind_success(stream: &mut LdapStream, msgid: i32) -> Result<(), Lda /// /// On success, returns `Ok(Some(bound_dn))`. `Ok(None)` means credentials failed, /// either because the account does not exist, or the password is wrong. -pub async fn op_bind( +pub async fn op_bind( stream: &mut LdapStream, - db: &Database, + db: &Database, req: LdapBindRequest, msgid: i32, ) -> Result, LdapStreamError> { diff --git a/src/ldap/op/search.rs b/src/ldap/op/search.rs index d881508..9182fdb 100644 --- a/src/ldap/op/search.rs +++ b/src/ldap/op/search.rs @@ -174,9 +174,9 @@ fn search_entry_from_user(user: &User, req_attrs: &[String]) -> LdapSearchResult } } -pub async fn search_by_mail_filter( +pub async fn search_by_mail_filter( stream: &mut LdapStream, - db: &Database, + db: &Database, sr: LdapSearchRequest, msgid: i32, ) -> Result<(), LdapStreamError> { diff --git a/src/main.rs b/src/main.rs index ac42c60..cb6ee76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,12 +12,12 @@ mod stream; #[cfg(feature = "http")] use crate::http::http_listen; use cli::CliArgs; -use db::{Database, DatabaseInterface, FilesystemDatabase, MemoryDatabase, Role, User}; +use db::{Database, DatabaseInterface, MemoryDatabase, Role, User}; use error::GlobalError; use ldap::ldap_handler; use listener::ListenerPath; -async fn create_dummy_users(db: &mut Database) { +async fn create_dummy_users(db: &mut Database) { db.create_user(User { username: "admin".to_string(), domain: None, @@ -69,11 +69,7 @@ async fn main() -> Result<(), GlobalError> { let ldap_listener = ListenerPath::new(&cli.listen_ldap)?.listener().await?; - let mut db = if let Some(db_path) = &cli.db { - FilesystemDatabase::from_path(db_path).await.unwrap() - } else { - MemoryDatabase::new() - }; + let mut db = MemoryDatabase::new(); create_dummy_users(&mut db).await; #[cfg(feature = "http")]