From 144d6f9189b36a581fdc4e5a76cb982e9253ff74 Mon Sep 17 00:00:00 2001 From: madonuko Date: Thu, 18 Jul 2024 20:40:42 +0800 Subject: [PATCH] feat(cfg/auth): Auth.add_to_chroot() --- src/cfg/auth.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cfg/auth.rs b/src/cfg/auth.rs index 97907bf..87b2c65 100644 --- a/src/cfg/auth.rs +++ b/src/cfg/auth.rs @@ -52,7 +52,7 @@ impl Auth { shadow } - pub fn add_user(&self) -> Result<(), std::io::Error> { + pub fn add_user(&self) -> std::io::Result<()> { let mut cmd = std::process::Command::new("useradd"); cmd.arg(&self.username); if let Some(shell) = &self.shell { @@ -69,4 +69,10 @@ impl Auth { } cmd.output().map(|_| ()) } + + #[tracing::instrument] + pub fn add_to_chroot(&self, chroot: &std::path::Path) -> std::io::Result<()> { + tracing::debug!("Adding user to chroot"); + tiffin::Container::new(chroot.to_owned()).run(|| self.add_user()).and_then(|r| r) + } }