From: Ian Jackson Date: Thu, 12 Nov 2020 21:55:17 +0000 (+0000) Subject: check acl format X-Git-Tag: otter-0.2.0~532 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6730dae884b021211678a72ed5cb9679a348ca08;p=otter.git check acl format Signed-off-by: Ian Jackson --- diff --git a/src/spec.rs b/src/spec.rs index 0f8ffdc1..aa75aa14 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -53,6 +53,8 @@ pub enum SpecError { PosOffTable, LibraryNotFound, LibraryItemNotFound, + AclInvalidAccountGlob, + AclEntryOverlappingAllowDeny, } display_as_debug!{SpecError} @@ -116,7 +118,6 @@ struct UrlOnStdout; //#[derive(Debug,Serialize,Deserialize)] //struct TokenByEmail { email: String }; // xxx ^ implement this -// xxx ^ //---------- Game TOML file ---------- @@ -244,6 +245,7 @@ pub mod implementation { use crate::imports::*; type AS = AccountScope; + type SE = SpecError; type TPS = TablePlayerSpec; impl Default for Acl

{ @@ -255,9 +257,17 @@ pub mod implementation { { self.ents.serialize(s) } } - impl From> for Acl

{ - fn from(ents: RawAcl

) -> Self { - // xxx check + impl TryFrom> for Acl

{ + type Error = SpecError; + #[throws(SpecError)] + fn try_from(ents: RawAcl

) -> Self { + for ent in &ents { + glob::Pattern::new(&ent.account_glob) + .map_err(|_| SE::AclInvalidAccountGlob)?; + if ! ent.deny.is_disjoint(&ent.allow) { + throw!(SE::AclEntryOverlappingAllowDeny); + } + } Acl { ents } } }