chiark / gitweb /
otter cli: change the meaning of list and list-all
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Mar 2021 19:22:37 +0000 (19:22 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Mar 2021 11:42:03 +0000 (11:42 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bin/otter.rs
src/spec.rs

index 3ae2df2f42d33210365a0326661b1b4dcc3a6d58..708ff2275f8563af787548dfd86d7aeaa6e83471 100644 (file)
@@ -180,17 +180,33 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse {
     }
 
     MC::ListGames { all } => {
-      let (scope, auth) = if all == Some(true) {
-        let auth = authorise_scope_direct(cs, &AS::Server)?;
-        (None, auth.therefore_ok())
+      let ag = AccountsGuard::lock();
+      let names = Instance::list_names(
+        None, Authorisation::authorise_any());
+      let auth_all = if all == Some(true) {
+        let auth =cs.superuser.ok_or(ME::AuthorisationError)?.into();
+        Some(auth)
       } else {
-        let AccountSpecified { notional_account, auth, .. } =
-          cs.account.as_ref().ok_or(ME::SpecifyAccount)?;
-        (Some(notional_account), *auth)
+        None
       };
-      let mut games = Instance::list_names(scope, auth);
-      games.sort_unstable();
-      MR::GamesList(games)
+      let mut names = names.into_iter().map(|name| {
+        let gref = Instance::lookup_by_name_unauth(&name)?;
+        let mut igu = gref.lock_even_poisoned();
+        let _ig = if let Some(auth_all) = auth_all {
+          igu.by_ref(auth_all)
+        } else {
+          cs.check_acl(&ag, &mut igu, PCH::Instance, &[TP::ShowInList])?.0
+        };
+        Ok::<_,ME>(name)
+      }).filter(|ent| matches_doesnot!(
+        ent,
+        = Ok(_),
+        ! Err(ME::GameNotFound) | Err(ME::AuthorisationError),
+        = Err(_),
+      ))
+        .collect::<Result<Vec<_>,_>>() ?;
+      names.sort_unstable();
+      MR::GamesList(names)
     }
 
     MC::AlterGame { game, insns, how } => {
index d21aa85980c54dc56571cdc3b3002545c9c639cb..3107160261410d269085e2c8e19199f3682ee934 100644 (file)
@@ -501,6 +501,7 @@ fn connect(ma: &MainOpts) -> Conn {
 
 const PLAYER_ALWAYS_PERMS: &[TablePermission] = &[
   TP::TestExistence,
+  TP::ShowInList,
   TP::ViewNotSecret,
   TP::Play,
 ];
@@ -600,7 +601,7 @@ mod list_games {
     let mut ap = ArgumentParser::new();
     ap.refer(&mut sa.all)
       .add_option(&["--all"],StoreTrue,
-                    "list all games, not just yours");
+                  "user superuser access to list *all* games");
     ap
   }
 
index 7da64d575a258440f5c80baa381baf187ca668a7..58125f7706fcc3ad512e6f9157c45d7f5c35d372 100644 (file)
@@ -121,6 +121,7 @@ pub struct AclEntry<Perm: Eq + Hash> {
 #[derive(FromPrimitive,ToPrimitive)]
 pub enum TablePermission {
   TestExistence,
+  ShowInList,
   ViewNotSecret,
   Play,
   ChangePieces,