chiark / gitweb /
sshkeys: Provide SshReinstallKeys command
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 8 Jun 2021 19:06:06 +0000 (20:06 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 8 Jun 2021 19:07:00 +0000 (20:07 +0100)
No corresponding cli subcommand - just use command-ron.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/commands.rs
src/sshkeys.rs

index 94808fc83dc6b41a8494405ecb3feb26a0524eeb..e396d426c42ad6458f43f764af76e3ee8b90bc13 100644 (file)
@@ -471,6 +471,13 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
       ag.sshkeys_remove(acctid, index, id, auth)?;
       MR::Fine
     }
+    MC::SshReinstallKeys => {
+      let superuser = cs.superuser()
+        .ok_or(ME::SuperuserAuthorisationRequired)?;
+      let mut ag = AccountsGuard::lock();
+      ag.sshkeys_rewrite_authorized_keys(superuser)?;
+      MR::Fine
+    }
 
     MC::LoadFakeRng(ents) => {
       let superuser = cs.superuser()
index 83e59c36a5e81ea7b0177480c041379e6d589a61..18a573b44f16106bf9915fff31762efa0daae0f4 100644 (file)
@@ -63,6 +63,7 @@ pub enum MgmtCommand {
   SshAddKey { akl: sshkeys::AuthkeysLine },
   SshDeleteKey { index: usize, id: sshkeys::Id },
   ThisConnAuthBy, // -> Fine or SshKeySpec
+  SshReinstallKeys, // managment only
 
   LoadFakeRng(Vec<String>),
 }
index a1e6525e16cfe1b2e6fdf0402d6eb894eba854c2..0eb67c4a730b6084df0e7251835a351fa5d46e32 100644 (file)
@@ -403,6 +403,16 @@ impl AccountsGuard {
     }
     // ABSENT
   }
+
+  #[throws(ME)]
+  pub fn sshkeys_rewrite_authorized_keys(
+    &mut self,
+    _:Authorisation<authproofs::Global>
+  ) {
+    let accounts = self.get_mut();
+    let gl = &mut accounts.ssh_keys;
+    gl.rewrite_authorized_keys()?;
+  }
 }
 
 impl Global {