From 8fcd32eca2f25f0537da98bd225ffff995d0e109 Mon Sep 17 00:00:00 2001 From: Dietrich Date: Mon, 9 Nov 2020 13:58:13 +0100 Subject: [PATCH] Fix missing lints - Docs need to be improved still --- Cargo.toml | 6 ++++++ README.md | 1 + src/lib.rs | 1 + src/userlib/files.rs | 31 +++++++++++++++---------------- src/userlib/mod.rs | 39 +++++++++++++++++---------------------- 5 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index 108e30d..c3ca0fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,14 @@ [package] name = "adduser" version = "0.1.0" +description = "Library for managing Linux users and their directories" authors = ["Dietrich "] edition = "2018" +license = "MIT OR Apache-2.0" +keywords = ["user", "admin", "linux", "manage"] +categories = ["system-tools", "system-tools::user-management"] +repository = "https://git.teilgedanken.de/Rust/useradd/" +readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e75fbd --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Usermanager written in Rust \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 4212420..bc10321 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ clippy::cargo )] //#![allow(clippy::non_ascii_literal)] +#![allow(clippy::missing_errors_doc)] #[macro_use] extern crate lazy_static; diff --git a/src/userlib/files.rs b/src/userlib/files.rs index a86681d..b81fac3 100644 --- a/src/userlib/files.rs +++ b/src/userlib/files.rs @@ -67,6 +67,21 @@ pub struct LockedFileGuard { path: PathBuf, pub(crate) file: File, } +struct TempLockFile { + tlf: PathBuf, +} +impl Drop for TempLockFile { + fn drop(&mut self) { + info!("removing temporary lockfile {}", self.tlf.to_str().unwrap()); + std::fs::remove_file(&self.tlf).unwrap(); + } +} +impl Deref for TempLockFile { + type Target = PathBuf; + fn deref(&self) -> &PathBuf { + &self.tlf + } +} impl LockedFileGuard { pub fn new(path: &PathBuf) -> Result { @@ -118,22 +133,6 @@ impl LockedFileGuard { /// * try to lock again now that the old logfile has been safely removed. /// * remove the original file and only keep the lock hardlink fn try_to_lock_file(path: &PathBuf) -> Result<(PathBuf, File), crate::UserLibError> { - struct TempLockFile { - tlf: PathBuf, - } - impl Drop for TempLockFile { - fn drop(&mut self) { - info!("removing temporary lockfile {}", self.tlf.to_str().unwrap()); - std::fs::remove_file(&self.tlf).unwrap(); - } - } - impl Deref for TempLockFile { - type Target = PathBuf; - fn deref(&self) -> &PathBuf { - &self.tlf - } - } - info!("locking file {}", path.to_string_lossy()); let mut tempfilepath_const = path.clone(); // get the pid diff --git a/src/userlib/mod.rs b/src/userlib/mod.rs index 72f593b..f6085c5 100644 --- a/src/userlib/mod.rs +++ b/src/userlib/mod.rs @@ -187,31 +187,26 @@ impl UserDBWrite for UserDBLocal { Self::delete_home(user)?; } let group = self.get_group_pos_by_id(user.get_gid()); - match group { - Some((group, id)) => { - if group - .get_member_names() - .expect("groups have to have members") - .len() - == 1 - { - UserDBLocal::delete_from_group( - group, - &group_file_content, - &mut locked_g, - )?; - let _gres = self.groups.remove(id); - } else { - warn!( - "The primary group {} was not empty and is thus not removed.", - group.get_groupname().unwrap() - ); - } + if let Some((group, id)) = group { + if group + .get_member_names() + .expect("groups have to have members") + .len() + == 1 + { + Self::delete_from_group(group, &group_file_content, &mut locked_g)?; + let _gres = self.groups.remove(id); + } else { + warn!( + "The primary group {} was not empty and is thus not removed.", + group.get_groupname().unwrap() + ); } - None => warn!( + } else { + warn!( "The users primary group could not be found {}", user.get_gid() - ), + ) } // Remove the user from the memory database(HashMap) let res = self.users.remove(args.username);