diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2022-09-28 21:46:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 21:46:50 +0900 |
commit | fa9e7aab6d49f241a4eb30cc0e261f8ceb64af2f (patch) | |
tree | 04f3babcb09101e9264f021ecff53f7db266a80c /runtime/ops/os.rs | |
parent | b312279e58e51520a38e51cca317a09cdadd7cb4 (diff) |
feat: add --allow-sys permission flag (#16028)
Diffstat (limited to 'runtime/ops/os.rs')
-rw-r--r-- | runtime/ops/os.rs | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/runtime/ops/os.rs b/runtime/ops/os.rs index 14c4229a1..0e51e3120 100644 --- a/runtime/ops/os.rs +++ b/runtime/ops/os.rs @@ -161,7 +161,10 @@ fn op_exit(state: &mut OpState) { #[op] fn op_loadavg(state: &mut OpState) -> Result<(f64, f64, f64), AnyError> { super::check_unstable(state, "Deno.loadavg"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("loadavg", Some("Deno.loadavg()"))?; match sys_info::loadavg() { Ok(loadavg) => Ok((loadavg.one, loadavg.five, loadavg.fifteen)), Err(_) => Ok((0.0, 0.0, 0.0)), @@ -171,7 +174,10 @@ fn op_loadavg(state: &mut OpState) -> Result<(f64, f64, f64), AnyError> { #[op] fn op_hostname(state: &mut OpState) -> Result<String, AnyError> { super::check_unstable(state, "Deno.hostname"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("hostname", Some("Deno.hostname()"))?; let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string()); Ok(hostname) } @@ -179,7 +185,10 @@ fn op_hostname(state: &mut OpState) -> Result<String, AnyError> { #[op] fn op_os_release(state: &mut OpState) -> Result<String, AnyError> { super::check_unstable(state, "Deno.osRelease"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("osRelease", Some("Deno.osRelease()"))?; let release = sys_info::os_release().unwrap_or_else(|_| "".to_string()); Ok(release) } @@ -189,7 +198,10 @@ fn op_network_interfaces( state: &mut OpState, ) -> Result<Vec<NetworkInterface>, AnyError> { super::check_unstable(state, "Deno.networkInterfaces"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("networkInterfaces", Some("Deno.networkInterfaces()"))?; Ok(netif::up()?.map(NetworkInterface::from).collect()) } @@ -255,7 +267,10 @@ fn op_system_memory_info( state: &mut OpState, ) -> Result<Option<MemInfo>, AnyError> { super::check_unstable(state, "Deno.systemMemoryInfo"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("systemMemoryInfo", Some("Deno.systemMemoryInfo()"))?; match sys_info::mem_info() { Ok(info) => Ok(Some(MemInfo { total: info.total, @@ -274,7 +289,10 @@ fn op_system_memory_info( #[op] fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> { super::check_unstable(state, "Deno.getGid"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("getGid", Some("Deno.getGid()"))?; // TODO(bartlomieju): #[allow(clippy::undocumented_unsafe_blocks)] unsafe { @@ -286,7 +304,10 @@ fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> { #[op] fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> { super::check_unstable(state, "Deno.getGid"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("getGid", Some("Deno.getGid()"))?; Ok(None) } @@ -294,7 +315,10 @@ fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> { #[op] fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> { super::check_unstable(state, "Deno.getUid"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("getUid", Some("Deno.getUid()"))?; // TODO(bartlomieju): #[allow(clippy::undocumented_unsafe_blocks)] unsafe { @@ -306,6 +330,9 @@ fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> { #[op] fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> { super::check_unstable(state, "Deno.getUid"); - state.borrow_mut::<Permissions>().env.check_all()?; + state + .borrow_mut::<Permissions>() + .sys + .check("getUid", Some("Deno.getUid()"))?; Ok(None) } |