mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2026-03-30 07:24:49 -04:00
feat: added basic ACL functionality
This commit is contained in:
parent
6a9f8dfa6f
commit
7562925aeb
13 changed files with 183 additions and 4 deletions
33
src/database/key_value/acl.rs
Normal file
33
src/database/key_value/acl.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use tracing::warn;
|
||||
|
||||
use crate::{service::acl::{Data, AclDatabaseEntry, AclMode}, KeyValueDatabase};
|
||||
|
||||
impl Data for KeyValueDatabase {
|
||||
fn check_acl(&self,host: &url::Host<String> ) -> crate::Result<Option<AclMode>> {
|
||||
let thing = self.acl_list.get(host.to_string().as_bytes())?;
|
||||
if let Some(thing) = thing {
|
||||
match thing.first() {
|
||||
Some(0x1) => Ok(Some(AclMode::Allow)),
|
||||
Some(0x0) => Ok(Some(AclMode::Block)),
|
||||
Some(invalid) => {
|
||||
warn!("found invalid value for mode byte in value {}, probably db corruption", invalid);
|
||||
Ok(None)
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn add_acl(&self, acl: AclDatabaseEntry) -> crate::Result<()> {
|
||||
self.acl_list.insert(acl.hostname.to_string().as_bytes(), match acl.mode {
|
||||
AclMode::Block => &[0x0],
|
||||
AclMode::Allow => &[0x1],
|
||||
})
|
||||
}
|
||||
|
||||
fn remove_acl(&self,host: url::Host<String>) -> crate::Result<()> {
|
||||
self.acl_list.remove(host.to_string().as_bytes())
|
||||
}
|
||||
}
|
||||
|
|
@ -11,3 +11,5 @@ mod sending;
|
|||
mod transaction_ids;
|
||||
mod uiaa;
|
||||
mod users;
|
||||
|
||||
mod acl;
|
||||
Loading…
Add table
Add a link
Reference in a new issue