Fix missing lints - Docs need to be improved still
This commit is contained in:
parent
467c8ee007
commit
8fcd32eca2
@ -1,8 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "adduser"
|
name = "adduser"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
description = "Library for managing Linux users and their directories"
|
||||||
authors = ["Dietrich <dietrich@teilgedanken.de>"]
|
authors = ["Dietrich <dietrich@teilgedanken.de>"]
|
||||||
edition = "2018"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
clippy::cargo
|
clippy::cargo
|
||||||
)]
|
)]
|
||||||
//#![allow(clippy::non_ascii_literal)]
|
//#![allow(clippy::non_ascii_literal)]
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
@ -67,6 +67,21 @@ pub struct LockedFileGuard {
|
|||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
pub(crate) file: File,
|
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 {
|
impl LockedFileGuard {
|
||||||
pub fn new(path: &PathBuf) -> Result<Self, crate::UserLibError> {
|
pub fn new(path: &PathBuf) -> Result<Self, crate::UserLibError> {
|
||||||
@ -118,22 +133,6 @@ impl LockedFileGuard {
|
|||||||
/// * try to lock again now that the old logfile has been safely removed.
|
/// * try to lock again now that the old logfile has been safely removed.
|
||||||
/// * remove the original file and only keep the lock hardlink
|
/// * remove the original file and only keep the lock hardlink
|
||||||
fn try_to_lock_file(path: &PathBuf) -> Result<(PathBuf, File), crate::UserLibError> {
|
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());
|
info!("locking file {}", path.to_string_lossy());
|
||||||
let mut tempfilepath_const = path.clone();
|
let mut tempfilepath_const = path.clone();
|
||||||
// get the pid
|
// get the pid
|
||||||
|
@ -187,31 +187,26 @@ impl UserDBWrite for UserDBLocal {
|
|||||||
Self::delete_home(user)?;
|
Self::delete_home(user)?;
|
||||||
}
|
}
|
||||||
let group = self.get_group_pos_by_id(user.get_gid());
|
let group = self.get_group_pos_by_id(user.get_gid());
|
||||||
match group {
|
if let Some((group, id)) = group {
|
||||||
Some((group, id)) => {
|
if group
|
||||||
if group
|
.get_member_names()
|
||||||
.get_member_names()
|
.expect("groups have to have members")
|
||||||
.expect("groups have to have members")
|
.len()
|
||||||
.len()
|
== 1
|
||||||
== 1
|
{
|
||||||
{
|
Self::delete_from_group(group, &group_file_content, &mut locked_g)?;
|
||||||
UserDBLocal::delete_from_group(
|
let _gres = self.groups.remove(id);
|
||||||
group,
|
} else {
|
||||||
&group_file_content,
|
warn!(
|
||||||
&mut locked_g,
|
"The primary group {} was not empty and is thus not removed.",
|
||||||
)?;
|
group.get_groupname().unwrap()
|
||||||
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 {}",
|
"The users primary group could not be found {}",
|
||||||
user.get_gid()
|
user.get_gid()
|
||||||
),
|
)
|
||||||
}
|
}
|
||||||
// Remove the user from the memory database(HashMap)
|
// Remove the user from the memory database(HashMap)
|
||||||
let res = self.users.remove(args.username);
|
let res = self.users.remove(args.username);
|
||||||
|
Loading…
Reference in New Issue
Block a user