Implement unix permissions
This commit is contained in:
parent
10c88e7424
commit
f38426e458
19 changed files with 99 additions and 76 deletions
|
@ -33,7 +33,7 @@ pub extern fn debug_input(b: u8) {
|
|||
pub struct DebugScheme;
|
||||
|
||||
impl Scheme for DebugScheme {
|
||||
fn open(&self, _path: &[u8], _flags: usize) -> Result<usize> {
|
||||
fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ impl EnvScheme {
|
|||
}
|
||||
|
||||
impl Scheme for EnvScheme {
|
||||
fn open(&self, path: &[u8], _flags: usize) -> Result<usize> {
|
||||
fn open(&self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let path = str::from_utf8(path).map_err(|_err| Error::new(ENOENT))?.trim_matches('/');
|
||||
|
||||
let env_lock = {
|
||||
|
|
|
@ -24,7 +24,7 @@ impl EventScheme {
|
|||
}
|
||||
|
||||
impl Scheme for EventScheme {
|
||||
fn open(&self, _path: &[u8], _flags: usize) -> Result<usize> {
|
||||
fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let handle = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
|
|
|
@ -35,7 +35,7 @@ impl InitFsScheme {
|
|||
}
|
||||
|
||||
impl Scheme for InitFsScheme {
|
||||
fn open(&self, path: &[u8], _flags: usize) -> Result<usize> {
|
||||
fn open(&self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let path_utf8 = str::from_utf8(path).map_err(|_err| Error::new(ENOENT))?;
|
||||
let path_trimmed = path_utf8.trim_matches('/');
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl Scheme for InitFsScheme {
|
|||
self.handles.write().insert(id, Handle {
|
||||
path: entry.0,
|
||||
data: (entry.1).0,
|
||||
mode: if (entry.1).1 { MODE_DIR } else { MODE_FILE },
|
||||
mode: if (entry.1).1 { MODE_DIR | 0o755 } else { MODE_FILE | 0o744 },
|
||||
seek: 0
|
||||
});
|
||||
|
||||
|
@ -130,6 +130,8 @@ impl Scheme for InitFsScheme {
|
|||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
|
||||
stat.st_mode = handle.mode;
|
||||
stat.st_uid = 0;
|
||||
stat.st_gid = 0;
|
||||
stat.st_size = handle.data.len() as u64;
|
||||
|
||||
Ok(0)
|
||||
|
|
|
@ -7,7 +7,7 @@ use syscall::scheme::Scheme;
|
|||
pub struct IrqScheme;
|
||||
|
||||
impl Scheme for IrqScheme {
|
||||
fn open(&self, path: &[u8], _flags: usize) -> Result<usize> {
|
||||
fn open(&self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let path_str = str::from_utf8(path).or(Err(Error::new(ENOENT)))?;
|
||||
|
||||
let id = path_str.parse::<usize>().or(Err(Error::new(ENOENT)))?;
|
||||
|
|
|
@ -25,7 +25,7 @@ impl RootScheme {
|
|||
}
|
||||
|
||||
impl Scheme for RootScheme {
|
||||
fn open(&self, path: &[u8], _flags: usize) -> Result<usize> {
|
||||
fn open(&self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let context = {
|
||||
let contexts = context::contexts();
|
||||
let context = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
|
|
|
@ -218,7 +218,7 @@ impl UserScheme {
|
|||
}
|
||||
|
||||
impl Scheme for UserScheme {
|
||||
fn open(&self, path: &[u8], flags: usize) -> Result<usize> {
|
||||
fn open(&self, path: &[u8], flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||
let address = inner.capture(path)?;
|
||||
let result = inner.call(SYS_OPEN, address, path.len(), flags);
|
||||
|
@ -226,15 +226,15 @@ impl Scheme for UserScheme {
|
|||
result
|
||||
}
|
||||
|
||||
fn mkdir(&self, path: &[u8], mode: usize) -> Result<usize> {
|
||||
fn mkdir(&self, path: &[u8], mode: u16, _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||
let address = inner.capture(path)?;
|
||||
let result = inner.call(SYS_MKDIR, address, path.len(), mode);
|
||||
let result = inner.call(SYS_MKDIR, address, path.len(), mode as usize);
|
||||
let _ = inner.release(address);
|
||||
result
|
||||
}
|
||||
|
||||
fn rmdir(&self, path: &[u8]) -> Result<usize> {
|
||||
fn rmdir(&self, path: &[u8], _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||
let address = inner.capture(path)?;
|
||||
let result = inner.call(SYS_RMDIR, address, path.len(), 0);
|
||||
|
@ -242,7 +242,7 @@ impl Scheme for UserScheme {
|
|||
result
|
||||
}
|
||||
|
||||
fn unlink(&self, path: &[u8]) -> Result<usize> {
|
||||
fn unlink(&self, path: &[u8], _uid: u32, _gid: u32) -> Result<usize> {
|
||||
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
|
||||
let address = inner.capture(path)?;
|
||||
let result = inner.call(SYS_UNLINK, address, path.len(), 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue