chiark / gitweb /
wip errors from introducing accounts
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 2 Nov 2020 00:03:01 +0000 (00:03 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 2 Nov 2020 00:03:01 +0000 (00:03 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/accounts.rs
src/api.rs
src/cmdlistener.rs
src/global.rs
src/spec.rs

index 9c9c7370d201e7ac69c3ed930731e88bcdb2020b..c02a0096477fd2c597bdfa0db164baeb6ea37da9 100644 (file)
@@ -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<Arc<AccountName>, AccountId>,
   records: DenseSlotMap<AccountId, AccountRecord>,
 }
@@ -187,7 +189,7 @@ impl From<Box<dyn PlayerAccessSpec>> 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<AccountId>;
 }
 
@@ -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<P:Perm> From<Acl<P>> for LoadedAcl<P> {
     fn from(acl: Acl<P>) -> LoadedAcl<P> {
-      (&acl).into()
-    }
-  }
-
-  impl<P:Perm> From<&Acl<P>> for LoadedAcl<P> {
-    fn from(acl: &Acl<P>) -> LoadedAcl<P> {
       let ents = acl.ents.into_iter().filter_map(
         |AclEntry { account_glob, allow, deny }|
         {
@@ -482,19 +478,13 @@ pub mod loaded_acl {
 
   impl<P:Perm> From<LoadedAcl<P>> for Acl<P> {
     fn from(acl: LoadedAcl<P>) -> Acl<P> {
-      (&acl).into()
-    }
-  }
-
-  impl<P:Perm> From<&LoadedAcl<P>> for Acl<P> {
-    fn from(acl: &LoadedAcl<P>) -> Acl<P> {
       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() }
     }
index 2d575a42cfd9253186f1b66e83e8b8080508d1a9..74c522b40a7e7269a8def9ab3825d7bb0c39efbb 100644 (file)
@@ -20,7 +20,6 @@ struct ApiPieceOpArgs<'a> {
   player: PlayerId,
   piece: PieceId,
   p: &'a dyn Piece,
-  iplayers: &'a SecondarySlotMap<PlayerId, PlayerRecord>,
   lens: &'a dyn Lens /* used for LogEntry and PieceId but not Pos */
 }
 
@@ -143,7 +142,7 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
     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,
       })?;
index 123f52873f8e843f5b59f0c03798487755f52b40..e0656abd95b7376fc1b2852a32ee8509678a2812 100644 (file)
@@ -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<InstanceName>)
   {
     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 = &current_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
index 28b22f4c7559f745a3d71895be00ddff650c0803..a58bd45d90e115c3cf6e9720903ef1cd1169bd6a 100644 (file)
@@ -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(),
index f654f1e507485b12ac5ec4aaead0ac8e4167697f..4ca6e3fa21fee93e10d0d4b6ca1773a870e7cc08 100644 (file)
@@ -233,7 +233,6 @@ pub mod pos_traits {
 pub mod implementation {
   use super::*;
   use crate::imports::*;
-  type Insn = crate::commands::MgmtGameInstruction;
 
   impl<P: Eq + Hash> Default for Acl<P> {
     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