use std::io::{stdin, stdout, Write};
use std::os::unix::process::CommandExt;
use std::process::Command;
use pam::Client;
use rpassword::read_password_from_tty;
use users::get_user_by_name;
fn main() {
print!("login: ");
stdout().flush().unwrap();
let mut login = String::new();
stdin().read_line(&mut login).unwrap();
login.pop(); let password = read_password_from_tty(Some("password: ")).unwrap();
let mut client = Client::with_password("system-auth").expect("Failed to init PAM client!");
client
.conversation_mut()
.set_credentials(login.clone(), password);
client.authenticate().expect("Authentication failed!");
client.open_session().expect("Failed to open a session!");
let user = get_user_by_name(&login).unwrap();
let error = Command::new("/bin/bash")
.uid(user.uid())
.gid(user.primary_group_id())
.exec();
println!("Error spawning bash: {:?}", error);
}