Browse Source

Explicitly set home dir

Bookworm defaults to /nonexisting for system accounts.
master
Adrian Heine 8 months ago
parent
commit
6b34c9ea34
  1. 24
      src/builder.rs
  2. 12
      src/locator.rs
  3. 4
      src/resources/mod.rs
  4. 13
      src/symbols/user.rs

24
src/builder.rs

@ -121,7 +121,7 @@ impl<D: Clone> ImplementationBuilder<Cert<D>> for DefaultBuilder {
fn create(
resource: &Cert<D>,
target: &<Cert<D> as Resource>::Artifact,
(csr, root_cert, account_key, challenges_dir, user_name, _): <Self::Prerequisites as ToArtifact>::Artifact,
(csr, root_cert, account_key, challenges_dir, (user_name, _), _): <Self::Prerequisites as ToArtifact>::Artifact,
) -> Self::Implementation {
CertSymbol::new(
resource.0.clone(),
@ -552,13 +552,13 @@ impl<D: Clone> ImplementationBuilder<UserForDomain<D>> for DefaultBuilder {
type Prerequisites = ();
fn prerequisites(_resource: &UserForDomain<D>) -> Self::Prerequisites {}
type Implementation = UserSymbol<Rc<str>, StdCommandRunner>;
type Implementation = UserSymbol<Rc<str>, Rc<Path>, StdCommandRunner>;
fn create(
_resource: &UserForDomain<D>,
(user_name, _home_path): &<UserForDomain<D> as Resource>::Artifact,
(user_name, home_path): &<UserForDomain<D> as Resource>::Artifact,
(): <Self::Prerequisites as ToArtifact>::Artifact,
) -> Self::Implementation {
UserSymbol::new(user_name.0.clone(), StdCommandRunner)
UserSymbol::new(user_name.0.clone(), home_path.into(), StdCommandRunner)
}
}
@ -566,13 +566,13 @@ impl ImplementationBuilder<User> for DefaultBuilder {
type Prerequisites = ();
fn prerequisites(_resource: &User) -> Self::Prerequisites {}
type Implementation = UserSymbol<Rc<str>, StdCommandRunner>;
type Implementation = UserSymbol<Rc<str>, Rc<Path>, StdCommandRunner>;
fn create(
resource: &User,
(): &<User as Resource>::Artifact,
home_path: &<User as Resource>::Artifact,
(): <Self::Prerequisites as ToArtifact>::Artifact,
) -> Self::Implementation {
UserSymbol::new(resource.0.clone(), StdCommandRunner)
UserSymbol::new(resource.0.clone(), home_path.into(), StdCommandRunner)
}
}
@ -594,13 +594,13 @@ impl ImplementationBuilder<AcmeUser> for DefaultBuilder {
type Prerequisites = ();
fn prerequisites(_resource: &AcmeUser) -> Self::Prerequisites {}
type Implementation = UserSymbol<Rc<str>, StdCommandRunner>;
type Implementation = UserSymbol<Rc<str>, Rc<Path>, StdCommandRunner>;
fn create(
_resource: &AcmeUser,
user_name: &<AcmeUser as Resource>::Artifact,
(user_name, home_path): &<AcmeUser as Resource>::Artifact,
(): <Self::Prerequisites as ToArtifact>::Artifact,
) -> Self::Implementation {
UserSymbol::new(user_name.0.clone(), StdCommandRunner)
UserSymbol::new(user_name.0.clone(), home_path.into(), StdCommandRunner)
}
}
@ -617,7 +617,7 @@ impl ImplementationBuilder<AcmeChallengesDir> for DefaultBuilder {
fn create(
_resource: &AcmeChallengesDir,
target: &<AcmeChallengesDir as Resource>::Artifact,
user_name: <Self::Prerequisites as ToArtifact>::Artifact,
(user_name, _): <Self::Prerequisites as ToArtifact>::Artifact,
) -> Self::Implementation {
(
DirSymbol::new(target.clone_rc()),
@ -658,7 +658,7 @@ impl ImplementationBuilder<AcmeAccountKey> for DefaultBuilder {
fn create(
_resource: &AcmeAccountKey,
target: &<AcmeAccountKey as Resource>::Artifact,
user_name: <Self::Prerequisites as ToArtifact>::Artifact,
(user_name, _): <Self::Prerequisites as ToArtifact>::Artifact,
) -> Self::Implementation {
(
KeySymbol::new(StdCommandRunner, target.clone_rc()),

12
src/locator.rs

@ -202,8 +202,9 @@ impl<P: Policy> ResourceLocator<AcmeAccountKey> for DefaultLocator<P> {
impl<P: Policy> ResourceLocator<AcmeUser> for DefaultLocator<P> {
type Prerequisites = ();
fn locate(_resource: &AcmeUser) -> (<AcmeUser as Resource>::Artifact, Self::Prerequisites) {
let acme_user = P::acme_user();
(UserNameArtifact(acme_user.into()), ())
let user_name = P::acme_user();
let home = P::user_home(&user_name);
((UserNameArtifact(user_name.into()), PathArtifact::from(home)), ())
}
}
@ -264,10 +265,11 @@ impl<P: Policy, D: AsRef<str>> ResourceLocator<UserForDomain<D>> for DefaultLoca
}
}
impl<P> ResourceLocator<User> for DefaultLocator<P> {
impl<P: Policy> ResourceLocator<User> for DefaultLocator<P> {
type Prerequisites = ();
fn locate(_resource: &User) -> (<User as Resource>::Artifact, Self::Prerequisites) {
((), ())
fn locate(resource: &User) -> (<User as Resource>::Artifact, Self::Prerequisites) {
let home = P::user_home(&resource.0);
((PathArtifact::from(home)), ())
}
}

4
src/resources/mod.rs

@ -91,7 +91,7 @@ impl Resource for AcmeAccountKey {
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct AcmeUser;
impl Resource for AcmeUser {
type Artifact = UserNameArtifact;
type Artifact = (UserNameArtifact, PathArtifact);
}
#[derive(Debug, Hash, PartialEq, Eq)]
@ -138,7 +138,7 @@ pub fn get_saved_directory(
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct User(pub Rc<str>);
impl Resource for User {
type Artifact = ();
type Artifact = PathArtifact;
}
#[derive(Debug, Hash, PartialEq, Eq)]

13
src/symbols/user.rs

@ -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(),
],
)

Loading…
Cancel
Save