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> {
|
fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
|
||||||
if id == 1 {
|
if id == 1 {
|
||||||
let mut input = self.input.borrow_mut();
|
|
||||||
for &b in buf.iter() {
|
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())
|
Ok(buf.len())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,8 +3,8 @@ name = "login"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
liner = "*"
|
|
||||||
syscall = { path = "../../syscall/" }
|
syscall = { path = "../../syscall/" }
|
||||||
|
termion = "*"
|
||||||
|
|
||||||
[dependencies.octavo]
|
[dependencies.octavo]
|
||||||
git = "https://github.com/libOctavo/octavo"
|
git = "https://github.com/libOctavo/octavo"
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
extern crate liner;
|
|
||||||
extern crate octavo;
|
extern crate octavo;
|
||||||
extern crate syscall;
|
extern crate syscall;
|
||||||
|
extern crate termion;
|
||||||
|
|
||||||
use liner::Context;
|
|
||||||
use octavo::octavo_digest::Digest;
|
use octavo::octavo_digest::Digest;
|
||||||
use octavo::octavo_digest::sha3::Sha512;
|
use octavo::octavo_digest::sha3::Sha512;
|
||||||
|
use std::io::{Read, Write};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{env, thread};
|
use std::{env, io, thread};
|
||||||
|
use termion::input::TermRead;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut args = env::args().skip(1);
|
let mut args = env::args().skip(1);
|
||||||
|
@ -28,44 +29,57 @@ pub fn main() {
|
||||||
env::set_var("TTY", &tty);
|
env::set_var("TTY", &tty);
|
||||||
|
|
||||||
thread::spawn(move || {
|
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 {
|
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() {
|
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()];
|
if let Some(password) = stdin.read_passwd(&mut stdout).expect("login: failed to read password") {
|
||||||
let mut hash = Sha512::default();
|
let mut output = vec![0; Sha512::output_bytes()];
|
||||||
hash.update(&password.as_bytes());
|
let mut hash = Sha512::default();
|
||||||
hash.result(&mut output);
|
hash.update(&password.as_bytes());
|
||||||
|
hash.result(&mut output);
|
||||||
|
|
||||||
print!("hash: ");
|
println!("");
|
||||||
for b in output.iter() {
|
|
||||||
print!("{:X} ", b);
|
|
||||||
}
|
|
||||||
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);
|
env::set_current_dir(home).expect("login: failed to cd to home");
|
||||||
for arg in sh_args.iter() {
|
|
||||||
command.arg(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
command.env("USER", &user);
|
let mut command = Command::new(&sh);
|
||||||
command.env("HOME", home);
|
for arg in sh_args.iter() {
|
||||||
command.env("PATH", "file:bin");
|
command.arg(arg);
|
||||||
|
}
|
||||||
|
|
||||||
match command.spawn() {
|
command.env("USER", &user);
|
||||||
Ok(mut child) => match child.wait() {
|
command.env("HOME", home);
|
||||||
Ok(_status) => (), //println!("login: waited for {}: {:?}", sh, status.code()),
|
command.env("PATH", "file:bin");
|
||||||
Err(err) => panic!("login: failed to wait for '{}': {}", sh, err)
|
|
||||||
},
|
match command.spawn() {
|
||||||
Err(err) => panic!("login: failed to execute '{}': {}", sh, err)
|
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