Simplify SetuidCommandRunner
This commit is contained in:
parent
229eb3a9e9
commit
70786ebf40
3 changed files with 17 additions and 35 deletions
|
|
@ -115,12 +115,8 @@ impl<D: Clone> ImplementationBuilder<Cert<D>> for DefaultBuilder {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Implementation = CertSymbol<
|
type Implementation =
|
||||||
SetuidCommandRunner<'static, String, StdCommandRunner>,
|
CertSymbol<SetuidCommandRunner<String>, SetuidCommandRunner<String>, D, PathBuf>;
|
||||||
SetuidCommandRunner<'static, String, StdCommandRunner>,
|
|
||||||
D,
|
|
||||||
PathBuf,
|
|
||||||
>;
|
|
||||||
fn create(
|
fn create(
|
||||||
resource: &Cert<D>,
|
resource: &Cert<D>,
|
||||||
target: &<Cert<D> as Resource>::Artifact,
|
target: &<Cert<D> as Resource>::Artifact,
|
||||||
|
|
@ -128,7 +124,7 @@ impl<D: Clone> ImplementationBuilder<Cert<D>> for DefaultBuilder {
|
||||||
) -> Self::Implementation {
|
) -> Self::Implementation {
|
||||||
CertSymbol::new(
|
CertSymbol::new(
|
||||||
resource.0.clone(),
|
resource.0.clone(),
|
||||||
SetuidCommandRunner::new(user_name.0, &StdCommandRunner),
|
SetuidCommandRunner::new(user_name.0),
|
||||||
root_cert.into(),
|
root_cert.into(),
|
||||||
account_key.into(),
|
account_key.into(),
|
||||||
challenges_dir.into(),
|
challenges_dir.into(),
|
||||||
|
|
@ -448,7 +444,7 @@ impl<D, P: AsRef<Path>> ImplementationBuilder<SystemdSocketService<D, P>> for De
|
||||||
FileSymbol<PathBuf, String>,
|
FileSymbol<PathBuf, String>,
|
||||||
SystemdUserSessionSymbol<'static, String, StdCommandRunner>,
|
SystemdUserSessionSymbol<'static, String, StdCommandRunner>,
|
||||||
OwnerSymbol<StdCommandRunner, StdCommandRunner, PathBuf, String>,
|
OwnerSymbol<StdCommandRunner, StdCommandRunner, PathBuf, String>,
|
||||||
UserServiceSymbol<'static, PathBuf, String, StdCommandRunner>,
|
UserServiceSymbol<'static, PathBuf, String>,
|
||||||
);
|
);
|
||||||
fn create(
|
fn create(
|
||||||
resource: &SystemdSocketService<D, P>,
|
resource: &SystemdSocketService<D, P>,
|
||||||
|
|
@ -475,12 +471,7 @@ impl<D, P: AsRef<Path>> ImplementationBuilder<SystemdSocketService<D, P>> for De
|
||||||
user_name.0.clone(),
|
user_name.0.clone(),
|
||||||
StdCommandRunner,
|
StdCommandRunner,
|
||||||
),
|
),
|
||||||
UserServiceSymbol::new(
|
UserServiceSymbol::new(socket_path.clone().into(), user_name.0.clone(), resource.1),
|
||||||
socket_path.clone().into(),
|
|
||||||
user_name.0.clone(),
|
|
||||||
resource.1,
|
|
||||||
&StdCommandRunner,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,17 +78,13 @@ impl CommandRunner for StdCommandRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SetuidCommandRunner<'a, U: AsRef<str>, C: CommandRunner> {
|
pub struct SetuidCommandRunner<U: AsRef<str>> {
|
||||||
command_runner: &'a C,
|
|
||||||
user_name: U,
|
user_name: U,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, U: AsRef<str>, C: CommandRunner> SetuidCommandRunner<'a, U, C> {
|
impl<'a, U: AsRef<str>> SetuidCommandRunner<U> {
|
||||||
pub fn new(user_name: U, command_runner: &'a C) -> Self {
|
pub fn new(user_name: U) -> Self {
|
||||||
SetuidCommandRunner {
|
Self { user_name }
|
||||||
command_runner,
|
|
||||||
user_name,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +117,7 @@ impl Drop for TempSetEnv<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> {
|
impl<U: AsRef<str>> CommandRunner for SetuidCommandRunner<U> {
|
||||||
async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult<Output> {
|
async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult<Output> {
|
||||||
let uid = get_user_by_name(self.user_name.as_ref())
|
let uid = get_user_by_name(self.user_name.as_ref())
|
||||||
.expect("User does not exist")
|
.expect("User does not exist")
|
||||||
|
|
|
||||||
|
|
@ -8,28 +8,23 @@ use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UserService<'a, S: AsRef<Path>, U: AsRef<str>, R: CommandRunner> {
|
pub struct UserService<'a, S: AsRef<Path>, U: AsRef<str>> {
|
||||||
socket_path: S,
|
socket_path: S,
|
||||||
service_name: &'a str,
|
service_name: &'a str,
|
||||||
command_runner: SetuidCommandRunner<'a, U, R>,
|
command_runner: SetuidCommandRunner<U>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: AsRef<Path>, U: AsRef<str>, R: CommandRunner> UserService<'static, S, U, R> {
|
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'static, S, U> {
|
||||||
pub fn new(
|
pub fn new(socket_path: S, user_name: U, service_name: &'static str) -> Self {
|
||||||
socket_path: S,
|
|
||||||
user_name: U,
|
|
||||||
service_name: &'static str,
|
|
||||||
command_runner: &'static R,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
socket_path,
|
socket_path,
|
||||||
service_name,
|
service_name,
|
||||||
command_runner: SetuidCommandRunner::new(user_name, command_runner),
|
command_runner: SetuidCommandRunner::new(user_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: AsRef<Path>, U: AsRef<str>, R: CommandRunner> UserService<'_, S, U, R> {
|
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'_, S, U> {
|
||||||
async fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
|
async fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
|
||||||
let mut tries = 5;
|
let mut tries = 5;
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -85,7 +80,7 @@ impl<S: AsRef<Path>, U: AsRef<str>, R: CommandRunner> UserService<'_, S, U, R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<S: AsRef<Path>, U: AsRef<str>, R: CommandRunner> Symbol for UserService<'_, S, U, R> {
|
impl<S: AsRef<Path>, U: AsRef<str>> Symbol for UserService<'_, S, U> {
|
||||||
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||||
self.check_if_service().await
|
self.check_if_service().await
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue