Files
inbuxa-server/crates/directory/src/lib.rs
T
jcoffey-dev 6a53d47106 Mark the files this fork changed (AGPL section 5(a))
The AGPL asks a modified version to carry prominent notices saying it was
modified, and giving a date. Publishing the source is the conveyance that
asks for it, so it wants doing before the repository is public rather than
at the release.

Every upstream file the fork changed now says so in its header, beneath the
notice it came with: 164 files, found by diffing against the upstream
snapshot branch rather than by guessing, so the list is what actually
differs. Files the fork wrote itself already carry their own copyright and
need nothing. Upstream's notices are untouched, which its licence requires
and which was already true.

The README says the same thing in prose, since the obligation is on the
work as a whole and not only its Rust files.

Builds unchanged: the server and the test binary both compile.
2026-09-19 23:48:35 -07:00

133 lines
3.3 KiB
Rust

/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*
* Modified by Coffey Labs in 2026 for INBUXA.
*/
// inbuxa: composite stores (sharded members, read replicas) nest store
// futures deeply enough to pass rustc's default query depth
#![recursion_limit = "512"]
#![warn(clippy::large_futures)]
use crate::backend::oidc::OpenIdDirectory;
use backend::{ldap::LdapDirectory, sql::SqlDirectory};
use deadpool::managed::PoolError;
use ldap3::LdapError;
use registry::schema::enums::DirectoryType;
use std::{collections::HashMap, fmt::Debug, sync::Arc};
pub mod backend;
pub mod core;
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum Credentials {
Basic {
username: String,
secret: String,
mfa_token: Option<String>,
},
Bearer {
username: Option<String>,
token: String,
},
}
#[allow(clippy::large_enum_variant)]
pub enum Directory {
Ldap(LdapDirectory),
Sql(SqlDirectory),
OpenId(OpenIdDirectory),
Unavailable(UnavailableDirectory),
}
pub struct UnavailableDirectory {
directory_type: DirectoryType,
error: String,
}
impl UnavailableDirectory {
pub fn new(directory_type: DirectoryType, error: impl Into<String>) -> Self {
Self {
directory_type,
error: error.into(),
}
}
pub fn directory_type(&self) -> DirectoryType {
self.directory_type
}
pub fn error(&self) -> trc::Error {
trc::StoreEvent::NotConfigured
.into_err()
.details("Directory is unavailable because it failed to initialize")
.reason(&self.error)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Recipient {
Account(Account),
Group(Group),
Invalid,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Account {
pub email: String,
pub email_aliases: Vec<String>,
pub secret: Option<String>,
pub groups: Option<Vec<String>>,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Group {
pub email: String,
pub email_aliases: Vec<String>,
pub description: Option<String>,
}
#[derive(Clone, Debug)]
pub struct Directories {
pub default_directory: Option<Arc<Directory>>,
pub directories: HashMap<u32, Arc<Directory>, nohash_hasher::BuildNoHashHasher<u32>>,
}
impl Debug for Directory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Directory").finish()
}
}
trait IntoError {
fn into_error(self) -> trc::Error;
}
impl IntoError for PoolError<LdapError> {
fn into_error(self) -> trc::Error {
match self {
PoolError::Backend(error) => error.into_error(),
PoolError::Timeout(_) => trc::StoreEvent::PoolError
.into_err()
.details("Connection timed out"),
err => trc::StoreEvent::PoolError.reason(err),
}
}
}
impl IntoError for LdapError {
fn into_error(self) -> trc::Error {
if let LdapError::LdapResult { result } = &self {
trc::StoreEvent::LdapError
.ctx(trc::Key::Code, result.rc)
.reason(self)
} else {
trc::StoreEvent::LdapError.reason(self)
}
}
}