feat: added basic ACL functionality

This commit is contained in:
NinekoTheCat 2023-12-24 11:03:02 +01:00
parent 6a9f8dfa6f
commit 7562925aeb
No known key found for this signature in database
GPG key ID: 700DB3F678A4AB66
13 changed files with 183 additions and 4 deletions

View 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())
}
}

View file

@ -11,3 +11,5 @@ mod sending;
mod transaction_ids;
mod uiaa;
mod users;
mod acl;