From 3ff51e6e5f2c0809ca16d2061eab04f6be6e7e20 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 28 Sep 2016 14:12:05 -0600 Subject: [PATCH] Add smith editor, hashing in login, update ion --- .gitmodules | 3 ++ Makefile | 3 +- programs/ion | 2 +- programs/login/Cargo.toml | 10 ++++++ programs/login/src/main.rs | 65 +++++++++++++++++++++++++++----------- programs/smith | 1 + 6 files changed, 63 insertions(+), 21 deletions(-) create mode 160000 programs/smith diff --git a/.gitmodules b/.gitmodules index ea9df03..572b836 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "programs/extrautils"] path = programs/extrautils url = https://github.com/redox-os/extrautils.git +[submodule "programs/smith"] + path = programs/smith + url = https://github.com/redox-os/Smith.git diff --git a/Makefile b/Makefile index 7b95c81..e43b6a7 100644 --- a/Makefile +++ b/Makefile @@ -266,7 +266,8 @@ $(BUILD)/filesystem.bin: \ extrautils \ schemes \ filesystem/bin/ion \ - filesystem/bin/login + filesystem/bin/login \ + filesystem/bin/smith rm -rf $@ $(BUILD)/filesystem/ echo exit | cargo run --manifest-path schemes/redoxfs/Cargo.toml --bin redoxfs-utility $@ mkdir -p $(BUILD)/filesystem/ diff --git a/programs/ion b/programs/ion index cbb3c30..d0a2e0a 160000 --- a/programs/ion +++ b/programs/ion @@ -1 +1 @@ -Subproject commit cbb3c3003f654d09cd3b3cf1a179469bb1b558b3 +Subproject commit d0a2e0a224bc1c57718d58b7b2d1cd8d1c80d052 diff --git a/programs/login/Cargo.toml b/programs/login/Cargo.toml index 23bc463..ad494c4 100644 --- a/programs/login/Cargo.toml +++ b/programs/login/Cargo.toml @@ -3,4 +3,14 @@ name = "login" version = "0.1.0" [dependencies] +liner = "*" syscall = { path = "../../syscall/" } + +[dependencies.octavo] +git = "https://github.com/libOctavo/octavo" +default-features = false +features = ["digest"] + +[replace] +"libc:0.2.16" = { git = "https://github.com/redox-os/liblibc.git", branch = "new_kernel" } +"rustc-serialize:0.3.19" = { git = "https://github.com/redox-os/rustc-serialize.git" } diff --git a/programs/login/src/main.rs b/programs/login/src/main.rs index ca273fb..cefffb2 100644 --- a/programs/login/src/main.rs +++ b/programs/login/src/main.rs @@ -1,8 +1,12 @@ +extern crate liner; +extern crate octavo; extern crate syscall; -use std::env; +use liner::Context; +use octavo::octavo_digest::Digest; +use octavo::octavo_digest::sha3::Sha512; use std::process::Command; -use std::thread; +use std::{env, thread}; pub fn main() { let mut args = env::args().skip(1); @@ -11,8 +15,6 @@ pub fn main() { let sh = args.next().expect("login: no sh provided"); let sh_args: Vec = args.collect(); - env::set_current_dir("file:").expect("login: failed to cd to file:"); - let _ = syscall::close(2); let _ = syscall::close(1); let _ = syscall::close(0); @@ -21,25 +23,50 @@ pub fn main() { let _ = syscall::open(&tty, syscall::flag::O_RDWR); let _ = syscall::open(&tty, syscall::flag::O_RDWR); + env::set_var("COLUMNS", "80"); + env::set_var("LINES", "30"); + env::set_var("TTY", &tty); + thread::spawn(move || { + let mut con = Context::new(); + loop { - let mut command = Command::new(&sh); - for arg in sh_args.iter() { - command.arg(arg); - } + let user = con.read_line("\x1B[1mredox login:\x1B[0m ", &mut |_| {}).expect("login: failed to read user"); - command.env("HOME", "file:home"); - command.env("PATH", "file:bin"); - command.env("COLUMNS", "80"); - command.env("LINES", "30"); - command.env("TTY", &tty); + if ! user.is_empty() { + let password = con.read_line("\x1B[1mpassword:\x1B[0m ", &mut |_| {}).expect("login: failed to read user"); - 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) + 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!(""); + + let home = "file:home"; + + env::set_current_dir(home).expect("login: failed to cd to home"); + + let mut command = Command::new(&sh); + for arg in sh_args.iter() { + command.arg(arg); + } + + 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) + } } } }); diff --git a/programs/smith b/programs/smith new file mode 160000 index 0000000..23405d7 --- /dev/null +++ b/programs/smith @@ -0,0 +1 @@ +Subproject commit 23405d7cd9f59d37dbaa6b07fe3ab66b065beff5