properly do read_all

This commit is contained in:
Dietrich 2020-10-23 15:17:57 +02:00
parent 134b97cfec
commit 98d4c72f7f
2 changed files with 6 additions and 25 deletions

View File

@ -1,11 +1,5 @@
extern crate adduser; extern crate adduser;
use adduser::NewFromString;
use adduser::Shadow;
use adduser::User;
use std::fs::File;
use std::io::{prelude::*, BufReader};
fn main() { fn main() {
simplelog::CombinedLogger::init(vec![simplelog::TermLogger::new( simplelog::CombinedLogger::init(vec![simplelog::TermLogger::new(
simplelog::LevelFilter::Warn, simplelog::LevelFilter::Warn,
@ -13,24 +7,11 @@ fn main() {
simplelog::TerminalMode::Mixed, simplelog::TerminalMode::Mixed,
)]) )])
.unwrap(); .unwrap();
let file: File = File::open("/etc/passwd").unwrap(); use adduser::api::UserDBRead;
let reader: BufReader<File> = BufReader::new(file);
for line in reader.lines() { let db = adduser::UserDBLocal::load_files(adduser::Files::default());
let line: String = line.unwrap();
println!("{}", User::new_from_string(line).unwrap()); for u in db.get_all_users() {
println!("{}", u);
} }
let line = "test:!!$6$/RotIe4VZzzAun4W$7YUONvru1rDnllN5TvrnOMsWUD5wSDUPAD6t6/Xwsr/0QOuWF3HcfAhypRkGa8G1B9qqWV5kZSnCb8GKMN9N61:18260:0:99999:7:::".to_string();
assert_eq!(
format!("{}", Shadow::new_from_string(line.clone()).unwrap()),
line
);
// let pwd = User::default();
// let pwd2 =
// User::new_from_string("howdy:notencrypted:1001:1001:not done:/home/test:/bin/bash");
// println!("Test struct: {}", pwd);
// assert_eq!(pwd, pwd2.unwrap())
} }

View File

@ -15,5 +15,5 @@ pub use user::passwd_fields::{
}; };
pub use user::shadow_fields::Shadow; pub use user::shadow_fields::Shadow;
pub use user::User; pub use user::User;
pub use userlib::NewFromString; pub use userlib::{Files, NewFromString, UserDBLocal};
pub use userlib_error::UserLibError; pub use userlib_error::UserLibError;