Explicitly set home dir

Bookworm defaults to /nonexisting for system accounts.
This commit is contained in:
Adrian Heine 2023-09-12 11:26:54 +02:00
parent 6d564e58e0
commit 6b34c9ea34
4 changed files with 30 additions and 23 deletions

View file

@ -4,27 +4,30 @@ use async_trait::async_trait;
use once_cell::sync::Lazy;
use std::error::Error;
use tokio::sync::Semaphore;
use std::path::Path;
pub type Wait = Lazy<Semaphore>;
static WAIT: Wait = Lazy::new(|| Semaphore::new(1));
#[derive(Debug)]
pub struct User<U, C> {
pub struct User<U, H, C> {
user_name: U,
home_path: H,
command_runner: C,
}
impl<U, C> User<U, C> {
pub const fn new(user_name: U, command_runner: C) -> Self {
impl<U, H, C> User<U, H, C> {
pub const fn new(user_name: U, home_path: H, command_runner: C) -> Self {
Self {
user_name,
home_path,
command_runner,
}
}
}
#[async_trait(?Send)]
impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
impl<U: AsRef<str>, H: AsRef<Path>, C: CommandRunner> Symbol for User<U, H, C> {
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let output = self
.command_runner
@ -48,6 +51,8 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
args![
// "-m", // Necessary for Fedora, not accepted in Debian
"--system",
"--home",
self.home_path.as_ref(),
self.user_name.as_ref(),
],
)