From 6389bb988d04d7a88a29f92964b8c885dad976f9 Mon Sep 17 00:00:00 2001 From: Dietrich Date: Fri, 30 Oct 2020 19:45:41 +0100 Subject: [PATCH] actually remove the shadow line and fix a final newline --- src/userlib/files.rs | 1 + src/userlib/mod.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/userlib/files.rs b/src/userlib/files.rs index 9ac2d7d..e6d77d8 100644 --- a/src/userlib/files.rs +++ b/src/userlib/files.rs @@ -85,6 +85,7 @@ impl LockedFileGuard { self.file .write_all(&new_content.into_bytes()) .expect("Failed to write all users."); + let _ = self.file.write("\n".as_bytes()); Ok(()) } diff --git a/src/userlib/mod.rs b/src/userlib/mod.rs index 6a5187e..5686dce 100644 --- a/src/userlib/mod.rs +++ b/src/userlib/mod.rs @@ -116,6 +116,25 @@ impl UserDBWrite for UserDBLocal { let ncont = locked_p.replace_contents(modified_p); match ncont { 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) let res = self.users.remove(username); return Ok(