From 0bbda9d7769df1ef9f758d778b11fb32fc2c0f79 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 5 Oct 2016 18:01:05 -0600 Subject: [PATCH] Implement unix permissions --- src/flag.rs | 31 ++++++++++++++++++------------- src/lib.rs | 4 ++-- src/scheme.rs | 16 ++++++++-------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/flag.rs b/src/flag.rs index 73b4dd8..c3e7d91 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -25,25 +25,30 @@ pub const FUTEX_REQUEUE: usize = 2; pub const MAP_WRITE: usize = 1; pub const MAP_WRITE_COMBINE: usize = 2; +pub const MODE_TYPE: u16 = 0xF000; pub const MODE_DIR: u16 = 0x4000; pub const MODE_FILE: u16 = 0x8000; -pub const MODE_ALL: u16 = MODE_DIR | MODE_FILE; + +pub const MODE_PERM: u16 = 0x0FFF; +pub const MODE_SETUID: u16 = 0o4000; +pub const MODE_SETGID: u16 = 0o2000; pub const SEEK_SET: usize = 0; pub const SEEK_CUR: usize = 1; pub const SEEK_END: usize = 2; -pub const O_RDONLY: usize = 0; -pub const O_WRONLY: usize = 1; -pub const O_RDWR: usize = 2; -pub const O_NONBLOCK: usize = 4; -pub const O_APPEND: usize = 8; -pub const O_SHLOCK: usize = 0x10; -pub const O_EXLOCK: usize = 0x20; -pub const O_ASYNC: usize = 0x40; -pub const O_FSYNC: usize = 0x80; -pub const O_CREAT: usize = 0x200; -pub const O_TRUNC: usize = 0x400; -pub const O_EXCL: usize = 0x800; +pub const O_RDONLY: usize = 0x0000_0000; +pub const O_WRONLY: usize = 0x0001_0000; +pub const O_RDWR: usize = 0x0002_0000; +pub const O_NONBLOCK: usize = 0x0004_0000; +pub const O_APPEND: usize = 0x0008_0000; +pub const O_SHLOCK: usize = 0x0010_0000; +pub const O_EXLOCK: usize = 0x0020_0000; +pub const O_ASYNC: usize = 0x0040_0000; +pub const O_FSYNC: usize = 0x0080_0000; +pub const O_CLOEXEC: usize = 0x0100_0000; +pub const O_CREAT: usize = 0x0200_0000; +pub const O_TRUNC: usize = 0x0400_0000; +pub const O_EXCL: usize = 0x0800_0000; pub const WNOHANG: usize = 1; diff --git a/src/lib.rs b/src/lib.rs index 463503d..94b7e65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,8 +112,8 @@ pub fn lseek(fd: usize, offset: isize, whence: usize) -> Result { unsafe { syscall3(SYS_LSEEK, fd, offset as usize, whence) } } -pub fn mkdir(path: &str, mode: usize) -> Result { - unsafe { syscall3(SYS_MKDIR, path.as_ptr() as usize, path.len(), mode) } +pub fn mkdir(path: &str, mode: u16) -> Result { + unsafe { syscall3(SYS_MKDIR, path.as_ptr() as usize, path.len(), mode as usize) } } pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result { diff --git a/src/scheme.rs b/src/scheme.rs index 43d1899..310bb88 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -5,10 +5,10 @@ use super::*; pub trait Scheme { fn handle(&self, packet: &mut Packet) { packet.a = Error::mux(match packet.a { - SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d), - SYS_MKDIR => self.mkdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d), - SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }), - SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }), + SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid), + SYS_MKDIR => self.mkdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid), + SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), + SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), SYS_DUP => self.dup(packet.b), SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), @@ -28,22 +28,22 @@ pub trait Scheme { /* Scheme operations */ #[allow(unused_variables)] - fn open(&self, path: &[u8], flags: usize) -> Result { + fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result { Err(Error::new(ENOENT)) } #[allow(unused_variables)] - fn mkdir(&self, path: &[u8], mode: usize) -> Result { + fn mkdir(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result { Err(Error::new(ENOENT)) } #[allow(unused_variables)] - fn rmdir(&self, path: &[u8]) -> Result { + fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result { Err(Error::new(ENOENT)) } #[allow(unused_variables)] - fn unlink(&self, path: &[u8]) -> Result { + fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result { Err(Error::new(ENOENT)) }