diff options
author | Elias Sjögreen <eliassjogreen1@gmail.com> | 2021-12-15 15:41:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-15 15:41:49 +0100 |
commit | ee49cce726c27cdcb372b9dba7f2deab840d9e6b (patch) | |
tree | d1a9a843eb5fba782a7cff5e50cb973ee3806225 /runtime/permissions.rs | |
parent | 4d176b7b7c11aabc584bee45423f108ea47faefe (diff) |
feat(ext/ffi): implement UnsafePointer and UnsafePointerView (#12828)
Diffstat (limited to 'runtime/permissions.rs')
-rw-r--r-- | runtime/permissions.rs | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/runtime/permissions.rs b/runtime/permissions.rs index 9a85e5e58..50c126f3f 100644 --- a/runtime/permissions.rs +++ b/runtime/permissions.rs @@ -1044,22 +1044,39 @@ impl UnaryPermission<FfiDescriptor> { self.query(path) } - pub fn check(&mut self, path: &Path) -> Result<(), AnyError> { - let (resolved_path, display_path) = resolved_and_display_path(path); - let (result, prompted) = self.query(Some(&resolved_path)).check( - self.name, - Some(&format!("\"{}\"", display_path.display())), - self.prompt, - ); - if prompted { - if result.is_ok() { - self.granted_list.insert(FfiDescriptor(resolved_path)); - } else { - self.denied_list.insert(FfiDescriptor(resolved_path)); - self.global_state = PermissionState::Denied; + pub fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError> { + if let Some(path) = path { + let (resolved_path, display_path) = resolved_and_display_path(path); + let (result, prompted) = self.query(Some(&resolved_path)).check( + self.name, + Some(&format!("\"{}\"", display_path.display())), + self.prompt, + ); + + if prompted { + if result.is_ok() { + self.granted_list.insert(FfiDescriptor(resolved_path)); + } else { + self.denied_list.insert(FfiDescriptor(resolved_path)); + self.global_state = PermissionState::Denied; + } } + + result + } else { + let (result, prompted) = + self.query(None).check(self.name, None, self.prompt); + + if prompted { + if result.is_ok() { + self.global_state = PermissionState::Granted; + } else { + self.global_state = PermissionState::Denied; + } + } + + result } - result } pub fn check_all(&mut self) -> Result<(), AnyError> { @@ -1314,7 +1331,7 @@ impl deno_websocket::WebSocketPermissions for Permissions { } impl deno_ffi::FfiPermissions for Permissions { - fn check(&mut self, path: &Path) -> Result<(), AnyError> { + fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError> { self.ffi.check(path) } } @@ -1740,7 +1757,7 @@ pub fn create_child_permissions( .ffi .granted_list .iter() - .all(|desc| main_perms.ffi.check(&desc.0).is_ok()) + .all(|desc| main_perms.ffi.check(Some(&desc.0)).is_ok()) { return Err(escalation_error()); } |