Some fixes for cooked mode
This commit is contained in:
parent
3ff51e6e5f
commit
25519c4f1c
|
@ -65,9 +65,15 @@ impl Scheme for DisplayScheme {
|
|||
|
||||
fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
|
||||
if id == 1 {
|
||||
let mut input = self.input.borrow_mut();
|
||||
for &b in buf.iter() {
|
||||
input.push_back(b);
|
||||
self.input.borrow_mut().push_back(b);
|
||||
if ! self.console.borrow().raw_mode {
|
||||
if b == 0x7F {
|
||||
self.write(0, b"\x08")?;
|
||||
} else {
|
||||
self.write(0, &[b])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(buf.len())
|
||||
} else {
|
||||
|
|
|
@ -3,8 +3,8 @@ name = "login"
|
|||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
liner = "*"
|
||||
syscall = { path = "../../syscall/" }
|
||||
termion = "*"
|
||||
|
||||
[dependencies.octavo]
|
||||
git = "https://github.com/libOctavo/octavo"
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
extern crate liner;
|
||||
extern crate octavo;
|
||||
extern crate syscall;
|
||||
extern crate termion;
|
||||
|
||||
use liner::Context;
|
||||
use octavo::octavo_digest::Digest;
|
||||
use octavo::octavo_digest::sha3::Sha512;
|
||||
use std::io::{Read, Write};
|
||||
use std::process::Command;
|
||||
use std::{env, thread};
|
||||
use std::{env, io, thread};
|
||||
use termion::input::TermRead;
|
||||
|
||||
pub fn main() {
|
||||
let mut args = env::args().skip(1);
|
||||
|
@ -28,44 +29,57 @@ pub fn main() {
|
|||
env::set_var("TTY", &tty);
|
||||
|
||||
thread::spawn(move || {
|
||||
let mut con = Context::new();
|
||||
let stdin = io::stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
let stdout = io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
|
||||
loop {
|
||||
let user = con.read_line("\x1B[1mredox login:\x1B[0m ", &mut |_| {}).expect("login: failed to read user");
|
||||
stdout.write_all(b"\x1B[1mredox login:\x1B[0m ").expect("login: failed to write user prompt");
|
||||
let _ = stdout.flush();
|
||||
|
||||
let user = (&mut stdin as &mut Read).read_line().expect("login: failed to read user").unwrap_or(String::new());
|
||||
if ! user.is_empty() {
|
||||
let password = con.read_line("\x1B[1mpassword:\x1B[0m ", &mut |_| {}).expect("login: failed to read user");
|
||||
stdout.write_all(b"\x1B[1mpassword:\x1B[0m ").expect("login: failed to write password prompt");
|
||||
let _ = stdout.flush();
|
||||
|
||||
let mut output = vec![0; Sha512::output_bytes()];
|
||||
let mut hash = Sha512::default();
|
||||
hash.update(&password.as_bytes());
|
||||
hash.result(&mut output);
|
||||
if let Some(password) = stdin.read_passwd(&mut stdout).expect("login: failed to read password") {
|
||||
let mut output = vec![0; Sha512::output_bytes()];
|
||||
let mut hash = Sha512::default();
|
||||
hash.update(&password.as_bytes());
|
||||
hash.result(&mut output);
|
||||
|
||||
print!("hash: ");
|
||||
for b in output.iter() {
|
||||
print!("{:X} ", b);
|
||||
}
|
||||
println!("");
|
||||
println!("");
|
||||
|
||||
let home = "file:home";
|
||||
print!("hash: '{}' ", password);
|
||||
for b in output.iter() {
|
||||
print!("{:X} ", b);
|
||||
}
|
||||
println!("");
|
||||
|
||||
env::set_current_dir(home).expect("login: failed to cd to home");
|
||||
let home = "file:home";
|
||||
|
||||
let mut command = Command::new(&sh);
|
||||
for arg in sh_args.iter() {
|
||||
command.arg(arg);
|
||||
}
|
||||
env::set_current_dir(home).expect("login: failed to cd to home");
|
||||
|
||||
command.env("USER", &user);
|
||||
command.env("HOME", home);
|
||||
command.env("PATH", "file:bin");
|
||||
let mut command = Command::new(&sh);
|
||||
for arg in sh_args.iter() {
|
||||
command.arg(arg);
|
||||
}
|
||||
|
||||
match command.spawn() {
|
||||
Ok(mut child) => match child.wait() {
|
||||
Ok(_status) => (), //println!("login: waited for {}: {:?}", sh, status.code()),
|
||||
Err(err) => panic!("login: failed to wait for '{}': {}", sh, err)
|
||||
},
|
||||
Err(err) => panic!("login: failed to execute '{}': {}", sh, err)
|
||||
command.env("USER", &user);
|
||||
command.env("HOME", home);
|
||||
command.env("PATH", "file:bin");
|
||||
|
||||
match command.spawn() {
|
||||
Ok(mut child) => match child.wait() {
|
||||
Ok(_status) => (), //println!("login: waited for {}: {:?}", sh, status.code()),
|
||||
Err(err) => panic!("login: failed to wait for '{}': {}", sh, err)
|
||||
},
|
||||
Err(err) => panic!("login: failed to execute '{}': {}", sh, err)
|
||||
}
|
||||
|
||||
stdout.write(b"\x1Bc").expect("login: failed to reset screen");
|
||||
let _ = stdout.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue