From 659f7bd3204ad5acd429037414644d0b0567113d Mon Sep 17 00:00:00 2001 From: Albert S Date: Mon, 14 Sep 2020 19:45:58 +0200 Subject: [PATCH] getpwnam: Give precise error message if we cannot lookup the user --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index bc36a93..7f72161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,6 +82,12 @@ fn getpwnam(username: &str) -> std::io::Result { let username_ptr = username_c.as_ptr(); let pwnamresult: *mut libc::passwd = unsafe { libc::getpwnam(username_ptr) }; if pwnamresult.is_null() { + if Error::last_os_error().raw_os_error().unwrap() == 0 { + return Err(Error::new( + ErrorKind::NotFound, + format!("The username '{}' was not found", username), + )); + } return Err(Error::new( Error::last_os_error().kind(), "Lookup of user failed: ".to_owned() +