Skip to content

Instantly share code, notes, and snippets.

@MggMuggins
Last active December 23, 2017 21:04
Show Gist options
  • Save MggMuggins/2124a135e515a4568ca3e1e744598241 to your computer and use it in GitHub Desktop.
Save MggMuggins/2124a135e515a4568ca3e1e744598241 to your computer and use it in GitHub Desktop.
authd stuff
//extern crate argon2rs;
extern crate extra;
//#[macro_use] extern crate failure;
extern crate syscall;
//mod error;
//mod group;
mod scheme;
//mod user;
use std::io::{Read, Write};
use std::fs::File;
use extra::option::OptionalExt;
use syscall::data::Packet;
use syscall::scheme::SchemeMut;
use scheme::AuthScheme;
fn main() {
if unsafe { syscall::clone(0).unwrap() } == 0 {
let mut socket = File::create(":auth").unwrap_or_exit(1);
let mut scheme = AuthScheme::new();
syscall::setrens(0, 0).unwrap_or_exit(1);
loop {
let mut packet = Packet::default();
socket.read(&mut packet).unwrap_or_exit(1);
scheme.handle(&mut packet);
socket.write(&mut packet).unwrap_or_exit(1);
}
}
}
PANIC: no entry found for key
FILE: ~/Workspace/Rust/Redox/redox/rust/src/libcore/option.rs
LINE: 874
TRACE: FFFFFF40001B2700
FFFFFF40001B2700: FFFFFF000015AC4A
FFFFFF000015AAA0+01AA
rust_begin_unwind
FFFFFF40001B2790: FFFFFF0000198DB4
FFFFFF0000198D30+0084
core::panicking::panic_fmt::h1a71b4e9c4db074d
FFFFFF40001B2800: FFFFFF0000198E29
FFFFFF0000198DC0+0069
core::option::expect_failed::hb2ee3b9bcaa0e524
FFFFFF40001B2860: FFFFFF000017B12A
FFFFFF000017AE30+02FA
kernel::scheme::SchemeList::get_name::h2e7ad92aa280db9d
FFFFFF40001B28C0: FFFFFF000017CD87
FFFFFF000017CA70+0317
kernel::syscall::fs::open::h0f47b616a7573ac9
FFFFFF40001B29A0: FFFFFF00001883FF
FFFFFF0000187910+0AEF
syscall
FFFFFF40001B2DA0: FFFFFF0000122247
FFFFFF0000122220+0027
kernel::arch::x86_64::interrupt::syscall::syscall::inner::h9a8b7c6924d5dd65
FFFFFF40001B2DD0: FFFFFF0000122200
FFFFFF00001221E0+0020
kernel::arch::x86_64::interrupt::syscall::syscall::h5be5f63457689bd1
00000180000FF870: 0000000000408785
00000180000FF8B0: 0000000000407AFB
00000180000FF9B0: 0000000000411D4D
00000180000FFA90: 0000000000412875
00000180000FFAF0: 00000000004003A0
00000180000FFB40: 0000000000402237
00000180000FFD70: 000000000041C63F
00000180000FFDB0: 0000000000412D86
00000180000FFE80: 00000000004001F5
0000008000000018: EMPTY RETURN
HALT
use std::collections::HashMap;
use std::str::from_utf8;
use syscall::data::Stat;
use syscall::error::Result;
use syscall::scheme::SchemeMut;
//use user::User;
//use group::Group;
struct Connection {
uid: u32,
gid: u32,
path: String
}
impl Connection {
}
pub struct AuthScheme {
//users: Vec<User>,
//groups: Vec<Group>,
connections: HashMap<usize, Connection>
}
impl AuthScheme {
pub fn new() -> AuthScheme {
AuthScheme {
//users: Vec::new(),
//groups: Vec::new(),
connections: HashMap::new()
}
}
}
impl SchemeMut for AuthScheme {
fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
println!("Path: {:?}, FLAGS:{}, UID: {}, GID: {}", from_utf8(path).unwrap(), flags, uid, gid);
//Select an available id
let id = (0..self.connections.len())
.into_iter()
.find(|i| !self.connections.contains_key(&i))
.unwrap_or_else(|| unreachable!() );
//println!("Key selected: {}", id);
self.connections.insert(id, Connection {
uid,
gid,
path: String::from_utf8_lossy(path).into_owned()//.unwrap_or(|err| return )
});
//println!("Connection Established");
Ok(id)
}
fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
println!("ID: {}", id);
let text = &mut b"Hello everything!".to_owned();
Ok(0)
}
fn write(&mut self, id: usize, buf: &[u8]) -> Result<usize> {
println!("{}", from_utf8(buf).unwrap());
Ok(buf.len())
}
fn fstat(&mut self, id: usize, _stat: &mut Stat) -> Result<usize> {
/*let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?;
*stat = Stat {
st_mode: MODE_CHR | 0o666,
..Default::default()
};*/
println!("STAT: {}", id);
Ok(id)
}
fn close(&mut self, id: usize) -> Result<usize> {
println!("CLOSE: {}", id);
self.connections.remove(&id);
Ok(0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment