actually remove the shadow line and fix a final newline

This commit is contained in:
Dietrich 2020-10-30 19:45:41 +01:00
parent bacbfae4d1
commit 6389bb988d
2 changed files with 20 additions and 0 deletions

View File

@ -85,6 +85,7 @@ impl LockedFileGuard {
self.file self.file
.write_all(&new_content.into_bytes()) .write_all(&new_content.into_bytes())
.expect("Failed to write all users."); .expect("Failed to write all users.");
let _ = self.file.write("\n".as_bytes());
Ok(()) Ok(())
} }

View File

@ -116,6 +116,25 @@ impl UserDBWrite for UserDBLocal {
let ncont = locked_p.replace_contents(modified_p); let ncont = locked_p.replace_contents(modified_p);
match ncont { match ncont {
Ok(_) => { Ok(_) => {
let shad = user.get_shadow();
match shad {
Some(shadow) => {
let modified_s = shadow.remove_in(&s);
let ncont = locked_s.replace_contents(modified_s);
match ncont {
Ok(_) => (),
Err(e) => {
return Err(format!(
"Error during write to the database. \
Please doublecheck as the shadowdatabase could be corrupted: {}",
e,
)
.into());
}
}
}
None => (),
}
// Remove the user from the memory database(HashMap) // Remove the user from the memory database(HashMap)
let res = self.users.remove(username); let res = self.users.remove(username);
return Ok( return Ok(