From: Ian Jackson Date: Mon, 2 Nov 2020 00:03:01 +0000 (+0000) Subject: wip errors from introducing accounts X-Git-Tag: otter-0.2.0~560 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c76e443a06cea0b9f19fe441b08f232a0abd2019;p=otter.git wip errors from introducing accounts Signed-off-by: Ian Jackson --- diff --git a/src/accounts.rs b/src/accounts.rs index 9c9c7370..c02a0096 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -42,7 +42,7 @@ impl AccountScope { E, F: FnMut(&str) -> Result<(),E> > - (&'out self, ns: NS, f: F) + (&'out self, ns: NS, mut f: F) { const ENCODE : percent_encoding::AsciiSet = percent_encoding::NON_ALPHANUMERIC.remove(b':'); @@ -69,7 +69,7 @@ impl AccountScope { let mut split = s.split(':'); let scope = { - let next = ||{ + let mut next = ||{ split.next() .ok_or(InvalidScopedName::MissingScopeComponent) }; @@ -109,7 +109,9 @@ impl Display for AccountName { #[throws(fmt::Error)] /// Return value is parseable, and filesystem- and html-safeb fn fmt(&self, f: &mut fmt::Formatter) { - self.scope.display_name(&[ self.subaccount.as_str() ], |s| f.write_str(s)) + self.scope.display_name(&[ + self.subaccount.as_str() + ], |s| f.write_str(s))? } } @@ -132,7 +134,7 @@ impl FromStr for AccountName { #[throws(InvalidScopedName)] fn from_str(s: &str) -> Self { - let subaccount = default(); + let mut subaccount = default(); let names = std::slice::from_mut(&mut subaccount); let scope = AccountScope::parse_name(s, names)?; AccountName { scope, subaccount } @@ -161,7 +163,7 @@ pub struct TokenRevelation { #[derive(Debug,Default)] #[derive(Serialize,Deserialize)] -struct Accounts { +pub struct Accounts { names: HashMap, AccountId>, records: DenseSlotMap, } @@ -187,7 +189,7 @@ impl From> for AccessRecord { // xxx load, incl reveleation expiry // xxx periodic token reveleation expiry -trait AccountNameOrId : Copy { +pub trait AccountNameOrId : Copy { fn initial_lookup(self, accounts: &Accounts) -> Option; } @@ -294,9 +296,9 @@ impl AccountsGuard { { use hash_map::Entry::*; let accounts = self.0.get_or_insert_with(default); - let name_entry = accounts.names.entry(new_record.account.clone()); + let mut name_entry = accounts.names.entry(new_record.account.clone()); if_chain!{ - if let Occupied(oe) = name_entry; + if let Occupied(ref mut oe) = name_entry; let acctid = *oe.get(); if let Some(old_record) = accounts.records.get_mut(acctid); then { @@ -305,7 +307,7 @@ impl AccountsGuard { let acctid = accounts.records.insert(new_record); match name_entry { Vacant(ve) => { ve.insert(acctid); } - Occupied(oe) => { oe.insert(acctid); } + Occupied(ref mut oe) => { oe.insert(acctid); } } } } @@ -453,12 +455,6 @@ pub mod loaded_acl { impl From> for LoadedAcl

{ fn from(acl: Acl

) -> LoadedAcl

{ - (&acl).into() - } - } - - impl From<&Acl

> for LoadedAcl

{ - fn from(acl: &Acl

) -> LoadedAcl

{ let ents = acl.ents.into_iter().filter_map( |AclEntry { account_glob, allow, deny }| { @@ -482,19 +478,13 @@ pub mod loaded_acl { impl From> for Acl

{ fn from(acl: LoadedAcl

) -> Acl

{ - (&acl).into() - } - } - - impl From<&LoadedAcl

> for Acl

{ - fn from(acl: &LoadedAcl

) -> Acl

{ let LoadedAcl(ents) = acl; Acl { ents: ents.into_iter().map( |LoadedAclEntry { pat, allow, deny, .. }| AclEntry { account_glob: pat.to_string(), - allow: unpack(allow), - deny: unpack(deny), + allow: unpack(&allow), + deny: unpack(&deny), } ).collect() } } diff --git a/src/api.rs b/src/api.rs index 2d575a42..74c522b4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -20,7 +20,6 @@ struct ApiPieceOpArgs<'a> { player: PlayerId, piece: PieceId, p: &'a dyn Piece, - iplayers: &'a SecondarySlotMap, lens: &'a dyn Lens /* used for LogEntry and PieceId but not Pos */ } @@ -143,7 +142,7 @@ fn api_piece_op(form : Json>) form.op.check_held(pc,player)?; let (wrc, update, logents) = form.op.op(ApiPieceOpArgs { - gs, player, piece, iplayers, + gs, player, piece, p: p.as_ref(), lens: &lens, })?; diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 123f5287..e0656abd 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -215,7 +215,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { // ---------- game command implementations ---------- -type ExecuteGameInsnResults<'igr, 'ig : 'igr> = ( +type ExecuteGameInsnResults<'igr, 'ig> = ( ExecuteGameChangeUpdates, MgmtGameResponse, &'igr mut InstanceGuard<'ig>, @@ -514,19 +514,19 @@ fn execute_for_game<'cs, 'igr, 'ig : 'igr>( { let mut uh = UpdateHandler::from_how(how); let mut responses = Vec::with_capacity(insns.len()); - let mut iga = None; + let mut auth = None; let res = (||{ for insn in insns.drain(0..) { let (updates, resp, ig) = execute_game_insn(cs, ag, igu, insn)?; uh.accumulate(ig, updates)?; responses.push(resp); - iga = Some(ig); + auth = Some(Authorisation::authorised(&*ig.name)); } - if let Some(ig) = iga { uh.complete(cs,ig)?; } + if let Some(auth) = auth { uh.complete(cs, igu.by_mut(auth))?; } Ok(None) })(); - if let Some(ig) = iga { - ig.save_game_now()?; + if let Some(auth) = auth { + igu.by_mut(auth).save_game_now()?; } MgmtResponse::AlterGame { responses, @@ -770,7 +770,7 @@ impl CommandStream<'_> { Authorisation) { let ipl_unauth = { - let ig = ig.by(Authorisation::authorise_any()); + let ig = ig.by_ref(Authorisation::authorise_any()); ig.iplayers.byid(player)? }; let how = PCH::InstanceOrOnlyAffectedAccount(ipl_unauth.ipl.acctid); @@ -831,7 +831,7 @@ impl CommandStream<'_> { PCH::InstanceOrOnlyAffectedPlayer(object_player) => { if_chain!{ if let Some(object_ipr) = - ig.by(Authorisation::authorise_any()).iplayers + ig.by_ref(Authorisation::authorise_any()).iplayers .get(object_player); then { subject_is(object_ipr.ipl.acctid) } else { None } @@ -845,13 +845,12 @@ impl CommandStream<'_> { let auth = { let subject = ¤t_account.cooked; let (acl, owner) = { - let ig = ig.by(Authorisation::authorise_any()); + let ig = ig.by_ref(Authorisation::authorise_any()); (&ig.acl, &ig.name.account) }; - let eacl = EffectiveAcl { - owner_account : Some(&owner.to_string()), - acl : acl, - }; + let owner_account = owner.to_string(); + let owner_account = Some(owner_account.as_str()); + let eacl = EffectiveAcl { owner_account, acl }; eacl.check(subject, p)? }; auth diff --git a/src/global.rs b/src/global.rs index 28b22f4c..a58bd45d 100644 --- a/src/global.rs +++ b/src/global.rs @@ -844,7 +844,7 @@ impl InstanceGuard<'_> { |(player, PlayerRecord { ipl, .. })| (player, ipl.clone()) ).collect(); - let acl = (&s.c.g.acl).into(); + let acl = s.c.g.acl.clone().into(); let isa = InstanceSaveAccesses { ipieces, tokens_players, aplayers, acl }; @@ -943,7 +943,7 @@ impl InstanceGuard<'_> { let g = Instance { gs, iplayers, - acl: (&acl).into(), + acl: acl.into(), ipieces: PiecesLoaded(ipieces), name: name.clone(), clients : Default::default(), diff --git a/src/spec.rs b/src/spec.rs index f654f1e5..4ca6e3fa 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -233,7 +233,6 @@ pub mod pos_traits { pub mod implementation { use super::*; use crate::imports::*; - type Insn = crate::commands::MgmtGameInstruction; impl Default for Acl

{ fn default() -> Self { Acl { ents: default() } } @@ -272,7 +271,7 @@ pub mod implementation { } #[typetag::serde(tag="access")] - pub trait PlayerAccessSpec : Debug { + pub trait PlayerAccessSpec : Debug + Sync + Send { fn override_token(&self) -> Option<&RawToken> { // xxx check this on setting access None