remove duplicated code
This commit is contained in:
parent
ffafa7e473
commit
abdb704ba0
@ -42,55 +42,19 @@ impl UserDBLocal {
|
|||||||
shadow_content: &str,
|
shadow_content: &str,
|
||||||
group_content: &str,
|
group_content: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let shadow_entries: Vec<crate::Shadow> = shadow_content
|
let shadow_entries: Vec<crate::Shadow> = string_to(&shadow_content);
|
||||||
.lines()
|
let mut users = user_vec_to_hashmap(string_to(&passwd_content));
|
||||||
.filter_map(|line| {
|
let groups = string_to(&group_content);
|
||||||
if line.len() > 5 {
|
shadow_to_users(&mut users, shadow_entries);
|
||||||
Some(crate::Shadow::new_from_string(line.to_owned()).expect("Parsing failed"))
|
let res = Self {
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let mut res = Self {
|
|
||||||
source_files: Files {
|
source_files: Files {
|
||||||
passwd: None,
|
passwd: None,
|
||||||
group: None,
|
group: None,
|
||||||
shadow: None,
|
shadow: None,
|
||||||
},
|
},
|
||||||
users: passwd_content
|
users,
|
||||||
.lines()
|
group_entries: groups,
|
||||||
.filter_map(|line| {
|
|
||||||
if line.len() > 5 {
|
|
||||||
println!("{}", line);
|
|
||||||
let user = crate::User::new_from_string(line.to_owned())
|
|
||||||
.expect("failed to read lines");
|
|
||||||
Some((user.get_username().to_owned(), user))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
group_entries: group_content
|
|
||||||
.lines()
|
|
||||||
.filter_map(|line| {
|
|
||||||
if line.len() > 5 {
|
|
||||||
Some(
|
|
||||||
crate::Group::new_from_string(line.to_owned()).expect("Parsing failed"),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
};
|
};
|
||||||
for shadow in shadow_entries {
|
|
||||||
let user = res.users.get_mut(shadow.get_username()).expect(&format!(
|
|
||||||
"the user {} does not exist",
|
|
||||||
shadow.get_username()
|
|
||||||
));
|
|
||||||
user.password = crate::Password::Shadow(shadow);
|
|
||||||
}
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user