|
@ -1,3 +1,4 @@ |
|
|
|
|
|
use std::borrow::Cow;
|
|
|
use std::error::Error;
|
|
|
use std::error::Error;
|
|
|
use std::fmt;
|
|
|
use std::fmt;
|
|
|
use std::io::Error as IoError;
|
|
|
use std::io::Error as IoError;
|
|
@ -70,13 +71,13 @@ impl fmt::Display for UserError { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub struct User<'a, E, A> where E: Error + Sized, A: 'a + UserAdder<SubE=E> {
|
|
|
pub struct User<'a, E, A> where E: Error + Sized, A: 'a + UserAdder<SubE=E> {
|
|
|
user_name: &'a str,
|
|
|
|
|
|
|
|
|
user_name: Cow<'a, str>,
|
|
|
command_runner: &'a CommandRunner,
|
|
|
command_runner: &'a CommandRunner,
|
|
|
user_adder: &'a A
|
|
|
user_adder: &'a A
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<'a, E: Error + Sized, A: 'a + UserAdder<SubE=E>> User<'a, E, A> {
|
|
|
impl<'a, E: Error + Sized, A: 'a + UserAdder<SubE=E>> User<'a, E, A> {
|
|
|
pub fn new(user_name: &'a str, command_runner: &'a CommandRunner, user_adder: &'a A) -> User<'a, E, A> {
|
|
|
|
|
|
|
|
|
pub fn new(user_name: Cow<'a, str>, command_runner: &'a CommandRunner, user_adder: &'a A) -> User<'a, E, A> {
|
|
|
User {
|
|
|
User {
|
|
|
user_name: user_name,
|
|
|
user_name: user_name,
|
|
|
command_runner: command_runner,
|
|
|
command_runner: command_runner,
|
|
@ -93,7 +94,7 @@ impl<'a, E: Error, A: UserAdder<SubE=E>> fmt::Display for User<'a, E, A> { |
|
|
|
|
|
|
|
|
impl<'a, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, E, A> {
|
|
|
impl<'a, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, E, A> {
|
|
|
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
|
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
|
let output = self.command_runner.run_with_args("getent", &["passwd", self.user_name]);
|
|
|
|
|
|
|
|
|
let output = self.command_runner.run_with_args("getent", &["passwd", &*self.user_name]);
|
|
|
match output {
|
|
|
match output {
|
|
|
Ok(output) => match output.status.code() {
|
|
|
Ok(output) => match output.status.code() {
|
|
|
Some(2) => Ok(false),
|
|
|
Some(2) => Ok(false),
|
|
@ -105,7 +106,7 @@ impl<'a, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, E, A> { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn execute(&self) -> Result<(), Box<Error>> {
|
|
|
fn execute(&self) -> Result<(), Box<Error>> {
|
|
|
self.user_adder.add_user(self.user_name).map_err(|e| Box::new(e) as Box<Error>)
|
|
|
|
|
|
|
|
|
self.user_adder.add_user(&*self.user_name).map_err(|e| Box::new(e) as Box<Error>)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|